Browse Source

Work towards port of FDEM code to C++-11 and improved unit testing.

enhancement_3
Trevor Irons 8 years ago
parent
commit
067a3a30a7

+ 1
- 1
CMakeLists.txt View File

191
 set(LEMMA_VERSION_MAJOR "0")
191
 set(LEMMA_VERSION_MAJOR "0")
192
 set(LEMMA_VERSION_MINOR "1")
192
 set(LEMMA_VERSION_MINOR "1")
193
 set(LEMMA_VERSION_PATCH "1")
193
 set(LEMMA_VERSION_PATCH "1")
194
-set(LEMMA_VERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}")
194
+set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"")
195
 
195
 
196
 configure_file (
196
 configure_file (
197
 	"${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
197
 	"${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"

+ 4
- 0
Modules/FDEM1D/examples/CMakeLists.txt View File

1
 add_executable( LayeredEarthEM LayeredEarthEM.cpp  )
1
 add_executable( LayeredEarthEM LayeredEarthEM.cpp  )
2
 target_link_libraries(  LayeredEarthEM  "lemmacore" "fdem1d")
2
 target_link_libraries(  LayeredEarthEM  "lemmacore" "fdem1d")
3
 
3
 
4
+add_executable( FieldPoints FieldPoints.cpp  )
5
+target_link_libraries(  FieldPoints  "lemmacore" "fdem1d")
6
+
4
 INSTALL_TARGETS( "/share/FEM1D/"
7
 INSTALL_TARGETS( "/share/FEM1D/"
5
 	LayeredEarthEM 
8
 	LayeredEarthEM 
9
+	FieldPoints
6
 )
10
 )

+ 45
- 0
Modules/FDEM1D/examples/FieldPoints.cpp View File

1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      11/01/2016 02:24:11 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
18
+ */
19
+#include<random>
20
+#include<FDEM1D>
21
+using namespace Lemma;
22
+
23
+int main()
24
+{
25
+
26
+    std::random_device rd;
27
+    std::mt19937 gen(rd());
28
+
29
+    // up to 11 layers
30
+    std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
31
+    int np = d(gen);
32
+
33
+    auto Obj = FieldPoints::NewSP();
34
+    // fill with details
35
+        Obj->SetNumberOfPoints(np);
36
+        //void SetLocation(const int& nrec, const Real& xp, const Real& yp,
37
+        //                 const Real& zp);
38
+
39
+    YAML::Node node = Obj->Serialize();
40
+    std::cout << node << std::endl;
41
+    auto Obj2 = FieldPoints::DeSerialize(node);
42
+    //std::cout << Obj2->GetNumberOfPoints() << std::endl;
43
+    //std::cout << Obj->GetNumberOfPoints() << std::endl;
44
+}
45
+

+ 12
- 8
Modules/FDEM1D/examples/LayeredEarthEM.cpp View File

31
 
31
 
32
     std::uniform_real_distribution<> dis(0, 1);
32
     std::uniform_real_distribution<> dis(0, 1);
33
     VectorXcr con = VectorXcr(nl);
33
     VectorXcr con = VectorXcr(nl);
34
+    VectorXr thick = VectorXr(nl-2);
34
     con(0) = 0;
35
     con(0) = 0;
35
     for ( int i=1; i<nl; ++i ) {
36
     for ( int i=1; i<nl; ++i ) {
36
         con(i) = Complex(dis(gen), dis(gen));
37
         con(i) = Complex(dis(gen), dis(gen));
37
     }
38
     }
38
-    std::cout << con << std::endl;
39
+    for ( int i=0; i<nl-2; ++i ) {
40
+        thick(i) = dis(gen);
41
+    }
42
+    auto Obj = LayeredEarthEM::NewSP();
43
+         Obj->SetNumberOfLayers(nl);
44
+         Obj->SetLayerConductivity(con);
45
+         Obj->SetLayerThickness(thick);
39
 
46
 
40
-    auto model = LayeredEarthEM::NewSP();
41
-        model->SetNumberOfLayers(nl);
42
-        //model->SetLayerThickness( (VectorXr(4) << 10,10,10,10).finished() );
43
-        //model->SetLayerConductivity( (VectorXcr(6) << .1, .10,.10,.10,.10,.10).finished() );
44
-    auto model2 = LayeredEarthEM::DeSerialize(model->Serialize());
47
+    auto model2 = LayeredEarthEM::DeSerialize(Obj->Serialize());
45
 
48
 
46
-    std::cout << model->GetNumberOfLayers() << std::endl;
47
-    std::cout << model2->GetNumberOfLayers() << std::endl;
49
+    std::cout << *Obj << std::endl;
50
+    //std::cout << model->GetNumberOfLayers() << std::endl;
51
+    //std::cout << model2->GetNumberOfLayers() << std::endl;
48
 
52
 
49
 }
53
 }
50
 
54
 

+ 1
- 0
Modules/FDEM1D/include/FDEM1D View File

1
 #include "LayeredEarthEM.h"
1
 #include "LayeredEarthEM.h"
2
+#include "FieldPoints.h"
2
 
3
 
3
 /* vim: set tabstop=4 expandtab: */
4
 /* vim: set tabstop=4 expandtab: */
4
 /* vim: set filetype=cpp: */
5
 /* vim: set filetype=cpp: */

+ 41
- 43
Modules/FDEM1D/include/FieldPoints.h View File

28
 #endif
28
 #endif
29
 
29
 
30
 #include "LemmaObject.h"
30
 #include "LemmaObject.h"
31
-#include "dipolesource.h"
32
-
33
-#ifdef HAVE_YAMLCPP
34
-#include "yaml-cpp/yaml.h"
35
-#endif
31
+//#include "dipolesource.h"
36
 
32
 
