Browse Source

More work on kernel calculation checking. Improved VTK file output

master
Trevor Irons 7 years ago
parent
commit
3f023f568b
2 changed files with 60 additions and 17 deletions
  1. 6
    2
      examples/KernelV0-2.cpp
  2. 54
    15
      src/KernelV0.cpp

+ 6
- 2
examples/KernelV0-2.cpp View File

41
         Kern->PushCoil( "Coil 2", Rx1 );
41
         Kern->PushCoil( "Coil 2", Rx1 );
42
         Kern->SetLayeredEarthEM( earth );
42
         Kern->SetLayeredEarthEM( earth );
43
 
43
 
44
-        Kern->SetIntegrationSize( (Vector3r() << 20.2151538,20.438572,100).finished() );
45
-        Kern->SetIntegrationOrigin( (Vector3r() << -10, -10, .5).finished() );
44
+        Kern->SetIntegrationSize( (Vector3r() << 200, 200., 100).finished() );
45
+        Kern->SetIntegrationOrigin( (Vector3r() << -100, -100, .5).finished() );
46
         Real tol(1e-13); // 13
46
         Real tol(1e-13); // 13
47
         Kern->SetTolerance( tol ); // 1e-12
47
         Kern->SetTolerance( tol ); // 1e-12
48
 
48
 
76
     // may be more natural to work with?
76
     // may be more natural to work with?
77
     std::vector<std::string> tx = {std::string("Coil 1")};
77
     std::vector<std::string> tx = {std::string("Coil 1")};
78
     std::vector<std::string> rx = {std::string("Coil 2")};
78
     std::vector<std::string> rx = {std::string("Coil 2")};
79
+
80
+    //std::cout << "KERNEL.yaml" << std::endl;
81
+    //std::cout << *Kern << std::endl;
82
+
79
     Kern->CalculateK0( tx, rx, true ); // 3rd argument is vtk output
83
     Kern->CalculateK0( tx, rx, true ); // 3rd argument is vtk output
80
 
84
 
81
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
85
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));

+ 54
- 15
src/KernelV0.cpp View File

80
         for ( auto txm : TxRx) {
80
         for ( auto txm : TxRx) {
81
             node[txm.first] = txm.second->Serialize();
81
             node[txm.first] = txm.second->Serialize();
82
         }
82
         }
83
+
83
         // LayeredEarthEM
84
         // LayeredEarthEM
84
         node["SigmaModel"] = SigmaModel->Serialize();
85
         node["SigmaModel"] = SigmaModel->Serialize();
85
 
86
 
208
             // Fill in leaf data
209
             // Fill in leaf data
209
             vtkDoubleArray* kr = vtkDoubleArray::New();
210
             vtkDoubleArray* kr = vtkDoubleArray::New();
210
                 kr->SetNumberOfComponents(1);
211
                 kr->SetNumberOfComponents(1);
211
-                kr->SetName("Re($K_0$)");
212
+                kr->SetName("Re($\\mathcal{K}_0$)");
212
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
213
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
213
             vtkDoubleArray* ki = vtkDoubleArray::New();
214
             vtkDoubleArray* ki = vtkDoubleArray::New();
214
                 ki->SetNumberOfComponents(1);
215
                 ki->SetNumberOfComponents(1);
215
-                ki->SetName("Im($K_0$)");
216
+                ki->SetName("Im($\\mathcal{K}_0$)");
216
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
217
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
217
             vtkDoubleArray* km = vtkDoubleArray::New();
218
             vtkDoubleArray* km = vtkDoubleArray::New();
218
                 km->SetNumberOfComponents(1);
219
                 km->SetNumberOfComponents(1);
219
-                km->SetName("mod($K_0$)");
220
+                km->SetName("mod($\\mathcal{K}_0$)");
220
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
221
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
221
             vtkIntArray* kid = vtkIntArray::New();
222
             vtkIntArray* kid = vtkIntArray::New();
222
                 kid->SetNumberOfComponents(1);
223
                 kid->SetNumberOfComponents(1);
224
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
225
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
225
             vtkIntArray* kerr = vtkIntArray::New();
226
             vtkIntArray* kerr = vtkIntArray::New();
226
                 kerr->SetNumberOfComponents(1);
227
                 kerr->SetNumberOfComponents(1);
