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
 
24
 int main(int argc, char** argv) {
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
         return(EXIT_SUCCESS);
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
     auto Kern = KernelV0::NewSP();
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
         Kern->SetIntegrationSize( (Vector3r() << 200, 200., 100).finished() );
50
         Kern->SetIntegrationSize( (Vector3r() << 200, 200., 100).finished() );
45
         Kern->SetIntegrationOrigin( (Vector3r() << -100, -100, .5).finished() );
51
         Kern->SetIntegrationOrigin( (Vector3r() << -100, -100, .5).finished() );
64
 
70
 
65
         //VectorXr interfaces = VectorXr::LinSpaced( 41, .5, 45.5 ); // nlay, low, high
71
         //VectorXr interfaces = VectorXr::LinSpaced( 41, .5, 45.5 ); // nlay, low, high
66
         //VectorXr interfaces = VectorXr::LinSpaced( 61, .5, 45.5 ); // nlay, low, high
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
         Real thick = .1;
74
         Real thick = .1;
69
         for (int ilay=1; ilay<interfaces.size(); ++ilay) {
75
         for (int ilay=1; ilay<interfaces.size(); ++ilay) {
70
             interfaces(ilay) = interfaces(ilay-1) + thick;
76
             interfaces(ilay) = interfaces(ilay-1) + thick;
71
-            thick *= 1.075;
77
+            thick *= 1.085;
72
         }
78
         }
73
         Kern->SetDepthLayerInterfaces( interfaces ); // nlay, low, high
79
         Kern->SetDepthLayerInterfaces( interfaces ); // nlay, low, high
74
 
80
 
75
     // We could, I suppose, take the earth model in here? For non-linear that
81
     // We could, I suppose, take the earth model in here? For non-linear that
76
     // may be more natural to work with?
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
     Kern->CalculateK0( tx, rx, false ); // 3rd argument is vtk output
87
     Kern->CalculateK0( tx, rx, false ); // 3rd argument is vtk output
84
 
88
 
85
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
89
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
91
     for (auto lp : rx) {
95
     for (auto lp : rx) {
92
         dout << lp << "\t";
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
         dout << "#real\n";
101
         dout << "#real\n";
99
         dout << Kern->GetKernel().real() << std::endl;
102
         dout << Kern->GetKernel().real() << std::endl;
100
         dout << "#imag\n";
103
         dout << "#imag\n";
105
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
108
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
106
     out << *Kern;
109
     out << *Kern;
107
     out.close();
110
     out.close();
111
+
108
 }
112
 }
109
 
113
 
110
 
114
 

+ 24
- 3
include/KernelV0.h View File

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
          * @param[in] value the 1D-EM model used for calculations
190
          * @param[in] value the 1D-EM model used for calculations
170
          */
191
          */
171
         inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
192
         inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
300
         Vector3r                                  Size;
321
         Vector3r                                  Size;
301
         Vector3r                                  Origin;
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
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
329
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
309
         std::shared_ptr< FieldPoints >            cpoints = nullptr;
330
         std::shared_ptr< FieldPoints >            cpoints = nullptr;

+ 49
- 14
src/KernelV0.cpp View File

47
     // Description:  DeSerializing constructor (locked)
47
     // Description:  DeSerializing constructor (locked)
48
     //--------------------------------------------------------------------------------------
48
     //--------------------------------------------------------------------------------------
49
     KernelV0::KernelV0 (const YAML::Node& node, const ctor_key&) : LemmaObject(node) {
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
     }  // -----  end of method KernelV0::KernelV0  (constructor)  -----
82
     }  // -----  end of method KernelV0::KernelV0  (constructor)  -----
52
 
83
 
77
         node.SetTag( GetName() );
108
         node.SetTag( GetName() );
78
 
109
 
79
         // Coils Transmitters & Receivers
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
         // LayeredEarthEM
117
         // LayeredEarthEM
85
-        node["SigmaModel"] = SigmaModel->Serialize();
118
+        if (SigmaModel != nullptr) {
119
+            node["SigmaModel"] = SigmaModel->Serialize();
120
+        }
86
 
121
 
122
+        node["PulseType"] = "FID";
87
         node["Larmor"] = Larmor;
123
         node["Larmor"] = Larmor;
88
         node["Temperature"] = Temperature;
124
         node["Temperature"] = Temperature;
89
         node["tol"] = tol;
125
         node["tol"] = tol;
90
         node["minLevel"] = minLevel;
126
         node["minLevel"] = minLevel;
91
         node["maxLevel"] = maxLevel;
127
         node["maxLevel"] = maxLevel;
92
         node["Taup"] = Taup;
128
         node["Taup"] = Taup;
93
-
94
         node["PulseI"] = PulseI;
129
         node["PulseI"] = PulseI;
95
         node["Interfaces"] = Interfaces;
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
         return node;
139
         return node;
101
     }		// -----  end of method KernelV0::Serialize  -----
140
     }		// -----  end of method KernelV0::Serialize  -----
132
     //       Class:  KernelV0
171
     //       Class:  KernelV0
133
     //      Method:  DeSerialize
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
         // Set up
176
         // Set up
139
         Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad  2246.*2.*PI;
177
         Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad  2246.*2.*PI;
140
 
178
 
174
         std::cout << "Calculating K0 kernel\n";
212
         std::cout << "Calculating K0 kernel\n";
175
         Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
213
         Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
176
         for (ilay=0; ilay<Interfaces.size()-1; ++ilay) {
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
             Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
217
             Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
179
             Origin(2) = Interfaces(ilay);
218
             Origin(2) = Interfaces(ilay);
180
             IntegrateOnOctreeGrid( vtkOutput );
219
             IntegrateOnOctreeGrid( vtkOutput );
205
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
244
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
206
 
245
 
207
             for (int iq=0; iq<PulseI.size(); ++iq) {
246
             for (int iq=0; iq<PulseI.size(); ++iq) {
208
-
209
             // Fill in leaf data
247
             // Fill in leaf data
210
             vtkDoubleArray* kr = vtkDoubleArray::New();
248
             vtkDoubleArray* kr = vtkDoubleArray::New();
211
                 kr->SetNumberOfComponents(1);
249
                 kr->SetNumberOfComponents(1);
245
                 hri->SetNumberOfComponents(3);
283
                 hri->SetNumberOfComponents(3);
246
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
284
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
247
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
285
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
248
-
249
             //Real LeafVol(0);
286
             //Real LeafVol(0);
250
             for (auto leaf : LeafDict) {
287
             for (auto leaf : LeafDict) {
251
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
288
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
309
             hri->Delete();
346
             hri->Delete();
310
 
347
 
311
             }
348
             }
312
-
313
             curse->Delete();
349
             curse->Delete();
314
             oct->Delete();
350
             oct->Delete();
315
         #else
351
         #else
337
 
373
 
338
         // Compute Mn0
374
         // Compute Mn0
339
         Vector3r Mn0 = ComputeMn0(1.0, B0);
375
         Vector3r Mn0 = ComputeMn0(1.0, B0);
340
-        //std::cout << "Mn0\t" << Mn0.transpose() << std::endl;
341
         Real Mn0Abs = Mn0.norm();
376
         Real Mn0Abs = Mn0.norm();
342
 
377
 
343
         // Compute phase delay
378
         // Compute phase delay

Loading…
Cancel
Save