37
 namespace Lemma {
33
 namespace Lemma {
38
 
34
 
35
+    // Forward Declarations
36
+    class DipoleSource;
37
+
39
     // =======================================================================
38
     // =======================================================================
40
     //        Class:  FieldPoints
39
     //        Class:  FieldPoints
41
     /**
40
     /**
42
      *  \brief  Points in the subsurface where 1D EM calculations are made
41
      *  \brief  Points in the subsurface where 1D EM calculations are made
43
-     */ \details
42
+     *  \details These are the points where Hankel transform calculations are
43
+     *           made.
44
+     *  \note In previous versions of Lemma, this class was called ReceiverPoints,
45
+     *        the functionality remains roughly the same, but the name is more
46
+     *        appropriate.
47
+     */
44
     // =======================================================================
48
     // =======================================================================
45
     class FieldPoints : public LemmaObject {
49
     class FieldPoints : public LemmaObject {
46
 
50
 
51
+        /**
52
+         *  Stream operator printing out information about this class.
53
+         */
54
+        friend std::ostream &operator<<(std::ostream &stream, const FieldPoints &ob);
55
+
56
+        struct ctor_key {};
57
+
47
         public:
58
         public:
48
 
59
 
49
             // ====================    FRIENDS     ===========================
60
             // ====================    FRIENDS     ===========================
50
 
61
 
51
-            /**
52
-             *  Stream operator printing out information about this class.
53
-             */
54
-            friend std::ostream &operator<<(std::ostream &stream,
55
-                        const FieldPoints &ob);
56
-
57
-            friend class EMEarth1D;
58
-            friend class DipoleSource;
62
+            //friend class EMEarth1D;
63
+            //friend class DipoleSource;
59
 
64
 
60
             // ====================  LIFECYCLE     ===========================
65
             // ====================  LIFECYCLE     ===========================
61
 
66
 
67
+            /** Default locked constructor. */
68
+            explicit FieldPoints ( const ctor_key& );
69
+
70
+            /** Locked deserializing constructor. */
71
+            FieldPoints (const YAML::Node& node, const ctor_key&);
72
+
73
+            /** Default destructor. */
74
+            ~FieldPoints ();
75
+
62
             /**
76
             /**
63
              *  Factory method for generating concrete class.
77
              *  Factory method for generating concrete class.
64
              *  @return a std::shared_ptr of type FieldPoints
78
              *  @return a std::shared_ptr of type FieldPoints
65
              */
79
              */
66
-            static std::shared_ptr<FieldPoints*> NewSP();
80
+            static std::shared_ptr<FieldPoints> NewSP();
67
 
81
 
68
         	/**
82
         	/**
69
              *  Uses YAML to serialize this object.
83
              *  Uses YAML to serialize this object.
84
+             *  @note The actual calculation results are not serialized, currently.
70
              *  @return a YAML::Node
85
              *  @return a YAML::Node
71
              */
86
              */
72
             YAML::Node Serialize() const;
87
             YAML::Node Serialize() const;
76
              *   @param[in] node is a YAML node containing the serialized class information
91
              *   @param[in] node is a YAML node containing the serialized class information
77
              *   @return a std::shared_ptr object of FieldPoints
92
              *   @return a std::shared_ptr object of FieldPoints
78
              */
93
              */
79
-            static std::shared_ptr< FieldPoints* > DeSerialize(const YAML::Node& node);
94
+            static std::shared_ptr<FieldPoints> DeSerialize(const YAML::Node& node);
80
 
95
 
81
             // ====================  OPERATORS     ===========================
96
             // ====================  OPERATORS     ===========================
82
 
97
 
85
             // ====================  ACCESS        ===========================
100
             // ====================  ACCESS        ===========================
86
 
101
 
87
             /** Sets the number of receivers */
102
             /** Sets the number of receivers */
88
-            virtual void SetNumberOfReceivers(const int &nrec);
103
+            virtual void SetNumberOfPoints(const int &nrec);
89
 
104
 
90
             /** Returns the location of a single receiver as an Eigen Vector */
105
             /** Returns the location of a single receiver as an Eigen Vector */
91
             void SetLocation(const int& nrec, const Vector3r& loc);
106
             void SetLocation(const int& nrec, const Vector3r& loc);
96
 
111
 
97
             // ====================  INQUIRY       ===========================
112
             // ====================  INQUIRY       ===========================
98
 
113
 
114
+            /** Returns the name of the underlying class, similiar to Python's type */
115
+            virtual inline std::string GetName() const {
116
+                return CName;
117
+            }
118
+
99
             /// Returns the number of receiverpoints.
119
             /// Returns the number of receiverpoints.
100
-            int GetNumberOfReceivers();
120
+            int GetNumberOfPoints();
101
 
121
 
102
             /// Returns all the receiver locations as a 3 X matrix
122
             /// Returns all the receiver locations as a 3 X matrix
103
             Vector3Xr GetLocations();
123
             Vector3Xr GetLocations();
187
             /// Returns the mask for this point
207
             /// Returns the mask for this point
188
             int GetMask(const int& i);
208
             int GetMask(const int& i);
189
 
209
 
190
-
191
         protected:
210
         protected:
192
 
211
 
193
-            // ====================  LIFECYCLE     ===========================
194
-
195
-            /** Default protected constructor. */
196
-            FieldPoints ( );
197
-
198
-            #ifdef HAVE_YAMLCPP
199
-            /** Default protected constructor. */
200
-            FieldPoints (const YAML::Node& node);
201
-            #endif
202
-
203
-            /** Default protected constructor. */
204
-            ~FieldPoints ();
205
-
206
-            /**
207
-             * @copybrief LemmaObject::Release()
208
-             * @copydetails LemmaObject::Release()
209
-             */
210
-            void Release();
211
-
212
             // ====================  OPERATIONS    ===========================
212
             // ====================  OPERATIONS    ===========================
213
 
213
 
214
             /// Sets the number of H bins. These bins are often frequencies.
214
             /// Sets the number of H bins. These bins are often frequencies.
243
 
243
 
244
             // ====================  DATA MEMBERS  ===========================
244
             // ====================  DATA MEMBERS  ===========================
245
 
245
 
246
+        private:
247
+
246
             /// Number of receivers
248
             /// Number of receivers
247
-            int                         NumberOfReceivers;
249
+            int                         NumberOfPoints;
248
 
250
 
249
             /// Number of fields
251
             /// Number of fields
250
             int                         NumberOfBinsE;
252
             int                         NumberOfBinsE;
259
             /// Locations of receivers
261
             /// Locations of receivers
260
             Vector3Xr                   Locations;
262
             Vector3Xr                   Locations;
261
 
263
 
262
-        private:
263
-
264
             // NOTE, these are not serialized in output!
264
             // NOTE, these are not serialized in output!
265
-
266
             /// Electric field at receiver locations
265
             /// Electric field at receiver locations
267
             std::vector<Vector3Xcr>     Efield;
266
             std::vector<Vector3Xcr>     Efield;
268
 
267
 
269
             /// H field at receiver locations
268
             /// H field at receiver locations
270
             std::vector<Vector3Xcr>     Hfield;
269
             std::vector<Vector3Xcr>     Hfield;
271
 
270
 
272
-
273
             /** ASCII string representation of the class name */
271
             /** ASCII string representation of the class name */
274
             static constexpr auto CName = "FieldPoints";
272
             static constexpr auto CName = "FieldPoints";
275
 
273
 

+ 3
- 4
Modules/FDEM1D/include/LayeredEarthEM.h View File

35
         /** Recursively streams information about this class */
35
         /** Recursively streams information about this class */
36
         friend std::ostream &operator<<(std::ostream &stream, const LayeredEarthEM &ob);
36
         friend std::ostream &operator<<(std::ostream &stream, const LayeredEarthEM &ob);
37
 
37
 
38
-
39
         struct ctor_key {};
38
         struct ctor_key {};
40
 
39
 
41
         public:
40
         public:
42
 
41
 
43
             // ====================  LIFECYCLE     ===========================
42
             // ====================  LIFECYCLE     ===========================
44
 
43
 
45
-            /** Default protected constructor. */
44
+            /** Default locked constructor. */
46
             explicit LayeredEarthEM ( const ctor_key& );
45
             explicit LayeredEarthEM ( const ctor_key& );
47
 
46
 
48
-            /** Default protected constructor. */
47
+            /** Locked deserializing constructor. */
49
 			LayeredEarthEM ( const YAML::Node& node, const ctor_key& );
48
 			LayeredEarthEM ( const YAML::Node& node, const ctor_key& );
50
 
49
 
51
-            /** Default protected constructor. */
50
+            /** Default destructor */
52
             virtual ~LayeredEarthEM ();
51
             virtual ~LayeredEarthEM ();
53
 
52
 
54
             /**
53
             /**

+ 1
- 1
Modules/FDEM1D/src/CMakeLists.txt View File

2
 	${FEM1DSOURCE}
2
 	${FEM1DSOURCE}
3
 	#${CMAKE_CURRENT_SOURCE_DIR}/AEMSurvey.cpp
3
 	#${CMAKE_CURRENT_SOURCE_DIR}/AEMSurvey.cpp
4
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthEM.cpp
4
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthEM.cpp
5
-	#${CMAKE_CURRENT_SOURCE_DIR}/FieldPoints.cpp
5
+	${CMAKE_CURRENT_SOURCE_DIR}/FieldPoints.cpp
6
 	#${CMAKE_CURRENT_SOURCE_DIR}/DipoleSource.cpp
6
 	#${CMAKE_CURRENT_SOURCE_DIR}/DipoleSource.cpp
7
 	#${CMAKE_CURRENT_SOURCE_DIR}/UngroundedElectricDipole.cpp
7
 	#${CMAKE_CURRENT_SOURCE_DIR}/UngroundedElectricDipole.cpp
8
 	PARENT_SCOPE
8
 	PARENT_SCOPE

+ 81
- 112
Modules/FDEM1D/src/FieldPoints.cpp View File

11
   @version  $Id: receiverpoints.cpp 203 2015-01-09 21:19:04Z tirons $
11
   @version  $Id: receiverpoints.cpp 203 2015-01-09 21:19:04Z tirons $
12
  **/
12
  **/
13
 
13
 
14
-#include "receiverpoints.h"
14
+#include "FieldPoints.h"
15
 
15
 
16
 namespace Lemma {
16
 namespace Lemma {
17
 
17
 
18
     // ====================    FRIENDS     ======================
18
     // ====================    FRIENDS     ======================
19
 
19
 
20
-#ifdef HAVE_YAMLCPP
21
-    std::ostream &operator << (std::ostream &stream, const ReceiverPoints &ob) {
22
-        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+    std::ostream &operator << (std::ostream &stream, const FieldPoints &ob) {
21
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
23
         return stream;
22
         return stream;
24
     }
23
     }
25
-#else
26
-    std::ostream &operator<<(std::ostream &stream,
27
-                const ReceiverPoints &ob) {
28
-
29
-        stream << *(LemmaObject*)(&ob);
30
-        stream << "Number of Receivers "<< ob.NumberOfReceivers  << "\n";
31
-        return stream;
32
-    }
33
-#endif
34
 
24
 
35
     // ====================  LIFECYCLE     ===================================
25
     // ====================  LIFECYCLE     ===================================
36
 
26
 
37
-    ReceiverPoints::ReceiverPoints(const std::string& name) :
38
-        LemmaObject(name),
39
-        NumberOfReceivers(0), NumberOfBinsE(0), NumberOfBinsH(0) {
27
+    FieldPoints::FieldPoints( const ctor_key& ) : LemmaObject( ),
28
+        NumberOfPoints(0), NumberOfBinsE(0), NumberOfBinsH(0) {
40
     }
29
     }
41
 
30
 
42
-#ifdef HAVE_YAMLCPP
43
     //--------------------------------------------------------------------------------------
31
     //--------------------------------------------------------------------------------------
44
-    //       Class:  ReceiverPoints
45
-    //      Method:  ReceiverPoints
32
+    //       Class:  FieldPoints
33
+    //      Method:  FieldPoints
46
     // Description:  constructor (protected)
34
     // Description:  constructor (protected)
47
     //--------------------------------------------------------------------------------------
35
     //--------------------------------------------------------------------------------------
48
-    ReceiverPoints::ReceiverPoints (const YAML::Node& node) : LemmaObject(node) {
49
-
36
+    FieldPoints::FieldPoints (const YAML::Node& node, const ctor_key&) : LemmaObject(node) {
50
         //DeSerialize
37
         //DeSerialize
51
-        NumberOfReceivers = node["NumberOfReceivers"].as<int>();
38
+        NumberOfPoints = node["NumberOfPoints"].as<int>();
52
         NumberOfBinsE = node["NumberOfBinsE"].as<int>();
39
         NumberOfBinsE = node["NumberOfBinsE"].as<int>();
53
         NumberOfBinsH = node["NumberOfBinsH"].as<int>();
40
         NumberOfBinsH = node["NumberOfBinsH"].as<int>();
54
         Mask = node["Mask"].as<VectorXi>();
41
         Mask = node["Mask"].as<VectorXi>();
55
         Locations = node["Locations"].as<Vector3Xr>();
42
         Locations = node["Locations"].as<Vector3Xr>();
43
+    }  // -----  end of method FieldPoints::FieldPoints  (constructor)  -----
56
 
44
 
57
-    }  // -----  end of method ReceiverPoints::ReceiverPoints  (constructor)  -----
58
-#endif
59
-
60
-    ReceiverPoints::~ReceiverPoints() {
61
-        if (this->NumberOfReferences != 0)
62
-            throw DeleteObjectWithReferences( this );
45
+    FieldPoints::~FieldPoints() {
63
     }
46
     }
64
 
47
 
65
-    ReceiverPoints* ReceiverPoints::New() {
66
-        ReceiverPoints* Obj = new ReceiverPoints("ReceiverPoints");
67
-        Obj->AttachTo(Obj);
68
-        return Obj;
48
+    std::shared_ptr<FieldPoints> FieldPoints::NewSP() {
49
+        return std::make_shared<FieldPoints> ( ctor_key() );
69
     }
50
     }
70
 
51
 
71
-    void ReceiverPoints::Delete() {
72
-        this->DetachFrom(this);
73
-    }
52
+    //--------------------------------------------------------------------------------------
53
+    //       Class:  FieldPoints
54
+    //      Method:  Serialize
55
+    //--------------------------------------------------------------------------------------
56
+    YAML::Node  FieldPoints::Serialize (  ) const {
57
+        YAML::Node node = LemmaObject::Serialize();
58
+        node.SetTag( GetName() );
74
 
59
 
75
-    void ReceiverPoints::Release() {
76
-        delete this;
77
-    }
60
+        // update here
61
+        node["NumberOfPoints"] = NumberOfPoints;
62
+        node["NumberOfBinsE"] = NumberOfBinsE;
63
+        node["NumberOfBinsH"] = NumberOfBinsH;
64
+        node["Mask"] = Mask;
65
+        node["Locations"] = Locations;// Can be huge
66
+        //std::cout << "Locations.data" << Locations.data()[0] << std::endl;
67
+        return node;
68
+    }		// -----  end of method FieldPoints::Serialize  -----
69
+
70
+
71
+    //--------------------------------------------------------------------------------------
72
+    //       Class:  FieldPoints
73
+    //      Method:  DeSerialize
74
+    //--------------------------------------------------------------------------------------
75
+    std::shared_ptr<FieldPoints> FieldPoints::DeSerialize ( const YAML::Node& node  ) {
76
+        if (node.Tag() != "FieldPoints") {
77
+            throw  DeSerializeTypeMismatch( "FieldPoints", node.Tag());
78
+        }
79
+        return std::make_shared<FieldPoints> ( node, ctor_key() );
80
+    }		// -----  end of method FieldPoints::DeSerialize  -----
78
 
81
 
79
     // ====================  ACCESS        ===================================
82
     // ====================  ACCESS        ===================================
80
 
83
 
81
-    void ReceiverPoints::SetNumberOfReceivers(const int &nrec) {
84
+    void FieldPoints::SetNumberOfPoints(const int &nrec) {
82
 
85
 
83
         if (nrec > 0)
86
         if (nrec > 0)
84
-            this->NumberOfReceivers = nrec;
87
+            this->NumberOfPoints = nrec;
85
         else
88
         else
86
             throw std::runtime_error("NUMBER RECEIVERS LESS THAN 1");
89
             throw std::runtime_error("NUMBER RECEIVERS LESS THAN 1");
87
 
90
 
95
         ResizeHField();
98
         ResizeHField();
96
     }
99
     }
97
 
100
 
98
-    void ReceiverPoints::ResizeEField() {
101
+    void FieldPoints::ResizeEField() {
99
         Efield.clear();
102
         Efield.clear();
100
         for (int i=0; i<NumberOfBinsE; ++i) {
103
         for (int i=0; i<NumberOfBinsE; ++i) {
101
             Eigen::Matrix<Complex, 3, Eigen::Dynamic> tempe;
104
             Eigen::Matrix<Complex, 3, Eigen::Dynamic> tempe;
102
             this->Efield.push_back(tempe);
105
             this->Efield.push_back(tempe);
103
-            this->Efield[i].resize(Eigen::NoChange, NumberOfReceivers);
106
+            this->Efield[i].resize(Eigen::NoChange, NumberOfPoints);
104
             this->Efield[i].setZero();
107
             this->Efield[i].setZero();
105
         }
108
         }
106
     }
109
     }
107
 
110
 
108
-    void ReceiverPoints::ResizeHField() {
111
+    void FieldPoints::ResizeHField() {
109
         Hfield.clear();
112
         Hfield.clear();
110
         for (int i=0; i<NumberOfBinsH; ++i) {
113
         for (int i=0; i<NumberOfBinsH; ++i) {
111
             Eigen::Matrix<Complex, 3, Eigen::Dynamic> temph;
114
             Eigen::Matrix<Complex, 3, Eigen::Dynamic> temph;
112
             this->Hfield.push_back(temph);
115
             this->Hfield.push_back(temph);
113
-            this->Hfield[i].resize(Eigen::NoChange, NumberOfReceivers);
116
+            this->Hfield[i].resize(Eigen::NoChange, NumberOfPoints);
114
             this->Hfield[i].setZero();
117
             this->Hfield[i].setZero();
115
         }
118
         }
116
     }
119
     }
117
 
120
 
118
-    void ReceiverPoints::SetNumberOfBinsE(const int& nbins) {
121
+    void FieldPoints::SetNumberOfBinsE(const int& nbins) {
119
         NumberOfBinsE = nbins;
122
         NumberOfBinsE = nbins;
120
         ResizeEField();
123
         ResizeEField();
121
     }
124
     }
122
 
125
 
123
-    void ReceiverPoints::SetNumberOfBinsH(const int& nbins) {
126
+    void FieldPoints::SetNumberOfBinsH(const int& nbins) {
124
         NumberOfBinsH = nbins;
127
         NumberOfBinsH = nbins;
125
         ResizeHField();
128
         ResizeHField();
126
     }
129
     }
127
 
130
 
128
-    void ReceiverPoints::SetLocation(const int&nrec,const  Vector3r& loc) {
131
+    void FieldPoints::SetLocation(const int&nrec,const  Vector3r& loc) {
129
         this->Locations.col(nrec) = loc;
132
         this->Locations.col(nrec) = loc;
130
     }
133
     }
131
 
134
 
132
-    void ReceiverPoints::SetLocation(const int&nrec,const  Real& xp,
135
+    void FieldPoints::SetLocation(const int&nrec,const  Real& xp,
133
                     const Real& yp, const Real& zp) {
136
                     const Real& yp, const Real& zp) {
134
         this->Locations.col(nrec) << xp, yp, zp;
137
         this->Locations.col(nrec) << xp, yp, zp;
135
     }
138
     }
136
 
139
 
137
-    void ReceiverPoints::SetEfield(const int& nbin,
140
+    void FieldPoints::SetEfield(const int& nbin,
138
                     const int& loc, const Complex &ex,
141
                     const int& loc, const Complex &ex,
139
                     const Complex &ey, const Complex &ez) {
142
                     const Complex &ey, const Complex &ez) {
140
         this->Efield[nbin].col(loc) << ex, ey, ez;
143
         this->Efield[nbin].col(loc) << ex, ey, ez;
141
     }
144
     }
142
 
145
 
143
-    void ReceiverPoints::AppendEfield(const int&nbin, const int& loc,
146
+    void FieldPoints::AppendEfield(const int&nbin, const int& loc,
144
                     const Complex &ex,
147
                     const Complex &ex,
145
                     const Complex &ey, const Complex &ez) {
148
                     const Complex &ey, const Complex &ez) {
146
         #ifdef LEMMAUSEOMP
149
         #ifdef LEMMAUSEOMP
149
         this->Efield[nbin].col(loc) += Vector3cr(ex, ey, ez); //temp;
152
         this->Efield[nbin].col(loc) += Vector3cr(ex, ey, ez); //temp;
150
     }
153
     }
151
 
154
 
152
-    void ReceiverPoints::SetHfield(const int &nbin, const int& loc,
155
+    void FieldPoints::SetHfield(const int &nbin, const int& loc,
153
                     const Complex &hx, const Complex &hy,
156
                     const Complex &hx, const Complex &hy,
154
                     const Complex &hz) {
157
                     const Complex &hz) {
155
         this->Hfield[nbin].col(loc) << hx, hy, hz;
158
         this->Hfield[nbin].col(loc) << hx, hy, hz;
156
     }
159
     }
157
 
160
 
158
-    void ReceiverPoints::AppendHfield(const int &nbin, const int& loc,
161
+    void FieldPoints::AppendHfield(const int &nbin, const int& loc,
159
                     const Complex &hx, const Complex &hy,
162
                     const Complex &hx, const Complex &hy,
160
                     const Complex &hz) {
163
                     const Complex &hz) {
161
 //      #ifdef LEMMAUSEOMP
164
 //      #ifdef LEMMAUSEOMP
182
 
185
 
183
 
186
 
184
     // ====================  INQUIRY       ===================================
187
     // ====================  INQUIRY       ===================================
185
-    Vector3Xr ReceiverPoints::GetLocations() {
188
+    Vector3Xr FieldPoints::GetLocations() {
186
         return this->Locations;
189
         return this->Locations;
187
     }
190
     }
188
 
191
 
189
-    MatrixXr ReceiverPoints::GetLocationsMat() {
192
+    MatrixXr FieldPoints::GetLocationsMat() {
190
         return MatrixXr(this->Locations);
193
         return MatrixXr(this->Locations);
191
     }
194
     }
192
 
195
 
193
-    Vector3r ReceiverPoints::GetLocation(const int &nrec) {
196
+    Vector3r FieldPoints::GetLocation(const int &nrec) {
194
         return this->Locations.col(nrec);
197
         return this->Locations.col(nrec);
195
     }
198
     }
196
 
199
 
197
-    Real ReceiverPoints::GetLocationX(const int &nrec) {
200
+    Real FieldPoints::GetLocationX(const int &nrec) {
198
         return this->Locations.col(nrec)[0];
201
         return this->Locations.col(nrec)[0];
199
     }
202
     }
200
 
203
 
201
-    Real ReceiverPoints::GetLocationY(const int &nrec) {
204
+    Real FieldPoints::GetLocationY(const int &nrec) {
202
         return this->Locations.col(nrec)[1];
205
         return this->Locations.col(nrec)[1];
203
     }
206
     }
204
 
207
 
205
-    Real ReceiverPoints::GetLocationZ(const int &nrec) {
208
+    Real FieldPoints::GetLocationZ(const int &nrec) {
206
         return this->Locations.col(nrec)[2];
209
         return this->Locations.col(nrec)[2];
207
     }
210
     }
208
 
211
 
209
-    Vector3cr ReceiverPoints::GetEfield(const int &nfreq, const int&nrec) {
212
+    Vector3cr FieldPoints::GetEfield(const int &nfreq, const int&nrec) {
210
         return this->Efield[nfreq].col(nrec);
213
         return this->Efield[nfreq].col(nrec);
211
     }
214
     }
212
 
215
 
213
-    Vector3cr ReceiverPoints::GetHfield(const int &nfreq, const int&nrec) {
216
+    Vector3cr FieldPoints::GetHfield(const int &nfreq, const int&nrec) {
214
         return this->Hfield[nfreq].col(nrec);
217
         return this->Hfield[nfreq].col(nrec);
215
     }
218
     }
216
 
219
 
217
-    std::vector<Vector3Xcr> ReceiverPoints::GetHfield( ) {
220
+    std::vector<Vector3Xcr> FieldPoints::GetHfield( ) {
218
         return this->Hfield;
221
         return this->Hfield;
219
     }
222
     }
220
 
223
 
221
-    std::vector<Vector3Xcr> ReceiverPoints::GetEfield( ) {
224
+    std::vector<Vector3Xcr> FieldPoints::GetEfield( ) {
222
         return this->Efield;
225
         return this->Efield;
223
     }
226
     }
224
 
227
 
225
-    Vector3Xcr ReceiverPoints::GetEfield (const int &nfreq) {
228
+    Vector3Xcr FieldPoints::GetEfield (const int &nfreq) {
226
         return this->Efield[nfreq];
229
         return this->Efield[nfreq];
227
     }
230
     }
228
 
231
 
229
-    MatrixXcr ReceiverPoints::GetEfieldMat (const int &nfreq) {
232
+    MatrixXcr FieldPoints::GetEfieldMat (const int &nfreq) {
230
         return MatrixXcr(this->Efield[nfreq]);
233
         return MatrixXcr(this->Efield[nfreq]);
231
     }
234
     }
232
 
235
 
233
-    MatrixXcr ReceiverPoints::GetHfieldMat (const int &nfreq) {
236
+    MatrixXcr FieldPoints::GetHfieldMat (const int &nfreq) {
234
         return MatrixXcr(this->Hfield[nfreq]);
237
         return MatrixXcr(this->Hfield[nfreq]);
235
     }
238
     }
236
 
239
 
237
-    Vector3Xcr ReceiverPoints::GetHfield (const int &nfreq) {
240
+    Vector3Xcr FieldPoints::GetHfield (const int &nfreq) {
238
         return this->Hfield[nfreq];
241
         return this->Hfield[nfreq];
239
     }
242
     }
240
 
243
 
241
-    void ReceiverPoints::MaskPoint(const int& imask) {
244
+    void FieldPoints::MaskPoint(const int& imask) {
242
         Mask(imask) = true;
245
         Mask(imask) = true;
243
     }
246
     }
244
 
247
 
245
-    void ReceiverPoints::UnMaskPoint(const int& imask) {
248
+    void FieldPoints::UnMaskPoint(const int& imask) {
246
         Mask(imask) = false;
249
         Mask(imask) = false;
247
     }
250
     }
248
 
251
 
249
-    void ReceiverPoints::UnMaskAllPoints() {
252
+    void FieldPoints::UnMaskAllPoints() {
250
         Mask.setZero();
253
         Mask.setZero();
251
     }
254
     }
252
 
255
 
253
-    int ReceiverPoints::GetMask(const int& i) {
256
+    int FieldPoints::GetMask(const int& i) {
254
         return Mask(i);
257
         return Mask(i);
255
     }
258
     }
256
 
259
 
257
-    int ReceiverPoints::GetNumberOfReceivers() {
258
-        return this->NumberOfReceivers;
260
+    int FieldPoints::GetNumberOfPoints() {
261
+        return this->NumberOfPoints;
259
     }
262
     }
260
 
263
 
261
-    void ReceiverPoints::ClearFields() {
264
+    void FieldPoints::ClearFields() {
262
         for (int i=0; i<NumberOfBinsE; ++i) {
265
         for (int i=0; i<NumberOfBinsE; ++i) {
263
             this->Efield[i].setZero();
266
             this->Efield[i].setZero();
264
         }
267
         }
267
         }
270
         }
268
     }
271
     }
269
 
272
 
270
-
271
-#ifdef HAVE_YAMLCPP
272
-    //--------------------------------------------------------------------------------------
273
-    //       Class:  ReceiverPoints
274
-    //      Method:  Serialize
275
-    //--------------------------------------------------------------------------------------
276
-    YAML::Node  ReceiverPoints::Serialize (  ) const {
277
-        YAML::Node node = LemmaObject::Serialize(); //static_cast<const LemmaObject*>(this)->Serialize();
278
-        node.SetTag( this->Name ); // Set Tag after doing parents
279
-
280
-        // update here
281
-        node["NumberOfReceivers"] = NumberOfReceivers;
282
-        node["NumberOfBinsE"] = NumberOfBinsE;
283
-        node["NumberOfBinsH"] = NumberOfBinsH;
284
-        //node["Mask"] = Mask;
285
-        //std::cout << "Locations.data" << Locations.data()[0] << std::endl;
286
-        // node["Locations"] = Locations.data(); // HUGE
287
-        return node;
288
-    }		// -----  end of method ReceiverPoints::Serialize  -----
289
-
290
-
291
-    //--------------------------------------------------------------------------------------
292
-    //       Class:  ReceiverPoints
293
-    //      Method:  DeSerialize
294
-    //--------------------------------------------------------------------------------------
295
-    ReceiverPoints* ReceiverPoints::DeSerialize ( const YAML::Node& node  ) {
296
-        ReceiverPoints* Object = new ReceiverPoints(node);
297
-        Object->AttachTo(Object);
298
-        DESERIALIZECHECK( node, Object )
299
-        return Object ;
300
-    }		// -----  end of method ReceiverPoints::DeSerialize  -----
301
-#endif
302
-
303
-
304
     #ifdef LEMMAUSEVTK
273
     #ifdef LEMMAUSEVTK
305
-    vtkActor* ReceiverPoints::GetVtkGlyphActor(const FIELDTYPE &ftype,
274
+    vtkActor* FieldPoints::GetVtkGlyphActor(const FIELDTYPE &ftype,
306
                     const Real &clip, const Real &scale,
275
                     const Real &clip, const Real &scale,
307
                     const int &nfreq) {
276
                     const int &nfreq) {
308
 
277
 
325
         vVects->SetNumberOfComponents(3);
294
         vVects->SetNumberOfComponents(3);
326
 
295
 
327
         // Make PointData
296
         // Make PointData
328
-        for (int ic=0; ic<NumberOfReceivers; ++ic) {
297
+        for (int ic=0; ic<NumberOfPoints; ++ic) {
329
 
298
 
330
             Vector3r loc = this->GetLocation(ic);
299
             Vector3r loc = this->GetLocation(ic);
331
 
300
 
401
         return vActor;
370
         return vActor;
402
     }
371
     }
403
 
372
 
404
-    vtkDataObject* ReceiverPoints::GetVtkDataObject(const FIELDTYPE &ftype,
373
+    vtkDataObject* FieldPoints::GetVtkDataObject(const FIELDTYPE &ftype,
405
                     const int& nbin,
374
                     const int& nbin,
406
                     const int& start, const int& end,
375
                     const int& start, const int& end,
407
                     const FIELDCOMPONENT& fcomp,
376
                     const FIELDCOMPONENT& fcomp,
408
                     const SPATIALCOORDINANT &scord) {
377
                     const SPATIALCOORDINANT &scord) {
409
 
378
 
410
         if (start < 0) throw 77;
379
         if (start < 0) throw 77;
411
-        if (end > NumberOfReceivers) throw 78;
380
+        if (end > NumberOfPoints) throw 78;
412
         if (start > end) throw 79;
381
         if (start > end) throw 79;
413
 
382
 
414
         int ifc(-1);
383
         int ifc(-1);
487
         return _dataObject;
456
         return _dataObject;
488
     }
457
     }
489
 
458
 
490
-    vtkDataObject* ReceiverPoints::GetVtkDataObjectFreq(const FIELDTYPE &ftype,
459
+    vtkDataObject* FieldPoints::GetVtkDataObjectFreq(const FIELDTYPE &ftype,
491
                     const int& nrec,
460
                     const int& nrec,
492
                     const int& fstart, const int& fend,
461
                     const int& fstart, const int& fend,
493
                     const FIELDCOMPONENT& fcomp,
462
                     const FIELDCOMPONENT& fcomp,

+ 6
- 0
Modules/FDEM1D/testing/GetNameCheck.h View File

33
         TS_ASSERT_EQUALS( Obj->GetName(), std::string("LayeredEarthEM") );
33
         TS_ASSERT_EQUALS( Obj->GetName(), std::string("LayeredEarthEM") );
34
     }
34
     }
35
 
35
 
36
+    void testFieldPoints( void )
37
+    {
38
+        auto Obj = FieldPoints::NewSP();
39
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("FieldPoints") );
40
+    }
41
+
36
 };
42
 };
37
 
43
 

+ 38
- 5
Modules/FDEM1D/testing/SerializeCheck.h View File

20
 #include <cxxtest/TestSuite.h>
20
 #include <cxxtest/TestSuite.h>
21
 #include <FDEM1D>
21
 #include <FDEM1D>
22
 #include <random>
22
 #include <random>
23
-
23
+#define EPSILON 1e-10
24
 using namespace Lemma;
24
 using namespace Lemma;
25
 
25
 
26
 class MyTestSuite : public CxxTest::TestSuite
26
 class MyTestSuite : public CxxTest::TestSuite
33
         std::mt19937 gen(rd());
33
         std::mt19937 gen(rd());
34
 
34
 
35
         // up to 11 layers
35
         // up to 11 layers
36
-        std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
36
+        std::discrete_distribution<> d({0,0,0,0,10,10,10,10,10,10,10,10,10,10});
37
         int nl = d(gen);
37
         int nl = d(gen);
38
 
38
 
39
         // for Reals
39
         // for Reals
40
-        std::uniform_real_distribution<> dis(1e-2, 1);
40
+        std::uniform_real_distribution<> dis(1e-1, 1);
41
 
41
 
42
         // conductivity
42
         // conductivity
43
         VectorXcr con = VectorXcr(nl);
43
         VectorXcr con = VectorXcr(nl);
63
 
63
 
64
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
64
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
65
         TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
65
         TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
66
-        TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerConductivity() - Obj2->GetLayerConductivity()).array().sum()), 1e-16 );
67
-        TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerThickness() - Obj2->GetLayerThickness()).array().sum()), 1e-16 );
66
+        for (int ilay=0; ilay<nl; ++ilay) {
67
+            TS_ASSERT_DELTA( std::real(Obj->GetLayerConductivity(ilay)), std::real(Obj2->GetLayerConductivity(ilay)), EPSILON );
68
+        }
69
+        for (int ilay=1; ilay<nl-1; ++ilay) {
70
+            TS_ASSERT_DELTA( Obj->GetLayerThickness(ilay), Obj2->GetLayerThickness(ilay), EPSILON );
71
+        }
68
     }
