Browse Source

coupling fixes

master
T-bone 7 years ago
parent
commit
fc005c1d1e
3 changed files with 56 additions and 32 deletions
  1. 1
    1
      CMakeLists.txt
  2. 38
    24
      examples/Coupling.cpp
  3. 17
    7
      src/Coupling.cpp

+ 1
- 1
CMakeLists.txt View File

@@ -24,7 +24,7 @@ endif()
24 24
 
25 25
 # Install
26 26
 install ( TARGETS merlin DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
27
-install ( FILES include/MERLIN  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 
27
+install ( FILES include/Merlin  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 
28 28
 install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma  FILES_MATCHING PATTERN "*.h")
29 29
 
30 30
 #install ( DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma/  FILES_MATCHING PATTERN "FDEM1D")

+ 38
- 24
examples/Coupling.cpp View File

@@ -20,49 +20,65 @@
20 20
 #include <Merlin>
21 21
 using namespace Lemma;
22 22
 
23
-std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real Offsetx, Real Offsety ) ;
24
-void MoveLoop( std::shared_ptr<PolygonalWireAntenna> Loop, int nd, Real Radius, Real Offsetx, Real Offsety );
23
+static constexpr Real GAMMA = 2.67518e8;                  // MKS units
25 24
 
26
-int main(int argc, char** argv) {
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 );
27 27
 
28
-    Real offset = atof(argv[1]);
28
+int main(int argc, char** argv) {
29 29
 
30
-	auto earth = LayeredEarthEM::NewSP();
31
-		earth->SetNumberOfLayers(3);
32
-		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
33
-		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
34
-        // Set mag field info
35
-        // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
36
-        earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
30
+    if ( argc < 2 ) {
31
+        std::cout << "Calculates the coupling between two sNMR loops at the Larmor frequency. Usage\n"
32
+                  << "\t./Coupling   EarthModel.yaml" << std::endl;
33
+        exit(0);
34
+    }
35
+    //Real offset = atof(argv[1]);
36
+    auto earth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[1]) );
37
+    Real Larmor = earth->GetMagneticFieldMagnitude()*GAMMA/(2*PI);
38
+//  RedButtes model, also how you can generate your own files
39
+// 	auto earth = LayeredEarthEM::NewSP();
40
+// 		earth->SetNumberOfLayers(3);
41
+// 		earth->SetLayerConductivity( (VectorXcr(3) << Complex(0.,0), Complex(1./50.,0), Complex(1./100.)).finished() );
42
+// 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
43
+//         // Set mag field info
44
+//         // From NOAA, Laramie WY, June 9 2016, aligned with mag. north
45
+//         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
46
+//     auto sig = std::ofstream("SigmaModel.yaml");
47
+//         sig << *earth << std::endl;
48
+//         sig.close();
37 49
 
38 50
     // Transmitter loops
39
-    auto Tx1 = CircularLoop(21, 15, 100, 100);
40
-    auto Tx2 = CircularLoop(21, 15, 100, 100 + offset);
51
+    auto Tx1 = CircularLoop(21, 15, 100, 75, Larmor);
52
+    auto Tx2 = CircularLoop(21, 15, 100, 75, Larmor); // initially coincident
41 53
 
42 54
     auto Kern = Coupling::NewSP();
43 55
         Kern->PushCoil( "Coil 1", Tx1 );
44 56
         Kern->PushCoil( "Coil 2", Tx2 );
45 57
         Kern->SetLayeredEarthEM( earth );
46 58
 
47
-        Kern->SetIntegrationSize( (Vector3r() << 200,200,50).finished() );
48
-        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,5).finished() );
49
-        Kern->SetTolerance( 1e-7 ); // 1e-12
59
+        Kern->SetIntegrationSize( (Vector3r() << 200,300,20).finished() );
60
+        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0.01).finished() );
61
+        Kern->SetTolerance( 1e-5 ); // 1e-12
50 62
 
51 63
     std::vector<std::string> tx = {std::string("Coil 1")};
52 64
     std::vector<std::string> rx = {std::string("Coil 2")};
53
-    VectorXr Offsets = VectorXr::LinSpaced(60, 5.25, 60); // nbins, low, high
65
+    VectorXr Offsets = VectorXr::LinSpaced(6, 22.00, 23.0); // nbins, low, high
54 66
 
55 67
     auto outfile = std::ofstream("coupling.dat");
56 68
     for (int ii=0; ii< Offsets.size(); ++ii) {
57
-        MoveLoop(Tx2, 21, 15, 100, 100 + Offsets(ii));
69
+        MoveLoop(Tx2, 21, 15, 100, 75 + Offsets(ii), Larmor);
70
+        #ifdef LEMMAUSEVTK
71
+        Complex coupling = Kern->Calculate( tx, rx, true );
72
+        #else
58 73
         Complex coupling = Kern->Calculate( tx, rx, false );
74
+        #endif
59 75
         std::cout << "coupling " << coupling << std::endl;
60 76
         outfile << Offsets(ii) << "\t" <<  std::real(coupling) << "\t" << std::imag(coupling) << std::endl;
61 77
     }
