소스 검색

Kernel calculation seems to be working.

master
Trevor Irons 7 년 전
부모
커밋
79e743c9c6
3개의 변경된 파일100개의 추가작업 그리고 41개의 파일을 삭제
  1. 10
    11
      examples/KernelV0.cpp
  2. 54
    5
      include/KernelV0.h
  3. 36
    25
      src/KernelV0.cpp

+ 10
- 11
examples/KernelV0.cpp 파일 보기

33
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
33
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
34
 
34
 
35
     // Transmitter loops
35
     // Transmitter loops
36
-    auto Tx1 = CircularLoop(65, 15, 100, 100);
37
-    auto Tx2 = CircularLoop(65, 15, 100, 120);
36
+    auto Tx1 = CircularLoop(31, 15, 100, 100);
37
+    auto Tx2 = CircularLoop(31, 15, 100, 120);
38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
39
 
39
 
40
     auto Kern = KernelV0::NewSP();
40
     auto Kern = KernelV0::NewSP();
43
         Kern->SetLayeredEarthEM( earth );
43
         Kern->SetLayeredEarthEM( earth );
44
         // std::cout << *Kern << std::endl;
44
         // std::cout << *Kern << std::endl;
45
 
45
 
46
-        // Kern->SetPulseDuration();
47
-        // Kern->SetPulseCurrent();
48
-        // Kern->SetPulseMoments();
49
-        // Kern->SetDepthLayers();
50
-        // Kern->SetIntegrationOrigin();
51
-        // Kern->SetIntegrationSize();
46
+        Kern->SetIntegrationSize( (Vector3r() << 200,200,2).finished() );
47
+        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,15).finished() );
48
+        Kern->SetTolerance( 1e-11 );
52
 
49
 
50
+        Kern->SetPulseDuration(0.020);
51
+        Kern->SetPulseCurrent( VectorXr::LinSpaced( 20, .01, 200 )  ); // nbins, low, high
52
+        Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 20, .5, 50 ) );
53
 
53
 
54
     // We could, I suppose, take the earth model in here? For non-linear that
54
     // We could, I suppose, take the earth model in here? For non-linear that
55
     // may be more natural to work with?
55
     // may be more natural to work with?
56
     std::vector<std::string> tx = {std::string("Coil 1")};
56
     std::vector<std::string> tx = {std::string("Coil 1")};
57
     std::vector<std::string> rx = {std::string("Coil 1")};
57
     std::vector<std::string> rx = {std::string("Coil 1")};
58
-    Kern->CalculateK0( tx, rx , true ); //, false );
59
-    //Kern->CalculateK0( "Coil 1", "Coil 1" );
58
+    Kern->CalculateK0( tx, rx, true );
60
 
59
 
61
 }
60
 }
62
 
61
 
75
     Tx1->SetCurrent(1.);
74
     Tx1->SetCurrent(1.);
76
     Tx1->SetNumberOfTurns(1);
75
     Tx1->SetNumberOfTurns(1);
77
     Tx1->SetNumberOfFrequencies(1);
76
     Tx1->SetNumberOfFrequencies(1);
78
-    Tx1->SetFrequency(0,2500);
77
+    Tx1->SetFrequency(0,2246);
79
 
78
 
80
     return Tx1;
79
     return Tx1;
81
 }
80
 }

+ 54
- 5
include/KernelV0.h 파일 보기

135
         }		// -----  end of method KernelV0::set_SigmaModel  -----
135
         }		// -----  end of method KernelV0::set_SigmaModel  -----
136
 
136
 
137
         /**
137
         /**
138
+         *
139
+         */
140
+        inline void SetIntegrationSize ( const Vector3r& size ) {
141
+            Size = size;
142
+            return ;
143
+        }		// -----  end of method KernelV0::SetIntegrationSize  -----
144
+
145
+        /**
146
+         *
147
+         */
148
+        inline void SetIntegrationOrigin ( const Vector3r& origin ) {
149
+            Origin = origin;
150
+            return ;
151
+        }		// -----  end of method KernelV0::SetIntegrationOrigin  -----
152
+
153
+        /**
154
+         *
155
+         */
156
+        inline void SetPulseCurrent ( const VectorXr& Amps ) {
157
+            PulseI = Amps;
158
+            return ;
159
+        }		// -----  end of method KernelV0::SetIntegrationOrigin  -----
160
+
161
+        /**
138
          *   Assign transmiter coils
162
          *   Assign transmiter coils
139
          */