72
     }
69
 
73
 
74
+    void testFieldPoints(void)
75
+    {
76
+        std::random_device rd;
77
+        std::mt19937 gen(rd());
78
+
79
+        // up to 11 layers
80
+        std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
81
+        std::uniform_real_distribution<> dis(1e-1, 10);
82
+
83
+        int np = d(gen);
84
+        auto Obj = FieldPoints::NewSP();
85
+            Obj->SetNumberOfPoints(np);
86
+
87
+            for (int ip=0; ip<np; ++ip) {
88
+                Obj->SetLocation( ip, dis(gen), dis(gen), dis(gen) );
89
+            }
90
+
91
+        YAML::Node node = Obj->Serialize();
92
+        auto Obj2 = FieldPoints::DeSerialize(node);
93
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
94
+        for (int ip=0; ip<np; ++ip) {
95
+            TS_ASSERT_DELTA( Obj->GetLocationX(ip), Obj2->GetLocationX(ip), EPSILON );
96
+            TS_ASSERT_DELTA( Obj->GetLocationY(ip), Obj2->GetLocationY(ip), EPSILON );
97
+            TS_ASSERT_DELTA( Obj->GetLocationZ(ip), Obj2->GetLocationZ(ip), EPSILON );
98
+            TS_ASSERT_EQUALS( Obj->GetLocationX(ip), Obj->GetLocation(ip)(0) );
99
+            TS_ASSERT_EQUALS( Obj->GetLocationY(ip), Obj->GetLocation(ip)(1) );
100
+            TS_ASSERT_EQUALS( Obj->GetLocationZ(ip), Obj->GetLocation(ip)(2) );
101
+        }
102
+    }
70
 };
