Browse Source

Added serialization of KernelV0 encompasing all input parameters. No need to compile to change settings.

master
T-bone 7 years ago
parent
commit
2067f79ac6
3 changed files with 99 additions and 39 deletions
  1. 26
    22
      examples/KernelV0-2.cpp
  2. 24
    3
      include/KernelV0.h
  3. 49
    14
      src/KernelV0.cpp

+ 26
- 22
examples/KernelV0-2.cpp View File

@@ -23,23 +23,29 @@ using namespace Lemma;
23 23
 
24 24
 int main(int argc, char** argv) {
25 25
 
26
-    if (argc<4) {
27
-        std::cout << "./KernelV0-2 earth.yaml tx.yaml  rx.yaml \n";
26
+    if (argc<3) {
27
+        //std::cout << "./KernelV0-2 earth.yaml tx.yaml  rx.yaml \n";
28
+        std::cout << "./KernelV0-2 Kernel.yaml TxString RxString  \n";
28 29
         return(EXIT_SUCCESS);
29 30
     }
30
-    std::cout << "Using earth model: " << argv[1] << std::endl;
31
-    auto earth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[1]) );
32 31
 
33
-    std::cout << "Using transmitter: " << argv[2] << std::endl;
34
-    auto Tx = PolygonalWireAntenna::DeSerialize( YAML::LoadFile(argv[2]) );
32
+    std::cout << "Using kernel paramaters: " << argv[1] << std::endl;
33
+    auto Kern = KernelV0::DeSerialize( YAML::LoadFile(argv[1]) );
35 34
 
36
-    std::cout << "Using receivers: " << argv[3] << std::endl;
37
-    auto Rx1 = PolygonalWireAntenna::DeSerialize( YAML::LoadFile(argv[3]) );
35
+//     std::cout << "Using earth model: " << argv[1] << std::endl;
36
+//     auto earth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[2]) );
37
+//
38
+//     std::cout << "Using transmitter: " << argv[2] << std::endl;
39
+//     auto Tx = PolygonalWireAntenna::DeSerialize( YAML::LoadFile(argv[3]) );
40
+//
41
+//     std::cout << "Using receivers: " << argv[3] << std::endl;
42
+//     auto Rx1 = PolygonalWireAntenna::DeSerialize( YAML::LoadFile(argv[4]) );
38 43
 
44
+#if 0
39 45
     auto Kern = KernelV0::NewSP();
40
-        Kern->PushCoil( "Coil 1", Tx );
41
-        Kern->PushCoil( "Coil 2", Rx1 );
42
-        Kern->SetLayeredEarthEM( earth );
46
+        //Kern->PushCoil( "Coil 1", Tx );
47
+        //Kern->PushCoil( "Coil 2", Rx1 );
48
+        //Kern->SetLayeredEarthEM( earth );
43 49
 
44 50
         Kern->SetIntegrationSize( (Vector3r() << 200, 200., 100).finished() );
45 51
         Kern->SetIntegrationOrigin( (Vector3r() << -100, -100, .5).finished() );
