Browse Source

Merlin 2.0 has been started conforming with changes to Lemma. Leaner, meaner and more elegant. Kernel calculations are up first.

master
Trevor Irons 5 years ago
commit
507ae715f2
10 changed files with 429 additions and 0 deletions
  1. 30
    0
      CMakeLists.txt
  2. 14
    0
      Merlin.dox
  3. 6
    0
      examples/CMakeLists.txt
  4. 69
    0
      examples/KernelV0.cpp
  5. 163
    0
      include/KernelV0.h
  6. 4
    0
      include/Merlin
  7. BIN
      src/.KernelV0.cpp.swp
  8. 4
    0
      src/CMakeLists.txt
  9. 139
    0
      src/KernelV0.cpp
  10. 0
    0
      testing/CMakeLists.txt

+ 30
- 0
CMakeLists.txt View File

@@ -0,0 +1,30 @@
1
+add_subdirectory("src")
2
+add_library( merlin ${MERLINSOURCE} )  
3
+target_include_directories( merlin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
4
+
5
+set_target_properties(merlin PROPERTIES 
6
+	VERSION  "${LEMMA_VERSION_NOQUOTES}"
7
+	SOVERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}"
8
+	PROJECT_LABEL "FDEM1D ${LABEL_SUFFIX}"
9
+)
10
+
11
+# Linking
12
+target_link_libraries(merlin "lemmacore" "fdem1d" )
13
+
14
+# Testing
15
+if (LEMMA_ENABLE_TESTING)
16
+	add_subdirectory(testing)
17
+endif()
18
+
19
+# Install
20
+install ( TARGETS merlin DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
21
+install ( FILES include/MERLIN  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 
22
+install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma  FILES_MATCHING PATTERN "*.h")
23
+
24
+#install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/  FILES_MATCHING PATTERN "FDEM1D")
25
+#install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/FDEM1D  FILES_MATCHING PATTERN "*.h")
26
+
27
+# Examples
28
+if (LEMMA_BUILD_EXAMPLES)
29
+	add_subdirectory(examples)
30
+endif()

+ 14
- 0
Merlin.dox View File

@@ -0,0 +1,14 @@
1
+/**
2
+ * @file
3
+ * @date      09/15/2016 04:28:16 PM
4
+ * @author    Trevor Irons (ti)
5
+ * @email     tirons@egi.utah.edu
6
+ * @copyright Copyright (c) 2016, University of Utah
7
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
8
+ */
9
+
10
+/**
11
+    \defgroup Merlin Merlin
12
+    @brief    Merlin provides surface NMR capabilities.
13
+    @details  Merlin provides classes and methods for sNMR modelling and inversion.
14
+*/

+ 6
- 0
examples/CMakeLists.txt View File

@@ -0,0 +1,6 @@
1
+add_executable( KernelV0 KernelV0.cpp  )
2
+target_link_libraries(  KernelV0  "lemmacore" "fdem1d" "merlin")
3
+
4
+INSTALL_TARGETS( "/share/Merlin/"
5
+	KernelV0
6
+)

+ 69
- 0
examples/KernelV0.cpp View File

@@ -0,0 +1,69 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      11/11/2016 02:44:37 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
18
+ */
19
+
20
+#include <Merlin>
21
+using namespace Lemma;
22
+
23
+std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real Offsetx, Real Offsety ) ;
24
+
25
+int main() {
26
+
27
+	auto earth = LayeredEarthEM::NewSP();
28
+		earth->SetNumberOfLayers(3);
29
+		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
30
+		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
31
+
32
+    // Transmitter loops
33
+    auto Tx1 = CircularLoop(60, 15, 0, 0);
34
+    auto Tx2 = CircularLoop(60, 15, 15, 0);
35
+    //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
36
+
37
+    auto Kern = KernelV0::NewSP();
38
+        Kern->PushCoil( "Coil 1", Tx1 );
39
+        Kern->PushCoil( "Coil 2", Tx2 );
40
+        Kern->SetLayeredEarthEM( earth );
41
+        // std::cout << *Kern << std::endl;
42
+
43
+    // We could, I suppose, take the earth model in here? For non-linear that
44
+    // may be more natural to work with?
45
+    std::vector<std::string> tx = {std::string("Coil 1")};
46
+    std::vector<std::string> rx = {std::string("Coil 1")};
47
+    Kern->CalculateK0( tx, rx );
48
+    //Kern->CalculateK0( "Coil 1", "Coil 1" );
49
+
50
+}
51
+
52
+std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
53
+    auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
54
+         Tx1->SetNumberOfPoints(nd);
55
+
56
+    VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
57
+    int ii;
58
+    for (ii=0; ii<nd-1; ++ii) {
59
+        Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
60
+    }
61
+    Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*1, Offsety,  -1e-3));
62
+
63
+    Tx1->SetCurrent(1.);
64
+    Tx1->SetNumberOfTurns(1);
65
+    Tx1->SetNumberOfFrequencies(1);
66
+    Tx1->SetFrequency(0,2500);
67
+
68
+    return Tx1;
69
+}

