|
@@ -0,0 +1,234 @@
|
|
1
|
+// ===========================================================================
|
|
2
|
+//
|
|
3
|
+// Filename: hantenna.cpp
|
|
4
|
+//
|
|
5
|
+// Created: 10/07/2010 08:57:04 AM
|
|
6
|
+// Modified: 11 April 2018
|
|
7
|
+// Compiler: Tested with g++, icpc, and MSVC 2017
|
|
8
|
+//
|
|
9
|
+// Author: Trevor Irons (ti)
|
|
10
|
+//
|
|
11
|
+// Copyright (C) 2012,2018 Trevor Irons
|
|
12
|
+//
|
|
13
|
+// Organisation: Lemma Software
|
|
14
|
+//
|
|
15
|
+// Email: Trevor.Irons@lemmasoftware.org
|
|
16
|
+//
|
|
17
|
+// ===========================================================================
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ @file
|
|
21
|
+ @author Trevor Irons
|
|
22
|
+ @date 10/07/2010
|
|
23
|
+ $Id$
|
|
24
|
+ **/
|
|
25
|
+
|
|
26
|
+#include "LemmaCore"
|
|
27
|
+#include "FDEM1D"
|
|
28
|
+#include "timer.h"
|
|
29
|
+
|
|
30
|
+using namespace Lemma;
|
|
31
|
+
|
|
32
|
+std::vector<Real> readinpfile(const std::string& fname);
|
|
33
|
+
|
|
34
|
+std::vector<std::string> readinpfile2(const std::string& fname);
|
|
35
|
+
|
|
36
|
+int main(int argc, char** argv) {
|
|
37
|
+
|
|
38
|
+ std::cout <<
|
|
39
|
+ "\n"
|
|
40
|
+ << "Hantenna \n\n
|
|
41
|
+ << "Hantenna is a programme for computing the H field from polygonal wire\n"
|
|
42
|
+ << "loop sources \n\n"
|
|
43
|
+ << "Hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
|
|
44
|
+ << "Lemma is Free and Open Source Software (FOSS) and is released under\n"
|
|
45
|
+ << "the MPL, it is covered by the following copyrights:\n"
|
|
46
|
+ << "Copyright (C) 2009, 2010, 2011, 2012, 218 Trevor P. Irons\n"
|
|
47
|
+ << "Copyright (C) 2011, 2012 M. Andy Kass\n\n"
|
|
48
|
+ << "More information may be found at: https://lemmasoftware.org\n"
|
|
49
|
+ << " info@lemmasoftware.org\n\n"
|
|
50
|
+ << "=====================================================================\n"
|
|
51
|
+ << "This programme is part of Lemma, a geophysical modelling and inversion API \n"
|
|
52
|
+ << "This Source Code Form is subject to the terms of the Mozilla Public\n"
|
|
53
|
+ << "License, v. 2.0. If a copy of the MPL was not distributed with this\n"
|
|
54
|
+ << "file, You can obtain one at http://mozilla.org/MPL/2.0/. \n"
|
|
55
|
+ << "=====================================================================\n\n\n";
|
|
56
|
+
|
|
57
|
+ if (argc < 5) {
|
|
58
|
+ std::cout << "usage: hantenna.exe trans.inp cond.inp points.inp config.inp \n";
|
|
59
|
+ exit(0);
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ #ifdef LEMMAUSEOMP
|
|
63
|
+ std::cout << "OpenMP is using " << omp_get_max_threads() << " threads" << std::endl;
|
|
64
|
+ #endif
|
|
65
|
+
|
|
66
|
+ std::vector<Real> Trans = readinpfile(std::string(argv[1]));
|
|
67
|
+ std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
|
|
68
|
+ std::vector<Real> Points = readinpfile(std::string(argv[3]));
|
|
69
|
+ std::vector<std::string> config = readinpfile2(std::string(argv[4]));
|
|
70
|
+
|
|
71
|
+ //////////////////////////////////////
|
|
72
|
+ // Define transmitter
|
|
73
|
+ auto trans = PolygonalWireAntenna::NewSP();
|
|
74
|
+ trans->SetNumberOfPoints((int)(Trans[0]));
|
|
75
|
+ int ip=1;
|
|
76
|
+ for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
|
|
77
|
+ trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
|
|
78
|
+ }
|
|
79
|
+ trans->SetNumberOfFrequencies(1);
|
|
80
|
+ trans->SetFrequency(0, Trans[ip]);
|
|
81
|
+ trans->SetCurrent(Trans[ip+1]);
|
|
82
|
+ trans->SetMinDipoleRatio(atof(config[1].c_str()));
|
|
83
|
+ trans->SetMinDipoleMoment(atof(config[2].c_str()));
|
|
84
|
+ trans->SetMaxDipoleMoment(atof(config[3].c_str()));
|
|
85
|
+
|
|
86
|
+ /////////////////////////////////////
|
|
87
|
+ // Field calculations
|
|
88
|
+ auto receivers = FieldPoints::NewSP();
|
|
89
|
+ int nx = (int)Points[0];
|
|
90
|
+ int ny = (int)Points[1];
|
|
91
|
+ int nz = (int)Points[2];
|
|
92
|
+ Real ox = Points[3];
|
|
93
|
+ Real oy = Points[4];
|
|
94
|
+ Real oz = Points[5];
|
|
95
|
+ Vector3r loc;
|
|
96
|
+ VectorXr dx(nx-1);
|
|
97
|
+ VectorXr dy(ny-1);
|
|
98
|
+ VectorXr dz(nz-1);
|
|
99
|
+ ip = 6;
|
|
100
|
+ int ir = 0;
|
|
101
|
+ for ( ; ip <6+nx-1; ++ip) {
|
|
102
|
+ dx[ir] = Points[ip];
|
|
103
|
+ ++ir;
|
|
104
|
+ }
|
|
105
|
+ ir = 0;
|
|
106
|
+ for ( ; ip <6+ny-1+nx-1; ++ip) {
|
|
107
|
+ dy[ir] = Points[ip];
|
|
108
|
+ ++ir;
|
|
109
|
+ }
|
|
110
|
+ ir = 0;
|
|
111
|
+ for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
|
|
112
|
+ dz[ir] = Points[ip];
|
|
113
|
+ ++ir;
|
|
114
|
+ }
|
|
115
|
+ receivers->SetNumberOfPoints(nx*ny*nz);
|
|
116
|
+ ir = 0;
|
|
117
|
+ Real pz = oz;
|
|
118
|
+ for (int iz=0; iz<nz; ++iz) {
|
|
119
|
+ Real py = oy;
|
|
120
|
+ for (int iy=0; iy<ny; ++iy) {
|
|
121
|
+ Real px = ox;
|
|
122
|
+ for (int ix=0; ix<nx; ++ix) {
|
|
123
|
+ loc << px, py, pz;
|
|
124
|
+ receivers->SetLocation(ir, loc);
|
|
125
|
+ if (ix < nx-1) px += dx[ix];
|
|
126
|
+ ++ ir;
|
|
127
|
+ }
|
|
128
|
+ if (iy<ny-1) py += dy[iy];
|
|
129
|
+ }
|
|
130
|
+ if (iz<nz-1) pz += dz[iz];
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ ////////////////////////////////////
|
|
134
|
+ // Define model
|
|
135
|
+ auto earth = LayeredEarthEM::NewSP();
|
|
136
|
+ VectorXcr sigma;
|
|
137
|
+ VectorXr thick;
|
|
138
|
+ earth->SetNumberOfLayers(CondMod[0]+1);
|
|
139
|
+ sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
|
|
140
|
+ thick.resize(CondMod[0]-1);
|
|
141
|
+ int ilay=1;
|
|
142
|
+ for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
|
|
143
|
+ sigma(ilay/2+1) = 1./CondMod[ilay];
|
|
144
|
+ thick(ilay/2) = CondMod[ilay+1];
|
|
145
|
+ }
|
|
146
|
+ sigma(ilay/2+1) = 1./ CondMod[ilay];
|
|
147
|
+ earth->SetLayerConductivity(sigma);
|
|
148
|
+ if (thick.size() > 0) earth->SetLayerThickness(thick);
|
|
149
|
+
|
|
150
|
+ auto EmEarth = EMEarth1D::NewSP();
|
|
151
|
+ EmEarth->AttachWireAntenna(trans);
|
|
152
|
+ EmEarth->AttachLayeredEarthEM(earth);
|
|
153
|
+ EmEarth->AttachFieldPoints(receivers);
|
|
154
|
+ EmEarth->SetFieldsToCalculate(H);
|
|
155
|
+ EmEarth->SetHankelTransformMethod(string2Enum<HANKELTRANSFORMTYPE>(config[0]));
|
|
156
|
+ EmEarth->SetHankelTransformMethod(FHTKEY201);
|
|
157
|
+
|
|
158
|
+ ///////////////////////////////////////////////
|
|
159
|
+ // Keep track of time
|
|
160
|
+ jsw_timer timer;
|
|
161
|
+ timer.begin();
|
|
162
|
+ clock_t launch = clock();
|
|
163
|
+ EmEarth->CalculateWireAntennaFields(true); // true=status bar
|
|
164
|
+ Real paTime = timer.end();
|
|
165
|
+
|
|
166
|
+ std::cout << "\n\n===========================================\ncalc. real time: " << paTime/60. << "\t[m]\n";
|
|
167
|
+
|
|
168
|
+ std::cout << "calc. user time: " << (clock()-launch)/CLOCKS_PER_SEC/60. << "\t[CPU m]"
|
|
169
|
+ << std::endl;
|
|
170
|
+
|
|
171
|
+ ////////////////////////////////////
|
|
172
|
+ // Report
|
|
173
|
+ std::fstream hrep("hfield.yaml", std::ios::out);
|
|
174
|
+ std::fstream hreal("hfield.dat", std::ios::out);
|
|
175
|
+
|
|
176
|
+ hrep << *EmEarth << std::endl;
|
|
177
|
+ hrep.close();
|
|
178
|
+ //hreal << *trans << std::endl;
|
|
179
|
+ //hreal << *earth << std::endl;
|
|
180
|
+
|
|
181
|
+ hreal << "// Right hand coordinate system, z is positive down\n";
|
|
182
|
+ hreal << "// x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
|
|
183
|
+ hreal.precision(8);
|
|
184
|
+ int i=0;
|
|
185
|
+ for (int iz=0; iz<nz; ++iz) {
|
|
186
|
+ for (int iy=0; iy<ny; ++iy) {
|
|
187
|
+ for (int ix=0; ix<nx; ++ix) {
|
|
188
|
+ hreal << receivers->GetLocation(i).transpose() << "\t";
|
|
189
|
+ hreal << receivers->GetHfield(0, i).transpose() << "\n";
|
|
190
|
+ ++i;
|
|
191
|
+ }
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+ hreal.close();
|
|
195
|
+ // Clean up
|
|
196
|
+}
|
|
197
|
+
|
|
198
|
+std::vector<Real> readinpfile(const std::string& fname) {
|
|
199
|
+ std::string buf;
|
|
200
|
+ char dump[255];
|
|
201
|
+ std::vector<Real> vals;
|
|
202
|
+ std::fstream input(fname.c_str(), std::ios::in);
|
|
203
|
+ if (input.fail()) {
|
|
204
|
+ std::cerr << "Input file " << fname << " failed to open\n";
|
|
205
|
+ exit(EXIT_FAILURE);
|
|
206
|
+ }
|
|
207
|
+ while (input >> buf) {
|
|
208
|
+ if (buf.substr(0,2) == "//") {
|
|
209
|
+ input.getline(dump, 255);
|
|
210
|
+ } else {
|
|
211
|
+ vals.push_back( atof(buf.c_str() ));
|
|
212
|
+ }
|
|
213
|
+ }
|
|
214
|
+ return vals;
|
|
215
|
+}
|
|
216
|
+
|
|
217
|
+std::vector<std::string> readinpfile2(const std::string& fname) {
|
|
218
|
+ std::string buf;
|
|
219
|
+ char dump[255];
|
|
220
|
+ std::vector<std::string> vals;
|
|
221
|
+ std::fstream input(fname.c_str(), std::ios::in);
|
|
222
|
+ if (input.fail()) {
|
|
223
|
+ std::cerr << "Input file " << fname << " failed to open\n";
|
|
224
|
+ exit(EXIT_FAILURE);
|
|
225
|
+ }
|
|
226
|
+ while (input >> buf) {
|
|
227
|
+ if (buf.substr(0,2) == "//") {
|
|
228
|
+ input.getline(dump, 255);
|
|
229
|
+ } else {
|
|
230
|
+ vals.push_back( std::string(buf.c_str() ));
|
|
231
|
+ }
|
|
232
|
+ }
|
|
233
|
+ return vals;
|
|
234
|
+}
|