Просмотр исходного кода

Work towards port to C++-11. Still not functioning, but a snapshot.

enhancement_3
Trevor Irons 8 лет назад
Родитель
Сommit
fe87e26a9a

+ 46
- 40
Modules/FDEM1D/include/DipoleSource.h Просмотреть файл

@@ -14,11 +14,10 @@
14 14
 #ifndef __DIPOLESOURCE_H
15 15
 #define __DIPOLESOURCE_H
16 16
 
17
-#include "LemmaObject.h"
18 17
 #include "LayeredEarthEM.h"
18
+#include "FieldPoints.h"
19 19
 
20
-#include "receiverpoints.h"
21
-#include "emearth1d.h"
20
+//#include "emearth1d.h"
22 21
 
23 22
 #ifdef LEMMAUSEVTK
24 23
 #include "vtkActor.h"
@@ -32,8 +31,8 @@
32 31
 
33 32
 namespace Lemma {
34 33
 
34
+    // Forward declarations
35 35
     class KernelEM1DManager;
36
-    class ReceiverPoints;
37 36
     class HankelTransform;
38 37
 
39 38
     // ==========================================================================
@@ -44,35 +43,48 @@ namespace Lemma {
44 43
     // ==========================================================================
45 44
     class DipoleSource : public LemmaObject {
46 45
 
47
-        public:
46
+        // ====================    FRIENDS     ======================
48 47
 
49
-            // ====================    FRIENDS     ======================
48
+        friend std::ostream &operator<<(std::ostream &stream, const DipoleSource &ob);
50 49
 
51
-            friend std::ostream &operator<<(std::ostream &stream,
52
-                        const DipoleSource &ob);
50
+        struct ctor_key{};
53 51
 
52
+        public:
54 53
 
55 54
             // ====================  LIFECYCLE     ======================
56 55
 
56
+            /** Default locked constructor. */
57
+            explicit DipoleSource ( const ctor_key& );
58
+
59
+            /** Locked deserializing constructor */
60
+            DipoleSource ( const YAML::Node& node, const ctor_key& );
61
+
62
+            /** Default locked constructor. */
63
+            ~DipoleSource ();
64
+
57 65
             /**
58
-             *  Returns pointer to new DipoleSource. Location is
66
+             *  Returns shared_ptr  to new DipoleSource. Location is
59 67
              *  initialized to (0,0,0) type and polarization are
60 68
              *  initialized  to nonworking values that will throw
61 69
              *  exceptions if used.
62 70
              */
63
-            static DipoleSource* New();
71
+            static std::shared_ptr< DipoleSource > NewSP();
64 72
 
65
-
66
-            /** Returns a deep copy of the dipole. Used to make thread safe methods. Does not
67
-                copy attachments.
73
+            /**
74
+             *   YAML Serializing method
68 75
              */
69
-            DipoleSource* Clone();
76
+            YAML::Node Serialize() const;
70 77
 
71 78
             /**
72
-             * @copybrief LemmaObject::Delete()
73
-             * @copydetails LemmaObject::Delete()
79
+             *   Constructs an object from a YAML::Node.
74 80
              */
75
-            void Delete();
81
+            static std::shared_ptr< DipoleSource > DeSerialize(const YAML::Node& node);
82
+
83
+
84
+            /** Returns a deep copy of the dipole. Used to make thread safe methods. Does not
85
+                copy attachments.
86
+             */
87
+            std::shared_ptr< DipoleSource > Clone();
76 88
 
77 89
             // ====================  OPERATORS     ======================
78 90
 
@@ -80,15 +92,15 @@ namespace Lemma {
80 92
 
81 93
             /** Determines if kernels have been loaded already, and if so if they can be reused
82 94
              */
83
-            void SetKernels(const int& ifreq,  const FIELDCALCULATIONS&  Fields, ReceiverPoints* Receivers, const int& irec,
84
-                    LayeredEarthEM* Earth );
95
+            void SetKernels(const int& ifreq,  const FIELDCALCULATIONS&  Fields, std::shared_ptr<FieldPoints> Receivers, const int& irec,
96
+                    std::shared_ptr<LayeredEarthEM> Earth );
85 97
 
86 98
             /** resets the kernels if they cannot be reused */
87
-            virtual void ReSetKernels(const int& ifreq,  const FIELDCALCULATIONS&  Fields, ReceiverPoints* Receivers, const int& irec,
88
-                    LayeredEarthEM* Earth );
99
+            virtual void ReSetKernels(const int& ifreq,  const FIELDCALCULATIONS&  Fields, std::shared_ptr<FieldPoints> Receivers,
100
+                    const int& irec, std::shared_ptr<LayeredEarthEM> Earth );
89 101
 
90 102
             /** Updates the receiver fields */
91
-            virtual void UpdateFields(const int& ifreq, HankelTransform* Hankel, const Real& wavef);
103
+            virtual void UpdateFields(const int& ifreq, std::shared_ptr<HankelTransform> Hankel, const Real& wavef);
92 104
 
93 105
             // ====================  ACCESS        ======================
94 106
 
@@ -169,7 +181,7 @@ namespace Lemma {
169 181
             DipoleSourceType GetType();
170 182
 
171 183
             /// Returns pointer to KernelEM1DManager
172
-            KernelEM1DManager*  GetKernelManager();
184
+            std::shared_ptr<KernelEM1DManager>  GetKernelManager();
173 185
 
174 186
             // Returns enumerated DipoleSourcePolarization
175 187
             //DipoleSourcePolarisation GetDipoleSourcePolarisation();
@@ -199,21 +211,12 @@ namespace Lemma {
199 211
             vtkActor* GetVtkActor();
200 212
             #endif
201 213
 
202
-        protected:
214
+            /** Returns the name of the underlying class, similiar to Python's type */
215
+            virtual inline std::string GetName() const {
216
+                return CName;
217
+            }
203 218
 
204
-            // ====================  LIFECYCLE     ======================
205
-
206
-            /// Default protected constructor.
207
-            DipoleSource (const std::string &name);
208
-
209
-            /// Default protected constructor.
210
-            ~DipoleSource ();
211
-
212
-            /**
213
-             * @copybrief LemmaObject::Release()
214
-             * @copydetails LemmaObject::Release()
215
-             */
216
-            void Release();
219
+        private:
217 220
 
218 221
             // ====================  DATA MEMBERS  ======================
219 222
 
@@ -263,13 +266,16 @@ namespace Lemma {
263 266
             VectorXr                     Freqs;
264 267
 
265 268
             /// Storage of the EM1D kernels used by this dipole
266
-            KernelEM1DManager*          KernelManager;
269
+            std::shared_ptr<KernelEM1DManager>          KernelManager;
267 270
 
268 271
             /// Receiver points, keep track if these have changed
269
-            ReceiverPoints*             Receivers;
272
+            std::shared_ptr<FieldPoints>                Receivers;
270 273
 
271 274
             /// Layered Earth used by Kernels
272
-            LayeredEarthEM*             Earth;
275
+            std::shared_ptr<LayeredEarthEM>             Earth;
276
+
277
+            /** ASCII string representation of the class name */
278
+            static constexpr auto CName = "DipoleSource";
273 279
 
274 280
     }; // -----  end of class  DipoleSource  -----
275 281
 

+ 6
- 4
Modules/FDEM1D/include/FieldPoints.h Просмотреть файл

@@ -28,12 +28,12 @@
28 28
 #endif
29 29
 
30 30
 #include "LemmaObject.h"
31
-//#include "dipolesource.h"
31
+//#include "DipoleSource.h"
32 32
 
33 33
 namespace Lemma {
34 34
 
35 35
     // Forward Declarations
36
-    class DipoleSource;
36
+    //class DipoleSource;
37 37
 
38 38
     // =======================================================================
39 39
     //        Class:  FieldPoints
@@ -48,6 +48,9 @@ namespace Lemma {
48 48
     // =======================================================================
49 49
     class FieldPoints : public LemmaObject {
50 50
 
51
+        friend class EMEarth1D;
52
+        friend class DipoleSource;
53
+
51 54
         /**
52 55
          *  Stream operator printing out information about this class.
53 56
          */
@@ -59,8 +62,7 @@ namespace Lemma {
59 62
 
60 63
             // ====================    FRIENDS     ===========================
61 64
 
62
-            //friend class EMEarth1D;
63
-            //friend class DipoleSource;
65
+
64 66
 
65 67
             // ====================  LIFECYCLE     ===========================
66 68
 

Modules/FDEM1D/include/kernelem1dmanager.h → Modules/FDEM1D/include/KernelEM1DManager.h Просмотреть файл

@@ -17,7 +17,7 @@
17 17
 //#include "dipolesource.h"
18 18
 //#include "kernelem1dreflbase.h"
19 19
 #include "kernelem1dbase.h"
20
-#include "kernelem1dspec.h"
20
+#include "KernelEM1DSpec.h"
21 21
 
22 22
 namespace Lemma {
23 23
 
@@ -34,22 +34,24 @@ namespace Lemma {
34 34
     // ===================================================================
35 35
     class KernelEM1DManager : public LemmaObject {
36 36
 
37
-        public:
37
+        struct ctor_key {};
38
+
39
+        friend std::ostream &operator<<(std::ostream &stream, const KernelEM1DManager &ob);
38 40
 
39
-            friend std::ostream &operator<<(std::ostream &stream,
40
-                        const KernelEM1DManager &ob);
41
+        public:
41 42
 
42 43
             // ====================  LIFECYCLE     =======================
43 44
 
45
+            /** Default protected constructor. */
46
+            KernelEM1DManager (const std::string& name);
47
+
48
+            /** Default protected constructor. */
49
+            ~KernelEM1DManager ();
50
+
44 51
             /** Returns a pointer to a new object of type KernelEM1DManager.
45 52
              * It allocates all necessary memory.
46 53
              */
47
-            static KernelEM1DManager* New();
48
-
49
-            /** Deletes this object. Delete also disconnects any
50
-             * attachments to this object.
51
-             */
52
-            void Delete();
54
+            static std::shared_ptr<KernelEM1DManager> NewSP();
53 55
 
54 56
             // ====================  OPERATORS     =======================
55 57
 
@@ -60,8 +62,8 @@ namespace Lemma {
60 62
             /*
61 63
             {
62 64
 
63
-                KernelEm1DSpec<Mode, Ikernel, Isource, Irecv>* NewKern =
64
-                    KernelEm1DSpec<Mode, Ikernel, Isource, Irecv>::New();
65
+                KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>* NewKern =
66
+                    KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::New();
65 67
                 KernelVec.push_back( NewKern );
66 68
                 NewKern->managerIdx = KernelVec.size()-1;
67 69
                 switch (Mode) {
@@ -99,9 +101,6 @@ namespace Lemma {
99 101
 
100 102
             /** Clears the vector of kernels */
101 103
             void ClearVec() {
102
-                for (unsigned int ik=0; ik<this->KernelVec.size(); ++ik) {
103
-                    this->KernelVec[ik]->Delete();
104
-                }
105 104
                 KernelVec.clear();
106 105
             }
107 106
 
@@ -109,81 +108,75 @@ namespace Lemma {
109 108
 
110 109
             /** Sets the LayeredEarthEM class that will be used by the kernels.
111 110
              */
112
-            void SetEarth( LayeredEarthEM*   Earth);
111
+            void SetEarth( std::shared_ptr<LayeredEarthEM>   Earth);
113 112
 
114 113
             /** Sets the source of the kernels */
115
-            void SetDipoleSource( DipoleSource*   Dipole, const int& ifreq, const Real& rx_zin);
114
+            void SetDipoleSource( std::shared_ptr<DipoleSource> Dipole, const int& ifreq, const Real& rx_zin);
116 115
 
117 116
             /** Returns pointer to specified kernel indice. Indices are assigned in the same
118 117
                 order as they are created by AddKernel.
119 118
              */
120
-            KernelEm1DBase*    GetKernel(const unsigned int& ik);
119
+            std::shared_ptr<KernelEm1DBase>    GetKernel(const unsigned int& ik);
121 120
 
122 121
             /** Returns pointer to connected dipole.
123 122
              */
124
-            DipoleSource*    GetDipole( );
123
+            std::shared_ptr<DipoleSource>    GetDipole( );
125 124
 
126
-            inline std::vector<KernelEm1DBase*>  GetSTLVector() {
125
+            inline std::vector< std::shared_ptr<KernelEm1DBase> >  GetSTLVector() {
127 126
                 return KernelVec;
128 127
             }
129 128
 
130 129
             // ====================  INQUIRY       =======================
131 130
 
131
+            /** Returns the name of the underlying class, similiar to Python's type */
132
+            virtual inline std::string GetName() const {
133
+                return CName;
134
+            }
135
+
132 136
         protected:
133 137
 
134 138
             // ====================  LIFECYCLE     =======================
135 139
 
136
-            /** Default protected constructor. */
137
-            KernelEM1DManager (const std::string& name);
138
-
139
-            /** Default protected constructor. */
140
-            ~KernelEM1DManager ();
141
-
142
-            /**
143
-             * @copybrief LemmaObject::Release()
144
-             * @copydetails LemmaObject::Release()
145
-             */
146
-            void Release();
147
-
148 140
             // ====================  DATA MEMBERS  =========================
149 141
 
150 142
             /** List of KernelEm1D instances */
151
-            std::vector<KernelEm1DBase*>           KernelVec;
143
+            std::vector< std::shared_ptr<KernelEm1DBase> >  KernelVec;
152 144
 
153 145
             /** Reflection base used for TE mode */
154
-            KernelEM1DReflBase*                    TEReflBase;
146
+            std::shared_ptr<KernelEM1DReflBase>        TEReflBase;
155 147
 
156 148
             /** Reflection base used for TM mode */
157
-            KernelEM1DReflBase*                    TMReflBase;
149
+            std::shared_ptr<KernelEM1DReflBase>        TMReflBase;
158 150
 
159 151
             /** EmEarth Class */
160
-            LayeredEarthEM*                        Earth;
152
+            std::shared_ptr<LayeredEarthEM>            Earth;
161 153
 
162 154
             /** EM dipole souce */
163
-            DipoleSource*                          Dipole;
155
+            std::shared_ptr<DipoleSource>              Dipole;
164 156
 
165 157
             /** Frequency index for the sources */
166
-            int                                    ifreq;
158
+            int                                        ifreq;
167 159
 
168 160
             /** Receiver height */
169
-            Real                                   rx_z;
161
+            Real                                       rx_z;
170 162
 
171 163
         private:
172 164
 
165
+            static constexpr auto CName = "KernelEM1DManager";
166
+
173 167
     }; // -----  end of class  KernelEM1DManager  -----
174 168
 
175 169
     // template methods
176 170
     template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
177 171
     int KernelEM1DManager::AddKernel( ) {
178 172
 
179
-        KernelEm1DSpec<Mode, Ikernel, Isource, Irecv>* NewKern =
180
-                    KernelEm1DSpec<Mode, Ikernel, Isource, Irecv>::New();
173
+        auto NewKern = KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::NewSP();
181 174
         KernelVec.push_back( NewKern );
182 175
         NewKern->managerIdx = KernelVec.size()-1;
183 176
         switch (Mode) {
184 177
             case TE:
185
-                if (TEReflBase == NULL) {
186
-                    TEReflBase = KernelEM1DReflSpec<TE, Isource, Irecv>::New();
178
+                if (TEReflBase == nullptr) {
179
+                    TEReflBase = KernelEM1DReflSpec<TE, Isource, Irecv>::NewSP();
187 180
                     TEReflBase->Initialise(Earth);
188 181
                     TEReflBase->SetUpSource(Dipole, ifreq);
189 182
                     TEReflBase->SetUpReceiver( rx_z );
@@ -191,8 +184,8 @@ namespace Lemma {
191 184
                 NewKern->SetReflBase(TEReflBase);
192 185
                 break;
193 186
             case TM:
194
-                if (TMReflBase == NULL) {
195
-                    TMReflBase = KernelEM1DReflSpec<TM, Isource, Irecv>::New();
187
+                if (TMReflBase == nullptr) {
188
+                    TMReflBase = KernelEM1DReflSpec<TM, Isource, Irecv>::NewSP();
196 189
                     TMReflBase->Initialise(Earth);
197 190
                     TMReflBase->SetUpSource(Dipole, ifreq);
198 191
                     TMReflBase->SetUpReceiver( rx_z );

Modules/FDEM1D/include/kernelem1dreflspec.h → Modules/FDEM1D/include/KernelEM1DReflSpec.h Просмотреть файл

@@ -14,40 +14,16 @@
14 14
 #ifndef  KERNELEM1DREFLSPEC_INC
15 15
 #define  KERNELEM1DREFLSPEC_INC
16 16
 
17
-#include "dipolesource.h"
18
-#include "kernelem1dreflbase.h"
19
-#include "layeredearthem.h"
17
+#include "DipoleSource.h"
18
+#include "LayeredEarthEM.h"
20 19
 
21
-// #include<unordered_map> // for caching results
20
+#include "kernelem1dreflbase.h"
22 21
 
23 22
 namespace Lemma {
24 23
 
25
-    // forward declare
26
-    //struct cache;
27
-    // Simple container to hold reflection results
28
-    struct  cache {
29
-        Real                       rho0;
30
-        Real                       lambda[805];
31
-        Real                       rams[805];
32
-        Complex                    uk[805];
33
-        Complex                    um[805];
34
-        Real                       zh0i[805];
35
-        VectorXcr                  Rtd[805];
36
-        VectorXcr                  Rtu[805];
37
-        VectorXcr                  u[805];
38
-        VectorXcr                  cf[805];
39
-        VectorXcr                  kk[805];
40
-        const Real                 epsilon;
41
-        //bool                       nc;
42
-        cache( ) : epsilon (std::numeric_limits<Real>::epsilon() ) { // TODO reset to precision of Real
43
-            //Rtd = VectorXcr::Zero(805);
44
-            //Rtu = VectorXcr::Zero(805);
45
-        }
46
-    };
47
-
48 24
     // forward declaration for friend
49 25
     template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
50
-    class KernelEm1DSpec;
26
+    class KernelEM1DSpec;
51 27
 
52 28
     // ===================================================================
53 29
     //  Class:  KernelEM1DReflSpec
@@ -55,29 +31,37 @@ namespace Lemma {
55 31
       @class
56 32
       \brief   Specialized version of KernelEM1DReflBase
57 33
       \details Through use of template specialisations, this KernelEm1D
58
-               class delivers much better performance.
34
+               class delivers much better performance. This class is internal
35
+               to Lemma, you should never need to instantiate it. The constructors
36
+               are public to allow make_shared. Additonally, this class is not
37
+               serializable.
59 38
      */
60 39
     // ===================================================================
61 40
     template<EMMODE Mode, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
62 41
     class KernelEM1DReflSpec : public KernelEM1DReflBase {
63 42
 
43
+        // TODO can we use the manager's key instead to lock for that?
44
+        struct ctor_key{};
45
+
64 46
         public:
65 47
 
48
+            // what do these template parameters do -TI
66 49
             template<EMMODE Mode2, int Ikernel2, DIPOLE_LOCATION Isource2, DIPOLE_LOCATION Irecv2>
67
-            friend class KernelEm1DSpec;
50
+            friend class KernelEM1DSpec;
68 51
             friend class KernelEM1DManager;
69 52
 
70 53
             // ====================  LIFECYCLE     =======================
71 54
 
72
-            static KernelEM1DReflSpec* New() {
73
-                KernelEM1DReflSpec<Mode, Isource, Irecv>*  Obj =
74
-                    new KernelEM1DReflSpec<Mode, Isource, Irecv>("KernelEM1DReflSpec<>");
75
-                Obj->AttachTo(Obj);
76
-                return Obj;
55
+            /// Default locked constructor.
56
+            explicit KernelEM1DReflSpec ( const ctor_key& ) : KernelEM1DReflBase( ) {
77 57
             }
78 58
 
79
-            void Delete() {
80
-                this->DetachFrom(this);
59
+            /// Default protected constructor.
60
+            ~KernelEM1DReflSpec () {
61
+            }
62
+
63
+            static std::shared_ptr<KernelEM1DReflSpec<Mode, Isource, Irecv> > NewSP() {
64
+                return std::make_shared<KernelEM1DReflSpec<Mode, Isource, Irecv> >( ctor_key() );
81 65
             }
82 66
 
83 67
             // ====================  OPERATORS     =======================
@@ -89,24 +73,10 @@ namespace Lemma {
89 73
             // ====================  INQUIRY       =======================
90 74
 
91 75
         protected:
76
+        private:
92 77
 
93 78
             // ====================  LIFECYCLE     =======================
94 79
 
95
-            /// Default protected constructor.
96
-            KernelEM1DReflSpec (const std::string& name) : KernelEM1DReflBase(name)
97
-            {
98
-            }
99
-
100
-            /// Default protected constructor.
101
-            ~KernelEM1DReflSpec () {
102
-                if (this->NumberOfReferences > 0)
103
-                    throw DeleteObjectWithReferences( this );
104
-            }
105
-
106
-            void Release() {
107
-                delete this;
108
-            }
109
-
110 80
             // ====================  OPERATIONS    =======================
111 81
 
112 82
             /** Computes reflection coefficients. Depending on the
@@ -134,15 +104,6 @@ namespace Lemma {
134 104
 
135 105
             // ====================  DATA MEMBERS  =========================
136 106
 
137
-        private:
138
-
139
-            //** Storage container for reused results */
140
-            //static std::unordered_map<Real, cache> CACHE;
141
-
142
-            //** Currenly used cache */
143
-            //cache* tcache;
144
-            //#pragma omp threadprivate(tcache)
145
-
146 107
     }; // -----  end of class  KernelEM1DReflSpec  -----
147 108
 
148 109
     //template<EMMODE Mode, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
@@ -180,63 +141,6 @@ namespace Lemma {
180 141
 
181 142
     ///////////////////////////////////////////////
182 143
     // Default mode definitions
183
-
184
-/*
185
-    template<EMMODE Mode, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
186
-    void KernelEM1DReflSpec<Mode, Isource, Irecv>::SetTCache(const Real& rho0) {
187
-       #ifdef LEMMAUSEOMP
188
-        #pragma omp critical
189
-        #endif
190
-        {
191
-        this->tcache = &this->CACHE[rho0];
192
-        }
193
-    }
194
-*/
195
-
196
-/*
197
-    template<EMMODE Mode, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
198
-    void KernelEM1DReflSpec<Mode, Isource, Irecv>::ComputeReflectionCoeffs(const Real& lambda, const int& idx) {
199
-
200
-        if ( (std::abs(this->tcache->lambda[idx]-lambda) <= this->tcache->epsilon) &&
201
-            this->tcache->u[idx].size() > 0  && std::abs(this->kk(0) - this->tcache->kk[idx](0)) <= this->tcache->epsilon ) {
202
-            //std::cout << "USING CACHED RESULTS !!!!!!" << std::endl;
203
-            // load all the values we need
204
-            this->u   = this->tcache->u[idx];
205
-            this->rams = this->tcache->rams[idx];
206
-            this->cf = this->tcache->cf[idx];
207
-            //this->kk = this->tcache->kk[idx];
208
-            this->uk = this->tcache->uk[idx];
209
-            this->um = this->tcache->um[idx];
210
-            this->rtd = this->tcache->Rtd[idx];
211
-            this->rtu = this->tcache->Rtu[idx];
212
-
213
-        } else { // else do the work
214
-        }
215
-
216
-        ComputeReflectionCoeffs(lambda);
217
-
218
-        //#pragma omp critical
219
-        //{
220
-        //std::cout << idx << "\t" << lambda << "\t" << rtd.transpose() << std::endl;
221
-        //}
222
-        // store the results
223
-        this->tcache->u[idx]      = this->u;
224
-        this->tcache->cf[idx]     = this->cf;
225
-        this->tcache->kk[idx]     = this->kk;
226
-        this->tcache->uk[idx]     = this->uk;
227
-        this->tcache->um[idx]     = this->um;
228
-        this->tcache->Rtd[idx]    = this->rtd;
229
-        this->tcache->Rtu[idx]    = this->rtu;
230
-        this->tcache->zh0i[idx]    = std::imag(this->zh[0]);
231
-        this->tcache->lambda[idx] = lambda;
232
-        this->tcache->rams[idx]   = rams;
233
-
234
-        }
235
-
236
-        return;
237
-    }
238
-*/
239
-
240 144
     template<EMMODE Mode, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
241 145
     void KernelEM1DReflSpec<Mode, Isource, Irecv>::ComputeReflectionCoeffs(const Real& lambda) {
242 146
         static bool called = false;

+ 0
- 1
Modules/FDEM1D/include/LayeredEarthEM.h Просмотреть файл

@@ -15,7 +15,6 @@
15 15
 #define __LAYEREDEARTHEM_H
16 16
 
17 17
 #include "LayeredEarth.h"
18
-#include <iomanip>
19 18
 
20 19
 namespace Lemma {
21 20
 

+ 37
- 47
Modules/FDEM1D/include/PolygonalWireAntenna.h Просмотреть файл

@@ -10,12 +10,12 @@
10 10
   @date     05/18/2010
11 11
   @version  $Id: PolygonalWireAntenna.h 211 2015-02-27 05:43:26Z tirons $
12 12
  **/
13
-
14
-#include "WireAntenna.h"
15
-
16 13
 #ifndef  POLYGONALWIREANTENNA_INC
17 14
 #define  POLYGONALWIREANTENNA_INC
18 15
 
16
+#include "DipoleSource.h"
17
+#include "WireAntenna.h"
18
+
19 19
 namespace Lemma {
20 20
 
21 21
     // ===================================================================
@@ -27,27 +27,42 @@ namespace Lemma {
27 27
     // ===================================================================
28 28
     class PolygonalWireAntenna : public WireAntenna {
29 29
 
30
-        friend std::ostream &operator<<(std::ostream &stream,
31
-                const PolygonalWireAntenna &ob);
30
+        friend std::ostream &operator<<(std::ostream &stream, const PolygonalWireAntenna &ob);
31
+
32
+        struct ctor_key {};
32 33
 
33 34
         public:
34 35
 
35 36
             // ====================  LIFECYCLE     =======================
36 37
 
38
+            /// Default protected constructor.
39
+            explicit PolygonalWireAntenna ( const ctor_key& );
40
+
41
+            /// Default protected constructor.
42
+            PolygonalWireAntenna (const YAML::Node& node, const ctor_key& );
43
+
44
+            /// Default protected constructor.
45
+            virtual ~PolygonalWireAntenna ();
46
+
37 47
             /**
38 48
              * Declares all memory and returns a new instance.
39 49
              */
40
-            static PolygonalWireAntenna* New();
50
+            static std::shared_ptr<PolygonalWireAntenna> NewSP();
51
+
52
+            /// Makes a deep copy of this antenna with all connections except
53
+            /// the dipole approximation.
54
+            std::shared_ptr<PolygonalWireAntenna> Clone();
41 55
 
42 56
             /**
43
-             * @copybrief LemmaObject::Delete()
44
-             * @copydetails LemmaObject::Delete()
57
+             *  Uses YAML to serialize this object.
58
+             *  @return a YAML::Node
45 59
              */
46
-            void Delete();
60
+            YAML::Node Serialize() const;
47 61
 
48
-            /// Makes a deep copy of this antenna with all connections except
49
-            /// the dipole approximation.
50
-            PolygonalWireAntenna* Clone();
62
+            /**
63
+             *   Constructs an object from a YAML::Node.
64
+             */
65
+            static std::shared_ptr<PolygonalWireAntenna> DeSerialize(const YAML::Node& node);
51 66
 
52 67
             // ====================  OPERATORS     =======================
53 68
 
@@ -77,40 +92,13 @@ namespace Lemma {
77 92
 
78 93
             // ====================  INQUIRY       =======================
79 94
 
80
-            #ifdef HAVE_YAMLCPP
81
-            /**
82
-             *  Uses YAML to serialize this object.
83
-             *  @return a YAML::Node
84
-             */
85
-            YAML::Node Serialize() const;
86
-
87
-            /**
88
-             *   Constructs an object from a YAML::Node.
89
-             */
90
-            static PolygonalWireAntenna* DeSerialize(const YAML::Node& node);
91
-            #endif
95
+            /** Returns the name of the underlying class, similiar to Python's type */
96
+            virtual inline std::string GetName() const {
97
+                return CName;
98
+            }
92 99
 
93 100
         protected:
94 101
 
95
-            // ====================  LIFECYCLE     =======================
96
-
97
-            /// Default protected constructor.
98
-            PolygonalWireAntenna (const std::string& name);
99
-
100
-#ifdef HAVE_YAMLCPP
101
-            /// Default protected constructor.
102
-            PolygonalWireAntenna (const YAML::Node& node);
103
-#endif
104
-
105
-            /// Default protected constructor.
106
-            ~PolygonalWireAntenna ();
107
-
108
-            /**
109
-             * @copybrief LemmaObject::Release()
110
-             * @copydetails LemmaObject::Release()
111
-             */
112
-            void Release();
113
-
114 102
             // ====================  DATA MEMBERS  =======================
115 103
 
116 104
             /// minimum ratio of dipole moment to distance to receiver point
@@ -123,15 +111,15 @@ namespace Lemma {
123 111
             Real maxDipoleMoment;
124 112
 
125 113
             /// appends
126
-            void PushXYZDipoles(const Vector3r &step, const Vector3r &cp,
114
+            void PushXYZDipoles( const Vector3r &step, const Vector3r &cp,
127 115
                             const Vector3r &dir,
128
-                            std::vector<DipoleSource*> &Dipoles) ;
116
+                            std::vector< std::shared_ptr<DipoleSource> > &Dipoles) ;
129 117
 
130 118
             /// corrects for overstep
131
-            void CorrectOverstepXYZDipoles(const Vector3r &step,
119
+            void CorrectOverstepXYZDipoles( const Vector3r &step,
132 120
                             const Vector3r &cp,
133 121
                             const Vector3r &dir,
134
-                            std::vector<DipoleSource*> &Dipoles );
122
+                            std::vector< std::shared_ptr<DipoleSource> > &Dipoles );
135 123
 
136 124
             // ====================  OPERATIONS    =======================
137 125
 
@@ -162,6 +150,8 @@ namespace Lemma {
162 150
 
163 151
             Vector3r                               rRepeat;
164 152
 
153
+            static constexpr auto CName = "PolygonalWireAntenna";
154
+
165 155
     }; // -----  end of class  PolygonalWireAntenna  -----
166 156
 
167 157
 }       // -----  end of Lemma  name  -----

+ 32
- 47
Modules/FDEM1D/include/WireAntenna.h Просмотреть файл

@@ -14,8 +14,7 @@
14 14
 #ifndef __WIREANTENNA_H
15 15
 #define __WIREANTENNA_H
16 16
 
17
-#include "LemmaObject.h"
18
-#include "dipolesource.h"
17
+#include "DipoleSource.h"
19 18
 
20 19
 #ifdef LEMMAUSEVTK
21 20
 #include "vtkActor.h"
@@ -32,29 +31,44 @@ namespace Lemma {
32 31
     // ===================================================================
33 32
     class WireAntenna : public LemmaObject {
34 33
 
35
-        friend std::ostream &operator<<(std::ostream &stream,
36
-            const WireAntenna &ob);
34
+        friend std::ostream &operator<<(std::ostream &stream, const WireAntenna &ob);
35
+
36
+        struct ctor_key {};
37 37
 
38 38
         public:
39 39
 
40 40
             // ====================  LIFECYCLE     =======================
41 41
 
42
+            /** Locked default constructor */
43
+            explicit WireAntenna ( const ctor_key& );
44
+
45
+            /** Locked deserializing constructor */
46
+            WireAntenna ( const YAML::Node& node, const ctor_key& );
47
+
48
+            /** Destructor */
49
+            virtual ~WireAntenna();
50
+
42 51
             /**
43 52
              * Initialises antenna to contain no points, with no current
44 53
              * and no frequency. NumberOfTurns set to 1
45 54
              */
46
-            static WireAntenna* New();
55
+            static std::shared_ptr<WireAntenna> NewSP();
47 56
 
48 57
             /**
49 58
              * Provides deep copy
50 59
              */
51
-            virtual WireAntenna* Clone();
60
+            virtual std::shared_ptr<WireAntenna> Clone();
52 61
 
53 62
             /**
54
-             * @copybrief LemmaObject::Delete()
55
-             * @copydetails LemmaObject::Delete()
63
+             *  Uses YAML to serialize this object.
64
+             *  @return a YAML::Node
56 65
              */
57
-            void Delete();
66
+            YAML::Node Serialize() const;
67
+
68
+            /**
69
+             *   Constructs an object from a YAML::Node.
70
+             */
71
+            static std::shared_ptr<WireAntenna> DeSerialize( const YAML::Node& node );
58 72
 
59 73
             // ====================  OPERATORS     =======================
60 74
 
@@ -113,19 +127,6 @@ namespace Lemma {
113 127
 
114 128
             // ====================  INQUIRY       =======================
115 129
 
116
-            #ifdef HAVE_YAMLCPP
117
-            /**
118
-             *  Uses YAML to serialize this object.
119
-             *  @return a YAML::Node
120
-             */
121
-            YAML::Node Serialize() const;
122
-
123
-            /**
124
-             *   Constructs an object from a YAML::Node.
125
-             */
126
-            static WireAntenna* DeSerialize(const YAML::Node& node);
127
-            #endif
128
-
129 130
 			/**
130 131
               * Returns the number of turns
131 132
               * @return the number of turns of the loop.
@@ -159,7 +160,7 @@ namespace Lemma {
159 160
 			/**
160 161
               * Returns pointer to a dipole source
161 162
 			  */
162
-            DipoleSource* GetDipoleSource(const int &dip);
163
+            std::shared_ptr<DipoleSource> GetDipoleSource(const int &dip);
163 164
 
164 165
 			/**
165 166
               * returns number of dipoles used to approximate this
@@ -184,30 +185,12 @@ namespace Lemma {
184 185
              */
185 186
             bool IsHorizontallyPlanar();
186 187
 
187
-        protected:
188
-
189
-            // ====================  LIFECYCLE     =======================
190
-
191
-			/**
192
-              * Default protected constructor.
193
-			  */
194
-            WireAntenna (const std::string &name);
195
-
196
-#ifdef HAVE_YAMLCPP
197
-        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
198
-            WireAntenna (const YAML::Node& node);
199
-#endif
200
-
201
-			/**
202
-              * Default protected destructor.
203
-			  */
204
-            ~WireAntenna ();
188
+            /** Returns the name of the underlying class, similiar to Python's type */
189
+            virtual inline std::string GetName() const {
190
+                return CName;
191
+            }
205 192
 
206
-            /**
207
-             * @copybrief LemmaObject::Release()
208
-             * @copydetails LemmaObject::Release()
209
-             */
210
-            void Release();
193
+        protected:
211 194
 
212 195
             // ====================  DATA MEMBERS  =======================
213 196
 
@@ -229,7 +212,7 @@ namespace Lemma {
229 212
 			/**
230 213
               * List of the dipoles
231 214
 			  */
232
-            std::vector<DipoleSource*>           Dipoles;
215
+            std::vector< std::shared_ptr<DipoleSource> > Dipoles;
233 216
 
234 217
 			/**
235 218
               * Points that define this loop
@@ -243,6 +226,8 @@ namespace Lemma {
243 226
 
244 227
         private:
245 228
 
229
+            static constexpr auto CName = "WireAntenna";
230
+
246 231
     }; // -----  end of class  WireAntenna  -----
247 232
 
248 233
 }

+ 40
- 46
Modules/FDEM1D/include/emearth1d.h Просмотреть файл

@@ -14,13 +14,17 @@
14 14
 #ifndef __EMEARTH1D_H
15 15
 #define __EMEARTH1D_H
16 16
 
17
-#include "dipolesource.h"
18
-#include "layeredearthem.h"
19
-#include "receiverpoints.h"
20
-#include "WireAntenna.h"
21
-#include "PolygonalWireAntenna.h"
22
-#include "kernelem1dspec.h"
23
-#include "kernelem1dmanager.h"
17
+
18
+
19
+// forward declare these due to include cycle
20
+//#include "LayeredEarthEM.h"
21
+//#include "DipoleSource.h"
22
+//#include "FieldPoints.h"
23
+//#include "WireAntenna.h"
24
+//#include "PolygonalWireAntenna.h"
25
+//#include "KernelEM1DManager.h"
26
+
27
+#include "KernelEM1DSpec.h"
24 28
 #include "hankeltransformgaussianquadrature.h"
25 29
 #include "hankeltransformhankel2.h"
26 30
 #include "FHTKey.h"
@@ -35,6 +39,12 @@
35 39
 
36 40
 namespace Lemma {
37 41
 
42
+    class WireAntenna;
43
+    class PolygonalWireAntenna;
44
+    class FieldPoints;
45
+    class DipoleSource;
46
+    class LayeredEarthEM;
47
+
38 48
     // =======================================================================
39 49
     //        Class:  EmEarth1D
40 50
     /// \brief  Implimentation of 1D EM solution.
@@ -45,37 +55,40 @@ namespace Lemma {
45 55
 		friend std::ostream &operator<<(std::ostream &stream,
46 56
 			const EMEarth1D &ob);
47 57
 
58
+        struct ctor_key{};
59
+
48 60
         public:
49 61
 
50 62
             //friend class KernelEm1D;
51 63
 
52 64
             // ====================  LIFECYCLE     ===========================
53 65
 
66
+            /** Default protected constructor. */
67
+            EMEarth1D ( const ctor_key& );
68
+
69
+            /** Default protected constructor. */
70
+			EMEarth1D ( const YAML::Node& node, const ctor_key& );
71
+
72
+            /** Default protected constructor. */
73
+            ~EMEarth1D ();
74
+
54 75
             /**
55 76
              *  Returns pointer to new EMEarth1D. Location is
56 77
              *  initialized to (0,0,0) type and polarization are
57 78
              *  initialized  to nonworking values that will throw
58 79
              *  exceptions if used.
59 80
              */
60
-            static EMEarth1D* New();
61
-
62
-            /**
63
-             * @copybrief LemmaObject::Delete()
64
-             * @copydetails LemmaObject::Delete()
65
-             */
66
-            void Delete();
81
+            static std::shared_ptr<EMEarth1D> NewSP();
67 82
 
68 83
             /** stream debugging info to std::out
69 84
              */
70 85
             void Query();
71 86
 
72
-            #ifdef HAVE_YAMLCPP
73 87
             /** YAML Serializing method
74 88
              */
75 89
             YAML::Node Serialize() const;
76 90
 
77 91
             //static EMEarth1D* DeSerialize(const YAML::Node& node);
78
-            #endif
79 92
 
80 93
             // ====================  OPERATORS     ===========================
81 94
 
@@ -99,13 +112,13 @@ namespace Lemma {
99 112
             void AttachWireAntenna(WireAntenna *antennae);
100 113
 
101 114
             /** Attaches a dipole for calculation */
102
-            void AttachDipoleSource(DipoleSource *dipole);
115
+            void AttachDipoleSource( std::shared_ptr<DipoleSource> dipole);
103 116
 
104 117
             /** Attaches a layered earth model for calculation */
105
-            void AttachLayeredEarthEM(LayeredEarthEM *Earth);
118
+            void AttachLayeredEarthEM( std::shared_ptr<LayeredEarthEM> Earth);
106 119
 
107 120
             /** Attaches a set of receiver points for calculation */
108
-            void AttachReceiverPoints(ReceiverPoints *Receivers);
121
+            void AttachFieldPoints( std::shared_ptr<FieldPoints> Receivers);
109 122
 
110 123
             /** Sets the fields that are calcultated, E,H or BOTH */
111 124
             void SetFieldsToCalculate(const FIELDCALCULATIONS &calc);
@@ -118,41 +131,22 @@ namespace Lemma {
118 131
 
119 132
         protected:
120 133
 
121
-            // ====================  LIFECYCLE     ===========================
122
-
123
-            /** Default protected constructor. */
124
-            EMEarth1D (const std::string& name);
125
-
126
-            #ifdef HAVE_YAMLCPP
127
-            /** Default protected constructor. */
128
-			EMEarth1D (const YAML::Node& node);
129
-            #endif
130
-
131
-            /** Default protected constructor. */
132
-            ~EMEarth1D ();
133
-
134
-            /**
135
-             * @copybrief LemmaObject::Release()
136
-             * @copydetails LemmaObject::Release()
137
-             */
138
-            void Release();
139
-
140 134
             // ====================  OPERATIONS    ===========================
141 135
 
142 136
             /** Used internally, this is the innermost loop of the MakeCalc3,
143 137
              *  and CalculateWireAntennaField routines.
144 138
              */
145 139
             void SolveSingleTxRxPair(const int &irec,
146
-                    HankelTransform *Hankel,
140
+                    std::shared_ptr<HankelTransform> Hankel,
147 141
                     const Real &wavef, const int &ifreq,
148
-                    DipoleSource *tDipole);
142
+                    std::shared_ptr<DipoleSource> tDipole);
149 143
 
150 144
             /** Used internally, this is the innermost loop of the MakeCalc3,
151 145
              *  and CalculateWireAntennaField routines.
152 146
              */
153
-            void SolveLaggedTxRxPair(const int &irec, Hankel2* Hankel,
147
+            void SolveLaggedTxRxPair(const int &irec, std::shared_ptr<Hankel2> Hankel,
154 148
                     const Real &wavef, const int &ifreq,
155
-                    PolygonalWireAntenna* antenna);
149
+                    std::shared_ptr<PolygonalWireAntenna> antenna);
156 150
 
157 151
             /** Removes all connections */
158 152
             void DetachAll();
@@ -160,16 +154,16 @@ namespace Lemma {
160 154
             // ====================  DATA MEMBERS  ===========================
161 155
 
162 156
             /** Computes field due to dipole */
163
-            DipoleSource*        Dipole;
157
+            std::shared_ptr<DipoleSource>        Dipole;
164 158
 
165 159
             /** Earth model (Cole-cole) */
166
-            LayeredEarthEM*      Earth;
160
+            std::shared_ptr<LayeredEarthEM>      Earth;
167 161
 
168 162
             /** Receiver points */
169
-            ReceiverPoints*      Receivers;
163
+            std::shared_ptr<FieldPoints>         Receivers;
170 164
 
171 165
             /** Wire antennae tx */
172
-            WireAntenna*         Antenna;
166
+            std::shared_ptr<WireAntenna>         Antenna;
173 167
 
174 168
             /** What fields are wanted */
175 169
             FIELDCALCULATIONS    FieldsToCalculate;

+ 9
- 7
Modules/FDEM1D/include/hankeltransform.h Просмотреть файл

@@ -14,13 +14,15 @@
14 14
 #ifndef __hankeltransform_h
15 15
 #define __hankeltransform_h
16 16
 
17
-#include "LemmaObject.h"
18
-#include "kernelem1dbase.h"
19
-#include "kernelem1dspec.h"
20
-#include "kernelem1dmanager.h"
17
+//#include "kernelem1dbase.h"
18
+#include "KernelEM1DSpec.h"
19
+#include "KernelEM1DManager.h"
21 20
 
22 21
 namespace Lemma {
23 22
 
23
+
24
+        class KernelEM1DBase;
25
+
24 26
         // ===================================================================
25 27
         //        Class:  HankelTransform
26 28
         /// \brief  Pure abstract class for hankel transforms
@@ -55,15 +57,15 @@ namespace Lemma {
55 57
                 /// = omega * sqrt( EP*AMU )  amu = 4 pi e-7  ep = 8.85e-12
56 58
                 virtual Complex Zgauss(const int &ikk, const EMMODE &imode,
57 59
                             const int &itype, const Real &rho,
58
-                            const Real &wavef, KernelEm1DBase *Kernel)=0;
60
+                            const Real &wavef, std::shared_ptr<KernelEm1DBase> Kernel)=0;
59 61
 
60 62
                 /// Computes related kernels, if applicable, otherwise this is
61 63
                 /// just a dummy function.
62 64
                 virtual void ComputeRelated(const Real& rho, KernelEm1DBase* Kernel);
63 65
 
64
-                virtual void ComputeRelated(const Real& rho, std::vector< KernelEm1DBase* > KernelVec);
66
+                virtual void ComputeRelated(const Real& rho, std::vector< std::shared_ptr<KernelEM1DBase> > KernelVec);
65 67
 
66
-                virtual void ComputeRelated(const Real& rho, KernelEM1DManager* KernelManager);
68
+                virtual void ComputeRelated(const Real& rho, std::shared_ptr<KernelEM1DManager> KernelManager);
67 69
 
68 70
                 // ====================  ACCESS        =======================
69 71
 

+ 1
- 1
Modules/FDEM1D/include/hankeltransformhankel2.h Просмотреть файл

@@ -16,7 +16,7 @@
16 16
 
17 17
 #include "hankeltransform.h"
18 18
 #include "kernelem1dbase.h"
19
-#include "kernelem1dspec.h"
19
+#include "KernelEM1DSpec.h"
20 20
 #include "CubicSplineInterpolator.h"
21 21
 
22 22
 namespace Lemma {

+ 12
- 20
Modules/FDEM1D/include/kernelem1dbase.h Просмотреть файл

@@ -38,6 +38,15 @@ namespace Lemma {
38 38
 
39 39
             // ====================  LIFECYCLE     =======================
40 40
 
41
+            /// Default protected constructor.
42
+            KernelEm1DBase ( ) : LemmaObject( ) {
43
+
44
+            }
45
+
46
+            /// Default protected constructor.
47
+            ~KernelEm1DBase () {
48
+            }
49
+
41 50
             // ====================  OPERATORS     =======================
42 51
 
43 52
             // ====================  OPERATIONS    =======================
@@ -77,26 +86,6 @@ namespace Lemma {
77 86
 
78 87
         protected:
79 88
 
80
-            // ====================  LIFECYCLE     =======================
81
-
82
-            /// Default protected constructor.
83
-            KernelEm1DBase (const std::string& name) : LemmaObject(name)
84
-            {
85
-            }
86
-
87
-            /// Default protected constructor.
88
-            ~KernelEm1DBase () {
89
-                if (this->NumberOfReferences > 0)
90
-                    throw DeleteObjectWithReferences( this );
91
-            }
92
-
93
-            void Release() {
94
-                delete this;
95
-            }
96
-
97
-            // ====================  OPERATIONS    =======================
98
-
99
-
100 89
             // ====================  DATA MEMBERS  =========================
101 90
 
102 91
             /** Where does this kernel live on the vector managed by the manager */
@@ -104,6 +93,9 @@ namespace Lemma {
104 93
 
105 94
         private:
106 95
 
96
+            /** ASCII string representation of the class name */
97
+            static constexpr auto CName = "KernelEM1DBase";
98
+
107 99
     }; // -----  end of class  KernelEm1DBase  -----
108 100
 
109 101
 } // namespace Lemma

+ 14
- 21
Modules/FDEM1D/include/kernelem1dreflbase.h Просмотреть файл

@@ -14,20 +14,18 @@
14 14
 #ifndef  KERNELEM1DREFLBASE_INC
15 15
 #define  KERNELEM1DREFLBASE_INC
16 16
 
17
-#include "dipolesource.h"
18
-#include "kernelem1dbase.h"
19
-#include "layeredearthem.h"
20
-//#include "kernelem1dspec.h"
17
+#include "KernelEM1DSpec.h"
18
+//#include "kernelem1dbase.h"
19
+#include "DipoleSource.h"
20
+#include "LayeredEarthEM.h"
21 21
 
22 22
 namespace Lemma {
23 23
 
24
-    //class DipoleSource;
25
-
26 24
     enum DIPOLE_LOCATION { INAIR, INGROUND };
27 25
 
28 26
     // forward declaration for friend
29
-    template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
30
-    class KernelEm1DSpec;
27
+    //template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
28
+    //class KernelEM1DSpec;
31 29
 
32 30
 
33 31
     // ===================================================================
@@ -40,9 +38,10 @@ namespace Lemma {
40 38
     // ===================================================================
41 39
     class KernelEM1DReflBase : public LemmaObject {
42 40
 
43
-        template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
44
-        friend class KernelEm1DSpec;
45
-        friend class KernelEM1DManager;
41
+        //template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
42
+        friend class KernelEM1DSpec;
43
+        //friend class KernelEM1DManager;
44
+        //friend class DipoleSource;
46 45
 
47 46
         public:
48 47
 
@@ -52,7 +51,7 @@ namespace Lemma {
52 51
 
53 52
             // ====================  OPERATIONS    =======================
54 53
 
55
-            void Initialise(LayeredEarthEM* EarthIn) {
54
+            void Initialise( std::shared_ptr<LayeredEarthEM> EarthIn) {
56 55
 
57 56
                 nlay = EarthIn->GetNumberOfLayers();
58 57
                 zh = VectorXcr::Zero(nlay);
@@ -88,7 +87,7 @@ namespace Lemma {
88 87
 
89 88
             }
90 89
 
91
-            void SetUpSource(DipoleSource *Dipole, const int &ifreq) {
90
+            void SetUpSource( std::shared_ptr<DipoleSource> Dipole, const int &ifreq ) {
92 91
 
93 92
                 zh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*MU0);
94 93
                 yh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*EPSILON0);
@@ -150,18 +149,12 @@ namespace Lemma {
150 149
             // ====================  LIFECYCLE     =======================
151 150
 
152 151
             /// Default protected constructor.
153
-            KernelEM1DReflBase (const std::string& name) : LemmaObject(name)
152
+            KernelEM1DReflBase ( ) : LemmaObject( )
154 153
             {
155 154
             }
156 155
 
157 156
             /// Default protected constructor.
158 157
             ~KernelEM1DReflBase () {
159
-                if (this->NumberOfReferences > 0)
160
-                    throw DeleteObjectWithReferences( this );
161
-            }
162
-
163
-            void Release() {
164
-                delete this;
165 158
             }
166 159
 
167 160
             // ====================  OPERATIONS    =======================
@@ -220,7 +213,7 @@ namespace Lemma {
220 213
 			EMMODE mode;
221 214
 
222 215
             /// Pointer to layered earth
223
-            LayeredEarthEM *Earth;
216
+            std::shared_ptr<LayeredEarthEM> Earth;
224 217
 
225 218
 			Complex       uk;
226 219
 			Complex       um;

+ 0
- 1485
Modules/FDEM1D/include/kernelem1dspec.h
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 2
- 1
Modules/FDEM1D/src/CMakeLists.txt Просмотреть файл

@@ -3,7 +3,8 @@ set (FEM1DSOURCE
3 3
 	#${CMAKE_CURRENT_SOURCE_DIR}/AEMSurvey.cpp
4 4
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthEM.cpp
5 5
 	${CMAKE_CURRENT_SOURCE_DIR}/FieldPoints.cpp
6
-	#${CMAKE_CURRENT_SOURCE_DIR}/DipoleSource.cpp
6
+	${CMAKE_CURRENT_SOURCE_DIR}/WireAntenna.cpp
7
+#	${CMAKE_CURRENT_SOURCE_DIR}/DipoleSource.cpp
7 8
 	#${CMAKE_CURRENT_SOURCE_DIR}/UngroundedElectricDipole.cpp
8 9
 	PARENT_SCOPE
9 10
 )

+ 26
- 112
Modules/FDEM1D/src/DipoleSource.cpp Просмотреть файл

@@ -11,122 +11,51 @@
11 11
   @version  $Id: dipolesource.cpp 203 2015-01-09 21:19:04Z tirons $
12 12
  **/
13 13
 
14
-#include "dipolesource.h"
15
-#include "kernelem1dmanager.h"
14
+#include "DipoleSource.h"
15
+#include "KernelEM1DManager.h"
16
+#include "FieldPoints.h"
17
+
18
+//#include "GroundedElectricDipole.h"
19
+//#include "UngroundedElectricDipole.h"
20
+//#include "MagneticDipole.h"
16 21
 
17
-#include "GroundedElectricDipole.h"
18
-#include "UngroundedElectricDipole.h"
19
-#include "MagneticDipole.h"
20
-#include "receiverpoints.h"
21 22
 #include "hankeltransform.h"
22 23
 
23 24
 namespace Lemma {
24 25
 
25 26
 
26 27
     // ====================    FRIENDS     ======================
27
-    std::ostream &operator<<(std::ostream &stream,
28
-                const DipoleSource &ob) {
29
-
30
-        stream << *(LemmaObject*)(&ob);
31
-        switch (ob.Type) {
32
-            case (NOSOURCETYPE):
33
-                stream << "\tType=" << ob.Type << " (Uninitialized dipole)"
34
-                << "\n";
35
-                break;
36
-            case (GROUNDEDELECTRICDIPOLE):
37
-                stream << "\tType=" << ob.Type << " (Grounded Electric dipole)"
38
-                << "\n";
39
-                break;
40
-            case (UNGROUNDEDELECTRICDIPOLE):
41
-                stream << "\tType=" << ob.Type << " (Ungrounded Electric dipole)"
42
-                << "\n";
43
-                break;
44
-            case (MAGNETICDIPOLE):
45
-                stream << "\tType=" << ob.Type << " (Magnetic dipole)"
46
-                << "\n";
47
-                break;
48
-            default:
49
-                throw NonValidDipoleType( );
50
-        }
51
-
52
-        /*
53
-        switch (ob.Polarisation) {
54
-
55
-            case(NOPOLARISATION):
56
-                stream << "Polarisation=" << ob.Polarisation <<
57
-                        " (Unset polarisation)" << "\n";
58
-                break;
59
-
60
-            case(XPOLARISATION):
61
-                stream << "Polarisation=" << ob.Polarisation <<
62
-                        " (X polarised)" << "\n";
63
-                break;
64
-
65
-            case(YPOLARISATION):
66
-                stream << "Polarisation=" << ob.Polarisation <<
67
-                        " (Y polarised)" << "\n";
68
-                break;
69
-
70
-            case(ZPOLARISATION):
71
-                stream << "Polarisation=" << ob.Polarisation <<
72
-                        " (Z polarised)" << "\n";
73
-                break;
74
-        }
75
-        */
76
-        stream << "\tPolarisation " << ob.Phat.transpose() << "\n";
77
-        stream << "\tLocation= " << ob.Location.transpose()
78
-                << " [metres] \n";
79
-        stream << "\tFrequencies= " << ob.Freqs.transpose() << " [Hz] \n";
80
-        stream << "\tPhase= " << ob.Phase << "\n";
81
-        stream << "\tMoment= " << ob.Moment << "\n";
28
+    std::ostream &operator<<(std::ostream &stream, const DipoleSource &ob) {
29
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
82 30
         return stream;
83 31
     }
84 32
 
85 33
 
86 34
     // ====================  LIFECYCLE     ======================
87 35
 
88
-    DipoleSource::DipoleSource(const std::string &name) :
89
-                    LemmaObject(name),
36
+    DipoleSource::DipoleSource( const ctor_key& ) : LemmaObject( ),
90 37
                     Type(NOSOURCETYPE),
91 38
                     Phase(0),
92 39
                     Moment(1),
93
-                    KernelManager(NULL),
94
-                    Receivers(NULL),
95
-                    Earth(NULL)
40
+                    KernelManager(nullptr),
41
+                    Receivers(nullptr),
42
+                    Earth(nullptr)
96 43
     {
97 44
         this->Location.setZero();
98 45
         this->Phat.setZero();
99 46
     }
100 47
 
101 48
     DipoleSource::~DipoleSource() {
102
-        if (this->NumberOfReferences != 0)
103
-            throw DeleteObjectWithReferences(this);
104
-        /* These are not attched as they are connected for such a short time that the reference counting
105
-           was getting tricked and calling delete
106
-        if (Receivers != NULL) {
107
-            Receivers->DetachFrom(this);
108
-        }
109
-
110
-        if (Earth != NULL) {
111
-            Earth->DetachFrom(this);
112
-        }
113
-        */
114
-        if (KernelManager != NULL) {
115
-            KernelManager->Delete();
116
-        }
117
-
118 49
     }
119 50
 
120
-    DipoleSource* DipoleSource::New() {
121
-        DipoleSource* Obj = new DipoleSource("DipoleSource");
122
-        Obj->AttachTo(Obj);
123
-        return Obj;
51
+    std::shared_ptr<DipoleSource> DipoleSource::NewSP() {
52
+        return std::make_shared<DipoleSource> ( ctor_key() );
124 53
     }
125 54
 
126
-    DipoleSource* DipoleSource::Clone() {
127 55
 
128
-        DipoleSource* Obj = new DipoleSource("DipoleSource");
129
-        Obj->AttachTo(Obj);
56
+    std::shared_ptr<DipoleSource> DipoleSource::Clone() {
57
+
58
+        auto Obj = DipoleSource::NewSP();
130 59
 
131 60
         // copy
132 61
         Obj->Type = Type;
@@ -159,14 +88,6 @@ namespace Lemma {
159 88
         return Obj;
160 89
     }
161 90
 
162
-    void DipoleSource::Delete() {
163
-        this->DetachFrom(this);
164
-    }
165
-
166
-    void DipoleSource::Release() {
167
-        delete this;
168
-    }
169
-
170 91
     // ====================  ACCESS        ======================
171 92
     void DipoleSource::SetLocation(const Vector3r &posin) {
172 93
         this->Location = posin;
@@ -275,21 +196,15 @@ namespace Lemma {
275 196
 
276 197
     // ====================  OPERATIONS     =====================
277 198
 
278
-    void DipoleSource::SetKernels(const int& ifreq, const FIELDCALCULATIONS&  Fields , ReceiverPoints* ReceiversIn, const int& irecin,
279
-            LayeredEarthEM* EarthIn  ) {
199
+    void DipoleSource::SetKernels(const int& ifreq, const FIELDCALCULATIONS&  Fields , std::shared_ptr<FieldPoints> ReceiversIn, const int& irecin,
200
+            std::shared_ptr<LayeredEarthEM> EarthIn  ) {
280 201
 
281
-        // These are not properly attached because in tight parallel loops reference counting is unreliable. This is safe as this
282
-        // method is not exposed to the public API and we know what we are doing here -TI
283 202
         if (Receivers != ReceiversIn) {
284
-            //if (Receivers != NULL) Receivers->DetachFrom(this);
285 203
             Receivers = ReceiversIn;
286
-            //ReceiversIn->AttachTo(this);
287 204
         }
288 205
 
289 206
         if (Earth != EarthIn) {
290
-            //if (Earth != NULL) Earth->DetachFrom(this);
291 207
             Earth = EarthIn;
292
-            //EarthIn->AttachTo(this);
293 208
         }
294 209
 
295 210
         if (irecin != irec) {
@@ -317,10 +232,9 @@ namespace Lemma {
317 232
         lays = Earth->GetLayerAtThisDepth(Location[2]);
318 233
         layr = Earth->GetLayerAtThisDepth(Receivers->GetLocation(irec)[2]);
319 234
 
320
-        if (KernelManager != NULL) KernelManager->Delete();
321
-        KernelManager = KernelEM1DManager::New();
235
+        KernelManager = KernelEM1DManager::NewSP();
322 236
             KernelManager->SetEarth(Earth);
323
-            KernelManager->SetDipoleSource(this, ifreq, Receivers->GetLocation(irec)[2]);
237
+            KernelManager->SetDipoleSource(shared_from_this(), ifreq, Receivers->GetLocation(irec)[2]);
324 238
         kernelFreq = Freqs(ifreq); // this is never used
325 239
         ReSetKernels( ifreq, Fields, Receivers, irec, Earth );
326 240
 
@@ -329,8 +243,8 @@ namespace Lemma {
329 243
 
330 244
     // TODO we could make the dipoles template specializations avoiding this rats nest of switch statements. Probably
331 245
     //      not the most critical piece though
332
-    void DipoleSource::ReSetKernels(const int& ifreq, const FIELDCALCULATIONS&  Fields , ReceiverPoints* Receivers, const int& irec,
333
-            LayeredEarthEM* Earth  ) {
246
+    void DipoleSource::ReSetKernels(const int& ifreq, const FIELDCALCULATIONS&  Fields , std::shared_ptr<FieldPoints> Receivers, const int& irec,
247
+            std::shared_ptr<LayeredEarthEM> Earth  ) {
334 248
 
335 249
         Vector3r Pol = Phat;
336 250
 
@@ -807,7 +721,7 @@ namespace Lemma {
807 721
 
808 722
     }
809 723
 
810
-    void DipoleSource::UpdateFields( const int& ifreq, HankelTransform* Hankel, const Real& wavef) {
724
+    void DipoleSource::UpdateFields( const int& ifreq, std::shared_ptr<HankelTransform> Hankel, const Real& wavef) {
811 725
 
812 726
         Vector3r Pol = Phat;
813 727
 
@@ -1189,7 +1103,7 @@ namespace Lemma {
1189 1103
 
1190 1104
     // ====================  INQUIRY       ======================
1191 1105
 
1192
-    KernelEM1DManager*  DipoleSource::GetKernelManager() {
1106
+    std::shared_ptr<KernelEM1DManager>  DipoleSource::GetKernelManager() {
1193 1107
         return KernelManager;
1194 1108
     }
1195 1109
 

Modules/FDEM1D/src/kernelem1dmanager.cpp → Modules/FDEM1D/src/KernelEM1DManager.cpp Просмотреть файл


+ 38
- 83
Modules/FDEM1D/src/WireAntenna.cpp Просмотреть файл

@@ -15,65 +15,35 @@
15 15
 
16 16
 namespace Lemma {
17 17
 
18
-    #ifdef HAVE_YAMLCPP
19 18
     std::ostream &operator << (std::ostream &stream, const WireAntenna &ob) {
20
-        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
21 20
         return stream;
22 21
     }
23
-    #else
24
-    std::ostream &operator<<(std::ostream &stream,
25
-                const WireAntenna &ob) {
26
-
27
-        stream << *(LemmaObject*)(&ob);
28
-        stream << "Current: " << ob.Current << " [A]\n";
29
-        stream << "Frequencies: " << ob.Freqs.transpose() << " [Hz]\n";
30
-        stream << "Number of points " << ob.NumberOfPoints << "\n";
31
-        stream << "Number of turns " << ob.NumberOfTurns << "\n";
32
-
33
-        if (ob.NumberOfPoints) {
34
-            stream << "Points:\n" << ob.Points.transpose() << "\n";
35
-            //stream << "Dipoles used to approximate " << ob.Dipoles.size() << "\n";
36
-        }
37
-        return stream;
38
-    }
39
-    #endif
22
+
40 23
     // ====================  LIFECYCLE     =======================
41 24
 
42
-    WireAntenna::WireAntenna(const std::string &name) :
43
-        LemmaObject(name),
25
+    WireAntenna::WireAntenna( const ctor_key& ) : LemmaObject( ),
44 26
         NumberOfPoints(0), Current(1), NumberOfTurns(1) {
45 27
     }
46 28
 
47
-#ifdef HAVE_YAMLCPP
48
-    WireAntenna::WireAntenna(const YAML::Node &node) :
49
-        LemmaObject(node) {
29
+    WireAntenna::WireAntenna( const YAML::Node& node, const ctor_key& ) : LemmaObject( node ) {
50 30
         Points =  node["Points"].as<Vector3Xr>();
51 31
         Freqs = node["Freqs"].as<VectorXr>();
52 32
         NumberOfPoints = node["NumberOfPoints"].as<int>();
53 33
         NumberOfTurns = node["NumberOfTurns"].as<int>();
54 34
         Current = node["Current"].as<Real>();
55 35
     }
56
-#endif
57 36
 
58 37
     WireAntenna::~WireAntenna() {
59
-        for (unsigned int id=0; id<Dipoles.size(); ++id) {
60
-            Dipoles[id]->Delete();
61
-        }
62
-        Dipoles.clear();
63
-        if (this->NumberOfReferences != 0) {
64
-            throw DeleteObjectWithReferences(this);
65
-        }
66 38
     }
67 39
 
68
-    WireAntenna* WireAntenna::New() {
69
-        WireAntenna* Obj = new WireAntenna("WireAntenna");
70
-        Obj->AttachTo(Obj);
71
-        return Obj;
40
+    std::shared_ptr<WireAntenna> WireAntenna::NewSP() {
41
+        return std::make_shared<WireAntenna>( ctor_key() );
72 42
     }
73 43
 
74
-    WireAntenna* WireAntenna::Clone() {
75
-        WireAntenna* copy = WireAntenna::New();
76
-		//copy->AttachTo(copy); // NO! Attached above!
44
+    std::shared_ptr<WireAntenna> WireAntenna::Clone() {
45
+        auto copy = WireAntenna::NewSP();
46
+
77 47
 		copy->NumberOfPoints = this->NumberOfPoints;
78 48
 		copy->Freqs = this->Freqs;
79 49
 		copy->Current = this->Current;
@@ -83,13 +53,32 @@ namespace Lemma {
83 53
 		return copy;
84 54
     }
85 55
 
86
-    void WireAntenna::Delete() {
87
-        this->DetachFrom(this);
88
-    }
56
+    //--------------------------------------------------------------------------------------
57
+    //       Class:  WireAntenna
58
+    //      Method:  Serialize
59
+    //--------------------------------------------------------------------------------------
60
+    YAML::Node WireAntenna::Serialize (  ) const {
61
+        YAML::Node node = LemmaObject::Serialize();
62
+        node.SetTag( GetName() );
63
+        node["NumberOfPoints"] = NumberOfPoints;
64
+        node["NumberOfTurns"] = NumberOfTurns;
65
+        node["Current"] = Current;
66
+        node["Points"] = Points;
67
+        node["Freqs"] = Freqs;
68
+        return node;
69
+    }		// -----  end of method WireAntenna::Serialize  -----
89 70
 
90
-    void WireAntenna::Release() {
91
-        delete this;
92
-    }
71
+
72
+    //--------------------------------------------------------------------------------------
73
+    //       Class:  WireAntenna
74
+    //      Method:  DeSerialize
75
+    //--------------------------------------------------------------------------------------
76
+    std::shared_ptr<WireAntenna> WireAntenna::DeSerialize ( const YAML::Node& node ) {
77
+        if (node.Tag() != "WireAntenna") {
78
+            throw  DeSerializeTypeMismatch( "WireAntenna", node.Tag());
79
+        }
80
+        return std::make_shared<WireAntenna> ( node, ctor_key() );
81
+    }		// -----  end of method WireAntenna::DeSerialize  -----
93 82
 
94 83
 
95 84
     // ====================  ACCESS        =======================
@@ -165,9 +154,6 @@ namespace Lemma {
165 154
     void WireAntenna::ApproximateWithElectricDipoles(const Real &deltai) {
166 155
 
167 156
         // Get rid of any dipoles
168
-        for (unsigned int id=0; id<Dipoles.size(); ++id) {
169
-            Dipoles[id]->Delete();
170
-        }
171 157
         Dipoles.clear();
172 158
 
173 159
         Real Dist(0);
@@ -190,7 +176,7 @@ namespace Lemma {
190 176
 
191 177
                 // X dipoles
192 178
                 if (std::abs(r[0]) > 1e-6) {
193
-                    DipoleSource *tx = DipoleSource::New();
179
+                    auto tx = DipoleSource::NewSP();
194 180
                     tx->SetLocation(p);
195 181
                     tx->SetType(GROUNDEDELECTRICDIPOLE);
196 182
                     tx->SetPolarisation(XPOLARISATION);
@@ -201,7 +187,7 @@ namespace Lemma {
201 187
 
202 188
                 // Y dipoles
203 189
                 if (std::abs(r[1]) > 1e-6) {
204
-                    DipoleSource *ty = DipoleSource::New();
190
+                    auto ty = DipoleSource::NewSP();
205 191
                     ty->SetLocation(p);
206 192
                     ty->SetType(GROUNDEDELECTRICDIPOLE);
207 193
                     ty->SetPolarisation(YPOLARISATION);
@@ -212,7 +198,7 @@ namespace Lemma {
212 198
 
213 199
                 // Z dipoles
214 200
                 if (std::abs(r[2]) > 1e-6) {
215
-                    DipoleSource *tz = DipoleSource::New();
201
+                    auto tz = DipoleSource::NewSP();
216 202
                     tz->SetLocation(p);
217 203
                     tz->SetType(GROUNDEDELECTRICDIPOLE);
218 204
                     tz->SetPolarisation(ZPOLARISATION);
@@ -233,7 +219,7 @@ namespace Lemma {
233 219
         return Dipoles.size();
234 220
     }
235 221
 
236
-    DipoleSource* WireAntenna::GetDipoleSource(const int &dip) {
222
+    std::shared_ptr<DipoleSource> WireAntenna::GetDipoleSource(const int &dip) {
237 223
         return this->Dipoles[dip];
238 224
     }
239 225
 
@@ -243,37 +229,6 @@ namespace Lemma {
243 229
     }
244 230
     #endif
245 231
 
246
-    #ifdef HAVE_YAMLCPP
247
-    //--------------------------------------------------------------------------------------
248
-    //       Class:  WireAntenna
249
-    //      Method:  Serialize
250
-    //--------------------------------------------------------------------------------------
251
-    YAML::Node WireAntenna::Serialize (  ) const {
252
-        YAML::Node node = LemmaObject::Serialize();
253
-        node.SetTag( this->Name );
254
-        node["NumberOfPoints"] = NumberOfPoints;
255
-        node["NumberOfTurns"] = NumberOfTurns;
256
-        node["Current"] = Current;
257
-        node["Points"] = Points;
258
-        node["Freqs"] = Freqs;
259
-        return node;
260
-    }		// -----  end of method WireAntenna::Serialize  -----
261
-
262
-
263
-    //--------------------------------------------------------------------------------------
264
-    //       Class:  WireAntenna
265
-    //      Method:  DeSerialize
266
-    //--------------------------------------------------------------------------------------
267
-    WireAntenna* WireAntenna::DeSerialize ( const YAML::Node& node ) {
268
-        WireAntenna* Object = new WireAntenna(node);
269
-        Object->AttachTo(Object);
270
-        DESERIALIZECHECK( node, Object )
271
-        return Object ;
272
-    }		// -----  end of method WireAntenna::DeSerialize  -----
273
-
274
-    #endif
275
-
276
-
277 232
     //--------------------------------------------------------------------------------------
278 233
     //       Class:  WireAntenna
279 234
     //      Method:  IsPlanar

+ 312
- 312
Modules/FDEM1D/src/kernelem1dspec.cpp
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 1
- 1
Modules/LemmaCore/include/LemmaObject.h Просмотреть файл

@@ -34,7 +34,7 @@ namespace Lemma {
34 34
   *           standard. All Lemma objects should be created as C++-11 Smart pointers, using
35 35
   *           the supplied New method. Calls to Delete are no longer necessary or available.
36 36
   */
37
-class LemmaObject {
37
+class LemmaObject : public std::enable_shared_from_this<LemmaObject> {
38 38
 
39 39
     /**
40 40
      *  Streams class information as YAML::Node

Загрузка…
Отмена
Сохранить