Browse Source

Cleaning up Doxygen warnings, and added DCIP Module

add-code-of-conduct-1
Trevor Irons 6 years ago
parent
commit
6b77a42717
53 changed files with 225 additions and 7421 deletions
  1. 50
    0
      Modules/DCIP/CMakeLists.txt
  2. 8
    16
      Modules/DCIP/config/DCIPConfig.h.in
  3. 33
    37
      Modules/DCIP/include/DCIPElectrode.h
  4. 43
    51
      Modules/DCIP/include/DCSurvey.h
  5. 7
    0
      Modules/DCIP/src/CMakeLists.txt
  6. 16
    48
      Modules/DCIP/src/DCIPElectrode.cpp
  7. 30
    73
      Modules/DCIP/src/DCSurvey.cpp
  8. 2
    2
      Modules/FDEM1D/include/FHTKey101.h
  9. 0
    88
      Modules/FDEM1D/include/GroundedElectricDipole.h
  10. 0
    1
      Modules/FDEM1D/include/KernelEM1DBase.h
  11. 0
    1
      Modules/FDEM1D/include/KernelEM1DManager.h
  12. 0
    1
      Modules/FDEM1D/include/KernelEM1DReflBase.h
  13. 0
    1
      Modules/FDEM1D/include/KernelEM1DReflSpec.h
  14. 0
    1
      Modules/FDEM1D/include/KernelEM1DSpec.h
  15. 0
    1
      Modules/FDEM1D/include/MagneticDipole.h
  16. 0
    1
      Modules/FDEM1D/include/digitalfilterintegrator.h
  17. 0
    1
      Modules/FDEM1D/include/integrationkernel.h
  18. 0
    1
      Modules/FDEM1D/include/inversesolver.h
  19. 0
    1
      Modules/FDEM1D/include/sintransintegrationkernel.h
  20. 0
    85
      Modules/FDEM1D/src/GroundedElectricDipole.cpp
  21. 0
    342
      Modules/LemmaCore/examples/utORS.cpp
  22. 0
    34
      Modules/LemmaCore/examples/utQWEKey.cpp
  23. 0
    86
      Modules/LemmaCore/examples/utSerialize.cpp
  24. 0
    197
      Modules/LemmaCore/examples/utTEMSurvey.cpp
  25. 0
    168
      Modules/LemmaCore/examples/utXMLParse.cpp
  26. 0
    67
      Modules/LemmaCore/examples/utYAMLconfig.cpp
  27. 0
    84
      Modules/LemmaCore/examples/utgaussquad.cpp
  28. 0
    258
      Modules/LemmaCore/examples/utgmrprint.cpp
  29. 0
    93
      Modules/LemmaCore/examples/uthankel2.cpp
  30. 0
    257
      Modules/LemmaCore/examples/uthantenna.cpp
  31. 0
    218
      Modules/LemmaCore/examples/utlogbarriercg.cpp
  32. 0
    67
      Modules/LemmaCore/examples/utpolygonalantenna.cpp
  33. 0
    68
      Modules/LemmaCore/examples/utreadfemubc.cpp
  34. 0
    54
      Modules/LemmaCore/examples/utsandbox.cpp
  35. 0
    199
      Modules/LemmaCore/examples/uttemforward.cpp
  36. 0
    131
      Modules/LemmaCore/examples/utteminv1d.cpp
  37. 0
    84
      Modules/LemmaCore/examples/uttemreader.cpp
  38. 0
    207
      Modules/LemmaCore/examples/uttemsandbox.cpp
  39. 0
    319
      Modules/LemmaCore/examples/wireantenna.cpp
  40. 5
    1
      Modules/LemmaCore/include/CubicSplineInterpolator.h
  41. 28
    20
      Modules/LemmaCore/include/EarthModel.h
  42. 0
    1
      Modules/LemmaCore/include/Filter.h
  43. 0
    1
      Modules/LemmaCore/include/GridReader.h
  44. 0
    1
      Modules/LemmaCore/include/RectilinearGridReader.h
  45. 0
    1
      Modules/LemmaCore/include/WindowFilter.h
  46. 3
    0
      Modules/LemmaCore/include/helper.h
  47. 0
    0
      Modules/Optimization/CMakeLists.txt
  48. 0
    98
      Modules/Optimization/include/bicgstab.h
  49. 0
    437
      Modules/Optimization/include/cg.h
  50. 0
    1366
      Modules/Optimization/include/logbarriercg.h
  51. 0
    1956
      Modules/Optimization/include/logbarriercg_newton.h
  52. 0
    111
      Modules/Optimization/include/quasinewtonbfgs.h
  53. 0
    85
      Modules/Optimization/src/quasinewtonbfgs.cpp

+ 50
- 0
Modules/DCIP/CMakeLists.txt View File

