瀏覽代碼

Model class added for forward modelling as well.

master
Trevor Irons 7 年之前
父節點
當前提交
65b348c9f5
共有 7 個檔案被更改,包括 318 行新增6 行删除
  1. 9
    6
      examples/ForwardFID.cpp
  2. 11
    0
      include/ForwardFID.h
  3. 143
    0
      include/LayeredEarthMR.h
  4. 1
    0
      include/Merlin
  5. 1
    0
      src/CMakeLists.txt
  6. 24
    0
      src/ForwardFID.cpp
  7. 129
    0
      src/LayeredEarthMR.cpp

+ 9
- 6
examples/ForwardFID.cpp 查看文件

@@ -27,13 +27,16 @@ int main(int argc, char** argv) {
27 27
     //    return(EXIT_FAILURE);
28 28
     }
29 29
 
30
-    auto Forward = ForwardFID::NewSP();
31
-        Forward->SetWindowEdges( VectorXr::LinSpaced(10,0,1) );
32
-
33
-    std::cout << *Forward << std::endl;
30
+    auto Model = LayeredEarthMR::NewSP();
31
+        Model->SetNumberOfLayers(20);
32
+        Model->SetT2StarBins(10, 500, 20);
33
+        std::cout << *Model << std::endl;
34 34
 
35
-    //auto FID = Forward->ForwardModel();
36
-    //std::cout << *FID << std::endl;
35
+    auto Forward = ForwardFID::NewSP();
36
+        //Forward->SetWindowEdges( VectorXr::LinSpaced(10,0,1) );
37
+        Forward->SetLogSpacedWindows(10,1000,30);
38
+        //auto FID =  Forward->ForwardModel(Model);
39
+    //std::cout << *Forward << std::endl;
37 40
 
38 41
     return EXIT_SUCCESS;
39 42
 }

+ 11
- 0
include/ForwardFID.h 查看文件

