ソースを参照

Hantenna for WinDoze

lagkey
Trevor Irons 6年前
コミット
877e02b39f

+ 11
- 7
CMakeLists.txt ファイルの表示

@@ -24,11 +24,10 @@ set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMM
24 24
 ## Options--what do you want to do
25 25
 
26 26
 option ( BUILD_SHARED_LIBS      "Shared or static libraries"  OFF )
27
-#option ( CMAKE_BUILD_TYPE       "Debug Release"  "Release" )
28
-set(CMAKE_BUILD_TYPE "Release" CACHE STRING
29
-       "Choose the type of build, options are: Debug Release
30
-        RelWithDebInfo MinSizeRel."
31
-       FORCE)
27
+set(CMAKE_BUILD_TYPE "Release" STRING
28
+       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
29
+       FORCE cache)
30
+set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel )
32 31
  
33 32
 option ( LEMMA_ENABLE_TESTING       "Turn on unit testing" OFF )
34 33
 option ( LEMMA_BUILD_EXAMPLES       "Compile example Lemma applications" OFF )
@@ -253,7 +252,11 @@ if (LEMMA_USE_BOOST)
253 252
 	endif()
254 253
 	find_path( HAVE_BOOST_SPECIAL_FUNCTIONS "boost/math/special_functions.hpp" ) 
255 254
 	if(HAVE_BOOST_SPECIAL_FUNCTIONS)
256
-		add_compile_options(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
255
+		add_definitions(-DHAVE_BOOST_SPECIAL_FUNCTIONS)
256
+	endif()
257
+	find_path( HAVE_BOOST_PROGRESS "boost/progress.hpp" ) 
258
+	if(HAVE_BOOST_PROGRESS)
259
+		add_definitions(-DHAVE_BOOST_PROGRESS)
257 260
 	endif()
258 261
 endif()
259 262
 
@@ -267,12 +270,13 @@ if (LEMMA_USE_OPENMP)
267 270
         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
268 271
         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
269 272
         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
270
-        # 
273
+        add_definitions(-DLEMMAUSEOMP)
271 274
     else()
272 275
         find_package(OpenMP REQUIRED)
273 276
         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
274 277
         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
275 278
         set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
279
+        add_definitions(-DLEMMAUSEOMP)
276 280
     endif()
277 281
 endif()
278 282
 

+ 5
- 0
Modules/FDEM1D/examples/CMakeLists.txt ファイルの表示

@@ -18,10 +18,15 @@ add_executable( EMDipEarth1D EMDipEarth1D.cpp  )
18 18
 target_link_libraries(  EMDipEarth1D  "lemmacore" "fdem1d")
19 19
 set_property(TARGET EMDipEarth1D PROPERTY CXX_STANDARD 14)
20 20
 
21
+add_executable( Hantenna Hantenna.cpp  )
22
+target_link_libraries(  Hantenna  "lemmacore" "fdem1d")
23
+set_property(TARGET Hantenna PROPERTY CXX_STANDARD 14)
24
+
21 25
 INSTALL_TARGETS( "/share/FEM1D/"
22 26
 	LayeredEarthEM 
23 27
 	FieldPoints
24 28
 	PolygonalWireAntenna
25 29
 	EMDipEarth1D
26 30
     CircularLoop
31
+	Hantenna
27 32
 )

+ 234
- 0
Modules/FDEM1D/examples/Hantenna.cpp ファイルの表示

@@ -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
+}

+ 1
- 1
Modules/FDEM1D/include/EMEarth1D.h ファイルの表示

@@ -30,7 +30,7 @@
30 30
 #include "QWEKey.h"
31 31
 #include "CubicSplineInterpolator.h"
32 32
 
33
-#ifdef HAVEBOOSTPROGRESS
33
+#ifdef HAVE_BOOST_PROGRESS
34 34
 #include "boost/progress.hpp"
35 35
 #endif
36 36
 

+ 7
- 7
Modules/FDEM1D/src/EMEarth1D.cpp ファイルの表示

@@ -73,7 +73,7 @@ namespace Lemma {
73 73
     EMEarth1D::EMEarth1D( const ctor_key& key ) : LemmaObject( key ),
74 74
             Dipole(nullptr), Earth(nullptr), Receivers(nullptr), Antenna(nullptr),
75 75
             FieldsToCalculate(BOTH), HankelType(ANDERSON801), icalcinner(0), icalc(0)
76
-        //#ifdef HAVEBOOSTPROGRESS
76
+        //#ifdef HAVE_BOOST_PROGRESS
77 77
         //    , disp(0)
78 78
         //#endif
79 79
         {
@@ -191,7 +191,7 @@ namespace Lemma {
191 191
 
192 192
     void EMEarth1D::CalculateWireAntennaFields(bool progressbar) {
193 193
 
194
-        #ifdef HAVEBOOSTPROGRESS
194
+        #ifdef HAVE_BOOST_PROGRESS
195 195
         boost::progress_display *disp;
196 196
         #endif
197 197
 
@@ -263,7 +263,7 @@ namespace Lemma {
263 263
 
264 264
                 //std::cout << "freq parallel #1" << std::endl;
265 265
                 //** Progress display bar for long calculations */
266
-                #ifdef HAVEBOOSTPROGRESS
266
+                #ifdef HAVE_BOOST_PROGRESS
267 267
                 if (progressbar) {
268 268
                     disp = new boost::progress_display( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
269 269
                 }
@@ -327,7 +327,7 @@ namespace Lemma {
327 327
                         //std::cout << "Normal Path\n";
328 328
                         //std::cout << Receivers->GetHfield(0, irec) << std::endl;
329 329
                         //if (irec == 1) exit(0);
330
-                        #ifdef HAVEBOOSTPROGRESS
330
+                        #ifdef HAVE_BOOST_PROGRESS
331 331
                         if (progressbar) ++(*disp);
332 332
                         #endif
333 333
                     } // receiver loop
@@ -381,7 +381,7 @@ namespace Lemma {
381 381
                             } // frequency loop
382 382
                         } // OMP_PARALLEL BLOCK
383 383
                     } // mask loop
384
-                    #ifdef HAVEBOOSTPROGRESS
384
+                    #ifdef HAVE_BOOST_PROGRESS
385 385
                     //if (Receivers->GetNumberOfPoints() > 100) {
386 386
                     //    ++ disp;
387 387
                     //}
@@ -449,7 +449,7 @@ namespace Lemma {
449 449
                             } // frequency loop
450 450
                         } // OMP_PARALLEL BLOCK
451 451
                     } // mask loop
452
-                    #ifdef HAVEBOOSTPROGRESS
452
+                    #ifdef HAVE_BOOST_PROGRESS
453 453
                     //if (Receivers->GetNumberOfPoints() > 100) {
454 454
                     //    ++ disp;
455 455
                     //}
@@ -471,7 +471,7 @@ namespace Lemma {
471 471
             this->Dipole = nullptr;
472 472
         }
473 473
 
474
-        #ifdef HAVEBOOSTPROGRESS
474
+        #ifdef HAVE_BOOST_PROGRESS
475 475
         if (progressbar) {
476 476
             delete disp;
477 477
         }

読み込み中…
キャンセル
保存