+ 163
- 0
include/KernelV0.h View File

@@ -0,0 +1,163 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      11/11/2016 01:47:34 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
18
+ */
19
+#ifndef  KERNELV0_INC
20
+#define  KERNELV0_INC
21
+
22
+#pragma once
23
+#include "LemmaObject.h"
24
+#include "LayeredEarthEM.h"
25
+#include "PolygonalWireAntenna.h"
26
+
27
+namespace Lemma {
28
+
29
+    /**
30
+     * \ingroup Merlin
31
+     * \brief
32
+     * \details
33
+     */
34
+    class KernelV0 : public LemmaObject {
35
+
36
+        friend std::ostream &operator<<(std::ostream &stream, const KernelV0 &ob);
37
+
38
+        protected:
39
+        /*
40
+         *  This key is used to lock the constructor. It is protected so that inhereted
41
+         *  classes also have the key to contruct their base class.
42
+         */
43
+        struct ctor_key {};
44
+
45
+        public:
46
+
47
+        // ====================  LIFECYCLE     =======================
48
+
49
+        /**
50
+         * Default constructor.
51
+         * @note This method is locked, and cannot be called directly.
52
+         *       The reason that the method is public is to enable the use
53
+         *       of make_shared whilst enforcing the use of shared_ptr,
54
+         *       in c++-17, this curiosity may be resolved.
55
+         * @see KernelV0::NewSP
56
+         */
57
+        explicit KernelV0 ( const ctor_key& );
58
+
59
+        /**
60
+         * DeSerializing constructor.
61
+         * @note This method is locked, and cannot be called directly.
62
+         *       The reason that the method is public is to enable the use
63
+         *       of make_shared whilst enforcing the use of shared_ptr,
64
+         *       in c++-17, this curiosity may be resolved.
65
+         * @see KernelV0::DeSerialize
66
+         */
67
+        KernelV0 ( const YAML::Node& node, const ctor_key& );
68
+
69
+        /**
70
+         * Default destructor.
71
+         * @note This method should never be called due to the mandated
72
+         *       use of smart pointers. It is necessary to keep the method
73
+         *       public in order to allow for the use of the more efficient
74
+         *       make_shared constructor.
75
+         */
76
+        virtual ~KernelV0 ();
77
+
78
+        /**
79
+         *  Uses YAML to serialize this object.
80
+         *  @return a YAML::Node
81
+         *  @see KernelV0::DeSerialize
82
+         */
83
+        virtual YAML::Node Serialize() const;
84
+
85
+        /*
86
+         *  Factory method for generating concrete class.
87
+         *  @return a std::shared_ptr of type KernelV0
88
+         */
89
+        static std::shared_ptr< KernelV0 > NewSP();
90
+
91
+        /**
92
+         *   Constructs an KernelV0 object from a YAML::Node.
93
+         *   @see KernelV0::Serialize
94
+         */
95
+        static std::shared_ptr<KernelV0> DeSerialize(const YAML::Node& node);
96
+
97
+        // ====================  OPERATORS     =======================
98
+
99
+        // ====================  OPERATIONS    =======================
100
+
101
+        /**
102
+         * @return std::shared_ptr<LayeredEarthEM>
103
+         */
104
+        inline std::shared_ptr<LayeredEarthEM> GetSigmaModel (  ) {
105
+            return SigmaModel;
106
+        }		// -----  end of method KernelV0::get_SigmaModel  -----
107
+
108
+        /**
109
+         * @param[in] value the 1D-EM model used for calculations
110
+         */
111
+        inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
112
+            SigmaModel	= value;
113
+            return ;
114
+        }		// -----  end of method KernelV0::set_SigmaModel  -----
115
+
116
+        /**
117
+         *   Assign transmiter coils
118
+         */
119
+        inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
120
+            TxRx[label] = ant;
121
+        }
122
+
123
+        /**
124
+         *
125
+         */
126
+        void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx );
127
+
128
+        void CalculateK0 (const char* tx, const char* rx );
129
+
130
+        // ====================  INQUIRY       =======================
131
+        /**
132
+         *  Returns the name of the underlying class, similiar to Python's type
133
+         *  @return string of class name
134
+         */
135
+        virtual inline std::string GetName() const {
136
+            return CName;
137
+        }
138
+
139
+        protected:
140
+
141
+        // ====================  LIFECYCLE     =======================
142
+
143
+        /** Copy is disabled */
144
+        KernelV0( const KernelV0& ) = delete;
145
+
146
+        // ====================  DATA MEMBERS  =========================
147
+
148
+        private:
149
+
150
+        std::shared_ptr< LayeredEarthEM >        SigmaModel;
151
+
152
+        std::map< std::string , std::shared_ptr< PolygonalWireAntenna > >  TxRx;
153
+
154
+        /** ASCII string representation of the class name */
155
+        static constexpr auto CName = "KernelV0";
156
+
157
+    }; // -----  end of class  KernelV0  -----
158
+}  // -----  end of namespace Lemma ----
159
+
160
+/* vim: set tabstop=4 expandtab: */
161
+/* vim: set filetype=cpp: */
162
+
163
+#endif   // ----- #ifndef KERNELV0_INC  -----

