Browse Source

Fix in phase term of coils!

master
T-bone 7 years ago
parent
commit
d294baa90f

+ 3
- 4
examples/Coupling.cpp View File

39
 	auto earth = LayeredEarthEM::NewSP();
39
 	auto earth = LayeredEarthEM::NewSP();
40
 		earth->SetNumberOfLayers(3);
40
 		earth->SetNumberOfLayers(3);
41
 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
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
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
42
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
44
         // Set mag field info
43
         // Set mag field info
45
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
44
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
60
         Kern->SetLayeredEarthEM( earth );
59
         Kern->SetLayeredEarthEM( earth );
61
 
60
 
62
         Kern->SetIntegrationSize( (Vector3r() << 50,200,20).finished() );
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
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
65
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
67
     std::vector<std::string> rx = {std::string("Coil 2")};
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
     auto outfile = std::ofstream("coupling.dat");
69
     auto outfile = std::ofstream("coupling.dat");
71
     for (int ii=0; ii< Offsets.size(); ++ii) {
70
     for (int ii=0; ii< Offsets.size(); ++ii) {

+ 12
- 12
examples/Interference.cpp View File

22
 
22
 
23
 static constexpr Real GAMMA = 2.67518e8;                  // MKS units
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
 int main(int argc, char** argv) {
28
 int main(int argc, char** argv) {
29
     /*
29
     /*
50
     Real Larmor = earth->GetMagneticFieldMagnitude()*GAMMA/(2*PI);
50
     Real Larmor = earth->GetMagneticFieldMagnitude()*GAMMA/(2*PI);
51
 
51
 
52
     // Transmitter loops
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
     auto Kern = LoopInteractions<INTERFERENCE>::NewSP();
56
     auto Kern = LoopInteractions<INTERFERENCE>::NewSP();
57
         Kern->PushCoil( "Coil 1", Tx1 );
57
         Kern->PushCoil( "Coil 1", Tx1 );
59
         Kern->SetLayeredEarthEM( earth );
59
         Kern->SetLayeredEarthEM( earth );
60
 
60
 
61
         Kern->SetIntegrationSize( (Vector3r()   << 50,200,50).finished() );
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
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
65
     std::vector<std::string> tx = {std::string("Coil 1")};//,std::string("Coil 2")};
66
     std::vector<std::string> rx = {std::string("Coil 2")};
66
     std::vector<std::string> rx = {std::string("Coil 2")};
67
     VectorXr Offsets = VectorXr::LinSpaced(61, 0.00, 60.0); // nbins, low, high
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
     for (int ii=0; ii< Offsets.size(); ++ii) {
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
         #ifdef LEMMAUSEVTK
72
         #ifdef LEMMAUSEVTK
73
         Complex coupling = Kern->Calculate( tx, rx, true );
73
         Complex coupling = Kern->Calculate( tx, rx, true );
74
         #else
74
         #else
80
     outfile.close();
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
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
85
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
86
          Tx1->SetNumberOfPoints(nd);
86
          Tx1->SetNumberOfPoints(nd);
88
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
88
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
89
     int ii;
89
     int ii;
90
     for (ii=0; ii<nd; ++ii) {
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
     Tx1->SetCurrent(1.);
94
     Tx1->SetCurrent(1.);
99
     return Tx1;
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
     Tx1->SetNumberOfPoints(nd);
104
     Tx1->SetNumberOfPoints(nd);
105
 
105
 
106
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
106
     VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
107
     int ii;
107
     int ii;
108
     for (ii=0; ii<nd; ++ii) {
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
     Tx1->SetCurrent(1.);
112
     Tx1->SetCurrent(1.);

+ 16
- 10
examples/KV0-3loops.cpp View File

25
 int main(int argc, char** argv) {
25
 int main(int argc, char** argv) {
26
 
26
 
27
     if (argc < 3) {
27
     if (argc < 3) {
28
-        std::cout << "./KVo-3loops  <offset>  <tolerance>" << std::endl;
28
+        std::cout << "./KVo-3loops  <offset>  <tolerance> <rx>" << std::endl;
29
         exit(0);
29
         exit(0);
30
     }
30
     }
31
 
31
 
40
         // Set mag field info
40
         // Set mag field info
41
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
41
         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
42
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
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
     // Transmitter loops
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
     auto Kern = KernelV0::NewSP();
55
     auto Kern = KernelV0::NewSP();
51
         Kern->PushCoil( "Coil 1", Tx1 );
56
         Kern->PushCoil( "Coil 1", Tx1 );
85
     // may be more natural to work with?
90
     // may be more natural to work with?
86
     std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2"), std::string("Coil 3") };
91
     std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2"), std::string("Coil 3") };
87
     std::vector<std::string> rx = {std::string("Coil 1"), std::string("Coil 2"), std::string("Coil 3") };
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
     Kern->CalculateK0( tx, rx, true );
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
     dout << "# Transmitters: ";
98
     dout << "# Transmitters: ";
93
     for (auto lp : tx) {
99
     for (auto lp : tx) {
94
         dout << lp << "\t";
100
         dout << lp << "\t";
109
         dout << Kern->GetKernel().imag() << std::endl;
115
         dout << Kern->GetKernel().imag() << std::endl;
110
         dout.close();
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
     //std::ofstream out = std::ofstream(std::string("k-coincident.yaml"));
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
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
124
 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {

+ 5
- 6
examples/KernelV0.cpp View File

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

+ 1
- 1
include/KernelV0.h View File

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

+ 19
- 5
src/KernelV0.cpp View File

281
 
281
 
282
         // Compute phase delay
282
         // Compute phase delay
283
         // TODO add transmiiter current phase and delay induced apparent time phase!
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
         Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
285
         Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
286
 
286
 
287
         // Calcuate vector of all responses
287
         // Calcuate vector of all responses
288
         VectorXcr F = VectorXcr::Zero( PulseI.size() );
288
         VectorXcr F = VectorXcr::Zero( PulseI.size() );
289
         for (int iq=0; iq<PulseI.size(); ++iq) {
289
         for (int iq=0; iq<PulseI.size(); ++iq) {
290
             // Compute the tipping angle
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
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
292
             F(iq) = -volume*Complex(0,Larmor)*Mn0Abs*(EBR.alpha+EBR.beta)*ejztr*sintheta*PhaseTerm;
293
         }
293
         }
294
         return F;
294
         return F;
412
         // implicit else, is a leaf
412
         // implicit else, is a leaf
413
         Kern.row(ilay) += ksum;
413
         Kern.row(ilay) += ksum;
414
         VOLSUM += 8.*vol;
414
         VOLSUM += 8.*vol;
415
-        nleaves += 1;
415
+        nleaves += 8; // reflects the number of kernel evaluations
416
         return;     // is leaf
416
         return;     // is leaf
417
     }
417
     }
418
 
418
 
425
         const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
425
         const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
426
 
426
 
427
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
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
         // Next level step, interested in one level below
430
         // Next level step, interested in one level below
431
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
431
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
502
             }
502
             }
503
             return;  // not a leaf
503
             return;  // not a leaf
504
         }
504
         }
505
+        /* just stuff with sum of the kids and don't subdivide */
506
+        /*
505
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
507
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
506
         LeafDictIdx[curse->GetLeafId()] = nleaves;
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
         Kern.row(ilay) += ksum;
521
         Kern.row(ilay) += ksum;
508
         VOLSUM += 8*vol;
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
         return;     // is a leaf
524
         return;     // is a leaf
511
     }
525
     }
512
 
526
 

+ 2
- 1
src/LoopInteractions.cpp View File

47
 
47
 
48
     template <>
48
     template <>
49
     Complex LoopInteractions<INTERFERENCE>::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
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
     template <>
54
     template <>

Loading…
Cancel
Save