103
 };
71
 
104
 

+ 2
- 0
Modules/LemmaCore/include/LemmaObject.h View File

62
          *        all external classes that might need to be serialized.
62
          *        all external classes that might need to be serialized.
63
          */
63
          */
64
         virtual YAML::Node Serialize() const {
64
         virtual YAML::Node Serialize() const {
65
+            std::cout.precision( 21 );
65
             YAML::Node node = YAML::Node();
66
             YAML::Node node = YAML::Node();
66
             node.SetTag( GetName() );
67
             node.SetTag( GetName() );
67
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
68
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
68
             node["Serialized"] = std::ctime(&now);
69
             node["Serialized"] = std::ctime(&now);
70
+            node["Lemma_VERSION"] = LEMMA_VERSION;
69
             return node;
71
             return node;
70
         };
72
         };
71
 
73
 

+ 2
- 0
Modules/LemmaCore/include/lemma.h View File

165
 #ifndef __LEMMA_H
165
 #ifndef __LEMMA_H
166
 #define __LEMMA_H
166
 #define __LEMMA_H
167
 
167
 
168
+    #include <LemmaConfig.h>
169
+
168
     // Include some basic stuff that will always be needed
170
     // Include some basic stuff that will always be needed
169
     #include <iostream>
171
     #include <iostream>