227
-                kerr->SetName("nleaf");
228
+                kerr->SetName("err");
229
+                kerr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
230
+            // Ht field
231
+            vtkDoubleArray* htr = vtkDoubleArray::New();
232
+                htr->SetNumberOfComponents(3);
233
+                htr->SetName("Re($\\mathbf{\\mathcal{H}}_T$)");
234
+                htr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
235
+            vtkDoubleArray* hti = vtkDoubleArray::New();
236
+                hti->SetNumberOfComponents(3);
237
+                hti->SetName("Im($\\mathbf{\\mathcal{H}}_T$)");
238
+                hti->SetNumberOfTuples( oct->GetNumberOfLeaves() );
239
+            // Hr field
240
+            vtkDoubleArray* hrr = vtkDoubleArray::New();
241
+                hrr->SetNumberOfComponents(3);
242
+                hrr->SetName("Re($\\mathbf{\\mathcal{H}}_R$)");
243
+                hrr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
244
+            vtkDoubleArray* hri = vtkDoubleArray::New();
245
+                hri->SetNumberOfComponents(3);
246
+                hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
247
+                hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
228
 
248
 
229
             //Real LeafVol(0);
249
             //Real LeafVol(0);
230
             for (auto leaf : LeafDict) {
250
             for (auto leaf : LeafDict) {
234
                 kid->InsertTuple1( leaf.first, leaf.first );
254
                 kid->InsertTuple1( leaf.first, leaf.first );
235
                 //LeafVol += std::real(leaf.second);
255
                 //LeafVol += std::real(leaf.second);
236
             }
256
             }
237
-            //std::cout << "\n\nLeafVol=" << LeafVol << std::endl;
257
+
258
+            for (auto leaf : LeafHt ) {
259
+                htr->InsertTuple( leaf.first, leaf.second.real().data() );
260
+                hti->InsertTuple( leaf.first, leaf.second.imag().data() );
261
+            }
262
+
263
+            for (auto leaf : LeafHr ) {
264
+                hrr->InsertTuple( leaf.first, leaf.second.real().data() );
265
+                hri->InsertTuple( leaf.first, leaf.second.imag().data() );
266
+            }
238
 
267
 
239
             for (auto leaf : LeafDictIdx) {
268
             for (auto leaf : LeafDictIdx) {
240
                 kerr->InsertTuple1( leaf.first, leaf.second );
269
                 kerr->InsertTuple1( leaf.first, leaf.second );
245
             auto kmi = oct->GetLeafData()->AddArray(km);
274
             auto kmi = oct->GetLeafData()->AddArray(km);
246
             auto kidi = oct->GetLeafData()->AddArray(kid);
275
             auto kidi = oct->GetLeafData()->AddArray(kid);
247
             auto keri = oct->GetLeafData()->AddArray(kerr);
276
             auto keri = oct->GetLeafData()->AddArray(kerr);
277
+            auto khtr = oct->GetLeafData()->AddArray(htr);
278
+            auto khti = oct->GetLeafData()->AddArray(hti);
279
+            auto khrr = oct->GetLeafData()->AddArray(hrr);
280
+            auto khri = oct->GetLeafData()->AddArray(hri);
248
 
281
 
249
             auto write = vtkXMLHyperOctreeWriter::New();
282
             auto write = vtkXMLHyperOctreeWriter::New();
250
                 //write.SetDataModeToAscii()
283
                 //write.SetDataModeToAscii()
260
             oct->GetLeafData()->RemoveArray( kmi );
293
             oct->GetLeafData()->RemoveArray( kmi );
261
             oct->GetLeafData()->RemoveArray( kidi );
294
             oct->GetLeafData()->RemoveArray( kidi );
262
             oct->GetLeafData()->RemoveArray( keri );
295
             oct->GetLeafData()->RemoveArray( keri );
296
+            oct->GetLeafData()->RemoveArray( khtr );
297
+            oct->GetLeafData()->RemoveArray( khti );
298
+            oct->GetLeafData()->RemoveArray( khrr );
299
+            oct->GetLeafData()->RemoveArray( khri );
263
 
300
 
264
             kerr->Delete();
301
             kerr->Delete();
265
             kid->Delete();
302
             kid->Delete();
266
             kr->Delete();
303
             kr->Delete();
267
             ki->Delete();
304
             ki->Delete();
268
             km->Delete();
305
             km->Delete();
306
+            htr->Delete();
307
+            hti->Delete();
308
+            hrr->Delete();
309
+            hri->Delete();
269
 
310
 
270
             }
311
             }
271
 
312
 
313
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
354
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
314
             //TODO TEST FOR ASYMETRY
355
             //TODO TEST FOR ASYMETRY
315
             //Real sintheta = std::sin(0.5*GAMMA*PulseI(iq)*Taup*(EBT.alpha-EBT.beta));