@@ -116,6 +116,15 @@ namespace Lemma {
116 116
          */
117 117
         void SetWindowEdges( const VectorXr& Edges );
118 118
 
119
+        /**
120
+         *  Sets the windows for calculation as a series of log spaced windows.
121
+         *  This method calculates the window edges, so the centres will be n-1
122
+         *  @param[in] first is the beginning of the vector
123
+         *  @param[in] last is the last element in the vector
124
+         *  @param[in] n is the number of elements
125
+         */
126
+        void SetLogSpacedWindows(const Real& first, const Real& last, const int& n);
127
+
119 128
         // ====================  INQUIRY       =======================
120 129
         /**
121 130
          *  Returns the name of the underlying class, similiar to Python's type
@@ -135,6 +144,8 @@ namespace Lemma {
135 144
         // ====================  DATA MEMBERS  =========================
136 145
         private:
137 146
 
147
+        void CalcQTMatrix(  );
148
+
138 149
         /** ASCII string representation of the class name */
139 150
         static constexpr auto CName = "ForwardFID";
140 151
 

+ 143
- 0
include/LayeredEarthMR.h 查看文件

@@ -0,0 +1,143 @@
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      08/28/2017 03:32:26 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2017, University of Utah
17
+ * @copyright Copyright (c) 2017, Lemma Software, LLC
18
+ */
19
+
20
+#ifndef  LAYEREDEARTHMR_INC
21
+#define  LAYEREDEARTHMR_INC
22
+
23
+
24
+#pragma once
25
+#include "LayeredEarth.h"
26
+#include "MerlinConfig.h"
27
+
28
+namespace Lemma {
29
+
30
+    /**
31
+     * \ingroup Merlin
32
+     * \brief
33
+     * \details
34
+     */
35
+    class LayeredEarthMR : public LayeredEarth {
36
+
37
+        friend std::ostream &operator<<(std::ostream &stream, const LayeredEarthMR &ob);
38
+
39
+        protected:
40
+        /*
41
+         *  This key is used to lock the constructor. It is protected so that inhereted
42
+         *  classes also have the key to contruct their base class.
43
+         */
44
+        struct ctor_key {};
45
+
46
+        public:
47
+
48
+        // ====================  LIFECYCLE     =======================
49
+
50
+        /**
51
+         * Default constructor.
52
+         * @note This method is locked, and cannot be called directly.
53
+         *       The reason that the method is public is to enable the use
54
+         *       of make_shared whilst enforcing the use of shared_ptr,
55
+         *       in c++-17, this curiosity may be resolved.
56
+         * @see LayeredEarthMR::NewSP
57
+         */
58
+        explicit LayeredEarthMR ( const ctor_key& );
59
+
60
+        /**
61
+         * DeSerializing constructor.
62
+         * @note This method is locked, and cannot be called directly.
63
+         *       The reason that the method is public is to enable the use
64
+         *       of make_shared whilst enforcing the use of shared_ptr,
65
+         *       in c++-17, this curiosity may be resolved.
66
+         * @see LayeredEarthMR::DeSerialize
67
+         */
68
+        LayeredEarthMR ( const YAML::Node& node, const ctor_key& );
69
+
70
+        /**
71
+         * Default destructor.
72
+         * @note This method should never be called due to the mandated
73
+         *       use of smart pointers. It is necessary to keep the method
74
+         *       public in order to allow for the use of the more efficient
75
+         *       make_shared constructor.
76
+         */
77
+        virtual ~LayeredEarthMR ();
78
+
79
+        /**
80
+         *  Uses YAML to serialize this object.
81
+         *  @return a YAML::Node
82
+         *  @see LayeredEarthMR::DeSerialize
83
+         */
84
+        virtual YAML::Node Serialize() const;
85
+
86
+        /*
87
+         *  Factory method for generating concrete class.
88
+         *  @return a std::shared_ptr of type LayeredEarthMR
89
+         */
90
+        static std::shared_ptr< LayeredEarthMR > NewSP();
91
+
92
+        /**
93
+         *   Constructs an LayeredEarthMR object from a YAML::Node.
94
+         *   @see LayeredEarthMR::Serialize
95
+         */
96
+        static std::shared_ptr<LayeredEarthMR> DeSerialize(const YAML::Node& node);
97
+
98
+        // ====================  OPERATORS     =======================
99
+
100
+        // ====================  OPERATIONS    =======================
101
+
102
+        // ====================  ACCESS        =======================
103
+
104
+
105
+        void SetNumberOfLayers(const int& nlay);
106
+
107
+        void SetT2StarBins(const Real& first, const Real& last, const int& nT2);
108
+
109
+        // ====================  INQUIRY       =======================
110
+        /**
111
+         *  Returns the name of the underlying class, similiar to Python's type
112
+         *  @return string of class name
113
+         */
114
+        virtual inline std::string GetName() const {
115
+            return CName;
116
+        }
117
+
118
+        protected:
119
+
120
+        // ====================  LIFECYCLE     =======================
121
+
122
+        /** Copy is disabled */
123
+        LayeredEarthMR( const LayeredEarthMR& ) = delete;
124
+
125
+        // ====================  DATA MEMBERS  =========================
126
+
127
+        private:
128
+
129
+        /** ASCII string representation of the class name */
130
+        static constexpr auto CName = "LayeredEarthMR";
131
+
132
+        VectorXr T2StarBins;
133
+        VectorXr T2StarBinEdges;  // Convenience for pcolor
134
+
135
+    }; // -----  end of class  LayeredEarthMR  -----
136
+}  // -----  end of namespace Lemma ----
137
+
138
+/* vim: set tabstop=4 expandtab: */
139
+/* vim: set filetype=cpp: */
140
+
141
+
142
+#endif   // ----- #ifndef LAYEREDEARTHMR_INC  -----
143
+

+ 1
- 0
include/Merlin 查看文件

@@ -3,6 +3,7 @@
3 3
 #include "Coupling.h"
4 4
 #include "LoopInteractions.h"
5 5
 #include "DataFID.h"
6
+#include "LayeredEarthMR.h"
6 7
 
7 8
 /* vim: set tabstop=4 expandtab: */
8 9
 /* vim: set filetype=cpp: */

+ 1
- 0
src/CMakeLists.txt 查看文件

@@ -5,5 +5,6 @@ set (MERLINSOURCE
5 5
 	${CMAKE_CURRENT_SOURCE_DIR}/Coupling.cpp
6 6
 	${CMAKE_CURRENT_SOURCE_DIR}/LoopInteractions.cpp
7 7
 	${CMAKE_CURRENT_SOURCE_DIR}/DataFID.cpp
8
+	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarthMR.cpp
8 9
 	PARENT_SCOPE
9 10
 )

+ 24
- 0
src/ForwardFID.cpp 查看文件

@@ -114,6 +114,30 @@ namespace Lemma {
114 114
         return FID;
115 115
     }		// -----  end of method ForwardFID::ForwardModel  -----
116 116
 
117
+    //--------------------------------------------------------------------------------------
118
+    //       Class:  ForwardFID
119
+    //      Method:  LogSpaced
120
+    //--------------------------------------------------------------------------------------
121
+    void ForwardFID::SetLogSpacedWindows ( const Real& first, const Real& last,
122
+        const int& n ) {
123
+        WindowEdges = VectorXr::Zero(n);
124
+        Real m = 1./(n-1.);
125
+        Real quotient = std::pow(last/first, m);
126
+        WindowEdges[0] = first;
127
+        for (int i=1; i<n; ++i) {
128
+            WindowEdges[i] = WindowEdges[i-1]*quotient;
129
+        }
130
+        WindowCentres = (WindowEdges.head(n-1) + WindowEdges.tail(n-1)) / 2;
131
+        return;
132
+    }		// -----  end of method ForwardFID::LogSpaced  -----
133
+
134
+    //--------------------------------------------------------------------------------------
135
+    //       Class:  ForwardFID
136
+    //      Method:  CalcQTMatrix
137
+    //--------------------------------------------------------------------------------------
138
+    void ForwardFID::CalcQTMatrix (  ) {
139
+        return ;
140
+    }		// -----  end of method ForwardFID::CalcQTMatrix  -----
117 141
 
118 142
 } // ----  end of namespace Lemma  ----
