瀏覽代碼

Fix in phase term of coils!

master
T-bone 8 年之前
父節點
當前提交
d294baa90f
共有 7 個檔案被更改,包括 58 行新增39 行删除
  1. 3
    4
      examples/Coupling.cpp
  2. 12
    12
      examples/Interference.cpp
  3. 16
    10
      examples/KV0-3loops.cpp
  4. 5
    6
      examples/KernelV0.cpp
  5. 1
    1
      include/KernelV0.h
  6. 19
    5
      src/KernelV0.cpp
  7. 2
    1
      src/LoopInteractions.cpp

+ 3
- 4
examples/Coupling.cpp 查看文件

@@ -39,7 +39,6 @@ int main(int argc, char** argv) {
39 39
 	auto earth = LayeredEarthEM::NewSP();
40 40
 		earth->SetNumberOfLayers(3);
41 41
 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
42
-		//earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./7.,0), Complex(1./100.)).finished() );
43 42
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
44 43
         // Set mag field info
45 44
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
@@ -60,12 +59,12 @@ int main(int argc, char** argv) {
60 59
         Kern->SetLayeredEarthEM( earth );
61 60
 
62 61
         Kern->SetIntegrationSize( (Vector3r() << 50,200,20).finished() );
63
-        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0.01).finished() );
64
-        Kern->SetTolerance( 1e-12 ); // 1e-12
62
+        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0.1).finished() );
63
+        Kern->SetTolerance( 1e-7 ); // 1e-12
65 64
 
66 65
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
67 66
     std::vector<std::string> rx = {std::string("Coil 2")};
68
-    VectorXr Offsets = VectorXr::LinSpaced(30, 0.00, 45.0); // nbins, low, high
67
+    VectorXr Offsets = VectorXr::LinSpaced(121, 0.00, 60.0); // nbins, low, high
69 68
 
70 69
     auto outfile = std::ofstream("coupling.dat");
71 70
     for (int ii=0; ii< Offsets.size(); ++ii) {

+ 12
- 12
examples/Interference.cpp 查看文件

@@ -22,8 +22,8 @@ using namespace Lemma;
22 22
 
23 23
 static constexpr Real GAMMA = 2.67518e8;                  // MKS units
24 24
 
25
-std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real Offsetx, Real Offsety, Real wL ) ;
26
-void MoveLoop( std::shared_ptr<PolygonalWireAntenna> Loop, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL );
25
+std::shared_ptr<PolygonalWireAntenna>       CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety, Real wL, Real pol=1. ) ;
26
+void MoveLoop( std::shared_ptr<PolygonalWireAntenna> Loop, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL, Real pol=1. );
27 27
 