356
             //Real sintheta = std::sin(0.5*GAMMA*PulseI(iq)*Taup*(EBT.alpha-EBT.beta));
316
-            //F(iq) = volume * Complex(EBT.Bperp.real().norm(), EBT.Bperp.imag().norm()); //Complex(sintheta, EBT.Bperp.norm() );
357
+            //F(iq) = volume * Complex(EBT.Bperp.real().norm(), EBT.Bperp.imag().norm());
358
+            //Complex(sintheta, EBT.Bperp.norm() );
317
             //F(iq) = volume * Complex(EBT.alpha, EBT.beta);
359
             //F(iq) = volume * Complex(EBT.alpha, EBT.beta);
318
             //F(iq) = volume * MU0*Hr.norm();
360
             //F(iq) = volume * MU0*Hr.norm();
319
             //F(iq) = volume * EBT.err;
361
             //F(iq) = volume * EBT.err;
362
         // This all follows Weichman et al., 2000.
404
         // This all follows Weichman et al., 2000.
363
         // There are some numerical stability issues that arise when the two terms in the beta
405
         // There are some numerical stability issues that arise when the two terms in the beta
364
         // formulation are nearly equivalent. The current formulation will result in a null-valued
406
         // formulation are nearly equivalent. The current formulation will result in a null-valued
365
-        // beta, although this does not entirely recreate the true value of B perp.
366
-        // Reformulating may be welcome
407
+        // beta, although this does not entirely recreate the true value of B perp. Error is checked
408
+        // to be below 1%, but reformulating may be welcome
367
         EllipticB ElipB = EllipticB();
409
         EllipticB ElipB = EllipticB();
368
-        Vector3cr Bperp = B - B0hat.dot(B)*B0hat; // Eigen is OK with this
369
-        //Vector3r  Bperpr = B.real() - B0hat.dot(B.real())*B0hat;
370
-        //Vector3r  Bperpi = B.imag() - B0hat.dot(B.imag())*B0hat;
371
-        //Vector3cr Bperp = Bperpr + Complex(0,1)*Bperpi;
372
-        //ElipB.BperpdotB = Bperp.dot(B0hat);       // TODO remove
410
+        Vector3cr Bperp = B - B0hat.dot(B)*B0hat;
373
         Real BperpNorm  = Bperp.norm();
411
         Real BperpNorm  = Bperp.norm();
412
+        // These two are equivalent
374
         //Complex Bp2 = Bperp.transpose() * Bperp;
413
         //Complex Bp2 = Bperp.transpose() * Bperp;
375
         Complex Bp2 = Bperp.conjugate().dot(Bperp);
414
         Complex Bp2 = Bperp.conjugate().dot(Bperp);
376
         VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
415
         VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
381
         ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
420
         ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
382
         ElipB.bhatp = B0hat.cross(ElipB.bhat);
421
         ElipB.bhatp = B0hat.cross(ElipB.bhat);
383
         ElipB.zeta = std::real(std::log(ElipB.eizt)/Complex(0,1));
422
         ElipB.zeta = std::real(std::log(ElipB.eizt)/Complex(0,1));
384
-        /* use as an error check decomposed field - computed actual */
423
+        /* as an error check decomposed field - computed actual */
385
 //         Vector3cr Bperp2 = ElipB.eizt * (ElipB.alpha * ElipB.bhat
424
 //         Vector3cr Bperp2 = ElipB.eizt * (ElipB.alpha * ElipB.bhat
386
 //                        + (Complex(0,1) * ElipB.beta * ElipB.bhatp) );
425
 //                        + (Complex(0,1) * ElipB.beta * ElipB.bhatp) );
387
 //         ElipB.err = (Bperp-Bperp2).norm();
426
 //         ElipB.err = (Bperp-Bperp2).norm();
388
-//         if (ElipB.err > .01*Bperp.norm() ) {
427
+//         if (ElipB.err > .01*Bperp.norm() ) { // 1% error
389
 //             std::cout << "Elip error\n";
428
 //             std::cout << "Elip error\n";
390
 //             Real Beta2 = sgn( std::real(iB0.dot( Bperp.cross(Bperp.conjugate())) )) *
429
 //             Real Beta2 = sgn( std::real(iB0.dot( Bperp.cross(Bperp.conjugate())) )) *
391
 //                      (INVSQRT2*std::sqrt(BperpNorm*BperpNorm - std::abs(Bp2)));
430
 //                      (INVSQRT2*std::sqrt(BperpNorm*BperpNorm - std::abs(Bp2)));

Loading…
Cancel
Save