Browse Source

Working on kernel matrix calculation

master
Trevor Irons 8 years ago
parent
commit
68b1082cce
3 changed files with 64 additions and 15 deletions
  1. 17
    5
      examples/KernelV0.cpp
  2. 10
    1
      include/KernelV0.h
  3. 37
    9
      src/KernelV0.cpp

+ 17
- 5
examples/KernelV0.cpp View File

28
 		earth->SetNumberOfLayers(3);
28
 		earth->SetNumberOfLayers(3);
29
 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
29
 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
30
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
30
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
31
+        // Set mag field info
32
+        // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
33
+        earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
31
 
34
 
32
     // Transmitter loops
35
     // Transmitter loops
33
-    auto Tx1 = CircularLoop(60, 15, 100, 100);
34
-    auto Tx2 = CircularLoop(60, 15, 100, 120);
36
+    auto Tx1 = CircularLoop(65, 15, 100, 100);
37
+    auto Tx2 = CircularLoop(65, 15, 100, 120);
35
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
36
 
39
 
37
     auto Kern = KernelV0::NewSP();
40
     auto Kern = KernelV0::NewSP();
40
         Kern->SetLayeredEarthEM( earth );
43
         Kern->SetLayeredEarthEM( earth );
41
         // std::cout << *Kern << std::endl;
44
         // std::cout << *Kern << std::endl;
42
 
45
 
46
+        // Kern->SetPulseDuration();
47
+        // Kern->SetPulseCurrent();
48
+        // Kern->SetPulseMoments();
49
+        // Kern->SetDepthLayers();
50
+        // Kern->SetIntegrationOrigin();
51
+        // Kern->SetIntegrationSize();
52
+
53
+
43
     // 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
44
     // may be more natural to work with?
55
     // may be more natural to work with?
45
     std::vector<std::string> tx = {std::string("Coil 1")};
56
     std::vector<std::string> tx = {std::string("Coil 1")};
46
-    std::vector<std::string> rx = {std::string("Coil 2")};
57
+    std::vector<std::string> rx = {std::string("Coil 1")};
47
     Kern->CalculateK0( tx, rx , true ); //, false );
58
     Kern->CalculateK0( tx, rx , true ); //, false );
48
     //Kern->CalculateK0( "Coil 1", "Coil 1" );
59
     //Kern->CalculateK0( "Coil 1", "Coil 1" );
49
 
60
 
50
 }
61
 }
51
 
62
 
52
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
63
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
64
+
53
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
65
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
54
          Tx1->SetNumberOfPoints(nd);
66
          Tx1->SetNumberOfPoints(nd);
55
 
67
 
56
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
68
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
57
     int ii;
69
     int ii;
58
-    for (ii=0; ii<nd-1; ++ii) {
70
+    for (ii=0; ii<nd; ++ii) {
59
         Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
71
         Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
60
     }
72
     }
61
-    Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*1, Offsety,  -1e-3));
73
+    //Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*1, Offsety,  -1e-3));
62
 
74
 
63
     Tx1->SetCurrent(1.);
75
     Tx1->SetCurrent(1.);
64
     Tx1->SetNumberOfTurns(1);
76
     Tx1->SetNumberOfTurns(1);

+ 10
- 1
include/KernelV0.h View File

154
         void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
154
         void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
155
                 bool vtkOutput=false );
155
                 bool vtkOutput=false );
156
 
156
 
157
+        /**
158
+         *  Sets the temperature, which has implications in calculation of \f$ M_N^{(0)}\f$. Units in
159
+         *  Kelvin.
160
+         */
161
+        void SetTemperature(const Real& tempK) {
162
+            Temperature = tempK;
163
+        }
164
+
157
         // ====================  INQUIRY       =======================
165
         // ====================  INQUIRY       =======================