163
          */
140
         inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
164
         inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
158
          *  Sets the temperature, which has implications in calculation of \f$ M_N^{(0)}\f$. Units in
182
          *  Sets the temperature, which has implications in calculation of \f$ M_N^{(0)}\f$. Units in
159
          *  Kelvin.
183
          *  Kelvin.
160
          */
184
          */
161
-        void SetTemperature(const Real& tempK) {
185
+        inline void SetTemperature(const Real& tempK) {
162
             Temperature = tempK;
186
             Temperature = tempK;
163
         }
187
         }
164
 
188
 
189
+        /**
190
+         *  Sets the tolerance to use for making the adaptive mesh
191
+         *
192
+         */
193
+        inline void SetTolerance(const Real& ttol) {
194
+            tol = ttol;
195
+        }
196
+
197
+        inline void SetPulseDuration(const Real& taup) {
198
+            Taup = taup;
199
+        }
200
+
201
+        inline void SetDepthLayerInterfaces( const VectorXr& iface ){
202
+            Interfaces = iface;
203
+        }
204
+
165
         // ====================  INQUIRY       =======================
205
         // ====================  INQUIRY       =======================
166
         /**
206
         /**
167
          *  Returns the name of the underlying class, similiar to Python's type
207
          *  Returns the name of the underlying class, similiar to Python's type
196
 
236
 
197
         Vector3r ComputeMn0(const Real& Porosity, const Vector3r& B0);
237
         Vector3r ComputeMn0(const Real& Porosity, const Vector3r& B0);
198
 
238
 
199
-        void IntegrateOnOctreeGrid( const Real& tolerance , bool vtkOutput=false );
239
+        Complex IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput=false );
200
 
240
 
201
         /**
241
         /**
202
          *  Recursive call to integrate a function on an adaptive Octree Grid.
242
          *  Recursive call to integrate a function on an adaptive Octree Grid.
225
         // ====================  DATA MEMBERS  =========================
265
         // ====================  DATA MEMBERS  =========================
226
 
266
 
227
         int                                       nleaves;
267
         int                                       nleaves;
268
+        int                                       minLevel=3;
269
+        int                                       maxLevel=10;
228
 
270
 
229
         Real                                      VOLSUM;
271
         Real                                      VOLSUM;
230
-        Real                                      tol=1e-3;
272
+        Real                                      tol=1e-11;
231
         Real                                      Temperature=283.;
273
         Real                                      Temperature=283.;
274
+        Real                                      Taup = .020;  // Sec
275
+        Real                                      Ip = 10;      // Amps
276
+        Real                                      Larmor;
232
 
277
 
233
         Complex                                   SUM;
278
         Complex                                   SUM;
234
 
279
 
235
-        Vector3r   Size;
236
-        Vector3r   Origin;
280
+        Vector3r                                  Size;
281
+        Vector3r                                  Origin;
282
+
283
+        VectorXr   PulseI;
284
+        VectorXr   Interfaces;
237
 
285
 
238
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
286
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
239
 
287
 
245
 
293
 
246
         #ifdef LEMMAUSEVTK
294
         #ifdef LEMMAUSEVTK
247
         std::map< int, Complex  >                 LeafDict;
295
         std::map< int, Complex  >                 LeafDict;
296
+        std::map< int, int     >                  LeafDictIdx;
248
         std::map< int, Real     >                 LeafDictErr;
297
         std::map< int, Real     >                 LeafDictErr;
249
         #endif
298
         #endif
250
 
299
 

+ 36
- 25
src/KernelV0.cpp 파일 보기

105
     void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
105
     void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
106
             bool vtkOutput ) {
106
             bool vtkOutput ) {
107
 
107
 
108
+        // Set up
109
+        Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad  2246.*2.*PI;
110
+
108
         // All EM calculations will share same field points
111
         // All EM calculations will share same field points
109
         cpoints = FieldPoints::NewSP();
112
         cpoints = FieldPoints::NewSP();
110
             cpoints->SetNumberOfPoints(8);
113
             cpoints->SetNumberOfPoints(8);
133
                     EMEarths[rx]->SetTxRxMode(RX);
136
                     EMEarths[rx]->SetTxRxMode(RX);
134
             }
137
             }
135
         }
138
         }
136
-        IntegrateOnOctreeGrid( 1e-13, vtkOutput );
139
+
140
+        std::cout << "Calculating K0 kernel\n";
141
+        MatrixXcr Kern = MatrixXcr::Zero( Interfaces.size() - 1, PulseI.size() );
142
+        for (int ilay=0; ilay< Interfaces.size()-1; ++ilay) {
143
+            for (int iq=0; iq< PulseI.size()-1; ++iq) {
144
+                std::cout << "Layer " << ilay << " q " << iq << std::endl;
145
+                Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
146
+                Origin(2) = Interfaces(ilay);
147
+                Ip = PulseI(iq);
148
+                Kern(ilay, iq) = IntegrateOnOctreeGrid( ilay, iq, vtkOutput );
149
+            }
150
+        }
151
+        std::cout << "\rFinished KERNEL\n";
152
+        std::cout << Kern << std::endl;
153
+        //IntegrateOnOctreeGrid( vtkOutput );
137
     }
154
     }
138
 
155
 
139
     //--------------------------------------------------------------------------------------
156
     //--------------------------------------------------------------------------------------
140
     //       Class:  KernelV0
157
     //       Class:  KernelV0
141
     //      Method:  IntegrateOnOctreeGrid
158
     //      Method:  IntegrateOnOctreeGrid
142
     //--------------------------------------------------------------------------------------
159
     //--------------------------------------------------------------------------------------
143
-    void KernelV0::IntegrateOnOctreeGrid( const Real& tolerance, bool vtkOutput) {
160
+    Complex KernelV0::IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput) {
144
 
161
 
145
-        this->tol = tolerance;
146
-        //Vector3r                Size;
147
-            Size << 200,200,2;
148
-        //Vector3r                Origin;
149
-            Origin << 0,0,5.0;
150
-        Vector3r                cpos;  // centre position
151
-            //cpos << 100,100,50;
152
-            cpos = (Size-Origin).array() / 2.;
153
-        int                     maxlevel;
162
+        Vector3r cpos = (Size-Origin).array() / 2.;
154
 
163
 
155
         SUM = 0;
164
         SUM = 0;
156
         VOLSUM = 0;
165
         VOLSUM = 0;
184
                 kid->SetNumberOfComponents(1);
193
                 kid->SetNumberOfComponents(1);
185
                 kid->SetName("ID");
194
                 kid->SetName("ID");
186
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
195
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
187
-            //vtkDoubleArray* kerr = vtkDoubleArray::New();
188
-            //    kerr->SetNumberOfComponents(1);
189
-            //    kerr->SetName("Error");
196
+            vtkIntArray* kerr = vtkIntArray::New();
197
+                kerr->SetNumberOfComponents(1);
198
+                kerr->SetName("nleaf");
190
 
199
 
191
             for (auto leaf : LeafDict) {
200
             for (auto leaf : LeafDict) {
192
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
201
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
193
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
202
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
203
+                km->InsertTuple1( leaf.first, std::abs(leaf.second) );
194
                 kid->InsertTuple1( leaf.first, leaf.first );
204
                 kid->InsertTuple1( leaf.first, leaf.first );
195
             }
205
             }
196
 
206
 
197
-            //for (auto leaf : LeafDictErr) {
198
-            //    kerr->InsertTuple1( leaf.first, std::imag(leaf.second) );
199
-            //}
207
+            for (auto leaf : LeafDictIdx) {
208
+                kerr->InsertTuple1( leaf.first, leaf.second );
209
+            }
200
 
210
 
201
             oct->GetLeafData()->AddArray(kr);
211
             oct->GetLeafData()->AddArray(kr);
202
             oct->GetLeafData()->AddArray(ki);
212
             oct->GetLeafData()->AddArray(ki);
203
             oct->GetLeafData()->AddArray(km);
213
             oct->GetLeafData()->AddArray(km);
204
             oct->GetLeafData()->AddArray(kid);
214
             oct->GetLeafData()->AddArray(kid);
205
-            //oct->GetLeafData()->AddArray(kerr);
215
+            oct->GetLeafData()->AddArray(kerr);
206
 
216
 
207
             auto write = vtkXMLHyperOctreeWriter::New();
217
             auto write = vtkXMLHyperOctreeWriter::New();
208
                 //write.SetDataModeToAscii()
218
                 //write.SetDataModeToAscii()
209
                 write->SetInputData(oct);
219
                 write->SetInputData(oct);
210
-                write->SetFileName("octree.vto");
220
+                std::string fname = std::string("octree-") + to_string(ilay)
221
+                                  + std::string("-") + to_string(iq) + std::string(".vto");
222
+                write->SetFileName(fname.c_str());
211
                 write->Write();
223
                 write->Write();
212
                 write->Delete();
224
                 write->Delete();
213
 
225
 
228
         std::cout << "nleaves\t" << nleaves << std::endl;
240
         std::cout << "nleaves\t" << nleaves << std::endl;
229
         std::cout << "KSUM\t" << SUM << std::endl;
241
         std::cout << "KSUM\t" << SUM << std::endl;
230
 
242
 
243
+        return SUM;
231
     }
244
     }
232
 
245
 
233
     //--------------------------------------------------------------------------------------
246
     //--------------------------------------------------------------------------------------
258
         Vector3r Mn0 = ComputeMn0(phi, B0);
271
         Vector3r Mn0 = ComputeMn0(phi, B0);
259
         Real Mn0Abs = Mn0.norm();
272
         Real Mn0Abs = Mn0.norm();
260
 
273
 
261
-        Real Taup = 0.020; // s
262
-        Real Ip   = 10;      // A
263
-
264
         // Compute the tipping angle
274
         // Compute the tipping angle
265
         Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
275
         Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
266
 
276
 
279
                 const Real& vol) {
289
                 const Real& vol) {
280
 
290
 
281
         Vector3r B0hat = {1,0,0};
291
         Vector3r B0hat = {1,0,0};
282
-        Real Larmor = 2500.*2.*PI;
283
 
292
 
284
         // earth response of receiver adjoint field
293
         // earth response of receiver adjoint field
285
         Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
294
         Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
384
 
393
 
385
         Complex ksum = kvals.sum();     // Kernel sum
394
         Complex ksum = kvals.sum();     // Kernel sum
386
         // Evaluate whether or not furthur splitting is needed
395
         // Evaluate whether or not furthur splitting is needed
387
-        if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
396
+        if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
388
             for (int ichild=0; ichild<8; ++ichild) {
397
             for (int ichild=0; ichild<8; ++ichild) {
389
                 Vector3r cp = pos; // Eigen complains about combining these
398
                 Vector3r cp = pos; // Eigen complains about combining these
390
                 cp += posadd.row(ichild);
399
                 cp += posadd.row(ichild);
467
 
476
 
468
         Complex ksum = kvals.sum();     // Kernel sum
477
         Complex ksum = kvals.sum();     // Kernel sum
469
         // Evaluate whether or not furthur splitting is needed
478
         // Evaluate whether or not furthur splitting is needed
470
-        if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
479
+        Real err = std::abs(ksum - parentVal);
480
+        if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
471
             oct->SubdivideLeaf(curse);
481
             oct->SubdivideLeaf(curse);
472
             for (int ichild=0; ichild<8; ++ichild) {
482
             for (int ichild=0; ichild<8; ++ichild) {
473
                 curse->ToChild(ichild);
483
                 curse->ToChild(ichild);
482
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
492
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
483
                 if (isleaf) {  // Include result in final integral
493
                 if (isleaf) {  // Include result in final integral
484
                     LeafDict[curse->GetLeafId()] = kvals(ichild);       // VTK
494
                     LeafDict[curse->GetLeafId()] = kvals(ichild);       // VTK
495
+                    LeafDictIdx[curse->GetLeafId()] = nleaves;          // VTK
485
                     SUM += ksum;
496
                     SUM += ksum;
486
                     VOLSUM += 8*vol;
497
                     VOLSUM += 8*vol;
487
                     nleaves += 1;
498
                     nleaves += 1;

Loading…
취소
저장