Browse Source

Working on kernel matrix calculation

master
Trevor Irons 7 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,10 +28,13 @@ int main() {
28 28
 		earth->SetNumberOfLayers(3);
29 29
 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
30 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 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 38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
36 39
 
37 40
     auto Kern = KernelV0::NewSP();
@@ -40,25 +43,34 @@ int main() {
40 43
         Kern->SetLayeredEarthEM( earth );
41 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 54
     // We could, I suppose, take the earth model in here? For non-linear that
44 55
     // may be more natural to work with?
45 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 58
     Kern->CalculateK0( tx, rx , true ); //, false );
48 59
     //Kern->CalculateK0( "Coil 1", "Coil 1" );
49 60
 
50 61
 }
51 62
 
52 63
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
64
+
53 65
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
54 66
          Tx1->SetNumberOfPoints(nd);
55 67
 
56 68
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
57 69
     int ii;
58
-    for (ii=0; ii<nd-1; ++ii) {
70
+    for (ii=0; ii<nd; ++ii) {
59 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 75
     Tx1->SetCurrent(1.);
64 76
     Tx1->SetNumberOfTurns(1);

+ 10
- 1
include/KernelV0.h View File

@@ -154,6 +154,14 @@ namespace Lemma {
154 154
         void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
155 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 165
         // ====================  INQUIRY       =======================
158 166
         /**
159 167
          *  Returns the name of the underlying class, similiar to Python's type
@@ -220,7 +228,7 @@ namespace Lemma {
220 228
 
221 229
         Real                                      VOLSUM;
222 230
         Real                                      tol=1e-3;
223
-        //Real                                        Temperature;
231
+        Real                                      Temperature=283.;
224 232
 
225 233
         Complex                                   SUM;
226 234
 
@@ -237,6 +245,7 @@ namespace Lemma {
237 245
 
238 246
         #ifdef LEMMAUSEVTK
239 247
         std::map< int, Complex  >                 LeafDict;
248
+        std::map< int, Real     >                 LeafDictErr;
240 249
         #endif
241 250
 
242 251
         // Physical constants and conversion factors

+ 37
- 9
src/KernelV0.cpp View File

@@ -133,8 +133,7 @@ namespace Lemma {
133 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,7 +144,7 @@ namespace Lemma {
145 144
 
146 145
         this->tol = tolerance;
147 146
         //Vector3r                Size;
148
-            Size << 200,200,20;
147
+            Size << 200,200,2;
149 148
         //Vector3r                Origin;
150 149
             Origin << 0,0,5.0;
151 150
         Vector3r                cpos;  // centre position
@@ -177,12 +176,33 @@ namespace Lemma {
177 176
                 ki->SetNumberOfComponents(1);
178 177
                 ki->SetName("Im($K_0$)");
179 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 191
             for (auto leaf : LeafDict) {
181 192
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
182 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 201
             oct->GetLeafData()->AddArray(kr);
185 202
             oct->GetLeafData()->AddArray(ki);
203
+            oct->GetLeafData()->AddArray(km);
204
+            oct->GetLeafData()->AddArray(kid);
205
+            //oct->GetLeafData()->AddArray(kerr);
186 206
 
187 207
             auto write = vtkXMLHyperOctreeWriter::New();
188 208
                 //write.SetDataModeToAscii()
@@ -191,8 +211,11 @@ namespace Lemma {
191 211
                 write->Write();
192 212
                 write->Delete();
193 213
 
214
+            //kerr->Delete();
215
+            kid->Delete();
194 216
             kr->Delete();
195 217
             ki->Delete();
218
+            km->Delete();
196 219
             curse->Delete();
197 220
             oct->Delete();
198 221
         #else
@@ -212,8 +235,8 @@ namespace Lemma {
212 235
     //      Method:  f
213 236
     //--------------------------------------------------------------------------------------
214 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,8 +247,10 @@ namespace Lemma {
224 247
                 const Vector3cr& Br, const Real& vol, const Real& phi) {
225 248
 
226 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 254
         EllipticB EBT = EllipticFieldRep(Bt, B0hat);
230 255
         EllipticB EBR = EllipticFieldRep(Br, B0hat);
231 256
 
@@ -234,7 +259,7 @@ namespace Lemma {
234 259
         Real Mn0Abs = Mn0.norm();
235 260
 
236 261
         Real Taup = 0.020; // s
237
-        Real Ip = 10;      // A
262
+        Real Ip   = 10;      // A
238 263
 
239 264
         // Compute the tipping angle
240 265
         Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
@@ -264,8 +289,11 @@ namespace Lemma {
264 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 296
     Vector3r KernelV0::ComputeMn0(const Real& Porosity, const Vector3r& B0) {
268
-        Real Temperature = 283; // in K
269 297
         Real chi_n = NH2O*((GAMMA*GAMMA*HBAR*HBAR)/(4.*KB*Temperature));
270 298
         return chi_n*Porosity*B0;
271 299
     }

Loading…
Cancel
Save