119 143
 

+ 129
- 0
src/LayeredEarthMR.cpp 查看文件

@@ -0,0 +1,129 @@
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      08/28/2017 03:32:34 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2017, University of Utah
17
+ * @copyright Copyright (c) 2017, Lemma Software, LLC
18
+ */
19
+
20
+#include "LayeredEarthMR.h"
21
+
22
+namespace Lemma {
23
+
24
+    // ====================  FRIEND METHODS  =====================
25
+
26
+    std::ostream &operator << (std::ostream &stream, const LayeredEarthMR &ob) {
27
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
28
+        return stream;
29
+    }
30
+
31
+    // ====================  LIFECYCLE     =======================
32
+
33
+    //--------------------------------------------------------------------------------------
34
+    //       Class:  LayeredEarthMR
35
+    //      Method:  LayeredEarthMR
36
+    // Description:  constructor (locked)
37
+    //--------------------------------------------------------------------------------------
38
+    LayeredEarthMR::LayeredEarthMR (const ctor_key&) : LayeredEarth( ) {
39
+
40
+    }  // -----  end of method LayeredEarthMR::LayeredEarthMR  (constructor)  -----
41
+
42
+    //--------------------------------------------------------------------------------------
43
+    //       Class:  LayeredEarthMR
44
+    //      Method:  LayeredEarthMR
45
+    // Description:  DeSerializing constructor (locked)
46
+    //--------------------------------------------------------------------------------------
47
+    LayeredEarthMR::LayeredEarthMR (const YAML::Node& node, const ctor_key&) : LayeredEarth(node) {
48
+
49
+    }  // -----  end of method LayeredEarthMR::LayeredEarthMR  (constructor)  -----
50
+
51
+    //--------------------------------------------------------------------------------------
52
+    //       Class:  LayeredEarthMR
53
+    //      Method:  NewSP()
54
+    // Description:  public constructor returing a shared_ptr
55
+    //--------------------------------------------------------------------------------------
56
+    std::shared_ptr< LayeredEarthMR >  LayeredEarthMR::NewSP() {
57
+        return std::make_shared< LayeredEarthMR >( ctor_key() );
58
+    }
59
+
60
+    //--------------------------------------------------------------------------------------
61
+    //       Class:  LayeredEarthMR
62
+    //      Method:  ~LayeredEarthMR
63
+    // Description:  destructor (protected)
64
+    //--------------------------------------------------------------------------------------
65
+    LayeredEarthMR::~LayeredEarthMR () {
66
+
67
+    }  // -----  end of method LayeredEarthMR::~LayeredEarthMR  (destructor)  -----
68
+
69
+    //--------------------------------------------------------------------------------------
70
+    //       Class:  LayeredEarthMR
71
+    //      Method:  Serialize
72
+    //--------------------------------------------------------------------------------------
73
+    YAML::Node  LayeredEarthMR::Serialize (  ) const {
74
+        YAML::Node node = LayeredEarth::Serialize();
75
+        node.SetTag( GetName() );
76
+        // FILL IN CLASS SPECIFICS HERE
77
+        node["Merlin_VERSION"] = MERLIN_VERSION;
78
+        node["T2StarBins"] = T2StarBins;
79
+        node["T2StarBinEdges"] = T2StarBinEdges;
80
+        return node;
81
+    }		// -----  end of method LayeredEarthMR::Serialize  -----
82
+
83
+    //--------------------------------------------------------------------------------------
84
+    //       Class:  LayeredEarthMR
85
+    //      Method:  DeSerialize
86
+    //--------------------------------------------------------------------------------------
87
+    std::shared_ptr<LayeredEarthMR> LayeredEarthMR::DeSerialize ( const YAML::Node& node  ) {
88
+        if (node.Tag() !=  "LayeredEarthMR" ) {
89
+            throw  DeSerializeTypeMismatch( "LayeredEarthMR", node.Tag());
90
+        }
91
+        return std::make_shared< LayeredEarthMR > ( node, ctor_key() );
92
+    }		// -----  end of method LayeredEarthMR::DeSerialize  -----
93
+
94
+    //--------------------------------------------------------------------------------------
95
+    //       Class:  LayeredEarthMR
96
+    //      Method:  SetNumberOfLayers
97
+    //--------------------------------------------------------------------------------------
98
+    void LayeredEarthMR::SetNumberOfLayers ( const int& nlay  ) {
99
+        return ;
100
+    }		// -----  end of method LayeredEarthMR::SetNumberOfLayers  -----
101
+
102
+
103
+    //--------------------------------------------------------------------------------------
104
+    //       Class:  LayeredEarthMR
105
+    //      Method:  SetNumberOfT2StarBins
106
+    //--------------------------------------------------------------------------------------
107
+    void LayeredEarthMR::SetT2StarBins ( const Real& first, const Real& last, const int& nT2 ) {
108
+        T2StarBinEdges = VectorXr::Zero(nT2+1);
109
+        Real m = 1./(nT2);
110
+        Real quotient = std::pow(last/first, m);
111
+        T2StarBinEdges[0] = first;
112
+        for (int i=1; i<nT2+1; ++i) {
113
+            T2StarBinEdges[i] = T2StarBinEdges[i-1]*quotient;
114
+        }
115
+        T2StarBins = (T2StarBinEdges.head(nT2) + T2StarBinEdges.tail(nT2)) / 2;
116
+        return;
117
+    }		// -----  end of method LayeredEarthMR::SetNumberOfT2StarBins  -----
118
+
119
+
120
+} // ----  end of namespace Lemma  ----
121
+
122
+
123
+
124
+
125
+
126
+/* vim: set tabstop=4 expandtab: */
127
+/* vim: set filetype=cpp: */
128
+
129
+

Loading…
取消
儲存