+ 4
- 0
include/Merlin View File

@@ -0,0 +1,4 @@
1
+#include "KernelV0.h"
2
+
3
+/* vim: set tabstop=4 expandtab: */
4
+/* vim: set filetype=cpp: */

BIN
src/.KernelV0.cpp.swp View File


+ 4
- 0
src/CMakeLists.txt View File

@@ -0,0 +1,4 @@
1
+set (MERLINSOURCE
2
+	${CMAKE_CURRENT_SOURCE_DIR}/KernelV0.cpp
3
+	PARENT_SCOPE
4
+)

+ 139
- 0
src/KernelV0.cpp View File

@@ -0,0 +1,139 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      11/11/2016 01:47:25 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
18
+ */
19
+
20
+
21
+#include "KernelV0.h"
22
+#include "EMEarth1D.h"
23
+#include "FieldPoints.h"
24
+
25
+namespace Lemma {
26
+
27
+    // ====================  FRIEND METHODS  =====================
28
+
29
+    std::ostream &operator << (std::ostream &stream, const KernelV0 &ob) {
30
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
31
+        return stream;
32
+    }
33
+
34
+    // ====================  LIFECYCLE     =======================
35
+
36
+    //--------------------------------------------------------------------------------------
37
+    //       Class:  KernelV0
38
+    //      Method:  KernelV0
39
+    // Description:  constructor (locked)
40
+    //--------------------------------------------------------------------------------------
41
+    KernelV0::KernelV0 (const ctor_key&) : LemmaObject( ) {
42
+
43
+    }  // -----  end of method KernelV0::KernelV0  (constructor)  -----
44
+
45
+    //--------------------------------------------------------------------------------------
46
+    //       Class:  KernelV0
47
+    //      Method:  KernelV0
48
+    // Description:  DeSerializing constructor (locked)
49
+    //--------------------------------------------------------------------------------------
50
+    KernelV0::KernelV0 (const YAML::Node& node, const ctor_key&) : LemmaObject(node) {
51
+
52
+    }  // -----  end of method KernelV0::KernelV0  (constructor)  -----
53
+
54
+    //--------------------------------------------------------------------------------------
55
+    //       Class:  KernelV0
56
+    //      Method:  NewSP()
57
+    // Description:  public constructor returing a shared_ptr
58
+    //--------------------------------------------------------------------------------------
59
+    std::shared_ptr< KernelV0 >  KernelV0::NewSP() {
60
+        return std::make_shared< KernelV0 >( ctor_key() );
61
+    }
62
+
63
+    //--------------------------------------------------------------------------------------
64
+    //       Class:  KernelV0
65
+    //      Method:  ~KernelV0
66
+    // Description:  destructor (protected)
67
+    //--------------------------------------------------------------------------------------
68
+    KernelV0::~KernelV0 () {
69
+
70
+    }  // -----  end of method KernelV0::~KernelV0  (destructor)  -----
71
+
72
+    //--------------------------------------------------------------------------------------
73
+    //       Class:  KernelV0
74
+    //      Method:  Serialize
75
+    //--------------------------------------------------------------------------------------
76
+    YAML::Node  KernelV0::Serialize (  ) const {
77
+        YAML::Node node = LemmaObject::Serialize();
78
+        node.SetTag( GetName() );
79
+
80
+        // Coils Transmitters & Receivers
81
+        for ( auto txm : TxRx) {
82
+            node[txm.first] = txm.second->Serialize();
83
+        }
84
+
85
+        // LayeredEarthEM
86
+        node["SigmaModel"] = SigmaModel->Serialize();
87
+
88
+        return node;
89
+    }		// -----  end of method KernelV0::Serialize  -----
90
+
91
+    //--------------------------------------------------------------------------------------
92
+    //       Class:  KernelV0
93
+    //      Method:  DeSerialize
94
+    //--------------------------------------------------------------------------------------
95
+    std::shared_ptr<KernelV0> KernelV0::DeSerialize ( const YAML::Node& node  ) {
96
+        if (node.Tag() !=  "KernelV0" ) {
97
+            throw  DeSerializeTypeMismatch( "KernelV0", node.Tag());
98
+        }
99
+        return std::make_shared< KernelV0 > ( node, ctor_key() );
100
+    }		// -----  end of method KernelV0::DeSerialize  -----
101
+
102
+    //--------------------------------------------------------------------------------------
103
+    //       Class:  KernelV0
104
+    //      Method:  DeSerialize
105
+    //--------------------------------------------------------------------------------------
106
+    void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx ) {
107
+
108
+        for (auto tx : Tx) {
109
+            // Set up EMEarth
110
+            auto EmEarth = EMEarth1D::NewSP();
111
+                EmEarth->AttachWireAntenna(TxRx[tx]);
112
+                EmEarth->AttachLayeredEarthEM(SigmaModel);
113
+         		EmEarth->SetFieldsToCalculate(H);
114
+                // TODO query for method, altough with flat antennae, this is fastest
115
+                EmEarth->SetHankelTransformMethod(ANDERSON801);
116
+
117
+// 		EmEarth->AttachFieldPoints(receivers);
118
+//         //EmEarth->SetHankelTransformMethod(FHTKEY101);
119
+// 	    EmEarth->CalculateWireAntennaFields();
120
+//         Vector3Xcr Rx1 = receivers->GetHfield(0);
121
+//         //receivers->ClearFields();
122
+//
123
+// 		//EmEarth->AttachWireAntenna(Tx2);
124
+// 	    EmEarth->CalculateWireAntennaFields();
125
+//         Rx1 += receivers->GetHfield(0);
126
+
127
+        }
128
+
129
+    }
130
+
131
+    void KernelV0::CalculateK0 ( const char* tx, const char* rx ) {
132
+
133
+    }
134
+
135
+} // ----  end of namespace Lemma  ----
136
+
137
+/* vim: set tabstop=4 expandtab: */
138
+/* vim: set filetype=cpp: */
139
+

+ 0
- 0
testing/CMakeLists.txt View File


Loading…
Cancel
Save