170
     #include <iomanip>
172
     #include <iomanip>

+ 1
- 1
config/LemmaConfig.h.in View File

20
 #define LEMMA_VERSION_MAJOR @LEMMA_VERSION_MAJOR@
20
 #define LEMMA_VERSION_MAJOR @LEMMA_VERSION_MAJOR@
21
 #define LEMMA_VERSION_MINOR @LEMMA_VERSION_MINOR@
21
 #define LEMMA_VERSION_MINOR @LEMMA_VERSION_MINOR@
22
 #define LEMMA_VERSION_PATCH @LEMMA_VERSION_PATCH@
22
 #define LEMMA_VERSION_PATCH @LEMMA_VERSION_PATCH@
23
-//#define LEMMA_VERSION @LEMMA_VERSION@
23
+#define LEMMA_VERSION @LEMMA_VERSION@

+ 1
- 1
vim/c.vim View File

17
 
17
 
18
 " Lemma types
18
 " Lemma types
19
 highlight leType ctermfg=Yellow guifg=Yellow
19
 highlight leType ctermfg=Yellow guifg=Yellow
20
-syn keyword leType HankelTransform KernelEm1D KernelEM1DManager DipoleSource EarthModel LayeredEarth LayeredEarthEM TEMSurvey TEMSurveyLine TEMSurveyLineRecord TEMInductiveReceiver PolygonalWireAntenna TEMTransmitter TEMReceiver Instrument InstrumentTem LemmaObject ReceiverPoints DCIPElectrode TEMSurveyData TEMSurveyLineData TEMSurveyLineRecordData  ASCIIParser CubicSplineInterpolator RectilinearGrid GridReader RectilinearGridReader RectilinearGridVTKExporter Filter WindowFilter DEMParticle DEMGrain Data DataReader
20
+syn keyword leType HankelTransform KernelEm1D KernelEM1DManager DipoleSource EarthModel LayeredEarth LayeredEarthEM TEMSurvey TEMSurveyLine TEMSurveyLineRecord TEMInductiveReceiver PolygonalWireAntenna TEMTransmitter TEMReceiver Instrument InstrumentTem LemmaObject FieldPoints DCIPElectrode TEMSurveyData TEMSurveyLineData TEMSurveyLineRecordData  ASCIIParser CubicSplineInterpolator RectilinearGrid GridReader RectilinearGridReader RectilinearGridVTKExporter Filter WindowFilter DEMParticle DEMGrain Data DataReader 
21
 
21
 
22
 " Deprecated Lemma Types
22
 " Deprecated Lemma Types
23
 highlight dleType ctermfg=Blue guifg=Blue 
23
 highlight dleType ctermfg=Blue guifg=Blue 

Loading…
Cancel
Save