62 78
     outfile.close();
63 79
 }
64 80
 
65
-std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety ) {
81
+std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
66 82
 
67 83
     auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
68 84
          Tx1->SetNumberOfPoints(nd);
@@ -72,17 +88,16 @@ std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius,
72 88
     for (ii=0; ii<nd; ++ii) {
73 89
         Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
74 90
     }
75
-    //Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*1, Offsety,  -1e-3));
76 91
 
77 92
     Tx1->SetCurrent(1.);
78 93
     Tx1->SetNumberOfTurns(1);
79 94
     Tx1->SetNumberOfFrequencies(1);
80
-    Tx1->SetFrequency(0,2246);
95
+    Tx1->SetFrequency(0,wL);
81 96
 
82 97
     return Tx1;
83 98
 }
84 99
 
85
-void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Radius, Real Offsetx, Real Offsety ) {
100
+void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
86 101
 
87 102
     Tx1->SetNumberOfPoints(nd);
88 103
 
@@ -91,11 +106,10 @@ void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Ra
91 106
     for (ii=0; ii<nd; ++ii) {
92 107
         Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*std::cos(range(ii)), Offsety+Radius*std::sin(range(ii)),  -1e-3));
93 108
     }
94
-    //Tx1->SetPoint(ii, Vector3r(Offsetx+Radius*1, Offsety,  -1e-3));
95 109
 
96 110
     Tx1->SetCurrent(1.);
97 111
     Tx1->SetNumberOfTurns(1);
98 112
     Tx1->SetNumberOfFrequencies(1);
99
-    Tx1->SetFrequency(0,2246);
113
+    Tx1->SetFrequency(0,wL);
100 114
 
101 115
 }

+ 17
- 7
src/Coupling.cpp View File

@@ -107,9 +107,15 @@ namespace Lemma {
107 107
     //--------------------------------------------------------------------------------------
108 108
     Complex Coupling::Calculate (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
109 109
             bool vtkOutput ) {
110
-        // All EM calculations will share same field points
111
-        cpoints = FieldPoints::NewSP();
112
-            cpoints->SetNumberOfPoints(8);
110
+
111
+        static bool first = false; // a little hackish
112
+        if (!first) {
113
+            // All EM calculations will share same field points
114
+            cpoints = FieldPoints::NewSP();
115
+                cpoints->SetNumberOfPoints(8);
116
+        }
117
+        first = true;
118
+
113 119
         for (auto tx : Tx) {
114 120
             // Set up EMEarth
115 121
             EMEarths[tx] = EMEarth1D::NewSP();
@@ -140,6 +146,7 @@ namespace Lemma {
140 146
         SUM = 0;
141 147
         IntegrateOnOctreeGrid( vtkOutput );
142 148
         std::cout << "\nFinished KERNEL\n";
149
+        EMEarths.clear();
143 150
         return SUM;
144 151
     }
145 152
 
@@ -147,7 +154,9 @@ namespace Lemma {
147 154
     //       Class:  Coupling
148 155
     //      Method:  IntegrateOnOctreeGrid
149 156
     //--------------------------------------------------------------------------------------
150
-    void Coupling::IntegrateOnOctreeGrid( bool vtkOutput) {
157
+    void Coupling::IntegrateOnOctreeGrid( bool vtkOutput ) {
158
+
159
+        static int count = 0;
151 160
 
152 161
         Vector3r cpos = Origin + Size/2.;
153 162
 
@@ -209,7 +218,7 @@ namespace Lemma {
209 218
             auto write = vtkXMLHyperOctreeWriter::New();
210 219
                 //write.SetDataModeToAscii()
211 220
                 write->SetInputData(oct);
212
-                std::string fname = std::string("octree-couple") + std::string(".vto");
221
+                std::string fname = std::string("octree-couple-") + to_string(count) + std::string(".vto");
213 222
                 write->SetFileName(fname.c_str());
214 223
                 write->Write();
215 224
                 write->Delete();
@@ -235,6 +244,7 @@ namespace Lemma {
235 244
         }
236 245
         std::cout << "\nVOLSUM=" << VOLSUM << "\tActual=" <<  Size(0)*Size(1)*Size(2)
237 246
                   << "\tDifference=" << VOLSUM - (Size(0)*Size(1)*Size(2)) <<  std::endl;
247
+        count += 1;
238 248
     }
239 249
 
240 250
     //--------------------------------------------------------------------------------------
@@ -242,8 +252,8 @@ namespace Lemma {
242 252
     //      Method:  f
243 253
     //--------------------------------------------------------------------------------------
244 254
     Complex Coupling::f( const Vector3r& r, const Real& volume, const Vector3cr& Ht, const Vector3cr& Hr ) {
245
-        return volume*Ht.dot(Hr);
246
-        //return Ht.dot(Hr);
255
+        //return volume*(Hr.norm() + Ht.norm());//.dot(Hr);
256
+        return volume * ( Ht.dot(Hr) );
247 257
     }
248 258
 
249 259
     //--------------------------------------------------------------------------------------

Loading…
Cancel
Save