1
+# Configure EMSchur3D 
2
+set(DCIP_VERSION_MAJOR "0")
3
+set(DCIP_VERSION_MINOR "0")
4
+set(DCIP_VERSION_PATCH "1")
5
+set(DCIP_VERSION "\"${DCIP_VERSION_MAJOR}.${DCIP_VERSION_MINOR}.${DCIP_VERSION_PATCH}\"")
6
+set(DCIP_VERSION_NOQUOTES "${DCIP_VERSION_MAJOR}.${DCIP_VERSION_MINOR}.${DCIP_VERSION_PATCH}")
7
+
8
+option ( LEMMA_MODULE_DCIP TRUE )
9
+
10
+configure_file (
11
+	"${CMAKE_CURRENT_SOURCE_DIR}/config/DCIPConfig.h.in"
12
+	"${PROJECT_BINARY_DIR}/include/DCIPConfig.h"
13
+	)
14
+install ( FILES  ${PROJECT_BINARY_DIR}/include/EMSchur3DConfig.h   DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/ )
15
+
16
+	add_subdirectory("src")
17
+	add_library( dcip ${DCIPSOURCE} )  
18
+	target_include_directories( dcip PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
19
+
20
+	set_target_properties(dcip PROPERTIES 
21
+		VERSION  "${DCIP_VERSION_NOQUOTES}"
22
+		SOVERSION "${DCIP_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}"
23
+		PROJECT_LABEL "DCIP ${LABEL_SUFFIX}"
24
+    	CXX_STANDARD_14
25
+    	CXX_STANDARD_REQUIRED_ON
26
+	)
27
+
28
+	# Linking
29
+	target_link_libraries(dcip "lemmacore" "fdem1d" )
30
+
31
+	# Linking
32
+	target_link_libraries(dcip ${VTK_LIBRARIES})
33
+
34
+	# Testing
35
+	#if (LEMMA_ENABLE_TESTING)
36
+	#	add_subdirectory(testing)
37
+	#endif()
38
+
39
+	# Install
40
+	install ( TARGETS dcip DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
41
+	install ( FILES include/EMSchur3D  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 
42
+	install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma  FILES_MATCHING PATTERN "*.h")
43
+
44
+	#install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/  FILES_MATCHING PATTERN "FDEM1D")
45
+	#install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/FDEM1D  FILES_MATCHING PATTERN "*.h")
46
+
47
+	# Examples
48
+	#if (LEMMA_BUILD_EXAMPLES)
49
+	#	add_subdirectory(examples)
50
+	#endif()

Modules/LemmaCore/examples/utSkyTEM.cpp → Modules/DCIP/config/DCIPConfig.h.in View File

9
 
9
 
10
 /**
10
 /**
11
  * @file
11
  * @file
12
- * @date      02/27/2015 11:02:43 AM
12
+ * @date      10/23/2018 01:57:40 PM
13
  * @version   $Id$
13
  * @version   $Id$
14
  * @author    Trevor Irons (ti)
14
  * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2015, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2015, Trevor Irons
15
+ * @email     Trevor.Irons@utah.edu
16
+ * @copyright Copyright (c) 2018, University of Utah
17
+ * @copyright Copyright (c) 2018, Lemma Software, LLC
18
  */
18
  */
19
 
19
 
20
-// SkyTEM forward modelling programme
21
-
22
-#include "TEMSurvey.h"
23
-
24
-int main() {
25
-
26
-    std::cout << "SkyTEM modelling\n";
27
-
28
-
29
-
30
-}
31
-
20
+#define DCIP_VERSION_MAJOR @DCIP_VERSION_MAJOR@
21
+#define DCIP_VERSION_MINOR @DCIP_VERSION_MINOR@
22
+#define DCIP_VERSION_PATCH @DCIP_VERSION_PATCH@
23
+#define DCIP_VERSION @DCIP_VERSION@

+ 33
- 37
Modules/DCIP/include/DCIPElectrode.h View File

26
 namespace Lemma {
26
 namespace Lemma {
27
 
27
 
28
     /**
28
     /**
29
-      \brief
30
-      \details
29
+      \brief    Describes the location of an electrode used in a DC/IP survey
30
+      \details  This class is used together with FEM4EllipticPDE to solve DC/IP
31
+                problems.
31
      */
32
      */
32
     class DCIPElectrode : public LemmaObject {
33
     class DCIPElectrode : public LemmaObject {
33
 
34
 
39
         // ====================  LIFECYCLE     =======================
40
         // ====================  LIFECYCLE     =======================
40
 
41
 
41
         /**
42
         /**
42
-         * @copybrief LemmaObject::New()
43
-         * @copydetails LemmaObject::New()
43
+         * \brief   Returns new shared pointer to DCIP object.
44
+         * \details Use this method, as the default constructor is locked.
44
          */
45
          */
45
-        static DCIPElectrode* New();
46
+        static std::shared_ptr<DCIPElectrode> NewSP();
46
 
47
 
47
         /**
48
         /**
48
-         *  @copybrief   LemmaObject::Delete()
49
-         *  @copydetails LemmaObject::Delete()
49
+         *  Uses YAML to serialize this object.
50
+         *  @return a YAML::Node
50
          */
51
          */
51
-        void Delete();
52
+        YAML::Node Serialize() const;
53
+
54
+        /**
55
+         *   Constructs an object from a YAML::Node.
56
+         */
57
+        static std::shared_ptr<DCIPElectrode> DeSerialize(const YAML::Node& node);
58
+
59
+        /** Default protected constructor, use New */
60
+        explicit DCIPElectrode (const ctor_key& key);
61
+
62
+        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
63
+        DCIPElectrode (const YAML::Node& node, const ctor_key& key);
64
+
65
+        /** Default protected destructor, use Delete */
66
+        virtual ~DCIPElectrode ();
52
 
67
 
53
         // ====================  OPERATORS     =======================
68
         // ====================  OPERATORS     =======================
54
 
69
 
72
         int GetNodeID() {return Node_ID;}
87
         int GetNodeID() {return Node_ID;}
73
         // ====================  INQUIRY       =======================
88
         // ====================  INQUIRY       =======================
74
 
89
 
75
-#ifdef HAVE_YAMLCPP
76
-        /**
77
-         *  Uses YAML to serialize this object.
78
-         *  @return a YAML::Node
79
-         */
80
-        YAML::Node Serialize() const;
81
-
82
-        /**
83
-         *   Constructs an object from a YAML::Node.
84
-         */
85
-        static DCIPElectrode* DeSerialize(const YAML::Node& node);
86
-#endif
90
+        /** Returns the name of the underlying class, similiar to Python's type */
91
+        virtual std::string GetName() const {
92
+            return this->CName;
93
+        }
87
 
94
 
88
         protected:
95
         protected:
89
 
96
 
90
         // ====================  LIFECYCLE     =======================
97
         // ====================  LIFECYCLE     =======================
91
 
98
 
92
-        /** Default protected constructor, use New */
93
-        DCIPElectrode (const std::string& name);
94
-
95
-#ifdef HAVE_YAMLCPP
96
-        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
97
-        DCIPElectrode (const YAML::Node& node);
98
-#endif
99
-
100
-        /** Default protected destructor, use Delete */
101
-        ~DCIPElectrode ();
102
-
103
-        /**
104
-         *  @copybrief   LemmaObject::Release()
105
-         *  @copydetails LemmaObject::Release()
106
-         */
107
-        void Release();
108
-
109
         private:
99
         private:
110
 
100
 
111
         // ====================  DATA MEMBERS  =========================
101
         // ====================  DATA MEMBERS  =========================
112
 
102
 
103
+        /** ASCII string representation of the class name */
104
+        static constexpr auto CName = "DCIPElectrode";
105
+
106
+        /** no copy */
107
+        DCIPElectrode ( const DCIPElectrode& ) = delete;
108
+
113
         /** The location of the electrode */
109
         /** The location of the electrode */
114
         Vector3r Location;
110
         Vector3r Location;
115
 
111
 

+ 43
- 51
Modules/DCIP/include/DCSurvey.h View File

10
 /**
10
 /**
11
  * @file
11
  * @file
12
  * @date      10/08/2014 01:51:50 PM
12
  * @date      10/08/2014 01:51:50 PM
13
- * @version   $Id$
14
  * @author    Trevor Irons (ti)
13
  * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
14
+ * @email     Trevor.Irons@lemmasoftware.org
15
+ * @copyright Copyright (c) 2014, 2018 Trevor Irons
18
  */
16
  */
19
 
17
 
20
 #ifndef  DCSURVEY
18
 #ifndef  DCSURVEY
23
 #include "LemmaObject.h"
21
 #include "LemmaObject.h"
24
 #include "DCIPElectrode.h"
22
 #include "DCIPElectrode.h"
25
 
23
 
26
-#ifdef HAVE_YAMLCPP
27
-#include "yaml-cpp/yaml.h"
28
-#endif
29
-
30
 #ifdef LEMMAUSEVTK
24
 #ifdef LEMMAUSEVTK
31
 #include <vtkDataSet.h>
25
 #include <vtkDataSet.h>
32
 #endif
26
 #endif
49
         // ====================  LIFECYCLE     =======================
43
         // ====================  LIFECYCLE     =======================
50
 
44
 
51
         /**
45
         /**
52
-         * @copybrief LemmaObject::New()
53
-         * @copydetails LemmaObject::New()
46
+         * \brief   Returns new shared pointer to DCIP object.
47
+         * \details Use this method, as the default constructor is locked.
54
          */
48
          */
55
-        static DCSurvey* New();
49
+        static std::shared_ptr<DCSurvey> NewSP();
56
 
50
 
57
         /**
51
         /**
58
-         *  @copybrief   LemmaObject::Delete()
59
-         *  @copydetails LemmaObject::Delete()
52
+         *  Uses YAML to serialize this object.
53
+         *  @return a YAML::Node
60
          */
54
          */
61
-        void Delete();
55
+        YAML::Node Serialize() const;
56
+
57
+        /**
58
+         *   Constructs an object from a YAML::Node.
59
+         */
60
+        static std::shared_ptr<DCSurvey> DeSerialize(const YAML::Node& node);
61
+
62
+        /** Default protected constructor, use New */
63
+        explicit DCSurvey (const ctor_key& key);
64
+
65
+        /** Default protected constructor, use New */
66
+        DCSurvey (const YAML::Node& node, const ctor_key& key);
67
+
68
+        /** Default protected destructor, use Delete */
69
+        virtual ~DCSurvey ();
62
 
70
 
63
         // ====================  OPERATORS     =======================
71
         // ====================  OPERATORS     =======================
64
 
72
 
75
          *   @param[in] label is an optional tag for electrode.
83
          *   @param[in] label is an optional tag for electrode.
76
          *   @param[in] nodeID is the optional node ID on a mesh
84
          *   @param[in] nodeID is the optional node ID on a mesh
77
          */
85
          */
78
-        int PoundElectrode( DCIPElectrode* Electrode, const std::string& label = "NULL", const int& nodeID=-1 );
86
+        int PoundElectrode( std::shared_ptr<DCIPElectrode> Electrode, const std::string& label = "NULL", const int& nodeID=-1 );
79
 
87
 
80
         /** Alternative Factory method of setting electrodes. IN this manner all memoy management
88
         /** Alternative Factory method of setting electrodes. IN this manner all memoy management
81
          *  is handled by DCSurvey.
89
          *  is handled by DCSurvey.
88
          *  @param[in] label is an optional label for electrode.
96
          *  @param[in] label is an optional label for electrode.
89
          *  @param[in] nodeID is the optional node ID on a mesh
97
          *  @param[in] nodeID is the optional node ID on a mesh
90
          */
98
          */
91
-        DCIPElectrode* PoundElectrode( const Vector3r& loc, const std::string& label = "NULL", const int& nodeID=-1  );
99
+        std::shared_ptr<DCIPElectrode> PoundElectrode( const Vector3r& loc, const std::string& label = "NULL", const int& nodeID=-1  );
92
 
100
 
93
 #ifdef LEMMAUSEVTK
101
 #ifdef LEMMAUSEVTK
94
-        DCIPElectrode* PoundElectrode( const int& nodeID, vtkDataSet* Mesh, const std::string& label = "NULL" );
102
+        std::shared_ptr<DCIPElectrode> PoundElectrode( const int& nodeID, vtkDataSet* Mesh, const std::string& label = "NULL" );
95
 #endif
103
 #endif
96
 
104
 
97
         /**
105
         /**
106
          *   @param[in] J is the current intensity
114
          *   @param[in] J is the current intensity
107
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
115
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
108
          *   @see AddInjection(const int& iA, const Real& J)
116
          *   @see AddInjection(const int& iA, const Real& J)
109
-         *   @see AddInjection(DCIPElectrode* A, const Real& J)
117
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, const Real& J)
110
          */
118
          */
111
-        int AddInjection( DCIPElectrode* A, DCIPElectrode* B, const Real& J);
119
+        int AddInjection( std::shared_ptr<DCIPElectrode> A, std::shared_ptr<DCIPElectrode> B, const Real& J);
112
 
120
 
113
         /**
121
         /**
114
          *   Adds an injection point.
122
          *   Adds an injection point.
117
          *   B,  the negative current electrode is taken to be infinity
125
          *   B,  the negative current electrode is taken to be infinity
118
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
126
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
119
          *   @see AddInjection(const int& iA, const Real& J)
127
          *   @see AddInjection(const int& iA, const Real& J)
120
-         *   @see AddInjection(DCIPElectrode* A, DCIPElectrode* B, const Real& J)
128
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, std::shared_ptr<DCIPElectrode> B, const Real& J)
121
          */
129
          */
122
-        int AddInjection( DCIPElectrode* A, const Real& J );
130
+        int AddInjection( std::shared_ptr<DCIPElectrode> A, const Real& J );
123
 
131
 
124
         /**
132
         /**
125
          *   Adds an injection point.
133
          *   Adds an injection point.
126
          *   @param[in] A is the positive current electrode index
134
          *   @param[in] A is the positive current electrode index
127
          *   @param[in] B is the negative current electrode index
135
          *   @param[in] B is the negative current electrode index
128
          *   @param[in] J is the current intensity
136
          *   @param[in] J is the current intensity
129
-         *   @see AddInjection(DCIPElectrode* A, DCIPElectrode* B, const Real& J)
130
-         *   @see AddInjection(DCIPElectrode* A, const Real& J)
137
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, std::shared_ptr<DCIPElectrode> B, const Real& J)
138
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, const Real& J)
131
          *   @see AddInjection(const int& iA, const Real& J)
139
          *   @see AddInjection(const int& iA, const Real& J)
132
          */
140
          */
133
         int AddInjection( const int& iA, const int& iB, const Real& J );
141
         int AddInjection( const int& iA, const int& iB, const Real& J );
136
          *   Adds an injection point with the negative electrode at infinity.
144
          *   Adds an injection point with the negative electrode at infinity.
137
          *   @param[in] A is the positive current electrode index
145
          *   @param[in] A is the positive current electrode index
138
          *   @param[in] J is the current intensity
146
          *   @param[in] J is the current intensity
139
-         *   @see AddInjection(DCIPElectrode* A, DCIPElectrode* B, const Real& J)
140
-         *   @see AddInjection(DCIPElectrode* A, const Real& J)
147
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, std::shared_ptr<DCIPElectrode> B, const Real& J)
148
+         *   @see AddInjection(std::shared_ptr<DCIPElectrode> A, const Real& J)
141
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
149
          *   @see AddInjection(const int& iA, const int& iB, const Real& J)
142
          */
150
          */
143
         int AddInjection( const int& iA, const Real& J );
151
         int AddInjection( const int& iA, const Real& J );
147
          *   @param[in] N is a pointer to the `negative' electrode
155
          *   @param[in] N is a pointer to the `negative' electrode
148
          *   @param[in] iJ is the current injection index to associate with this measurement
156
          *   @param[in] iJ is the current injection index to associate with this measurement
149
          */
157
          */
150
-        void AddMeasurement( const int& iJ, DCIPElectrode* M, DCIPElectrode* N );
158
+        void AddMeasurement( const int& iJ, std::shared_ptr<DCIPElectrode> M, std::shared_ptr<DCIPElectrode> N );
151
 
159
 
152
         /** Adds a potential measurement via the electrode pair comparison \f$ M - N \f$.
160
         /** Adds a potential measurement via the electrode pair comparison \f$ M - N \f$.
153
          *   @param[in] M is the `positive' electrode string label name
161
          *   @param[in] M is the `positive' electrode string label name
154
          *   @param[in] N is the `negative' electrode string label name
162
          *   @param[in] N is the `negative' electrode string label name
155
          *   @param[in] iJ is the current injection index to associate with this measurement
163
          *   @param[in] iJ is the current injection index to associate with this measurement
156
-         *   @see AddMeasurement( const int& iJ, DCIPElectrode* M, DCIPElectrode* N )
164
+         *   @see AddMeasurement( const int& iJ, std::shared_ptr<DCIPElectrode> M, std::shared_ptr<DCIPElectrode> N )
157
          */
165
          */
158
         void AddMeasurement( const int& ij, const std::string& M, const std::string& N);
166
         void AddMeasurement( const int& ij, const std::string& M, const std::string& N);
159
 
167
 
178
 
186
 
179
         // ====================  INQUIRY       =======================
187
         // ====================  INQUIRY       =======================
180
 
188
 
181
-        #ifdef HAVE_YAMLCPP
182
-        YAML::Node Serialize() const;
183
-        static DCSurvey* DeSerialize(const YAML::Node& node);
184
-        #endif
185
-
186
         protected:
189
         protected:
187
 
190
 
188
         // ====================  LIFECYCLE     =======================
191
         // ====================  LIFECYCLE     =======================
189
 
192
 
190
-        /** Default protected constructor, use New */
191
-        DCSurvey (const std::string& name);
192
-
193
-        #ifdef HAVE_YAMLCPP
194
-        /** Default protected constructor, use New */
195
-        DCSurvey (const YAML::Node& node);
196
-        #endif
197
-
198
-        /** Default protected destructor, use Delete */
199
-        ~DCSurvey ();
200
-
201
-        /**
202
-         *  @copybrief   LemmaObject::Release()
203
-         *  @copydetails LemmaObject::Release()
204
-         */
205
-        void Release();
206
-
207
         private:
193
         private:
208
 
194
 
209
         // ====================  DATA MEMBERS  =========================
195
         // ====================  DATA MEMBERS  =========================
210
 
196
 
197
+        /** ASCII string representation of the class name */
198
+        static constexpr auto CName = "DCSurvey";
199
+
200
+        /** no copy */
201
+        DCSurvey ( const DCSurvey& ) = delete;
202
+
211
         /** The electrodes */
203
         /** The electrodes */
212
-        std::vector<DCIPElectrode*>                Electrodes;
204
+        std::vector< std::shared_ptr<DCIPElectrode> >                Electrodes;
213
 
205
 
214
         /** Tags for the electrodes, lines etc. Ordered with Electrodes std::vector */
206
         /** Tags for the electrodes, lines etc. Ordered with Electrodes std::vector */
215
         std::vector<std::string>                   OrderedElectrodeLabels;
207
         std::vector<std::string>                   OrderedElectrodeLabels;
216
 
208
 
217
         /** Map of tags for the electrodes, lines etc. */
209
         /** Map of tags for the electrodes, lines etc. */
218
-        std::map<std::string, std::pair<DCIPElectrode*, int> >      ElectrodeLabelMap;
210
+        std::map<std::string, std::pair< std::shared_ptr<DCIPElectrode>, int> >      ElectrodeLabelMap;
219
 
211
 
220
         /** The A Injection electrodes */
212
         /** The A Injection electrodes */
221
         std::vector<int>     A_Electrodes;
213
         std::vector<int>     A_Electrodes;

+ 7
- 0
Modules/DCIP/src/CMakeLists.txt View File

1
+set (DCIPSOURCE
2
+	
3
+	${CMAKE_CURRENT_SOURCE_DIR}/DCIPElectrode.cpp
4
+	${CMAKE_CURRENT_SOURCE_DIR}/DCSurvey.cpp
5
+	
6
+	PARENT_SCOPE
7
+)

+ 16
- 48
Modules/DCIP/src/DCIPElectrode.cpp View File

24
 
24
 
25
 
25
 
26
     // ====================  FRIEND METHODS  =====================
26
     // ====================  FRIEND METHODS  =====================
27
-#ifdef HAVE_YAMLCPP
27
+
28
     std::ostream &operator << (std::ostream &stream, const DCIPElectrode &ob) {
28
     std::ostream &operator << (std::ostream &stream, const DCIPElectrode &ob) {
29
-        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulate thingy
30
-        return stream;
31
-    }
32
-#else
33
-    std::ostream &operator<<(std::ostream &stream, const DCIPElectrode& ob) {
34
-        stream << *(LemmaObject*)(&ob);
29
+        stream << ob.Serialize()  << "\n";
35
         return stream;
30
         return stream;
36
     }
31
     }
37
-#endif
38
 
32
 
39
     // ====================  LIFECYCLE     =======================
33
     // ====================  LIFECYCLE     =======================
40
 
34
 
41
     //--------------------------------------------------------------------------------------
35
     //--------------------------------------------------------------------------------------
42
     //       Class:  DCIPElectrode
36
     //       Class:  DCIPElectrode
43
     //      Method:  DCIPElectrode
37
     //      Method:  DCIPElectrode
44
-    // Description:  constructor (protected)
38
+    // Description:  constructor (locked)
45
     //--------------------------------------------------------------------------------------
39
     //--------------------------------------------------------------------------------------
46
-    DCIPElectrode::DCIPElectrode (const std::string& name) : LemmaObject(name), Node_ID(-1), Label(std::string("None")) {
40
+    DCIPElectrode::DCIPElectrode (const ctor_key& key) :
41
+            LemmaObject(key), Node_ID(-1), Label(std::string("None")) {
47
 
42
 
48
     }  // -----  end of method DCIPElectrode::DCIPElectrode  (constructor)  -----
43
     }  // -----  end of method DCIPElectrode::DCIPElectrode  (constructor)  -----
49
 
44
 
50
-#ifdef HAVE_YAMLCPP
51
     //--------------------------------------------------------------------------------------
45
     //--------------------------------------------------------------------------------------
52
     //       Class:  DCIPElectrode
46
     //       Class:  DCIPElectrode
53
     //      Method:  DCIPElectrode
47
     //      Method:  DCIPElectrode
54
-    // Description:  DeSerializing constructor (protected)
48
+    // Description:  DeSerializing constructor (locked)
55
     //--------------------------------------------------------------------------------------
49
     //--------------------------------------------------------------------------------------
56
-    DCIPElectrode::DCIPElectrode (const YAML::Node& node) : LemmaObject(node) {
57
-        if (node.Tag() != this->Name) {
50
+    DCIPElectrode::DCIPElectrode (const YAML::Node& node, const ctor_key& key) : LemmaObject(node, key) {
51
+        if (node.Tag() != DCIPElectrode::CName) {
58
             throw std::runtime_error("In DCIPElectrode(node), node is of wrong type");
52
             throw std::runtime_error("In DCIPElectrode(node), node is of wrong type");
59
         }
53
         }
60
         this->Location = node["Location"].as<Vector3r>();
54
         this->Location = node["Location"].as<Vector3r>();
61
         this->Node_ID = node["Node_ID"].as<int>();
55
         this->Node_ID = node["Node_ID"].as<int>();
62
         this->Label = node["Label"].as<std::string>();
56
         this->Label = node["Label"].as<std::string>();
63
     }  // -----  end of method DCIPElectrode::DCIPElectrode  (constructor)  -----
57
     }  // -----  end of method DCIPElectrode::DCIPElectrode  (constructor)  -----
64
-#endif
65
 
58
 
66
     //--------------------------------------------------------------------------------------
59
     //--------------------------------------------------------------------------------------
67
     //       Class:  DCIPElectrode
60
     //       Class:  DCIPElectrode
68
     //      Method:  New()
61
     //      Method:  New()
69
     // Description:  public constructor
62
     // Description:  public constructor
70
     //--------------------------------------------------------------------------------------
63
     //--------------------------------------------------------------------------------------
71
-    DCIPElectrode* DCIPElectrode::New() {
72
-        DCIPElectrode*  Obj = new DCIPElectrode("DCIPElectrode");
73
-        Obj->AttachTo(Obj);
74
-        return Obj;
64
+    std::shared_ptr<DCIPElectrode> DCIPElectrode::NewSP() {
65
+        return std::make_shared<DCIPElectrode>( ctor_key() );
75
     }
66
     }
76
 
67
 
77
     //--------------------------------------------------------------------------------------
68
     //--------------------------------------------------------------------------------------
85
 
76
 
86
     //--------------------------------------------------------------------------------------
77
     //--------------------------------------------------------------------------------------
87
     //       Class:  DCIPElectrode
78
     //       Class:  DCIPElectrode
88
-    //      Method:  Delete
89
-    // Description:  public destructor
90
-    //--------------------------------------------------------------------------------------
91
-    void DCIPElectrode::Delete() {
92
-        this->DetachFrom(this);
93
-    }
94
-
95
-    //--------------------------------------------------------------------------------------
96
-    //       Class:  DCIPElectrode
97
-    //      Method:  Release
98
-    // Description:  destructor (protected)
99
-    //--------------------------------------------------------------------------------------
100
-    void DCIPElectrode::Release() {
101
-        delete this;
102
-    }
103
-
104
-
105
-#ifdef HAVE_YAMLCPP
106
-    //--------------------------------------------------------------------------------------
107
-    //       Class:  DCIPElectrode
108
     //      Method:  Serialize
79
     //      Method:  Serialize
109
     //--------------------------------------------------------------------------------------
80
     //--------------------------------------------------------------------------------------
110
     YAML::Node  DCIPElectrode::Serialize (  ) const {
81
     YAML::Node  DCIPElectrode::Serialize (  ) const {
111
         YAML::Node node = LemmaObject::Serialize();
82
         YAML::Node node = LemmaObject::Serialize();
112
-        node.SetTag( this->Name );
83
+        node.SetTag( this->GetName() );
113
         // FILL IN CLASS SPECIFICS HERE
84
         // FILL IN CLASS SPECIFICS HERE
114
         node["Location"] = Location;
85
         node["Location"] = Location;
115
         node["Node_ID"] = Node_ID;
86
         node["Node_ID"] = Node_ID;
117
         return node;
88
         return node;
118
     }		// -----  end of method DCIPElectrode::Serialize  -----
89
     }		// -----  end of method DCIPElectrode::Serialize  -----
119
 
90
 
120
-
121
     //--------------------------------------------------------------------------------------
91
     //--------------------------------------------------------------------------------------
122
     //       Class:  DCIPElectrode
92
     //       Class:  DCIPElectrode
123
     //      Method:  DeSerialize
93
     //      Method:  DeSerialize
124
     //--------------------------------------------------------------------------------------
94
     //--------------------------------------------------------------------------------------
125
-    DCIPElectrode* DCIPElectrode::DeSerialize ( const YAML::Node& node  ) {
126
-        DCIPElectrode* Object = new DCIPElectrode(node);
127
-        Object->AttachTo(Object);
128
-        DESERIALIZECHECK( node, Object )
129
-        return Object ;
95
+    std::shared_ptr<DCIPElectrode> DCIPElectrode::DeSerialize ( const YAML::Node& node  ) {
96
+        if ( node.Tag() != DCIPElectrode::CName ) {
97
+            throw  DeSerializeTypeMismatch( DCIPElectrode::CName, node.Tag());
98
+        }
99
+        return std::make_shared< DCIPElectrode > ( node, ctor_key() );
130
     }		// -----  end of method DCIPElectrode::DeSerialize  -----
100
     }		// -----  end of method DCIPElectrode::DeSerialize  -----
131
-#endif
132
-
133
 
101
 
134
     //--------------------------------------------------------------------------------------
102
     //--------------------------------------------------------------------------------------
135
     //       Class:  DCIPElectrode
103
     //       Class:  DCIPElectrode

+ 30
- 73
Modules/DCIP/src/DCSurvey.cpp View File

10
 /**
10
 /**
11
  * @file
11
  * @file
12
  * @date      10/08/2014 01:52:04 PM
12
  * @date      10/08/2014 01:52:04 PM
13
- * @version   $Id$
14
  * @author    Trevor Irons (ti)
13
  * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
14
+ * @email     Trevor.Irons@lemmasoftware.org
15
+ * @copyright Copyright (c) 2014, 2018 Trevor Irons
18
  */
16
  */
19
 
17
 
20
 #include	"DCSurvey.h"
18
 #include	"DCSurvey.h"
21
 
19
 
22
 namespace Lemma {
20
 namespace Lemma {
23
 
21
 
24
-
25
     // ====================  FRIEND METHODS  =====================
22
     // ====================  FRIEND METHODS  =====================
26
 
23
 
27
-    #ifdef HAVE_YAMLCPP
28
     std::ostream &operator << (std::ostream &stream, const DCSurvey &ob) {
24
     std::ostream &operator << (std::ostream &stream, const DCSurvey &ob) {
29
-        stream << ob.Serialize()  << "\n---\n"; // End of doc --- a direct stream should encapsulate object
30
-        return stream;
31
-    }
32
-    #else
33
-    std::ostream &operator<<(std::ostream &stream, const DCSurvey &ob) {
34
-        stream << *(LemmaObject*)(&ob);
25
+        stream << ob.Serialize()  << "\n";
35
         return stream;
26
         return stream;
36
     }
27
     }
37
-    #endif
38
 
28
 
39
     // ====================  LIFECYCLE     =======================
29
     // ====================  LIFECYCLE     =======================
40
 
30
 
43
     //      Method:  DCSurvey
33
     //      Method:  DCSurvey
44
     // Description:  constructor (protected)
34
     // Description:  constructor (protected)
45
     //--------------------------------------------------------------------------------------
35
     //--------------------------------------------------------------------------------------
46
-    DCSurvey::DCSurvey (const std::string& name) : LemmaObject(name) {
36
+    DCSurvey::DCSurvey (const ctor_key& key) : LemmaObject(key) {
47
 
37
 
48
     }  // -----  end of method DCSurvey::DCSurvey  (constructor)  -----
38
     }  // -----  end of method DCSurvey::DCSurvey  (constructor)  -----
49
 
39
 
52
     //      Method:  DCSurvey
42
     //      Method:  DCSurvey
53
     // Description:  DeSerializing constructor (protected)
43
     // Description:  DeSerializing constructor (protected)
54
     //--------------------------------------------------------------------------------------
44
     //--------------------------------------------------------------------------------------
55
-    #ifdef HAVE_YAMLCPP
56
-    DCSurvey::DCSurvey (const YAML::Node& node) : LemmaObject(node) {
45
+    DCSurvey::DCSurvey (const YAML::Node& node, const ctor_key& key) : LemmaObject(node, key) {
57
 
46
 
58
         if (node.Tag() != "DCSurvey") {
47
         if (node.Tag() != "DCSurvey") {
59
             throw std::runtime_error("DCSurvey->DeSerialize cannot deserialize non-DCSurvey");
48
             throw std::runtime_error("DCSurvey->DeSerialize cannot deserialize non-DCSurvey");
63
         for(YAML::const_iterator it=node["Electrodes"].begin(); it!=node["Electrodes"].end(); ++it) {
52
         for(YAML::const_iterator it=node["Electrodes"].begin(); it!=node["Electrodes"].end(); ++it) {
64
             std::string e = it->first.as<std::string>();
53
             std::string e = it->first.as<std::string>();
65
             Electrodes.push_back( DCIPElectrode::DeSerialize( node["Electrodes"][e] ) );
54
             Electrodes.push_back( DCIPElectrode::DeSerialize( node["Electrodes"][e] ) );
66
-            Electrodes[Electrodes.size()-1]->AttachTo(this);
67
             eMap[ node["Electrodes"][Electrodes.size()-1] ] = Electrodes.size() -1 ;
55
             eMap[ node["Electrodes"][Electrodes.size()-1] ] = Electrodes.size() -1 ;
68
             OrderedElectrodeLabels.push_back(e);
56
             OrderedElectrodeLabels.push_back(e);
69
-            ElectrodeLabelMap[e] = std::pair<DCIPElectrode*, int>(Electrodes[Electrodes.size()-1], Electrodes.size()-1);
57
+            ElectrodeLabelMap[e] = std::pair< std::shared_ptr<DCIPElectrode>, int>(Electrodes[Electrodes.size()-1], Electrodes.size()-1);
70
         }
58
         }
71
 
59
 
72
         //std::cout << "J-0\n" << node["Injections"]["J-0"] << std::endl;
60
         //std::cout << "J-0\n" << node["Injections"]["J-0"] << std::endl;
93
         }
81
         }
94
 
82
 
95
     }  // -----  end of method DCSurvey::DCSurvey  (constructor)  -----
83
     }  // -----  end of method DCSurvey::DCSurvey  (constructor)  -----
96
-    #endif
97
 
84
 
98
     //--------------------------------------------------------------------------------------
85
     //--------------------------------------------------------------------------------------
99
     //       Class:  DCSurvey
86
     //       Class:  DCSurvey
100
     //      Method:  New()
87
     //      Method:  New()
101
     // Description:  public constructor
88
     // Description:  public constructor
102
     //--------------------------------------------------------------------------------------
89
     //--------------------------------------------------------------------------------------
103
-    DCSurvey* DCSurvey::New() {
104
-        DCSurvey*  Obj = new DCSurvey("DCSurvey");
105
-        Obj->AttachTo(Obj);
106
-        return Obj;
90
+    std::shared_ptr<DCSurvey> DCSurvey::NewSP() {
91
+        return std::make_shared<DCSurvey>( ctor_key() );
107
     }
92
     }
108
 
93
 
109
     //--------------------------------------------------------------------------------------
94
     //--------------------------------------------------------------------------------------
117
 
102
 
118
     //--------------------------------------------------------------------------------------
103
     //--------------------------------------------------------------------------------------
119
     //       Class:  DCSurvey
104
     //       Class:  DCSurvey
120
-    //      Method:  Delete
121
-    // Description:  public destructor
122
-    //--------------------------------------------------------------------------------------
123
-    void DCSurvey::Delete() {
124
-        this->DetachFrom(this);
125
-    }
126
-
127
-    //--------------------------------------------------------------------------------------
128
-    //       Class:  DCSurvey
129
-    //      Method:  Release
130
-    // Description:  destructor (protected)
131
-    //--------------------------------------------------------------------------------------
132
-    void DCSurvey::Release() {
133
-        this->PullElectrodes();
134
-        delete this;
135
-    }
136
-
137
-    #ifdef HAVE_YAMLCPP
138
-    //--------------------------------------------------------------------------------------
139
-    //       Class:  DCSurvey
140
     //      Method:  Serialize
105
     //      Method:  Serialize
141
     //--------------------------------------------------------------------------------------
106
     //--------------------------------------------------------------------------------------
142
     YAML::Node  DCSurvey::Serialize (  ) const {
107
     YAML::Node  DCSurvey::Serialize (  ) const {
143
         YAML::Node node = LemmaObject::Serialize();
108
         YAML::Node node = LemmaObject::Serialize();
144
-        node.SetTag( this->Name );
109
+        node.SetTag( this->GetName() );
145
         node["NumberOfElectrodes"] = Electrodes.size();
110
         node["NumberOfElectrodes"] = Electrodes.size();
146
 
111
 
147
         // All the electrodes
112
         // All the electrodes
148
-        for (std::map<std::string, std::pair<DCIPElectrode*, int> >::const_iterator it  = ElectrodeLabelMap.begin();
113
+        for (std::map<std::string, std::pair< std::shared_ptr<DCIPElectrode>, int> >::const_iterator it  = ElectrodeLabelMap.begin();
149
                                                                                     it != ElectrodeLabelMap.end(); ++it) {
114
                                                                                     it != ElectrodeLabelMap.end(); ++it) {
150
             node["Electrodes"][ it->first ] = it->second.first->Serialize();
115
             node["Electrodes"][ it->first ] = it->second.first->Serialize();
151
         }
116
         }
168
         return node;
133
         return node;
169
     }		// -----  end of method DCSurvey::Serialize  -----
134
     }		// -----  end of method DCSurvey::Serialize  -----
170
 
135
 
171
-
172
     //--------------------------------------------------------------------------------------
136
     //--------------------------------------------------------------------------------------
173
     //       Class:  DCSurvey
137
     //       Class:  DCSurvey
174
     //      Method:  DeSerialize
138
     //      Method:  DeSerialize
175
     //--------------------------------------------------------------------------------------
139
     //--------------------------------------------------------------------------------------
176
-    DCSurvey* DCSurvey::DeSerialize ( const YAML::Node& node  ) {
177
-        DCSurvey* Object = new DCSurvey(node);
178
-        Object->AttachTo(Object);
179
-        DESERIALIZECHECK( node, Object )
180
-        return Object ;
140
+    std::shared_ptr<DCSurvey> DCSurvey::DeSerialize ( const YAML::Node& node  ) {
141
+        if ( node.Tag() != DCSurvey::CName ) {
142
+            throw  DeSerializeTypeMismatch( DCSurvey::CName, node.Tag());
143
+        }
144
+        return std::make_shared< DCSurvey > ( node, ctor_key() );
181
     }		// -----  end of method DCSurvey::DeSerialize  -----
145
     }		// -----  end of method DCSurvey::DeSerialize  -----
182
-    #endif
183
 
146
 
184
     //--------------------------------------------------------------------------------------
147
     //--------------------------------------------------------------------------------------
185
     //       Class:  DCSurvey
148
     //       Class:  DCSurvey
186
     //      Method:  PoundElectrode
149
     //      Method:  PoundElectrode
187
     //--------------------------------------------------------------------------------------
150
     //--------------------------------------------------------------------------------------
188
-    int DCSurvey::PoundElectrode ( DCIPElectrode* Electrode, const std::string& tag, const int&nodeID ) {
151
+    int DCSurvey::PoundElectrode ( std::shared_ptr<DCIPElectrode> Electrode, const std::string& tag, const int&nodeID ) {
189
         Electrodes.push_back(Electrode);
152
         Electrodes.push_back(Electrode);
190
         if (tag != "NULL") {
153
         if (tag != "NULL") {
191
             OrderedElectrodeLabels.push_back(tag);
154
             OrderedElectrodeLabels.push_back(tag);
192
             //ElectrodeTagMap[tag] = Electrode;
155
             //ElectrodeTagMap[tag] = Electrode;
193
-            ElectrodeLabelMap[tag] = std::pair<DCIPElectrode*, int> (Electrode, Electrodes.size()-1);
156
+            ElectrodeLabelMap[tag] = std::pair< std::shared_ptr<DCIPElectrode>, int> (Electrode, Electrodes.size()-1);
194
             Electrode->SetLabel(tag);
157
             Electrode->SetLabel(tag);
195
         } else {
158
         } else {
196
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
159
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
197
             //ElectrodeTagMap[std::string("E") + to_string(Electrodes.size()-1)] = Electrode;
160
             //ElectrodeTagMap[std::string("E") + to_string(Electrodes.size()-1)] = Electrode;
198
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
161
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
199
-                std::pair<DCIPElectrode*, int>(Electrode, Electrodes.size()-1);
162
+                std::pair< std::shared_ptr<DCIPElectrode>, int>(Electrode, Electrodes.size()-1);
200
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
163
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
201
         }
164
         }
202
-        Electrode->AttachTo(this);
203
         return  static_cast<int>( Electrodes.size() ) ;
165
         return  static_cast<int>( Electrodes.size() ) ;
204
     }		// -----  end of method DCSurvey::PoundElectrode  -----
166
     }		// -----  end of method DCSurvey::PoundElectrode  -----
205
 
167
 
207
     //       Class:  DCSurvey
169
     //       Class:  DCSurvey
208
     //      Method:  PoundElectrode
170
     //      Method:  PoundElectrode
209
     //--------------------------------------------------------------------------------------
171
     //--------------------------------------------------------------------------------------
210
-    DCIPElectrode* DCSurvey::PoundElectrode ( const Vector3r& loc, const std::string& tag, const int& nodeID ) {
211
-        DCIPElectrode* Electrode = DCIPElectrode::New();
172
+    std::shared_ptr<DCIPElectrode> DCSurvey::PoundElectrode ( const Vector3r& loc, const std::string& tag, const int& nodeID ) {
173
+        auto Electrode = DCIPElectrode::NewSP();
212
             Electrode->SetLocation( loc );
174
             Electrode->SetLocation( loc );
213
         Electrodes.push_back(Electrode);
175
         Electrodes.push_back(Electrode);
214
         if (tag != "NULL") {
176
         if (tag != "NULL") {
215
             OrderedElectrodeLabels.push_back(tag);
177
             OrderedElectrodeLabels.push_back(tag);
216
-            ElectrodeLabelMap[tag] = std::pair<DCIPElectrode*, int> (Electrode, Electrodes.size()-1);
178
+            ElectrodeLabelMap[tag] = std::pair< std::shared_ptr<DCIPElectrode>, int> (Electrode, Electrodes.size()-1);
217
             Electrode->SetLabel(tag);
179
             Electrode->SetLabel(tag);
218
         } else {
180
         } else {
219
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
181
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
220
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
182
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
221
-                std::pair<DCIPElectrode*, int>(Electrode, Electrodes.size()-1);
183
+                std::pair< std::shared_ptr<DCIPElectrode>, int>(Electrode, Electrodes.size()-1);
222
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
184
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
223
         }
185
         }
224
-        Electrode->AttachTo(this);
225
         return  Electrode;
186
         return  Electrode;
226
     }		// -----  end of method DCSurvey::PoundElectrode  -----
187
     }		// -----  end of method DCSurvey::PoundElectrode  -----
227
 
188
 
230
     //      Method:  PoundElectrode
191
     //      Method:  PoundElectrode
231
     //--------------------------------------------------------------------------------------
192
     //--------------------------------------------------------------------------------------
232
 #ifdef LEMMAUSEVTK
193
 #ifdef LEMMAUSEVTK
233
-    DCIPElectrode* DCSurvey::PoundElectrode( const int& nodeID, vtkDataSet* Mesh, const std::string& tag ) {
234
-        DCIPElectrode* Electrode = DCIPElectrode::New();
194
+    std::shared_ptr<DCIPElectrode> DCSurvey::PoundElectrode( const int& nodeID, vtkDataSet* Mesh, const std::string& tag ) {
195
+        auto Electrode = DCIPElectrode::NewSP();
235
         double* loc = Mesh->GetPoint(nodeID);
196
         double* loc = Mesh->GetPoint(nodeID);
236
         Electrode->SetLocation( Vector3r(loc[0], loc[1], loc[2]) );
197
         Electrode->SetLocation( Vector3r(loc[0], loc[1], loc[2]) );
237
         Electrodes.push_back(Electrode);
198
         Electrodes.push_back(Electrode);
238
         if (tag != "NULL") {
199
         if (tag != "NULL") {
239
             OrderedElectrodeLabels.push_back(tag);
200
             OrderedElectrodeLabels.push_back(tag);
240
-            ElectrodeLabelMap[tag] = std::pair<DCIPElectrode*, int> (Electrode, Electrodes.size()-1);
201
+            ElectrodeLabelMap[tag] = std::pair< std::shared_ptr<DCIPElectrode>, int> (Electrode, Electrodes.size()-1);
241
             Electrode->SetLabel(tag);
202
             Electrode->SetLabel(tag);
242
         } else {
203
         } else {
243
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
204
             OrderedElectrodeLabels.push_back( std::string("E") + to_string(Electrodes.size()-1) );
244
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
205
             ElectrodeLabelMap[std::string("E") + to_string(Electrodes.size()-1)] =
245
-                std::pair<DCIPElectrode*, int>(Electrode, Electrodes.size()-1);
206
+                std::pair< std::shared_ptr<DCIPElectrode>, int>(Electrode, Electrodes.size()-1);
246
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
207
             Electrode->SetLabel( std::string("E") + to_string(Electrodes.size()-1) );
247
         }
208
         }
248
-        Electrode->AttachTo(this);
249
         return Electrode;
209
         return Electrode;
250
     }		// -----  end of method DCSurvey::PoundElectrode  -----
210
     }		// -----  end of method DCSurvey::PoundElectrode  -----
251
 #endif
211
 #endif
255
     //      Method:  PullElectrodes
215
     //      Method:  PullElectrodes
256
     //--------------------------------------------------------------------------------------
216
     //--------------------------------------------------------------------------------------
257
     void DCSurvey::PullElectrodes (  ) {
217
     void DCSurvey::PullElectrodes (  ) {
258
-        for (std::vector<DCIPElectrode*>::iterator it = Electrodes.begin() ; it != Electrodes.end(); ++it) {
259
-            (*it)->DetachFrom(this);
260
-        }
261
         Electrodes.clear();
218
         Electrodes.clear();
262
         OrderedElectrodeLabels.clear();
219
         OrderedElectrodeLabels.clear();
263
         ElectrodeLabelMap.clear();
220
         ElectrodeLabelMap.clear();
274
     //       Class:  DCSurvey
231
     //       Class:  DCSurvey
275
     //      Method:  AddInjection
232
     //      Method:  AddInjection
276
     //--------------------------------------------------------------------------------------
233
     //--------------------------------------------------------------------------------------
277
-    int DCSurvey::AddInjection ( DCIPElectrode* A, DCIPElectrode* B, const Real& J ) {
234
+    int DCSurvey::AddInjection ( std::shared_ptr<DCIPElectrode> A, std::shared_ptr<DCIPElectrode> B, const Real& J ) {
278
         bool fA = false;
235
         bool fA = false;
279
         bool fB = false;
236
         bool fB = false;
280
         for (unsigned int i=0; i<Electrodes.size(); ++i) {
237
         for (unsigned int i=0; i<Electrodes.size(); ++i) {
305
     //       Class:  DCSurvey
262
     //       Class:  DCSurvey
306
     //      Method:  AddMeasurement
263
     //      Method:  AddMeasurement
307
     //--------------------------------------------------------------------------------------
264
     //--------------------------------------------------------------------------------------
308
-    void DCSurvey::AddMeasurement ( const int& iJ, DCIPElectrode* M, DCIPElectrode* N  ) {
265
+    void DCSurvey::AddMeasurement ( const int& iJ, std::shared_ptr<DCIPElectrode> M, std::shared_ptr<DCIPElectrode> N  ) {
309
         bool fM = false;
266
         bool fM = false;
310
         bool fN = false;
267
         bool fN = false;
311
         for (unsigned int i=0; i<Electrodes.size(); ++i) {
268
         for (unsigned int i=0; i<Electrodes.size(); ++i) {
335
 
292
 
336
     void DCSurvey::AddMeasurement ( const int& iJ, const std::string& M, const std::string& N ) {
293
     void DCSurvey::AddMeasurement ( const int& iJ, const std::string& M, const std::string& N ) {
337
 
294
 
338
-        std::pair<DCIPElectrode*, int> Mp = ElectrodeLabelMap[M];
339
-        std::pair<DCIPElectrode*, int> Np = ElectrodeLabelMap[N];
295
+        std::pair< std::shared_ptr<DCIPElectrode>, int> Mp = ElectrodeLabelMap[M];
296
+        std::pair< std::shared_ptr<DCIPElectrode>, int> Np = ElectrodeLabelMap[N];
340
 
297
 
341
         if (Mp.first == NULL) {
298
         if (Mp.first == NULL) {
342
             throw std::runtime_error( "Injection point M not found" );
299
             throw std::runtime_error( "Injection point M not found" );

+ 2
- 2
Modules/FDEM1D/include/FHTKey101.h View File

54
         ~FHTKey101 ();
54
         ~FHTKey101 ();
55
 
55
 
56
         /**
56
         /**
57
-         * @copybrief LemmaObject::New()
58
-         * @copydetails LemmaObject::New()
57
+         * \brief   returns shared_ptr with new object
58
+         * \details Use this method as default constructor is locked.
59
          */
59
          */
60
         static std::shared_ptr<FHTKey101> NewSP();
60
         static std::shared_ptr<FHTKey101> NewSP();
61
 
61
 

+ 0
- 88
Modules/FDEM1D/include/GroundedElectricDipole.h 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      01/29/2014 06:59:39 AM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-
21
-#ifndef  GROUNDEDELECTRICDIPOLE_INC
22
-#define  GROUNDEDELECTRICDIPOLE_INC
23
-
24
-#include "dipolesource.h"
25
-
26
-namespace Lemma {
27
-
28
-    /**
29
-      \ingroup FDEM1D
30
-      \brief   Grounded electric dipole
31
-      \details Used to model an idealised grounded electrid dipole of arbitrary
32
-               polarisation.
33
-     */
34
-    class GroundedElectricDipole : public DipoleSource {
35
-
36
-        friend std::ostream &operator<<(std::ostream &stream,
37
-                const GroundedElectricDipole &ob);
38
-
39
-        public:
40
-
41
-        // ====================  LIFECYCLE     =======================
42
-
43
-        /**
44
-         * @copybrief LemmaObject::New()
45
-         * @copydetails LemmaObject::New()
46
-         */
47
-        static GroundedElectricDipole* New();
48
-
49
-        /**
50
-         *  @copybrief   LemmaObject::Delete()
51
-         *  @copydetails LemmaObject::Delete()
52
-         */
53
-        void Delete();
54
-
55
-        // ====================  OPERATORS     =======================
56
-
57
-        // ====================  OPERATIONS    =======================
58
-
59
-        // ====================  ACCESS        =======================
60
-
61
-        // ====================  INQUIRY       =======================
62
-
63
-        protected:
64
-
65
-        // ====================  LIFECYCLE     =======================
66
-
67
-        /** Default protected constructor, use New */
68
-        GroundedElectricDipole (const std::string& name);
69
-
70
-        /** Default protected destructor, use Delete */
71
-        ~GroundedElectricDipole ();
72
-
73
-        /**
74
-         *  @copybrief   LemmaObject::Release()
75
-         *  @copydetails LemmaObject::Release()
76
-         */
77
-        void Release();
78
-
79
-        private:
80
-
81
-        // ====================  DATA MEMBERS  =========================
82
-
83
-    }; // -----  end of class  GroundedElectricDipole  -----
84
-
85
-}		// -----  end of Lemma  name  -----
86
-
87
-#endif   // ----- #ifndef GROUNDEDELECTRICDIPOLE_INC  -----
88
-

+ 0
- 1
Modules/FDEM1D/include/KernelEM1DBase.h View File

24
     // ===================================================================
24
     // ===================================================================
25
     //  Class:  KernelEM1DBase
25
     //  Class:  KernelEM1DBase
26
     /**
26
     /**
27
-      @class
28
       \ingroup FDEM1D
27
       \ingroup FDEM1D
29
       \brief   Pure virtual base class of KernelEm1D
28
       \brief   Pure virtual base class of KernelEm1D
30
       \details Defines interface for HankelTransform classes
29
       \details Defines interface for HankelTransform classes

+ 0
- 1
Modules/FDEM1D/include/KernelEM1DManager.h View File

25
     // ===================================================================
25
     // ===================================================================
26
     //  Class:  KernelEM1DManager
26
     //  Class:  KernelEM1DManager
27
     /**
27
     /**
28
-      @class
29
       \ingroup FDEM1D
28
       \ingroup FDEM1D
30
       \brief   Keeps track of Kernels for EM1D
29
       \brief   Keeps track of Kernels for EM1D
31
       \details This class keeps track of the various types of kernel terms
30
       \details This class keeps track of the various types of kernel terms

+ 0
- 1
Modules/FDEM1D/include/KernelEM1DReflBase.h View File

29
     // ===================================================================
29
     // ===================================================================
30
     //  Class:  KernelEM1DReflBase
30
     //  Class:  KernelEM1DReflBase
31
     /**
31
     /**
32
-      @class
33
       \ingroup FDEM1D
32
       \ingroup FDEM1D
34
       \brief   Abstract class defining EM1DRefl class.
33
       \brief   Abstract class defining EM1DRefl class.
35
       \details Derived classes are template specialized for optimal performance.
34
       \details Derived classes are template specialized for optimal performance.

+ 0
- 1
Modules/FDEM1D/include/KernelEM1DReflSpec.h View File

26
     // ===================================================================
26
     // ===================================================================
27
     //  Class:  KernelEM1DReflSpec
27
     //  Class:  KernelEM1DReflSpec
28
     /**
28
     /**
29
-      @class
30
       \ingroup FDEM1D
29
       \ingroup FDEM1D
31
       \brief   Specialized version of KernelEM1DReflBase
30
       \brief   Specialized version of KernelEM1DReflBase
32
       \details Through use of template specialisations, this KernelEm1D
31
       \details Through use of template specialisations, this KernelEm1D

+ 0
- 1
Modules/FDEM1D/include/KernelEM1DSpec.h View File

27
     // ===================================================================
27
     // ===================================================================
28
     //  Class:  KernelEM1DSpec
28
     //  Class:  KernelEM1DSpec
29
     /**
29
     /**
30
-      @class
31
       \ingroup FDEM1D
30
       \ingroup FDEM1D
32
       \brief   Optimized version of KernelEm1D
31
       \brief   Optimized version of KernelEm1D
33
       \details Through use of template specialisations, this KernelEm1D
32
       \details Through use of template specialisations, this KernelEm1D

+ 0
- 1
Modules/FDEM1D/include/MagneticDipole.h View File

25
 namespace Lemma {
25
 namespace Lemma {
26
 
26
 
27
 /**
27
 /**
28
-  @class
29
   \ingroup FDEM1D
28
   \ingroup FDEM1D
30
   \brief   Magnetic Dipole
29
   \brief   Magnetic Dipole
31
   \details Used to model an idealised magnetic dipole of arbitrary
30
   \details Used to model an idealised magnetic dipole of arbitrary

+ 0
- 1
Modules/FDEM1D/include/digitalfilterintegrator.h View File

22
     // ===================================================================
22
     // ===================================================================
23
     //  Class:  DigitalFilterIntegrator
23
     //  Class:  DigitalFilterIntegrator
24
     /**
24
     /**
25
-      @class
26
       \brief   Reimplimentation of Walt Anderson's digital filtering
25
       \brief   Reimplimentation of Walt Anderson's digital filtering
27
                algorithms which are public domain.
26
                algorithms which are public domain.
28
       \details Walt Anderson wrote several routines for digital filtering
27
       \details Walt Anderson wrote several routines for digital filtering

+ 0
- 1
Modules/FDEM1D/include/integrationkernel.h View File

21
     // ===================================================================
21
     // ===================================================================
22
     //  Class:  IntegrationKernel
22
     //  Class:  IntegrationKernel
23
     /**
23
     /**
24
-      @class
25
       \brief    Abstract class that computes arguments for numerical
24
       \brief    Abstract class that computes arguments for numerical
26
                 integrators.
25
                 integrators.
27
       \details  Needs to provide Argument function, as well as be able to
26
       \details  Needs to provide Argument function, as well as be able to

+ 0
- 1
Modules/FDEM1D/include/inversesolver.h View File

25
     // ===================================================================
25
     // ===================================================================
26
     //  Class:  InverseSolver
26
     //  Class:  InverseSolver
27
     /**
27
     /**
28
-      @class  InverseSolver
29
       \brief   Abstract class for inverse problem solver.
28
       \brief   Abstract class for inverse problem solver.
30
       \details General solution of inverse problems.
29
       \details General solution of inverse problems.
31
      */
30
      */

+ 0
- 1
Modules/FDEM1D/include/sintransintegrationkernel.h View File

21
     // ===================================================================
21
     // ===================================================================
22
     //  Class:  SinTransIntegrationKernel
22
     //  Class:  SinTransIntegrationKernel
23
     /**
23
     /**
24
-      @class
25
       \brief    Integration kernel for testing sinine transform.
24
       \brief    Integration kernel for testing sinine transform.
26
       \details  Evaluates sinine at the argument, using lagged convolution.
25
       \details  Evaluates sinine at the argument, using lagged convolution.
27
                 all of these kernels have exact solutions.
26
                 all of these kernels have exact solutions.

+ 0
- 85
Modules/FDEM1D/src/GroundedElectricDipole.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      01/29/2014 07:05:13 AM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-#include "GroundedElectricDipole.h"
21
-
22
-
23
-namespace Lemma {
24
-
25
-    // ====================  FRIEND METHODS  =====================
26
-
27
-    std::ostream &operator<<(std::ostream &stream, const GroundedElectricDipole &ob) {
28
-
29
-        stream << *(DipoleSource*)(&ob);
30
-
31
-        return stream;
32
-    }
33
-
34
-    // ====================  LIFECYCLE     =======================
35
-
36
-    //--------------------------------------------------------------------------------------
37
-    //       Class:  GroundedElectricDipole
38
-    //      Method:  GroundedElectricDipole
39
-    // Description:  constructor (protected)
40
-    //--------------------------------------------------------------------------------------
41
-    GroundedElectricDipole::GroundedElectricDipole (const std::string& name) : DipoleSource(name) {
42
-
43
-    }  // -----  end of method GroundedElectricDipole::GroundedElectricDipole  (constructor)  -----
44
-
45
-
46
-    //--------------------------------------------------------------------------------------
47
-    //       Class:  GroundedElectricDipole
48
-    //      Method:  New()
49
-    // Description:  public constructor
50
-    //--------------------------------------------------------------------------------------
51
-    GroundedElectricDipole* GroundedElectricDipole::New() {
52
-        GroundedElectricDipole*  Obj = new GroundedElectricDipole("GroundedElectricDipole");
53
-        Obj->AttachTo(Obj);
54
-        return Obj;
55
-    }
56
-
57
-    //--------------------------------------------------------------------------------------
58
-    //       Class:  GroundedElectricDipole
59
-    //      Method:  ~GroundedElectricDipole
60
-    // Description:  destructor (protected)
61
-    //--------------------------------------------------------------------------------------
62
-    GroundedElectricDipole::~GroundedElectricDipole () {
63
-
64
-    }  // -----  end of method GroundedElectricDipole::~GroundedElectricDipole  (destructor)  -----
65
-
66
-    //--------------------------------------------------------------------------------------
67
-    //       Class:  GroundedElectricDipole
68
-    //      Method:  Delete
69
-    // Description:  public destructor
70
-    //--------------------------------------------------------------------------------------
71
-    void GroundedElectricDipole::Delete() {
72
-        this->DetachFrom(this);
73
-    }
74
-
75
-    //--------------------------------------------------------------------------------------
76
-    //       Class:  GroundedElectricDipole
77
-    //      Method:  Release
78
-    // Description:  destructor (protected)
79
-    //--------------------------------------------------------------------------------------
80
-    void GroundedElectricDipole::Release() {
81
-        delete this;
82
-    }
83
-
84
-}		// -----  end of Lemma  name  -----
85
-

+ 0
- 342
Modules/LemmaCore/examples/utORS.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utdipolesource.cpp
4
-//
5
-//    Description:
6
-//
7
-//        Version:  0.0
8
-//        Created:  12/02/2009 11:57:14 AM
9
-//       Revision:  none
10
-//       Compiler:  g++ (c++)
11
-//
12
-//         Author:  Trevor Irons (ti)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  United States Geological Survey (USGS)
16
-//
17
-//          Email:  tirons@mines.edu, tirons@usgs.gov
18
-//
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include <iostream>
35
-#include <fstream>
36
-
37
-#include "dipolesource.h"
38
-#include "layeredearth.h"
39
-#include "receiverpoints.h"
40
-#include "emearth1d.h"
41
-#include "WireAntenna.h"
42
-#include "PolygonalWireAntenna.h"
43
-
44
-#if  LEMMAUSEVTK
45
-#include "vtkRenderer.h"
46
-#include "vtkRenderWindow.h"
47
-#include "vtkRenderWindowInteractor.h"
48
-#include "vtkRenderLargeImage.h"
49
-#include "vtkPNGWriter.h"
50
-#include "vtkRectilinearGrid.h"
51
-#include "vtkXMLRectilinearGridWriter.h"
52
-#include "vtkDoubleArray.h"
53
-#include "vtkFieldData.h"
54
-#include "vtkCellData.h"
55
-#endif     // -----  not LEMMA_USE_VTK  -----
56
-
57
-// For testing purposes disable VTK and run scale.sh
58
-//#undef LEMMAUSEVTK
59
-
60
-#include "timer.h"
61
-
62
-using namespace Lemma;
63
-
64
-double randDouble(double low, double high) {
65
-	//srand(time(0));
66
-	double temp;
67
-	/* swap low & high around if the user makes no sense */
68
-	if (low > high)	{
69
-	temp = low;
70
-	low = high;
71
-	high = temp;
72
-	}
73
-	/* calculate the random number & return it */
74
-	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
75
-	* (high - low) + low;
76
-	return temp;
77
-}
78
-
79
-
80
-int main() {
81
-
82
-	// Keep track of time
83
-	jsw_timer timer;
84
-
85
-
86
-	srand(time(0));
87
-
88
-	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
89
-	pa->SetNumberOfFrequencies(1);
90
-	pa->SetFrequency(0, 540000);
91
-    Real Depth  =   370;  // nominal depth
92
-    Real Width  = 0.14;  // transmitter height
93
-    Real Height = 0.70;//  .14;  //.014;  // transmitter width
94
-
95
-
96
-	pa->SetNumberOfPoints(5);
97
-    /*
98
-    pa->SetPoint(0, Vector3r(       0,       0, Depth));
99
-	pa->SetPoint(1, Vector3r(       0,       0, Depth+Height));
100
-	pa->SetPoint(2, Vector3r(       0,   Width, Depth+Height));
101
-	pa->SetPoint(3, Vector3r(       0,   Width, Depth));
102
-	pa->SetPoint(4, Vector3r(       0,       0, Depth));
103
-    */
104
-
105
-    pa->SetPoint(0, Vector3r(   -Width/2., -Height/2., Depth));
106
-	pa->SetPoint(1, Vector3r(    Width/2., -Height/2., Depth));
107
-	pa->SetPoint(2, Vector3r(    Width/2.,  Height/2., Depth));
108
-	pa->SetPoint(3, Vector3r(   -Width/2.,  Height/2., Depth));
109
-	pa->SetPoint(4, Vector3r(   -Width/2., -Height/2., Depth));
110
-
111
-	pa->SetCurrent(1.);
112
-    pa->SetNumberOfTurns(6);
113
-	//Vector3r rp = Vector3r::Random(3);
114
-	//rp << 150., 10, 0.;
115
-	//rp << -27.1456, 15.2350, -1e-3;
116
-	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
117
-	//rp << 3.22806, -13.1548, 14.9695;
118
-	//rp.setRandom(3);
119
-	//std::cout <<  "rp " << rp.transpose() << std::endl;
120
-	//pa->ApproximateWithElectricDipoles(rp);
121
-
122
-
123
-	// Define model
124
-    Real Sigma = 1.0/20. ; // .05;
125
-	VectorXcr sigma(2);
126
-		sigma << Complex(0.,0), Complex(Sigma,0);
127
-	VectorXr  thick(1);
128
-		thick << 10;
129
-	LayeredEarthEM *earth = LayeredEarthEM::New();
130
-		earth->SetNumberOfLayers(2);
131
-		earth->SetLayerConductivity(sigma);
132
-		//earth->SetLayerThickness(thick);
133
-
134
-	// Receivers
135
-	ReceiverPoints *receivers = ReceiverPoints::New();
136
-		Vector3r loc;
137
-		Real ox    =    -5.*Width - .003373;
138
-		Real oy    =    -3.*Height - .003373;
139
-		Real oz    =    Depth - Height/2. - .003373;
140
-		int nx     =   120; // 60;
141
-		int ny     =   180; //  50;
142
-		int nz     =   100; // 40;
143
-		Real hx    =    11.*Width/nx;
144
-		Real hy    =     7.*Height/ny;
145
-		Real hz    =     1.*Height/nz;
146
-
147
-        receivers->SetNumberOfReceivers(nx*ny*nz);
148
-		int ir = 0;
149
-		for (int iz=0; iz<nz; ++iz) {
150
-		for (int iy=0; iy<ny; ++iy) {
151
-		for (int ix=0; ix<nx; ++ix) {
152
-			loc << ox+ix*hx, oy+iy*hy, oz+iz*hz;
153
-			receivers->SetLocation(ir, loc);
154
-			++ ir;
155
-		}
156
-        }
157
-        }
158
-
159
-	// EmEarth
160
-	EMEarth1D  *EmEarth = EMEarth1D::New();
161
-		//EmEarth->AttachWireAntenna(wire);
162
-		EmEarth->AttachWireAntenna(pa);
163
-		EmEarth->AttachLayeredEarthEM(earth);
164
-		EmEarth->AttachReceiverPoints(receivers);
165
-		EmEarth->SetFieldsToCalculate(E);
166
-        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
167
-        EmEarth->SetHankelTransformMethod(ANDERSON801);
168
-
169
-	// Do calculation
170
-	timer.begin();
171
-	EmEarth->CalculateWireAntennaFields();
172
-	Real paTime = timer.end();
173
-	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
174
-
175
-	//EmEarth->AttachWireAntenna(wire);
176
-	//timer.begin();
177
-	//EmEarth->CalculateWireAntennaFields();
178
-	//Real waTime = timer.end();
179
-	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
180
-/*
181
-	depth = depth2;
182
-	std::fstream real("reale_lay.dat", std::ios::out);
183
-	std::fstream imag("image_lay.dat", std::ios::out);
184
-	for (int iz=0; iz<nz; ++iz) {
185
-		Vector3cr temp = receivers->GetEfield(0,iz);
186
-		real << ox << "\t" << oy << "\t" << depth << "\t"
187
-				<< temp(0).real() << "\t" << temp(1).real()
188
-				<< "\t" << temp(2).real() << std::endl;
189
-		imag << ox << "\t" << oy << "\t" << depth << "\t"
190
-				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
191
-				<< "\t" << std::imag(temp(2)) << std::endl;
192
-		depth += dx;
193
-	}
194
-	real.close();
195
-	imag.close();
196
-*/
197
-
198
-	//wire->Delete();
199
-#if  LEMMAUSEVTK
200
-
201
-    // Set Coordinates
202
-    vtkDoubleArray *xCoords = vtkDoubleArray::New();
203
-    xCoords->InsertNextValue(ox-hx/2.);
204
-    double xm1 = ox-hx/2.;
205
-    for (int ix=0; ix<nx; ix++) {
206
-        xCoords->InsertNextValue(xm1 + hx);
207
-        xm1 += hx;
208
-    }
209
-
210
-    vtkDoubleArray *yCoords = vtkDoubleArray::New();
211
-    yCoords->InsertNextValue(oy-hy/2.);
212
-    double ym1 = oy-hy/2.;
213
-    for (int iy=0; iy<ny; iy++) {
214
-        yCoords->InsertNextValue(ym1 + hy);
215
-        ym1 += hy;
216
-    }
217
-
218
-    vtkDoubleArray *zCoords = vtkDoubleArray::New();
219
-    zCoords->InsertNextValue(oz-hz/2.);
220
-    double zm1 = oz-hz/2.;
221
-    for (int iz=0; iz<nz; iz++) {
222
-        zCoords->InsertNextValue(zm1 + hz);
223
-        zm1 += hz;
224
-    }
225
-
226
-    vtkDoubleArray *EReal = vtkDoubleArray::New();
227
-    vtkDoubleArray *EImag = vtkDoubleArray::New();
228
-    vtkDoubleArray *Watts = vtkDoubleArray::New();
229
-    EReal->SetNumberOfComponents(3);
230
-    EImag->SetNumberOfComponents(3);
231
-    Watts->SetNumberOfComponents(1);
232
-
233
-    ir = 0;
234
-    Real WattsTotal(0);
235
-    Real WattsInterior(0);
236
-    for (int iz=0; iz<nz; ++iz) {
237
-    for (int iy=0; iy<ny; ++iy) {
238
-    for (int ix=0; ix<nx; ++ix) {
239
-        //sigmaArray->InsertTuple1(i,  sigma[ix][iy][iz] );
240
-		Vector3cr E = receivers->GetEfield(0, ir);
241
-        EReal-> InsertTuple3(ir, real(E(0)), real(E(1)), real(E(2)));
242
-        EImag-> InsertTuple3(ir, imag(E(0)), imag(E(1)), imag(E(2)));
243
-        //std::cout << std::abs(ox+ix*hx) << "\t"  <<  Width/2. << endl; // && std::abs(oy+iy*hy) > Height/2. ) { // && std::abs(oz+iz*hz - Depth) > Width/2. ) {
244
-        //if ( std::abs( ox+ix*hx ) < Width/2. && std::abs(oy+iy*hy) < Height/2. && std::abs(oz+iz*hz - Depth) < Width/2. ) {
245
-        if ( std::sqrt( std::pow(ox+ix*hx,2)  + std::pow(oz+iz*hz - Depth, 2) ) < .085 && std::abs(oy+iy*hy) < Height/2. ) {
246
-            Watts-> InsertTuple1(ir,  1e-20 );
247
-            WattsInterior += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
248
-        } else {
249
-            Watts-> InsertTuple1(ir, .5* (pow( (std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
250
-            //Watts-> InsertTuple1(ir,  1e-20 );
251
-            WattsTotal += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
252
-        }
253
-		++ ir;
254
-    }
255
-    }
256
-    }
257
-    std::cout << "Total Power: " << Sigma << "\t" << WattsTotal << "\t" << WattsInterior << endl;
258
-
259
-    EReal->SetName("E_real");
260
-    EImag->SetName("E_imag");
261
-    Watts->SetName("Power");
262
-
263
-    vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
264
-        rgrid->SetDimensions(nx+1,ny+1,nz+1);
265
-        rgrid->SetXCoordinates(xCoords);
266
-        rgrid->SetYCoordinates(yCoords);
267
-        rgrid->SetZCoordinates(zCoords);
268
-
269
-        rgrid->GetCellData()->AddArray(EReal);
270
-        rgrid->GetCellData()->AddArray(EImag);
271
-        rgrid->GetCellData()->AddArray(Watts);
272
-        //rgrid->Update();
273
-
274
-    vtkXMLRectilinearGridWriter *gridWrite = vtkXMLRectilinearGridWriter::New();
275
-        gridWrite->SetInputData(rgrid);
276
-        gridWrite->SetFileName("ors.vtr");
277
-        gridWrite->Write();
278
-        //gridWrite->Update();
279
-
280
-#endif
281
-	EmEarth->Delete();
282
-	receivers->Delete();
283
-	earth->Delete();
284
-
285
-#if  LEMMAUSEVTKX
286
-	// Create the usual rendering stuff.
287
-	vtkRenderer           *renderer = vtkRenderer::New();
288
-	vtkRenderWindow         *renWin = vtkRenderWindow::New();
289
-	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
290
-
291
-	std::cout << "wire antennae approximating " << std::endl;
292
-	loc << 0, .5*Width, Depth+.5*Height;
293
-	pa->ApproximateWithElectricDipoles(loc);
294
-    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
295
-
296
-    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
297
-	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
298
-		pdipActors[id] = pa->GetVtkActor(id);
299
-		renderer->AddActor(pdipActors[id]);
300
-	}
301
-
302
-    /*
303
-    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
304
-	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
305
-		dipActors[id] = wire->GetVtkActor(id);
306
-		renderer->AddActor(dipActors[id]);
307
-	}
308
-    */
309
-
310
-	renderer->SetBackground(1,1,1);
311
-
312
-	// Render the window
313
-	renWin->AddRenderer(renderer);
314
-	renWin->SetWindowName("Wire antennae");
315
-
316
-	iren->SetRenderWindow(renWin);
317
-	iren->Initialize();
318
-	iren->Start();
319
-	iren->Render();
320
-
321
-    #if 0
322
-	cout << "Enter File name?: ";
323
-	std::string pngName;
324
-	std::cin >> pngName;
325
-	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
326
-	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
327
-	renlarge->SetInput(renderer);
328
-	renlarge->SetMagnification(2);
329
-	pngwrite->SetInputConnection(renlarge->GetOutputPort());
330
-	pngName.append(".png");
331
-	pngwrite->SetFileName(pngName.c_str());
332
-	pngwrite->Write();
333
-    #endif
334
-
335
-#endif     // -----  not LEMMA_USE_VTK  -----
336
-
337
-
338
-	//std::cout << *pa << std::endl;
339
-	//pa->Delete();
340
-
341
-	return 0;
342
-}

+ 0
- 34
Modules/LemmaCore/examples/utQWEKey.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      02/12/2014 01:01:29 PM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-#include "QWEKey.h"
21
-using namespace Lemma;
22
-
23
-int main() {
24
-
25
-    // TODO chech
26
-
27
-    QWEKey* QWE = QWEKey::New();
28
-    QWE->TestPrivate( 5 );
29
-    QWE->Delete();
30
-
31
-    return 0;
32
-}
33
-
34
-

+ 0
- 86
Modules/LemmaCore/examples/utSerialize.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      09/29/2014 01:31:26 PM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-#include "Lemma"
21
-
22
-using namespace Lemma;
23
-
24
-#ifdef  HAVE_YAMLCPP
25
-#include "yaml-cpp/yaml.h"
26
-
27
-int main() {
28
-
29
-    std::ofstream ofstr("output.yaml");
30
-    //ofstr << "%YAML 1.2\n" << "---\n";
31
-    //ofstr << "LEMMA_CLASSES:\n";
32
-
33
-    // This works for individual classes or even groups of unrelated classes. But
34
-    // How should references work? One option would be to hack YAML and allow for references
35
-    // across 'Docs'. This is maybe undesireable, as then it's not valid YAML anymore.
36
-    // OR we could have some other kind of IDENTIFIER that could be used and Connections could be
37
-    // made AFTER the whole file is processed?
38
-
39
-    // Alternative is each class is written to it's own file. And then implicit on the Serialize function, the file tags are written
40
-    // into the YAML instead of the pointer. Alternatively, tags could do this too.
41
-
42
-    // Or file could be saved as pointer.yaml
43
-
44
-    // *
45
-    // * Or a file contains all the subclasses it point to. So that it's self-enclosed. This is nice as it's quite
46
-    // * flexible. The only downwside is possible repeat of classes. Basically if the API is careful though, only 1
47
-    // * instance will need to be serialized.
48
-    // *
49
-
50
-
51
-    TEMTransmitter* Seq = TEMTransmitter::New();
52
-        Seq->SetRepFrequency( 20, KHZ );
53
-        VectorXr Times (18);
54
-        VectorXr Amps (18);
55
-        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
56
-                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
57
-        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
58
-                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
59
-        Seq->SetWaveform(Times, Amps, MILLISEC);
60
-    // OK dump to disk
61
-    ofstr << *Seq ;
62
-    ofstr.close();
63
-    Seq->Delete();
64
-
65
-
66
-    // OK now load
67
-    std::ifstream ifstr("output.yaml");
68
-    std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
69
-
70
-    TEMTransmitter* Seq2 = TEMTransmitter::DeSerialize( nodes[0] );
71
-    std::cout << "Loaded\n" << *Seq2;
72
-    Seq2->Delete();
73
-    ifstr.close();
74
-
75
-    //YAML::Node nodes = YAML::LoadFile("output.yaml");
76
-    //std::cout << nodes[0] << std::endl;
77
-    //std::cout << nodes[1] << std::endl;
78
-
79
-    exit(EXIT_SUCCESS);
80
-}
81
-
82
-#else
83
-int main() {
84
-
85
-}
86
-#endif

+ 0
- 197
Modules/LemmaCore/examples/utTEMSurvey.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      10/06/2014 10:37:30 AM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-#include "Lemma"
21
-using namespace Lemma;
22
-
23
-int main() {
24
-
25
-    // Each pulse sequence functions as an autonomous transmitter. A record may contain multiple transmitters (moments).
26
-    // There is some small overhead for wire loop locations, but generality is retained doing this, as well as monitoring of
27
-    // slight changes in geometry for both pulses.
28
-    TEMTransmitter* TxHM = TEMTransmitter::New();
29
-        TxHM->SetRepFrequency( 20, KHZ );
30
-        VectorXr Times (18);
31
-        VectorXr Amps (18);
32
-        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
33
-                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
34
-        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
35
-                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
36
-        TxHM->SetWaveform( Times, Amps, MILLISEC );
37
-        // Define wire loop
38
-        TxHM->SetNumberOfPoints(8);
39
-        TxHM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
40
-        TxHM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
41
-        TxHM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
42
-        TxHM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
43
-        TxHM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
44
-        TxHM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
45
-        TxHM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
46
-        TxHM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
47
-        TxHM->SetNumberOfTurns(8);
48
-
49
-    // Each Transmitter needs its own `Receiver(s)', the only difference may be the time gates, but that's OK.
50
-    //     It's a minor amount of overhead for greatly improved genearality. As sometimes different gates are
51
-    //     masked.
52
-    TEMInductiveReceiver* RxHM = TEMInductiveReceiver::New();
53
-        RxHM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
54
-        RxHM->SetMoment( 1 );                  // Normalized
55
-        RxHM->SetReferenceTime( 4., MILLISEC );
56
-        RxHM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
57
-
58
-        // Gate Centres  ms
59
-        VectorXr centres (37);
60
-        centres << 7.15000000e-04,   2.21500000e-03,   4.21500000e-03,   6.21500000e-03,
61
-                   8.21500000e-03,   1.02150000e-02,   1.22150000e-02,   1.47150000e-02,
62
-                   1.82150000e-02,   2.27150000e-02,   2.82150000e-02,   3.52150000e-02,
63
-                   4.42150000e-02,   5.57150000e-02,   7.02150000e-02,   8.82150000e-02,
64
-                   1.10715000e-01,   1.38715000e-01,   1.74215000e-01,   2.19715000e-01,
65
-                   2.76715000e-01,   3.48715000e-01,   4.39715000e-01,   5.53715000e-01,
66
-                   6.97715000e-01,   8.79215000e-01,   1.10771500e+00,   1.39621500e+00,
67
-                   1.76021500e+00,   2.21871500e+00,   2.79671500e+00,   3.52571500e+00,
68
-                   4.44471500e+00,   5.60321500e+00,   7.06321500e+00,   8.90421500e+00,
69
-                   1.10667200e+01;
70
-        //centres.array() += 4.;
71
-
72
-        // Gate Widths  ms
73
-        VectorXr widths (37);
74
-        widths <<   4.30000000e-04,   1.43000000e-03,   3.43000000e-03,   5.43000000e-03,
75
-                    7.43000000e-03,   9.43000000e-03,   1.14300000e-02,   1.34300000e-02,
76
-                    1.64300000e-02,   2.04300000e-02,   2.54300000e-02,   3.14300000e-02,
77
-                    3.94300000e-02,   4.94300000e-02,   6.24300000e-02,   7.84300000e-02,
78
-                    9.84300000e-02,   1.23430000e-01,   1.54430000e-01,   1.94430000e-01,
79
-                    2.45430000e-01,   3.08430000e-01,   3.89430000e-01,   4.90430000e-01,
80
-                    6.17430000e-01,   7.78430000e-01,   9.80430000e-01,   1.23543000e+00,
81
-                    1.55743000e+00,   1.96343000e+00,   2.47443000e+00,   3.11943000e+00,
82
-                    3.93243000e+00,   4.95743000e+00,   6.24943000e+00,   7.87743000e+00,
83
-                    9.93143000e+00;
84
-
85
-        RxHM->SetWindows(centres, widths, MILLISEC);
86
-
87
-    TEMTransmitter* TxLM = TEMTransmitter::New();
88
-        TxLM->SetRepFrequency( 20, KHZ );
89
-        VectorXr TimesLM (18);
90
-        VectorXr AmpsLM (18);
91
-
92
-        TimesLM << -8.00000E-004, -7.86965E-004, -7.66493E-004, -7.23688E-004,
93
-                   -6.39938E-004, -5.16174E-004, -3.93340E-004, -2.63993E-004,
94
-                   -1.43952E-004, -7.15990E-006, -2.50712E-006,  0.00000E+000,
95
-                    2.19597E-007,  1.47193E-006,  3.34398E-006,  4.68669E-006,
96
-                    5.96484E-006,  7.04934E-006;
97
-        TimesLM.array() = TimesLM.array() + 8e-4;  // Valgrind Hack += yields error. Correct for SkyTEM convention
98
-
99
-
100
-        AmpsLM <<  0.00000E+000,  3.67188E-002,  6.17188E-002,  1.17969E-001,
101
-                   2.14844E-001,  3.28906E-001,	 4.75781E-001,  6.30469E-001,
102
-                   7.82031E-001,  9.92969E-001,	 1.00000E+000,  1.00000E+000,
103
-                   9.63459E-001,  6.01030E-001,  2.29652E-001,  8.64702E-002,
104
-                   2.53196E-002,  0.00000E+000;
105
-        AmpsLM.array() = AmpsLM.array() * 8.;   // Also correct for SkyTEM convention in .geo file
106
-
107
-        TxLM->SetWaveform( TimesLM, AmpsLM, SEC );
108
-        // Define wire loop
109
-        TxLM->SetNumberOfPoints(8);
110
-        TxLM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
111
-        TxLM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
112
-        TxLM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
113
-        TxLM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
114
-        TxLM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
115
-        TxLM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
116
-        TxLM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
117
-        TxLM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
118
-        TxLM->SetNumberOfTurns(8);
119
-
120
-
121
-    TEMInductiveReceiver* RxLM = TEMInductiveReceiver::New();
122
-        RxLM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
123
-        RxLM->SetMoment( 1 );                  // Normalized
124
-        RxLM->SetReferenceTime( 8e-4, SEC );
125
-        RxLM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
126
-
127
-        // Gate Centres  ms
128
-        VectorXr centresLM (26);
129
-            centresLM << 7.150000E-07, 2.215000E-06, 4.215000E-06, 6.215000E-06, 8.215000E-06,
130
-                         1.021500E-05, 1.221500E-05, 1.471500E-05, 1.821500E-05, 2.271500E-05,
131
-                         2.821500E-05, 3.521500E-05, 4.421500E-05, 5.571500E-05, 7.021500E-05,
132
-                         8.821500E-05, 1.107150E-04, 1.387150E-04, 1.742150E-04, 2.197150E-04,
133
-                         2.767150E-04, 3.487150E-04, 4.397150E-04, 5.537150E-04, 6.977150E-04,
134
-                         8.792150E-04;
135
-
136
-        VectorXr widthsLM (26);
137
-            widthsLM << 5.700000E-07, 1.570000E-06, 1.570000E-06, 1.570000E-06, 1.570000E-06,
138
-                        1.570000E-06, 1.570000E-06, 2.570000E-06, 3.570000E-06, 4.570000E-06,
139
-                        5.570000E-06, 7.570000E-06, 9.570000E-06, 1.257000E-05, 1.557000E-05,
140
-                        1.957000E-05, 2.457000E-05, 3.057000E-05, 3.957000E-05, 5.057000E-05,
141
-                        6.257000E-05, 8.057000E-05, 1.005700E-04, 1.265700E-04, 1.605700E-04,
142
-                        2.015700E-04;
143
-
144
-        RxLM->SetWindows(centresLM, widthsLM, SEC);
145
-
146
-
147
-
148
-    // Specifies survey, this is the Glue Class, the top of the structure, etc.
149
-    TEMSurvey* Survey = TEMSurvey::New();
150
-        Survey->SetNumberOfLines(1);  // Flight lines or
151
-                                      // Internally each line is a class? But that's sort of hidden to the
152
-                                      // end user. Having each line seperate is nice for constrained inversion, where
153
-                                      // each line is a nice thing to deal with.
154
-        Survey->GetLine(0)->SetNumberOfRecords(1);    // Each Record then contains everything needed for modelling response curve(s)
155
-        Survey->GetLine(0)->GetRecord(0)->SetNumberOfPulseSequences( 1 );
156
-        Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 0, TxHM, RxHM );
157
-        //Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 1, TxHM, RxHM );
158
-
159
-
160
-    LayeredEarthEM* Earth = LayeredEarthEM::New();
161
-        Earth->SetNumberOfLayers(31);
162
-        Earth->SetLayerThickness( (VectorXr(29) <<  5.00E+00,  5.40E+00,
163
-             5.80E+00, 6.30E+00, 6.80E+00, 7.30E+00, 7.80E+00, 8.50E+00,
164
-             9.10E+00, 9.80E+00, 1.06E+01, 1.14E+01, 1.23E+01, 1.33E+01,
165
-             1.43E+01, 1.54E+01, 1.66E+01, 1.79E+01, 1.93E+01, 2.08E+01,
166
-             2.25E+01, 2.42E+01, 2.61E+01, 2.81E+01, 3.03E+01, 3.27E+01,
167
-             3.52E+01, 3.80E+01, 4.10E+01).finished() );
168
-
169
-        VectorXcr rho = ( (VectorXcr(31) << 0, 1.54E+01, 4.21E+01,
170
-            9.25E+01, 1.26E+02, 1.17E+02, 7.57E+01, 3.21E+01, 1.40E+01, 1.96E+01,
171
-            2.67E+01, 2.56E+01, 2.00E+01, 1.86E+01, 2.31E+01, 2.97E+01, 3.50E+01,
172
-            3.79E+01, 3.75E+01, 3.32E+01, 2.52E+01, 1.57E+01, 8.38E+00, 5.38E+00,
173
-            5.49E+00, 6.34E+00, 7.07E+00, 7.81E+00, 8.67E+00, 9.59E+00, 1.05E+01
174
-        ).finished() ); // 200 Ohm-m half space
175
-
176
-        Earth->SetLayerConductivity( 1./rho.array() );
177
-        // ALL SET UP
178
-        std::cout << *Survey << std::endl;
179
-
180
-        // OK do your thinc
181
-        //DataTEM* data =
182
-        Survey->ForwardModel( Earth );
183
-
184
-
185
-    // Clean up
186
-
187
-
188
-
189
-//     //Survey->Delete();
190
-//     Earth->Delete();
191
-//
192
-//     TxHM->Delete();
193
-//     RxHM->Delete();
194
-//     TxLM->Delete();
195
-//     RxLM->Delete();
196
-
197
-}

+ 0
- 168
Modules/LemmaCore/examples/utXMLParse.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      04/03/2014 01:08:28 PM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-#include "Lemma"
21
-#ifdef TINYXMLSUPPORT
22
-#include "tinyxml2.h"
23
-
24
-#include <ctime>
25
-using namespace tinyxml2;
26
-using namespace Lemma;
27
-
28
-void ParseTEM( XMLElement* element );
29
-
30
-template <typename T>
31
-std::vector<T> ReadLine( const int& nr, const std::string& line ) ;
32
-
33
-int main(int argc, char **argv) {
34
-
35
-    if ( argc > 1 ) {
36
-		XMLDocument* doc = new XMLDocument();
37
-		clock_t startTime = clock();
38
-		doc->LoadFile( argv[1] );
39
-		clock_t loadTime = clock();
40
-		int errorID = doc->ErrorID();
41
-
42
-        // Get some info
43
-        //static const char* xml = "<element/>";
44
-        //doc->Parse( xml );
45
-        //XMLNode* titleElement = doc->FirstChild(); //Element()->FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" );
46
-        XMLElement* titleElement = doc->FirstChildElement( ); //->FirstChildElement( "TITLE" );
47
-        //const char* title = titleElement->Value(); //GetText();
48
-        const char* title = titleElement->Value(); //GetText();
49
-
50
-        printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
51
-        printf( "Name of FirstChildElement: %s\n", title );
52
-
53
-        if (strcmp ( titleElement->Value(), "NGXFile" ) != 0) {
54
-            std::cout <<"NGX file was not detected!" << std::endl;
55
-            exit(EXIT_FAILURE);
56
-        } else {
57
-            //std::cout <<
58
-            //titleElement->FirstAttribute() ;//"type");// << std::endl;;
59
-            if (strcmp(  titleElement->FindAttribute("type")->Value(),"tem") == 0) {
60
-                // Parse TEM file
61
-                ParseTEM( titleElement );
62
-            } else {
63
-                std::cout << "No parser for NGX filetype " << titleElement->FindAttribute("type")->Value() << std::endl;
64
-                std::cout << "YOU should write one!\n";
65
-                exit(EXIT_FAILURE);
66
-            }
67
-
68
-        }
69
-
70
-		delete doc; doc = 0;
71
-
72
-        clock_t deleteTime = clock();
73
-		if ( !errorID ) {
74
-			printf( "========================================================\n");
75
-			printf( "Load time=%u\n",   (unsigned)(loadTime - startTime) );
76
-			printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
77
-			printf( "Total time=%u\n",  (unsigned)(deleteTime - startTime) );
78
-		}
79
-
80
-
81
-		exit(0);
82
-	} else {
83
-        std::cout << "Enter NGX.x file to parse\n";
84
-    }
85
-}
86
-
87
-void ParseTEM( XMLElement* element ) {
88
-
89
-    std::cout << "This is a NGX.t file" << std::endl;
90
-
91
-
92
-    if (strcmp( element->FindAttribute("version")->Value(),"0.1") == 0) {
93
-        std::cout << "Version 0.1 detected" << std::endl;
94
-    } else {
95
-        std::cout << "Unsupported NGX.t version" << std::endl;
96
-    }
97
-
98
-    // system description
99
-    std::cout << "System description" << std::endl;
100
-    std::cout << element->FirstChildElement("system")->FirstChildElement("name")->GetText() << std::endl;
101
-    XMLElement* system = element->FirstChildElement("system");
102
-        int ntx = atoi(system->FirstChildElement("transmitters")->FindAttribute("num")->Value());
103
-        std::cout << "numTx = " << ntx << std::endl;
104
-        // OK Parse Transmitter(s)
105
-        XMLElement* tx = system->FirstChildElement("transmitters")->FirstChildElement("transmitter");
106
-        //    std::cout << "Tx id = " << tx->FindAttribute("id")->Value() << std::endl;
107
-        //std::cout << tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
108
-        //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
109
-        for (int it=0; it<ntx; ++it) {
110
-            std::cout << "\nTransmitter " << it << std::endl;
111
-            if (it > 0) tx = tx->NextSiblingElement();
112
-            int npoints = atoi(tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value());
113
-
114
-            std::cout << "points= " << npoints; // tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
115
-            std::vector<Real> LP = ReadLine<Real>( npoints, std::string(tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText()) );
116
-            for (int ii=0; ii<npoints; ++ii) std::cout << "\t"<< LP[ii] ;
117
-            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
118
-            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("easting.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
119
-        }
120
-    std::cout << "\nEND system description\n";
121
-
122
-}
123
-
124
-
125
-template <typename T>
126
-std::vector<T> ReadLine( const int& nr, const std::string& line ) {
127
-
128
-    std::vector<T>   lineData;
129
-    std::stringstream  lineStream(line);
130
-
131
-    T value;
132
-    while(lineStream >> value) {
133
-        lineData.push_back(value);
134
-    }
135
-    return lineData;
136
-}
137
-#else
138
-
139
-int main() {
140
-    std::cout << "you have to compile lemma with external tinyxml library to use this" << std::endl;
141
-}
142
-
143
-#endif
144
-
145
-    //--------------------------------------------------------------------------------------
146
-    //       Class:  ASCIIParser
147
-    //      Method:  ReadInts
148
-    //--------------------------------------------------------------------------------------
149
-//     std::vector<int> ReadInts ( const int& nr ) {
150
-//         std::string buf;
151
-//         char *dump = new char[BufferSize];
152
-//         std::vector<int> vals(0);
153
-//         while (input >> buf) {
154
-//             if (buf.substr(0, CommentString.size()) == CommentString) {
155
-//                 input.getline(dump, BufferSize);
156
-//             } else {
157
-//                 vals.push_back( atoi(buf.c_str() ));
158
-//             }
159
-//             if (static_cast<int>(vals.size()) == nr) {
160
-//                 delete [] dump;
161
-//                 return vals;
162
-//             }
163
-//
164
-//         }
165
-//         delete [] dump;
166
-//         return vals;
167
-//     }		// -----  end of method ASCIIParser::ReadInts  -----
168
-

+ 0
- 67
Modules/LemmaCore/examples/utYAMLconfig.cpp View File

1
-#ifdef HAVE_YAMLCPP
2
-
3
-#include "yaml-cpp/yaml.h"
4
-#include "yaml-cpp/eventhandler.h"
5
-#include <fstream>
6
-#include <iostream>
7
-#include <vector>
8
-
9
-struct Params {
10
-	bool hasFile;
11
-	std::string fileName;
12
-};
13
-
14
-Params ParseArgs(int argc, char **argv) {
15
-	Params p;
16
-
17
-	std::vector<std::string> args(argv + 1, argv + argc);
18
-
19
-	return p;
20
-}
21
-
22
-class NullEventHandler: public YAML::EventHandler
23
-{
24
-public:
25
-	virtual void OnDocumentStart(const YAML::Mark&) {}
26
-	virtual void OnDocumentEnd() {}
27
-
28
-	virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
29
-	virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
30
-	virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
31
-
32
-	virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
33
-	virtual void OnSequenceEnd() {}
34
-
35
-	virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
36
-	virtual void OnMapEnd() {}
37
-};
38
-
39
-void parse(std::istream& input)
40
-{
41
-	try {
42
-		YAML::Node doc = YAML::Load(input);
43
-		std::cout << doc << "\n";
44
-	} catch(const YAML::Exception& e) {
45
-		std::cerr << e.what() << "\n";
46
-	}
47
-}
48
-
49
-int main(int argc, char **argv)
50
-{
51
-	Params p = ParseArgs(argc, argv);
52
-
53
-	if(argc > 1) {
54
-		std::ifstream fin;
55
-		fin.open(argv[1]);
56
-		parse(fin);
57
-	} else {
58
-		parse(std::cin);
59
-	}
60
-
61
-	return 0;
62
-}
63
-#else
64
-int main() {
65
-}
66
-#endif
67
-

+ 0
- 84
Modules/LemmaCore/examples/utgaussquad.cpp View File

1
-// ===========================================================================
2
-// 
3
-//       Filename:  utqaussquad.cpp
4
-// 
5
-//    Description:  Test for gaussian quadrature algorithm
6
-// 
7
-//        Version:  0.0
8
-//        Created:  10/05/2010 08:54:26 AM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++
11
-// 
12
-//         Author:  M. Andy Kass (MAK)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  Broken Spoke Development, LLC
16
-//
17
-//          Email:  mkass@numericalgeo.com
18
-// 
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "Lemma"
35
-using namespace Lemma;
36
-using namespace std;
37
-
38
-#ifdef LEMMAUSEVTK
39
-#include "matplot.h"
40
-using namespace matplot;
41
-#endif
42
-
43
-int main() {
44
-
45
-	int N = 600;
46
-	int upb = 5;
47
-	int lowb = -1;
48
-	VectorXr func(N);
49
-	VectorXr wx(N);
50
-	Real integrationres,actres;
51
-
52
-	gaussianquadrature *lgqw = gaussianquadrature::New();
53
-	lgqw->SetFreqs(N,upb,lowb);
54
-	lgqw->CalcAW();
55
-
56
-	wx=lgqw->GetAbscissae();
57
-	func=cos(wx.array());
58
-//	for (int ii=0;ii<N;++ii) {
59
-//		cout << wx(ii) << "  " << func(ii) << endl;
60
-//	}
61
-
62
-	lgqw->SetFunc(func);
63
-	lgqw->Integrate();
64
-	integrationres=lgqw->GetResult();
65
-
66
-	actres = -sin((Real)upb)+sin((Real)lowb);
67
-	
68
-	cout << "Gaussian Quadrature Result: " << integrationres << endl;
69
-	cout << "Actual Result: " << actres << endl;
70
-	
71
-		
72
-	//Plot things
73
-	#ifdef LEMMAUSEVTK
74
-	double colour1[3] = {0.0,0.0,1.0};
75
-
76
-	Plot2D_VTK p1("X", "Y", 800,600);
77
-	p1.plot(wx,func,colour1,".-");
78
-	p1.show();
79
-
80
-	#endif
81
-
82
-	return EXIT_SUCCESS;
83
-}
84
-

+ 0
- 258
Modules/LemmaCore/examples/utgmrprint.cpp View File

1
-// ===========================================================================
2
-//   This file is distributed with Lemma,
3
-//
4
-//       Filename:  utsnmrinversion1d.cpp
5
-//
6
-//        Created:  10/07/2010 08:57:04 AM
7
-//       Compiler:  Tested with g++, icpc, and MSVC 2010
8
-//
9
-//         Author:  Trevor Irons (ti)
10
-//
11
-//   Organisation:  Colorado School of Mines (CSM)
12
-//                  United States Geological Survey (USGS)
13
-//
14
-//          Email:  tirons@mines.edu, tirons@usgs.gov
15
-//
16
-//  This program is free software: you can redistribute it and/or modify
17
-//  it under the terms of the GNU General Public License as published by
18
-//  the Free Software Foundation, either version 3 of the License, or
19
-//  (at your option) any later version.
20
-//
21
-//  This program is distributed in the hope that it will be useful,
22
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
-//  GNU General Public License for more details.
25
-//
26
-//  You should have received a copy of the GNU General Public License
27
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
-//
29
-// ===========================================================================
30
-
31
-/**
32
-  @file
33
-  @author   Trevor Irons
34
-  @date     10/07/2010
35
-  @version   0.0
36
- **/
37
-
38
-#ifdef LEMMAUSEVTK
39
-#include "vtkRenderer.h"
40
-#include "vtkRenderWindow.h"
41
-#include "vtkRenderWindowInteractor.h"
42
-#include "vtkPNGWriter.h"
43
-#include "vtkRenderLargeImage.h"
44
-#endif
45
-
46
-#include "receiverpoints.h"
47
-#include "emearth1d.h"
48
-#include "PolygonalWireAntenna.h"
49
-
50
-using namespace Lemma;
51
-
52
-std::vector<Real>  readinpfile(const std::string& fname);
53
-
54
-int main(int argc, char** argv) {
55
-
56
-    std::cout <<
57
-    "\n"
58
-    << "hantenna - a programme for computing the h field from polygonal wire\n"
59
-    << "loop sources \n\n"
60
-    << "The following copyrights apply to this application:\n"
61
-    << "Copyright (C) 2009, 2010, 2011, 2012 Colorado School of Mines\n"
62
-    << "Copyright (C) 2009, 2010, 2011, 2012 Trevor Irons\n"
63
-    << "Copyright (C) 2011 Broken Spoke Development, LLC\n\n"
64
-    << "hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
65
-    << "More information may be found at https://lemmasoftware.org\n\n"
66
-    << "This program is free software: you can redistribute it and/or modify\n"
67
-    << "it under the terms of the GNU General Public License as published by\n"
68
-    << "the Free Software Foundation, either version 3 of the License, or\n"
69
-    << "(at your option) any later version.\n\n"
70
-
71
-    << "This program is distributed in the hope that it will be useful,\n"
72
-    << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
73
-    << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
74
-    << "GNU General Public License for more details.\n\n"
75
-
76
-    << "You should have received a copy of the GNU General Public License\n"
77
-    << "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n";
78
-
79
-    if (argc < 4) {
80
-        std::cout << "usage: hantenna.exe  trans.inp cond.inp points.inp \n";
81
-        exit(0);
82
-    }
83
-
84
-    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
85
-    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
86
-    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
87
-
88
-    //////////////////////////////////////
89
-    // Define transmitter
90
-    PolygonalWireAntenna* trans = PolygonalWireAntenna::New();
91
-        trans->SetNumberOfPoints((int)(Trans[0]));
92
-        int ip=1;
93
-        for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
94
-            trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
95
-        }
96
- 	    trans->SetNumberOfFrequencies(1);
97
- 	    trans->SetFrequency(0, Trans[ip]);
98
-        trans->SetCurrent(Trans[ip+1]);
99
-
100
-	// Receivers
101
- 	ReceiverPoints *receivers = ReceiverPoints::New();
102
-        int nx = (int)Points[0];
103
-        int ny = (int)Points[1];
104
-        int nz = (int)Points[2];
105
-        Real ox = Points[3];
106
-        Real oy = Points[4];
107
-        Real oz = Points[5];
108
-     	Vector3r loc;
109
-        VectorXr dx(nx-1); // TODO map the dx, dy, dz vectors
110
-        VectorXr dy(ny-1);
111
-        VectorXr dz(nz-1);
112
-        ip = 6;
113
-        int ir = 0;
114
-        for ( ; ip <6+nx-1; ++ip) {
115
-            dx[ir] = Points[ip];
116
-            ++ir;
117
-        }
118
-        ir = 0;
119
-        for ( ; ip <6+ny-1+nx-1; ++ip) {
120
-            dy[ir] = Points[ip];
121
-            ++ir;
122
-        }
123
-        ir = 0;
124
-        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
125
-            dz[ir] = Points[ip];
126
-            ++ir;
127
-        }
128
- 		receivers->SetNumberOfReceivers(nx*ny*nz);
129
- 		ir = 0;
130
-        Real pz  = oz;
131
- 		for (int iz=0; iz<nz; ++iz) {
132
- 		    Real py    =  oy;
133
- 		    for (int iy=0; iy<ny; ++iy) {
134
- 		        Real px    =  ox;
135
- 		        for (int ix=0; ix<nx; ++ix) {
136
- 			        loc << px, py, pz;
137
- 			        receivers->SetLocation(ir, loc);
138
- 			        if (ix < nx-1) px += dx[ix];
139
- 			        ++ ir;
140
-     	        }
141
-                if (iy<ny-1) py += dy[iy];
142
-            }
143
-            if (iz<nz-1) pz += dz[iz];
144
-        }
145
-
146
-    ////////////////////////////////////
147
-    // Define model
148
-    LayeredEarthEM *earth = LayeredEarthEM::New();
149
-    VectorXcr sigma;
150
-    VectorXr  thick;
151
- 	earth->SetNumberOfLayers(CondMod[0]+1);
152
- 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
153
-    thick.resize(CondMod[0]-1);
154
-    int ilay=1;
155
-    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
156
-        sigma(ilay/2+1) =  1./CondMod[ilay];
157
-        thick(ilay/2) =  CondMod[ilay+1];
158
-    }
159
-    sigma(ilay/2+1) = 1./ CondMod[ilay];
160
-	earth->SetLayerConductivity(sigma);
161
-    if (thick.size() > 0) earth->SetLayerThickness(thick);
162
-
163
-	EMEarth1D  *EmEarth = EMEarth1D::New();
164
-		EmEarth->AttachWireAntenna(trans);
165
-		EmEarth->AttachLayeredEarthEM(earth);
166
-		EmEarth->AttachReceiverPoints(receivers);
167
-		EmEarth->SetFieldsToCalculate(H);
168
-        EmEarth->CalculateWireAntennaFields();
169
-
170
-    #ifdef LEMMAUSEVTK
171
-	vtkRenderer           *renderer = vtkRenderer::New();
172
-	vtkRenderWindow         *renWin = vtkRenderWindow::New();
173
-	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
174
-    trans->ApproximateWithElectricDipoles( (VectorXr (3) << 0,0,0).finished() );
175
-	vtkActor **dipActors = new vtkActor*[trans->GetNumberOfDipoles()];
176
-	for (int id=0; id<trans->GetNumberOfDipoles(); ++id) {
177
-		dipActors[id] = trans->GetVtkActor(id);
178
-		renderer->AddActor(dipActors[id]);
179
-	}
180
-    vtkActor *hfield  = receivers->GetVtkGlyphActor (HFIELDREAL, 3, 1e2, 0);
181
- 	vtkActor *hfieldi = receivers->GetVtkGlyphActor (HFIELDIMAG, 3, 1e2, 0);
182
-    hfieldi->GetProperty()->SetColor(1,0,1);
183
- 	hfield->GetProperty()->SetColor(0,1,0);
184
- 	renderer->AddActor(hfield);
185
- 	renderer->AddActor(hfieldi);
186
-	renderer->SetBackground(0,0,0);
187
-	// Render the window
188
-	renWin->AddRenderer(renderer);
189
-	iren->SetRenderWindow(renWin);
190
-	iren->Initialize();
191
-	iren->Start();
192
-	iren->Render();
193
-	cout << "Enter File name?: ";
194
-	std::string pngName;
195
-	std::cin >> pngName;
196
-	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
197
-	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
198
-	renlarge->SetInput(renderer);
199
-	renlarge->SetMagnification(2);
200
-	pngwrite->SetInputConnection(renlarge->GetOutputPort());
201
-	pngName.append(".png");
202
-	pngwrite->SetFileName(pngName.c_str());
203
-	pngwrite->Write();
204
-	iren->Delete();
205
-	renWin->Delete();
206
-	renderer->Delete();
207
-    #endif
208
-
209
-    ////////////////////////////////////
210
-    // Report
211
- 	std::fstream hreal("hfield.dat", std::ios::out);
212
-    hreal << *trans << std::endl;
213
-    hreal << *earth << std::endl;
214
-    hreal << "Right hand coordinate system, z is positive down\n";
215
-    hreal << "x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
216
-    hreal.precision(8);
217
-    int i=0;
218
-	for (int iz=0; iz<nz; ++iz) {
219
-	for (int iy=0; iy<ny; ++iy) {
220
-	for (int ix=0; ix<nx; ++ix) {
221
-        hreal << receivers->GetLocation(i).transpose() << "\t";
222
- 		hreal << std::real(receivers->GetHfield(0, i).transpose()[0]) << "\t";
223
- 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[0]) << "\t";
224
- 		hreal << std::real(receivers->GetHfield(0, i).transpose()[1]) << "\t";
225
- 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[1]) << "\t";
226
- 		hreal << std::real(receivers->GetHfield(0, i).transpose()[2]) << "\t";
227
- 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[2]) << "\n";
228
-        ++i;
229
-    }
230
-    }
231
-    }
232
-    hreal.close();
233
-
234
-    // Clean up
235
-    EmEarth->Delete();
236
-    earth->Delete();
237
-    receivers->Delete();
238
-    trans->Delete();
239
-}
240
-
241
-std::vector<Real>  readinpfile(const std::string& fname) {
242
-    std::string buf;
243
-    char dump[255];
244
-    std::vector<Real> vals;
245
-    std::fstream input(fname.c_str(), std::ios::in);
246
-    if (input.fail()) {
247
-        std::cerr << "Input file " << fname << " failed to open\n";
248
-        exit(EXIT_FAILURE);
249
-    }
250
-    while (input >> buf) {
251
-        if (buf.substr(0,2) == "//") {
252
-            input.getline(dump, 255);
253
-        } else {
254
-            vals.push_back( atof(buf.c_str() ));
255
-        }
256
-    }
257
-    return vals;
258
-}

+ 0
- 93
Modules/LemmaCore/examples/uthankel2.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  uthankel2.cpp
4
-//
5
-//    Description:
6
-//
7
-//        Version:  0.0
8
-//        Created:  05/14/2010 10:26:59 AM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
-//
12
-//         Author:  Trevor Irons (ti)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  United States Geological Survey (USGS)
16
-//
17
-//          Email:  tirons@mines.edu, tirons@usgs.gov
18
-//
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "hankeltransformhankel2.h"
35
-#include "hankeltransformgaussianquadrature.h"
36
-#include "kernelem1d.h"
37
-#include "layeredearthem.h"
38
-
39
-using namespace Lemma;
40
-
41
-int main() {
42
-
43
-	// Define model
44
-	LayeredEarthEM *Earth = LayeredEarthEM::New();
45
-		VectorXcr sigma(3);
46
-		sigma << 0., .1, 0.01;
47
-		VectorXr  thick(1);
48
-		thick << 10;
49
-		Earth->SetNumberOfLayers(3);
50
-		Earth->SetLayerConductivity(sigma);
51
-		Earth->SetLayerThickness(thick);
52
-
53
-	// Source
54
-	// Test with a single dipole
55
-	DipoleSource *dipole = DipoleSource::New();
56
-		dipole->SetMoment(2);
57
-		dipole->SetType(MAGNETICDIPOLE);
58
-		dipole->SetPolarisation(ZPOLARISATION);
59
-		dipole->SetLocation(0,0,0);
60
-		dipole->SetNumberOfFrequencies(1);
61
-		dipole->SetFrequency(0,1000);
62
-		dipole->SetPhase(0);
63
-
64
-	KernelEm1D *Kernel = KernelEm1D::New();
65
-		Kernel->Initialise(Earth);
66
-		Kernel->SetUpSource(dipole, 0);
67
-		Kernel->SetUpReceiver(-0.4);
68
-    //std::vector< KernelEm1DBase* > KernelVec;
69
-    //    KernelVec.push_back( )
70
-
71
-	std::cout.precision(10);
72
-
73
-	Hankel2 *dig = Hankel2::New();
74
-//         dig->ComputeRelated(.23 , Kernel);
75
-//  		std::cout << "  dig->Zgauss "
76
-//  				  << dig->Zgauss(0, TE, 0, 100.,
77
-//  								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
78
-//  			      << std::endl;
79
-
80
-// 	HankelTransformGaussianQuadrature *gauss =
81
-// 			HankelTransformGaussianQuadrature::New();
82
-// 		std::cout << "gauss->Zgauss "
83
-// 				  << gauss->Zgauss(0, TE, 0, 100.,
84
-// 								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
85
-// 			      << std::endl;
86
-
87
-	Earth->Delete();
88
-	dig->Delete();
89
-	//gauss->Delete();
90
-    dipole->Delete();
91
-	Kernel->Delete();
92
-	return EXIT_SUCCESS;
93
-}

+ 0
- 257
Modules/LemmaCore/examples/uthantenna.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  hantenna.cpp
4
-//
5
-//        Created:  10/07/2010 08:57:04 AM
6
-//       Modified:  14 Aug 2012
7
-//       Compiler:  Tested with g++, icpc, and MSVC 2010
8
-//
9
-//         Author:  Trevor Irons (ti)
10
-//
11
-//       Copyright (C) 2011    Broken Spoke Development, LLC
12
-//       Copyright (C) 2012    Trevor Irons
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//
16
-//          Email:  tirons@mines.edu
17
-//
18
-//  This program is free software: you can redistribute it and/or modify
19
-//  it under the terms of the GNU General Public License as published by
20
-//  the Free Software Foundation, either version 3 of the License, or
21
-//  (at your option) any later version.
22
-//
23
-//  This program is distributed in the hope that it will be useful,
24
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
-//  GNU General Public License for more details.
27
-//
28
-//  You should have received a copy of the GNU General Public License
29
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
-//
31
-// ===========================================================================
32
-
33
-/**
34
-  @file
35
-  @author   Trevor Irons
36
-  @date     10/07/2010
37
-  @version  $Revision: 208 $
38
-  $Id$
39
- **/
40
-
41
-#include "receiverpoints.h"
42
-#include "emearth1d.h"
43
-#include "PolygonalWireAntenna.h"
44
-#ifdef LEMMAUSEOMP
45
-#include "omp.h"
46
-#endif
47
-
48
-#include "timer.h"
49
-
50
-using namespace Lemma;
51
-
52
-std::vector<Real>  readinpfile(const std::string& fname);
53
-
54
-std::vector<std::string>  readinpfile2(const std::string& fname);
55
-
56
-int main(int argc, char** argv) {
57
-
58
-    std::cout <<
59
-    "\n"
60
-    << "hantenna- $Date: 2015-01-26 10:11:24 -0700 (Mon, 26 Jan 2015) $ $Revision: 208 $\n\n"
61
-    << "hantenna is a programme for computing the h field from polygonal wire\n"
62
-    << "loop sources \n\n"
63
-    << "hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
64
-    << "Lemma is Free and Open Source Software (FOSS) and is released under\n"
65
-    << "the MPL, it is covered by the following copyrights:\n"
66
-    << "Copyright (C) 2009, 2010, 2011, 2012      Colorado School of Mines\n"
67
-    << "Copyright (C) 2009, 2010, 2011, 2012      Trevor P. Irons\n"
68
-    << "Copyright (C) 2011, 2012                  M. Andy Kass\n\n"
69
-    << "More information may be found at: https://lemmasoftware.org\n"
70
-    << "                                  info@lemmasoftware.org\n\n"
71
-    << "=====================================================================\n"
72
-    << "This programme is part of Lemma, a geophysical modelling and inversion API \n"
73
-    << "This Source Code Form is subject to the terms of the Mozilla Public\n"
74
-    << "License, v. 2.0. If a copy of the MPL was not distributed with this\n"
75
-    << "file, You can obtain one at http://mozilla.org/MPL/2.0/. \n"
76
-    << "=====================================================================\n\n\n";
77
-
78
-    if (argc < 5) {
79
-        std::cout << "usage: hantenna.exe  trans.inp cond.inp points.inp config.inp \n";
80
-        exit(0);
81
-    }
82
-
83
-    #ifdef LEMMAUSEOMP
84
-    std::cout << "OpenMP is using " << omp_get_max_threads() << " threads" << std::endl;
85
-    #endif
86
-
87
-    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
88
-    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
89
-    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
90
-    std::vector<std::string> config  = readinpfile2(std::string(argv[4]));
91
-
92
-    //////////////////////////////////////
93
-    // Define transmitter
94
-    PolygonalWireAntenna* trans = PolygonalWireAntenna::New();
95
-        trans->SetNumberOfPoints((int)(Trans[0]));
96
-        int ip=1;
97
-        for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
98
-            trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
99
-        }
100
- 	    trans->SetNumberOfFrequencies(1);
101
- 	    trans->SetFrequency(0, Trans[ip]);
102
-        trans->SetCurrent(Trans[ip+1]);
103
-        trans->SetMinDipoleRatio(atof(config[1].c_str()));
104
-        trans->SetMinDipoleMoment(atof(config[2].c_str()));
105
-        trans->SetMaxDipoleMoment(atof(config[3].c_str()));
106
-
107
-	// Receivers
108
- 	ReceiverPoints *receivers = ReceiverPoints::New();
109
-        int nx = (int)Points[0];
110
-        int ny = (int)Points[1];
111
-        int nz = (int)Points[2];
112
-        Real ox = Points[3];
113
-        Real oy = Points[4];
114
-        Real oz = Points[5];
115
-     	Vector3r loc;
116
-        VectorXr dx(nx-1);
117
-        VectorXr dy(ny-1);
118
-        VectorXr dz(nz-1);
119
-        ip = 6;
120
-        int ir = 0;
121
-        for ( ; ip <6+nx-1; ++ip) {
122
-            dx[ir] = Points[ip];
123
-            ++ir;
124
-        }
125
-        ir = 0;
126
-        for ( ; ip <6+ny-1+nx-1; ++ip) {
127
-            dy[ir] = Points[ip];
128
-            ++ir;
129
-        }
130
-        ir = 0;
131
-        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
132
-            dz[ir] = Points[ip];
133
-            ++ir;
134
-        }
135
- 		receivers->SetNumberOfReceivers(nx*ny*nz);
136
- 		ir = 0;
137
-        Real pz  = oz;
138
- 		for (int iz=0; iz<nz; ++iz) {
139
- 		    Real py    =  oy;
140
- 		    for (int iy=0; iy<ny; ++iy) {
141
- 		        Real px    =  ox;
142
- 		        for (int ix=0; ix<nx; ++ix) {
143
- 			        loc << px, py, pz;
144
- 			        receivers->SetLocation(ir, loc);
145
- 			        if (ix < nx-1) px += dx[ix];
146
- 			        ++ ir;
147
-     	        }
148
-                if (iy<ny-1) py += dy[iy];
149
-            }
150
-            if (iz<nz-1) pz += dz[iz];
151
-        }
152
-
153
-    ////////////////////////////////////
154
-    // Define model
155
-    LayeredEarthEM *earth = LayeredEarthEM::New();
156
-    VectorXcr sigma;
157
-    VectorXr  thick;
158
- 	earth->SetNumberOfLayers(CondMod[0]+1);
159
- 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
160
-    thick.resize(CondMod[0]-1);
161
-    int ilay=1;
162
-    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
163
-        sigma(ilay/2+1) =  1./CondMod[ilay];
164
-        thick(ilay/2) =  CondMod[ilay+1];
165
-    }
166
-    sigma(ilay/2+1) = 1./ CondMod[ilay];
167
-	earth->SetLayerConductivity(sigma);
168
-    if (thick.size() > 0) earth->SetLayerThickness(thick);
169
-
170
-	EMEarth1D  *EmEarth = EMEarth1D::New();
171
-		EmEarth->AttachWireAntenna(trans);
172
-		EmEarth->AttachLayeredEarthEM(earth);
173
-		EmEarth->AttachReceiverPoints(receivers);
174
-		EmEarth->SetFieldsToCalculate(H);
175
-        EmEarth->SetHankelTransformMethod(string2Enum<HANKELTRANSFORMTYPE>(config[0]));
176
-        EmEarth->SetHankelTransformMethod(FHTKEY201);
177
-
178
-	// Keep track of time
179
-	jsw_timer timer;
180
-  	timer.begin();
181
-    clock_t launch = clock();
182
-    EmEarth->CalculateWireAntennaFields(true);    // true=status bar
183
-	Real paTime = timer.end();
184
-
185
-    std::cout << "\n\n===========================================\ncalc. real time: " << paTime/60. << "\t[m]\n";
186
-
187
-    std::cout << "calc. user time: " <<  (clock()-launch)/CLOCKS_PER_SEC/60.   << "\t[CPU m]"
188
-		 << std::endl;
189
-
190
-    ////////////////////////////////////
191
-    // Report
192
- 	std::fstream hrep("hfield.yaml", std::ios::out);
193
-    std::fstream hreal("hfield.dat", std::ios::out);
194
-
195
-    hrep << *EmEarth << std::endl;
196
-    hrep.close();
197
-    //hreal << *trans << std::endl;
198
-    //hreal << *earth << std::endl;
199
-
200
-    hreal << "// Right hand coordinate system, z is positive down\n";
201
-    hreal << "// x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
202
-    hreal.precision(8);
203
-    int i=0;
204
-	for (int iz=0; iz<nz; ++iz) {
205
-	for (int iy=0; iy<ny; ++iy) {
206
-	for (int ix=0; ix<nx; ++ix) {
207
-        hreal << receivers->GetLocation(i).transpose() << "\t";
208
- 		hreal << receivers->GetHfield(0, i).transpose() << "\n";
209
-        ++i;
210
-    }
211
-    }
212
-    }
213
-    hreal.close();
214
-    // Clean up
215
-    EmEarth->Delete();
216
-    earth->Delete();
217
-    receivers->Delete();
218
-    trans->Delete();
219
-}
220
-
221
-std::vector<Real>  readinpfile(const std::string& fname) {
222
-    std::string buf;
223
-    char dump[255];
224
-    std::vector<Real> vals;
225
-    std::fstream input(fname.c_str(), std::ios::in);
226
-    if (input.fail()) {
227
-        std::cerr << "Input file " << fname << " failed to open\n";
228
-        exit(EXIT_FAILURE);
229
-    }
230
-    while (input >> buf) {
231
-        if (buf.substr(0,2) == "//") {
232
-            input.getline(dump, 255);
233
-        } else {
234
-            vals.push_back( atof(buf.c_str() ));
235
-        }
236
-    }
237
-    return vals;
238
-}
239
-
240
-std::vector<std::string>  readinpfile2(const std::string& fname) {
241
-    std::string buf;
242
-    char dump[255];
243
-    std::vector<std::string> vals;
244
-    std::fstream input(fname.c_str(), std::ios::in);
245
-    if (input.fail()) {
246
-        std::cerr << "Input file " << fname << " failed to open\n";
247
-        exit(EXIT_FAILURE);
248
-    }
249
-    while (input >> buf) {
250
-        if (buf.substr(0,2) == "//") {
251
-            input.getline(dump, 255);
252
-        } else {
253
-            vals.push_back( std::string(buf.c_str() ));
254
-        }
255
-    }
256
-    return vals;
257
-}

+ 0
- 218
Modules/LemmaCore/examples/utlogbarriercg.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utlogbarriercg.cpp
4
-//
5
-//        Created:  12/29/2010 09:40:23 AM
6
-//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
-//
8
-//         Author:  Trevor Irons (ti)
9
-//
10
-//   Organisation:  Colorado School of Mines (CSM)
11
-//                  United States Geological Survey (USGS)
12
-//
13
-//          Email:  tirons@mines.edu, tirons@usgs.gov
14
-//
15
-//  This program is free software: you can redistribute it and/or modify
16
-//  it under the terms of the GNU General Public License as published by
17
-//  the Free Software Foundation, either version 3 of the License, or
18
-//  (at your option) any later version.
19
-//
20
-//  This program is distributed in the hope that it will be useful,
21
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
-//  GNU General Public License for more details.
24
-//
25
-//  You should have received a copy of the GNU General Public License
26
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
-//
28
-// ===========================================================================
29
-
30
-/**
31
-  @file
32
-  @author   Trevor Irons
33
-  @date     12/29/2010
34
-  @version   0.0
35
- **/
36
-
37
-#include "LemmaObject.h"
38
-//#include "logbarriercg.h"
39
-//#include "datasnmr.h"
40
-#include <ctime>
41
-
42
-#ifdef HAVEBOOSTRANDOM
43
-#include <boost/random.hpp>
44
-#include <boost/random/normal_distribution.hpp>
45
-#endif
46
-
47
-using namespace std;
48
-using namespace Lemma;
49
-
50
-MatrixXr BuildG(const Real& T2, const Real& Larmor, const Real& T,
51
-        const Real& dt, const VectorXr& nT2Bins, const Real& scale);
52
-
53
-MatrixXr BuildGw(const Real& T2, const Real& Larmor, const Real& T,
54
-        const Real& dt, const VectorXr& nT2Bins, const Real& scale,
55
-        const VectorXr& freqs);
56
-
57
-/// test driver program for log-barrier optimization algorithm
58
-int main() {
59
-    return 0;
60
-}
61
-
62
-#ifdef AA
63
-    // Parameters
64
-    Real T2(.200);
65
-    Real Larmor(2000); // Hz
66
-    Real wL = 2.*PI * Larmor;
67
-    Real T(.6);
68
-    Real dt(1e-4);
69
-    int  nT2(20);
70
-    Real T2Low(.020);
71
-    Real T2Hi(.220);
72
-
73
-    // T2 bins
74
-    VectorXr T2Bins = VectorXr::LinSpaced(nT2, T2Low, T2Hi);
75
-
76
-    // Build true model
77
-    VectorXr m = VectorXr::Zero(T2Bins.size());
78
-    //m[4]  = .15;
79
-    //m[5]  = .15;
80
-    //m[6]  = .15;
81
-    m[7]  = .15;
82
-    m[8]  = .15;
83
-    m[11] = .15;
84
-    m[12] = .15;
85
-    m[13] = .15;
86
-    m[14] = .15;
87
-
88
-    // Build G
89
-    srand ( std::time(NULL) );
90
-    Real scale = 1e-4*std::abs(VectorXr::Random(1)[0]);
91
-    MatrixXr G = BuildG(T2, wL, T, dt, T2Bins, scale);
92
-
93
-    #ifdef HAVEBOOSTRANDOM
94
-    Real mean = 0;
95
-    Real variance = scale*.05*(.5+.15);
96
-    boost::mt19937 randgen(static_cast<unsigned int> (std::time(0)));
97
-    boost::normal_distribution<Real> noise(mean, variance);
98
-    boost::variate_generator<boost::mt19937, boost::normal_distribution<Real> > nD(randgen, noise);
99
-    VectorXr noisy = G*m;
100
-//     for (int i=0; i < noisy.size(); ++i) {
101
-//        noisy(i) += nD();
102
-//     }
103
-    #else
104
-    VectorXr d = G * m;
105
-    VectorXr noisy = d.array();// + .05*( .5 + .15 ) *Eigen::ArrayXd::Random(d.size());
106
-    #endif
107
-
108
-    // Clean Data, and 10% random noise data
109
-    VectorXr RefMod = VectorXr::Zero(m.size());
110
-
111
-    // todo let alpha's be set.
112
-    Real alpha_s  =  .0;
113
-    Real alpha_t2 = 1.0;
114
-    Eigen::SparseMatrix<Real> Wd (G.rows(), G.rows());
115
-    Eigen::SparseMatrix<Real> Wm (G.cols(), G.cols());
116
-
117
-    /////////////////
118
-    // Model objective function
119
-    int ii = 0;
120
-    for (int iT2=0; iT2<nT2; ++iT2) {
121
-        Wm.coeffRef(ii, ii) += alpha_s - alpha_t2;
122
-        if (iT2 < nT2-1) {
123
-            Wm.coeffRef(ii, ii+1) += alpha_t2;
124
-        }
125
-        ++ii;
126
-    }
127
-    Wm.finalize();
128
-    std::fstream  WmOut( "wmMatrix.dat" , std::ios::out);
129
-    WmOut << Wm << std::endl;
130
-    WmOut.close();
131
-
132
-    // Data objective function
133
-    /// @todo add measure of suspected std dev to this.
134
-    for (int id=0; id<G.rows(); ++id) {
135
-        Wd.coeffRef(id, id) = 1.; // 1/sigma(i);
136
-    }
137
-    Wd.finalize();
138
-
139
-    // invert time-domain sinusoid exponent
140
-    //LogBarrierCG(G, RefMod, noisy, (Real)0., (Real)1e5, nT2, Wd, Wm, scale*1e1);
141
-    return EXIT_SUCCESS;
142
-
143
-//     #if 0
144
-//     // invert FD
145
-//     Eigen::FFT<Real> fft;
146
-//     fft.SetFlag(fft.HalfSpectrum);
147
-//     VectorXcr dw;
148
-//     fft.fwd(dw, noisy);
149
-//
150
-//     // Compute freqs Hz
151
-//     VectorXr freqs = DataSNMR::GetNMRSampledFrequencies(T/dt, dt);
152
-//     Real df = freqs[1];
153
-//     Real window = 300; // Hz
154
-//     int iL = (int)(Larmor/df);
155
-//     MatrixXr Gw = BuildGw(T2, wL, T, dt, T2Bins, scale, freqs.segment(iL-window/2, window));
156
-//
157
-//     VectorXr dwu = VectorXr::Zero(2.*window);
158
-//     dwu.head(window) = dw.segment(iL-window/2, window).real();
159
-//     dwu.tail(window) = dw.segment(iL-window/2, window).imag();
160
-//
161
-//     Eigen::DynamicSparseMatrix<Real> Wdw (Gw.rows(), Gw.rows());
162
-//     for (int id=0; id<Gw.rows(); ++id) {
163
-//         Wdw.coeffRef(id, id) = 1.; // 1/sigma(i);
164
-//     }
165
-//     Wdw.finalize();
166
-//     std::cout << "psize " << (Gw*RefMod).size() << std::endl;
167
-//     VectorXr dw2 = Gw*m;
168
-//     //std::cout << dw2 << std::endl;
169
-//     std::cout << "Gw " << Gw.rows() << "\t" << Gw.cols() << std::endl;
170
-//     std::cout << "dwu " << dwu.size() << std::endl;
171
-//     //RefMod.array() += .1;
172
-//     VectorXr mod = LogBarrierCG(Gw, RefMod, dwu, 0., 3., nT2, Wdw, Wm,scale*1e5);
173
-//     //VectorXr mod = LogBarrierCG(Gw, dwu, 0., 1e5);
174
-//
175
-//     std::fstream Gws("gw.out", std::ios::out);
176
-//     Gws << Gw << std::endl;
177
-//     Gws.close();
178
-//     #endif
179
-}
180
-
181
-#endif
182
-
183
-MatrixXr BuildG(const Real& T2, const Real& wL, const Real& T,
184
-            const Real& dt, const VectorXr& T2Bins, const Real& scale) {
185
-    std::cout << "scale " << scale << std::endl;
186
-    int nt = T/dt;
187
-    int nT2 = T2Bins.size();
188
-    MatrixXr G = MatrixXr::Zero(nt,nT2);
189
-    for (int iT2=0; iT2<nT2; ++iT2) {
190
-        Real t=0;
191
-        for (int it=0; it<nt; ++it) {
192
-            G(it, iT2) = scale * exp(-t/T2Bins(iT2)) * sin(wL * t);
193
-            t += dt;
194
-        }
195
-    }
196
-    return G;
197
-}
198
-
199
-
200
-MatrixXr BuildGw(const Real& T2, const Real& wL, const Real& T,
201
-            const Real& dt, const VectorXr& T2Bins, const Real& scale,
202
-            const VectorXr &freqs) {
203
-    VectorXr omegas = freqs.array() * 2.*PI;
204
-    std::cout << "scale " << scale << std::endl;
205
-    int nT2 = T2Bins.size();
206
-    MatrixXr Gw = MatrixXr::Zero(2*freqs.size(), nT2);
207
-    int nW = freqs.size();
208
-    Real sc = 1./dt;
209
-    for (int iT2=0; iT2<nT2; ++iT2) {
210
-        for (int iw=0; iw<freqs.size(); ++iw) {
211
-            Real a = 1./T2Bins(iT2);
212
-            Complex T = wL / ( wL*wL + (a+Complex(0, omegas[iw]))*(a+Complex(0,omegas[iw])) ) ;
213
-            Gw(iw, iT2)     = sc * scale * std::real(T);
214
-            Gw(iw+nW, iT2) = sc * scale * std::imag(T);
215
-        }
216
-    }
217
-    return Gw;
218
-}

+ 0
- 67
Modules/LemmaCore/examples/utpolygonalantenna.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utpolygonalantennae.cpp
4
-//
5
-//    Description:  Unit test of PolygonalAntenna
6
-//
7
-//        Version:  0.0
8
-//        Created:  05/26/2010 04:30:56 PM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
-//
12
-//         Author:  Trevor Irons (ti)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  United States Geological Survey (USGS)
16
-//
17
-//          Email:  tirons@mines.edu, tirons@usgs.gov
18
-//
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "Lemma"
35
-
36
-using namespace Lemma;
37
-
38
-int main() {
39
-
40
-    PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
41
-        pa->SetNumberOfPoints(5);
42
-        pa->SetPoint(0, Vector3r(  0,  0, -1e-3));
43
-        pa->SetPoint(1, Vector3r( 10,  0, -1e-3));
44
-        pa->SetPoint(2, Vector3r( 10, 10, -1e-3));
45
-        pa->SetPoint(3, Vector3r(  0, 10, -1e-3));
46
-        pa->SetPoint(4, Vector3r(  0,  0, -1e-3));
47
-        pa->SetNumberOfFrequencies(1);
48
-        pa->SetFrequency(0,1000.);
49
-        pa->SetCurrent(10.);
50
-        pa->SetNumberOfTurns(1);
51
-
52
-    Vector3r pos;
53
-    pos << 23,23,23;
54
-    pa->ApproximateWithElectricDipoles(pos);
55
-    std::cout << "pos "<< pos.transpose() << "  ndipoles="
56
-              << pa->GetNumberOfDipoles() << std::endl;
57
-    pos << 2,2,2;
58
-    pa->ApproximateWithElectricDipoles(pos);
59
-    std::cout << "pos "<< pos.transpose() << "  ndipoles="
60
-              << pa->GetNumberOfDipoles() << std::endl;
61
-    pos << 1,1,1;
62
-    pa->ApproximateWithElectricDipoles(pos);
63
-    std::cout << "pos "<< pos.transpose() << "  ndipoles="
64
-              << pa->GetNumberOfDipoles() << std::endl;
65
-
66
-    pa->Delete();
67
-}

+ 0
- 68
Modules/LemmaCore/examples/utreadfemubc.cpp View File

1
-// ===========================================================================
2
-// 
3
-//       Filename:  utreadfemubc.cpp
4
-// 
5
-//    Description:  
6
-// 
7
-//        Version:  0.0
8
-//        Created:  01/03/2013 02:47:24 PM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++ 
11
-// 
12
-//         Author:  M. Andy Kass (MAK)
13
-//
14
-//   Organisation:  Broken Spoke Development, LLC
15
-//                  
16
-//
17
-//          Email:  mkass@numericalgeo.com
18
-// 
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "Lemma"
35
-
36
-using namespace Lemma;
37
-
38
-#ifdef LEMMAUSEVTK
39
-#include "matplot.h"
40
-using namespace matplot;
41
-#endif
42
-
43
-int main() {
44
-
45
-	std::string datfile;
46
-
47
-	datfile = "126.obs";
48
-	
49
-	DataReaderFemUBC* Reader = DataReaderFemUBC::New();
50
-	DataFEM* thedata = DataFEM::New();
51
-
52
-	Reader->SetDataFEM(thedata);
53
-
54
-	try {
55
-	Reader->ReadData(datfile,1);
56
-	} catch(std::exception& e) {
57
-		exit(EXIT_FAILURE);
58
-	}
59
-
60
-	std::cout << *Reader << std::endl;
61
-	std::cout << *thedata << std::endl;
62
-
63
-
64
-	thedata->Delete();
65
-	Reader->Delete();
66
-
67
-	return EXIT_SUCCESS;
68
-}

+ 0
- 54
Modules/LemmaCore/examples/utsandbox.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utsandbox.cpp
4
-//
5
-//        Created:  07/29/2010 10:34:23 AM
6
-//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
-//
8
-//         Author:  Trevor Irons (ti)
9
-//
10
-//   Organisation:  Colorado School of Mines (CSM)
11
-//                  United States Geological Survey (USGS)
12
-//
13
-//          Email:  tirons@mines.edu, tirons@usgs.gov
14
-//
15
-//  This program is free software: you can redistribute it and/or modify
16
-//  it under the terms of the GNU General Public License as published by
17
-//  the Free Software Foundation, either version 3 of the License, or
18
-//  (at your option) any later version.
19
-//
20
-//  This program is distributed in the hope that it will be useful,
21
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
-//  GNU General Public License for more details.
24
-//
25
-//  You should have received a copy of the GNU General Public License
26
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
-//
28
-// ===========================================================================
29
-
30
-/**
31
-  @file test sandbox helm1rameters
32
-  @author   Trevor Irons
33
-  @date     07/29/2010
34
-  @version   0.0
35
- **/
36
-
37
-#include "Lemma"
38
-
39
-using namespace Lemma;
40
-
41
-int main() {
42
-
43
-    PolygonalWireAntenna *helm1 = PolygonalWireAntenna::New();
44
-	helm1->SetNumberOfFrequencies(1);
45
-	helm1->SetFrequency(0, 1000);
46
-	helm1->SetNumberOfPoints(5);
47
-	helm1->SetPoint(0, Vector3r(   0,   0, 0));
48
-	helm1->SetPoint(1, Vector3r(   0,   0, 0));
49
-	helm1->SetPoint(2, Vector3r(   0,   0, 0));
50
-	helm1->SetPoint(3, Vector3r(   0,   0, 0));
51
-	helm1->SetPoint(4, Vector3r(   0,   0, 0));
52
-	helm1->SetCurrent(1.);
53
-    helm1->Delete();
54
-}

+ 0
- 199
Modules/LemmaCore/examples/uttemforward.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  uttemforward.cpp
4
-//
5
-//    Description:  TEM Forward Modeller
6
-//
7
-//        Version:  0.0
8
-//        Created:  02/10/2011 03:32:18 PM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
-//
12
-//         Author:  M. Andy Kass (MAK)
13
-//
14
-//		Copyright:  2011 Trevor Irons and M. Andy Kass
15
-//
16
-//   Organisation:  Colorado School of Mines (CSM)
17
-//                  Broken Spoke Development, LLC
18
-//
19
-//          Email:  mkass@numericalgeo.com
20
-//
21
-//  This program is free software: you can redistribute it and/or modify
22
-//  it under the terms of the GNU General Public License as published by
23
-//  the Free Software Foundation, either version 3 of the License, or
24
-//  (at your option) any later version.
25
-//
26
-//  This program is distributed in the hope that it will be useful,
27
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
-//  GNU General Public License for more details.
30
-//
31
-//  You should have received a copy of the GNU General Public License
32
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
33
-//
34
-// ===========================================================================
35
-
36
-#include <time.h>
37
-#include "Lemma"
38
-#include "banner.h"
39
-
40
-using namespace Lemma;
41
-
42
-#ifdef LEMMAUSEVTK
43
-#include "matplot.h"
44
-using namespace matplot;
45
-#endif
46
-
47
-int main(int argv, char** argc) {
48
-
49
-	// Just for timing
50
-	clock_t launch =clock();
51
-
52
-	// Banner display
53
-	std::string name;
54
-	std::string version;
55
-	std::string usage;
56
-	name = "TEM Forward Modeller - 1D";
57
-	version = "1.0beta";
58
-	usage = "temforward1d [inputfile]";
59
-	banner(name,version,usage);
60
-    if ( argv < 2 ) {
61
-        std::cout << "No input file specified, should be of format\n";
62
-        std::cout <<
63
-"origparabk.obsy        ! Observations-style file.\n\
64
-origpara.con           ! Starting model.\n\
65
-100                    ! Number of Hankel kernel evaluations.\n\
66
-100 1. 1.0E+10         ! Number of Fourier kernel evaluations, & min & max freq.\n\
67
-N                      ! Is noise to be added?\n\
68
-5.  1.0E-08  30        ! Noise to be added: percentage, threshold, seed.\n\
69
-" << std::endl;
70
-
71
-        exit(0);
72
-    }
73
-
74
-	time_t curr=time(0);
75
-	std::cout << std::endl;
76
-	std::cout << "  Start time: " << ctime(&curr) << std::endl;
77
-
78
-	// Define objects
79
-	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
80
-//     PolygonalWireAntenna* pa = PolygonalWireAntenna::New();
81
-//         pa->SetNumberOfPoints(5);
82
-// 	    pa->SetPoint(0, Vector3r(   0,   0, -30.001));
83
-// 	    pa->SetPoint(1, Vector3r(   0,  20, -35.001));
84
-// 	    pa->SetPoint(2, Vector3r(  20 , 20, -35.001));
85
-// 	    pa->SetPoint(3, Vector3r(  20,   0, -30.001));
86
-// 	    pa->SetPoint(4, Vector3r(   0,   0, -30.001));
87
-// 	    pa->SetCurrent(100.);
88
-//         pa->SetNumberOfTurns(1);
89
-
90
-
91
-	//DipoleSource* Trans = DipoleSource::New();
92
-	ReceiverPoints *Receivers = ReceiverPoints::New();
93
-	LayeredEarthEM *Earth = LayeredEarthEM::New();
94
-	VectorXr maintimes;
95
-
96
-    /////////////////////////////////////
97
-	// Using model reader
98
-	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
99
-	    Reader->SetEMEarth1D(Earth);
100
-	    Reader->SetTransmitter(Trans);
101
-	    Reader->SetReceiver(Receivers);
102
-	    Reader->ReadParameters( argc[1] );
103
-	    maintimes = Reader->GetTimes();
104
-
105
-	// Attach it to instrumentTEM
106
-	InstrumentTem *instrument = InstrumentTem::New();
107
-	    instrument->EMEarthModel(Earth);
108
-	    instrument->SetTransmitLoop(Trans);
109
-	    //instrument->SetTransmitLoop(pa);
110
-	    //instrument->SetDipoleSource(Trans);
111
-	    instrument->SetReceiver(Receivers);
112
-
113
-
114
-
115
-        // TODO need to input these
116
-        VectorXr widths = VectorXr::Ones(maintimes.size()); // * 1e-5;
117
-        /*
118
-        widths.segment(0,5).array()  *= 5e-6;
119
-        widths.segment(5,5).array()  *= 1e-5;
120
-        widths.segment(10,5).array() *= 5e-5;
121
-        widths.segment(15,5).array() *= 2e-4;
122
-        widths.segment(20,5).array() *= 4e-4;
123
-        //widths.segment(25,5).array() *= 4e-4;
124
-        */
125
-        /*
126
-        widths << .48,4.,8.,8.,8.,8.,8.,12.,12.,12.,16.,16.,16.,20.,24.,24.,28.,32.,32.,36.,40.,44.,52.,
127
-  				56.,64.,68.,76.,88.,96.,104.,120.,132.,144.,160.,180.,200.,220.,248.,272.,304.,336.,376.,
128
-  				416.,464.,516.,572.,636.,708.,784.,872.,968.,1076.,1196.,1328.,1476.,1640.,1824.,2024.,
129
-  				2248.,2500. ;
130
-        */
131
-        widths *= 1e-6;
132
-        std::cout << widths.transpose() << std::endl;
133
-
134
-        instrument->SetReferenceTime(.025);
135
-        //instrument->SetReferenceTime(.025);
136
-	    instrument->SetTimeGates(maintimes, widths);
137
-
138
-        //instrument->SetReceiverType(MAGNETOMETER);
139
-        instrument->SetReceiverType(INDUCTIVE);
140
-        // Set the pulse
141
-        VectorXr Amp(4); Amp << 0,1,1,0;
142
-        VectorXr Times(4); Times << 0., .0005, .02497, .025;
143
-
144
-        //VectorXr Amp(4); Amp << 0,1,1,0;
145
-        //VectorXr Times(4); Times << -0.025, -0.0245, -0.00003, 0.0;
146
-        //instrument->SetPulse(Amp, Times);
147
-
148
-        //VectorXr Amp(3); Amp << 0,1,0;
149
-        //VectorXr Times(3); Times << 0, .015, .030;
150
-        //instrument->SetPulse(Amp, Times);
151
-
152
-        //VectorXr Amp(3); Amp << 0,1,0;
153
-        //VectorXr Times(3); Times << 0, .01, .020;
154
-        instrument->SetPulse(Amp, Times);
155
-
156
-    std::cout << *Earth << "\n" << *Trans << "\n" << *Receivers << std::endl;
157
-
158
-	// Perform the forward model
159
-	//instrument->MakeDirectCalculation( FHTKEY201  );
160
-	//instrument->MakeLaggedCalculation( ANDERSON801 );
161
-	//instrument->MakeLaggedCalculation( QWEKEY );
162
-	//instrument->MakeLaggedCalculation( CHAVE );
163
-	instrument->MakeLaggedCalculation( FHTKEY201 );
164
-	//instrument->MakeLaggedCalculation( FHTKEY101 );
165
-
166
-    int nlag = instrument->GetMeasurements().rows();
167
-	// Output results to screen
168
-	for (int ii=0; ii<nlag; ii++) {
169
-		std::cout<<"  "<<instrument->GetMeasurements()(ii,0)<<"  "<<instrument->GetMeasurements()(ii,1)<<std::endl;
170
-	}
171
-
172
-	// Output results to file
173
-	std::ofstream outfile1;
174
-	outfile1.open("solution.out");
175
-    //outfile1 << "//timegate [ms]\t dB/dt [nT/s]" << std::endl;
176
-    outfile1 << "//timegate [s]\t dB/dt [T/s]" << std::endl;
177
-	for (int ii=0; ii<nlag; ii++) {
178
-		//outfile1 << 1e3*instrument->GetMeasurements()(ii,0)<< "\t" << (MU0*1e9)*instrument->GetMeasurements()(ii,1)<<std::endl;
179
-		outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << MU0*instrument->GetMeasurements()(ii,1) << std::endl;
180
-		//outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << instrument->GetMeasurements()(ii,1)<<std::endl;
181
-	}
182
-	outfile1.close();
183
-
184
-
185
-	// Timing stuff
186
-	std::cout << "  Time for execution: " <<  (clock()-launch)/CLOCKS_PER_SEC   << " [CPU] seconds."
187
-		 << std::endl;
188
-
189
-
190
-	instrument->Delete();
191
-	Trans->Delete();
192
-	Earth->Delete();
193
-	Receivers->Delete();
194
-	Reader->Delete();
195
-
196
-	return EXIT_SUCCESS;
197
-}
198
-
199
-

+ 0
- 131
Modules/LemmaCore/examples/utteminv1d.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utteminv1d.cpp
4
-//
5
-//    Description:  Invert for the difference in water table
6
-//
7
-//        Version:  0.0
8
-//        Created:  03/23/2011 02:07:19 PM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
-//
12
-//         Author:  M. Andy Kass (MAK)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  Broken Spoke Development, LLC
16
-//
17
-//          Email:  mkass@numericalgeo.com
18
-//
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "Lemma"
35
-#include "banner.h"
36
-
37
-using namespace Lemma;
38
-
39
-int main () {
40
-
41
-	VectorXr maintimes;
42
-	int ntimes;
43
-
44
-	//Banner
45
-	std::string name;
46
-	std::string version;
47
-	std::string usage;
48
-	name = "TEM Inversion - 1D";
49
-	version = "1.0beta";
50
-	usage = "teminv1d [inputfile]";
51
-	banner(name,version,usage);
52
-
53
-	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
54
-	ReceiverPoints* Receivers = ReceiverPoints::New();
55
-	LayeredEarthEM* StartingMod = LayeredEarthEM::New();
56
-	//LayeredEarthEM* RecoveredMod = LayeredEarthEM::New();
57
-	InverseSolverTEM1D* Inverse = InverseSolverTEM1D::New();
58
-
59
-
60
-	Trans->SetNumberOfPoints(5);
61
-    Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
62
-    Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
63
-    Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
64
-    Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
65
-    Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
66
-	Trans->SetCurrent(1);
67
-	Trans->SetNumberOfTurns(1);
68
-    Trans->SetMinDipoleRatio(1/2.);
69
-
70
-	Vector3r loc;
71
-	Real ox = 50.;
72
-	Real oy = 50.;
73
-	Real depth = -1.e-3;
74
-	Receivers->SetNumberOfReceivers(1);
75
-	loc << ox,oy,depth;
76
-	Receivers->SetLocation(0,loc);
77
-
78
-	StartingMod->SetNumberOfLayers(22);
79
-	StartingMod->SetLayerConductivity( (VectorXcr(22) << 0.,1.e-3,
80
-		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,
81
-		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3).finished() );
82
-	StartingMod->SetLayerThickness((VectorXr(20)<<4,4,4,4,4,4,4,4,4,4,4,4,4,
83
-		4,4,4,4,4,4,4).finished());
84
-	//EM-47 gate times
85
-	ntimes = 30;
86
-	maintimes.resize(ntimes);
87
-	maintimes << 36.,45.25,57.,72.25,92.,117.,148.,186.5,234.,290.,
88
-		352.5,427.5,525.,647.5,802.5,1002.5,1257.5,1582.5,1997.5,2525.,
89
-		3197.5,4055.,5147.5,6542.5,8322.5,10592.,13490.,17187.,21902.,
90
-		27915.;
91
-	maintimes = maintimes.array() /1000000;
92
-
93
-	Inverse->AttachStartMod(StartingMod);
94
-	Inverse->AttachWireAntenna(Trans);
95
-	Inverse->AttachReceiver(Receivers);
96
-	Inverse->SetTimes(maintimes);
97
-	LayeredEarthEM* RecoveredMod = StartingMod->Clone();
98
-	Inverse->AttachRecMod(RecoveredMod);
99
-
100
-	//Read input data - temp for SEG!
101
-	/// TODO write a TEM data reader class.  and a functional TEM data class
102
-	std::fstream infile("rotateddat.dat",std::ios::in);
103
-	if (infile.fail()) {
104
-		std::cout << "Shit!" << std::endl;
105
-	}
106
-	MatrixXr rotinpdata;
107
-	rotinpdata.resize(30,1);
108
-	for (int ii=0;ii<30;ii++) {
109
-		infile >> rotinpdata(ii);
110
-	}
111
-	infile.close();
112
-
113
-
114
-	Inverse->AttachMeasuredData(rotinpdata);
115
-	//Inverse->SetFreeParams( (VectorXi(2)<<0,1).finished(),
116
-	//	(VectorXi(3)<<1,2,3).finished());
117
-
118
-	std::cout << *Inverse << std::endl;
119
-
120
-	Inverse->Calculate();
121
-	//Inverse->ShowSoln();
122
-	//Inverse->WriteSoln("temp.dat");
123
-
124
-	Inverse->Delete();
125
-	RecoveredMod->Delete();
126
-	StartingMod->Delete();
127
-	Receivers->Delete();
128
-	Trans->Delete();
129
-
130
-	return EXIT_SUCCESS;
131
-}

+ 0
- 84
Modules/LemmaCore/examples/uttemreader.cpp View File

1
-// ===========================================================================
2
-// 
3
-//       Filename:  uttemreader.cpp
4
-// 
5
-//    Description:  
6
-// 
7
-//        Version:  0.0
8
-//        Created:  02/19/2011 12:30:59 PM
9
-//       Revision:  none
10
-//       Compiler:  Tested with g++, icpc, and MSVC 2000 
11
-// 
12
-//         Author:  M. Andy Kass (MAK)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  Broken Spoke Brewery, LLC
16
-//
17
-//          Email:  mkass@numericalgeo.com
18
-// 
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include "Lemma"
35
-
36
-using namespace Lemma;
37
-
38
-
39
-int main() {
40
-
41
-	/*
42
-	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
43
-	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
44
-	ReceiverPoints *Receivers = ReceiverPoints::New();
45
-	LayeredEarthEM *Earth = LayeredEarthEM::New();
46
-	Reader->SetEMEarth1D(Earth);
47
-	Reader->SetTransmitter(Trans);
48
-	Reader->SetReceiver(Receivers);
49
-	Reader->ReadParameters("em1dtmfwd.in");
50
-
51
-	Reader->Delete();
52
-	Earth->Delete();
53
-	Receivers->Delete();
54
-	Trans->Delete();
55
-	*/
56
-
57
-	int rnObs;
58
-	int rnGates;
59
-	std::string inputfile;
60
-	MatrixXr somedata;
61
-	Vector3Xr somepositions;
62
-
63
-	DataTEM* TheData = DataTEM::New();
64
-	DataReaderTem* Reader = DataReaderTem::New();
65
-
66
-	inputfile = "temreadertest.txt";
67
-
68
-	Reader->SetDataTEM(TheData);
69
-	Reader->ReadData(inputfile);
70
-
71
-	rnObs = TheData->GetnObs();
72
-	rnGates = TheData->GetnGates();
73
-	somedata = TheData->GetData();
74
-	somepositions = TheData->GetPositions();
75
-
76
-	std::cout << rnObs << " " << rnGates << std::endl;
77
-	std::cout << somedata << std::endl;
78
-	std::cout << somepositions << std::endl;
79
-
80
-	Reader->Delete();
81
-	TheData->Delete();
82
-
83
-	return EXIT_SUCCESS;
84
-}

+ 0
- 207
Modules/LemmaCore/examples/uttemsandbox.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  uttemsandbox.cpp
4
-//
5
-//        Created:  09/29/2010 07:38:26 AM
6
-//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
-//
8
-//         Author:  Trevor Irons (ti), M. Andy Kass
9
-//
10
-//
11
-//   Organisation:  Colorado School of Mines (CSM)
12
-//                  United States Geological Survey (USGS)
13
-//					Broken Spoke Development, LLC
14
-//
15
-//          Email:  tirons@mines.edu, tirons@usgs.gov
16
-//					mkass@numericalgeo.com
17
-//
18
-//  This program is free software: you can redistribute it and/or modify
19
-//  it under the terms of the GNU General Public License as published by
20
-//  the Free Software Foundation, either version 3 of the License, or
21
-//  (at your option) any later version.
22
-//
23
-//  This program is distributed in the hope that it will be useful,
24
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
-//  GNU General Public License for more details.
27
-//
28
-//  You should have received a copy of the GNU General Public License
29
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
-//
31
-// ===========================================================================
32
-
33
-/**
34
-  @file
35
-  @author   Trevor Irons
36
-  @date     09/29/2010
37
-  @version   0.0
38
- **/
39
-
40
-#include "Lemma"
41
-using namespace Lemma;
42
-
43
-#ifdef LEMMAUSEVTK
44
-#include "matplot.h"
45
-using namespace matplot;
46
-#endif
47
-
48
-int main() {
49
-
50
-
51
-    int nfreq  =    6000;  // Number of frequencies
52
-
53
-	// Specify receiver times
54
-	int ntimes	=	30;
55
-	VectorXr times(ntimes);
56
-	times <<
57
-	36.0, 45.25, 57.0, 72.25, 92.0,
58
-	117.0, 148.0, 186.5, 234.0, 290.0,
59
-	352.5, 427.5, 525.0, 647.5, 802.5,
60
-	1002.5, 1257.5, 1582.5, 1997.5, 2525.0,
61
-	3197.5, 4055.0, 5147.5, 6542.5, 8322.5,
62
-	10592.0, 13490.0, 17187.0, 21902.0, 27915.0;
63
-
64
-	times = times.array()*1.0e-6;
65
-
66
-	//CALCULATE ABSCISSA
67
-	//define bounds
68
-
69
-	gaussianquadrature *lgqw = gaussianquadrature::New();
70
-
71
-	Real lowb;
72
-	Real upb;
73
-	lowb = 1.0;
74
-	upb = 6000000.0;
75
-	lgqw->SetFreqs(nfreq,upb,lowb);
76
-	lgqw->CalcAW();
77
-
78
-	VectorXr xu(nfreq);
79
-	xu=lgqw->GetAbscissae();
80
-	DipoleSource* Trans=DipoleSource::New();
81
-	Trans->SetType(MAGNETICDIPOLE);
82
-	Trans->SetPolarisation(ZPOLARISATION);
83
-	Trans->SetLocation(0.0,0.0,-1e-4);
84
-
85
-
86
-    // Specify Transmitter
87
-    //PolygonalWireAntenna* Trans  = PolygonalWireAntenna::New();
88
-    //Trans->SetNumberOfPoints(5);
89
-    //Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
90
-    //Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
91
-    //Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
92
-    //Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
93
-    //Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
94
-    Trans->SetNumberOfFrequencies(nfreq);
95
-    VectorXr  f(nfreq);
96
-    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
97
-    //    Trans->SetFrequency(ifreq, 1e-3 + dfreq*(Real)(ifreq));
98
-		Trans->SetFrequency(ifreq,xu(ifreq));
99
-        f(ifreq) = xu(ifreq);
100
-    }
101
-	//cout << Trans->GetFrequencies();
102
-    //Trans->SetCurrent(1);
103
-    //Trans->SetNumberOfTurns(1);
104
-
105
-    // Earth properties, top layer is air layer 0 conductivity is fine
106
-    LayeredEarthEM *Earth = LayeredEarthEM::New();
107
-        Earth->SetNumberOfLayers(4);
108
-        Earth->SetLayerConductivity( (VectorXcr(4) << 0.,1.e-6,1.e-2,1.e-6 ).finished() );
109
-        Earth->SetLayerThickness( (VectorXr(2) << 50, 20).finished() );
110
-
111
-    // Receivers, just 1 in the centre for now
112
-   	ReceiverPoints *Receivers = ReceiverPoints::New();
113
-		Vector3r loc;
114
-		Real ox     =    50.;
115
-		Real oy     =    50.;
116
-		Real depth  =  -1e-2;
117
-		Receivers->SetNumberOfReceivers(1);
118
-		loc << ox, oy, depth;
119
-		Receivers->SetLocation(0, loc);
120
-
121
-	// EmEarth
122
-	EMEarth1D  *EmEarth = EMEarth1D::New();
123
-		//EmEarth->AttachWireAntenna(Trans);
124
-		EmEarth->AttachDipoleSource(Trans);
125
-		EmEarth->AttachLayeredEarthEM(Earth);
126
-		EmEarth->AttachReceiverPoints(Receivers);
127
-		EmEarth->SetFieldsToCalculate(H);
128
-        // slower but may be more accurate, depending on frequencies
129
-        EmEarth->SetHankelTransformMethod(CHAVE);
130
-        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
131
-
132
-    // Do calculation
133
-   	//EmEarth->CalculateWireAntennaFields();
134
-	//EmEarth->MakeCalc();
135
-	EmEarth->MakeCalc3();
136
-
137
-    // Grab Z component
138
-    // A little painful, I'll try to clean up the API
139
-    VectorXcr Hw(nfreq);
140
-    VectorXr  e(nfreq);
141
-    Hw(0) = 0.; // DC component
142
-    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
143
-        Hw(ifreq) = (Receivers->GetHfield(ifreq, 0))(2);
144
-        e(ifreq) = ifreq;
145
-    }
146
-
147
-    VectorXr Ht(ntimes);                   // Time domain H field
148
-
149
-	//Sine transform
150
-	VectorXr func(nfreq);
151
-	for (int ii=0;ii<ntimes;++ii) {
152
-		func = (Hw.imag().array()*((f.array()*times(ii)).sin()));
153
-		lgqw->SetFunc(func);
154
-		lgqw->Integrate();
155
-		Ht(ii)=lgqw->GetResult();
156
-	}
157
-	Ht = Ht.array()*(-2.0/PI);
158
-
159
-	std::ofstream myfile1;
160
-	myfile1.open("solution.txt");
161
-	for (int ii=0;ii<ntimes;++ii) {
162
-		myfile1 << times(ii) << "   " << Ht(ii) << std::endl;
163
-	}
164
-	myfile1.close();
165
-
166
-	std::ofstream myfile2;
167
-	myfile2.open("freq_domain.txt");
168
-	for (int ii=0;ii<nfreq;++ii) {
169
-		myfile2 << f(ii) << "  " << Hw(ii).real() << "  " << Hw(ii).imag()
170
-			<< std::endl;
171
-	}
172
-	myfile2.close();
173
-
174
-    //std::cout << Ht << std::endl;
175
-    //std::cout << Hw.real() << std::endl;
176
-
177
-    // Quick and dirty plot
178
-    #ifdef  LEMMAUSEVTK
179
-    double colour1[3] = {0.0,0.0,1.0};
180
-    double colour2[3] = {1.0,0.0,0.0};
181
-
182
-    Plot2D_VTK p1("Hz", "Re(Hw)", 800, 600);
183
-    p1.plot(f, Hw.real().eval(), colour1, ".-");
184
-    p1.show();
185
-
186
-    Plot2D_VTK p2("Hz", "Im(Hw)", 800, 600);
187
-    p2.plot(f, Hw.imag().eval(), colour2, ".-");
188
-    p2.show();
189
-
190
-    Plot2D_VTK p3("Time (seconds)", "Ht", 800, 600);
191
-    p3.plot(times, Ht, colour2, ".-");
192
-    p3.show();
193
-
194
-	//Plot2D_VTK p4("index", "frequency",800,600);
195
-	//p4.plot(e,f,colour1,".-");
196
-	//p4.show();
197
-
198
-    #endif
199
-
200
-    // Clean up
201
-    Trans->Delete();
202
-    Earth->Delete();
203
-    Receivers->Delete();
204
-    EmEarth->Delete();
205
-
206
-    return EXIT_SUCCESS;
207
-}

+ 0
- 319
Modules/LemmaCore/examples/wireantenna.cpp View File

1
-// ===========================================================================
2
-//
3
-//       Filename:  utdipolesource.cpp
4
-//
5
-//    Description:
6
-//
7
-//        Version:  0.0
8
-//        Created:  12/02/2009 11:57:14 AM
9
-//       Revision:  none
10
-//       Compiler:  g++ (c++)
11
-//
12
-//         Author:  Trevor Irons (ti)
13
-//
14
-//   Organisation:  Colorado School of Mines (CSM)
15
-//                  United States Geological Survey (USGS)
16
-//
17
-//          Email:  tirons@mines.edu, tirons@usgs.gov
18
-//
19
-//  This program is free software: you can redistribute it and/or modify
20
-//  it under the terms of the GNU General Public License as published by
21
-//  the Free Software Foundation, either version 3 of the License, or
22
-//  (at your option) any later version.
23
-//
24
-//  This program is distributed in the hope that it will be useful,
25
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-//  GNU General Public License for more details.
28
-//
29
-//  You should have received a copy of the GNU General Public License
30
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
-//
32
-// ===========================================================================
33
-
34
-#include <iostream>
35
-#include <fstream>
36
-
37
-#include "dipolesource.h"
38
-#include "layeredearth.h"
39
-#include "receiverpoints.h"
40
-#include "emearth1d.h"
41
-#include "WireAntenna.h"
42
-#include "PolygonalWireAntenna.h"
43
-
44
-#if  LEMMAUSEVTK
45
-#include "vtkRenderer.h"
46
-#include "vtkRenderWindow.h"
47
-#include "vtkRenderWindowInteractor.h"
48
-#include "vtkRenderLargeImage.h"
49
-#include "vtkPNGWriter.h"
50
-#endif     // -----  not LEMMA_USE_VTK  -----
51
-
52
-// For testing purposes disable VTK and run scale.sh
53
-//#undef LEMMAUSEVTK
54
-
55
-#include "timer.h"
56
-
57
-using namespace Lemma;
58
-
59
-double randDouble(double low, double high) {
60
-	//srand(time(0));
61
-	double temp;
62
-	/* swap low & high around if the user makes no sense */
63
-	if (low > high)	{
64
-	temp = low;
65
-	low = high;
66
-	high = temp;
67
-	}
68
-	/* calculate the random number & return it */
69
-	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
70
-	* (high - low) + low;
71
-	return temp;
72
-}
73
-
74
-
75
-int main() {
76
-
77
-	// Keep track of time
78
-	jsw_timer timer;
79
-
80
-
81
-	srand(time(0));
82
-
83
-	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
84
-	pa->SetNumberOfFrequencies(1);
85
-	pa->SetFrequency(0, 1000);
86
-	pa->SetNumberOfPoints(5);
87
-	pa->SetPoint(0, Vector3r(   0,   0, -.001));
88
-	pa->SetPoint(1, Vector3r( 100,   0, -.001));
89
-	pa->SetPoint(2, Vector3r( 100, 100, -.001));
90
-	pa->SetPoint(3, Vector3r(   0, 100, -.001));
91
-	pa->SetPoint(4, Vector3r(   0,   0, -.001));
92
-	pa->SetCurrent(1.);
93
-    pa->SetNumberOfTurns(1);
94
-	//Vector3r rp = Vector3r::Random(3);
95
-	//rp << 150., 10, 0.;
96
-	//rp << -27.1456, 15.2350, -1e-3;
97
-	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
98
-	//rp << 3.22806, -13.1548, 14.9695;
99
-	//rp.setRandom(3);
100
-	//std::cout <<  "rp " << rp.transpose() << std::endl;
101
-	//pa->ApproximateWithElectricDipoles(rp);
102
-
103
-	WireAntenna *wire = WireAntenna::New();
104
-		wire->SetNumberOfPoints(5);
105
-		wire->SetPoint(0, Vector3r(   0,   0, -1e-3));
106
-		wire->SetPoint(1, Vector3r( 10,   0, -1e-3));
107
-		wire->SetPoint(2, Vector3r( 10, 10, -1e-3));
108
-		wire->SetPoint(3, Vector3r(   0, 10, -1e-3));
109
-		wire->SetPoint(4, Vector3r(   0,   0, -1e-3));
110
-		// TODO change wire antennae to use my class
111
-		//wire->SetNumberOfFrequencies(1);
112
-		wire->SetCurrent(1.);
113
-		wire->SetNumberOfFrequencies(1);
114
-		wire->SetFrequency(0, 1000);
115
-        wire->SetNumberOfTurns(1);
116
-		//wire->ApproximateWithElectricDipoles(5);
117
-
118
-	// Define model
119
-	VectorXcr sigma(2);
120
-		sigma << Complex(0.,0), Complex(.1,0);
121
-	VectorXr  thick(1);
122
-		thick << 10;
123
-	LayeredEarthEM *earth = LayeredEarthEM::New();
124
-		earth->SetNumberOfLayers(2);
125
-		earth->SetLayerConductivity(sigma);
126
-		//earth->SetLayerThickness(thick);
127
-
128
-	// Receivers
129
-	ReceiverPoints *receivers = ReceiverPoints::New();
130
-		Vector3r loc;
131
-		Real ox    =    50.561 ;
132
-		Real oy    =   105.235 ;
133
-		Real depth =    -3.75e1;
134
-		Real depth2 =   depth;
135
-		Real dx    =    1.;
136
-		int nz     =    1;
137
-		receivers->SetNumberOfReceivers(nz);
138
-		int ir = 0;
139
-		for (int iz=0; iz<nz; ++iz) {
140
-			loc << ox, oy, depth;
141
-			receivers->SetLocation(ir, loc);
142
-			depth += dx;
143
-			++ ir;
144
-		}
145
-
146
-	// EmEarth
147
-	EMEarth1D  *EmEarth = EMEarth1D::New();
148
-		//EmEarth->AttachWireAntenna(wire);
149
-		EmEarth->AttachWireAntenna(pa);
150
-		EmEarth->AttachLayeredEarthEM(earth);
151
-		EmEarth->AttachReceiverPoints(receivers);
152
-		EmEarth->SetFieldsToCalculate(H);
153
-        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
154
-
155
-	// Do calculation
156
-	timer.begin();
157
-	EmEarth->CalculateWireAntennaFields();
158
-	Real paTime = timer.end();
159
-	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
160
-
161
-	//EmEarth->AttachWireAntenna(wire);
162
-	//timer.begin();
163
-	//EmEarth->CalculateWireAntennaFields();
164
-	//Real waTime = timer.end();
165
-	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
166
-
167
-	depth = depth2;
168
-	std::fstream real("reale_lay.dat", std::ios::out);
169
-	std::fstream imag("image_lay.dat", std::ios::out);
170
-	std::fstream hreal("real_lay.dat", std::ios::out);
171
-	std::fstream himag("imag_lay.dat", std::ios::out);
172
-	for (int iz=0; iz<nz; ++iz) {
173
-		Vector3cr temp = receivers->GetEfield(0,iz);
174
-		real << ox << "\t" << oy << "\t" << depth << "\t"
175
-				<< temp(0).real() << "\t" << temp(1).real()
176
-				<< "\t" << temp(2).real() << std::endl;
177
-		imag << ox << "\t" << oy << "\t" << depth << "\t"
178
-				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
179
-				<< "\t" << std::imag(temp(2)) << std::endl;
180
-		temp = receivers->GetHfield(0, iz);
181
-		hreal << ox << "\t" << oy << "\t" << depth << "\t"
182
-				<< std::real(temp(0)) << "\t" << std::real(temp(1))
183
-				<< "\t" << std::real(temp(2)) << std::endl;
184
-		himag << ox << "\t" << oy << "\t" << depth << "\t"
185
-				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
186
-				<< "\t" << std::imag(temp(2)) << std::endl;
187
-		depth += dx;
188
-	}
189
-	real.close();
190
-	imag.close();
191
-	hreal.close();
192
-	himag.close();
193
-	EmEarth->Delete();
194
-	receivers->Delete();
195
-	earth->Delete();
196
-	//wire->Delete();
197
-
198
-#if  LEMMAUSEVTK
199
-	// Create the usual rendering stuff.
200
-	vtkRenderer           *renderer = vtkRenderer::New();
201
-	vtkRenderWindow         *renWin = vtkRenderWindow::New();
202
-	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
203
-
204
-	// Line of tx
205
-	vtkLineSource       *vline = vtkLineSource::New();
206
-	vtkTubeFilter       *vTube = vtkTubeFilter::New();
207
- 	vtkPolyDataMapper   *vMapper = vtkPolyDataMapper::New();
208
-	vtkActor             *vActor = vtkActor::New();
209
-	vline->SetPoint1(0,0,0);
210
-	vline->SetPoint2(10,0,0);
211
-
212
-	vTube->SetInputConnection(vline->GetOutputPort());
213
-	vTube->SetRadius(.2);
214
-	vTube->SetNumberOfSides(6);
215
-	vMapper->SetInputConnection(vTube->GetOutputPort());
216
-	vActor->SetMapper(vMapper);
217
-	vActor->GetProperty()->SetColor(0.0, .0, 1.0);
218
-	vActor->GetProperty()->SetOpacity(.15);
219
-	renderer->AddActor(vActor);
220
-
221
-	vtkLineSource       *vline2 = vtkLineSource::New();
222
-	vtkTubeFilter       *vTube2 = vtkTubeFilter::New();
223
- 	vtkPolyDataMapper   *vMapper2 = vtkPolyDataMapper::New();
224
-	vtkActor             *vActor2 = vtkActor::New();
225
-	vline2->SetPoint1(10,0,0);
226
-	vline2->SetPoint2(10,10,0);
227
-
228
-	vTube2->SetInputConnection(vline2->GetOutputPort());
229
-	vTube2->SetRadius(.2);
230
-	vTube2->SetNumberOfSides(6);
231
-	vMapper2->SetInputConnection(vTube2->GetOutputPort());
232
-	vActor2->SetMapper(vMapper2);
233
-	vActor2->GetProperty()->SetColor(0.0, .0, 1.0);
234
-	vActor2->GetProperty()->SetOpacity(.15);
235
-	renderer->AddActor(vActor2);
236
-
237
-	vtkLineSource       *vline3 = vtkLineSource::New();
238
-	vtkTubeFilter       *vTube3 = vtkTubeFilter::New();
239
- 	vtkPolyDataMapper   *vMapper3 = vtkPolyDataMapper::New();
240
-	vtkActor             *vActor3 = vtkActor::New();
241
-	vline3->SetPoint1(10,10,0);
242
-	vline3->SetPoint2(0,10,0);
243
-
244
-	vTube3->SetInputConnection(vline3->GetOutputPort());
245
-	vTube3->SetRadius(.2);
246
-	vTube3->SetNumberOfSides(6);
247
-	vMapper3->SetInputConnection(vTube3->GetOutputPort());
248
-	vActor3->SetMapper(vMapper3);
249
-	vActor3->GetProperty()->SetColor(0.0, .0, 1.0);
250
-	vActor3->GetProperty()->SetOpacity(.15);
251
-	renderer->AddActor(vActor3);
252
-
253
-	vtkLineSource       *vline4 = vtkLineSource::New();
254
-	vtkTubeFilter       *vTube4 = vtkTubeFilter::New();
255
- 	vtkPolyDataMapper   *vMapper4 = vtkPolyDataMapper::New();
256
-	vtkActor             *vActor4 = vtkActor::New();
257
-	vline4->SetPoint1(0,10,0);
258
-	vline4->SetPoint2(0,0,0);
259
-
260
-	vTube4->SetInputConnection(vline4->GetOutputPort());
261
-	vTube4->SetRadius(.2);
262
-	vTube4->SetNumberOfSides(6);
263
-	vMapper4->SetInputConnection(vTube4->GetOutputPort());
264
-	vActor4->SetMapper(vMapper4);
265
-	vActor4->GetProperty()->SetColor(0.0, .0, 1.0);
266
-	vActor4->GetProperty()->SetOpacity(.15);
267
-	renderer->AddActor(vActor4);
268
-
269
-    loc << 50, 50, -1e-3;
270
-	pa->ApproximateWithElectricDipoles(loc);
271
-
272
-    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
273
-    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
274
-	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
275
-		pdipActors[id] = pa->GetVtkActor(id);
276
-		renderer->AddActor(pdipActors[id]);
277
-	}
278
-
279
-    /*
280
-    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
281
-	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
282
-		dipActors[id] = wire->GetVtkActor(id);
283
-		renderer->AddActor(dipActors[id]);
284
-	}
285
-    */
286
-
287
-	renderer->SetBackground(1,1,1);
288
-
289
-	// Render the window
290
-	renWin->AddRenderer(renderer);
291
-	renWin->SetWindowName("Wire antennae");
292
-
293
-	iren->SetRenderWindow(renWin);
294
-	iren->Initialize();
295
-	iren->Start();
296
-	iren->Render();
297
-
298
-    #if 0
299
-	cout << "Enter File name?: ";
300
-	std::string pngName;
301
-	std::cin >> pngName;
302
-	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
303
-	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
304
-	renlarge->SetInput(renderer);
305
-	renlarge->SetMagnification(2);
306
-	pngwrite->SetInputConnection(renlarge->GetOutputPort());
307
-	pngName.append(".png");
308
-	pngwrite->SetFileName(pngName.c_str());
309
-	pngwrite->Write();
310
-    #endif
311
-
312
-#endif     // -----  not LEMMA_USE_VTK  -----
313
-
314
-
315
-	//std::cout << *pa << std::endl;
316
-	//pa->Delete();
317
-
318
-	return 0;
319
-}

+ 5
- 1
Modules/LemmaCore/include/CubicSplineInterpolator.h View File

23
 
23
 
24
 namespace Lemma {
24
 namespace Lemma {
25
 
25
 
26
-// Simple struct to hold spline terms
26
+
27
+/**
28
+ * \brief Simple struct to hold spline terms
29
+ * \details This struct holds the actual knot and spline interpolation terms.
30
+ */
27
 struct SplineSet{
31
 struct SplineSet{
28
     VectorXr a;
32
     VectorXr a;
29
     VectorXr b;
33
     VectorXr b;

+ 28
- 20
Modules/LemmaCore/include/EarthModel.h View File

21
     // ===================================================================
21
     // ===================================================================
22
     //        Class:  EarthModel
22
     //        Class:  EarthModel
23
     /// \ingroup LemmaCore
23
     /// \ingroup LemmaCore
24
-    /// \brief abstract class for Earth models
24
+    /// \brief   abstract class for Earth models
25
     /// \details
25
     /// \details
26
     // ===================================================================
26
     // ===================================================================
27
     class EarthModel : public LemmaObject {
27
     class EarthModel : public LemmaObject {
58
             void SetMagneticFieldComponents(const Vector3r &bfield,
58
             void SetMagneticFieldComponents(const Vector3r &bfield,
59
                             const MAGUNITS &unit);
59
                             const MAGUNITS &unit);
60
 
60
 
61
-            /// Sets the magnetic field using inclination, declination,
62
-            /// and magnitude, units of Tesla
63
-            /// @param[in] inc is the field's inclination
64
-            /// @param[in] dec is the field's declination
65
-            /// @param[in] Mag is the field's magnitude
66
-            /// @param[in] unit specifies the the units used.
67
-            /// The components are set according to
68
-            /// \f{eqnarray*} { B_x =& B \cos(inc (\pi/180)) \cos(dec (\pi/180))
69
-            ///            \\   B_y =& B \cos(inc (\pi/180)) \sin(dec (\pi/180))
70
-            ///            \\   B_z =& B \sin(inc (\pi/180))
71
-            /// \f}
61
+            /** Sets the magnetic field using inclination, declination,
62
+                and magnitude, units of Tesla
63
+                @param[in] inc is the field's inclination
64
+                @param[in] dec is the field's declination
65
+                @param[in] Mag is the field's magnitude
66
+                @param[in] unit specifies the the units used.
67
+                The components are set according to
68
+                \f{eqnarray*} { B_x =& B \cos(inc (\pi/180)) \cos(dec (\pi/180))
69
+                           \\   B_y =& B \cos(inc (\pi/180)) \sin(dec (\pi/180))
70
+                           \\   B_z =& B \sin(inc (\pi/180))
71
+                \f}
72
+             */
72
             void SetMagneticFieldIncDecMag(const Real& inc, const Real&dec,
73
             void SetMagneticFieldIncDecMag(const Real& inc, const Real&dec,
73
                             const Real& Mag, const MAGUNITS &unit);
74
                             const Real& Mag, const MAGUNITS &unit);
74
 
75
 
75
             // ====================  INQUIRY       =======================
76
             // ====================  INQUIRY       =======================
76
 
77
 
77
-            /// Gets the magnetic field of the earth, in T
78
+            /** @return the magnetic field of the earth, in T
79
+             */
78
             Vector3r GetMagneticField( );
80
             Vector3r GetMagneticField( );
79
 
81
 
80
-            /// Gets the magnetic field of the earth, in T
82
+            /** @return the magnetic field of the earth, in Gauss
83
+             */
81
             Vector3r GetMagneticFieldInGauss(  );
84
             Vector3r GetMagneticFieldInGauss(  );
82
 
85
 
83
-            /// Gets the magnetic field unit vector of the earth
86
+            /** @return the magnetic field unit vector of the earth
87
+             */
84
             Vector3r GetMagneticFieldUnitVector( );
88
             Vector3r GetMagneticFieldUnitVector( );
85
 
89
 
86
-            /// Returns the magnitude of the magnetic field \f$ \Vert
87
-            /// \mathbf{B}_0 \Vert \f$
90
+            /** @return the magnitude of the magnetic field (in T)
91
+             * \f$ \Vert \mathbf{B}_0 \Vert \f$
92
+             */
88
             Real GetMagneticFieldMagnitude();
93
             Real GetMagneticFieldMagnitude();
89
 
94
 
90
-            /// Returns the magnitude of the magnetic field \f$ \Vert
91
-            /// \mathbf{B}_0 \Vert \f$ in Gauss units
95
+            /** @return the magnitude of the magnetic field
96
+             *  \f$ \Vert \mathbf{B}_0 \Vert \f$ in Gauss units
97
+             */
92
             Real GetMagneticFieldMagnitudeInGauss( );
98
             Real GetMagneticFieldMagnitudeInGauss( );
93
 
99
 
94
-            /** Returns the name of the underlying class, similiar to Python's type */
100
+            /** @return the name of the underlying class, similiar to Python's
101
+                        type
102
+             */
95
             virtual inline std::string GetName() const;
103
             virtual inline std::string GetName() const;
96
 
104
 
97
         protected:
105
         protected:

+ 0
- 1
Modules/LemmaCore/include/Filter.h View File

19
     // ===================================================================
19
     // ===================================================================
20
     //  Class:  Filter
20
     //  Class:  Filter
21
     /**
21
     /**
22
-      @class  Filter
23
       \ingroup LemmaCore
22
       \ingroup LemmaCore
24
       \brief  Abstract class for filtering.
23
       \brief  Abstract class for filtering.
25
       \details Derived classes include fourier domain and time domain filters.
24
       \details Derived classes include fourier domain and time domain filters.

+ 0
- 1
Modules/LemmaCore/include/GridReader.h View File

24
 namespace Lemma {
24
 namespace Lemma {
25
 
25
 
26
     /**
26
     /**
27
-      @class
28
       \ingroup LemmaCore
27
       \ingroup LemmaCore
29
       \brief   Abstract class for grid readers.
28
       \brief   Abstract class for grid readers.
30
       \details Provides a consistent interface for reading grid files in Lemma.
29
       \details Provides a consistent interface for reading grid files in Lemma.

+ 0
- 1
Modules/LemmaCore/include/RectilinearGridReader.h View File

25
 namespace Lemma {
25
 namespace Lemma {
26
 
26
 
27
     /**
27
     /**
28
-      @class
29
       \ingroup LemmaCore
28
       \ingroup LemmaCore
30
       \brief   Base Class for rectilinear grid reader data files
29
       \brief   Base Class for rectilinear grid reader data files
31
       \details
30
       \details

+ 0
- 1
Modules/LemmaCore/include/WindowFilter.h View File

20
     // ===================================================================
20
     // ===================================================================
21
     //  Class:  WindowFilter
21
     //  Class:  WindowFilter
22
     /**
22
     /**
23
-      @class   WindowFilter
24
       \ingroup LemmaCore
23
       \ingroup LemmaCore
25
       \brief   Fourier domain window filter.
24
       \brief   Fourier domain window filter.
26
       \details Current types are Hamming and Hanning. Others to be added.
25
       \details Current types are Hamming and Hanning. Others to be added.

+ 3
- 0
Modules/LemmaCore/include/helper.h View File

182
   }
182
   }
183
 };
183
 };
184
 
184
 
185
+/**
186
+ *   \brief Serializes and Deserializes VectorXr arrays
187
+ */
185
 template<>
188
 template<>
186
 struct convert<Lemma::VectorXr> {
189
 struct convert<Lemma::VectorXr> {
187
   static Node encode(const Lemma::VectorXr& rhs) {
190
   static Node encode(const Lemma::VectorXr& rhs) {

+ 0
- 0
Modules/Optimization/CMakeLists.txt View File


+ 0
- 98
Modules/Optimization/include/bicgstab.h View File

1
-/*
2
- modifed from http://www.netlib.org/templates/cpp//
3
- Iterative template routine -- BiCGSTAB
4
-
5
- BiCGSTAB solves the unsymmetric linear system Ax = b
6
- using the Preconditioned BiConjugate Gradient Stabilized method
7
-
8
- BiCGSTAB follows the algorithm described on p. 27 of the
9
- SIAM Templates book.
10
-
11
- The return value indicates convergence within max_iter (input)
12
- iterations (0), or no convergence within max_iter iterations (1).
13
-
14
- Upon successful return, output arguments have the following values:
15
-
16
-        x  --  approximate solution to Ax = b
17
- max_iter  --  the number of iterations performed before the
18
-               tolerance was reached
19
-      tol  --  the residual after the final iteration
20
-*/
21
-
22
-#include <iostream>
23
-#include <fstream>
24
-#include "lemma.h"
25
-
26
-namespace Lemma {
27
-
28
-    template <typename Scalar>
29
-    VectorXr BiCGSTAB(const MatrixXr &A, const VectorXr &x0, const VectorXr &b,
30
-          const MatrixXr &M, int &max_iter, Scalar& tol) {
31
-        Scalar resid;
32
-        Scalar rho_1(0), rho_2(0), alpha(0), beta(0), omega(0);
33
-        VectorXr p, phat, s, shat, t, v;
34
-        VectorXr x = x0;
35
-        Scalar normb = b.norm();
36
-        VectorXr r = b - A * x;
37
-        VectorXr rtilde = r;
38
-
39
-        if (normb == 0.0)
40
-          normb = 1;
41
-
42
-        if ((resid = r.norm() / normb) <= tol) {
43
-          tol = resid;
44
-          max_iter = 0;
45
-          //return 0;
46
-          return x;
47
-        }
48
-
49
-        for (int i = 1; i <= max_iter; i++) {
50
-          rho_1 = rtilde.dot(r);
51
-          if (rho_1 == 0) {
52
-            tol = r.norm() / normb;
53
-            //return 2;
54
-            return x;
55
-          }
56
-          if (i == 1)
57
-            p = r;
58
-          else {
59
-            beta = (rho_1/rho_2) * (alpha/omega);
60
-            p = r + beta * (p - omega * v);
61
-          }
62
-          phat = M*p; //M.solve(p);
63
-          v = A * phat;
64
-          alpha = rho_1 / rtilde.dot(v);
65
-          s = r - alpha * v;
66
-          if ((resid = s.norm()/normb) < tol) {
67
-            x += alpha * phat;
68
-            tol = resid;
69
-            //return 0;
70
-            return x;
71
-          }
72
-          shat = M*s;//M.solve(s);
73
-          t = A * shat;
74
-          omega = t.dot(s) / t.dot(t);
75
-          x += alpha * phat + omega * shat;
76
-          r = s - omega * t;
77
-
78
-          rho_2 = rho_1;
79
-          if ((resid = r.norm() / normb) < tol) {
80
-            tol = resid;
81
-            max_iter = i;
82
-            //return 0;
83
-            return x;
84
-          }
85
-          if (omega == 0) {
86
-            tol = r.norm() / normb;
87
-            //return 3;
88
-            return x;
89
-          }
90
-        }
91
-
92
-        tol = resid;
93
-        return x;
94
-    }
95
-}
96
-
97
-/* vim: set tabstop=4 expandtab: */
98
-/* vim: set filetype=cpp: */

+ 0
- 437
Modules/Optimization/include/cg.h View File

1
-/* This file is part of Lemma, a geophysical modelling and inversion API */
2
-
3
-/* This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
-
7
-/**
8
-  @file
9
-  @author   Trevor Irons
10
-  @version  $Id: cg.h 87 2013-09-05 22:44:05Z tirons $
11
- **/
12
-
13
-#ifndef  CG_INC
14
-#define  CG_INC
15
-
16
-
17
-#include <iostream>
18
-#include <fstream>
19
-#include "lemma.h"
20
-
21
-namespace Lemma {
22
-
23
-    /** Port of netlib.org http://www.netlib.org/templates/cpp//cg.h
24
-     *  Solves the symmetric postive definite system Ax=b.
25
-     *  No preconditioner is used.
26
-     *  Iterative template routine -- CG
27
-     *
28
-     *  CG solves the symmetric positive definite linear
29
-     *  system Ax=b using the Conjugate Gradient method.
30
-     *
31
-     *  CG follows the algorithm described on p. 15 in the
32
-     *  SIAM Templates book.
33
-     *
34
-     *  The return value indicates convergence within max_iter (input)
35
-     *  iterations (0), or no convergence within max_iter iterations (1).
36
-     *
37
-     *  Upon successful return, output arguments have the following values:
38
-     *
39
-     *         x  --  approximate solution to Ax = b
40
-     *  max_iter  --  the number of iterations performed before the
41
-     *                tolerance was reached
42
-     *       tol  --  the residual after the final iteration
43
-     *  @param[in] A is a Real matrix A to be solved.
44
-     *  @param[in] x0 is the starting model.
45
-     *  @param[in] b is the right hand side.
46
-     */
47
-    template < typename Scalar >
48
-    VectorXr CG(const MatrixXr &A, const VectorXr &x0, const VectorXr &b,
49
-        int &max_iter, Scalar &tol) {
50
-
51
-        VectorXr p, q;
52
-        Scalar alpha, beta, rho, rho_1(0);
53
-        VectorXr x = x0;
54
-        Scalar normb = b.norm( );
55
-        VectorXr r = b - A*x;
56
-
57
-        if (normb == 0.0) {
58
-            normb = 1;
59
-        }
60
-
61
-        Scalar resid = r.norm() / normb;
62
-        if (resid <= tol) {
63
-            tol = resid;
64
-            max_iter = 0;
65
-            return x;
66
-        }
67
-
68
-        for (int i = 1; i <= max_iter; i++) {
69
-
70
-            rho = r.transpose()*r;
71
-
72
-            if (i == 1) {
73
-                p = r;
74
-            }
75
-            else {
76
-                beta = rho / rho_1;
77
-                p = r + beta * p;
78
-            }
79
-
80
-            q = A*p;
81
-            alpha = rho / p.dot(q);
82
-
83
-            x += alpha * p;
84
-            r -= alpha * q;
85
-
86
-            if ((resid = r.norm() / normb) <= tol) {
87
-                tol = resid;
88
-                max_iter = i;
89
-                return x;
90
-            }
91
-            rho_1 = rho;
92
-        }
93
-        tol = resid;
94
-        std::cerr << "CG FAILED TO REACH CONVERGENCE\n";
95
-        return x;
96
-    }
97
-
98
-    // Specialised routine that appliex mod(Ax) so that b and x are in real, but
99
-    // A is complex.
100
-    template < typename Scalar >
101
-    VectorXr CG_ModulusAx(const MatrixXcr &A, const VectorXr &x0, const VectorXr &b,
102
-        int &max_iter, Scalar &tol) {
103
-
104
-        VectorXr p, q;
105
-        Scalar beta, rho, rho_1(0);
106
-        Scalar alpha;
107
-        VectorXr x = x0;
108
-        Scalar normb = b.norm( );
109
-        VectorXr r = b.array() - (A*x).array().abs();
110
-
111
-        if (normb == 0.0) {
112
-            normb = 1;
113
-        }
114
-
115
-        Scalar resid = r.norm() / normb;
116
-        if (resid <= tol) {
117
-            tol = resid;
118
-            max_iter = 0;
119
-            return x;
120
-        }
121
-
122
-        for (int i = 1; i <= max_iter; i++) {
123
-
124
-            rho = r.dot(r); //conjugate().transpose()*r;
125
-
126
-            if (i == 1) {
127
-                p = r;
128
-            }
129
-            else {
130
-                beta = rho / rho_1;
131
-                p = r + beta * p;
132
-            }
133
-
134
-            q = (A*p).array().abs();
135
-            alpha = rho / p.dot(q);
136
-
137
-            x += alpha * p;
138
-            r -= alpha * q;
139
-
140
-            if ((resid = r.norm() / normb) <= tol) {
141
-                tol = resid;
142
-                max_iter = i;
143
-                return x;
144
-            }
145
-            rho_1 = rho;
146
-        }
147
-
148
-        tol = resid;
149
-        std::cerr << "CG FAILED TO REACH CONVERGENCE\n";
150
-        return x;
151
-    }
152
-
153
-// Preconditioned version of above
154
-//*****************************************************************
155
-// Iterative template routine -- CG
156
-//
157
-// CG solves the symmetric positive definite linear
158
-// system Ax=b using the Conjugate Gradient method.
159
-//
160
-// CG follows the algorithm described on p. 15 in the
161
-// SIAM Templates book.
162
-//
163
-// The return value indicates convergence within max_iter (input)
164
-// iterations (0), or no convergence within max_iter iterations (1).
165
-//
166
-// Upon successful return, output arguments have the following values:
167
-//
168
-//        x  --  approximate solution to Ax = b
169
-// max_iter  --  the number of iterations performed before the
170
-//               tolerance was reached
171
-//      tol  --  the residual after the final iteration
172
-//
173
-//*****************************************************************
174
-
175
-//template < class Matrix, class Vector, class Preconditioner, class Real >
176
-//int
177
-//CG(const Matrix &A, Vector &x, const Vector &b,
178
-//   const Preconditioner &M, int &max_iter, Real &tol)
179
-//{
180
-    #include <limits>
181
-    template <typename Preconditioner>
182
-    VectorXr CG(const MatrixXr &A, const VectorXr &x0, const VectorXr &b,
183
-        const Preconditioner &M, int &max_iter, Real &tol) {
184
-        //const Eigen::SparseMatrix<Real> &M, int &max_iter, Real &tol) {
185
-
186
-        VectorXr p, z, q;
187
-        VectorXr x = x0;
188
-        Real alpha(0), beta(0), rho(0), rho_1(0);
189
-        Real normb;
190
-        VectorXr r;
191
-        #ifdef LEMMAUSEOMP
192
-        #pragma omp parallel sections
193
-        {
194
-        #endif
195
-            #ifdef LEMMAUSEOMP
196
-            #pragma omp section
197
-            #endif
198
-            {
199
-                normb = b.norm();
200
-            }
201
-            #ifdef LEMMAUSEOMP
202
-            #pragma omp section
203
-            #endif
204
-            {
205
-                r = b - A*x;
206
-            }
207
-        #ifdef LEMMAUSEOMP
208
-        }
209
-        #endif
210
-        if (normb <= std::numeric_limits<double>::epsilon() ) {
211
-            normb = 1;
212
-        }
213
-        Real resid = r.norm() / normb;
214
-        if (resid <= tol) {
215
-            tol = resid;
216
-            max_iter = 0;
217
-            return x;
218
-        }
219
-        // todo do 0th loop manually, gets rid of if statement
220
-        for (int i = 1; i <= max_iter; i++) {
221
-            z = M.solve(r);
222
-            //z = M*r;
223
-            rho = r.transpose()*z;
224
-            if (i == 1) {
225
-                p = z;
226
-            } else {
227
-                beta = rho / rho_1;
228
-                p = z + beta * p;
229
-            }
230
-            q = A*p;
231
-            alpha = rho / p.dot(q);
232
-            #ifdef LEMMAUSEOMP
233
-            #pragma omp parallel sections
234
-            {
235
-            #endif
236
-                #ifdef LEMMAUSEOMP
237
-                #pragma omp section
238
-                #endif
239
-                {
240
-                    x += alpha * p;
241
-                }
242
-                #ifdef LEMMAUSEOMP
243
-                #pragma omp section
244
-                #endif
245
-                {
246
-                    r -= alpha * q;
247
-                }
248
-            #ifdef LEMMAUSEOMP
249
-            }
250
-            #endif
251
-            if ((resid = r.norm() / normb) <= tol) {
252
-               tol = resid;
253
-               max_iter = i;
254
-               return x;
255
-            }
256
-            rho_1 = rho;
257
-        }
258
-        tol = resid;
259
-        std::cerr << "Preconditioned CG failed to converge\n";
260
-        return x;
261
-    }
262
-
263
-    template < typename Scalar >
264
-    VectorXr CGJ(const MatrixXr &A, const VectorXr &x0, const VectorXr &b,
265
-        const Eigen::SparseMatrix<Scalar> &M, int &max_iter, Scalar &tol) {
266
-
267
-        VectorXr p, z, q;
268
-        VectorXr x = x0;
269
-        Scalar alpha(0), beta(0), rho(0), rho_1(0);
270
-        Scalar normb;
271
-        VectorXr r;
272
-        #ifdef LEMMAUSEOMP
273
-        #pragma omp parallel sections
274
-        {
275
-        #endif
276
-            #ifdef LEMMAUSEOMP
277
-            #pragma omp section
278
-            #endif
279
-            {
280
-                normb = b.norm();
281
-            }
282
-            #ifdef LEMMAUSEOMP
283
-            #pragma omp section
284
-            #endif
285
-            {
286
-                r = b - A*x;
287
-            }
288
-        #ifdef LEMMAUSEOMP
289
-        }
290
-        #endif
291
-        if (normb <= std::numeric_limits<double>::epsilon() ) {
292
-            normb = 1;
293
-        }
294
-        Scalar resid = r.norm() / normb;
295
-        if (resid <= tol) {
296
-            tol = resid;
297
-            max_iter = 0;
298
-            return x;
299
-        }
300
-        // todo do 0th loop manually, gets rid of if statement
301
-        for (int i = 1; i <= max_iter; i++) {
302
-            //z = M.solve(r);
303
-            z = M*r;
304
-            rho = r.transpose()*z;
305
-            if (i == 1) {
306
-                p = z;
307
-            } else {
308
-                beta = rho / rho_1;
309
-                p = z + beta * p;
310
-            }
311
-            q = A*p;
312
-            alpha = rho / p.dot(q);
313
-            #ifdef LEMMAUSEOMP
314
-            #pragma omp parallel sections
315
-            {
316
-            #endif
317
-                #ifdef LEMMAUSEOMP
318
-                #pragma omp section
319
-                #endif
320
-                {
321
-                    x += alpha * p;
322
-                }
323
-                #ifdef LEMMAUSEOMP
324
-                #pragma omp section
325
-                #endif
326
-                {
327
-                    r -= alpha * q;
328
-                }
329
-            #ifdef LEMMAUSEOMP
330
-            }
331
-            #endif
332
-            if ((resid = r.norm() / normb) <= tol) {
333
-               tol = resid;
334
-               max_iter = i;
335
-               return x;
336
-            }
337
-            rho_1 = rho;
338
-        }
339
-        tol = resid;
340
-        std::cerr << "Preconditioned CG failed to converge\n";
341
-        return x;
342
-    }
343
-
344
-    ///////////////////////////////////////////////////////
345
-    // Log Barrier
346
-    /** Solves one iteration, using implicit multiplication of At*b, and ATA.
347
-     *  @param[in] G is the sensitivity matrix to be inverted.
348
-     *  @param[in] WdTWd is the data weighting matrix, usually sparse.
349
-     *  @param[in] WmTWm is the model weighting matrix, usually sparse.
350
-     *  @param[in] X1 is a vector of the inverse of the current model X. Used in
351
-     *  log barrier. Should be computed as X1 = VectorXr( 1. / (x.array() - minVal ))
352
-     *  @param[in] Y1 is a vector of the inverse of the current model X. Used in
353
-     *  log barrier. Should be computed as X1 = VectorXr( 1. / (maxVal - x.array() ))
354
-     *  @param[in] X2 is the analaogous inverse of X^2 diagonal matrix, stored
355
-     *  as a Vector.
356
-     *  @param[in] Y2 is the analaogous inverse of (maxVal-X)^2 diagonal matrix, stored
357
-     *  as a Vector.
358
-     *  @param[in] D2 is the datamisfit vector, formally (d_predicted - d_observed).
359
-     *  @param[in,out] Mk is the input / output solution vector. The input value is
360
-     *  an itital guess, and output is the solution.
361
-     *  @param[in] Mr is the reference model.
362
-     *  @param[in] BETA is the regularisation (Tikhonov parameter) to apply
363
-     *  @param[in] P is a preconditioner of G. The product Pb ~ x
364
-     *  @param[in,out] max_iter is the number of iterations.
365
-     *  @param[in,out] tol is the desired tolerance on input, and achieved on
366
-     *  output.
367
-     */
368
-    template < typename  Scalar >
369
-    int implicit_log_CG(const MatrixXr& G, const MatrixXr& WdTWd, const VectorXr& WmTWm,
370
-				const VectorXr& X1, const VectorXr& X2,
371
-				const VectorXr& Y1, const VectorXr& Y2,
372
-				const VectorXr& D2, VectorXr& Mk, const VectorXr& Mr,
373
-				const Scalar& BETA, const MatrixXr& P,
374
-                int& max_iter, Scalar& tol) {
375
-
376
-        // TODO add WdTWD to this!
377
-
378
-        Scalar resid;
379
-        VectorXr p, z, q;
380
-        Scalar alpha(0), beta(0), rho(0), rho_1(0);
381
-
382
-        // Calculate 'B'
383
-        VectorXr delM = Mk - Mr;
384
-        VectorXr B = (-G.transpose()*D2).array() - BETA*((WmTWm.asDiagonal()*delM).array())
385
-                     + X1.array() + Y1.array();
386
-
387
-        Scalar normb = B.norm();
388
-
389
-        // Implicit calc of A*x
390
-        VectorXr Y = BETA*(WmTWm.asDiagonal()*Mk).array() +
391
-                (X2.asDiagonal()*Mk).array() + (Y2.asDiagonal()*Mk).array();
392
-        VectorXr Z = G*Mk;
393
-        VectorXr U = G.transpose()*Z;
394
-
395
-        VectorXr r = B - (Y + U);
396
-
397
-        if (normb == 0.0) normb = 1;
398
-
399
-        if ((resid = r.norm() / normb) <= tol) {
400
-            tol = resid;
401
-            max_iter = 0;
402
-            return 0;
403
-        }
404
-
405
-        for (int i = 1; i <= max_iter; i++) {
406
-            //z = M.solve(r); // we can solve directly z = P*r
407
-            z = P*r;
408
-            rho = r.dot(z);
409
-            if (i == 1)  p = z;
410
-            else {
411
-                beta = rho / rho_1;
412
-                p = beta * p;
413
- 	            p = p+z;
414
-            }
415
-            Y = BETA*(WmTWm.array()*p.array()) + X2.array()*p.array() + Y2.array()*p.array();
416
-            Z = G*p;
417
-            U = G.transpose()*Z;
418
-            q = Y+U;
419
-
420
-            alpha = rho / p.dot(q);
421
-
422
-            Mk = Mk + alpha * p;
423
-            r  = r - (alpha * q);
424
-
425
-            if ((resid = r.norm() / normb) <= tol) {
426
-                tol = resid;
427
-                max_iter = i;
428
-                return 0;
429
-            }
430
-            rho_1 = rho;
431
-        }
432
-        tol = resid;
433
-        return 1;
434
-    }
435
-} // end of namespace Lemma
436
-
437
-#endif   // ----- #ifndef CG_INC  -----

+ 0
- 1366
Modules/Optimization/include/logbarriercg.h
File diff suppressed because it is too large
View File


+ 0
- 1956
Modules/Optimization/include/logbarriercg_newton.h
File diff suppressed because it is too large
View File


+ 0
- 111
Modules/Optimization/include/quasinewtonbfgs.h View File

1
-/* This file is part of Lemma, a geophysical modelling and inversion API */
2
-
3
-/* This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
-
7
-/**
8
-  @file
9
-  @author   Trevor Irons
10
-  @date     08/09/2010
11
-  @version  $Id: quasinewtonbfgs.h 193 2014-11-10 23:51:41Z tirons $
12
- **/
13
-
14
-#ifndef  QUASINEWTONBFGS_INC
15
-#define  QUASINEWTONBFGS_INC
16
-
17
-#include "inversesolver.h"
18
-
19
-namespace Lemma {
20
-
21
-
22
-    // ===================================================================
23
-    //  Class:  QuasiNewtonBFGS
24
-    /**
25
-      @class  QuasiNewtonBFGS
26
-      \brief  Implimentation of a quasi-newton BFGS solver applied to
27
-              inverse problems.
28
-      \details Based of the algorithm described in Nocedal and Wright book.
29
-     */
30
-    // ===================================================================
31
-    class QuasiNewtonBFGS : public InverseSolver {
32
-
33
-        friend  std::ostream &operator<<(std::ostream &stream,
34
-                const QuasiNewtonBFGS &ob);
35
-
36
-        public:
37
-
38
-            // ====================  LIFECYCLE     =======================
39
-
40
-            /** Returns a pointer to a new object of type QuasiNewtonBFGS.
41
-             * It allocates all necessary memory.
42
-             */
43
-            static QuasiNewtonBFGS* New();
44
-
45
-            /**
46
-             * @copybrief LemmaObject::Delete()
47
-             * @copydetails LemmaObject::Delete()
48
-             */
49
-            void Delete();
50
-
51
-            // ====================  OPERATORS     =======================
52
-
53
-            // ====================  OPERATIONS    =======================
54
-
55
-            // ====================  ACCESS        =======================
56
-
57
-            // ====================  INQUIRY       =======================
58
-
59
-            /** @copybrief InverseSolver::NumberOfIterations()
60
-             *  @copydetails InverseSolver::NumberOfIterations()
61
-             */
62
-            int NumberOfIterations();
63
-
64
-            /** @copybrief InverseSolver::Success()
65
-             *  @copydetails InverseSolver::Success()
66
-             */
67
-            bool Success();
68
-
69
-            /** @copybrief InverseSolver::GetPhiMVector()
70
-             *  @copydetails InverseSolver::GetPhiMVector()
71
-             */
72
-            VectorXr GetPhiMVector();
73
-
74
-            /** @copybrief InverseSolver::GetPhiDVector()
75
-             *  @copydetails InverseSolver::GetPhiDVector()
76
-             */
77
-            VectorXr GetPhiDVector();
78
-
79
-            /// TODO remove this, test
80
-            void PrintNorm();
81
-
82
-        protected:
83
-
84
-            // ====================  LIFECYCLE     =======================
85
-
86
-            /// Default protected constructor.
87
-            QuasiNewtonBFGS (const std::string& cname);
88
-
89
-            /// Default protected constructor.
90
-            ~QuasiNewtonBFGS ();
91
-
92
-            /**
93
-             * @copybrief LemmaObject::Release()
94
-             * @copydetails LemmaObject::Release()
95
-             */
96
-            void Release();
97
-
98
-            // ====================  OPERATIONS    =======================
99
-
100
-            /// Just a filler
101
-            void FillInG(const Vector3r& pos, const Vector3r& step);
102
-
103
-            // ====================  DATA MEMBERS  =========================
104
-
105
-        private:
106
-
107
-    }; // -----  end of class  QuasiNewtonBFGS  -----
108
-
109
-}		// -----  end of Lemma  name  -----
110
-
111
-#endif   // ----- #ifndef QUASINEWTONBFGS_INC  -----

+ 0
- 85
Modules/Optimization/src/quasinewtonbfgs.cpp View File

1
-/* This file is part of Lemma, a geophysical modelling and inversion API */
2
-
3
-/* This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
-
7
-/**
8
-  @file
9
-  @author   Trevor Irons
10
-  @date     08/09/2010
11
-  @version  $Id: quasinewtonbfgs.cpp 87 2013-09-05 22:44:05Z tirons $
12
- **/
13
-
14
-#include "quasinewtonbfgs.h"
15
-
16
-
17
-namespace Lemma {
18
-
19
-    // ====================  STREAMS       =======================
20
-
21
-    std::ostream &operator<<(std::ostream &stream,
22
-            const QuasiNewtonBFGS &ob) {
23
-        stream << *(InverseSolver*)(&ob);
24
-        return stream;
25
-    }
26
-
27
-
28
-    // ====================  LIFECYCLE     =======================
29
-
30
-    QuasiNewtonBFGS* QuasiNewtonBFGS::New() {
31
-        QuasiNewtonBFGS* Object = new QuasiNewtonBFGS("QuasiNewtonBFGS");
32
-        Object->AttachTo(Object);
33
-        return Object;
34
-    }
35
-
36
-    QuasiNewtonBFGS::QuasiNewtonBFGS(const std::string &name) :
37
-        InverseSolver(name) {
38
-    }
39
-
40
-    void QuasiNewtonBFGS::Delete() {
41
-        this->DetachFrom(this);
42
-    }
43
-
44
-    void QuasiNewtonBFGS::Release() {
45
-        delete this;
46
-    }
47
-
48
-    QuasiNewtonBFGS::~QuasiNewtonBFGS() {
49
-        if (this->NumberOfReferences != 0)
50
-            throw DeleteObjectWithReferences( this );
51
-    }
52
-
53
-    // ====================  INQUIRY       =======================
54
-
55
-    int QuasiNewtonBFGS::NumberOfIterations() {
56
-        return 0;
57
-    }
58
-
59
-    bool QuasiNewtonBFGS::Success () {
60
-        return false;
61
-    }
62
-
63
-    void QuasiNewtonBFGS::PrintNorm() {
64
-        std::cout << "Norm " << std::endl;
65
-        PredictedData->Zero();
66
-        std::cout << ObservedData->Norm(PredictedData) << std::endl;
67
-    }
68
-
69
-    VectorXr QuasiNewtonBFGS::GetPhiMVector() {
70
-        VectorXr NewVec(2);
71
-        return NewVec;
72
-    }
73
-
74
-    VectorXr QuasiNewtonBFGS::GetPhiDVector() {
75
-        VectorXr NewVec(2);
76
-        return NewVec;
77
-    }
78
-
79
-    void QuasiNewtonBFGS::FillInG(const Vector3r& pos, const Vector3r& step) {
80
-
81
-    }
82
-
83
-    // ====================  ACCESS        =======================
84
-
85
-}		// -----  end of Lemma  name  -----

Loading…
Cancel
Save