@@ -64,22 +70,20 @@ int main(int argc, char** argv) {
64 70
 
65 71
         //VectorXr interfaces = VectorXr::LinSpaced( 41, .5, 45.5 ); // nlay, low, high
66 72
         //VectorXr interfaces = VectorXr::LinSpaced( 61, .5, 45.5 ); // nlay, low, high
67
-        VectorXr interfaces = VectorXr::LinSpaced( 61, .5, 45.5 ); // nlay, low, high
73
+        VectorXr interfaces = VectorXr::LinSpaced( 58, .5, 45.5 ); // nlay, low, high
68 74
         Real thick = .1;
69 75
         for (int ilay=1; ilay<interfaces.size(); ++ilay) {
70 76
             interfaces(ilay) = interfaces(ilay-1) + thick;
71
-            thick *= 1.075;
77
+            thick *= 1.085;
72 78
         }
73 79
         Kern->SetDepthLayerInterfaces( interfaces ); // nlay, low, high
74 80
 
75 81
     // We could, I suppose, take the earth model in here? For non-linear that
76 82
     // may be more natural to work with?
77
-    std::vector<std::string> tx = {std::string("Coil 1")};
78
-    std::vector<std::string> rx = {std::string("Coil 2")};
79
-
80
-    //std::cout << "KERNEL.yaml" << std::endl;
81
-    //std::cout << *Kern << std::endl;
83
+#endif
82 84
 
85
+    std::vector<std::string> tx = {std::string(argv[2])};
86
+    std::vector<std::string> rx = {std::string(argv[3])};
83 87
     Kern->CalculateK0( tx, rx, false ); // 3rd argument is vtk output
84 88
 
85 89
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
@@ -91,10 +95,9 @@ int main(int argc, char** argv) {
91 95
     for (auto lp : rx) {
92 96
         dout << lp << "\t";
93 97
     }
94
-    dout << "\n# Tolerance: " << tol << std::endl;
95
-
96
-        dout << interfaces.transpose() << std::endl;
97
-        dout << I.transpose() << std::endl;
98
+    dout << "\n# Tolerance: " << Kern->GetTolerance() << std::endl;
99
+        dout << Kern->GetInterfaces().transpose() << std::endl;
100
+        dout << Kern->GetPulseDuration()*Kern->GetPulseCurrent().transpose() << std::endl;
98 101
         dout << "#real\n";
99 102
         dout << Kern->GetKernel().real() << std::endl;
100 103
         dout << "#imag\n";
@@ -105,6 +108,7 @@ int main(int argc, char** argv) {
105 108
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
106 109
     out << *Kern;
107 110
     out.close();
111
+
108 112
 }
109 113
 
110 114
 

+ 24
- 3
include/KernelV0.h View File

@@ -166,6 +166,27 @@ namespace Lemma {
166 166
         }
167 167
 
168 168
         /**
169
+         * @return the integration tolerance
170
+         */
171
+        inline Real GetTolerance ( ) {
172
+            return tol;
173
+        }
174
+
175
+        /**
176
+         * @return the layer interfaces
177
+         */
178
+        inline VectorXr GetInterfaces ( ) {
179
+            return Interfaces;
180
+        }
181
+
182
+        /**
183
+         * @return the pulse peak current
184
+         */
185
+        inline VectorXr GetPulseCurrent ( ) {
186
+            return PulseI;
187
+        }
188
+
189
+        /**
169 190
          * @param[in] value the 1D-EM model used for calculations
170 191
          */
171 192
         inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
@@ -300,10 +321,10 @@ namespace Lemma {
300 321
         Vector3r                                  Size;
301 322
         Vector3r                                  Origin;
302 323
 
303
-        VectorXr   PulseI;
304
-        VectorXr   Interfaces;
324
+        VectorXr                                  PulseI;
325
+        VectorXr                                  Interfaces;
305 326
 
306
-        MatrixXcr   Kern;
327
+        MatrixXcr                                 Kern;
307 328
 
308 329
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
309 330
         std::shared_ptr< FieldPoints >            cpoints = nullptr;

+ 49
- 14
src/KernelV0.cpp View File

@@ -47,6 +47,37 @@ namespace Lemma {
47 47
     // Description:  DeSerializing constructor (locked)
48 48
     //--------------------------------------------------------------------------------------
49 49
     KernelV0::KernelV0 (const YAML::Node& node, const ctor_key&) : LemmaObject(node) {
50
+        //node["PulseType"] = "FID";
51
+        Larmor = node["Larmor"].as<Real>();
52
+        Temperature = node["Temperature"].as<Real>();
53
+        tol = node["tol"].as<Real>();
54
+        minLevel = node["minLevel"].as<int>();
55
+        maxLevel = node["maxLevel"].as<int>();
56
+        Taup = node["Taup"].as<Real>();
57
+        PulseI = node["PulseI"].as<VectorXr>();
58
+        Interfaces = node["Interfaces"].as<VectorXr>();
59
+        Size = node["IntegrationSize"].as<Vector3r>();
60
+        Origin = node["IntegrationOrigin"].as<Vector3r>();
61
+
62
+        if (node["SigmaModel"]) {
63
+            if (node["SigmaModel"].Tag() == "LayeredEarthEM") {
64
+                SigmaModel = LayeredEarthEM::DeSerialize(node["SigmaModel"]);
65
+            } else {
66
+                SigmaModel = LayeredEarthEM::DeSerialize( YAML::LoadFile( node["SigmaModel"].as<std::string>() ));
67
+            }
68
+        }
69
+
70
+        if (node["Coils"]) {
71
+            for ( auto coil : node["Coils"] ) {
72
+                std::cout << "coil " << coil.first << coil.second << std::endl;
73
+                if ( coil.second.Tag() == "PolygonalWireAntenna" ) {
74
+                    TxRx[ coil.first.as<std::string>() ] = PolygonalWireAntenna::DeSerialize( coil.second );
75
+                } else {
76
+                    TxRx[ coil.first.as<std::string>() ] =
77
+                        PolygonalWireAntenna::DeSerialize( YAML::LoadFile(coil.second.as<std::string>()) );
78
+                }
79
+            }
80
+        }
50 81
 
51 82
     }  // -----  end of method KernelV0::KernelV0  (constructor)  -----
52 83
 
@@ -77,25 +108,33 @@ namespace Lemma {
77 108
         node.SetTag( GetName() );
78 109
 
79 110
         // Coils Transmitters & Receivers
80
-        for ( auto txm : TxRx) {
81
-            node[txm.first] = txm.second->Serialize();
111
+        if (!TxRx.empty()) {
112
+            for ( auto txm : TxRx) {
113
+                node["Coils"][txm.first] = txm.second->Serialize();
114
+            }
82 115
         }
83 116
 
84 117
         // LayeredEarthEM
85
-        node["SigmaModel"] = SigmaModel->Serialize();
118
+        if (SigmaModel != nullptr) {
119
+            node["SigmaModel"] = SigmaModel->Serialize();
120
+        }
86 121
 
122
+        node["PulseType"] = "FID";
87 123
         node["Larmor"] = Larmor;
88 124
         node["Temperature"] = Temperature;
89 125
         node["tol"] = tol;
90 126
         node["minLevel"] = minLevel;
91 127
         node["maxLevel"] = maxLevel;
92 128
         node["Taup"] = Taup;
93
-
94 129
         node["PulseI"] = PulseI;
95 130
         node["Interfaces"] = Interfaces;
131
+        node["IntegrationSize"] = Size;
132
+        node["IntegrationOrigin"] = Origin;
96 133
 
97
-        for ( int ilay=0; ilay<Interfaces.size()-1; ++ilay ) {
98
-            node["Kern-" + to_string(ilay) ] = static_cast<VectorXcr>(Kern.row(ilay));
134
+        if (Kern.array().abs().any() > 1e-16) {
135
+            for ( int ilay=0; ilay<Interfaces.size()-1; ++ilay ) {
136
+                node["K0"]["layer-" + to_string(ilay) ] = static_cast<VectorXcr>(Kern.row(ilay));
137
+            }
99 138
         }
100 139
         return node;
101 140
     }		// -----  end of method KernelV0::Serialize  -----
@@ -132,9 +171,8 @@ namespace Lemma {
132 171
     //       Class:  KernelV0
133 172
     //      Method:  DeSerialize
134 173
     //--------------------------------------------------------------------------------------
135
-    void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
136
-            bool vtkOutput ) {
137
-
174
+    void KernelV0::CalculateK0 (const std::vector< std::string>& Tx,
175
+                                const std::vector<std::string >& Rx, bool vtkOutput ) {
138 176
         // Set up
139 177
         Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad  2246.*2.*PI;
140 178
 
@@ -174,7 +212,8 @@ namespace Lemma {
174 212
         std::cout << "Calculating K0 kernel\n";
175 213
         Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
176 214
         for (ilay=0; ilay<Interfaces.size()-1; ++ilay) {
177
-            std::cout << "Layer " << ilay << "\tfrom " << Interfaces(ilay) <<" to "<< Interfaces(ilay+1) << std::endl;
215
+            std::cout << "Layer " << ilay << "\tfrom " << Interfaces(ilay) <<" to "
216
+                      << Interfaces(ilay+1) << std::endl;
178 217
             Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
179 218
             Origin(2) = Interfaces(ilay);
180 219
             IntegrateOnOctreeGrid( vtkOutput );
@@ -205,7 +244,6 @@ namespace Lemma {
205 244
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
206 245
 
207 246
             for (int iq=0; iq<PulseI.size(); ++iq) {
208
-
209 247
             // Fill in leaf data
210 248
             vtkDoubleArray* kr = vtkDoubleArray::New();
211 249
                 kr->SetNumberOfComponents(1);
@@ -245,7 +283,6 @@ namespace Lemma {
245 283
                 hri->SetNumberOfComponents(3);
246 284
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
247 285
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
248
-
249 286
             //Real LeafVol(0);
250 287
             for (auto leaf : LeafDict) {
251 288
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
@@ -309,7 +346,6 @@ namespace Lemma {
309 346
             hri->Delete();
310 347
 
311 348
             }
312
-
313 349
             curse->Delete();
314 350
             oct->Delete();
315 351
         #else
@@ -337,7 +373,6 @@ namespace Lemma {
337 373
 
338 374
         // Compute Mn0
339 375
         Vector3r Mn0 = ComputeMn0(1.0, B0);
340
-        //std::cout << "Mn0\t" << Mn0.transpose() << std::endl;
341 376
         Real Mn0Abs = Mn0.norm();
342 377
 
343 378
         // Compute phase delay

Loading…
Cancel
Save