Преглед на файлове

More work on kernel calculation checking. Improved VTK file output

master
Trevor Irons преди 7 години
родител
ревизия
3f023f568b
променени са 2 файла, в които са добавени 60 реда и са изтрити 17 реда
  1. 6
    2
      examples/KernelV0-2.cpp
  2. 54
    15
      src/KernelV0.cpp

+ 6
- 2
examples/KernelV0-2.cpp Целия файл

@@ -41,8 +41,8 @@ int main(int argc, char** argv) {
41 41
         Kern->PushCoil( "Coil 2", Rx1 );
42 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 46
         Real tol(1e-13); // 13
47 47
         Kern->SetTolerance( tol ); // 1e-12
48 48
 
@@ -76,6 +76,10 @@ int main(int argc, char** argv) {
76 76
     // may be more natural to work with?
77 77
     std::vector<std::string> tx = {std::string("Coil 1")};
78 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 83
     Kern->CalculateK0( tx, rx, true ); // 3rd argument is vtk output
80 84
 
81 85
     std::ofstream dout = std::ofstream(std::string("Rx-")+std::string(argv[3])+std::string(".dat"));

+ 54
- 15
src/KernelV0.cpp Целия файл

@@ -80,6 +80,7 @@ namespace Lemma {
80 80
         for ( auto txm : TxRx) {
81 81
             node[txm.first] = txm.second->Serialize();
82 82
         }
83
+
83 84
         // LayeredEarthEM
84 85
         node["SigmaModel"] = SigmaModel->Serialize();
85 86
 
@@ -208,15 +209,15 @@ namespace Lemma {
208 209
             // Fill in leaf data
209 210
             vtkDoubleArray* kr = vtkDoubleArray::New();
210 211
                 kr->SetNumberOfComponents(1);
211
-                kr->SetName("Re($K_0$)");
212
+                kr->SetName("Re($\\mathcal{K}_0$)");
212 213
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
213 214
             vtkDoubleArray* ki = vtkDoubleArray::New();
214 215
                 ki->SetNumberOfComponents(1);
215
-                ki->SetName("Im($K_0$)");
216
+                ki->SetName("Im($\\mathcal{K}_0$)");
216 217
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
217 218
             vtkDoubleArray* km = vtkDoubleArray::New();
218 219
                 km->SetNumberOfComponents(1);
219
-                km->SetName("mod($K_0$)");
220
+                km->SetName("mod($\\mathcal{K}_0$)");
220 221
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
221 222
             vtkIntArray* kid = vtkIntArray::New();
222 223
                 kid->SetNumberOfComponents(1);
@@ -224,7 +225,26 @@ namespace Lemma {
224 225
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
225 226
             vtkIntArray* kerr = vtkIntArray::New();
226 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 249
             //Real LeafVol(0);
230 250
             for (auto leaf : LeafDict) {
@@ -234,7 +254,16 @@ namespace Lemma {
234 254
                 kid->InsertTuple1( leaf.first, leaf.first );
235 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 268
             for (auto leaf : LeafDictIdx) {
240 269
                 kerr->InsertTuple1( leaf.first, leaf.second );
@@ -245,6 +274,10 @@ namespace Lemma {
245 274
             auto kmi = oct->GetLeafData()->AddArray(km);
246 275
             auto kidi = oct->GetLeafData()->AddArray(kid);
247 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 282
             auto write = vtkXMLHyperOctreeWriter::New();
250 283
                 //write.SetDataModeToAscii()
@@ -260,12 +293,20 @@ namespace Lemma {
260 293
             oct->GetLeafData()->RemoveArray( kmi );
261 294
             oct->GetLeafData()->RemoveArray( kidi );
262 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 301
             kerr->Delete();
265 302
             kid->Delete();
266 303
             kr->Delete();
267 304
             ki->Delete();
268 305
             km->Delete();
306
+            htr->Delete();
307
+            hti->Delete();
308
+            hrr->Delete();
309
+            hri->Delete();
269 310
 
270 311
             }
271 312
 
@@ -313,7 +354,8 @@ namespace Lemma {
313 354
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
314 355
             //TODO TEST FOR ASYMETRY
315 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 359
             //F(iq) = volume * Complex(EBT.alpha, EBT.beta);
318 360
             //F(iq) = volume * MU0*Hr.norm();
319 361
             //F(iq) = volume * EBT.err;
@@ -362,15 +404,12 @@ namespace Lemma {
362 404
         // This all follows Weichman et al., 2000.
363 405
         // There are some numerical stability issues that arise when the two terms in the beta
364 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 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 411
         Real BperpNorm  = Bperp.norm();
412
+        // These two are equivalent
374 413
         //Complex Bp2 = Bperp.transpose() * Bperp;
375 414
         Complex Bp2 = Bperp.conjugate().dot(Bperp);
376 415
         VectorXcr iB0 = Complex(0,1)*B0hat.cast<Complex>().array();
@@ -381,11 +420,11 @@ namespace Lemma {
381 420
         ElipB.bhat = ((Real)1./ElipB.alpha)*(((Real)1./ElipB.eizt)*Bperp.array()).real().array();
382 421
         ElipB.bhatp = B0hat.cross(ElipB.bhat);
383 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 424
 //         Vector3cr Bperp2 = ElipB.eizt * (ElipB.alpha * ElipB.bhat
386 425
 //                        + (Complex(0,1) * ElipB.beta * ElipB.bhatp) );
387 426
 //         ElipB.err = (Bperp-Bperp2).norm();
388
-//         if (ElipB.err > .01*Bperp.norm() ) {
427
+//         if (ElipB.err > .01*Bperp.norm() ) { // 1% error
389 428
 //             std::cout << "Elip error\n";
390 429
 //             Real Beta2 = sgn( std::real(iB0.dot( Bperp.cross(Bperp.conjugate())) )) *
391 430
 //                      (INVSQRT2*std::sqrt(BperpNorm*BperpNorm - std::abs(Bp2)));

Loading…
Отказ
Запис