6c146fda784f72caa4bcd1af9c8f9728b3f42063
[Merlin.git] / examples / Interference.cpp
1 /* This file is part of Lemma, a geophysical modelling and inversion API.
2 * More information is available at http://lemmasoftware.org
3 */
4
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 /**
11 * @file
12 * @date 11/11/2016 02:44:37 PM
13 * @version $Id$
14 * @author Trevor Irons (ti)
15 * @email tirons@egi.utah.edu
16 * @copyright Copyright (c) 2016, University of Utah
17 * @copyright Copyright (c) 2016, Lemma Software, LLC
18 */
19
20 #include <Merlin>
21 using namespace Lemma;
22
23 static constexpr Real GAMMA = 2.67518e8; // MKS units
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 );
27
28 int main(int argc, char** argv) {
29 /*
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 */
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();
49
50 Real Larmor = earth->GetMagneticFieldMagnitude()*GAMMA/(2*PI);
51
52 // Transmitter loops
53 auto Tx1 = CircularLoop(21, 15, 50, 50, Larmor);
54 auto Tx2 = CircularLoop(21, 15, 50, 50, Larmor); // initially coincident
55
56 auto Kern = LoopInteractions<INTERFERENCE>::NewSP();
57 Kern->PushCoil( "Coil 1", Tx1 );
58 Kern->PushCoil( "Coil 2", Tx2 );
59 Kern->SetLayeredEarthEM( earth );
60
61 Kern->SetIntegrationSize( (Vector3r() << 50,200,50).finished() );
62 Kern->SetIntegrationOrigin( (Vector3r() << 0,0,5.0).finished() );
63 Kern->SetTolerance( 1e-3 ); // 1e-12
64
65 std::vector<std::string> tx = {std::string("Coil 1")};//,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
68
69 auto outfile = std::ofstream("interference.dat");
70 for (int ii=0; ii< Offsets.size(); ++ii) {
71 MoveLoop(Tx2, 21, 15, 50, 50 + Offsets(ii), Larmor);
72 #ifdef LEMMAUSEVTK
73 Complex coupling = Kern->Calculate( tx, rx, true );
74 #else
75 Complex coupling = Kern->Calculate( tx, rx, false );
76 #endif
77 std::cout << "coupling " << coupling << std::endl;
78 outfile << Offsets(ii) << "\t" << std::real(coupling) << "\t" << std::imag(coupling) << std::endl;
79 }
80 outfile.close();
81 }
82
83 std::shared_ptr<Lemma::PolygonalWireAntenna> CircularLoop ( int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
84
85 auto Tx1 = Lemma::PolygonalWireAntenna::NewSP();
86 Tx1->SetNumberOfPoints(nd);
87
88 VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
89 int 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));
92 }
93
94 Tx1->SetCurrent(1.);
95 Tx1->SetNumberOfTurns(1);
96 Tx1->SetNumberOfFrequencies(1);
97 Tx1->SetFrequency(0,wL);
98
99 return Tx1;
100 }
101
102 void MoveLoop( std::shared_ptr<Lemma::PolygonalWireAntenna> Tx1, int nd, Real Radius, Real Offsetx, Real Offsety, Real wL ) {
103
104 Tx1->SetNumberOfPoints(nd);
105
106 VectorXr range = VectorXr::LinSpaced(nd, 0, 2*PI);
107 int 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));
110 }
111
112 Tx1->SetCurrent(1.);
113 Tx1->SetNumberOfTurns(1);
114 Tx1->SetNumberOfFrequencies(1);
115 Tx1->SetFrequency(0,wL);
116
117 }