Explorar el Código

Updates for Lemma with shared_ptr, working again.

master
Trevor Irons hace 5 años
padre
commit
e8dbeb24d1

+ 11
- 3
CMakeLists.txt Ver fichero

@@ -1,12 +1,20 @@
1
-if (LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT)
1
+if (LEMMA_VTK7_SUPPORT OR LEMMA_VTK8_SUPPORT)
2 2
 	include_directories(${CMAKE_INSTALL_PREFIX}/include)
3 3
 
4 4
 	include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )
5 5
 	add_subdirectory("src")
6
-
6
+	
7 7
 	add_library( fem4ellipticpde ${FEMSOURCE} )  
8
-	target_link_libraries(fem4ellipticpde "lemmacore")
9 8
 
9
+	set_target_properties(fem4ellipticpde PROPERTIES 
10
+		VERSION  "${LEMMA_VERSION_NOQUOTES}"
11
+		SOVERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}"
12
+		PROJECT_LABEL "FDEM1D ${LABEL_SUFFIX}"
13
+    	CXX_STANDARD 14
14
+    	CXX_STANDARD_REQUIRED ON
15
+	)
16
+
17
+	target_link_libraries(fem4ellipticpde "lemmacore" "dcip")
10 18
 	install ( TARGETS fem4ellipticpde DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
11 19
 
12 20
 	if (LEMMA_BUILD_EXAMPLES)

+ 2
- 3
examples/FEM4EllipticPDE_bhmag.cpp Ver fichero

@@ -145,7 +145,7 @@ int main(int argc, char**argv) {
145 145
 
146 146
     ////////////////////////////////////////////
147 147
     // Solve
148
-    FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
148
+    auto Solver = FEM4EllipticPDE::NewSP();
149 149
         //Solver->SetGFunction(implG);
150 150
         //Solver->SetGFunction(Magnet);
151 151
         //Solver->SetSigmaFunction(implSigma);
@@ -156,10 +156,9 @@ int main(int argc, char**argv) {
156 156
         Solver->Solve(argv[3]);
157 157
 
158 158
     // Clean up
159
-    Solver->Delete();
159
+    //Solver->Delete();
160 160
     GReader->Delete();
161 161
     //implG->Delete();
162
-
163 162
     exit(EXIT_SUCCESS);
164 163
 }
165 164
 

+ 2
- 3
examples/LinearMag/Sphere.cpp Ver fichero

@@ -17,7 +17,7 @@
17 17
  * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
18 18
  */
19 19
 
20
-#include "Lemma"
20
+#include "LemmaCore"
21 21
 #include "LinearMag.h"
22 22
 
23 23
 using namespace Lemma;
@@ -42,7 +42,7 @@ int main( int argc, char** argv ) {
42 42
         exit(EXIT_SUCCESS);
43 43
     }
44 44
 
45
-    LinearMag* Mag = LinearMag::New();
45
+    auto Mag = LinearMag::NewSP();
46 46
         Mag->SetInducingMagField( 55234., 0, 0, NANOTESLA );
47 47
         Mag->SetVTUGridFile( argv[1] );
48 48
         Mag->CalculateRHS( "kappa" );
@@ -51,7 +51,6 @@ int main( int argc, char** argv ) {
51 51
     // Print out YAML serialization of class
52 52
     std::cout << *Mag << std::endl;
53 53
 
54
-    Mag->Delete();
55 54
     exit(EXIT_SUCCESS);
56 55
 }
57 56
 

+ 2
- 4
examples/ResampleWithDataset.cpp Ver fichero

@@ -30,10 +30,8 @@
30 30
 #include <cmath>
31 31
 #include <Eigen/Core>
32 32
 
33
-
34 33
 int main(int argc, char**argv) {
35 34
 
36
-
37 35
     std::cout << "Mesh boundary assigment routine\n";
38 36
     if (argc<4) {
39 37
         std::cout << "usage:\n" << "./ResampleWithDataset  inMesh.vtu  boundaries.stl  outG.vtu" << std::endl;
@@ -83,8 +81,8 @@ int main(int argc, char**argv) {
83 81
 
84 82
     //std::cout << *Resample << std::endl;.
85 83
 
86
-   std::cout << "Resampled grid, ncells=" << Resample->GetOutput()->GetNumberOfCells()  
87
-             << " npoints=" << Resample->GetOutput()->GetNumberOfPoints() << std::endl; 
84
+   std::cout << "Resampled grid, ncells=" << Resample->GetOutput()->GetNumberOfCells()
85
+             << " npoints=" << Resample->GetOutput()->GetNumberOfPoints() << std::endl;
88 86
 
89 87
     vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
90 88
         Writer->SetInputData( Resample->GetOutput() );

+ 3
- 6
examples/VTKDC.cpp Ver fichero

@@ -79,26 +79,23 @@ int main(int argc, char**argv) {
79 79
     std::ifstream ifstr(argv[2]);
80 80
     //std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
81 81
     YAML::Node nodes = YAML::Load(ifstr);
82
-    DCSurvey* Survey = DCSurvey::DeSerialize(nodes);
82
+    auto Survey = DCSurvey::DeSerialize(nodes);
83 83
     //std::cout << *Survey << std::endl;
84 84
 
85 85
 
86 86
     ////////////////////////////////////////////
87 87
     // Solve
88
-    FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
88
+    auto Solver = FEM4EllipticPDE::NewSP();
89 89
         //Solver->SetGFunction(implG);
90 90
         //Solver->SetGFunction(Magnet);
91 91
         //Solver->SetSigmaFunction(implSigma);
92 92
         //Solver->SetBoundaryStep(.05);
93 93
 
94 94
         Solver->SetGrid(uGrid);
95
-        Solver->SetupDC(Survey, 0);
95
+        Solver->SetupDC( Survey.get(), 0 );
96 96
         Solver->Solve( argv[3] );
97 97
         //Solver->SetGrid(rGrid);
98 98
         //Solver->Solve(argv[3]);
99 99
 
100
-    Survey->Delete();
101
-    Solver->Delete();
102
-
103 100
     exit(EXIT_SUCCESS);
104 101
 }

+ 17
- 24
include/FEM4EllipticPDE.h Ver fichero

@@ -88,15 +88,19 @@ namespace Lemma {
88 88
             /** Returns a pointer to a new object of type FEM4EllipticPDE.
89 89
              * It allocates all necessary memory.
90 90
              */
91
-            static FEM4EllipticPDE* New();
91
+            static std::shared_ptr<FEM4EllipticPDE> NewSP();
92 92
 
93
-            /** Deletes this object. Delete also disconnects any
94
-             * attachments to this object.
93
+            /**
94
+             * Default locked constructor.
95 95
              */
96
-            void Delete();
96
+            explicit FEM4EllipticPDE (const ctor_key& key);
97
+
98
+            /** Protected DeDerializing constructor, use factory DeSerialize  method*/
99
+            FEM4EllipticPDE (const YAML::Node& node, const ctor_key& key);
97 100
 
101
+            /** Default protected constructor. */
102
+            ~FEM4EllipticPDE ();
98 103
 
99
-            #ifdef HAVE_YAMLCPP
100 104
             /**
101 105
              *  Uses YAML to serialize this object.
102 106
              *  @return a YAML::Node
@@ -106,8 +110,7 @@ namespace Lemma {
106 110
             /**
107 111
              *   Constructs an object from a YAML::Node.
108 112
              */
109
-            static FEM4EllipticPDE* DeSerialize(const YAML::Node& node);
110
-            #endif
113
+            static std::shared_ptr<FEM4EllipticPDE> DeSerialize(const YAML::Node& node);
111 114
 
112 115
             // ====================  OPERATORS     =======================
113 116
 
@@ -170,27 +173,15 @@ namespace Lemma {
170 173
 
171 174
             // ====================  INQUIRY       =======================
172 175
 
176
+            /** Returns the name of the underlying class, similiar to Python's type */
177
+            virtual std::string GetName() const {
178
+                return this->CName;
179
+            }
180
+
173 181
         protected:
174 182
 
175 183
             // ====================  LIFECYCLE     =======================
176 184
 
177
-            /// Default protected constructor.
178
-            FEM4EllipticPDE (const std::string& cname);
179
-
180
-            #ifdef HAVE_YAMLCPP
181
-            /** Protected DeDerializing constructor, use factory DeSerialize  method*/
182
-            FEM4EllipticPDE (const YAML::Node& node);
183
-            #endif
184
-
185
-            /** Default protected constructor. */
186
-            ~FEM4EllipticPDE ();
187
-
188
-            /**
189
-             * @copybrief LemmaObject::Release()
190
-             * @copydetails LemmaObject::Release()
191
-             */
192
-            void Release();
193
-
194 185
             // ====================  OPERATIONS    =======================
195 186
 
196 187
             /** Used internally to construct stiffness matrix, A
@@ -316,6 +307,8 @@ namespace Lemma {
316 307
 
317 308
         private:
318 309
 
310
+            static constexpr auto CName = "FEM4EllipticPDE";
311
+
319 312
     }; // -----  end of class  FEM4EllipticPDE  -----
320 313
 
321 314
     /*! @} */

+ 18
- 31
include/LinearMag.h Ver fichero

@@ -41,26 +41,27 @@ namespace Lemma {
41 41
      */
42 42
     class LinearMag : public FEM4EllipticPDE {
43 43
 
44
-        friend std::ostream &operator<<(std::ostream &stream,
45
-                const LinearMag &ob);
44
+        friend std::ostream &operator << (std::ostream &stream, const LinearMag &ob);
46 45
 
47 46
         public:
48 47
 
49 48
         // ====================  LIFECYCLE     =======================
50 49
 
51 50
         /**
52
-         * @copybrief LemmaObject::New()
53
-         * @copydetails LemmaObject::New()
51
+         * @copybrief LemmaObject::NewSP()
52
+         * @copydetails LemmaObject::NewSP()
54 53
          */
55
-        static LinearMag* New();
54
+        static std::shared_ptr<LinearMag> NewSP();
56 55
 
57
-        /**
58
-         *  @copybrief   LemmaObject::Delete()
59
-         *  @copydetails LemmaObject::Delete()
60
-         */
61
-        void Delete();
56
+        /** Default protected constructor, use New */
57
+        LinearMag (const ctor_key& key);
58
+
59
+        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
60
+        LinearMag (const YAML::Node& node, const ctor_key& key);
61
+
62
+        /** Default protected destructor, use Delete */
63
+        ~LinearMag ();
62 64
 
63
-#ifdef HAVE_YAMLCPP
64 65
         /**
65 66
          *  Uses YAML to serialize this object.
66 67
          *  @return a YAML::Node
@@ -70,8 +71,7 @@ namespace Lemma {
70 71
         /**
71 72
          *   Constructs an object from a YAML::Node.
72 73
          */
73
-        static LinearMag* DeSerialize(const YAML::Node& node);
74
-#endif
74
+        static std::shared_ptr<LinearMag> DeSerialize(const YAML::Node& node);
75 75
 
76 76
         // ====================  OPERATORS     =======================
77 77
 
@@ -103,39 +103,26 @@ namespace Lemma {
103 103
 
104 104
         // ====================  INQUIRY       =======================
105 105
 
106
+        /** Returns the name of the underlying class, similiar to Python's type */
107
+        virtual std::string GetName() const { return this->CName; }
108
+
106 109
         protected:
107 110
 
108 111
         // ====================  LIFECYCLE     =======================
109 112
 
110
-        /** Default protected constructor, use New */
111
-        LinearMag (const std::string& name);
112
-
113
-#ifdef HAVE_YAMLCPP
114
-        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
115
-        LinearMag (const YAML::Node& node);
116
-#endif
117
-
118
-        /** Default protected destructor, use Delete */
119
-        ~LinearMag ();
120
-
121
-        /**
122
-         *  @copybrief   LemmaObject::Release()
123
-         *  @copydetails LemmaObject::Release()
124
-         */
125
-        void Release();
126
-
127 113
         private:
128 114
 
129 115
         // ====================  DATA MEMBERS  =========================
130 116
 
131 117
         Vector3r    B0;
132 118
 
133
-
134 119
         /**
135 120
          *   Used internally to scale mag units into Tesla
136 121
          */
137 122
         void ScaleB0 ( const MAGUNITS& U);
138 123
 
124
+        static constexpr auto CName = "LinearMag";
125
+
139 126
     }; // -----  end of class  LinearMag  -----
140 127
 
141 128
     /*! @} */ // End of group

+ 14
- 39
src/FEM4EllipticPDE.cpp Ver fichero

@@ -19,87 +19,62 @@
19 19
   @file
20 20
   @author   Trevor Irons
21 21
   @date     08/16/12
22
-  @version   0.0
23 22
  **/
24 23
 
25 24
 #include "FEM4EllipticPDE.h"
26 25
 
27 26
 namespace Lemma {
28 27
 
29
-#ifdef HAVE_YAMLCPP
30 28
     std::ostream &operator << (std::ostream &stream, const FEM4EllipticPDE &ob) {
31
-        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
29
+        stream << ob.Serialize()  << "\n";
32 30
         return stream;
33 31
     }
34
-#else
35
-	std::ostream &operator<<(std::ostream &stream,
36
-				const FEM4EllipticPDE &ob) {
37
-		stream << *(LemmaObject*)(&ob);
38
-		return stream;
39
-	}
40
-#endif
41
-
42 32
 
43 33
 	// ====================  LIFECYCLE     =======================
44 34
 
45
-	FEM4EllipticPDE::FEM4EllipticPDE(const std::string&name) :
46
-			LemmaObject(name), BndryH(10), BndrySigma(10),
35
+	FEM4EllipticPDE::FEM4EllipticPDE( const ctor_key& key ) :
36
+			LemmaObject(key), BndryH(10), BndrySigma(10),
47 37
             vtkSigma(nullptr), vtkG(nullptr), vtkGrid(nullptr), gFcn3(nullptr) {
48 38
 	}
49 39
 
50
-    #ifdef HAVE_YAMLCPP
51 40
     //--------------------------------------------------------------------------------------
52 41
     //       Class:  FEM4EllipticPDE
53 42
     //      Method:  FEM4EllipticPDE
54 43
     // Description:  DeSerializing constructor (protected)
55 44
     //--------------------------------------------------------------------------------------
56
-    FEM4EllipticPDE::FEM4EllipticPDE (const YAML::Node& node) : LemmaObject(node) {
45
+    FEM4EllipticPDE::FEM4EllipticPDE (const YAML::Node& node, const ctor_key& key) : LemmaObject(node, key) {
57 46
         // TODO impliment
58 47
         throw std::runtime_error("FEM4ELLIPTICPDE YAML CONSTRUCTOR NOT IMPLIMENTED!");
59 48
     }  // -----  end of method FEM4EllipticPDE::FEM4EllipticPDE  (constructor)  -----
60
-    #endif
61 49
 
62 50
 	FEM4EllipticPDE::~FEM4EllipticPDE() {
63 51
 	}
64 52
 
65
-    void FEM4EllipticPDE::Release() {
66
-        delete this;
67
-    }
68
-
69
-    FEM4EllipticPDE* FEM4EllipticPDE::New( ) {
70
-        FEM4EllipticPDE* Obj = new FEM4EllipticPDE("FEM4EllipticPDE");
71
-        Obj->AttachTo(Obj);
72
-        return Obj;
53
+    std::shared_ptr<FEM4EllipticPDE> FEM4EllipticPDE::NewSP( ) {
54
+        return std::make_shared<FEM4EllipticPDE>( ctor_key() );
73 55
     }
74 56
 
75
-    void FEM4EllipticPDE::Delete() {
76
-        this->DetachFrom(this);
77
-    }
78
-
79
-#ifdef HAVE_YAMLCPP
80 57
     //--------------------------------------------------------------------------------------
81 58
     //       Class:  FEM4EllipticPDE
82 59
     //      Method:  Serialize
83 60
     //--------------------------------------------------------------------------------------
84 61
     YAML::Node  FEM4EllipticPDE::Serialize (  ) const {
85
-        YAML::Node node = LemmaObject::Serialize();;
86
-        node.SetTag( this->Name );
87
-        // FILL IN CLASS SPECIFICS HERE
62
+        YAML::Node node = LemmaObject::Serialize();
63
+        node.SetTag( this->GetName() );
64
+        // node["thing"] = value;
88 65
         return node;
89 66
     }		// -----  end of method FEM4EllipticPDE::Serialize  -----
90 67
 
91
-
92 68
     //--------------------------------------------------------------------------------------
93 69
     //       Class:  FEM4EllipticPDE
94 70
     //      Method:  DeSerialize
95 71
     //--------------------------------------------------------------------------------------
96
-    FEM4EllipticPDE* FEM4EllipticPDE::DeSerialize ( const YAML::Node& node  ) {
97
-        FEM4EllipticPDE* Object = new FEM4EllipticPDE(node);
98
-        Object->AttachTo(Object);
99
-        DESERIALIZECHECK( node, Object )
100
-            return Object ;
72
+    std::shared_ptr<FEM4EllipticPDE> FEM4EllipticPDE::DeSerialize ( const YAML::Node& node  ) {
73
+        if (node.Tag() != "FEM4EllipticPDE") {
74
+            throw DeSerializeTypeMismatch( "FEM4EllipticPDE", node.Tag() );
75
+        }
76
+        return std::make_shared<FEM4EllipticPDE> (node, ctor_key());
101 77
     }		// -----  end of method FEM4EllipticPDE::DeSerialize  -----
102
-#endif
103 78
 
104 79
     // ====================  OPERATIONS    =======================
105 80
 

+ 12
- 47
src/LinearMag.cpp Ver fichero

@@ -10,7 +10,6 @@
10 10
 /**
11 11
  * @file
12 12
  * @date      03/21/2016 02:10:08 PM
13
- * @version   $Id$
14 13
  * @author    Trevor Irons (ti)
15 14
  * @email     tirons@egi.utah.edu
16 15
  * @copyright Copyright (c) 2016, University of Utah
@@ -22,17 +21,10 @@
22 21
 namespace Lemma {
23 22
 
24 23
 // ====================  FRIEND METHODS  =====================
25
-#ifdef HAVE_YAMLCPP
26 24
 std::ostream &operator << (std::ostream &stream, const LinearMag &ob) {
27
-    stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapsulate thingy
25
+    stream << ob.Serialize()  << "\n";
28 26
     return stream;
29 27
 }
30
-#else
31
-std::ostream &operator<<(std::ostream &stream, const LinearMag& ob) {
32
-    stream << *(FEM4EllipticPDE*)(&ob);
33
-    return stream;
34
-}
35
-#endif
36 28
 
37 29
 // ====================  LIFECYCLE     =======================
38 30
 
@@ -41,30 +33,26 @@ std::ostream &operator<<(std::ostream &stream, const LinearMag& ob) {
41 33
 //      Method:  LinearMag
42 34
 // Description:  constructor (protected)
43 35
 //--------------------------------------------------------------------------------------
44
-LinearMag::LinearMag (const std::string& name) : FEM4EllipticPDE(name) {
36
+LinearMag::LinearMag (const ctor_key& key) : FEM4EllipticPDE(key) {
45 37
 
46 38
 }  // -----  end of method LinearMag::LinearMag  (constructor)  -----
47 39
 
48
-#ifdef HAVE_YAMLCPP
49 40
 //--------------------------------------------------------------------------------------
50 41
 //       Class:  LinearMag
51 42
 //      Method:  LinearMag
52 43
 // Description:  DeSerializing constructor (protected)
53 44
 //--------------------------------------------------------------------------------------
54
-LinearMag::LinearMag (const YAML::Node& node) : FEM4EllipticPDE(node) {
45
+LinearMag::LinearMag (const YAML::Node& node, const ctor_key& key) : FEM4EllipticPDE(node, key) {
55 46
 
56 47
 }  // -----  end of method LinearMag::LinearMag  (constructor)  -----
57
-#endif
58 48
 
59 49
 //--------------------------------------------------------------------------------------
60 50
 //       Class:  LinearMag
61 51
 //      Method:  New()
62 52
 // Description:  public constructor
63 53
 //--------------------------------------------------------------------------------------
64
-LinearMag* LinearMag::New() {
65
-    LinearMag*  Obj = new LinearMag("LinearMag");
66
-    Obj->AttachTo(Obj);
67
-    return Obj;
54
+std::shared_ptr<LinearMag> LinearMag::NewSP() {
55
+    return std::make_shared<LinearMag>( ctor_key() );
68 56
 }
69 57
 
70 58
 //--------------------------------------------------------------------------------------
@@ -78,31 +66,11 @@ LinearMag::~LinearMag () {
78 66
 
79 67
 //--------------------------------------------------------------------------------------
80 68
 //       Class:  LinearMag
81
-//      Method:  Delete
82
-// Description:  public destructor
83
-//--------------------------------------------------------------------------------------
84
-void LinearMag::Delete() {
85
-    this->DetachFrom(this);
86
-}
87
-
88
-//--------------------------------------------------------------------------------------
89
-//       Class:  LinearMag
90
-//      Method:  Release
91
-// Description:  destructor (protected)
92
-//--------------------------------------------------------------------------------------
93
-void LinearMag::Release() {
94
-    delete this;
95
-}
96
-
97
-
98
-#ifdef HAVE_YAMLCPP
99
-//--------------------------------------------------------------------------------------
100
-//       Class:  LinearMag
101 69
 //      Method:  Serialize
102 70
 //--------------------------------------------------------------------------------------
103 71
 YAML::Node  LinearMag::Serialize (  ) const {
104 72
     YAML::Node node = FEM4EllipticPDE::Serialize();;
105
-    node.SetTag( this->Name );
73
+    node.SetTag( this->GetName() );
106 74
     // FILL IN CLASS SPECIFICS HERE
107 75
     node["B0"] = B0;
108 76
     return node;
@@ -113,15 +81,12 @@ YAML::Node  LinearMag::Serialize (  ) const {
113 81
 //       Class:  LinearMag
114 82
 //      Method:  DeSerialize
115 83
 //--------------------------------------------------------------------------------------
116
-LinearMag* LinearMag::DeSerialize ( const YAML::Node& node  ) {
117
-    LinearMag* Object = new LinearMag(node);
118
-    Object->AttachTo(Object);
119
-    DESERIALIZECHECK( node, Object )
120
-        return Object ;
84
+std::shared_ptr<LinearMag> LinearMag::DeSerialize ( const YAML::Node& node ) {
85
+    if ( node.Tag() != "LinearMag") {
86
+        throw DeSerializeTypeMismatch( "LinearMag", node.Tag() );
87
+    }
88
+    return std::make_shared<LinearMag>( node, ctor_key() );
121 89
 }		// -----  end of method LinearMag::DeSerialize  -----
122
-#endif
123
-
124
-
125 90
 
126 91
 //--------------------------------------------------------------------------------------
127 92
 //       Class:  LinearMag
@@ -193,7 +158,7 @@ void LinearMag::CalculateRHS ( const std::string& susName ) {
193 158
     G->SetName("G");
194 159
     //g.resize(vtkGrid->GetNumberOfPoints());
195 160
     VectorXr GG = VectorXr::Zero( vtkGrid->GetNumberOfPoints() );
196
-    
161
+
197 162
     // Iterate over all the points or all of the cells?
198 163
     for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
199 164
 

Loading…
Cancelar
Guardar