28 28
 int main(int argc, char** argv) {
29 29
     /*
@@ -50,8 +50,8 @@ int main(int argc, char** argv) {
50 50
     Real Larmor = earth->GetMagneticFieldMagnitude()*GAMMA/(2*PI);
51 51
 
52 52
     // Transmitter loops
53
-    auto Tx1 = CircularLoop(21, 15, 50, 50, Larmor);
54
-    auto Tx2 = CircularLoop(21, 15, 50, 50, Larmor); // initially coincident
53
+    auto Tx1 = CircularLoop(21, 15, 50, 50, Larmor,  1);
54
+    auto Tx2 = CircularLoop(21, 15, 50, 50, Larmor, -1); // initially coincident
55 55
 
56 56
     auto Kern = LoopInteractions<INTERFERENCE>::NewSP();
57 57
         Kern->PushCoil( "Coil 1", Tx1 );
@@ -59,16 +59,16 @@ int main(int argc, char** argv) {
59 59
         Kern->SetLayeredEarthEM( earth );
60 60
 
61 61
         Kern->SetIntegrationSize( (Vector3r()   << 50,200,50).finished() );
62
-        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,5.0).finished() );
63
-        Kern->SetTolerance( 1e-3 ); // 1e-12
62
+        Kern->SetIntegrationOrigin( (Vector3r() << 0, 0, 0.1).finished() );
63
+        Kern->SetTolerance( 1e-5 ); // 1e-12
64 64
 
65 65
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
66 66
     std::vector<std::string> rx = {std::string("Coil 2")};
67 67
     VectorXr Offsets = VectorXr::LinSpaced(61, 0.00, 60.0); // nbins, low, high
68 68
 
69
-    auto outfile = std::ofstream("interference.dat");
69
+    auto outfile = std::ofstream("interference-opposed.dat");
70 70
     for (int ii=0; ii< Offsets.size(); ++ii) {
71
-        MoveLoop(Tx2, 21, 15, 50, 50 + Offsets(ii), Larmor);
71
+        MoveLoop(Tx2, 21, 15, 50, 50 + Offsets(ii), Larmor, -1.);
72 72
         #ifdef LEMMAUSEVTK
73 73
         Complex coupling = Kern->Calculate( tx, rx, true );
74 74
         #else
@@ -80,7 +80,7 @@ int main(int argc, char** argv) {
80 80
     outfile.close();
81 81
 }
82 82
 
83
-std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
83
+std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety, Real wL, Real pol ) {
84 84
 
85 85
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
86 86
          Tx1->SetNumberOfPoints(nd);
@@ -88,7 +88,7 @@ std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius,
88 88
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
89 89
     int ii;
90 90
     for (ii=0; ii<nd; ++ii) {
91
-        Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
91
+        Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+pol*Radius*std::sin(range(ii)),  -1e-3));
92 92
     }
93 93
 
94 94
     Tx1->SetCurrent(1.);
@@ -99,14 +99,14 @@ std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius,
99 99
     return Tx1;
100 100
 }
101 101
 
102
-void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
102
+void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL, Real pol ) {
103 103
 
104 104
     Tx1->SetNumberOfPoints(nd);
105 105
 
106 106
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
107 107
     int ii;
108 108
     for (ii=0; ii<nd; ++ii) {
109
-        Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
109
+        Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+pol*Radius*std::sin(range(ii)),  -1e-3));
110 110
     }
111 111
 
112 112
     Tx1->SetCurrent(1.);

+ 16
- 10
examples/KV0-3loops.cpp 查看文件

@@ -25,7 +25,7 @@ std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real O
25 25
 int main(int argc, char** argv) {
26 26
 
27 27
     if (argc < 3) {
28
-        std::cout << "./KVo-3loops  <offset>  <tolerance>" << std::endl;
28
+        std::cout << "./KVo-3loops  <offset>  <tolerance> <rx>" << std::endl;
29 29
         exit(0);
30 30
     }
31 31
 
@@ -40,12 +40,17 @@ int main(int argc, char** argv) {
40 40
         // Set mag field info
41 41
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
42 42
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
43
+        //earth->SetMagneticFieldIncDecMag( 90, 0, 52750, NANOTESLA );
44
+        std::cout << "B0 " << earth->GetMagneticField( ).transpose() << std::endl;
45
+        std::cout << "hat BO " << earth->GetMagneticFieldUnitVector().transpose() << std::endl ;
46
+        std::cout << "hat |BO| " << earth->GetMagneticFieldUnitVector().norm() << std::endl ;
43 47
 
44 48
     // Transmitter loops
45
-    auto Tx1 = CircularLoop(21, 15, 100+offset/2., 100 - offset/2.);
46
-    auto Tx2 = CircularLoop(21, 15, 100+offset/2., 100 + offset/2.); // 100, 115, 124.8, 130
47
-    auto Tx3 = CircularLoop(21, 15, 100-offset/2., 100); // 100, 115, 124.8, 130
48
-    //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
49
+    auto Tx1 = CircularLoop(21, 15, 100+offset/2., 100-offset/2.);
50
+    auto Tx2 = CircularLoop(21, 15, 100+offset/2., 100+offset/2.);
51
+    auto Tx3 = CircularLoop(21, 15, 100-offset/2., 100          );
52
+
53
+
49 54
 
50 55
     auto Kern = KernelV0::NewSP();
51 56
         Kern->PushCoil( "Coil 1", Tx1 );
@@ -85,10 +90,11 @@ int main(int argc, char** argv) {
85 90
     // may be more natural to work with?
86 91
     std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2"), std::string("Coil 3") };
87 92
     std::vector<std::string> rx = {std::string("Coil 1"), std::string("Coil 2"), std::string("Coil 3") };
88
-    //std::vector<std::string> rx = {std::string("Coil 1")};
93
+    //std::vector<std::string> rx = {std::string("Coil 1"), std::string("Coil 2")};//, std::string("Coil 3") };
94
+    //std::vector<std::string> rx = {std::string(argv[3])};
89 95
     Kern->CalculateK0( tx, rx, true );
90 96
 
91
-    std::ofstream dout = std::ofstream(std::string("k0-3Tx-RxCh1-")+ std::string(argv[1])+ std::string(".dat"));
97
+    std::ofstream dout = std::ofstream(std::string("k0-3Tx-RxCh-") + std::string(argv[3]) + std::string("-tol") + std::string(argv[1])+ std::string(".dat"));
92 98
     dout << "# Transmitters: ";
93 99
     for (auto lp : tx) {
94 100
         dout << lp << "\t";
@@ -109,10 +115,10 @@ int main(int argc, char** argv) {
109 115
         dout << Kern->GetKernel().imag() << std::endl;
110 116
         dout.close();
111 117
 
112
-    std::ofstream out = std::ofstream(std::string("k0-3Tx-RxCh1-")+std::string(argv[1])+std::string(".yaml"));
118
+    //std::ofstream out = std::ofstream(std::string("k0-3Tx-RxCh1-")+std::string(argv[1])+std::string(".yaml"));
113 119
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
114
-    out << *Kern;
115
-    out.close();
120
+    //out << *Kern;
121
+    //out.close();
116 122
 }
117 123
 
118 124
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {

+ 5
- 6
examples/KernelV0.cpp 查看文件

@@ -25,7 +25,6 @@ std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real O
25 25
 int main(int argc, char** argv) {
26 26
 
27 27
     Real offset = atof(argv[1]);
28
-        std::cout << offset << std::endl;
29 28
 
30 29
 	auto earth = LayeredEarthEM::NewSP();
31 30
 		earth->SetNumberOfLayers(3);
@@ -64,8 +63,8 @@ int main(int argc, char** argv) {
64 63
         //Kern->SetPulseCurrent( VectorXr::LinSpaced( 1, 10, 200 )  ); // nbins, low, high
65 64
         Kern->SetPulseCurrent( I ); // nbins, low, high
66 65
 
67
-        //Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 30, 3, 45.5 ) ); // nlay, low, high
68
-        VectorXr interfaces = VectorXr::LinSpaced( 41, .5, 45.5 ); // nlay, low, high
66
+        //VectorXr interfaces = VectorXr::LinSpaced( 41, .5, 45.5 ); // nlay, low, high
67
+        VectorXr interfaces = VectorXr::LinSpaced( 51, .5, 45.5 ); // nlay, low, high
69 68
         Real thick = .5;
70 69
         for (int ilay=1; ilay<interfaces.size(); ++ilay) {
71 70
             interfaces(ilay) = interfaces(ilay-1) + thick;
@@ -76,10 +75,10 @@ int main(int argc, char** argv) {
76 75
     // We could, I suppose, take the earth model in here? For non-linear that
77 76
     // may be more natural to work with?
78 77
     std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
79
-    std::vector<std::string> rx = {std::string("Coil 1")};
78
+    std::vector<std::string> rx = {std::string("Coil 2")};
80 79
     Kern->CalculateK0( tx, rx, false );
81 80
 
82
-    std::ofstream dout = std::ofstream(std::string("k-")+ std::string(argv[1])+ std::string(".dat"));
81
+    std::ofstream dout = std::ofstream(std::string("k-Tx2coil-Rx1coil-offset-")+ std::string(argv[1])+ std::string(".dat"));
83 82
     //std::ofstream dout = std::ofstream(std::string("k-coincident.dat"));
84 83
         dout << interfaces.transpose() << std::endl;
85 84
         dout << I.transpose() << std::endl;
@@ -89,7 +88,7 @@ int main(int argc, char** argv) {
89 88
         dout << Kern->GetKernel().imag() << std::endl;
90 89
         dout.close();
91 90
 
92
-    std::ofstream out = std::ofstream(std::string("k-")+std::string(argv[1])+std::string(".yaml"));
91
+    std::ofstream out = std::ofstream(std::string("k-Tx2coil-Rx1coil-offset-")+std::string(argv[1])+std::string(".yaml"));
93 92
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
94 93
     out << *Kern;
95 94
     out.close();

+ 1
- 1
include/KernelV0.h 查看文件

@@ -271,7 +271,7 @@ namespace Lemma {
271 271
         int                                       ilay;
272 272
         int                                       nleaves;
273 273
         int                                       minLevel=4;
274
-        int                                       maxLevel=8;
274
+        int                                       maxLevel=10;
275 275
 
276 276
         Real                                      VOLSUM;
277 277
         Real                                      tol=1e-11;

+ 19
- 5
src/KernelV0.cpp 查看文件

@@ -281,14 +281,14 @@ namespace Lemma {
281 281
 
282 282
         // Compute phase delay
283 283
         // TODO add transmiiter current phase and delay induced apparent time phase!
284
-        Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) + (B0hat.dot(EBR.bhat.cross(EBT.bhat) ));
284
+        Complex PhaseTerm = EBR.bhat.dot(EBT.bhat) + Complex(0, (B0hat.dot(EBR.bhat.cross(EBT.bhat))));
285 285
         Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
286 286
 
287 287
         // Calcuate vector of all responses
288 288
         VectorXcr F = VectorXcr::Zero( PulseI.size() );
289 289
         for (int iq=0; iq<PulseI.size(); ++iq) {
290 290
             // Compute the tipping angle
291
-            Real sintheta = std::sin(0.5*GAMMA*PulseI(iq)*Taup*std::abs(EBT.alpha-EBT.beta));
291
+            Real sintheta = std::sin(0.5*GAMMA*PulseI(iq)*Taup*(EBT.alpha-EBT.beta)); // why std::abs
292 292
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
293 293
         }
294 294
         return F;
@@ -412,7 +412,7 @@ namespace Lemma {
412 412
         // implicit else, is a leaf
413 413
         Kern.row(ilay) += ksum;
414 414
         VOLSUM += 8.*vol;
415
-        nleaves += 1;
415
+        nleaves += 8; // reflects the number of kernel evaluations
416 416
         return;     // is leaf
417 417
     }
418 418
 
@@ -425,7 +425,7 @@ namespace Lemma {
425 425
         const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
426 426
 
427 427
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
428
-        std::cout.flush();
428
+        //std::cout.flush();
429 429
 
430 430
         // Next level step, interested in one level below
431 431
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
@@ -502,11 +502,25 @@ namespace Lemma {
502 502
             }
503 503
             return;  // not a leaf
504 504
         }
505
+        /* just stuff with sum of the kids and don't subdivide */
506
+        /*
505 507
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
506 508
         LeafDictIdx[curse->GetLeafId()] = nleaves;
509
+        */
510
+        /* Alternatively, subdivide the VTK octree here and stuff the children to make better
511
+         * visuals, but also 8x the storage...
512
+         */
513
+        oct->SubdivideLeaf(curse);
514
+        for (int ichild=0; ichild<8; ++ichild) {
515
+            curse->ToChild(ichild);
516
+            LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
517
+            LeafDictIdx[curse->GetLeafId()] = nleaves;
518
+            curse->ToParent();
519
+        }
520
+
507 521
         Kern.row(ilay) += ksum;
508 522
         VOLSUM += 8*vol;
509
-        nleaves += 1;
523
+        nleaves += 8; // good reason to say 1 or 8 here...8 sounds better and reflects kernel evaluations
510 524
         return;     // is a leaf
511 525
     }
512 526
 

+ 2
- 1
src/LoopInteractions.cpp 查看文件

@@ -47,7 +47,8 @@ namespace Lemma {
47 47
 
48 48
     template <>
49 49
     Complex LoopInteractions<INTERFERENCE>::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
50
-        return volume * (1.-((Ht+Hr).norm()/(Hr.norm() + Ht.norm()))); // interference
50
+        //return volume * (1.-((Ht+Hr).norm()/(Hr.norm() + Ht.norm()))); // normalized interference
51
+        return volume * (Ht+Hr).norm();  // interference not normalized
51 52
     }
52 53
 
53 54
     template <>

Loading…
取消
儲存