158
         /**
166
         /**
159
          *  Returns the name of the underlying class, similiar to Python's type
167
          *  Returns the name of the underlying class, similiar to Python's type
220
 
228
 
221
         Real                                      VOLSUM;
229
         Real                                      VOLSUM;
222
         Real                                      tol=1e-3;
230
         Real                                      tol=1e-3;
223
-        //Real                                        Temperature;
231
+        Real                                      Temperature=283.;
224
 
232
 
225
         Complex                                   SUM;
233
         Complex                                   SUM;
226
 
234
 
237
 
245
 
238
         #ifdef LEMMAUSEVTK
246
         #ifdef LEMMAUSEVTK
239
         std::map< int, Complex  >                 LeafDict;
247
         std::map< int, Complex  >                 LeafDict;
248
+        std::map< int, Real     >                 LeafDictErr;
240
         #endif
249
         #endif
241
 
250
 
242
         // Physical constants and conversion factors
251
         // Physical constants and conversion factors

+ 37
- 9
src/KernelV0.cpp View File

133
                     EMEarths[rx]->SetTxRxMode(RX);
133
                     EMEarths[rx]->SetTxRxMode(RX);
134
             }
134
             }
135
         }
135
         }
136
-        IntegrateOnOctreeGrid( 1e-7, vtkOutput );
137
-
136
+        IntegrateOnOctreeGrid( 1e-13, vtkOutput );
138
     }
137
     }
139
 
138
 
140
     //--------------------------------------------------------------------------------------
139
     //--------------------------------------------------------------------------------------
145
 
144
 
146
         this->tol = tolerance;
145
         this->tol = tolerance;
147
         //Vector3r                Size;
146
         //Vector3r                Size;
148
-            Size << 200,200,20;
147
+            Size << 200,200,2;
149
         //Vector3r                Origin;
148
         //Vector3r                Origin;
150
             Origin << 0,0,5.0;
149
             Origin << 0,0,5.0;
151
         Vector3r                cpos;  // centre position
150
         Vector3r                cpos;  // centre position
177
                 ki->SetNumberOfComponents(1);
176
                 ki->SetNumberOfComponents(1);
178
                 ki->SetName("Im($K_0$)");
177
                 ki->SetName("Im($K_0$)");
179
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
178
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
179
+            vtkDoubleArray* km = vtkDoubleArray::New();
180
+                km->SetNumberOfComponents(1);
181
+                km->SetName("mod($K_0$)");
182
+                km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
183
+            vtkIntArray* kid = vtkIntArray::New();
184
+                kid->SetNumberOfComponents(1);
185
+                kid->SetName("ID");
186
+                kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
187
+            //vtkDoubleArray* kerr = vtkDoubleArray::New();
188
+            //    kerr->SetNumberOfComponents(1);
189
+            //    kerr->SetName("Error");
190
+
180
             for (auto leaf : LeafDict) {
191
             for (auto leaf : LeafDict) {
181
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
192
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
182
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
193
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
194
+                kid->InsertTuple1( leaf.first, leaf.first );
183
             }
195
             }
196
+
197
+            //for (auto leaf : LeafDictErr) {
198
+            //    kerr->InsertTuple1( leaf.first, std::imag(leaf.second) );
199
+            //}
200
+
184
             oct->GetLeafData()->AddArray(kr);
201
             oct->GetLeafData()->AddArray(kr);
185
             oct->GetLeafData()->AddArray(ki);
202
             oct->GetLeafData()->AddArray(ki);
203
+            oct->GetLeafData()->AddArray(km);
204
+            oct->GetLeafData()->AddArray(kid);
205
+            //oct->GetLeafData()->AddArray(kerr);
186
 
206
 
187
             auto write = vtkXMLHyperOctreeWriter::New();
207
             auto write = vtkXMLHyperOctreeWriter::New();
188
                 //write.SetDataModeToAscii()
208
                 //write.SetDataModeToAscii()
191
                 write->Write();
211
                 write->Write();
192
                 write->Delete();
212
                 write->Delete();
193
 
213
 
214
+            //kerr->Delete();
215
+            kid->Delete();
194
             kr->Delete();
216
             kr->Delete();
195
             ki->Delete();
217
             ki->Delete();
218
+            km->Delete();
196
             curse->Delete();
219
             curse->Delete();
197
             oct->Delete();
220
             oct->Delete();
198
         #else
221
         #else
212
     //      Method:  f
235
     //      Method:  f
213
     //--------------------------------------------------------------------------------------
236
     //--------------------------------------------------------------------------------------
214
     Complex KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
237
     Complex KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
215
-        return Complex(volume*Ht.dot(Hr));
216
-        //return ComputeV0Cell(MU0*Ht, MU0*Hr, volume, 1.0);
238
+        //return Complex(volume*Ht.dot(Hr));
239
+        return ComputeV0Cell(MU0*Ht, MU0*Hr, volume, 1.0);
217
     }
240
     }
218
 
241
 
219
     //--------------------------------------------------------------------------------------
242
     //--------------------------------------------------------------------------------------
224
                 const Vector3cr& Br, const Real& vol, const Real& phi) {
247
                 const Vector3cr& Br, const Real& vol, const Real& phi) {
225
 
248
 
226
         // Compute the elliptic fields
249
         // Compute the elliptic fields
227
-        Vector3r B0hat = {1,0,0};
228
-        Vector3r B0 = 53000 * B0hat; // nT
250
+        Vector3r B0hat = SigmaModel->GetMagneticFieldUnitVector();
251
+        Vector3r B0 = SigmaModel->GetMagneticField();
252
+
253
+        // Elliptic representation
229
         EllipticB EBT = EllipticFieldRep(Bt, B0hat);
254
         EllipticB EBT = EllipticFieldRep(Bt, B0hat);
230
         EllipticB EBR = EllipticFieldRep(Br, B0hat);
255
         EllipticB EBR = EllipticFieldRep(Br, B0hat);
231
 
256
 
234
         Real Mn0Abs = Mn0.norm();
259
         Real Mn0Abs = Mn0.norm();
235
 
260
 
236
         Real Taup = 0.020; // s
261
         Real Taup = 0.020; // s
237
-        Real Ip = 10;      // A
262
+        Real Ip   = 10;      // A
238
 
263
 
239
         // Compute the tipping angle
264
         // Compute the tipping angle
240
         Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
265
         Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
264
         return -vol*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
289
         return -vol*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
265
     }
290
     }
266
 
291
 
292
+    //--------------------------------------------------------------------------------------
293
+    //       Class:  KernelV0
294
+    //      Method:  ComputeV0Cell
295
+    //--------------------------------------------------------------------------------------
267
     Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
296
     Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
268
-        Real Temperature = 283; // in K
269
         Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
297
         Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
270
         return chi_n*Porosity*B0;
298
         return chi_n*Porosity*B0;
271
     }
299
     }

Loading…
Cancel
Save