Procházet zdrojové kódy

Moved LemmaCore into Modules, cleaned up build process and documentation.

enhancement_3
T-bone před 8 roky
rodič
revize
6dfc65b209
71 změnil soubory, kde provedl 7940 přidání a 37 odebrání
  1. 15
    24
      CMakeLists.txt
  2. 2
    1
      Documentation/Doxyfile.in
  3. 13
    11
      Modules/FDEM1D/CMakeLists.txt
  4. 1
    1
      Modules/FDEM1D/testing/CMakeLists.txt
  5. 39
    0
      Modules/LemmaCore/CMakeLists.txt
  6. 24
    0
      Modules/LemmaCore/LemmaCore.dox
  7. 33
    0
      Modules/LemmaCore/examples/CMakeLists.txt
  8. 52
    0
      Modules/LemmaCore/examples/filter.cpp
  9. 342
    0
      Modules/LemmaCore/examples/utORS.cpp
  10. 34
    0
      Modules/LemmaCore/examples/utQWEKey.cpp
  11. 86
    0
      Modules/LemmaCore/examples/utSerialize.cpp
  12. 31
    0
      Modules/LemmaCore/examples/utSkyTEM.cpp
  13. 197
    0
      Modules/LemmaCore/examples/utTEMSurvey.cpp
  14. 168
    0
      Modules/LemmaCore/examples/utXMLParse.cpp
  15. 67
    0
      Modules/LemmaCore/examples/utYAMLconfig.cpp
  16. 84
    0
      Modules/LemmaCore/examples/utgaussquad.cpp
  17. 258
    0
      Modules/LemmaCore/examples/utgmrprint.cpp
  18. 93
    0
      Modules/LemmaCore/examples/uthankel2.cpp
  19. 257
    0
      Modules/LemmaCore/examples/uthantenna.cpp
  20. 218
    0
      Modules/LemmaCore/examples/utlogbarriercg.cpp
  21. 67
    0
      Modules/LemmaCore/examples/utpolygonalantenna.cpp
  22. 68
    0
      Modules/LemmaCore/examples/utreadfemubc.cpp
  23. 54
    0
      Modules/LemmaCore/examples/utsandbox.cpp
  24. 199
    0
      Modules/LemmaCore/examples/uttemforward.cpp
  25. 131
    0
      Modules/LemmaCore/examples/utteminv1d.cpp
  26. 84
    0
      Modules/LemmaCore/examples/uttemreader.cpp
  27. 207
    0
      Modules/LemmaCore/examples/uttemsandbox.cpp
  28. 319
    0
      Modules/LemmaCore/examples/wireantenna.cpp
  29. 161
    0
      Modules/LemmaCore/include/ASCIIParser.h
  30. 195
    0
      Modules/LemmaCore/include/CubicSplineInterpolator.h
  31. 94
    0
      Modules/LemmaCore/include/Data.h
  32. 75
    0
      Modules/LemmaCore/include/DataReader.h
  33. 149
    0
      Modules/LemmaCore/include/EarthModel.h
  34. 71
    0
      Modules/LemmaCore/include/Filter.h
  35. 78
    0
      Modules/LemmaCore/include/Grid.h
  36. 84
    0
      Modules/LemmaCore/include/GridReader.h
  37. 71
    0
      Modules/LemmaCore/include/Instrument.h
  38. 174
    0
      Modules/LemmaCore/include/LayeredEarth.h
  39. 40
    0
      Modules/LemmaCore/include/LemmaCore
  40. 168
    0
      Modules/LemmaCore/include/LemmaObject.h
  41. 216
    0
      Modules/LemmaCore/include/RectilinearGrid.h
  42. 110
    0
      Modules/LemmaCore/include/RectilinearGridReader.h
  43. 124
    0
      Modules/LemmaCore/include/RectilinearGridVTKExporter.h
  44. 127
    0
      Modules/LemmaCore/include/WindowFilter.h
  45. 24
    0
      Modules/LemmaCore/include/banner.h
  46. 288
    0
      Modules/LemmaCore/include/helper.h
  47. 333
    0
      Modules/LemmaCore/include/lemma.h
  48. 82
    0
      Modules/LemmaCore/include/timer.h
  49. 238
    0
      Modules/LemmaCore/src/ASCIIParser.cpp
  50. 20
    0
      Modules/LemmaCore/src/CMakeLists.txt
  51. 355
    0
      Modules/LemmaCore/src/CubicSplineInterpolator.cpp
  52. 30
    0
      Modules/LemmaCore/src/Data.cpp
  53. 29
    0
      Modules/LemmaCore/src/DataReader.cpp
  54. 129
    0
      Modules/LemmaCore/src/EarthModel.cpp
  55. 22
    0
      Modules/LemmaCore/src/Filter.cpp
  56. 43
    0
      Modules/LemmaCore/src/Grid.cpp
  57. 29
    0
      Modules/LemmaCore/src/Instrument.cpp
  58. 130
    0
      Modules/LemmaCore/src/LayeredEarth.cpp
  59. 86
    0
      Modules/LemmaCore/src/LemmaObject.cpp
  60. 215
    0
      Modules/LemmaCore/src/RectilinearGrid.cpp
  61. 113
    0
      Modules/LemmaCore/src/RectilinearGridReader.cpp
  62. 147
    0
      Modules/LemmaCore/src/RectilinearGridVTKExporter.cpp
  63. 83
    0
      Modules/LemmaCore/src/WindowFilter.cpp
  64. 36
    0
      Modules/LemmaCore/src/banner.cpp
  65. 201
    0
      Modules/LemmaCore/src/helper.cpp
  66. 12
    0
      Modules/LemmaCore/testing/CMakeLists.txt
  67. 69
    0
      Modules/LemmaCore/testing/GetNameCheck.h
  68. 75
    0
      Modules/LemmaCore/testing/SerializeCheck.h
  69. 23
    0
      Modules/LemmaCore/testing/testOne.cpp
  70. 23
    0
      Modules/LemmaCore/testing/testTwo.cpp
  71. 25
    0
      config/LemmaConfig.h.in

+ 15
- 24
CMakeLists.txt Zobrazit soubor

@@ -70,7 +70,7 @@ ExternalProject_Add(YAML-CPP
70 70
 	UPDATE_COMMAND ""
71 71
 	PATCH_COMMAND ""
72 72
     PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/yaml-cpp
73
-    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=ON -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
73
+    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
74 74
 		-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
75 75
 )
76 76
 add_compile_options(-DHAVE_YAMLCPP) 
@@ -89,6 +89,8 @@ else()
89 89
 		BUILD_COMMAND ""
90 90
 		INSTALL_COMMAND ""
91 91
     	PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest
92
+    	CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
93
+			-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
92 94
 	)
93 95
 	set (CXXTEST_INCLUDE_DIR  "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/")
94 96
 	set (CXXTEST_PYTHON_TESTGEN_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/external/CxxTest/src/CxxTest/bin/cxxtestgen" )
@@ -104,8 +106,8 @@ if ( LEMMA_TINYXML_SUPPORT )
104 106
 		UPDATE_COMMAND ""
105 107
 		PATCH_COMMAND ""
106 108
     	PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/tinyxml2
107
-    	CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON 
108
-		#-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
109
+    	CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} /
110
+			-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
109 111
 	)
110 112
 	add_compile_options(-DTINYXMLSUPPORT) 
111 113
 endif()
@@ -138,7 +140,7 @@ if ( LEMMA_VTK6_SUPPORT )
138 140
 	include(${VTK_USE_FILE}) 
139 141
 	add_compile_options(-DLEMMAUSEVTK) 
140 142
 	# Compile Matplot_vtk if VTK is present
141
-	add_subdirectory(Matplot_vtk)	
143
+	#add_subdirectory(Matplot_vtk)	
142 144
 	include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
143 145
 endif()
144 146
 
@@ -152,7 +154,7 @@ if ( LEMMA_VTK7_SUPPORT )
152 154
 	include(${VTK_USE_FILE}) 
153 155
 	add_compile_options(-DLEMMAUSEVTK) 
154 156
 	# Compile Matplot_vtk if VTK is present
155
-	add_subdirectory(Matplot_vtk)	
157
+	#add_subdirectory(Matplot_vtk)	
156 158
 	include_directories ("${PROJECT_SOURCE_DIR}/Matplot_vtk")
157 159
 endif()
158 160
 
@@ -178,6 +180,8 @@ else()
178 180
 	message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 or C++14 support. Please use a different C++ compiler.")
179 181
 endif()
180 182
 
183
+option( LEMMA_BUILD_EXAMPLES "Compile example Lemma applications" OFF )
184
+
181 185
 option( LEMMA_USE_OPENMP  "Use OpenMP in Lemma" OFF)
182 186
 CHECK_CXX_COMPILER_FLAG(-fopenmp COMPILER_SUPPORTS_OPENMP)
183 187
 if(COMPILER_SUPPORTS_OPENMP AND LEMMA_USE_OPENMP )
@@ -190,42 +194,29 @@ set(LEMMA_VERSION_PATCH "1")
190 194
 set(LEMMA_VERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}")
191 195
 
192 196
 configure_file (
193
-	"${PROJECT_SOURCE_DIR}/include/LemmaConfig.h.in"
197
+	"${PROJECT_SOURCE_DIR}/config/LemmaConfig.h.in"
194 198
 	"${PROJECT_BINARY_DIR}/include/LemmaConfig.h"
195 199
 )
196
-include_directories("${PROJECT_BINARY_DIR}/include")
197
-
198
-include_directories ("${PROJECT_SOURCE_DIR}/LemmaCore/include")
199 200
 
201
+include_directories("${PROJECT_BINARY_DIR}/include")
200 202
 include_directories ("${CMAKE_INSTALL_PREFIX}/include/")
201 203
 link_directories ("${CMAKE_INSTALL_PREFIX}/lib/")
202 204
 
203
-
205
+#######################################################################
206
+# CXXTEST Framework
204 207
 if(CXXTEST_FOUND)
205 208
 	option (LEMMA_ENABLE_TESTING  "Turn on unit testing" ON)
206 209
 	if (LEMMA_ENABLE_TESTING)
207
-    include_directories(${CXXTEST_INCLUDE_DIR})
208
-    enable_testing()
209
-    #CXXTEST_ADD_TEST(tester_executable runner.cpp
210
-    #                    ${CMAKE_CURRENT_SOURCE_DIR}/src/myTestsuite.h)
211
-	#CXXTEST_ADD_TEST(unittest_foo foo_test.cc
212
-    #                  ${CMAKE_CURRENT_SOURCE_DIR}/src/myTestSuite.h)
213
-    #target_link_libraries(unittest_foo foo) # as needed
214
-#	else()
215
-#	message(FATAL_ERROR "CxxTest not found.")
210
+    	#include_directories(${CXXTEST_INCLUDE_DIR}) # Add this in testing CMakeLists.txt instead, cleaner
211
+    	enable_testing()
216 212
 	endif()
217 213
 endif()
218 214
 
219
-add_subdirectory (LemmaCore) 
220
-
221 215
 ########################################################################
222 216
 # Build Modules
223 217
 add_subdirectory (Modules) 
224 218
 
225 219
 ########################################################################
226
-# 
227
-include_directories(${CMAKE_INSTALL_PREFIX}/include)
228
-
229 220
 # add a target to generate API documentation with Doxygen
230 221
 # ALL make documentation build by default if possible
231 222
 find_package(Doxygen)

+ 2
- 1
Documentation/Doxyfile.in Zobrazit soubor

@@ -586,8 +586,9 @@ USE_MATHJAX = YES
586 586
 # with spaces.
587 587
 #INPUT                  = ./include ./Documentation/dox ./modules/Wavelet/include ./modules/Merlin/include ./modules/FEM4EllipticPDE/include ./modules/EMSchur3D/include
588 588
 #INPUT                  = @CMAKE_CURRENT_SOURCE_DIR@/LemmaCore/include @CMAKE_CURRENT_SOURCE_DIR@/Modules/FEM4EllipticPDE.git/include
589
-INPUT   = @CMAKE_CURRENT_SOURCE_DIR@/LemmaCore/include @CMAKE_CURRENT_SOURCE_DIR@/Modules/*/include
589
+INPUT   = @CMAKE_CURRENT_SOURCE_DIR@/Modules/*/include
590 590
 INPUT  += @CMAKE_CURRENT_SOURCE_DIR@/Modules/
591
+INPUT  += @CMAKE_CURRENT_SOURCE_DIR@/Documentation/dox
591 592
 
592 593
 # This tag can be used to specify the character encoding of the source files
593 594
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is

+ 13
- 11
Modules/FDEM1D/CMakeLists.txt Zobrazit soubor

@@ -1,24 +1,26 @@
1
-include_directories(${CMAKE_INSTALL_PREFIX}/include)
2
-
3
-include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )
4 1
 add_subdirectory("src")
5
-
6 2
 add_library( fdem1d ${FEM1DSOURCE} )  
7
-target_link_libraries(fdem1d "lemmacore")
3
+target_include_directories( fdem1d PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
4
+
8 5
 set_target_properties(fdem1d PROPERTIES 
9 6
 	VERSION  "${LEMMA_VERSION}"
10 7
 	SOVERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}"
11
-	PROJECT_LABEL "Lemma ${LABEL_SUFFIX}"
8
+	PROJECT_LABEL "FDEM1D ${LABEL_SUFFIX}"
12 9
 )
13 10
 
14
-install ( TARGETS fdem1d DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
11
+# Linking
12
+target_link_libraries(fdem1d "lemmacore")
15 13
 
16
-if (LEMMA_BUILD_EXAMPLES)
17
-	add_subdirectory(examples)
18
-endif()
19
-	
14
+# Testing
20 15
 if (LEMMA_ENABLE_TESTING)
21 16
 	add_subdirectory(testing)
22 17
 endif()
23 18
 
19
+# Install
24 20
 install ( TARGETS fdem1d DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
21
+
22
+# Examples
23
+if (LEMMA_BUILD_EXAMPLES)
24
+	add_subdirectory(examples)
25
+endif()
26
+	

+ 1
- 1
Modules/FDEM1D/testing/CMakeLists.txt Zobrazit soubor

@@ -1,3 +1,3 @@
1
-
1
+include_directories(${CXXTEST_INCLUDE_DIR})
2 2
 CXXTEST_ADD_TEST(unittestFEM1D_GetNameCheck GetNameCheck.cc ${CMAKE_CURRENT_SOURCE_DIR}/GetNameCheck.h)
3 3
 target_link_libraries(unittestFEM1D_GetNameCheck "lemmacore" "fdem1d")

+ 39
- 0
Modules/LemmaCore/CMakeLists.txt Zobrazit soubor

@@ -0,0 +1,39 @@
1
+add_subdirectory("src")
2
+add_library( lemmacore ${SOURCE} )  
3
+target_include_directories( lemmacore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
4
+
5
+set_target_properties(lemmacore PROPERTIES 
6
+	VERSION  "${LEMMA_VERSION}"
7
+	SOVERSION "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}"
8
+	PROJECT_LABEL "LemmaCore ${LABEL_SUFFIX}"
9
+)
10
+
11
+# External project dependencies 
12
+add_dependencies(lemmacore YAML-CPP)
13
+if (LEMMA_TINYXML_SUPPORT)
14
+	add_dependencies(lemmacore TINYXML2)
15
+endif()
16
+if (LEMMA_MATIO_SUPPORT)
17
+	add_dependencies(lemmacore MATIO)
18
+endif()
19
+
20
+# Linking
21
+if ( LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT ) 
22
+	target_link_libraries(lemmacore ${VTK_LIBRARIES})
23
+	target_link_libraries(lemmacore "matplot")
24
+endif()
25
+
26
+target_link_libraries(lemmacore "yaml-cpp")
27
+
28
+# Testing
29
+if (LEMMA_ENABLE_TESTING)
30
+	add_subdirectory(testing)
31
+endif()
32
+
33
+# Install
34
+install ( TARGETS lemmacore DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
35
+
36
+# Examples
37
+if (LEMMA_BUILD_EXAMPLES)
38
+	add_subdirectory(examples)
39
+endif()

+ 24
- 0
Modules/LemmaCore/LemmaCore.dox Zobrazit soubor

@@ -0,0 +1,24 @@
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      09/15/2016 04:28:16 PM
13
+ * @author    Trevor Irons (ti)
14
+ * @email     tirons@egi.utah.edu
15
+ * @copyright Copyright (c) 2016, University of Utah
16
+ * @copyright Copyright (c) 2016, Lemma Software, LLC
17
+ */
18
+
19
+/**
20
+    \defgroup LemmaCore LemmaCore
21
+    @brief    LemmaCore provides the general framework and skeleton for applications.
22
+    @details  This module is the glue holding Lemma together.
23
+*/
24
+

+ 33
- 0
Modules/LemmaCore/examples/CMakeLists.txt Zobrazit soubor

@@ -0,0 +1,33 @@
1
+#FILE(GLOB  examples  "*.cpp")
2
+
3
+#add_executable( datatem datatem.cpp )
4
+#target_link_libraries(datatem "lemmacore")
5
+
6
+#add_executable( wireantenna wireantenna.cpp )
7
+#target_link_libraries(wireantenna "lemmacore")
8
+
9
+#add_executable( DCIPElectrode  DCIPElectrode.cpp )
10
+#target_link_libraries(DCIPElectrode "lemmacore")
11
+
12
+#add_executable( digitalfiltercostrans  digitalfiltercostrans.cpp )
13
+#target_link_libraries(digitalfiltercostrans "lemmacore")
14
+
15
+#add_executable( dipolefreqsweep  dipolefreqsweep.cpp )
16
+#target_link_libraries(dipolefreqsweep "lemmacore")
17
+
18
+#add_executable( dipolesource  dipolesource.cpp )
19
+#target_link_libraries(dipolesource "lemmacore")
20
+
21
+#add_executable( edipole  edipole.cpp )
22
+#target_link_libraries(edipole "lemmacore")
23
+
24
+#add_executable( emdipearth1d  emdipearth1d.cpp )
25
+#target_link_libraries(emdipearth1d "lemmacore")
26
+
27
+#add_executable( femforward  femforward.cpp )
28
+#target_link_libraries(femforward "lemmacore")
29
+
30
+add_executable( filter  filter.cpp )
31
+target_link_libraries(filter "lemmacore")
32
+
33
+

+ 52
- 0
Modules/LemmaCore/examples/filter.cpp Zobrazit soubor

@@ -0,0 +1,52 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utfilter.cpp
4
+//
5
+//        Created:  07/20/2010 10:12:07 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @author   Trevor Irons
32
+  @date     07/20/2010
33
+  @version   0.0
34
+ **/
35
+
36
+#include "WindowFilter.h"
37
+using namespace Lemma;
38
+
39
+int main() {
40
+
41
+    auto Hamming = WindowFilter::NewSP();
42
+
43
+        Hamming->SetWindowType( HANNING );
44
+        Hamming->SetSamplingInterval(1e-4);
45
+        Hamming->SetBandwidth(300);
46
+        Hamming->SetNumberOfSamples(1./1e-4);
47
+
48
+    std::cout << Hamming->GetFilterCoefficients() //.transpose()
49
+              << std::endl;
50
+
51
+
52
+}

+ 342
- 0
Modules/LemmaCore/examples/utORS.cpp Zobrazit soubor

@@ -0,0 +1,342 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utdipolesource.cpp
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  12/02/2009 11:57:14 AM
9
+//       Revision:  none
10
+//       Compiler:  g++ (c++)
11
+//
12
+//         Author:  Trevor Irons (ti)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  United States Geological Survey (USGS)
16
+//
17
+//          Email:  tirons@mines.edu, tirons@usgs.gov
18
+//
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include <iostream>
35
+#include <fstream>
36
+
37
+#include "dipolesource.h"
38
+#include "layeredearth.h"
39
+#include "receiverpoints.h"
40
+#include "emearth1d.h"
41
+#include "WireAntenna.h"
42
+#include "PolygonalWireAntenna.h"
43
+
44
+#if  LEMMAUSEVTK
45
+#include "vtkRenderer.h"
46
+#include "vtkRenderWindow.h"
47
+#include "vtkRenderWindowInteractor.h"
48
+#include "vtkRenderLargeImage.h"
49
+#include "vtkPNGWriter.h"
50
+#include "vtkRectilinearGrid.h"
51
+#include "vtkXMLRectilinearGridWriter.h"
52
+#include "vtkDoubleArray.h"
53
+#include "vtkFieldData.h"
54
+#include "vtkCellData.h"
55
+#endif     // -----  not LEMMA_USE_VTK  -----
56
+
57
+// For testing purposes disable VTK and run scale.sh
58
+//#undef LEMMAUSEVTK
59
+
60
+#include "timer.h"
61
+
62
+using namespace Lemma;
63
+
64
+double randDouble(double low, double high) {
65
+	//srand(time(0));
66
+	double temp;
67
+	/* swap low & high around if the user makes no sense */
68
+	if (low > high)	{
69
+	temp = low;
70
+	low = high;
71
+	high = temp;
72
+	}
73
+	/* calculate the random number & return it */
74
+	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
75
+	* (high - low) + low;
76
+	return temp;
77
+}
78
+
79
+
80
+int main() {
81
+
82
+	// Keep track of time
83
+	jsw_timer timer;
84
+
85
+
86
+	srand(time(0));
87
+
88
+	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
89
+	pa->SetNumberOfFrequencies(1);
90
+	pa->SetFrequency(0, 540000);
91
+    Real Depth  =   370;  // nominal depth
92
+    Real Width  = 0.14;  // transmitter height
93
+    Real Height = 0.70;//  .14;  //.014;  // transmitter width
94
+
95
+
96
+	pa->SetNumberOfPoints(5);
97
+    /*
98
+    pa->SetPoint(0, Vector3r(       0,       0, Depth));
99
+	pa->SetPoint(1, Vector3r(       0,       0, Depth+Height));
100
+	pa->SetPoint(2, Vector3r(       0,   Width, Depth+Height));
101
+	pa->SetPoint(3, Vector3r(       0,   Width, Depth));
102
+	pa->SetPoint(4, Vector3r(       0,       0, Depth));
103
+    */
104
+
105
+    pa->SetPoint(0, Vector3r(   -Width/2., -Height/2., Depth));
106
+	pa->SetPoint(1, Vector3r(    Width/2., -Height/2., Depth));
107
+	pa->SetPoint(2, Vector3r(    Width/2.,  Height/2., Depth));
108
+	pa->SetPoint(3, Vector3r(   -Width/2.,  Height/2., Depth));
109
+	pa->SetPoint(4, Vector3r(   -Width/2., -Height/2., Depth));
110
+
111
+	pa->SetCurrent(1.);
112
+    pa->SetNumberOfTurns(6);
113
+	//Vector3r rp = Vector3r::Random(3);
114
+	//rp << 150., 10, 0.;
115
+	//rp << -27.1456, 15.2350, -1e-3;
116
+	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
117
+	//rp << 3.22806, -13.1548, 14.9695;
118
+	//rp.setRandom(3);
119
+	//std::cout <<  "rp " << rp.transpose() << std::endl;
120
+	//pa->ApproximateWithElectricDipoles(rp);
121
+
122
+
123
+	// Define model
124
+    Real Sigma = 1.0/20. ; // .05;
125
+	VectorXcr sigma(2);
126
+		sigma << Complex(0.,0), Complex(Sigma,0);
127
+	VectorXr  thick(1);
128
+		thick << 10;
129
+	LayeredEarthEM *earth = LayeredEarthEM::New();
130
+		earth->SetNumberOfLayers(2);
131
+		earth->SetLayerConductivity(sigma);
132
+		//earth->SetLayerThickness(thick);
133
+
134
+	// Receivers
135
+	ReceiverPoints *receivers = ReceiverPoints::New();
136
+		Vector3r loc;
137
+		Real ox    =    -5.*Width - .003373;
138
+		Real oy    =    -3.*Height - .003373;
139
+		Real oz    =    Depth - Height/2. - .003373;
140
+		int nx     =   120; // 60;
141
+		int ny     =   180; //  50;
142
+		int nz     =   100; // 40;
143
+		Real hx    =    11.*Width/nx;
144
+		Real hy    =     7.*Height/ny;
145
+		Real hz    =     1.*Height/nz;
146
+
147
+        receivers->SetNumberOfReceivers(nx*ny*nz);
148
+		int ir = 0;
149
+		for (int iz=0; iz<nz; ++iz) {
150
+		for (int iy=0; iy<ny; ++iy) {
151
+		for (int ix=0; ix<nx; ++ix) {
152
+			loc << ox+ix*hx, oy+iy*hy, oz+iz*hz;
153
+			receivers->SetLocation(ir, loc);
154
+			++ ir;
155
+		}
156
+        }
157
+        }
158
+
159
+	// EmEarth
160
+	EMEarth1D  *EmEarth = EMEarth1D::New();
161
+		//EmEarth->AttachWireAntenna(wire);
162
+		EmEarth->AttachWireAntenna(pa);
163
+		EmEarth->AttachLayeredEarthEM(earth);
164
+		EmEarth->AttachReceiverPoints(receivers);
165
+		EmEarth->SetFieldsToCalculate(E);
166
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
167
+        EmEarth->SetHankelTransformMethod(ANDERSON801);
168
+
169
+	// Do calculation
170
+	timer.begin();
171
+	EmEarth->CalculateWireAntennaFields();
172
+	Real paTime = timer.end();
173
+	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
174
+
175
+	//EmEarth->AttachWireAntenna(wire);
176
+	//timer.begin();
177
+	//EmEarth->CalculateWireAntennaFields();
178
+	//Real waTime = timer.end();
179
+	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
180
+/*
181
+	depth = depth2;
182
+	std::fstream real("reale_lay.dat", std::ios::out);
183
+	std::fstream imag("image_lay.dat", std::ios::out);
184
+	for (int iz=0; iz<nz; ++iz) {
185
+		Vector3cr temp = receivers->GetEfield(0,iz);
186
+		real << ox << "\t" << oy << "\t" << depth << "\t"
187
+				<< temp(0).real() << "\t" << temp(1).real()
188
+				<< "\t" << temp(2).real() << std::endl;
189
+		imag << ox << "\t" << oy << "\t" << depth << "\t"
190
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
191
+				<< "\t" << std::imag(temp(2)) << std::endl;
192
+		depth += dx;
193
+	}
194
+	real.close();
195
+	imag.close();
196
+*/
197
+
198
+	//wire->Delete();
199
+#if  LEMMAUSEVTK
200
+
201
+    // Set Coordinates
202
+    vtkDoubleArray *xCoords = vtkDoubleArray::New();
203
+    xCoords->InsertNextValue(ox-hx/2.);
204
+    double xm1 = ox-hx/2.;
205
+    for (int ix=0; ix<nx; ix++) {
206
+        xCoords->InsertNextValue(xm1 + hx);
207
+        xm1 += hx;
208
+    }
209
+
210
+    vtkDoubleArray *yCoords = vtkDoubleArray::New();
211
+    yCoords->InsertNextValue(oy-hy/2.);
212
+    double ym1 = oy-hy/2.;
213
+    for (int iy=0; iy<ny; iy++) {
214
+        yCoords->InsertNextValue(ym1 + hy);
215
+        ym1 += hy;
216
+    }
217
+
218
+    vtkDoubleArray *zCoords = vtkDoubleArray::New();
219
+    zCoords->InsertNextValue(oz-hz/2.);
220
+    double zm1 = oz-hz/2.;
221
+    for (int iz=0; iz<nz; iz++) {
222
+        zCoords->InsertNextValue(zm1 + hz);
223
+        zm1 += hz;
224
+    }
225
+
226
+    vtkDoubleArray *EReal = vtkDoubleArray::New();
227
+    vtkDoubleArray *EImag = vtkDoubleArray::New();
228
+    vtkDoubleArray *Watts = vtkDoubleArray::New();
229
+    EReal->SetNumberOfComponents(3);
230
+    EImag->SetNumberOfComponents(3);
231
+    Watts->SetNumberOfComponents(1);
232
+
233
+    ir = 0;
234
+    Real WattsTotal(0);
235
+    Real WattsInterior(0);
236
+    for (int iz=0; iz<nz; ++iz) {
237
+    for (int iy=0; iy<ny; ++iy) {
238
+    for (int ix=0; ix<nx; ++ix) {
239
+        //sigmaArray->InsertTuple1(i,  sigma[ix][iy][iz] );
240
+		Vector3cr E = receivers->GetEfield(0, ir);
241
+        EReal-> InsertTuple3(ir, real(E(0)), real(E(1)), real(E(2)));
242
+        EImag-> InsertTuple3(ir, imag(E(0)), imag(E(1)), imag(E(2)));
243
+        //std::cout << std::abs(ox+ix*hx) << "\t"  <<  Width/2. << endl; // && std::abs(oy+iy*hy) > Height/2. ) { // && std::abs(oz+iz*hz - Depth) > Width/2. ) {
244
+        //if ( std::abs( ox+ix*hx ) < Width/2. && std::abs(oy+iy*hy) < Height/2. && std::abs(oz+iz*hz - Depth) < Width/2. ) {
245
+        if ( std::sqrt( std::pow(ox+ix*hx,2)  + std::pow(oz+iz*hz - Depth, 2) ) < .085 && std::abs(oy+iy*hy) < Height/2. ) {
246
+            Watts-> InsertTuple1(ir,  1e-20 );
247
+            WattsInterior += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
248
+        } else {
249
+            Watts-> InsertTuple1(ir, .5* (pow( (std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
250
+            //Watts-> InsertTuple1(ir,  1e-20 );
251
+            WattsTotal += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
252
+        }
253
+		++ ir;
254
+    }
255
+    }
256
+    }
257
+    std::cout << "Total Power: " << Sigma << "\t" << WattsTotal << "\t" << WattsInterior << endl;
258
+
259
+    EReal->SetName("E_real");
260
+    EImag->SetName("E_imag");
261
+    Watts->SetName("Power");
262
+
263
+    vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
264
+        rgrid->SetDimensions(nx+1,ny+1,nz+1);
265
+        rgrid->SetXCoordinates(xCoords);
266
+        rgrid->SetYCoordinates(yCoords);
267
+        rgrid->SetZCoordinates(zCoords);
268
+
269
+        rgrid->GetCellData()->AddArray(EReal);
270
+        rgrid->GetCellData()->AddArray(EImag);
271
+        rgrid->GetCellData()->AddArray(Watts);
272
+        //rgrid->Update();
273
+
274
+    vtkXMLRectilinearGridWriter *gridWrite = vtkXMLRectilinearGridWriter::New();
275
+        gridWrite->SetInputData(rgrid);
276
+        gridWrite->SetFileName("ors.vtr");
277
+        gridWrite->Write();
278
+        //gridWrite->Update();
279
+
280
+#endif
281
+	EmEarth->Delete();
282
+	receivers->Delete();
283
+	earth->Delete();
284
+
285
+#if  LEMMAUSEVTKX
286
+	// Create the usual rendering stuff.
287
+	vtkRenderer           *renderer = vtkRenderer::New();
288
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
289
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
290
+
291
+	std::cout << "wire antennae approximating " << std::endl;
292
+	loc << 0, .5*Width, Depth+.5*Height;
293
+	pa->ApproximateWithElectricDipoles(loc);
294
+    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
295
+
296
+    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
297
+	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
298
+		pdipActors[id] = pa->GetVtkActor(id);
299
+		renderer->AddActor(pdipActors[id]);
300
+	}
301
+
302
+    /*
303
+    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
304
+	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
305
+		dipActors[id] = wire->GetVtkActor(id);
306
+		renderer->AddActor(dipActors[id]);
307
+	}
308
+    */
309
+
310
+	renderer->SetBackground(1,1,1);
311
+
312
+	// Render the window
313
+	renWin->AddRenderer(renderer);
314
+	renWin->SetWindowName("Wire antennae");
315
+
316
+	iren->SetRenderWindow(renWin);
317
+	iren->Initialize();
318
+	iren->Start();
319
+	iren->Render();
320
+
321
+    #if 0
322
+	cout << "Enter File name?: ";
323
+	std::string pngName;
324
+	std::cin >> pngName;
325
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
326
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
327
+	renlarge->SetInput(renderer);
328
+	renlarge->SetMagnification(2);
329
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
330
+	pngName.append(".png");
331
+	pngwrite->SetFileName(pngName.c_str());
332
+	pngwrite->Write();
333
+    #endif
334
+
335
+#endif     // -----  not LEMMA_USE_VTK  -----
336
+
337
+
338
+	//std::cout << *pa << std::endl;
339
+	//pa->Delete();
340
+
341
+	return 0;
342
+}

+ 34
- 0
Modules/LemmaCore/examples/utQWEKey.cpp Zobrazit soubor

@@ -0,0 +1,34 @@
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      02/12/2014 01:01:29 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "QWEKey.h"
21
+using namespace Lemma;
22
+
23
+int main() {
24
+
25
+    // TODO chech
26
+
27
+    QWEKey* QWE = QWEKey::New();
28
+    QWE->TestPrivate( 5 );
29
+    QWE->Delete();
30
+
31
+    return 0;
32
+}
33
+
34
+

+ 86
- 0
Modules/LemmaCore/examples/utSerialize.cpp Zobrazit soubor

@@ -0,0 +1,86 @@
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      09/29/2014 01:31:26 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+
22
+using namespace Lemma;
23
+
24
+#ifdef  HAVE_YAMLCPP
25
+#include "yaml-cpp/yaml.h"
26
+
27
+int main() {
28
+
29
+    std::ofstream ofstr("output.yaml");
30
+    //ofstr << "%YAML 1.2\n" << "---\n";
31
+    //ofstr << "LEMMA_CLASSES:\n";
32
+
33
+    // This works for individual classes or even groups of unrelated classes. But
34
+    // How should references work? One option would be to hack YAML and allow for references
35
+    // across 'Docs'. This is maybe undesireable, as then it's not valid YAML anymore.
36
+    // OR we could have some other kind of IDENTIFIER that could be used and Connections could be
37
+    // made AFTER the whole file is processed?
38
+
39
+    // Alternative is each class is written to it's own file. And then implicit on the Serialize function, the file tags are written
40
+    // into the YAML instead of the pointer. Alternatively, tags could do this too.
41
+
42
+    // Or file could be saved as pointer.yaml
43
+
44
+    // *
45
+    // * Or a file contains all the subclasses it point to. So that it's self-enclosed. This is nice as it's quite
46
+    // * flexible. The only downwside is possible repeat of classes. Basically if the API is careful though, only 1
47
+    // * instance will need to be serialized.
48
+    // *
49
+
50
+
51
+    TEMTransmitter* Seq = TEMTransmitter::New();
52
+        Seq->SetRepFrequency( 20, KHZ );
53
+        VectorXr Times (18);
54
+        VectorXr Amps (18);
55
+        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
56
+                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
57
+        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
58
+                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
59
+        Seq->SetWaveform(Times, Amps, MILLISEC);
60
+    // OK dump to disk
61
+    ofstr << *Seq ;
62
+    ofstr.close();
63
+    Seq->Delete();
64
+
65
+
66
+    // OK now load
67
+    std::ifstream ifstr("output.yaml");
68
+    std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
69
+
70
+    TEMTransmitter* Seq2 = TEMTransmitter::DeSerialize( nodes[0] );
71
+    std::cout << "Loaded\n" << *Seq2;
72
+    Seq2->Delete();
73
+    ifstr.close();
74
+
75
+    //YAML::Node nodes = YAML::LoadFile("output.yaml");
76
+    //std::cout << nodes[0] << std::endl;
77
+    //std::cout << nodes[1] << std::endl;
78
+
79
+    exit(EXIT_SUCCESS);
80
+}
81
+
82
+#else
83
+int main() {
84
+
85
+}
86
+#endif

+ 31
- 0
Modules/LemmaCore/examples/utSkyTEM.cpp Zobrazit soubor

@@ -0,0 +1,31 @@
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      02/27/2015 11:02:43 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2015, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2015, Trevor Irons
18
+ */
19
+
20
+// SkyTEM forward modelling programme
21
+
22
+#include "TEMSurvey.h"
23
+
24
+int main() {
25
+
26
+    std::cout << "SkyTEM modelling\n";
27
+
28
+
29
+
30
+}
31
+

+ 197
- 0
Modules/LemmaCore/examples/utTEMSurvey.cpp Zobrazit soubor

@@ -0,0 +1,197 @@
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      10/06/2014 10:37:30 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+using namespace Lemma;
22
+
23
+int main() {
24
+
25
+    // Each pulse sequence functions as an autonomous transmitter. A record may contain multiple transmitters (moments).
26
+    // There is some small overhead for wire loop locations, but generality is retained doing this, as well as monitoring of
27
+    // slight changes in geometry for both pulses.
28
+    TEMTransmitter* TxHM = TEMTransmitter::New();
29
+        TxHM->SetRepFrequency( 20, KHZ );
30
+        VectorXr Times (18);
31
+        VectorXr Amps (18);
32
+        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
33
+                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
34
+        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
35
+                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
36
+        TxHM->SetWaveform( Times, Amps, MILLISEC );
37
+        // Define wire loop
38
+        TxHM->SetNumberOfPoints(8);
39
+        TxHM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
40
+        TxHM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
41
+        TxHM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
42
+        TxHM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
43
+        TxHM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
44
+        TxHM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
45
+        TxHM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
46
+        TxHM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
47
+        TxHM->SetNumberOfTurns(8);
48
+
49
+    // Each Transmitter needs its own `Receiver(s)', the only difference may be the time gates, but that's OK.
50
+    //     It's a minor amount of overhead for greatly improved genearality. As sometimes different gates are
51
+    //     masked.
52
+    TEMInductiveReceiver* RxHM = TEMInductiveReceiver::New();
53
+        RxHM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
54
+        RxHM->SetMoment( 1 );                  // Normalized
55
+        RxHM->SetReferenceTime( 4., MILLISEC );
56
+        RxHM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
57
+
58
+        // Gate Centres  ms
59
+        VectorXr centres (37);
60
+        centres << 7.15000000e-04,   2.21500000e-03,   4.21500000e-03,   6.21500000e-03,
61
+                   8.21500000e-03,   1.02150000e-02,   1.22150000e-02,   1.47150000e-02,
62
+                   1.82150000e-02,   2.27150000e-02,   2.82150000e-02,   3.52150000e-02,
63
+                   4.42150000e-02,   5.57150000e-02,   7.02150000e-02,   8.82150000e-02,
64
+                   1.10715000e-01,   1.38715000e-01,   1.74215000e-01,   2.19715000e-01,
65
+                   2.76715000e-01,   3.48715000e-01,   4.39715000e-01,   5.53715000e-01,
66
+                   6.97715000e-01,   8.79215000e-01,   1.10771500e+00,   1.39621500e+00,
67
+                   1.76021500e+00,   2.21871500e+00,   2.79671500e+00,   3.52571500e+00,
68
+                   4.44471500e+00,   5.60321500e+00,   7.06321500e+00,   8.90421500e+00,
69
+                   1.10667200e+01;
70
+        //centres.array() += 4.;
71
+
72
+        // Gate Widths  ms
73
+        VectorXr widths (37);
74
+        widths <<   4.30000000e-04,   1.43000000e-03,   3.43000000e-03,   5.43000000e-03,
75
+                    7.43000000e-03,   9.43000000e-03,   1.14300000e-02,   1.34300000e-02,
76
+                    1.64300000e-02,   2.04300000e-02,   2.54300000e-02,   3.14300000e-02,
77
+                    3.94300000e-02,   4.94300000e-02,   6.24300000e-02,   7.84300000e-02,
78
+                    9.84300000e-02,   1.23430000e-01,   1.54430000e-01,   1.94430000e-01,
79
+                    2.45430000e-01,   3.08430000e-01,   3.89430000e-01,   4.90430000e-01,
80
+                    6.17430000e-01,   7.78430000e-01,   9.80430000e-01,   1.23543000e+00,
81
+                    1.55743000e+00,   1.96343000e+00,   2.47443000e+00,   3.11943000e+00,
82
+                    3.93243000e+00,   4.95743000e+00,   6.24943000e+00,   7.87743000e+00,
83
+                    9.93143000e+00;
84
+
85
+        RxHM->SetWindows(centres, widths, MILLISEC);
86
+
87
+    TEMTransmitter* TxLM = TEMTransmitter::New();
88
+        TxLM->SetRepFrequency( 20, KHZ );
89
+        VectorXr TimesLM (18);
90
+        VectorXr AmpsLM (18);
91
+
92
+        TimesLM << -8.00000E-004, -7.86965E-004, -7.66493E-004, -7.23688E-004,
93
+                   -6.39938E-004, -5.16174E-004, -3.93340E-004, -2.63993E-004,
94
+                   -1.43952E-004, -7.15990E-006, -2.50712E-006,  0.00000E+000,
95
+                    2.19597E-007,  1.47193E-006,  3.34398E-006,  4.68669E-006,
96
+                    5.96484E-006,  7.04934E-006;
97
+        TimesLM.array() = TimesLM.array() + 8e-4;  // Valgrind Hack += yields error. Correct for SkyTEM convention
98
+
99
+
100
+        AmpsLM <<  0.00000E+000,  3.67188E-002,  6.17188E-002,  1.17969E-001,
101
+                   2.14844E-001,  3.28906E-001,	 4.75781E-001,  6.30469E-001,
102
+                   7.82031E-001,  9.92969E-001,	 1.00000E+000,  1.00000E+000,
103
+                   9.63459E-001,  6.01030E-001,  2.29652E-001,  8.64702E-002,
104
+                   2.53196E-002,  0.00000E+000;
105
+        AmpsLM.array() = AmpsLM.array() * 8.;   // Also correct for SkyTEM convention in .geo file
106
+
107
+        TxLM->SetWaveform( TimesLM, AmpsLM, SEC );
108
+        // Define wire loop
109
+        TxLM->SetNumberOfPoints(8);
110
+        TxLM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
111
+        TxLM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
112
+        TxLM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
113
+        TxLM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
114
+        TxLM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
115
+        TxLM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
116
+        TxLM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
117
+        TxLM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
118
+        TxLM->SetNumberOfTurns(8);
119
+
120
+
121
+    TEMInductiveReceiver* RxLM = TEMInductiveReceiver::New();
122
+        RxLM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
123
+        RxLM->SetMoment( 1 );                  // Normalized
124
+        RxLM->SetReferenceTime( 8e-4, SEC );
125
+        RxLM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
126
+
127
+        // Gate Centres  ms
128
+        VectorXr centresLM (26);
129
+            centresLM << 7.150000E-07, 2.215000E-06, 4.215000E-06, 6.215000E-06, 8.215000E-06,
130
+                         1.021500E-05, 1.221500E-05, 1.471500E-05, 1.821500E-05, 2.271500E-05,
131
+                         2.821500E-05, 3.521500E-05, 4.421500E-05, 5.571500E-05, 7.021500E-05,
132
+                         8.821500E-05, 1.107150E-04, 1.387150E-04, 1.742150E-04, 2.197150E-04,
133
+                         2.767150E-04, 3.487150E-04, 4.397150E-04, 5.537150E-04, 6.977150E-04,
134
+                         8.792150E-04;
135
+
136
+        VectorXr widthsLM (26);
137
+            widthsLM << 5.700000E-07, 1.570000E-06, 1.570000E-06, 1.570000E-06, 1.570000E-06,
138
+                        1.570000E-06, 1.570000E-06, 2.570000E-06, 3.570000E-06, 4.570000E-06,
139
+                        5.570000E-06, 7.570000E-06, 9.570000E-06, 1.257000E-05, 1.557000E-05,
140
+                        1.957000E-05, 2.457000E-05, 3.057000E-05, 3.957000E-05, 5.057000E-05,
141
+                        6.257000E-05, 8.057000E-05, 1.005700E-04, 1.265700E-04, 1.605700E-04,
142
+                        2.015700E-04;
143
+
144
+        RxLM->SetWindows(centresLM, widthsLM, SEC);
145
+
146
+
147
+
148
+    // Specifies survey, this is the Glue Class, the top of the structure, etc.
149
+    TEMSurvey* Survey = TEMSurvey::New();
150
+        Survey->SetNumberOfLines(1);  // Flight lines or
151
+                                      // Internally each line is a class? But that's sort of hidden to the
152
+                                      // end user. Having each line seperate is nice for constrained inversion, where
153
+                                      // each line is a nice thing to deal with.
154
+        Survey->GetLine(0)->SetNumberOfRecords(1);    // Each Record then contains everything needed for modelling response curve(s)
155
+        Survey->GetLine(0)->GetRecord(0)->SetNumberOfPulseSequences( 1 );
156
+        Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 0, TxHM, RxHM );
157
+        //Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 1, TxHM, RxHM );
158
+
159
+
160
+    LayeredEarthEM* Earth = LayeredEarthEM::New();
161
+        Earth->SetNumberOfLayers(31);
162
+        Earth->SetLayerThickness( (VectorXr(29) <<  5.00E+00,  5.40E+00,
163
+             5.80E+00, 6.30E+00, 6.80E+00, 7.30E+00, 7.80E+00, 8.50E+00,
164
+             9.10E+00, 9.80E+00, 1.06E+01, 1.14E+01, 1.23E+01, 1.33E+01,
165
+             1.43E+01, 1.54E+01, 1.66E+01, 1.79E+01, 1.93E+01, 2.08E+01,
166
+             2.25E+01, 2.42E+01, 2.61E+01, 2.81E+01, 3.03E+01, 3.27E+01,
167
+             3.52E+01, 3.80E+01, 4.10E+01).finished() );
168
+
169
+        VectorXcr rho = ( (VectorXcr(31) << 0, 1.54E+01, 4.21E+01,
170
+            9.25E+01, 1.26E+02, 1.17E+02, 7.57E+01, 3.21E+01, 1.40E+01, 1.96E+01,
171
+            2.67E+01, 2.56E+01, 2.00E+01, 1.86E+01, 2.31E+01, 2.97E+01, 3.50E+01,
172
+            3.79E+01, 3.75E+01, 3.32E+01, 2.52E+01, 1.57E+01, 8.38E+00, 5.38E+00,
173
+            5.49E+00, 6.34E+00, 7.07E+00, 7.81E+00, 8.67E+00, 9.59E+00, 1.05E+01
174
+        ).finished() ); // 200 Ohm-m half space
175
+
176
+        Earth->SetLayerConductivity( 1./rho.array() );
177
+        // ALL SET UP
178
+        std::cout << *Survey << std::endl;
179
+
180
+        // OK do your thinc
181
+        //DataTEM* data =
182
+        Survey->ForwardModel( Earth );
183
+
184
+
185
+    // Clean up
186
+
187
+
188
+
189
+//     //Survey->Delete();
190
+//     Earth->Delete();
191
+//
192
+//     TxHM->Delete();
193
+//     RxHM->Delete();
194
+//     TxLM->Delete();
195
+//     RxLM->Delete();
196
+
197
+}

+ 168
- 0
Modules/LemmaCore/examples/utXMLParse.cpp Zobrazit soubor

@@ -0,0 +1,168 @@
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      04/03/2014 01:08:28 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+#ifdef TINYXMLSUPPORT
22
+#include "tinyxml2.h"
23
+
24
+#include <ctime>
25
+using namespace tinyxml2;
26
+using namespace Lemma;
27
+
28
+void ParseTEM( XMLElement* element );
29
+
30
+template <typename T>
31
+std::vector<T> ReadLine( const int& nr, const std::string& line ) ;
32
+
33
+int main(int argc, char **argv) {
34
+
35
+    if ( argc > 1 ) {
36
+		XMLDocument* doc = new XMLDocument();
37
+		clock_t startTime = clock();
38
+		doc->LoadFile( argv[1] );
39
+		clock_t loadTime = clock();
40
+		int errorID = doc->ErrorID();
41
+
42
+        // Get some info
43
+        //static const char* xml = "<element/>";
44
+        //doc->Parse( xml );
45
+        //XMLNode* titleElement = doc->FirstChild(); //Element()->FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" );
46
+        XMLElement* titleElement = doc->FirstChildElement( ); //->FirstChildElement( "TITLE" );
47
+        //const char* title = titleElement->Value(); //GetText();
48
+        const char* title = titleElement->Value(); //GetText();
49
+
50
+        printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
51
+        printf( "Name of FirstChildElement: %s\n", title );
52
+
53
+        if (strcmp ( titleElement->Value(), "NGXFile" ) != 0) {
54
+            std::cout <<"NGX file was not detected!" << std::endl;
55
+            exit(EXIT_FAILURE);
56
+        } else {
57
+            //std::cout <<
58
+            //titleElement->FirstAttribute() ;//"type");// << std::endl;;
59
+            if (strcmp(  titleElement->FindAttribute("type")->Value(),"tem") == 0) {
60
+                // Parse TEM file
61
+                ParseTEM( titleElement );
62
+            } else {
63
+                std::cout << "No parser for NGX filetype " << titleElement->FindAttribute("type")->Value() << std::endl;
64
+                std::cout << "YOU should write one!\n";
65
+                exit(EXIT_FAILURE);
66
+            }
67
+
68
+        }
69
+
70
+		delete doc; doc = 0;
71
+
72
+        clock_t deleteTime = clock();
73
+		if ( !errorID ) {
74
+			printf( "========================================================\n");
75
+			printf( "Load time=%u\n",   (unsigned)(loadTime - startTime) );
76
+			printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
77
+			printf( "Total time=%u\n",  (unsigned)(deleteTime - startTime) );
78
+		}
79
+
80
+
81
+		exit(0);
82
+	} else {
83
+        std::cout << "Enter NGX.x file to parse\n";
84
+    }
85
+}
86
+
87
+void ParseTEM( XMLElement* element ) {
88
+
89
+    std::cout << "This is a NGX.t file" << std::endl;
90
+
91
+
92
+    if (strcmp( element->FindAttribute("version")->Value(),"0.1") == 0) {
93
+        std::cout << "Version 0.1 detected" << std::endl;
94
+    } else {
95
+        std::cout << "Unsupported NGX.t version" << std::endl;
96
+    }
97
+
98
+    // system description
99
+    std::cout << "System description" << std::endl;
100
+    std::cout << element->FirstChildElement("system")->FirstChildElement("name")->GetText() << std::endl;
101
+    XMLElement* system = element->FirstChildElement("system");
102
+        int ntx = atoi(system->FirstChildElement("transmitters")->FindAttribute("num")->Value());
103
+        std::cout << "numTx = " << ntx << std::endl;
104
+        // OK Parse Transmitter(s)
105
+        XMLElement* tx = system->FirstChildElement("transmitters")->FirstChildElement("transmitter");
106
+        //    std::cout << "Tx id = " << tx->FindAttribute("id")->Value() << std::endl;
107
+        //std::cout << tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
108
+        //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
109
+        for (int it=0; it<ntx; ++it) {
110
+            std::cout << "\nTransmitter " << it << std::endl;
111
+            if (it > 0) tx = tx->NextSiblingElement();
112
+            int npoints = atoi(tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value());
113
+
114
+            std::cout << "points= " << npoints; // tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
115
+            std::vector<Real> LP = ReadLine<Real>( npoints, std::string(tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText()) );
116
+            for (int ii=0; ii<npoints; ++ii) std::cout << "\t"<< LP[ii] ;
117
+            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
118
+            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("easting.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
119
+        }
120
+    std::cout << "\nEND system description\n";
121
+
122
+}
123
+
124
+
125
+template <typename T>
126
+std::vector<T> ReadLine( const int& nr, const std::string& line ) {
127
+
128
+    std::vector<T>   lineData;
129
+    std::stringstream  lineStream(line);
130
+
131
+    T value;
132
+    while(lineStream >> value) {
133
+        lineData.push_back(value);
134
+    }
135
+    return lineData;
136
+}
137
+#else
138
+
139
+int main() {
140
+    std::cout << "you have to compile lemma with external tinyxml library to use this" << std::endl;
141
+}
142
+
143
+#endif
144
+
145
+    //--------------------------------------------------------------------------------------
146
+    //       Class:  ASCIIParser
147
+    //      Method:  ReadInts
148
+    //--------------------------------------------------------------------------------------
149
+//     std::vector<int> ReadInts ( const int& nr ) {
150
+//         std::string buf;
151
+//         char *dump = new char[BufferSize];
152
+//         std::vector<int> vals(0);
153
+//         while (input >> buf) {
154
+//             if (buf.substr(0, CommentString.size()) == CommentString) {
155
+//                 input.getline(dump, BufferSize);
156
+//             } else {
157
+//                 vals.push_back( atoi(buf.c_str() ));
158
+//             }
159
+//             if (static_cast<int>(vals.size()) == nr) {
160
+//                 delete [] dump;
161
+//                 return vals;
162
+//             }
163
+//
164
+//         }
165
+//         delete [] dump;
166
+//         return vals;
167
+//     }		// -----  end of method ASCIIParser::ReadInts  -----
168
+

+ 67
- 0
Modules/LemmaCore/examples/utYAMLconfig.cpp Zobrazit soubor

@@ -0,0 +1,67 @@
1
+#ifdef HAVE_YAMLCPP
2
+
3
+#include "yaml-cpp/yaml.h"
4
+#include "yaml-cpp/eventhandler.h"
5
+#include <fstream>
6
+#include <iostream>
7
+#include <vector>
8
+
9
+struct Params {
10
+	bool hasFile;
11
+	std::string fileName;
12
+};
13
+
14
+Params ParseArgs(int argc, char **argv) {
15
+	Params p;
16
+
17
+	std::vector<std::string> args(argv + 1, argv + argc);
18
+
19
+	return p;
20
+}
21
+
22
+class NullEventHandler: public YAML::EventHandler
23
+{
24
+public:
25
+	virtual void OnDocumentStart(const YAML::Mark&) {}
26
+	virtual void OnDocumentEnd() {}
27
+
28
+	virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
29
+	virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
30
+	virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
31
+
32
+	virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
33
+	virtual void OnSequenceEnd() {}
34
+
35
+	virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
36
+	virtual void OnMapEnd() {}
37
+};
38
+
39
+void parse(std::istream& input)
40
+{
41
+	try {
42
+		YAML::Node doc = YAML::Load(input);
43
+		std::cout << doc << "\n";
44
+	} catch(const YAML::Exception& e) {
45
+		std::cerr << e.what() << "\n";
46
+	}
47
+}
48
+
49
+int main(int argc, char **argv)
50
+{
51
+	Params p = ParseArgs(argc, argv);
52
+
53
+	if(argc > 1) {
54
+		std::ifstream fin;
55
+		fin.open(argv[1]);
56
+		parse(fin);
57
+	} else {
58
+		parse(std::cin);
59
+	}
60
+
61
+	return 0;
62
+}
63
+#else
64
+int main() {
65
+}
66
+#endif
67
+

+ 84
- 0
Modules/LemmaCore/examples/utgaussquad.cpp Zobrazit soubor

@@ -0,0 +1,84 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  utqaussquad.cpp
4
+// 
5
+//    Description:  Test for gaussian quadrature algorithm
6
+// 
7
+//        Version:  0.0
8
+//        Created:  10/05/2010 08:54:26 AM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Development, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
18
+// 
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "Lemma"
35
+using namespace Lemma;
36
+using namespace std;
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "matplot.h"
40
+using namespace matplot;
41
+#endif
42
+
43
+int main() {
44
+
45
+	int N = 600;
46
+	int upb = 5;
47
+	int lowb = -1;
48
+	VectorXr func(N);
49
+	VectorXr wx(N);
50
+	Real integrationres,actres;
51
+
52
+	gaussianquadrature *lgqw = gaussianquadrature::New();
53
+	lgqw->SetFreqs(N,upb,lowb);
54
+	lgqw->CalcAW();
55
+
56
+	wx=lgqw->GetAbscissae();
57
+	func=cos(wx.array());
58
+//	for (int ii=0;ii<N;++ii) {
59
+//		cout << wx(ii) << "  " << func(ii) << endl;
60
+//	}
61
+
62
+	lgqw->SetFunc(func);
63
+	lgqw->Integrate();
64
+	integrationres=lgqw->GetResult();
65
+
66
+	actres = -sin((Real)upb)+sin((Real)lowb);
67
+	
68
+	cout << "Gaussian Quadrature Result: " << integrationres << endl;
69
+	cout << "Actual Result: " << actres << endl;
70
+	
71
+		
72
+	//Plot things
73
+	#ifdef LEMMAUSEVTK
74
+	double colour1[3] = {0.0,0.0,1.0};
75
+
76
+	Plot2D_VTK p1("X", "Y", 800,600);
77
+	p1.plot(wx,func,colour1,".-");
78
+	p1.show();
79
+
80
+	#endif
81
+
82
+	return EXIT_SUCCESS;
83
+}
84
+

+ 258
- 0
Modules/LemmaCore/examples/utgmrprint.cpp Zobrazit soubor

@@ -0,0 +1,258 @@
1
+// ===========================================================================
2
+//   This file is distributed with Lemma,
3
+//
4
+//       Filename:  utsnmrinversion1d.cpp
5
+//
6
+//        Created:  10/07/2010 08:57:04 AM
7
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
8
+//
9
+//         Author:  Trevor Irons (ti)
10
+//
11
+//   Organisation:  Colorado School of Mines (CSM)
12
+//                  United States Geological Survey (USGS)
13
+//
14
+//          Email:  tirons@mines.edu, tirons@usgs.gov
15
+//
16
+//  This program is free software: you can redistribute it and/or modify
17
+//  it under the terms of the GNU General Public License as published by
18
+//  the Free Software Foundation, either version 3 of the License, or
19
+//  (at your option) any later version.
20
+//
21
+//  This program is distributed in the hope that it will be useful,
22
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+//  GNU General Public License for more details.
25
+//
26
+//  You should have received a copy of the GNU General Public License
27
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
+//
29
+// ===========================================================================
30
+
31
+/**
32
+  @file
33
+  @author   Trevor Irons
34
+  @date     10/07/2010
35
+  @version   0.0
36
+ **/
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "vtkRenderer.h"
40
+#include "vtkRenderWindow.h"
41
+#include "vtkRenderWindowInteractor.h"
42
+#include "vtkPNGWriter.h"
43
+#include "vtkRenderLargeImage.h"
44
+#endif
45
+
46
+#include "receiverpoints.h"
47
+#include "emearth1d.h"
48
+#include "PolygonalWireAntenna.h"
49
+
50
+using namespace Lemma;
51
+
52
+std::vector<Real>  readinpfile(const std::string& fname);
53
+
54
+int main(int argc, char** argv) {
55
+
56
+    std::cout <<
57
+    "\n"
58
+    << "hantenna - a programme for computing the h field from polygonal wire\n"
59
+    << "loop sources \n\n"
60
+    << "The following copyrights apply to this application:\n"
61
+    << "Copyright (C) 2009, 2010, 2011, 2012 Colorado School of Mines\n"
62
+    << "Copyright (C) 2009, 2010, 2011, 2012 Trevor Irons\n"
63
+    << "Copyright (C) 2011 Broken Spoke Development, LLC\n\n"
64
+    << "hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
65
+    << "More information may be found at https://lemmasoftware.org\n\n"
66
+    << "This program is free software: you can redistribute it and/or modify\n"
67
+    << "it under the terms of the GNU General Public License as published by\n"
68
+    << "the Free Software Foundation, either version 3 of the License, or\n"
69
+    << "(at your option) any later version.\n\n"
70
+
71
+    << "This program is distributed in the hope that it will be useful,\n"
72
+    << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
73
+    << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
74
+    << "GNU General Public License for more details.\n\n"
75
+
76
+    << "You should have received a copy of the GNU General Public License\n"
77
+    << "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n";
78
+
79
+    if (argc < 4) {
80
+        std::cout << "usage: hantenna.exe  trans.inp cond.inp points.inp \n";
81
+        exit(0);
82
+    }
83
+
84
+    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
85
+    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
86
+    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
87
+
88
+    //////////////////////////////////////
89
+    // Define transmitter
90
+    PolygonalWireAntenna* trans = PolygonalWireAntenna::New();
91
+        trans->SetNumberOfPoints((int)(Trans[0]));
92
+        int ip=1;
93
+        for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
94
+            trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
95
+        }
96
+ 	    trans->SetNumberOfFrequencies(1);
97
+ 	    trans->SetFrequency(0, Trans[ip]);
98
+        trans->SetCurrent(Trans[ip+1]);
99
+
100
+	// Receivers
101
+ 	ReceiverPoints *receivers = ReceiverPoints::New();
102
+        int nx = (int)Points[0];
103
+        int ny = (int)Points[1];
104
+        int nz = (int)Points[2];
105
+        Real ox = Points[3];
106
+        Real oy = Points[4];
107
+        Real oz = Points[5];
108
+     	Vector3r loc;
109
+        VectorXr dx(nx-1); // TODO map the dx, dy, dz vectors
110
+        VectorXr dy(ny-1);
111
+        VectorXr dz(nz-1);
112
+        ip = 6;
113
+        int ir = 0;
114
+        for ( ; ip <6+nx-1; ++ip) {
115
+            dx[ir] = Points[ip];
116
+            ++ir;
117
+        }
118
+        ir = 0;
119
+        for ( ; ip <6+ny-1+nx-1; ++ip) {
120
+            dy[ir] = Points[ip];
121
+            ++ir;
122
+        }
123
+        ir = 0;
124
+        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
125
+            dz[ir] = Points[ip];
126
+            ++ir;
127
+        }
128
+ 		receivers->SetNumberOfReceivers(nx*ny*nz);
129
+ 		ir = 0;
130
+        Real pz  = oz;
131
+ 		for (int iz=0; iz<nz; ++iz) {
132
+ 		    Real py    =  oy;
133
+ 		    for (int iy=0; iy<ny; ++iy) {
134
+ 		        Real px    =  ox;
135
+ 		        for (int ix=0; ix<nx; ++ix) {
136
+ 			        loc << px, py, pz;
137
+ 			        receivers->SetLocation(ir, loc);
138
+ 			        if (ix < nx-1) px += dx[ix];
139
+ 			        ++ ir;
140
+     	        }
141
+                if (iy<ny-1) py += dy[iy];
142
+            }
143
+            if (iz<nz-1) pz += dz[iz];
144
+        }
145
+
146
+    ////////////////////////////////////
147
+    // Define model
148
+    LayeredEarthEM *earth = LayeredEarthEM::New();
149
+    VectorXcr sigma;
150
+    VectorXr  thick;
151
+ 	earth->SetNumberOfLayers(CondMod[0]+1);
152
+ 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
153
+    thick.resize(CondMod[0]-1);
154
+    int ilay=1;
155
+    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
156
+        sigma(ilay/2+1) =  1./CondMod[ilay];
157
+        thick(ilay/2) =  CondMod[ilay+1];
158
+    }
159
+    sigma(ilay/2+1) = 1./ CondMod[ilay];
160
+	earth->SetLayerConductivity(sigma);
161
+    if (thick.size() > 0) earth->SetLayerThickness(thick);
162
+
163
+	EMEarth1D  *EmEarth = EMEarth1D::New();
164
+		EmEarth->AttachWireAntenna(trans);
165
+		EmEarth->AttachLayeredEarthEM(earth);
166
+		EmEarth->AttachReceiverPoints(receivers);
167
+		EmEarth->SetFieldsToCalculate(H);
168
+        EmEarth->CalculateWireAntennaFields();
169
+
170
+    #ifdef LEMMAUSEVTK
171
+	vtkRenderer           *renderer = vtkRenderer::New();
172
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
173
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
174
+    trans->ApproximateWithElectricDipoles( (VectorXr (3) << 0,0,0).finished() );
175
+	vtkActor **dipActors = new vtkActor*[trans->GetNumberOfDipoles()];
176
+	for (int id=0; id<trans->GetNumberOfDipoles(); ++id) {
177
+		dipActors[id] = trans->GetVtkActor(id);
178
+		renderer->AddActor(dipActors[id]);
179
+	}
180
+    vtkActor *hfield  = receivers->GetVtkGlyphActor (HFIELDREAL, 3, 1e2, 0);
181
+ 	vtkActor *hfieldi = receivers->GetVtkGlyphActor (HFIELDIMAG, 3, 1e2, 0);
182
+    hfieldi->GetProperty()->SetColor(1,0,1);
183
+ 	hfield->GetProperty()->SetColor(0,1,0);
184
+ 	renderer->AddActor(hfield);
185
+ 	renderer->AddActor(hfieldi);
186
+	renderer->SetBackground(0,0,0);
187
+	// Render the window
188
+	renWin->AddRenderer(renderer);
189
+	iren->SetRenderWindow(renWin);
190
+	iren->Initialize();
191
+	iren->Start();
192
+	iren->Render();
193
+	cout << "Enter File name?: ";
194
+	std::string pngName;
195
+	std::cin >> pngName;
196
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
197
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
198
+	renlarge->SetInput(renderer);
199
+	renlarge->SetMagnification(2);
200
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
201
+	pngName.append(".png");
202
+	pngwrite->SetFileName(pngName.c_str());
203
+	pngwrite->Write();
204
+	iren->Delete();
205
+	renWin->Delete();
206
+	renderer->Delete();
207
+    #endif
208
+
209
+    ////////////////////////////////////
210
+    // Report
211
+ 	std::fstream hreal("hfield.dat", std::ios::out);
212
+    hreal << *trans << std::endl;
213
+    hreal << *earth << std::endl;
214
+    hreal << "Right hand coordinate system, z is positive down\n";
215
+    hreal << "x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
216
+    hreal.precision(8);
217
+    int i=0;
218
+	for (int iz=0; iz<nz; ++iz) {
219
+	for (int iy=0; iy<ny; ++iy) {
220
+	for (int ix=0; ix<nx; ++ix) {
221
+        hreal << receivers->GetLocation(i).transpose() << "\t";
222
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[0]) << "\t";
223
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[0]) << "\t";
224
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[1]) << "\t";
225
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[1]) << "\t";
226
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[2]) << "\t";
227
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[2]) << "\n";
228
+        ++i;
229
+    }
230
+    }
231
+    }
232
+    hreal.close();
233
+
234
+    // Clean up
235
+    EmEarth->Delete();
236
+    earth->Delete();
237
+    receivers->Delete();
238
+    trans->Delete();
239
+}
240
+
241
+std::vector<Real>  readinpfile(const std::string& fname) {
242
+    std::string buf;
243
+    char dump[255];
244
+    std::vector<Real> vals;
245
+    std::fstream input(fname.c_str(), std::ios::in);
246
+    if (input.fail()) {
247
+        std::cerr << "Input file " << fname << " failed to open\n";
248
+        exit(EXIT_FAILURE);
249
+    }
250
+    while (input >> buf) {
251
+        if (buf.substr(0,2) == "//") {
252
+            input.getline(dump, 255);
253
+        } else {
254
+            vals.push_back( atof(buf.c_str() ));
255
+        }
256
+    }
257
+    return vals;
258
+}

+ 93
- 0
Modules/LemmaCore/examples/uthankel2.cpp Zobrazit soubor

@@ -0,0 +1,93 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uthankel2.cpp
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  05/14/2010 10:26:59 AM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  Trevor Irons (ti)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  United States Geological Survey (USGS)
16
+//
17
+//          Email:  tirons@mines.edu, tirons@usgs.gov
18
+//
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "hankeltransformhankel2.h"
35
+#include "hankeltransformgaussianquadrature.h"
36
+#include "kernelem1d.h"
37
+#include "layeredearthem.h"
38
+
39
+using namespace Lemma;
40
+
41
+int main() {
42
+
43
+	// Define model
44
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
45
+		VectorXcr sigma(3);
46
+		sigma << 0., .1, 0.01;
47
+		VectorXr  thick(1);
48
+		thick << 10;
49
+		Earth->SetNumberOfLayers(3);
50
+		Earth->SetLayerConductivity(sigma);
51
+		Earth->SetLayerThickness(thick);
52
+
53
+	// Source
54
+	// Test with a single dipole
55
+	DipoleSource *dipole = DipoleSource::New();
56
+		dipole->SetMoment(2);
57
+		dipole->SetType(MAGNETICDIPOLE);
58
+		dipole->SetPolarisation(ZPOLARISATION);
59
+		dipole->SetLocation(0,0,0);
60
+		dipole->SetNumberOfFrequencies(1);
61
+		dipole->SetFrequency(0,1000);
62
+		dipole->SetPhase(0);
63
+
64
+	KernelEm1D *Kernel = KernelEm1D::New();
65
+		Kernel->Initialise(Earth);
66
+		Kernel->SetUpSource(dipole, 0);
67
+		Kernel->SetUpReceiver(-0.4);
68
+    //std::vector< KernelEm1DBase* > KernelVec;
69
+    //    KernelVec.push_back( )
70
+
71
+	std::cout.precision(10);
72
+
73
+	Hankel2 *dig = Hankel2::New();
74
+//         dig->ComputeRelated(.23 , Kernel);
75
+//  		std::cout << "  dig->Zgauss "
76
+//  				  << dig->Zgauss(0, TE, 0, 100.,
77
+//  								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
78
+//  			      << std::endl;
79
+
80
+// 	HankelTransformGaussianQuadrature *gauss =
81
+// 			HankelTransformGaussianQuadrature::New();
82
+// 		std::cout << "gauss->Zgauss "
83
+// 				  << gauss->Zgauss(0, TE, 0, 100.,
84
+// 								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
85
+// 			      << std::endl;
86
+
87
+	Earth->Delete();
88
+	dig->Delete();
89
+	//gauss->Delete();
90
+    dipole->Delete();
91
+	Kernel->Delete();
92
+	return EXIT_SUCCESS;
93
+}

+ 257
- 0
Modules/LemmaCore/examples/uthantenna.cpp Zobrazit soubor

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

+ 218
- 0
Modules/LemmaCore/examples/utlogbarriercg.cpp Zobrazit soubor

@@ -0,0 +1,218 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utlogbarriercg.cpp
4
+//
5
+//        Created:  12/29/2010 09:40:23 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     12/29/2010
34
+  @version   0.0
35
+ **/
36
+
37
+#include "LemmaObject.h"
38
+//#include "logbarriercg.h"
39
+//#include "datasnmr.h"
40
+#include <ctime>
41
+
42
+#ifdef HAVEBOOSTRANDOM
43
+#include <boost/random.hpp>
44
+#include <boost/random/normal_distribution.hpp>
45
+#endif
46
+
47
+using namespace std;
48
+using namespace Lemma;
49
+
50
+MatrixXr BuildG(const Real& T2, const Real& Larmor, const Real& T,
51
+        const Real& dt, const VectorXr& nT2Bins, const Real& scale);
52
+
53
+MatrixXr BuildGw(const Real& T2, const Real& Larmor, const Real& T,
54
+        const Real& dt, const VectorXr& nT2Bins, const Real& scale,
55
+        const VectorXr& freqs);
56
+
57
+/// test driver program for log-barrier optimization algorithm
58
+int main() {
59
+    return 0;
60
+}
61
+
62
+#ifdef AA
63
+    // Parameters
64
+    Real T2(.200);
65
+    Real Larmor(2000); // Hz
66
+    Real wL = 2.*PI * Larmor;
67
+    Real T(.6);
68
+    Real dt(1e-4);
69
+    int  nT2(20);
70
+    Real T2Low(.020);
71
+    Real T2Hi(.220);
72
+
73
+    // T2 bins
74
+    VectorXr T2Bins = VectorXr::LinSpaced(nT2, T2Low, T2Hi);
75
+
76
+    // Build true model
77
+    VectorXr m = VectorXr::Zero(T2Bins.size());
78
+    //m[4]  = .15;
79
+    //m[5]  = .15;
80
+    //m[6]  = .15;
81
+    m[7]  = .15;
82
+    m[8]  = .15;
83
+    m[11] = .15;
84
+    m[12] = .15;
85
+    m[13] = .15;
86
+    m[14] = .15;
87
+
88
+    // Build G
89
+    srand ( std::time(NULL) );
90
+    Real scale = 1e-4*std::abs(VectorXr::Random(1)[0]);
91
+    MatrixXr G = BuildG(T2, wL, T, dt, T2Bins, scale);
92
+
93
+    #ifdef HAVEBOOSTRANDOM
94
+    Real mean = 0;
95
+    Real variance = scale*.05*(.5+.15);
96
+    boost::mt19937 randgen(static_cast<unsigned int> (std::time(0)));
97
+    boost::normal_distribution<Real> noise(mean, variance);
98
+    boost::variate_generator<boost::mt19937, boost::normal_distribution<Real> > nD(randgen, noise);
99
+    VectorXr noisy = G*m;
100
+//     for (int i=0; i < noisy.size(); ++i) {
101
+//        noisy(i) += nD();
102
+//     }
103
+    #else
104
+    VectorXr d = G * m;
105
+    VectorXr noisy = d.array();// + .05*( .5 + .15 ) *Eigen::ArrayXd::Random(d.size());
106
+    #endif
107
+
108
+    // Clean Data, and 10% random noise data
109
+    VectorXr RefMod = VectorXr::Zero(m.size());
110
+
111
+    // todo let alpha's be set.
112
+    Real alpha_s  =  .0;
113
+    Real alpha_t2 = 1.0;
114
+    Eigen::SparseMatrix<Real> Wd (G.rows(), G.rows());
115
+    Eigen::SparseMatrix<Real> Wm (G.cols(), G.cols());
116
+
117
+    /////////////////
118
+    // Model objective function
119
+    int ii = 0;
120
+    for (int iT2=0; iT2<nT2; ++iT2) {
121
+        Wm.coeffRef(ii, ii) += alpha_s - alpha_t2;
122
+        if (iT2 < nT2-1) {
123
+            Wm.coeffRef(ii, ii+1) += alpha_t2;
124
+        }
125
+        ++ii;
126
+    }
127
+    Wm.finalize();
128
+    std::fstream  WmOut( "wmMatrix.dat" , std::ios::out);
129
+    WmOut << Wm << std::endl;
130
+    WmOut.close();
131
+
132
+    // Data objective function
133
+    /// @todo add measure of suspected std dev to this.
134
+    for (int id=0; id<G.rows(); ++id) {
135
+        Wd.coeffRef(id, id) = 1.; // 1/sigma(i);
136
+    }
137
+    Wd.finalize();
138
+
139
+    // invert time-domain sinusoid exponent
140
+    //LogBarrierCG(G, RefMod, noisy, (Real)0., (Real)1e5, nT2, Wd, Wm, scale*1e1);
141
+    return EXIT_SUCCESS;
142
+
143
+//     #if 0
144
+//     // invert FD
145
+//     Eigen::FFT<Real> fft;
146
+//     fft.SetFlag(fft.HalfSpectrum);
147
+//     VectorXcr dw;
148
+//     fft.fwd(dw, noisy);
149
+//
150
+//     // Compute freqs Hz
151
+//     VectorXr freqs = DataSNMR::GetNMRSampledFrequencies(T/dt, dt);
152
+//     Real df = freqs[1];
153
+//     Real window = 300; // Hz
154
+//     int iL = (int)(Larmor/df);
155
+//     MatrixXr Gw = BuildGw(T2, wL, T, dt, T2Bins, scale, freqs.segment(iL-window/2, window));
156
+//
157
+//     VectorXr dwu = VectorXr::Zero(2.*window);
158
+//     dwu.head(window) = dw.segment(iL-window/2, window).real();
159
+//     dwu.tail(window) = dw.segment(iL-window/2, window).imag();
160
+//
161
+//     Eigen::DynamicSparseMatrix<Real> Wdw (Gw.rows(), Gw.rows());
162
+//     for (int id=0; id<Gw.rows(); ++id) {
163
+//         Wdw.coeffRef(id, id) = 1.; // 1/sigma(i);
164
+//     }
165
+//     Wdw.finalize();
166
+//     std::cout << "psize " << (Gw*RefMod).size() << std::endl;
167
+//     VectorXr dw2 = Gw*m;
168
+//     //std::cout << dw2 << std::endl;
169
+//     std::cout << "Gw " << Gw.rows() << "\t" << Gw.cols() << std::endl;
170
+//     std::cout << "dwu " << dwu.size() << std::endl;
171
+//     //RefMod.array() += .1;
172
+//     VectorXr mod = LogBarrierCG(Gw, RefMod, dwu, 0., 3., nT2, Wdw, Wm,scale*1e5);
173
+//     //VectorXr mod = LogBarrierCG(Gw, dwu, 0., 1e5);
174
+//
175
+//     std::fstream Gws("gw.out", std::ios::out);
176
+//     Gws << Gw << std::endl;
177
+//     Gws.close();
178
+//     #endif
179
+}
180
+
181
+#endif
182
+
183
+MatrixXr BuildG(const Real& T2, const Real& wL, const Real& T,
184
+            const Real& dt, const VectorXr& T2Bins, const Real& scale) {
185
+    std::cout << "scale " << scale << std::endl;
186
+    int nt = T/dt;
187
+    int nT2 = T2Bins.size();
188
+    MatrixXr G = MatrixXr::Zero(nt,nT2);
189
+    for (int iT2=0; iT2<nT2; ++iT2) {
190
+        Real t=0;
191
+        for (int it=0; it<nt; ++it) {
192
+            G(it, iT2) = scale * exp(-t/T2Bins(iT2)) * sin(wL * t);
193
+            t += dt;
194
+        }
195
+    }
196
+    return G;
197
+}
198
+
199
+
200
+MatrixXr BuildGw(const Real& T2, const Real& wL, const Real& T,
201
+            const Real& dt, const VectorXr& T2Bins, const Real& scale,
202
+            const VectorXr &freqs) {
203
+    VectorXr omegas = freqs.array() * 2.*PI;
204
+    std::cout << "scale " << scale << std::endl;
205
+    int nT2 = T2Bins.size();
206
+    MatrixXr Gw = MatrixXr::Zero(2*freqs.size(), nT2);
207
+    int nW = freqs.size();
208
+    Real sc = 1./dt;
209
+    for (int iT2=0; iT2<nT2; ++iT2) {
210
+        for (int iw=0; iw<freqs.size(); ++iw) {
211
+            Real a = 1./T2Bins(iT2);
212
+            Complex T = wL / ( wL*wL + (a+Complex(0, omegas[iw]))*(a+Complex(0,omegas[iw])) ) ;
213
+            Gw(iw, iT2)     = sc * scale * std::real(T);
214
+            Gw(iw+nW, iT2) = sc * scale * std::imag(T);
215
+        }
216
+    }
217
+    return Gw;
218
+}

+ 67
- 0
Modules/LemmaCore/examples/utpolygonalantenna.cpp Zobrazit soubor

@@ -0,0 +1,67 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utpolygonalantennae.cpp
4
+//
5
+//    Description:  Unit test of PolygonalAntenna
6
+//
7
+//        Version:  0.0
8
+//        Created:  05/26/2010 04:30:56 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  Trevor Irons (ti)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  United States Geological Survey (USGS)
16
+//
17
+//          Email:  tirons@mines.edu, tirons@usgs.gov
18
+//
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+int main() {
39
+
40
+    PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
41
+        pa->SetNumberOfPoints(5);
42
+        pa->SetPoint(0, Vector3r(  0,  0, -1e-3));
43
+        pa->SetPoint(1, Vector3r( 10,  0, -1e-3));
44
+        pa->SetPoint(2, Vector3r( 10, 10, -1e-3));
45
+        pa->SetPoint(3, Vector3r(  0, 10, -1e-3));
46
+        pa->SetPoint(4, Vector3r(  0,  0, -1e-3));
47
+        pa->SetNumberOfFrequencies(1);
48
+        pa->SetFrequency(0,1000.);
49
+        pa->SetCurrent(10.);
50
+        pa->SetNumberOfTurns(1);
51
+
52
+    Vector3r pos;
53
+    pos << 23,23,23;
54
+    pa->ApproximateWithElectricDipoles(pos);
55
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
56
+              << pa->GetNumberOfDipoles() << std::endl;
57
+    pos << 2,2,2;
58
+    pa->ApproximateWithElectricDipoles(pos);
59
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
60
+              << pa->GetNumberOfDipoles() << std::endl;
61
+    pos << 1,1,1;
62
+    pa->ApproximateWithElectricDipoles(pos);
63
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
64
+              << pa->GetNumberOfDipoles() << std::endl;
65
+
66
+    pa->Delete();
67
+}

+ 68
- 0
Modules/LemmaCore/examples/utreadfemubc.cpp Zobrazit soubor

@@ -0,0 +1,68 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  utreadfemubc.cpp
4
+// 
5
+//    Description:  
6
+// 
7
+//        Version:  0.0
8
+//        Created:  01/03/2013 02:47:24 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++ 
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Broken Spoke Development, LLC
15
+//                  
16
+//
17
+//          Email:  mkass@numericalgeo.com
18
+// 
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "matplot.h"
40
+using namespace matplot;
41
+#endif
42
+
43
+int main() {
44
+
45
+	std::string datfile;
46
+
47
+	datfile = "126.obs";
48
+	
49
+	DataReaderFemUBC* Reader = DataReaderFemUBC::New();
50
+	DataFEM* thedata = DataFEM::New();
51
+
52
+	Reader->SetDataFEM(thedata);
53
+
54
+	try {
55
+	Reader->ReadData(datfile,1);
56
+	} catch(std::exception& e) {
57
+		exit(EXIT_FAILURE);
58
+	}
59
+
60
+	std::cout << *Reader << std::endl;
61
+	std::cout << *thedata << std::endl;
62
+
63
+
64
+	thedata->Delete();
65
+	Reader->Delete();
66
+
67
+	return EXIT_SUCCESS;
68
+}

+ 54
- 0
Modules/LemmaCore/examples/utsandbox.cpp Zobrazit soubor

@@ -0,0 +1,54 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utsandbox.cpp
4
+//
5
+//        Created:  07/29/2010 10:34:23 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file test sandbox helm1rameters
32
+  @author   Trevor Irons
33
+  @date     07/29/2010
34
+  @version   0.0
35
+ **/
36
+
37
+#include "Lemma"
38
+
39
+using namespace Lemma;
40
+
41
+int main() {
42
+
43
+    PolygonalWireAntenna *helm1 = PolygonalWireAntenna::New();
44
+	helm1->SetNumberOfFrequencies(1);
45
+	helm1->SetFrequency(0, 1000);
46
+	helm1->SetNumberOfPoints(5);
47
+	helm1->SetPoint(0, Vector3r(   0,   0, 0));
48
+	helm1->SetPoint(1, Vector3r(   0,   0, 0));
49
+	helm1->SetPoint(2, Vector3r(   0,   0, 0));
50
+	helm1->SetPoint(3, Vector3r(   0,   0, 0));
51
+	helm1->SetPoint(4, Vector3r(   0,   0, 0));
52
+	helm1->SetCurrent(1.);
53
+    helm1->Delete();
54
+}

+ 199
- 0
Modules/LemmaCore/examples/uttemforward.cpp Zobrazit soubor

@@ -0,0 +1,199 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uttemforward.cpp
4
+//
5
+//    Description:  TEM Forward Modeller
6
+//
7
+//        Version:  0.0
8
+//        Created:  02/10/2011 03:32:18 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//		Copyright:  2011 Trevor Irons and M. Andy Kass
15
+//
16
+//   Organisation:  Colorado School of Mines (CSM)
17
+//                  Broken Spoke Development, LLC
18
+//
19
+//          Email:  mkass@numericalgeo.com
20
+//
21
+//  This program is free software: you can redistribute it and/or modify
22
+//  it under the terms of the GNU General Public License as published by
23
+//  the Free Software Foundation, either version 3 of the License, or
24
+//  (at your option) any later version.
25
+//
26
+//  This program is distributed in the hope that it will be useful,
27
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
+//  GNU General Public License for more details.
30
+//
31
+//  You should have received a copy of the GNU General Public License
32
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
33
+//
34
+// ===========================================================================
35
+
36
+#include <time.h>
37
+#include "Lemma"
38
+#include "banner.h"
39
+
40
+using namespace Lemma;
41
+
42
+#ifdef LEMMAUSEVTK
43
+#include "matplot.h"
44
+using namespace matplot;
45
+#endif
46
+
47
+int main(int argv, char** argc) {
48
+
49
+	// Just for timing
50
+	clock_t launch =clock();
51
+
52
+	// Banner display
53
+	std::string name;
54
+	std::string version;
55
+	std::string usage;
56
+	name = "TEM Forward Modeller - 1D";
57
+	version = "1.0beta";
58
+	usage = "temforward1d [inputfile]";
59
+	banner(name,version,usage);
60
+    if ( argv < 2 ) {
61
+        std::cout << "No input file specified, should be of format\n";
62
+        std::cout <<
63
+"origparabk.obsy        ! Observations-style file.\n\
64
+origpara.con           ! Starting model.\n\
65
+100                    ! Number of Hankel kernel evaluations.\n\
66
+100 1. 1.0E+10         ! Number of Fourier kernel evaluations, & min & max freq.\n\
67
+N                      ! Is noise to be added?\n\
68
+5.  1.0E-08  30        ! Noise to be added: percentage, threshold, seed.\n\
69
+" << std::endl;
70
+
71
+        exit(0);
72
+    }
73
+
74
+	time_t curr=time(0);
75
+	std::cout << std::endl;
76
+	std::cout << "  Start time: " << ctime(&curr) << std::endl;
77
+
78
+	// Define objects
79
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
80
+//     PolygonalWireAntenna* pa = PolygonalWireAntenna::New();
81
+//         pa->SetNumberOfPoints(5);
82
+// 	    pa->SetPoint(0, Vector3r(   0,   0, -30.001));
83
+// 	    pa->SetPoint(1, Vector3r(   0,  20, -35.001));
84
+// 	    pa->SetPoint(2, Vector3r(  20 , 20, -35.001));
85
+// 	    pa->SetPoint(3, Vector3r(  20,   0, -30.001));
86
+// 	    pa->SetPoint(4, Vector3r(   0,   0, -30.001));
87
+// 	    pa->SetCurrent(100.);
88
+//         pa->SetNumberOfTurns(1);
89
+
90
+
91
+	//DipoleSource* Trans = DipoleSource::New();
92
+	ReceiverPoints *Receivers = ReceiverPoints::New();
93
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
94
+	VectorXr maintimes;
95
+
96
+    /////////////////////////////////////
97
+	// Using model reader
98
+	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
99
+	    Reader->SetEMEarth1D(Earth);
100
+	    Reader->SetTransmitter(Trans);
101
+	    Reader->SetReceiver(Receivers);
102
+	    Reader->ReadParameters( argc[1] );
103
+	    maintimes = Reader->GetTimes();
104
+
105
+	// Attach it to instrumentTEM
106
+	InstrumentTem *instrument = InstrumentTem::New();
107
+	    instrument->EMEarthModel(Earth);
108
+	    instrument->SetTransmitLoop(Trans);
109
+	    //instrument->SetTransmitLoop(pa);
110
+	    //instrument->SetDipoleSource(Trans);
111
+	    instrument->SetReceiver(Receivers);
112
+
113
+
114
+
115
+        // TODO need to input these
116
+        VectorXr widths = VectorXr::Ones(maintimes.size()); // * 1e-5;
117
+        /*
118
+        widths.segment(0,5).array()  *= 5e-6;
119
+        widths.segment(5,5).array()  *= 1e-5;
120
+        widths.segment(10,5).array() *= 5e-5;
121
+        widths.segment(15,5).array() *= 2e-4;
122
+        widths.segment(20,5).array() *= 4e-4;
123
+        //widths.segment(25,5).array() *= 4e-4;
124
+        */
125
+        /*
126
+        widths << .48,4.,8.,8.,8.,8.,8.,12.,12.,12.,16.,16.,16.,20.,24.,24.,28.,32.,32.,36.,40.,44.,52.,
127
+  				56.,64.,68.,76.,88.,96.,104.,120.,132.,144.,160.,180.,200.,220.,248.,272.,304.,336.,376.,
128
+  				416.,464.,516.,572.,636.,708.,784.,872.,968.,1076.,1196.,1328.,1476.,1640.,1824.,2024.,
129
+  				2248.,2500. ;
130
+        */
131
+        widths *= 1e-6;
132
+        std::cout << widths.transpose() << std::endl;
133
+
134
+        instrument->SetReferenceTime(.025);
135
+        //instrument->SetReferenceTime(.025);
136
+	    instrument->SetTimeGates(maintimes, widths);
137
+
138
+        //instrument->SetReceiverType(MAGNETOMETER);
139
+        instrument->SetReceiverType(INDUCTIVE);
140
+        // Set the pulse
141
+        VectorXr Amp(4); Amp << 0,1,1,0;
142
+        VectorXr Times(4); Times << 0., .0005, .02497, .025;
143
+
144
+        //VectorXr Amp(4); Amp << 0,1,1,0;
145
+        //VectorXr Times(4); Times << -0.025, -0.0245, -0.00003, 0.0;
146
+        //instrument->SetPulse(Amp, Times);
147
+
148
+        //VectorXr Amp(3); Amp << 0,1,0;
149
+        //VectorXr Times(3); Times << 0, .015, .030;
150
+        //instrument->SetPulse(Amp, Times);
151
+
152
+        //VectorXr Amp(3); Amp << 0,1,0;
153
+        //VectorXr Times(3); Times << 0, .01, .020;
154
+        instrument->SetPulse(Amp, Times);
155
+
156
+    std::cout << *Earth << "\n" << *Trans << "\n" << *Receivers << std::endl;
157
+
158
+	// Perform the forward model
159
+	//instrument->MakeDirectCalculation( FHTKEY201  );
160
+	//instrument->MakeLaggedCalculation( ANDERSON801 );
161
+	//instrument->MakeLaggedCalculation( QWEKEY );
162
+	//instrument->MakeLaggedCalculation( CHAVE );
163
+	instrument->MakeLaggedCalculation( FHTKEY201 );
164
+	//instrument->MakeLaggedCalculation( FHTKEY101 );
165
+
166
+    int nlag = instrument->GetMeasurements().rows();
167
+	// Output results to screen
168
+	for (int ii=0; ii<nlag; ii++) {
169
+		std::cout<<"  "<<instrument->GetMeasurements()(ii,0)<<"  "<<instrument->GetMeasurements()(ii,1)<<std::endl;
170
+	}
171
+
172
+	// Output results to file
173
+	std::ofstream outfile1;
174
+	outfile1.open("solution.out");
175
+    //outfile1 << "//timegate [ms]\t dB/dt [nT/s]" << std::endl;
176
+    outfile1 << "//timegate [s]\t dB/dt [T/s]" << std::endl;
177
+	for (int ii=0; ii<nlag; ii++) {
178
+		//outfile1 << 1e3*instrument->GetMeasurements()(ii,0)<< "\t" << (MU0*1e9)*instrument->GetMeasurements()(ii,1)<<std::endl;
179
+		outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << MU0*instrument->GetMeasurements()(ii,1) << std::endl;
180
+		//outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << instrument->GetMeasurements()(ii,1)<<std::endl;
181
+	}
182
+	outfile1.close();
183
+
184
+
185
+	// Timing stuff
186
+	std::cout << "  Time for execution: " <<  (clock()-launch)/CLOCKS_PER_SEC   << " [CPU] seconds."
187
+		 << std::endl;
188
+
189
+
190
+	instrument->Delete();
191
+	Trans->Delete();
192
+	Earth->Delete();
193
+	Receivers->Delete();
194
+	Reader->Delete();
195
+
196
+	return EXIT_SUCCESS;
197
+}
198
+
199
+

+ 131
- 0
Modules/LemmaCore/examples/utteminv1d.cpp Zobrazit soubor

@@ -0,0 +1,131 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utteminv1d.cpp
4
+//
5
+//    Description:  Invert for the difference in water table
6
+//
7
+//        Version:  0.0
8
+//        Created:  03/23/2011 02:07:19 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Development, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
18
+//
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "Lemma"
35
+#include "banner.h"
36
+
37
+using namespace Lemma;
38
+
39
+int main () {
40
+
41
+	VectorXr maintimes;
42
+	int ntimes;
43
+
44
+	//Banner
45
+	std::string name;
46
+	std::string version;
47
+	std::string usage;
48
+	name = "TEM Inversion - 1D";
49
+	version = "1.0beta";
50
+	usage = "teminv1d [inputfile]";
51
+	banner(name,version,usage);
52
+
53
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
54
+	ReceiverPoints* Receivers = ReceiverPoints::New();
55
+	LayeredEarthEM* StartingMod = LayeredEarthEM::New();
56
+	//LayeredEarthEM* RecoveredMod = LayeredEarthEM::New();
57
+	InverseSolverTEM1D* Inverse = InverseSolverTEM1D::New();
58
+
59
+
60
+	Trans->SetNumberOfPoints(5);
61
+    Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
62
+    Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
63
+    Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
64
+    Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
65
+    Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
66
+	Trans->SetCurrent(1);
67
+	Trans->SetNumberOfTurns(1);
68
+    Trans->SetMinDipoleRatio(1/2.);
69
+
70
+	Vector3r loc;
71
+	Real ox = 50.;
72
+	Real oy = 50.;
73
+	Real depth = -1.e-3;
74
+	Receivers->SetNumberOfReceivers(1);
75
+	loc << ox,oy,depth;
76
+	Receivers->SetLocation(0,loc);
77
+
78
+	StartingMod->SetNumberOfLayers(22);
79
+	StartingMod->SetLayerConductivity( (VectorXcr(22) << 0.,1.e-3,
80
+		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,
81
+		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3).finished() );
82
+	StartingMod->SetLayerThickness((VectorXr(20)<<4,4,4,4,4,4,4,4,4,4,4,4,4,
83
+		4,4,4,4,4,4,4).finished());
84
+	//EM-47 gate times
85
+	ntimes = 30;
86
+	maintimes.resize(ntimes);
87
+	maintimes << 36.,45.25,57.,72.25,92.,117.,148.,186.5,234.,290.,
88
+		352.5,427.5,525.,647.5,802.5,1002.5,1257.5,1582.5,1997.5,2525.,
89
+		3197.5,4055.,5147.5,6542.5,8322.5,10592.,13490.,17187.,21902.,
90
+		27915.;
91
+	maintimes = maintimes.array() /1000000;
92
+
93
+	Inverse->AttachStartMod(StartingMod);
94
+	Inverse->AttachWireAntenna(Trans);
95
+	Inverse->AttachReceiver(Receivers);
96
+	Inverse->SetTimes(maintimes);
97
+	LayeredEarthEM* RecoveredMod = StartingMod->Clone();
98
+	Inverse->AttachRecMod(RecoveredMod);
99
+
100
+	//Read input data - temp for SEG!
101
+	/// TODO write a TEM data reader class.  and a functional TEM data class
102
+	std::fstream infile("rotateddat.dat",std::ios::in);
103
+	if (infile.fail()) {
104
+		std::cout << "Shit!" << std::endl;
105
+	}
106
+	MatrixXr rotinpdata;
107
+	rotinpdata.resize(30,1);
108
+	for (int ii=0;ii<30;ii++) {
109
+		infile >> rotinpdata(ii);
110
+	}
111
+	infile.close();
112
+
113
+
114
+	Inverse->AttachMeasuredData(rotinpdata);
115
+	//Inverse->SetFreeParams( (VectorXi(2)<<0,1).finished(),
116
+	//	(VectorXi(3)<<1,2,3).finished());
117
+
118
+	std::cout << *Inverse << std::endl;
119
+
120
+	Inverse->Calculate();
121
+	//Inverse->ShowSoln();
122
+	//Inverse->WriteSoln("temp.dat");
123
+
124
+	Inverse->Delete();
125
+	RecoveredMod->Delete();
126
+	StartingMod->Delete();
127
+	Receivers->Delete();
128
+	Trans->Delete();
129
+
130
+	return EXIT_SUCCESS;
131
+}

+ 84
- 0
Modules/LemmaCore/examples/uttemreader.cpp Zobrazit soubor

@@ -0,0 +1,84 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  uttemreader.cpp
4
+// 
5
+//    Description:  
6
+// 
7
+//        Version:  0.0
8
+//        Created:  02/19/2011 12:30:59 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000 
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Brewery, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
18
+// 
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+
39
+int main() {
40
+
41
+	/*
42
+	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
43
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
44
+	ReceiverPoints *Receivers = ReceiverPoints::New();
45
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
46
+	Reader->SetEMEarth1D(Earth);
47
+	Reader->SetTransmitter(Trans);
48
+	Reader->SetReceiver(Receivers);
49
+	Reader->ReadParameters("em1dtmfwd.in");
50
+
51
+	Reader->Delete();
52
+	Earth->Delete();
53
+	Receivers->Delete();
54
+	Trans->Delete();
55
+	*/
56
+
57
+	int rnObs;
58
+	int rnGates;
59
+	std::string inputfile;
60
+	MatrixXr somedata;
61
+	Vector3Xr somepositions;
62
+
63
+	DataTEM* TheData = DataTEM::New();
64
+	DataReaderTem* Reader = DataReaderTem::New();
65
+
66
+	inputfile = "temreadertest.txt";
67
+
68
+	Reader->SetDataTEM(TheData);
69
+	Reader->ReadData(inputfile);
70
+
71
+	rnObs = TheData->GetnObs();
72
+	rnGates = TheData->GetnGates();
73
+	somedata = TheData->GetData();
74
+	somepositions = TheData->GetPositions();
75
+
76
+	std::cout << rnObs << " " << rnGates << std::endl;
77
+	std::cout << somedata << std::endl;
78
+	std::cout << somepositions << std::endl;
79
+
80
+	Reader->Delete();
81
+	TheData->Delete();
82
+
83
+	return EXIT_SUCCESS;
84
+}

+ 207
- 0
Modules/LemmaCore/examples/uttemsandbox.cpp Zobrazit soubor

@@ -0,0 +1,207 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uttemsandbox.cpp
4
+//
5
+//        Created:  09/29/2010 07:38:26 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti), M. Andy Kass
9
+//
10
+//
11
+//   Organisation:  Colorado School of Mines (CSM)
12
+//                  United States Geological Survey (USGS)
13
+//					Broken Spoke Development, LLC
14
+//
15
+//          Email:  tirons@mines.edu, tirons@usgs.gov
16
+//					mkass@numericalgeo.com
17
+//
18
+//  This program is free software: you can redistribute it and/or modify
19
+//  it under the terms of the GNU General Public License as published by
20
+//  the Free Software Foundation, either version 3 of the License, or
21
+//  (at your option) any later version.
22
+//
23
+//  This program is distributed in the hope that it will be useful,
24
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+//  GNU General Public License for more details.
27
+//
28
+//  You should have received a copy of the GNU General Public License
29
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+//
31
+// ===========================================================================
32
+
33
+/**
34
+  @file
35
+  @author   Trevor Irons
36
+  @date     09/29/2010
37
+  @version   0.0
38
+ **/
39
+
40
+#include "Lemma"
41
+using namespace Lemma;
42
+
43
+#ifdef LEMMAUSEVTK
44
+#include "matplot.h"
45
+using namespace matplot;
46
+#endif
47
+
48
+int main() {
49
+
50
+
51
+    int nfreq  =    6000;  // Number of frequencies
52
+
53
+	// Specify receiver times
54
+	int ntimes	=	30;
55
+	VectorXr times(ntimes);
56
+	times <<
57
+	36.0, 45.25, 57.0, 72.25, 92.0,
58
+	117.0, 148.0, 186.5, 234.0, 290.0,
59
+	352.5, 427.5, 525.0, 647.5, 802.5,
60
+	1002.5, 1257.5, 1582.5, 1997.5, 2525.0,
61
+	3197.5, 4055.0, 5147.5, 6542.5, 8322.5,
62
+	10592.0, 13490.0, 17187.0, 21902.0, 27915.0;
63
+
64
+	times = times.array()*1.0e-6;
65
+
66
+	//CALCULATE ABSCISSA
67
+	//define bounds
68
+
69
+	gaussianquadrature *lgqw = gaussianquadrature::New();
70
+
71
+	Real lowb;
72
+	Real upb;
73
+	lowb = 1.0;
74
+	upb = 6000000.0;
75
+	lgqw->SetFreqs(nfreq,upb,lowb);
76
+	lgqw->CalcAW();
77
+
78
+	VectorXr xu(nfreq);
79
+	xu=lgqw->GetAbscissae();
80
+	DipoleSource* Trans=DipoleSource::New();
81
+	Trans->SetType(MAGNETICDIPOLE);
82
+	Trans->SetPolarisation(ZPOLARISATION);
83
+	Trans->SetLocation(0.0,0.0,-1e-4);
84
+
85
+
86
+    // Specify Transmitter
87
+    //PolygonalWireAntenna* Trans  = PolygonalWireAntenna::New();
88
+    //Trans->SetNumberOfPoints(5);
89
+    //Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
90
+    //Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
91
+    //Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
92
+    //Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
93
+    //Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
94
+    Trans->SetNumberOfFrequencies(nfreq);
95
+    VectorXr  f(nfreq);
96
+    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
97
+    //    Trans->SetFrequency(ifreq, 1e-3 + dfreq*(Real)(ifreq));
98
+		Trans->SetFrequency(ifreq,xu(ifreq));
99
+        f(ifreq) = xu(ifreq);
100
+    }
101
+	//cout << Trans->GetFrequencies();
102
+    //Trans->SetCurrent(1);
103
+    //Trans->SetNumberOfTurns(1);
104
+
105
+    // Earth properties, top layer is air layer 0 conductivity is fine
106
+    LayeredEarthEM *Earth = LayeredEarthEM::New();
107
+        Earth->SetNumberOfLayers(4);
108
+        Earth->SetLayerConductivity( (VectorXcr(4) << 0.,1.e-6,1.e-2,1.e-6 ).finished() );
109
+        Earth->SetLayerThickness( (VectorXr(2) << 50, 20).finished() );
110
+
111
+    // Receivers, just 1 in the centre for now
112
+   	ReceiverPoints *Receivers = ReceiverPoints::New();
113
+		Vector3r loc;
114
+		Real ox     =    50.;
115
+		Real oy     =    50.;
116
+		Real depth  =  -1e-2;
117
+		Receivers->SetNumberOfReceivers(1);
118
+		loc << ox, oy, depth;
119
+		Receivers->SetLocation(0, loc);
120
+
121
+	// EmEarth
122
+	EMEarth1D  *EmEarth = EMEarth1D::New();
123
+		//EmEarth->AttachWireAntenna(Trans);
124
+		EmEarth->AttachDipoleSource(Trans);
125
+		EmEarth->AttachLayeredEarthEM(Earth);
126
+		EmEarth->AttachReceiverPoints(Receivers);
127
+		EmEarth->SetFieldsToCalculate(H);
128
+        // slower but may be more accurate, depending on frequencies
129
+        EmEarth->SetHankelTransformMethod(CHAVE);
130
+        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
131
+
132
+    // Do calculation
133
+   	//EmEarth->CalculateWireAntennaFields();
134
+	//EmEarth->MakeCalc();
135
+	EmEarth->MakeCalc3();
136
+
137
+    // Grab Z component
138
+    // A little painful, I'll try to clean up the API
139
+    VectorXcr Hw(nfreq);
140
+    VectorXr  e(nfreq);
141
+    Hw(0) = 0.; // DC component
142
+    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
143
+        Hw(ifreq) = (Receivers->GetHfield(ifreq, 0))(2);
144
+        e(ifreq) = ifreq;
145
+    }
146
+
147
+    VectorXr Ht(ntimes);                   // Time domain H field
148
+
149
+	//Sine transform
150
+	VectorXr func(nfreq);
151
+	for (int ii=0;ii<ntimes;++ii) {
152
+		func = (Hw.imag().array()*((f.array()*times(ii)).sin()));
153
+		lgqw->SetFunc(func);
154
+		lgqw->Integrate();
155
+		Ht(ii)=lgqw->GetResult();
156
+	}
157
+	Ht = Ht.array()*(-2.0/PI);
158
+
159
+	std::ofstream myfile1;
160
+	myfile1.open("solution.txt");
161
+	for (int ii=0;ii<ntimes;++ii) {
162
+		myfile1 << times(ii) << "   " << Ht(ii) << std::endl;
163
+	}
164
+	myfile1.close();
165
+
166
+	std::ofstream myfile2;
167
+	myfile2.open("freq_domain.txt");
168
+	for (int ii=0;ii<nfreq;++ii) {
169
+		myfile2 << f(ii) << "  " << Hw(ii).real() << "  " << Hw(ii).imag()
170
+			<< std::endl;
171
+	}
172
+	myfile2.close();
173
+
174
+    //std::cout << Ht << std::endl;
175
+    //std::cout << Hw.real() << std::endl;
176
+
177
+    // Quick and dirty plot
178
+    #ifdef  LEMMAUSEVTK
179
+    double colour1[3] = {0.0,0.0,1.0};
180
+    double colour2[3] = {1.0,0.0,0.0};
181
+
182
+    Plot2D_VTK p1("Hz", "Re(Hw)", 800, 600);
183
+    p1.plot(f, Hw.real().eval(), colour1, ".-");
184
+    p1.show();
185
+
186
+    Plot2D_VTK p2("Hz", "Im(Hw)", 800, 600);
187
+    p2.plot(f, Hw.imag().eval(), colour2, ".-");
188
+    p2.show();
189
+
190
+    Plot2D_VTK p3("Time (seconds)", "Ht", 800, 600);
191
+    p3.plot(times, Ht, colour2, ".-");
192
+    p3.show();
193
+
194
+	//Plot2D_VTK p4("index", "frequency",800,600);
195
+	//p4.plot(e,f,colour1,".-");
196
+	//p4.show();
197
+
198
+    #endif
199
+
200
+    // Clean up
201
+    Trans->Delete();
202
+    Earth->Delete();
203
+    Receivers->Delete();
204
+    EmEarth->Delete();
205
+
206
+    return EXIT_SUCCESS;
207
+}

+ 319
- 0
Modules/LemmaCore/examples/wireantenna.cpp Zobrazit soubor

@@ -0,0 +1,319 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utdipolesource.cpp
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  12/02/2009 11:57:14 AM
9
+//       Revision:  none
10
+//       Compiler:  g++ (c++)
11
+//
12
+//         Author:  Trevor Irons (ti)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  United States Geological Survey (USGS)
16
+//
17
+//          Email:  tirons@mines.edu, tirons@usgs.gov
18
+//
19
+//  This program is free software: you can redistribute it and/or modify
20
+//  it under the terms of the GNU General Public License as published by
21
+//  the Free Software Foundation, either version 3 of the License, or
22
+//  (at your option) any later version.
23
+//
24
+//  This program is distributed in the hope that it will be useful,
25
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+//  GNU General Public License for more details.
28
+//
29
+//  You should have received a copy of the GNU General Public License
30
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+//
32
+// ===========================================================================
33
+
34
+#include <iostream>
35
+#include <fstream>
36
+
37
+#include "dipolesource.h"
38
+#include "layeredearth.h"
39
+#include "receiverpoints.h"
40
+#include "emearth1d.h"
41
+#include "WireAntenna.h"
42
+#include "PolygonalWireAntenna.h"
43
+
44
+#if  LEMMAUSEVTK
45
+#include "vtkRenderer.h"
46
+#include "vtkRenderWindow.h"
47
+#include "vtkRenderWindowInteractor.h"
48
+#include "vtkRenderLargeImage.h"
49
+#include "vtkPNGWriter.h"
50
+#endif     // -----  not LEMMA_USE_VTK  -----
51
+
52
+// For testing purposes disable VTK and run scale.sh
53
+//#undef LEMMAUSEVTK
54
+
55
+#include "timer.h"
56
+
57
+using namespace Lemma;
58
+
59
+double randDouble(double low, double high) {
60
+	//srand(time(0));
61
+	double temp;
62
+	/* swap low & high around if the user makes no sense */
63
+	if (low > high)	{
64
+	temp = low;
65
+	low = high;
66
+	high = temp;
67
+	}
68
+	/* calculate the random number & return it */
69
+	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
70
+	* (high - low) + low;
71
+	return temp;
72
+}
73
+
74
+
75
+int main() {
76
+
77
+	// Keep track of time
78
+	jsw_timer timer;
79
+
80
+
81
+	srand(time(0));
82
+
83
+	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
84
+	pa->SetNumberOfFrequencies(1);
85
+	pa->SetFrequency(0, 1000);
86
+	pa->SetNumberOfPoints(5);
87
+	pa->SetPoint(0, Vector3r(   0,   0, -.001));
88
+	pa->SetPoint(1, Vector3r( 100,   0, -.001));
89
+	pa->SetPoint(2, Vector3r( 100, 100, -.001));
90
+	pa->SetPoint(3, Vector3r(   0, 100, -.001));
91
+	pa->SetPoint(4, Vector3r(   0,   0, -.001));
92
+	pa->SetCurrent(1.);
93
+    pa->SetNumberOfTurns(1);
94
+	//Vector3r rp = Vector3r::Random(3);
95
+	//rp << 150., 10, 0.;
96
+	//rp << -27.1456, 15.2350, -1e-3;
97
+	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
98
+	//rp << 3.22806, -13.1548, 14.9695;
99
+	//rp.setRandom(3);
100
+	//std::cout <<  "rp " << rp.transpose() << std::endl;
101
+	//pa->ApproximateWithElectricDipoles(rp);
102
+
103
+	WireAntenna *wire = WireAntenna::New();
104
+		wire->SetNumberOfPoints(5);
105
+		wire->SetPoint(0, Vector3r(   0,   0, -1e-3));
106
+		wire->SetPoint(1, Vector3r( 10,   0, -1e-3));
107
+		wire->SetPoint(2, Vector3r( 10, 10, -1e-3));
108
+		wire->SetPoint(3, Vector3r(   0, 10, -1e-3));
109
+		wire->SetPoint(4, Vector3r(   0,   0, -1e-3));
110
+		// TODO change wire antennae to use my class
111
+		//wire->SetNumberOfFrequencies(1);
112
+		wire->SetCurrent(1.);
113
+		wire->SetNumberOfFrequencies(1);
114
+		wire->SetFrequency(0, 1000);
115
+        wire->SetNumberOfTurns(1);
116
+		//wire->ApproximateWithElectricDipoles(5);
117
+
118
+	// Define model
119
+	VectorXcr sigma(2);
120
+		sigma << Complex(0.,0), Complex(.1,0);
121
+	VectorXr  thick(1);
122
+		thick << 10;
123
+	LayeredEarthEM *earth = LayeredEarthEM::New();
124
+		earth->SetNumberOfLayers(2);
125
+		earth->SetLayerConductivity(sigma);
126
+		//earth->SetLayerThickness(thick);
127
+
128
+	// Receivers
129
+	ReceiverPoints *receivers = ReceiverPoints::New();
130
+		Vector3r loc;
131
+		Real ox    =    50.561 ;
132
+		Real oy    =   105.235 ;
133
+		Real depth =    -3.75e1;
134
+		Real depth2 =   depth;
135
+		Real dx    =    1.;
136
+		int nz     =    1;
137
+		receivers->SetNumberOfReceivers(nz);
138
+		int ir = 0;
139
+		for (int iz=0; iz<nz; ++iz) {
140
+			loc << ox, oy, depth;
141
+			receivers->SetLocation(ir, loc);
142
+			depth += dx;
143
+			++ ir;
144
+		}
145
+
146
+	// EmEarth
147
+	EMEarth1D  *EmEarth = EMEarth1D::New();
148
+		//EmEarth->AttachWireAntenna(wire);
149
+		EmEarth->AttachWireAntenna(pa);
150
+		EmEarth->AttachLayeredEarthEM(earth);
151
+		EmEarth->AttachReceiverPoints(receivers);
152
+		EmEarth->SetFieldsToCalculate(H);
153
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
154
+
155
+	// Do calculation
156
+	timer.begin();
157
+	EmEarth->CalculateWireAntennaFields();
158
+	Real paTime = timer.end();
159
+	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
160
+
161
+	//EmEarth->AttachWireAntenna(wire);
162
+	//timer.begin();
163
+	//EmEarth->CalculateWireAntennaFields();
164
+	//Real waTime = timer.end();
165
+	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
166
+
167
+	depth = depth2;
168
+	std::fstream real("reale_lay.dat", std::ios::out);
169
+	std::fstream imag("image_lay.dat", std::ios::out);
170
+	std::fstream hreal("real_lay.dat", std::ios::out);
171
+	std::fstream himag("imag_lay.dat", std::ios::out);
172
+	for (int iz=0; iz<nz; ++iz) {
173
+		Vector3cr temp = receivers->GetEfield(0,iz);
174
+		real << ox << "\t" << oy << "\t" << depth << "\t"
175
+				<< temp(0).real() << "\t" << temp(1).real()
176
+				<< "\t" << temp(2).real() << std::endl;
177
+		imag << ox << "\t" << oy << "\t" << depth << "\t"
178
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
179
+				<< "\t" << std::imag(temp(2)) << std::endl;
180
+		temp = receivers->GetHfield(0, iz);
181
+		hreal << ox << "\t" << oy << "\t" << depth << "\t"
182
+				<< std::real(temp(0)) << "\t" << std::real(temp(1))
183
+				<< "\t" << std::real(temp(2)) << std::endl;
184
+		himag << ox << "\t" << oy << "\t" << depth << "\t"
185
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
186
+				<< "\t" << std::imag(temp(2)) << std::endl;
187
+		depth += dx;
188
+	}
189
+	real.close();
190
+	imag.close();
191
+	hreal.close();
192
+	himag.close();
193
+	EmEarth->Delete();
194
+	receivers->Delete();
195
+	earth->Delete();
196
+	//wire->Delete();
197
+
198
+#if  LEMMAUSEVTK
199
+	// Create the usual rendering stuff.
200
+	vtkRenderer           *renderer = vtkRenderer::New();
201
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
202
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
203
+
204
+	// Line of tx
205
+	vtkLineSource       *vline = vtkLineSource::New();
206
+	vtkTubeFilter       *vTube = vtkTubeFilter::New();
207
+ 	vtkPolyDataMapper   *vMapper = vtkPolyDataMapper::New();
208
+	vtkActor             *vActor = vtkActor::New();
209
+	vline->SetPoint1(0,0,0);
210
+	vline->SetPoint2(10,0,0);
211
+
212
+	vTube->SetInputConnection(vline->GetOutputPort());
213
+	vTube->SetRadius(.2);
214
+	vTube->SetNumberOfSides(6);
215
+	vMapper->SetInputConnection(vTube->GetOutputPort());
216
+	vActor->SetMapper(vMapper);
217
+	vActor->GetProperty()->SetColor(0.0, .0, 1.0);
218
+	vActor->GetProperty()->SetOpacity(.15);
219
+	renderer->AddActor(vActor);
220
+
221
+	vtkLineSource       *vline2 = vtkLineSource::New();
222
+	vtkTubeFilter       *vTube2 = vtkTubeFilter::New();
223
+ 	vtkPolyDataMapper   *vMapper2 = vtkPolyDataMapper::New();
224
+	vtkActor             *vActor2 = vtkActor::New();
225
+	vline2->SetPoint1(10,0,0);
226
+	vline2->SetPoint2(10,10,0);
227
+
228
+	vTube2->SetInputConnection(vline2->GetOutputPort());
229
+	vTube2->SetRadius(.2);
230
+	vTube2->SetNumberOfSides(6);
231
+	vMapper2->SetInputConnection(vTube2->GetOutputPort());
232
+	vActor2->SetMapper(vMapper2);
233
+	vActor2->GetProperty()->SetColor(0.0, .0, 1.0);
234
+	vActor2->GetProperty()->SetOpacity(.15);
235
+	renderer->AddActor(vActor2);
236
+
237
+	vtkLineSource       *vline3 = vtkLineSource::New();
238
+	vtkTubeFilter       *vTube3 = vtkTubeFilter::New();
239
+ 	vtkPolyDataMapper   *vMapper3 = vtkPolyDataMapper::New();
240
+	vtkActor             *vActor3 = vtkActor::New();
241
+	vline3->SetPoint1(10,10,0);
242
+	vline3->SetPoint2(0,10,0);
243
+
244
+	vTube3->SetInputConnection(vline3->GetOutputPort());
245
+	vTube3->SetRadius(.2);
246
+	vTube3->SetNumberOfSides(6);
247
+	vMapper3->SetInputConnection(vTube3->GetOutputPort());
248
+	vActor3->SetMapper(vMapper3);
249
+	vActor3->GetProperty()->SetColor(0.0, .0, 1.0);
250
+	vActor3->GetProperty()->SetOpacity(.15);
251
+	renderer->AddActor(vActor3);
252
+
253
+	vtkLineSource       *vline4 = vtkLineSource::New();
254
+	vtkTubeFilter       *vTube4 = vtkTubeFilter::New();
255
+ 	vtkPolyDataMapper   *vMapper4 = vtkPolyDataMapper::New();
256
+	vtkActor             *vActor4 = vtkActor::New();
257
+	vline4->SetPoint1(0,10,0);
258
+	vline4->SetPoint2(0,0,0);
259
+
260
+	vTube4->SetInputConnection(vline4->GetOutputPort());
261
+	vTube4->SetRadius(.2);
262
+	vTube4->SetNumberOfSides(6);
263
+	vMapper4->SetInputConnection(vTube4->GetOutputPort());
264
+	vActor4->SetMapper(vMapper4);
265
+	vActor4->GetProperty()->SetColor(0.0, .0, 1.0);
266
+	vActor4->GetProperty()->SetOpacity(.15);
267
+	renderer->AddActor(vActor4);
268
+
269
+    loc << 50, 50, -1e-3;
270
+	pa->ApproximateWithElectricDipoles(loc);
271
+
272
+    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
273
+    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
274
+	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
275
+		pdipActors[id] = pa->GetVtkActor(id);
276
+		renderer->AddActor(pdipActors[id]);
277
+	}
278
+
279
+    /*
280
+    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
281
+	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
282
+		dipActors[id] = wire->GetVtkActor(id);
283
+		renderer->AddActor(dipActors[id]);
284
+	}
285
+    */
286
+
287
+	renderer->SetBackground(1,1,1);
288
+
289
+	// Render the window
290
+	renWin->AddRenderer(renderer);
291
+	renWin->SetWindowName("Wire antennae");
292
+
293
+	iren->SetRenderWindow(renWin);
294
+	iren->Initialize();
295
+	iren->Start();
296
+	iren->Render();
297
+
298
+    #if 0
299
+	cout << "Enter File name?: ";
300
+	std::string pngName;
301
+	std::cin >> pngName;
302
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
303
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
304
+	renlarge->SetInput(renderer);
305
+	renlarge->SetMagnification(2);
306
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
307
+	pngName.append(".png");
308
+	pngwrite->SetFileName(pngName.c_str());
309
+	pngwrite->Write();
310
+    #endif
311
+
312
+#endif     // -----  not LEMMA_USE_VTK  -----
313
+
314
+
315
+	//std::cout << *pa << std::endl;
316
+	//pa->Delete();
317
+
318
+	return 0;
319
+}

+ 161
- 0
Modules/LemmaCore/include/ASCIIParser.h Zobrazit soubor

@@ -0,0 +1,161 @@
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      09/23/2013 02:31:24 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2013, Trevor Irons
17
+ */
18
+
19
+#ifndef  ASCIIPARSER_INC
20
+#define  ASCIIPARSER_INC
21
+
22
+#include "LemmaObject.h"
23
+#include <fstream>
24
+
25
+namespace Lemma {
26
+
27
+/**
28
+ * \ingroup LemmaCore
29
+ * \brief   Provides ASCII input file parsing
30
+ * \details Able to accomodate various inputs and comment styles
31
+ */
32
+class ASCIIParser : public LemmaObject {
33
+
34
+    friend std::ostream &operator<<(std::ostream &stream,
35
+            const ASCIIParser &ob);
36
+
37
+    public:
38
+
39
+    // ====================  LIFECYCLE     =======================
40
+
41
+    /**
42
+     *  Factory method for generating concrete class.
43
+     *  @return a std::shared_ptr of type ASCIIParser
44
+     */
45
+    static std::shared_ptr< ASCIIParser >  NewSP();
46
+
47
+    /**
48
+     *  Constructs an object from a YAML serialization
49
+     *  @return a std::shared_ptr of type ASCIIParser
50
+     */
51
+    static std::shared_ptr< ASCIIParser >  DeSerialize( const YAML::Node& node );
52
+
53
+    /**
54
+     *  Uses YAML to serialize this object.
55
+     *  @return a YAML::Node
56
+     */
57
+    YAML::Node Serialize() const;
58
+
59
+    // ====================  OPERATORS     =======================
60
+
61
+    // ====================  OPERATIONS    =======================
62
+
63
+    /** Opens the file up for reading. Throws an exception if something bad happens.
64
+        @param[in] fname is the filename to be parsed.
65
+     */
66
+    void Open (const std::string& fname);
67
+
68
+
69
+    /** Closes the file. Throws an exception if something bad happens.
70
+     */
71
+    void Close ( );
72
+
73
+    /** Reads a series of Reals.
74
+     *  @param[in] nr is the number of reals to read. Enter -1 for the entire file
75
+     *  @todo throw exception if no file is open
76
+     */
77
+    std::vector<Real> ReadReals( const int& nr);
78
+
79
+    /** Reads a series of Reals.
80
+     *  @param[in] nr is the number of ints to read. Enter -1 for the entire file
81
+     *  @todo throw exception if no file is open
82
+     */
83
+    std::vector<int> ReadInts( const int& nr);
84
+
85
+    /** Reads a series of space delimited strings
86
+     *  @param[in] nr is the number of strings to read. Enter -1 for the entire file
87
+     *  @todo throw exception if no file is open
88
+     */
89
+    std::vector< std::string > ReadStrings( const int& nr);
90
+
91
+    /**
92
+     * @param[in] loc is the point in the file to jump to. Uses seekg
93
+     */
94
+    void JumpToLocation(const int& loc);
95
+
96
+    // ====================  ACCESS        =======================
97
+
98
+    /** Sets the comment identifier key.
99
+     * @param[in] key is a string identifying comments. All text after the key will be
100
+     *  ignored by the parser. Default is //
101
+     */
102
+    void SetCommentString( const std::string& key );
103
+
104
+    /** Sets the buffer size. This affects the maximum number of column in a line. Defaults
105
+     *  is 255.
106
+     *  @param[in] BufferSize is the size of the buffer to use
107
+     */
108
+    void SetBufferSize( const int& BufferSize);
109
+
110
+    /**
111
+     * @return the current position in the file, as reported by istream::tellg
112
+     */
113
+    int GetFileLocation();
114
+
115
+    /** Returns the name of the underlying class, similiar to Python's type */
116
+    virtual inline std::string GetName() const {
117
+        return CName;
118
+    }
119
+
120
+    // ====================  INQUIRY       =======================
121
+
122
+    protected:
123
+
124
+    // ====================  LIFECYCLE     =======================
125
+
126
+    /** Default protected constructor, use New */
127
+    ASCIIParser ( );
128
+
129
+    /** Constructor using YAML::Node */
130
+    ASCIIParser ( const YAML::Node& node );
131
+
132
+    /** Default protected destructor, use Delete */
133
+    ~ASCIIParser ();
134
+
135
+    /**
136
+     *  @copybrief   LemmaObject::Release()
137
+     *  @copydetails LemmaObject::Release()
138
+     */
139
+    void Release();
140
+
141
+    private:
142
+
143
+    // ====================  DATA MEMBERS  =========================
144
+
145
+    /** ASCII string representation of the class name */
146
+    static constexpr auto CName = "ASCIIParser";
147
+
148
+    /** c++ style file IO */
149
+    std::fstream input;
150
+
151
+    /** comment string, defaults to c++ style // */
152
+    std::string  CommentString;
153
+
154
+    /** Buffer size, max line width supported, defaults to 255 */
155
+    int BufferSize;
156
+
157
+}; // -----  end of class  ASCIIParser  -----
158
+
159
+}		// -----  end of Lemma  name  -----
160
+
161
+#endif   // ----- #ifndef ASCIIPARSER_INC  -----

+ 195
- 0
Modules/LemmaCore/include/CubicSplineInterpolator.h Zobrazit soubor

@@ -0,0 +1,195 @@
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      09/25/2013 08:20:14 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2013, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2013, Trevor Irons
18
+ */
19
+
20
+#ifndef  CUBICSPLINEINTERPOLATOR_INC
21
+#define  CUBICSPLINEINTERPOLATOR_INC
22
+
23
+#include "LemmaObject.h"
24
+
25
+namespace Lemma {
26
+
27
+// Simple struct to hold spline terms
28
+struct SplineSet{
29
+    VectorXr a;
30
+    VectorXr b;
31
+    VectorXr c;
32
+    VectorXr d;
33
+    VectorXr x;
34
+
35
+    SplineSet( ) {
36
+    }
37
+
38
+    SplineSet(const int&n) {
39
+        a = VectorXr::Zero(n+1);
40
+        b = VectorXr::Zero(n);
41
+        c = VectorXr::Zero(n+1);
42
+        d = VectorXr::Zero(n);
43
+        x = VectorXr::Zero(n+1);
44
+    }
45
+};
46
+
47
+/**
48
+ * \ingroup LemmaCore
49
+ * \brief   Real 1D Natural cubic spline interpolator.
50
+ * \details Splines are fit between knots \f$j\f$ according to the forulae
51
+ *          \f[ S_j(x) =  a_j + b_j(x - x_j) + c_j(x-x_j)^2 + d_j(x-x_y)^3  \f]
52
+ *          The spline must satisfy the following conditions
53
+ *           \f{eqnarray} {
54
+ *               S_i(x_i) & = & y_i = S_{i-1}(x_i), i = 1,..., n-1 \\
55
+ *               S'_i(x_i) & = &  S'_{i-1}(x_i), i = 1,..., n-1 \\
56
+ *               S''_i(x_i) & = & S''_{i-1}(x_i), i = 1,..., n-1 \\
57
+ *               S''_0(x_0) & = & S''_{n-1}(x_n) = 0
58
+ *           \f}
59
+ */
60
+class CubicSplineInterpolator : public LemmaObject {
61
+
62
+    friend std::ostream &operator<<(std::ostream &stream,
63
+            const CubicSplineInterpolator &ob);
64
+
65
+    public:
66
+
67
+    // ====================  LIFECYCLE     =======================
68
+
69
+    /**
70
+     *  Factory method for generating concrete class.
71
+     *  @return a std::shared_ptr of type CubicSplineInterpolator
72
+     */
73
+    static std::shared_ptr<CubicSplineInterpolator> NewSP();
74
+
75
+    /**
76
+     *  Uses YAML to serialize this object.
77
+     *  @return a YAML::Node
78
+     */
79
+    YAML::Node Serialize() const;
80
+
81
+    /**
82
+     *   Constructs an object from a YAML::Node.
83
+     */
84
+    static std::shared_ptr< CubicSplineInterpolator > DeSerialize(const YAML::Node& node);
85
+
86
+    // ====================  OPERATORS     =======================
87
+
88
+    // ====================  OPERATIONS    =======================
89
+
90
+    /** Sets the knots to use for interpolation.
91
+        @param[in] x are the absissa values
92
+        @param[in] y are the ordinate values
93
+     */
94
+    void SetKnots(const VectorXr& x, const VectorXr& y);
95
+
96
+    /** Resets the knots to use for interpolation, when abscissa values haven't changed.
97
+        @param[in] y are the ordinate values
98
+     */
99
+    void ResetKnotOrdinate( const VectorXr& y );
100
+
101
+    /** Interpolate a monotonically increasing ordered set.
102
+        @param[in] x are the interpolation abscissa points
103
+        @return the ordinate values at x
104
+     */
105
+    VectorXr InterpolateOrderedSet(const VectorXr& x);
106
+
107
+    /** integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments
108
+     *  @param[in] x0 is left argument
109
+     *  @param[in] x1 is right argument
110
+     *  @param[in] n is the number of points, must be even
111
+     */
112
+    Real Integrate(const Real& x0, const Real& x1, const int& n);
113
+
114
+    /** integrates using cubic spline values. Taken from AMRIRA P223F project code Leroi, which in turn was based on
115
+        This is a modification of the FUNCTION PPVALU in the book
116
+        "A PRACTICAL GUIDE TO SPLINES"  by C. DE BOOR
117
+     */
118
+    Real Integrate(const Real& x0, const Real& x1);
119
+
120
+    /** @returns the know abscissa values
121
+     */
122
+    VectorXr GetKnotAbscissa();
123
+
124
+    /** @returns the know abscissa values
125
+     */
126
+    VectorXr GetKnotOrdinate();
127
+
128
+    /** Interpolation at a single point.
129
+        @param[in] x is the interpolation abscissa point
130
+        @param[in] i is an optional index to start searching at. Defaults to zero
131
+        @return the ordinate value at x
132
+     */
133
+    Real Interpolate(const Real& x, int& i);
134
+
135
+    /** Interpolation at a single point.
136
+        @param[in] x is the interpolation abscissa point
137
+        @return the ordinate value at x
138
+     */
139
+    Real Interpolate(const Real& x);
140
+
141
+    // ====================  ACCESS        =======================
142
+
143
+    // ====================  INQUIRY       =======================
144
+
145
+    /** Returns the name of the underlying class, similiar to Python's type */
146
+    virtual inline std::string GetName() const {
147
+        return CName;
148
+    }
149
+
150
+    protected:
151
+
152
+    // ====================  LIFECYCLE     =======================
153
+
154
+    /** Default protected constructor, use New */
155
+    CubicSplineInterpolator ( );
156
+
157
+    /** Protected DeDerializing constructor, use factory DeSerialize  method*/
158
+    CubicSplineInterpolator (const YAML::Node& node);
159
+
160
+    /** Default protected destructor, smart pointers auto delete */
161
+    ~CubicSplineInterpolator ();
162
+
163
+    /**
164
+     *  @copybrief   LemmaObject::Release()
165
+     *  @copydetails LemmaObject::Release()
166
+     */
167
+    void Release();
168
+
169
+    // ====================  OPERATIONS    =======================
170
+
171
+    /** Finds the interval of knots in spline to use for integration.
172
+     */
173
+    int Interval(const Real& x);
174
+
175
+    private:
176
+
177
+    /** ASCII string representation of the class name */
178
+    static constexpr auto CName = "CubicSplineInterpolator";
179
+
180
+    SplineSet Spline;
181
+
182
+    int ilo;
183
+
184
+    int mflag;
185
+
186
+    // ====================  DATA MEMBERS  =========================
187
+
188
+}; // -----  end of class  CubicSplineInterpolator  -----
189
+
190
+}		// -----  end of Lemma  name  -----
191
+
192
+#endif   // ----- #ifndef CUBICSPLINEINTERPOLATOR_INC  -----
193
+
194
+/* vim: set tabstop=4 expandtab: */
195
+/* vim: set filetype=cpp: */

+ 94
- 0
Modules/LemmaCore/include/Data.h Zobrazit soubor

@@ -0,0 +1,94 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/01/2010
11
+  @version  $Id: data.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef  _DATA_H_INC
15
+#define  _DATA_H_INC
16
+
17
+#include "LemmaObject.h"
18
+
19
+namespace Lemma {
20
+
21
+    // ===================================================================
22
+    //        Class:  Data
23
+    /**
24
+     *  \ingroup LemmaCore
25
+     *  \brief Abstract class for data from an instrument
26
+     *  \details Currently provides no functionality, but this will likely
27
+     *          change in the near future.
28
+     */
29
+    // ===================================================================
30
+    class Data : public LemmaObject {
31
+
32
+        friend std::ostream &operator<<(std::ostream &stream,
33
+                const Data &ob);
34
+
35
+        public:
36
+
37
+            // ====================  LIFECYCLE     =======================
38
+
39
+            /** Copies the *structure* of this class to a new object and
40
+             * returns a pointer to this object. Memory management is
41
+             * the responsibility of the receiver!. The data values are
42
+             * not copied.
43
+             */
44
+            virtual Data* Clone()=0;
45
+
46
+            // ====================  OPERATORS     =======================
47
+
48
+            // ====================  OPERATIONS    =======================
49
+
50
+            /** Clears all data arrays and containers
51
+             */
52
+            virtual void Zero()=0;
53
+
54
+            /** Data2 needs to be compatible with the calling class. Data2 will
55
+             * be cast into the calling class type. Most of the time this
56
+             * cast will not perform anything, as Data2 *is* the same type
57
+             * as the calling class.
58
+             */
59
+            virtual Real Norm(Data* Data2)=0;
60
+
61
+            // ====================  ACCESS        =======================
62
+
63
+            // ====================  INQUIRY       =======================
64
+
65
+            /** Returns the name of the underlying class, similiar to Python's type */
66
+            virtual inline std::string GetName() const {
67
+                return CName;
68
+            }
69
+
70
+        protected:
71
+
72
+            // ====================  LIFECYCLE     =======================
73
+
74
+            /** Default protected constructor. */
75
+            Data (  );
76
+
77
+            /** Default protected constructor. */
78
+            ~Data ();
79
+
80
+            // ====================  DATA MEMBERS  =========================
81
+
82
+        private:
83
+
84
+            /** ASCII string representation of the class name */
85
+            static constexpr auto CName = "Data";
86
+
87
+    }; // -----  end of class  Data  -----
88
+
89
+}       // -----  end of Lemma  name  -----
90
+
91
+#endif   // ----- #ifndef _DATA_H_INC  -----
92
+
93
+/* vim: set tabstop=4 expandtab: */
94
+/* vim: set filetype=cpp: */

+ 75
- 0
Modules/LemmaCore/include/DataReader.h Zobrazit soubor

@@ -0,0 +1,75 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/01/2010
11
+  @version  $Id: datareader.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef  DATAREADER_H_INC
15
+#define  DATAREADER_H_INC
16
+
17
+#include "LemmaObject.h"
18
+#include "Data.h"
19
+
20
+namespace Lemma {
21
+
22
+// ===================================================================
23
+//        Class:  DataReader
24
+/// \ingroup LemmaCore
25
+/// \brief  Abstract class whose derived members read data files and
26
+/// converts them to Data Classes
27
+/// \details
28
+// ===================================================================
29
+class DataReader : public LemmaObject {
30
+
31
+    friend std::ostream &operator<<(std::ostream &stream,
32
+            const DataReader &ob);
33
+
34
+    public:
35
+
36
+        // ====================  LIFECYCLE     =======================
37
+
38
+        // ====================  OPERATORS     =======================
39
+
40
+        // ====================  OPERATIONS    =======================
41
+
42
+        // ====================  ACCESS        =======================
43
+        virtual Data* GetData()=0;
44
+
45
+        // ====================  INQUIRY       =======================
46
+        /** Returns the name of the underlying class, similiar to Python's type */
47
+        virtual inline std::string GetName() const {
48
+            return CName;
49
+        }
50
+
51
+    protected:
52
+
53
+        // ====================  LIFECYCLE     =======================
54
+
55
+        /// Default protected constructor.
56
+        DataReader ( );
57
+
58
+        /// Default protected constructor.
59
+        ~DataReader ( );
60
+
61
+        // ====================  DATA MEMBERS  =========================
62
+
63
+    private:
64
+
65
+        /** ASCII string representation of the class name */
66
+        static constexpr auto CName = "DataReader";
67
+
68
+}; // -----  end of class  DataReader  -----
69
+
70
+}       // -----  end of Lemma  name  -----
71
+
72
+#endif   // ----- #ifndef DATAREADER_H_INC  -----
73
+
74
+/* vim: set tabstop=4 expandtab: */
75
+/* vim: set filetype=cpp: */

+ 149
- 0
Modules/LemmaCore/include/EarthModel.h Zobrazit soubor

@@ -0,0 +1,149 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/23/2010
11
+  @version  $Id: earthmodel.h 198 2014-12-27 06:14:05Z tirons $
12
+ **/
13
+
14
+#ifndef  EARTHMODEL_INC
15
+#define  EARTHMODEL_INC
16
+
17
+#include "LemmaObject.h"
18
+
19
+namespace Lemma {
20
+
21
+    // ===================================================================
22
+    //        Class:  EarthModel
23
+    /// \ingroup LemmaGroup
24
+    /// \brief abstract class for Earth models
25
+    /// \details
26
+    // ===================================================================
27
+    class EarthModel : public LemmaObject {
28
+
29
+        // ====================    FRIENDS     ===========================
30
+        friend std::ostream &operator<<(std::ostream &stream,
31
+                        const EarthModel &ob);
32
+
33
+        public:
34
+
35
+            // ====================  LIFECYCLE     =======================
36
+            /** YAML Serializing method
37
+             */
38
+            YAML::Node Serialize() const;
39
+            //static LayeredEarth* DeSerialize(const YAML::Node& node);
40
+
41
+            // ====================  OPERATORS     =======================
42
+
43
+            // ====================  OPERATIONS    =======================
44
+
45
+            // ====================  ACCESS        =======================
46
+
47
+            /** Sets the earth's magnetic field, in Tesla
48
+                @param[in] bfield contains the x,y, and z components of
49
+                the field. EarthModel::Inc, EarthModel::Dec, and
50
+                EarthModel::BMag are computed:
51
+                \f{eqnarray*}{ \mathrm{Inc} = &
52
+                \cos^{-1}( \mathbf{B} \cdot \hat{\mathbf{z}} / B )
53
+                \\ \mathrm{Dec} =& \cos^{-1}
54
+                         (\mathbf{B} \cdot \hat{\mathbf{x}} / B )
55
+                   \\           \mathrm{Mag} =& \Vert \mathbf{B} \Vert  \f}
56
+               @param[in] unit specifies the units of bfield.
57
+              */
58
+            void SetMagneticFieldComponents(const Vector3r &bfield,
59
+                            const MAGUNITS &unit);
60
+
61
+            /// Sets the magnetic field using inclination, declination,
62
+            /// and magnitude, units of Tesla
63
+            /// @param[in] inc is the field's inclination
64
+            /// @param[in] dec is the field's declination
65
+            /// @param[in] Mag is the field's magnitude
66
+            /// @param[in] unit specifies the the units used.
67
+            /// The components are set according to
68
+            /// \f{eqnarray*} { B_x =& B \cos(inc (\pi/180)) \cos(dec (\pi/180))
69
+            ///            \\   B_y =& B \cos(inc (\pi/180)) \sin(dec (\pi/180))
70
+            ///            \\   B_z =& B \sin(inc (\pi/180))
71
+            /// \f}
72
+            void SetMagneticFieldIncDecMag(const Real& inc, const Real&dec,
73
+                            const Real& Mag, const MAGUNITS &unit);
74
+
75
+            // ====================  INQUIRY       =======================
76
+
77
+            /// Gets the magnetic field of the earth, in T
78
+            Vector3r GetMagneticField( );
79
+
80
+            /// Gets the magnetic field of the earth, in T
81
+            Vector3r GetMagneticFieldInGauss(  );
82
+
83
+            /// Gets the magnetic field unit vector of the earth
84
+            Vector3r GetMagneticFieldUnitVector( );
85
+
86
+            /// Returns the magnitude of the magnetic field \f$ \Vert
87
+            /// \mathbf{B}_0 \Vert \f$
88
+            Real GetMagneticFieldMagnitude();
89
+
90
+            /// Returns the magnitude of the magnetic field \f$ \Vert
91
+            /// \mathbf{B}_0 \Vert \f$ in Gauss units
92
+            Real GetMagneticFieldMagnitudeInGauss( );
93
+
94
+            /** Returns the name of the underlying class, similiar to Python's type */
95
+            virtual inline std::string GetName() const {
96
+                return this->CName;
97
+            }
98
+
99
+        protected:
100
+
101
+            // ====================  LIFECYCLE     =======================
102
+
103
+            /// Default protected constructor.
104
+            EarthModel ( );
105
+
106
+            /** Deserialize constructor */
107
+            EarthModel (const YAML::Node& node);
108
+
109
+            /// Default protected constructor.
110
+            ~EarthModel ();
111
+
112
+            // ====================  DATA MEMBERS  =========================
113
+
114
+        private:
115
+
116
+            /** ASCII string representation of the class name */
117
+            static constexpr auto CName = "EarthModel";
118
+
119
+            /// Magnetic field, in units of nT
120
+            Vector3r          BField;
121
+
122
+            /// Magnetic field unit vector \f$  \hat{\mathbf{B}_0} \f$
123
+            Vector3r          BFieldUnit;
124
+
125
+            /// Inclination of the magnetic field
126
+            Real              BInc;
127
+
128
+            /// Declination of the magnetic field
129
+            Real              BDec;
130
+
131
+            /// Declination of the magnetic field
132
+            Real              BMag;
133
+
134
+    }; // -----  end of class  EarthModel  -----
135
+
136
+    //////////////////////////////////////////////////////////////
137
+    // Error Classes
138
+
139
+    /** If the Earth class is NULL valued, throw this
140
+     */
141
+    class NullEarth : public std::runtime_error {
142
+            /** Thrown when an Earth pointer is NULL
143
+             */
144
+            public: NullEarth ();
145
+    };
146
+
147
+}       // -----  end of Lemma  name  -----
148
+
149
+#endif   // ----- #ifndef EARTHMODEL_INC  -----

+ 71
- 0
Modules/LemmaCore/include/Filter.h Zobrazit soubor

@@ -0,0 +1,71 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     07/20/2010
11
+  @version  $Id: filter.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "LemmaObject.h"
15
+
16
+namespace Lemma {
17
+
18
+
19
+    // ===================================================================
20
+    //  Class:  Filter
21
+    /**
22
+      @class  Filter
23
+      \ingroup LemmaCore
24
+      \brief  Abstract class for filtering.
25
+      \details Derived classes include fourier domain and time domain filters.
26
+     */
27
+    // ===================================================================
28
+
29
+    class Filter : public LemmaObject {
30
+
31
+        public:
32
+
33
+            // ====================  LIFECYCLE     =======================
34
+
35
+            // ====================  OPERATORS     =======================
36
+
37
+            // ====================  OPERATIONS    =======================
38
+
39
+            // ====================  ACCESS        =======================
40
+
41
+            // ====================  INQUIRY       =======================
42
+
43
+            /** Returns the name of the underlying class, similiar to Python's type */
44
+            virtual inline std::string GetName() const {
45
+                return this->CName;
46
+            }
47
+
48
+        protected:
49
+
50
+            // ====================  LIFECYCLE     =======================
51
+
52
+            /// Default protected constructor.
53
+            Filter ( );
54
+
55
+            /// Default protected constructor.
56
+            ~Filter ();
57
+
58
+            // ====================  DATA MEMBERS  =========================
59
+
60
+        private:
61
+
62
+            /** ASCII string representation of the class name */
63
+            static constexpr auto CName = "Filter";
64
+
65
+    }; // -----  end of class  Filter  -----
66
+
67
+
68
+}		// -----  end of Lemma  name  -----
69
+
70
+/* vim: set tabstop=4 expandtab: */
71
+/* vim: set filetype=cpp: */

+ 78
- 0
Modules/LemmaCore/include/Grid.h Zobrazit soubor

@@ -0,0 +1,78 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     10/25/2009
11
+  @version  $Id: grid.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef __GRID_H
15
+#define __GRID_H
16
+
17
+#include "LemmaObject.h"
18
+
19
+namespace Lemma {
20
+
21
+// ===============================================================================
22
+//        Class:  Grid
23
+/// \ingroup LemmaCore
24
+/// \brief Abstract base class for grids.
25
+/// \details Grids define values in space, they may either be an integral part
26
+/// of models, or simply the output of a forward modelling procedure.
27
+// ===============================================================================
28
+
29
+class Grid : public LemmaObject {
30
+
31
+    friend std::ostream &operator<<(std::ostream &stream,
32
+            const Grid &ob);
33
+
34
+    public:
35
+
36
+        // ====================  LIFECYCLE     ===================================
37
+
38
+        YAML::Node Serialize() const;
39
+
40
+        // ====================  OPERATORS     ===================================
41
+
42
+        // ====================  OPERATIONS    ===================================
43
+
44
+        // ====================  ACCESS        ===================================
45
+
46
+        // ====================  INQUIRY       ===================================
47
+
48
+        /** Returns the name of the underlying class, similiar to Python's type */
49
+        virtual inline std::string GetName() const {
50
+            return this->CName;
51
+        }
52
+
53
+    protected:
54
+
55
+        // ====================  LIFECYCLE     ===================================
56
+
57
+        /** Protected DeDerializing constructor, use factory DeSerialize  method on non abstract classes*/
58
+        Grid (const YAML::Node& node);
59
+
60
+        /// Default protected constructor.
61
+        Grid ( );
62
+
63
+        /// Default protected constructor.
64
+        ~Grid ();
65
+
66
+        // ====================  DATA MEMBERS  ===================================
67
+
68
+    private:
69
+
70
+        /** ASCII string representation of the class name */
71
+        static constexpr auto CName = "Grid";
72
+
73
+}; // -----  end of class  Grid  -----
74
+
75
+} // namespace Lemma
76
+
77
+#endif // __GRID_H
78
+

+ 84
- 0
Modules/LemmaCore/include/GridReader.h Zobrazit soubor

@@ -0,0 +1,84 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+
8
+/**
9
+  @file
10
+  @date      09/23/2013 11:25:11 AM
11
+  @version   $Id$
12
+  @author    Trevor Irons (ti)
13
+  @email     Trevor.Irons@xri-geo.com
14
+  @copyright Copyright (c) 2013, XRI Geophysics, LLC
15
+  @copyright Copyright (c) 2013, Trevor Irons
16
+ **/
17
+
18
+#ifndef  GRIDREADER_INC
19
+#define  GRIDREADER_INC
20
+
21
+#include "LemmaObject.h"
22
+#include "Grid.h"
23
+
24
+namespace Lemma {
25
+
26
+    /**
27
+      @class
28
+      \ingroup LemmaCore
29
+      \brief   Abstract class for grid readers.
30
+      \details Provides a consistent interface for reading grid files in Lemma.
31
+     */
32
+    class GridReader : public LemmaObject {
33
+
34
+        friend std::ostream &operator << (std::ostream &stream, const GridReader &ob) {
35
+            stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
36
+            return stream;
37
+        }
38
+
39
+        public:
40
+
41
+            // ====================  LIFECYCLE     =======================
42
+
43
+            // ====================  OPERATORS     =======================
44
+
45
+            // ====================  OPERATIONS    =======================
46
+
47
+            virtual void ReadASCIIGridFile( const std::string& name )=0;
48
+
49
+            virtual std::shared_ptr< Grid > GetGrid( )=0;
50
+
51
+            // ====================  ACCESS        =======================
52
+
53
+            // ====================  INQUIRY       =======================
54
+
55
+            /** Returns the name of the underlying class, similiar to Python's type */
56
+            virtual inline std::string GetName() const {
57
+                return this->CName;
58
+            }
59
+
60
+        protected:
61
+
62
+            // ====================  LIFECYCLE     =======================
63
+
64
+            /** Default protected constructor, use New */
65
+            GridReader ( ) : LemmaObject( ) {
66
+            }
67
+
68
+            /** Default protected constructor, use Delete */
69
+            ~GridReader () {
70
+            }
71
+
72
+        private:
73
+
74
+            /** ASCII string representation of the class name */
75
+            static constexpr auto CName = "GridReader";
76
+
77
+            // ====================  DATA MEMBERS  =========================
78
+
79
+    }; // -----  end of class  GridReader  -----
80
+
81
+
82
+}		// -----  end of Lemma  name  -----
83
+
84
+#endif   // ----- #ifndef GRIDREADER_INC  -----

+ 71
- 0
Modules/LemmaCore/include/Instrument.h Zobrazit soubor

@@ -0,0 +1,71 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     02/05/2010
11
+  @version  $Id: instrument.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef __INSTRUMENT_H
15
+#define __INSTRUMENT_H
16
+
17
+#include "LemmaObject.h"
18
+
19
+namespace Lemma {
20
+
21
+	// =======================================================================
22
+	//        Class:  Instrument
23
+    /// \ingroup LemmaCore
24
+	/// \brief    Abstract class for instruments
25
+	/// \details
26
+	// =======================================================================
27
+	class Instrument : public LemmaObject {
28
+
29
+		friend std::ostream &operator<<(std::ostream &stream,
30
+			const Instrument &ob);
31
+
32
+		public:
33
+
34
+			// ====================  LIFECYCLE     ===========================
35
+
36
+			// ====================  OPERATORS     ===========================
37
+
38
+			// ====================  OPERATIONS    ===========================
39
+            //virtual void ForwardModelOnOctreeMesh()=0;
40
+
41
+			// ====================  ACCESS        ===========================
42
+
43
+			// ====================  INQUIRY       ===========================
44
+
45
+            /** Returns the name of the underlying class, similiar to Python's type */
46
+            virtual inline std::string GetName() const {
47
+                return this->CName;
48
+            }
49
+
50
+			// ====================  DATA MEMBERS  ===========================
51
+
52
+		protected:
53
+
54
+			// ====================  LIFECYCLE     ===========================
55
+
56
+			/// Default protected constructor.
57
+			Instrument ( );
58
+
59
+			/// Default protected constructor.
60
+			~Instrument ();
61
+
62
+		private:
63
+
64
+            /** ASCII string representation of the class name */
65
+            static constexpr auto CName = "Instrument";
66
+
67
+	}; // -----  end of class  Instrument  -----
68
+
69
+}		// -----  end of Lemma  name  -----
70
+
71
+#endif // __INSTRUMENT_H

+ 174
- 0
Modules/LemmaCore/include/LayeredEarth.h Zobrazit soubor

@@ -0,0 +1,174 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     06/24/2009
11
+  @version   0.0
12
+ **/
13
+
14
+#ifndef __LAYEREDEARTH_H
15
+#define __LAYEREDEARTH_H
16
+
17
+#include "EarthModel.h"
18
+
19
+namespace Lemma {
20
+
21
+	const int MAXLAYERS	= 10;
22
+
23
+	// =======================================================================
24
+	//        Class:  LayeredEarth
25
+    /// \ingroup LemmaCore
26
+	/// \brief Abstract 1D layered earth.
27
+	// =======================================================================
28
+	class LayeredEarth : public EarthModel {
29
+
30
+        friend class LayeredEarthEM;
31
+
32
+		public:
33
+
34
+			// ====================    FRIENDS     ===========================
35
+			/** Recursively prints out information about this class
36
+             */
37
+            friend std::ostream &operator<<(std::ostream &stream,
38
+						const LayeredEarth &ob);
39
+
40
+			// ====================  LIFECYCLE     ===========================
41
+
42
+			// ====================  OPERATORS     ===========================
43
+
44
+			// ====================  OPERATIONS    ===========================
45
+
46
+			// ====================  ACCESS        ===========================
47
+
48
+			/** Sets the number of layers and resizes all model parameters to
49
+			 *  be the correct size, finally initialises all values to free
50
+			 *  space.
51
+             */
52
+			virtual void SetNumberOfLayers(const int& nlay)=0;
53
+
54
+			/** Sets the thickness of the layers
55
+             */
56
+			void SetLayerThickness(const VectorXr &thick);
57
+
58
+			// ====================  INQUIRY       ===========================
59
+
60
+			/** Returns the number of layers in the model */
61
+			int GetNumberOfLayers( );
62
+
63
+			/** Returns the number of layers in the model, excluding the air
64
+			 * layer
65
+             */
66
+			int GetNumberOfNonAirLayers( );
67
+
68
+			/** Returns the layer that a depth is in.
69
+			 * @param[in] depth is the depth you desire to know the layer of
70
+			 * @return the indice of the layer that depth is in.
71
+             */
72
+			int GetLayerAtThisDepth(const Real& depth);
73
+
74
+			/** Returns the thickness of a layer
75
+             *  @param[in] lay is the layer indice
76
+             *  @return the thickness of a layer
77
+             */
78
+			Real GetLayerThickness(const int & lay);
79
+
80
+			/** Returns the depth of the bottom interface of a layer
81
+             *  @param[in] lay is the layer indice
82
+             *  @return the depth of the bottom interface of a layer
83
+             */
84
+			Real GetLayerDepth(const int & lay);
85
+
86
+            /** YAML Serializing method
87
+             */
88
+            YAML::Node Serialize() const;
89
+            //static LayeredEarth* DeSerialize(const YAML::Node& node);
90
+
91
+            /** Returns the name of the underlying class, similiar to Python's type */
92
+            virtual inline std::string GetName() const {
93
+                return this->CName;
94
+            }
95
+
96
+		protected:
97
+
98
+			// ====================  LIFECYCLE     ===========================
99
+
100
+			/** Default protected constructor. */
101
+			LayeredEarth ( );
102
+
103
+            /** Default protected constructor. */
104
+			LayeredEarth (const YAML::Node& node);
105
+
106
+			/** Default protected constructor. */
107
+			~LayeredEarth ();
108
+
109
+			// ====================  DATA MEMBERS  ===========================
110
+
111
+        private:
112
+            /** ASCII string representation of the class name */
113
+            static constexpr auto CName = "LayeredEarth";
114
+
115
+			/** Number of layers in the model, including the air layer,
116
+			 * and counting from 0
117
+             */
118
+			int               NumberOfLayers;
119
+
120
+			/** Number of interfaces in the model. Equal to NumberOfLayers - 1
121
+			 */
122
+            int               NumberOfInterfaces;
123
+
124
+			/** Vector of layer thicknesses */
125
+			VectorXr          LayerThickness;
126
+
127
+	}; // -----  end of class  LayeredEarth  -----
128
+
129
+
130
+    ///////////////////////////////////////////////////////////////////
131
+    // Error classes
132
+
133
+    /** If a model with less than two layers is specified, throw error. Not set up
134
+     * for whole space solutions.
135
+     */
136
+    class EarthModelWithLessThanTwoLayers : public std::runtime_error {
137
+        public:
138
+            EarthModelWithLessThanTwoLayers( );
139
+    };
140
+
141
+    /** If a solver has a max number of layers, and this is exceeded, throw this
142
+     * error.
143
+     */
144
+    class EarthModelWithMoreThanMaxLayers : public std::runtime_error {
145
+        public:
146
+            /** Thrown when an Earth model with more than the maximum number of
147
+             *  Layers is given
148
+             */
149
+            EarthModelWithMoreThanMaxLayers( );
150
+    };
151
+
152
+    /** If the model parameters have different lengths than the earth model, throw
153
+     * this error.
154
+     */
155
+    class EarthModelParametersDoNotMatchNumberOfLayers : public std::runtime_error {
156
+        public:
157
+            /** Thrown when the parameters do not match the number of Layers
158
+             */
159
+            EarthModelParametersDoNotMatchNumberOfLayers ( );
160
+    };
161
+
162
+    /** If a request if made for a non-valid earth model parameter, throw this
163
+     * error.
164
+     */
165
+    class RequestForNonValidEarthModelParameter : public std::runtime_error {
166
+        public:
167
+            /** Thrown when a request is made for a non-valid earth parameter
168
+             */
169
+            RequestForNonValidEarthModelParameter ( );
170
+    };
171
+
172
+} // namespace Lemma
173
+
174
+#endif // __LAYEREDEARTH_H

+ 40
- 0
Modules/LemmaCore/include/LemmaCore Zobrazit soubor

@@ -0,0 +1,40 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* Copyright (C) 2009-2013 Trevor Irons <trevorirons@gmail.com> */
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
+  @file
11
+  @author   Trevor Irons
12
+  @version  $Id$
13
+ **/
14
+
15
+// Convenience include all of LemmaCore
16
+#ifndef  LEMMAINCLUDE_INC
17
+#define  LEMMAINCLUDE_INC
18
+#include "ASCIIParser.h"
19
+#include "CubicSplineInterpolator.h"
20
+//#include "Data.h"
21
+//#include "DataReader.h"
22
+//#include "EarthModel.h"
23
+//#include "Filter.h"
24
+//#include "Grid.h"
25
+//#include "GridReader.h"
26
+//#include "Instrument.h"
27
+//#include "LayeredEarth.h"
28
+//#include "LemmaObject.h"
29
+#include "RectilinearGrid.h"
30
+#include "RectilinearGridReader.h"
31
+#include "RectilinearGridVTKExporter.h"
32
+#include "WindowFilter.h"
33
+// helpers and utilities
34
+#include "banner.h"
35
+#include "helper.h"
36
+#include "timer.h"
37
+#endif   // ----- #ifndef LEMMAINCLUDE_INC  -----
38
+
39
+/* vim: set tabstop=4 expandtab: */
40
+/* vim: set filetype=cpp: */

+ 168
- 0
Modules/LemmaCore/include/LemmaObject.h Zobrazit soubor

@@ -0,0 +1,168 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     06-13-2016
11
+ **/
12
+
13
+#ifndef __LEMMAOBJECT_H
14
+#define __LEMMAOBJECT_H
15
+
16
+#include "helper.h"
17
+#include "lemma.h"
18
+#include "yaml-cpp/yaml.h"
19
+
20
+#include <chrono>
21
+#include <memory>
22
+
23
+namespace Lemma {
24
+
25
+/**
26
+  * \ingroup  LemmaCore
27
+  * \brief    Abstract class providing common interface for Lemma Objects.
28
+  * \details  Lemma objects can be members of other Lemma, and may be members
29
+  *           of multiple objects. Since updates should be atomic, and objects
30
+  *           can be large, it becomes useful to count the number of
31
+  *           Classes an object is a member of.
32
+  *           Before C++-11, this was done internally in Lemma, with the inclusion of
33
+  *           more sophisticated smart pointers, this logic has been offloaded to the
34
+  *           standard. All Lemma objects should be created as C++-11 Smart pointers, using
35
+  *           the supplied New method. Calls to Delete are no longer necessary or available.
36
+  */
37
+class LemmaObject {
38
+
39
+    /**
40
+     *  Streams class information as YAML::Node
41
+     */
42
+    friend YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject &ob) ;
43
+
44
+    friend class LemmaObjectDeleter;
45
+
46
+    public:
47
+
48
+        // ====================  LIFECYCLE     ==============================
49
+
50
+        // Needed because many derived classes have Eigen vectors as members,
51
+        // causing alignment issues when vectorisation is enabled.
52
+        EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53
+
54
+        // ====================  OPERATORS     ==============================
55
+
56
+        // ====================  OPERATIONS    ==============================
57
+
58
+        // ====================  ACCESS        ==============================
59
+
60
+        // ====================  INQUIRY       ==============================
61
+
62
+        /** Returns the name of the underlying class; Run-time type information (RTTI). This approach
63
+            Was chosen over typeid due to name mangling among various compilers, and the need for consistency
64
+            in Serialized objects.
65
+         */
66
+        virtual inline std::string GetName() const {
67
+            return this->CName;
68
+        }
69
+
70
+        /**
71
+         *  Uses YAML to serialize this object.
72
+         *  @return a YAML::Node
73
+         *  FOR NOT LemmaObject does not write out any YAML info,
74
+         *      in the future the reference count could be logged? But the utility
75
+         *      of that is minimal.
76
+         *  @note Not every Lemma class needs to be Serializable, for instance HankelTransform
77
+         *        classes will never need to be Serialized. There may be a need to differentiate these
78
+         *        two families in to a LemmaInternalClass without serializing and perhaps this class for
79
+         *        all external classes that might need to be serialized.
80
+         */
81
+        virtual YAML::Node Serialize() const {
82
+            YAML::Node node = YAML::Node();
83
+            node.SetTag( GetName() );
84
+            std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
85
+            node["Serialized"] = std::ctime(&now);
86
+            return node;
87
+        };
88
+
89
+    protected:
90
+
91
+        // ====================  LIFECYCLE     ==============================
92
+
93
+        /** Protected default constructor. This is an abstract class and
94
+         *  cannot be instantiated.
95
+         */
96
+        LemmaObject ( );
97
+
98
+        /** Protected DeDerializing constructor, use factory DeSerialize  method*/
99
+        LemmaObject (const YAML::Node& node);
100
+
101
+        /** Protected default destructor. This is an abstract class and
102
+         *  cannot be instantiated. Virtual is necessary so that if base class destructor is
103
+         *  called, we get the right behaviour.
104
+         */
105
+        virtual ~LemmaObject();
106
+
107
+    private:
108
+
109
+        // ====================  DATA MEMBERS  ==============================
110
+
111
+        /** ASCII string representation of the class name */
112
+        static constexpr auto CName = "LemmaObject";
113
+
114
+}; // -----  end of class  LemmaObject  -----
115
+
116
+class LemmaObjectDeleter
117
+{
118
+    public:
119
+        void operator()(LemmaObject* p) { delete p; }
120
+};
121
+
122
+    /////////////////////////////////////////////////////////////////
123
+    // Error Classes
124
+
125
+    /** Error called when DeSerializing breaks. If the node type is not the expected one
126
+     *  this error is thown.
127
+     */
128
+    class DeSerializeTypeMismatch : public std::runtime_error {
129
+        public:
130
+            DeSerializeTypeMismatch(const std::string& expected, const std::string& got);
131
+
132
+    };
133
+
134
+    /** If an assignment is made that is out of bounts, throw this.
135
+     */
136
+    class AssignmentOutOfBounds : public std::runtime_error {
137
+        public:
138
+            /** Throw when an assignment is out of bounds.
139
+             *  @param[in] ptr is a pointer to the class throwing the exception.
140
+             */
141
+            AssignmentOutOfBounds(LemmaObject *ptr);
142
+    };
143
+
144
+    /** If a pointer to a class is requested, but it is NULL valued, throw this
145
+     */
146
+    class RequestToReturnNullPointer : public std::runtime_error {
147
+        public:
148
+            /** Thrown when the pointer is NULL
149
+             *  @param[in] ptr is a pointer to the class throwing the exception.
150
+             */
151
+            RequestToReturnNullPointer(LemmaObject *ptr);
152
+    };
153
+
154
+    /** If an error in opening a .mat file is encountered, throw this.
155
+     */
156
+    class MatFileCannotBeOpened : public std::runtime_error {
157
+        /** thown when a mat file fails to be opened.
158
+         */
159
+            public: MatFileCannotBeOpened();
160
+    };
161
+
162
+	/** Generic file I/O error. */
163
+	class GenericFileIOError : public std::runtime_error {
164
+			public: GenericFileIOError(LemmaObject *ptr, const std::string &filename);
165
+	};
166
+
167
+}
168
+#endif // __LEMMAOBJECT_H

+ 216
- 0
Modules/LemmaCore/include/RectilinearGrid.h Zobrazit soubor

@@ -0,0 +1,216 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     10/28/2010
11
+  @version  $Id: rectilineargrid.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef  RECTILINEARGRID_INC
15
+#define  RECTILINEARGRID_INC
16
+
17
+#include "Grid.h"
18
+
19
+namespace Lemma {
20
+
21
+    // ===================================================================
22
+    //  Class:  RectilinearGrid
23
+    /**
24
+      @class
25
+      \ingroup LemmaCore
26
+      \brief   Impliments a rectilinear grid.
27
+      \details A rectilinear grid can vary regularily in space but must be
28
+               constant variation across each dimension. In this way three
29
+               vectors can define the entire grid, and each cell is right
30
+               aligned with all its neighbours.
31
+     */
32
+    // ===================================================================
33
+    class RectilinearGrid : public Grid {
34
+
35
+        friend std::ostream &operator<<(std::ostream &stream,
36
+			const RectilinearGrid &ob);
37
+
38
+        public:
39
+
40
+            // ====================  LIFECYCLE     =======================
41
+
42
+            /**
43
+             *  Factory method for generating concrete class.
44
+             *  @return a std::shared_ptr of type RectilinearGrid
45
+             */
46
+            static std::shared_ptr<RectilinearGrid> NewSP();
47
+
48
+
49
+            /**
50
+             *  Uses YAML to serialize this object.
51
+             *  @return a YAML::Node
52
+             */
53
+            YAML::Node Serialize() const;
54
+
55
+            /**
56
+             *   Constructs an object from a YAML::Node.
57
+             */
58
+            static std::shared_ptr< RectilinearGrid > DeSerialize(const YAML::Node& node);
59
+
60
+            // ====================  OPERATORS     =======================
61
+
62
+            // ====================  OPERATIONS    =======================
63
+
64
+            /**
65
+             *  Sets the dimensions in x, y and z
66
+             *  @param[in] nx is the number of cells in x
67
+             *  @param[in] ny is the number of cells in y
68
+             *  @param[in] nz is the number of cells in z
69
+             */
70
+            void SetDimensions (const int &nx, const int &ny, const int &nz);
71
+
72
+            /**
73
+             *  Sets the offset in x, y and z. This sets the corner position of the top SW corner.
74
+             *  @param[in] ox is the number of cells in x
75
+             *  @param[in] oy is the number of cells in y
76
+             *  @param[in] oz is the number of cells in z
77
+             */
78
+            void SetOffset (const Real &ox, const Real &oy, const Real &oz);
79
+
80
+            /**
81
+             *  Sets the spacing in x, y and z
82
+             *  @param[in] dx is a Vector of cell spacing in x, must be same
83
+             *  size ad nx
84
+             *  @param[in] dy is a Vector of cell spacing in x, must be same
85
+             *  size ad ny
86
+             *  @param[in] dz is a Vector of cell spacing in x, must be same
87
+             *  size ad nz
88
+             */
89
+            void SetSpacing (const VectorXr &dx, const VectorXr &dy,
90
+                const VectorXr &dz);
91
+
92
+
93
+            // ====================  ACCESS        =======================
94
+
95
+            /** Returns the number of cells in x
96
+             *  @return number of cells in x
97
+             */
98
+            int GetNx();
99
+
100
+            /** Returns the number of cells in y
101
+             *  @return number of cells in y
102
+             */
103
+            int GetNy();
104
+
105
+            /** Returns the number of cells in z
106
+             *  @return number of cells in z
107
+             */
108
+            int GetNz();
109
+
110
+            /** Returns the offset of cells in x
111
+             *  @return offset of cells in x
112
+             */
113
+            Real GetOx();
114
+
115
+            /** Returns the number of cells in y
116
+             *  @return number of cells in y
117
+             */
118
+            Real GetOy();
119
+
120
+            /** Returns the offset of cells in z
121
+             *  @return offset of cells in z
122
+             */
123
+            Real GetOz();
124
+
125
+            /** Returns Spacing Vector
126
+             *  @return dx
127
+             */
128
+            VectorXr GetDx();
129
+
130
+            /** Returns a spacing
131
+             *  @return dx[ix]
132
+             */
133
+            Real GetDx(const int& ix);
134
+
135
+            /** Returns Spacing Vector
136
+             *  @return dy
137
+             */
138
+            VectorXr GetDy();
139
+
140
+            /** Returns a spacing
141
+             *  @return dy[iy]
142
+             */
143
+            Real GetDy(const int& iy);
144
+
145
+            /** Returns Spacing Vector
146
+             *  @return dz
147
+             */
148
+            VectorXr GetDz();
149
+
150
+            /** Returns Spacing Vector
151
+             *  @return dz[iz]
152
+             */
153
+            Real GetDz(const int& iz);
154
+
155
+            // ====================  INQUIRY       =======================
156
+
157
+            /** Returns the name of the underlying class, similiar to Python's type */
158
+            virtual inline std::string GetName() const {
159
+                return this->CName;
160
+            }
161
+
162
+        protected:
163
+
164
+            // ====================  LIFECYCLE     =======================
165
+
166
+            /** Default protected constructor. */
167
+            RectilinearGrid ( );
168
+
169
+            /** Protected DeDerializing constructor, use factory DeSerialize  method*/
170
+            RectilinearGrid (const YAML::Node& node);
171
+
172
+            /** Default protected constructor. */
173
+            ~RectilinearGrid ();
174
+
175
+            // ====================  DATA MEMBERS  =========================
176
+
177
+            /// Number of cells in the x dimension
178
+            int nx;
179
+
180
+            /// Number of cells in the y dimension
181
+            int ny;
182
+
183
+            /// Number of cells in the z dimension
184
+            int nz;
185
+
186
+            /// Grid offset in x dimension
187
+            Real ox;
188
+
189
+            /// Grid offset in y dimension
190
+            Real oy;
191
+
192
+            /// Grid offset in z dimension
193
+            Real oz;
194
+
195
+            /// Cell spacing in the x dimension
196
+            VectorXr dx;
197
+
198
+            /// Cell spacing in the y dimension
199
+            VectorXr dy;
200
+
201
+            /// Cell spacing in the z dimension
202
+            VectorXr dz;
203
+
204
+        private:
205
+
206
+            /** ASCII string representation of the class name */
207
+            static constexpr auto CName = "RectilinearGrid";
208
+
209
+    }; // -----  end of class  RectilinearGrid  -----
210
+
211
+}		// -----  end of Lemma  name  -----
212
+
213
+#endif   // ----- #ifndef RECTILINEARGRID_INC  -----
214
+
215
+/* vim: set tabstop=4 expandtab: */
216
+/* vim: set filetype=cpp: */

+ 110
- 0
Modules/LemmaCore/include/RectilinearGridReader.h Zobrazit soubor

@@ -0,0 +1,110 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+
8
+/**
9
+  @file
10
+  @date      09/23/2013 11:05:11 AM
11
+  @version   $Id$
12
+  @author    Trevor Irons (ti)
13
+  @email     Trevor.Irons@xri-geo.com
14
+  @copyright Copyright (c) 2013, XRI Geophysics, LLC
15
+  @copyright Copyright (c) 2013, Trevor Irons
16
+ **/
17
+
18
+#ifndef  RECTILINEARGRIDREADER_INC
19
+#define  RECTILINEARGRIDREADER_INC
20
+
21
+#include "GridReader.h"
22
+#include "RectilinearGrid.h"
23
+#include "ASCIIParser.h"
24
+
25
+namespace Lemma {
26
+
27
+    /**
28
+      @class
29
+      \ingroup LemmaCore
30
+      \brief   Base Class for rectilinear grid reader data files
31
+      \details
32
+     \todo this set of classes is deprecated, use serialize methods!
33
+     */
34
+    class RectilinearGridReader : public GridReader {
35
+
36
+        friend std::ostream &operator<<(std::ostream &stream,
37
+                const RectilinearGridReader &ob);
38
+
39
+        public:
40
+
41
+            // ====================  LIFECYCLE     =======================
42
+
43
+            /**
44
+             *  Factory method for generating concrete class.
45
+             *  @return a std::shared_ptr of type RectilinearGridReader
46
+             */
47
+            static std::shared_ptr< RectilinearGridReader > NewSP();
48
+
49
+            // ====================  OPERATORS     =======================
50
+
51
+            // ====================  OPERATIONS    =======================
52
+
53
+            /**
54
+            Reads a .mod file, a simple representation of the grid. These files
55
+            have the following format:
56
+            @verbatim
57
+            nx ny nz  // number of cells in x, y, and z
58
+            ox oy oz  // grid offset of top SW corner
59
+
60
+            hx[0] hx[1] ... hx[nx-1]  // grid cell spacing in x, from 0 to nx-1
61
+            hy[0] hy[1] ... hy[ny-1]  // grid cell spacing in y, from 0 to ny-1
62
+            hz[0] hz[1] ... hz[nz-1]  // grid cell spacing in z, from 0 to nz-1
63
+
64
+            // c++ style (//) comments are allowed anywhere, c-style are not
65
+            @endverbatim
66
+            */
67
+            void ReadASCIIGridFile( const std::string& name );
68
+
69
+            // ====================  ACCESS        =======================
70
+            /**
71
+             * Accessor method for the underlying RectilinearGrid class constructed
72
+             * from the input file.
73
+             */
74
+            std::shared_ptr<Grid> GetGrid();
75
+
76
+            // ====================  INQUIRY       =======================
77
+
78
+            /** Returns the name of the underlying class, similiar to Python's type */
79
+            virtual inline std::string GetName() const {
80
+                return this->CName;
81
+            }
82
+
83
+        protected:
84
+
85
+            // ====================  LIFECYCLE     =======================
86
+
87
+            /** Default protected constructor, use New */
88
+            RectilinearGridReader ( );
89
+
90
+            /** Default protected constructor, use Delete */
91
+            ~RectilinearGridReader ();
92
+
93
+        private:
94
+
95
+            // ====================  DATA MEMBERS  =========================
96
+
97
+            /** ASCII string representation of the class name */
98
+            static constexpr auto CName = "RectilinearGridReader";
99
+
100
+            /** Object holding constructed Grid */
101
+            std::shared_ptr<RectilinearGrid> rGrid;
102
+
103
+            /** Performs actual file parsing */
104
+            std::shared_ptr<ASCIIParser> Parser;
105
+
106
+    }; // -----  end of class  RectilinearGridReader  -----
107
+
108
+}		// -----  end of Lemma  name  -----
109
+
110
+#endif   // ----- #ifndef RECTILINEARGRIDREADER_INC  -----

+ 124
- 0
Modules/LemmaCore/include/RectilinearGridVTKExporter.h Zobrazit soubor

@@ -0,0 +1,124 @@
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      09/25/2013 08:20:01 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2013, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2013, Trevor Irons
18
+ */
19
+
20
+
21
+#ifndef  RECTILINEARGRIDVTKEXPORTER_INC
22
+#define  RECTILINEARGRIDVTKEXPORTER_INC
23
+
24
+#ifdef  LEMMAUSEVTK
25
+
26
+#include "LemmaObject.h"
27
+#include "RectilinearGrid.h"
28
+
29
+#include <vtkSmartPointer.h>
30
+#include "vtkXMLRectilinearGridWriter.h"
31
+#include "vtkRectilinearGrid.h"
32
+#include "vtkDoubleArray.h"
33
+#include "vtkFieldData.h"
34
+#include "vtkCellData.h"
35
+
36
+namespace Lemma {
37
+
38
+/**
39
+  \ingroup LemmaCore
40
+  \brief   Exports a LemmaRectilinearGrid into a VTKRectilinearGrid.
41
+  \details Results can then be dumped to a VTK file or used directly.
42
+ */
43
+class RectilinearGridVTKExporter : public LemmaObject {
44
+
45
+    friend std::ostream &operator<<(std::ostream &stream,
46
+            const RectilinearGridVTKExporter &ob);
47
+
48
+    public:
49
+
50
+    // ====================  LIFECYCLE     =======================
51
+
52
+    /**
53
+     * @copybrief LemmaObject::New()
54
+     * @copydetails LemmaObject::New()
55
+     */
56
+    static RectilinearGridVTKExporter* New();
57
+
58
+    /**
59
+     *  Factory method for generating concrete class.
60
+     *  @return a std::shared_ptr of type RectilinearGridVTKExporter
61
+     */
62
+    static std::shared_ptr< RectilinearGridVTKExporter > NewSP();
63
+
64
+    // ====================  OPERATORS     =======================
65
+
66
+    // ====================  OPERATIONS    =======================
67
+
68
+    // ====================  ACCESS        =======================
69
+    /**
70
+     * Sets the Grid to be exported
71
+     */
72
+    void SetGrid( std::shared_ptr<RectilinearGrid> Grid);
73
+
74
+    // ====================  INQUIRY       =======================
75
+
76
+    /**
77
+     *  @return Returns a pointer to a vtkRectilinearGrid containing same information as the Lemma Grid.
78
+     */
79
+    vtkSmartPointer<vtkRectilinearGrid>  GetVTKGrid();
80
+
81
+    /**
82
+     *  Writes the exported VTKGrid out to a .vtr XML file
83
+     *  @param[in] name is the filename to write to. The .vtr extension will be added
84
+     */
85
+    void WriteVTKGrid( const std::string& name );
86
+
87
+    /** Returns the name of the underlying class, similiar to Python's type */
88
+    virtual inline std::string GetName() const {
89
+        return this->CName;
90
+    }
91
+
92
+    protected:
93
+
94
+    // ====================  LIFECYCLE     =======================
95
+
96
+    /** Default protected constructor, use New */
97
+    RectilinearGridVTKExporter ( );
98
+
99
+    /** Default protected destructor, use Delete */
100
+    ~RectilinearGridVTKExporter ();
101
+
102
+    private:
103
+
104
+    /** ASCII string representation of the class name */
105
+    static constexpr auto CName = "RectilinearGridVTKExporter";
106
+
107
+    void BuildVTKRectilinearGrid();
108
+
109
+    // ====================  DATA MEMBERS  =========================
110
+
111
+    /** The Grid to convert from */
112
+    std::shared_ptr<RectilinearGrid>    Grid;
113
+
114
+    /** The Grid to convert to */
115
+    vtkSmartPointer<vtkRectilinearGrid> VTKGrid;
116
+
117
+}; // -----  end of class  RectilinearGridVTKExporter  -----
118
+
119
+}		// -----  end of Lemma  name  -----
120
+
121
+#endif     // -----  not LEMMAUSEVTK  -----
122
+
123
+#endif   // ----- #ifndef RECTILINEARGRIDVTKEXPORTER_INC  -----
124
+

+ 127
- 0
Modules/LemmaCore/include/WindowFilter.h Zobrazit soubor

@@ -0,0 +1,127 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     07/20/2010
11
+  @version  $Id: windowfilter.h 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#ifndef  WINDOWFILTER_INC
15
+#define  WINDOWFILTER_INC
16
+#include "Filter.h"
17
+
18
+namespace Lemma {
19
+    /** Types of filter window that are supported.
20
+     */
21
+    enum WINDOWTYPE { HAMMING, /*!< A hamming window */
22
+                      HANNING, /*!< A hanning window */
23
+                      RECTANGULAR /*!< Rectangular window */
24
+                    };
25
+
26
+    // ===================================================================
27
+    //  Class:  WindowFilter
28
+    /**
29
+      @class   WindowFilter
30
+      \ingroup LemmaCore
31
+      \brief   Fourier domain window filter.
32
+      \details Current types are Hamming and Hanning. Others to be added.
33
+     */
34
+    // ===================================================================
35
+    class WindowFilter : public Filter {
36
+
37
+        public:
38
+
39
+            // ====================  LIFECYCLE     =======================
40
+
41
+           /**
42
+            *  Factory method for generating concrete class.
43
+            *  @return a std::shared_ptr of type WindowFilter
44
+            */
45
+            static std::shared_ptr< WindowFilter > NewSP();
46
+
47
+            // ====================  OPERATORS     =======================
48
+
49
+            // ====================  OPERATIONS    =======================
50
+
51
+            /// Sets the bandwith of the window.
52
+            /// @param[in] width Bandwidth in Hz
53
+            void SetBandwidth(const Real& width);
54
+
55
+            /// Sets the sampling rate of an input time domain signal.
56
+            /// @param[in] dt is the sampling rate, in seconds.
57
+            void SetSamplingInterval(const Real& dt);
58
+
59
+            /// Specifies the length of the time series to apply filter to.
60
+            void SetNumberOfSamples(const int& nt);
61
+
62
+            /// Sets the type of window to compute.
63
+            void SetWindowType(const WINDOWTYPE& type);
64
+
65
+            /** Returns the number of frequency bins for whole data record.
66
+             *  this is different then the length of the filter. This is
67
+             *  simply the length of the real to complex FFT, or
68
+             *  Nw = Nt%2 ? (Nt-1)/2+1 : (Nt)/2+1;
69
+             *  @return the number of frequency bins.
70
+             */
71
+            int GetNumberOfFrequencyBins();
72
+
73
+            // ====================  ACCESS        =======================
74
+
75
+            // ====================  INQUIRY       =======================
76
+
77
+            /// Returns a Vector of the filter coefficients.
78
+            VectorXr GetFilterCoefficients( );
79
+
80
+            /** Returns the name of the underlying class, similiar to Python's type */
81
+            virtual inline std::string GetName() const {
82
+                return this->CName;
83
+            }
84
+
85
+        protected:
86
+
87
+            // ====================  LIFECYCLE     =======================
88
+
89
+            /// Default protected constructor.
90
+            WindowFilter ( );
91
+
92
+            /// Default protected constructor.
93
+            ~WindowFilter ( );
94
+
95
+            // ====================  DATA MEMBERS  =========================
96
+
97
+            /// Width of the window
98
+            int         Width;
99
+
100
+            /// Length of time series
101
+            int         Nt;
102
+
103
+            /// Length of the frequency series representation
104
+            int         Nw;
105
+
106
+            /// Sampling rate of a time domain signal
107
+            Real        SamplingRate;
108
+
109
+            /// Bandwith of filter
110
+            Real        Bandwidth;
111
+
112
+            /// The filter coefficients
113
+            VectorXr    Coefficients;
114
+
115
+            /// The type of filter to use
116
+            WINDOWTYPE  Type;
117
+
118
+        private:
119
+
120
+        /** ASCII string representation of the class name */
121
+        static constexpr auto CName = "WindowFilter";
122
+
123
+    }; // -----  end of class  WindowFilter  -----
124
+
125
+}       // -----  end of Lemma  name  -----
126
+
127
+#endif   // ----- #ifndef WINDOWFILTER_INC  -----

+ 24
- 0
Modules/LemmaCore/include/banner.h Zobrazit soubor

@@ -0,0 +1,24 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API
2
+ */
3
+
4
+/* This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
+
8
+/**
9
+  @file
10
+  @author   M. Andy Kass
11
+  @date     05/03/2010
12
+  @version  $Id: banner.h 87 2013-09-05 22:44:05Z tirons $
13
+ **/
14
+
15
+#ifndef __BANNER_H
16
+#define __BANNER_H
17
+#include <iostream>
18
+#include <ostream>
19
+void banner(const std::string &name, const std::string &version,
20
+		const std::string &usage);
21
+#endif
22
+
23
+/* vim: set tabstop=4 expandtab: */
24
+/* vim: set filetype=cpp: */

+ 288
- 0
Modules/LemmaCore/include/helper.h Zobrazit soubor

@@ -0,0 +1,288 @@
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      10/02/2014 02:49:55 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#pragma once
21
+
22
+#ifndef  HELPER_INC
23
+#define  HELPER_INC
24
+
25
+#include "lemma.h"
26
+#include "yaml-cpp/yaml.h"
27
+
28
+namespace Lemma {
29
+
30
+/** \addtogroup LemmaCore
31
+ * @{
32
+ */
33
+
34
+    /**
35
+     *  Convenience function for string conversion
36
+     *  @param[in] t input value to be converted to string
37
+     *  @return string representation of input value
38
+     */
39
+    template <class T>
40
+    inline std::string to_string (const T& t) {
41
+        std::stringstream ss;
42
+        ss << t;
43
+        return ss.str();
44
+    }
45
+
46
+    /// convert enums to string saves repeated code useful for YAML serializing
47
+    std::string enum2String(const FREQUENCYUNITS& Units);
48
+    /// convert enums to string saves repeated code useful for YAML serializing
49
+    std::string enum2String(const TIMEUNITS& Units);
50
+    /// convert enums to string saves repeated code useful for YAML serializing
51
+    std::string enum2String(const MAGUNITS& Units);
52
+    /// convert enums to string saves repeated code useful for YAML serializing
53
+    std::string enum2String(const TEMPUNITS& Units);
54
+    /// convert enums to string saves repeated code useful for YAML serializing
55
+    std::string enum2String(const FEMCOILORIENTATION& Units);
56
+    /// convert enums to string saves repeated code useful for YAML serializing
57
+    std::string enum2String(const ORIENTATION& Units);
58
+    /// convert enums to string saves repeated code useful for YAML serializing
59
+    std::string enum2String(const FIELDCOMPONENT& Comp);
60
+    /// convert enums to string saves repeated code useful for YAML serializing
61
+    std::string enum2String(const HANKELTRANSFORMTYPE& Htype);
62
+    /// convert enums to string saves repeated code useful for YAML serializing
63
+    std::string enum2String(const FIELDCALCULATIONS& Htype);
64
+
65
+    // other way around is a template, where template argument lets us know
66
+    // which specialisation to use.
67
+    template <typename T>
68
+    T string2Enum( const std::string& str );
69
+
70
+    // Handy little class that indents a stream.
71
+    // Based on solution provided here, todo may need to add to some managing class which keeps
72
+    // track of nesting levels? But perhaps not. A Lemma class will contain pointers to other Lemma
73
+    // classes. But those are not specifically listed out.
74
+    // http://stackoverflow.com/questions/9599807/how-to-add-indention-to-the-stream-operator
75
+    class IndentingOStreambuf : public std::streambuf {
76
+        std::streambuf*     myDest;
77
+        bool                myIsAtStartOfLine;
78
+        std::string         myIndent;
79
+        std::ostream*       myOwner;
80
+    protected:
81
+        virtual int         overflow( int ch )
82
+        {
83
+            if ( myIsAtStartOfLine && ch != '\n' ) {
84
+                myDest->sputn( myIndent.data(), myIndent.size() );
85
+            }
86
+            myIsAtStartOfLine = ch == '\n';
87
+            return myDest->sputc( ch );
88
+        }
89
+    public:
90
+        explicit            IndentingOStreambuf(
91
+                                std::streambuf* dest, int indent = 4 )
92
+            : myDest( dest )
93
+            , myIsAtStartOfLine( true )
94
+            , myIndent( indent, ' ' )
95
+            , myOwner( NULL )
96
+        {
97
+        }
98
+        explicit            IndentingOStreambuf(
99
+                                std::ostream& dest, int indent = 4 )
100
+            : myDest( dest.rdbuf() )
101
+            , myIsAtStartOfLine( true )
102
+            , myIndent( indent, ' ' )
103
+            , myOwner( &dest )
104
+        {
105
+            myOwner->rdbuf( this );
106
+        }
107
+        virtual             ~IndentingOStreambuf()
108
+        {
109
+            if ( myOwner != NULL ) {
110
+                myOwner->rdbuf( myDest );
111
+            }
112
+        }
113
+    };
114
+
115
+/** @}*/
116
+
117
+} // end namespace Lemma
118
+
119
+///////////////////////////////////////////////////////
120
+// YAML Serializing helper functions. Can we move this into helper.h
121
+namespace YAML {
122
+
123
+template<>
124
+struct convert<Lemma::Complex> {
125
+  static Node encode(const Lemma::Complex& rhs) {
126
+    Node node;
127
+    node["real"] = rhs.real();
128
+    node["imag"] = rhs.imag();
129
+
130
+    // No labels
131
+    //node.push_back(rhs.real());
132
+    //node.push_back(rhs.imag());
133
+
134
+    node.SetTag( "Complex" ); // too verbose?
135
+    return node;
136
+  }
137
+
138
+  static bool decode(const Node& node, Lemma::Complex& rhs) {
139
+    // Disabled due to overly verbose output. Just believe...
140
+    if( node.Tag() != "Complex" ) {
141
+        return false;
142
+    }
143
+    rhs = Lemma::Complex( node["real"].as<Lemma::Real>(), node["imag"].as<Lemma::Real>()  );
144
+    // no label style
145
+    //rhs = Lemma::Complex( node[0].as<Lemma::Real>(), node[1].as<Lemma::Real>()  );
146
+    return true;
147
+  }
148
+
149
+};
150
+
151
+template<>
152
+struct convert<Lemma::Vector3Xr> {
153
+  static Node encode(const Lemma::Vector3Xr& rhs) {
154
+    Node node;
155
+    node["size"] = rhs.cols();
156
+    //node["rows"] = rhs.rows(); // == 3
157
+    for (int ic=0; ic<rhs.cols(); ++ic) {
158
+        node[ic].push_back( rhs(0, ic) );
159
+        node[ic].push_back( rhs(1, ic) );
160
+        node[ic].push_back( rhs(2, ic) );
161
+    }
162
+    node.SetTag( "Vector3Xr" );
163
+    return node;
164
+  }
165
+
166
+  static bool decode(const Node& node, Lemma::Vector3Xr& rhs) {
167
+    if( node.Tag() != "Vector3Xr" ) {
168
+        return false;
169
+    }
170
+    rhs.resize( Eigen::NoChange, node["size"].as<int>() );
171
+    for (unsigned int ic=0; ic<node.size(); ++ic) {
172
+        int ir=0;
173
+        for(YAML::const_iterator it=node[ic].begin();it!=node[ic].end();++it) {
174
+            rhs(ir, ic) = it->as<Lemma::Real>();
175
+            ++ir;
176
+        }
177
+    }
178
+    return true;
179
+  }
180
+};
181
+
182
+template<>
183
+struct convert<Lemma::VectorXr> {
184
+  static Node encode(const Lemma::VectorXr& rhs) {
185
+    Node node;
186
+    node["size"] = rhs.size();
187
+    for (int ic=0; ic<rhs.size(); ++ic) {
188
+        node["data"].push_back( rhs(ic) );
189
+    }
190
+    node.SetTag( "VectorXr" );
191
+    return node;
192
+  }
193
+
194
+  static bool decode(const Node& node, Lemma::VectorXr& rhs) {
195
+    if( node.Tag() != "VectorXr" ) {
196
+        return false;
197
+    }
198
+    rhs.resize( node["size"].as<int>() );
199
+    int ir=0;
200
+    for(YAML::const_iterator it=node["data"].begin(); it!=node["data"].end(); ++it) {
201
+        rhs(ir) = it->as<Lemma::Real>();
202
+        ++ir;
203
+    }
204
+    return true;
205
+  }
206
+};
207
+
208
+template<>
209
+struct convert<Lemma::VectorXcr> {
210
+  static Node encode(const Lemma::VectorXcr& rhs) {
211
+    Node node;
212
+    node["size"] = rhs.size();
213
+    for (int ic=0; ic<rhs.size(); ++ic) {
214
+        node["data"].push_back( rhs(ic) );
215
+    }
216
+    node.SetTag( "VectorXcr" );
217
+    return node;
218
+  }
219
+
220
+  static bool decode(const Node& node, Lemma::VectorXcr& rhs) {
221
+    if( node.Tag() != "VectorXcr" ) {
222
+        return false;
223
+    }
224
+    rhs.resize( node["size"].as<int>() );
225
+    int ir=0;
226
+    for(YAML::const_iterator it=node["data"].begin(); it!=node["data"].end(); ++it) {
227
+        rhs(ir) = it->as<Lemma::Complex>();
228
+        ++ir;
229
+    }
230
+    return true;
231
+  }
232
+};
233
+
234
+
235
+template<>
236
+struct convert<Lemma::VectorXi> {
237
+  static Node encode(const Lemma::VectorXi& rhs) {
238
+    Node node;
239
+    node["size"] = rhs.size();
240
+    for (int ic=0; ic<rhs.size(); ++ic) {
241
+        node["data"].push_back( rhs(ic) );
242
+    }
243
+    node.SetTag( "VectorXi" );
244
+    return node;
245
+  }
246
+
247
+  static bool decode(const Node& node, Lemma::VectorXi& rhs) {
248
+    if( node.Tag() != "VectorXi" ) {
249
+        return false;
250
+    }
251
+    rhs.resize( node["size"].as<int>() );
252
+    int ir=0;
253
+    for(YAML::const_iterator it=node["data"].begin(); it!=node["data"].end(); ++it) {
254
+        rhs(ir) = it->as<int>();
255
+        ++ir;
256
+    }
257
+    return true;
258
+  }
259
+};
260
+
261
+template<>
262
+struct convert<Lemma::Vector3r> {
263
+  static Node encode(const Lemma::Vector3r& rhs) {
264
+    Node node;
265
+    for (int ic=0; ic<rhs.size(); ++ic) {
266
+        node[0].push_back( rhs(ic) );
267
+    }
268
+    node.SetTag( "Vector3r" );
269
+    return node;
270
+  }
271
+
272
+  static bool decode(const Node& node, Lemma::Vector3r& rhs) {
273
+    if( node.Tag() != "Vector3r" ) {
274
+        return false;
275
+    }
276
+    int ir=0;
277
+    for(YAML::const_iterator it=node[0].begin(); it!=node[0].end(); ++it) {
278
+        rhs(ir) = it->as<Lemma::Real>();
279
+        ++ir;
280
+    }
281
+    return true;
282
+  }
283
+};
284
+
285
+}
286
+
287
+#endif   // ----- #ifndef HELPER_INC  -----
288
+

+ 333
- 0
Modules/LemmaCore/include/lemma.h Zobrazit soubor

@@ -0,0 +1,333 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     06/19/2009 09:12:20 AM  The Birth of Lemma!
11
+  @version  $Id: lemma.h 203 2015-01-09 21:19:04Z tirons $
12
+ **/
13
+
14
+/** \mainpage Lemma is an ElectroMagnetics Modelling API
15
+    \image html lemma.png
16
+
17
+    \authors Trevor Irons and M. Andrew Kass and others
18
+
19
+    Lemma is a recursive acronym that stands for <B>L</B>emma is an
20
+    <B>E</B>lectro<B>M</B>agnetics <B>M</B>odelling <B>A</B>PI.
21
+    Lemma is a cross-platform library delivering an expressive API that
22
+    can be used to easily create versatile programs.
23
+    We are building a powerful, flexible,
24
+    expresive framework that allows for the straightforward creation of
25
+    geophysical EM applications. Lemma is not itself a program, instead
26
+    it is a collection of building blocks to make applications.
27
+    We chose this name because:
28
+
29
+    - In mathematics a Lemma is a proven proposition which is used as a
30
+    stepping stone to a larger result rather than as a statement in-and-of
31
+    itself.
32
+    - In addition to the electromagnetic modelling, some other facilities are
33
+    provided such as numerical optimization and inversion capabilities. These
34
+    tools are also considered stepping stones to final products.
35
+
36
+    We feel that this is a partucularily approprate name, as Lemma's
37
+    API can be leveraged create powerful applications such as forward
38
+    modelling and inverting frequency and time-domain
39
+    surveys of arbitrary survey design, SNMR surveys, CSAMT and more.
40
+
41
+    \section Motivation
42
+    Why another Geophysical EM project? For starters, there
43
+    aren't that many quality open source packages out there. Those that do
44
+    exist are generally specialized to perform a single task and extending
45
+    them is a major undertaking. Lemma's approach is much different, by
46
+    providing a set of general tools users can easily assemble applications
47
+    that suite their needs.
48
+
49
+    While most geophysical EM modeling packages are concerned with forward
50
+    modeling <B>DATA</B> between specific transmitters and receivers located
51
+    on the surface of the earth; Lemma is fundamentally concerned with
52
+    modelling <B>FIELDS</B> due to sources, the field values can be calculated
53
+    everywhere within the domain. This allows for solving multiphysics EM
54
+    problems. Tradional EM data may be forward modelled using the Lemma::Instrument
55
+    classes.
56
+
57
+    \section Capabilities Capabilities
58
+    In the long term, we have many goals for this software project. Due to its
59
+    design, Lemma can be built upon and extended easily. The initial aim is to
60
+    provide flexible 1D and 3D EM modelling in the time and frequency domains.
61
+    The project is still in beta, but we have made a lot of progress already.
62
+    We will release our first non-beta release as soon as the following are
63
+    supported.
64
+
65
+    \subsection FDM Frequency-domain forward modelling
66
+    Lemma was initially called EMMODFD: Electromagnetic Modelling in the Frequency
67
+    Domain. As such this is the most mature area of Lemma.
68
+
69
+    \par 1D
70
+    Frequency domain solutions to electrical and magnetic dipoles can be computed
71
+    quasi-analytically in 1D. Calculations can be made in or above the layered
72
+    media, and complex electrical conductivity and magnetic susceptibility are
73
+    supported according to the Cole-Cole model. Sources may be embdedded in the
74
+    media or in the resisitive air layer. Lemma can also can compute fields due
75
+    to arbitrarily shaped ungrounded wire loops, topography of the loops is also
76
+    supported. Two separate approaches to solving the Hankel transform, one
77
+    based on Anderson's digitial filtering technique, and another based on Gaussian
78
+    quadrature.
79
+
80
+    \par 3D
81
+    A fast 3D solver that can modify the 1D results based
82
+    on arbitrary electrical conductivity model is nearing completion.
83
+
84
+    \par future work
85
+    We are also planning on supporting grounded wires in the near future.
86
+
87
+    \subsection TDM Time-domain forward modelling
88
+	A 1D time-domain solution has been implemented that utilises both a
89
+	dipole source as well as a wire loop.  Currently, only one receiver is
90
+	modelled at a time, but will be generalised.  In addition, utilities
91
+	to read in data files for modelling have been implemented.
92
+    We would like to offer 3D time domain support, but this will not be
93
+    provided before our first stable release.
94
+
95
+    \subsection DataFormats Data Formats
96
+    The EM community is plagued with myriad data formats. Often each equiptment
97
+    manufacturer provides their own data format and interoperability is a
98
+    constant struggle. We are working on a flexible data format based on the XML
99
+    format that can be adapted to many types of data. The template for this
100
+    format will be publically released and we hope it catches on in the community.
101
+    At the least, it will provide a mechanism to compare datasets and datatypes
102
+    within Lemma.
103
+
104
+    \section Modules Modules
105
+    Due to Lemma's design, it is easy to extend the platform. In some cases this
106
+    extension results in adding functionality that is not directly related to
107
+    ElectroMagnetics. The following modules utilise parts of Lemma to provide
108
+    their functionality.
109
+
110
+    \subsection Merlin Merlin.
111
+    This module provides nuclear magnetic resonance functionality.
112
+
113
+
114
+    \section Tutorials
115
+        - \ref Tutorial - Basic intruduction to Lemma, including aquiring and
116
+          compiling the code, class structure, and building your own
117
+          applications.
118
+        - \ref Extending Tutorial on how to extend Lemma.
119
+
120
+
121
+    \section Development Development and design
122
+    Ths package is primarily being developed by the Center for Gravity,
123
+    Electrical, and Magnetic Studies (CGEM) at the Colorado School of Mines (CSM), the United
124
+    States Geological Survey (USGS), and Broken Spoke Development, LLC. It draws on work by
125
+    many others including Ki Ha Lee, and Walt Anderson. All new work and
126
+    interfaces are written entirely in C++. Several small external projects are
127
+    included, which are written in standard C, and FORTRAN 77. We adapt a
128
+    modern, test driven, object oriented, C++ framework.
129
+
130
+    \section Legalities
131
+
132
+    \subsection Copyrights
133
+    The following copyrights apply to the source.
134
+    Most of the code was developed either by Trevor
135
+    Copyright (C) 2008-2010 Trevor Irons <tirons@mines.edu> or
136
+    M. Andrew Kass Copyright (C) 2010 <mkass@numericalgeo.com>.
137
+
138
+    The 1D EM solver was derived (but updated heavily) from a fortran
139
+    programme written by Ki Ha Lee in 1984. We have communicated with Ki Ha,
140
+    and he assured us that this code is in the public domian.
141
+
142
+    A Gaussian quadrature hankel transform originally written by Alan Chave was
143
+    ported to C++. This code is in the public domain, and was published in Geophysics.
144
+
145
+    A digital filtering approach to the Hankel transform written by Walt
146
+    Anderson was also rewritten for Lemma. The origional fortran code is also in
147
+    the public domain. Using this Hankel transform works
148
+    arround the copyright issue mentioned above, but may not produce accurate
149
+    results for high frequencies.
150
+
151
+    Please note that Ki Ha Lee and Walt Anderson had no part in this work, and
152
+    the above should not be interpreted as any sort of endorsement by those
153
+    parties.
154
+
155
+    \subsection License
156
+
157
+    This Source Code Form is subject to the terms of the Mozilla Public
158
+    License, v. 2.0. If a copy of the MPL was not distributed with this
159
+    file, You can obtain one at http://mozilla.org/MPL/2.0/.
160
+
161
+    \section Contributing Suggestions and contributions
162
+        We welcome contributions and suggestions. Feel free to email the development
163
+        team at info@lemmasoftware.org.
164
+        Under the terms of the MPL, if you modify a Lemma file, you are obligated to
165
+        share those contributions back with the community.
166
+
167
+    \section Useful Useful links
168
+        - Home page https://lemmasoftware.org
169
+        - SVN repository https://svn.lemmasoftware.org
170
+        - Broken Spoke Develpment http://numericalgeo.com
171
+        - CGEM at the Coloroado School of Mines http://geophysics.mines.edu/cgem/
172
+**/
173
+
174
+#pragma once
175
+
176
+#ifndef __LEMMA_H
177
+#define __LEMMA_H
178
+
179
+    // Include some basic stuff that will always be needed
180
+    #include <iostream>
181
+    #include <iomanip>
182
+    #include <complex>
183
+    #include <fstream>
184
+    #include <string>
185
+    #include <vector>
186
+    #include <stdexcept>
187
+    #include <sstream>
188
+
189
+    #include <Eigen/Core>
190
+    #include <cstddef>
191
+    #include <Eigen/StdVector>
192
+    #include <Eigen/Sparse>
193
+    #include <unsupported/Eigen/FFT>
194
+    //#include <unsupported/Eigen/SparseExtra>
195
+    #include <Eigen/Geometry>
196
+
197
+    /** \brief The only namespace used by Lemma
198
+     *
199
+     *  \details The rational behind this namespace is that built-in
200
+     *  types should be used wherever possible, but not
201
+     *  not built-in names. This allows for code that is better
202
+     *  enacsulated and easier to modify. The typedefs and constants
203
+     *  specified here are defined so that
204
+     *  precision/inplimentation can easily be changed.
205
+     *  All floating precision types should be typedefed in this file
206
+     *  and should not be used natively within any code.
207
+     *  Lemma uses
208
+     *  the Eigen Matrix/Vector/Linear Algebra library.
209
+     *  <http://eigen.tuxfamily.org> and a lot of the namespece typedefs
210
+     *  are specifying Eigen types.
211
+     */
212
+    namespace Lemma {
213
+
214
+        /// Real defines precision for the whole API, default is double
215
+#ifdef  LEMMA_SINGLE_PRECISION
216
+        typedef float Real;
217
+#else      // -----      LEMMA_SINGLE_PRECISION  -----
218
+        typedef double Real;
219
+#endif     // -----  not LEMMA_SINGLE_PRECISION  -----
220
+
221
+        /// Complex version of Real.
222
+        typedef std::complex<Real> Complex;
223
+
224
+        /// A 3 component Eigen vector of Reals
225
+        typedef Eigen::Matrix<Real, 3, 1> Vector3r;
226
+
227
+        /// A 3 X Dynamic Component Eigen matrix of Reals
228
+        typedef Eigen::Matrix<Real, 3, Eigen::Dynamic> Vector3Xr;
229
+
230
+        /// Variable length Eigen vector of Reals
231
+        typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> VectorXr;
232
+
233
+        /// Variable length Eigen vector of integers (int)
234
+        typedef Eigen::Matrix<int, Eigen::Dynamic, 1> VectorXi;
235
+
236
+        /// Variable length Eigen vector of Complexes
237
+        typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> VectorXcr;
238
+
239
+        /// A 3 Component Eigen vector of Complexes
240
+        typedef Eigen::Matrix<Complex, 3, 1> Vector3cr;
241
+
242
+        /// A 3 X Dynamic Component Eigen matrix of Complexes
243
+        typedef Eigen::Matrix<Complex, 3, Eigen::Dynamic> Vector3Xcr;
244
+
245
+        /// Variable length Eigen Matrix of Reals
246
+        typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic> MatrixXr;
247
+
248
+        /// Variable length Eigen Matrix of ints
249
+        typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> MatrixXi;
250
+
251
+        /// Variable length Eigen vector of Complexes
252
+        typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> MatrixXcr;
253
+
254
+        ////////////////////////////////////////
255
+        // Constants used across the programmes
256
+
257
+        /// Restating the obvious, this is pi
258
+        const Real PI = 4.0*atan(1.0);
259
+
260
+        /// Permitivity of Free Space
261
+        //const Real EPSILON0 = 8.854187817e-12;
262
+        const Real EPSILON0 = 8.854187817e-12;
263
+
264
+        /// Permeability of free space
265
+        const Real MU0 = 4.*PI*1e-7;
266
+
267
+        /// 1/4 of \f$ \pi\f$
268
+        const Real QPI = .25/PI;
269
+
270
+        /// Some functions will convert units from SI (standard) to Gauss
271
+        /// This is because NMR calculations are much more natural in Gauss
272
+        enum MAGUNITS  {TESLA, NANOTESLA, GAUSS};
273
+
274
+        /// Unit of temperature entered
275
+        enum TEMPUNITS {CELCIUS, KELVIN};
276
+
277
+        /// Unit of time entered
278
+        enum TIMEUNITS {SEC, MILLISEC, MICROSEC, NANOSEC, PICOSEC};
279
+
280
+        /// Unit of time entered
281
+        enum FREQUENCYUNITS {HZ, KHZ, MHZ, GHZ};
282
+
283
+		/// FEM coil relative orientations
284
+		enum FEMCOILORIENTATION {COAXIAL, COPLANAR};
285
+
286
+		/// General orientation relative to coordinate system
287
+		enum ORIENTATION {X, Y, Z, NX, NY, NZ};
288
+
289
+        /// Type of field
290
+        enum FIELDTYPE         {HFIELDREAL, HFIELDIMAG, EFIELDREAL, EFIELDIMAG};
291
+
292
+        /// Compenent of vector field
293
+        enum FIELDCOMPONENT    {XCOMPONENT=0, YCOMPONENT=1, ZCOMPONENT=2};
294
+
295
+        /// Spatial component of vector
296
+        enum SPATIALCOORDINANT  {XCOORD=0, YCOORD=1, ZCOORD=2};
297
+
298
+        /** Evaluation method for Hankel integrals.
299
+         *  ANDERSON801     Walt Anderson's 801 point filter
300
+         *  CHAVE           Alan Chave's gaussian quadrature integration method
301
+         *  FHTKEY201       Key's 201 point filter
302
+         *  FHTKEY201       Key's 101 point filter
303
+         *  FHTKEY51        Key's 51 point filter
304
+         *  QWEKEY          Key's Gaussian quadrature integration method
305
+         */
306
+        enum HANKELTRANSFORMTYPE { ANDERSON801, CHAVE, FHTKEY201, FHTKEY101, FHTKEY51, QWEKEY };
307
+
308
+        /** Enum is OK because these are the only physically possible sources.
309
+         @param NOSOURCETYPE is default.
310
+         @param ELECTRICDIPOLE is an electric dipole
311
+         @param MAGNETICDIPOLE is a magnetic dipole
312
+        */
313
+        enum DipoleSourceType {NOSOURCETYPE, GROUNDEDELECTRICDIPOLE, UNGROUNDEDELECTRICDIPOLE, MAGNETICDIPOLE};
314
+
315
+        /// Only three polarizations are supported. They may be summed to
316
+        /// approximate others
317
+        /// @param NOPOLARISATION is uninitialized, default value
318
+        /// @param XPOLARISATION is a dipole oriented in the x direction
319
+        /// @param YPOLARISATION is a dipole oriented in the y direction
320
+        /// @param ZPOLARISATION is a dipole oriented in the z direction
321
+        enum DipoleSourcePolarisation {NOPOLARISATION, XPOLARISATION,
322
+            YPOLARISATION,  ZPOLARISATION};
323
+
324
+        /// The polarity may be either negative or positinve
325
+        enum DipoleSourcePolarity {NEGATIVE, POSITIVE};
326
+
327
+        /** The fields to make calculations on
328
+        */
329
+        enum FIELDCALCULATIONS {E, H, BOTH};
330
+
331
+    }
332
+
333
+#endif // __Lemma_H

+ 82
- 0
Modules/LemmaCore/include/timer.h Zobrazit soubor

@@ -0,0 +1,82 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     01/27/2010
11
+  @version  $Id: timer.h 87 2013-09-05 22:44:05Z tirons $
12
+ **/
13
+
14
+#ifndef  TIMER_H_INC
15
+#define  TIMER_H_INC
16
+
17
+#include <iostream>
18
+#include <fstream>
19
+#include <ctime>
20
+#ifdef LEMMAUSEOMP
21
+#include "omp.h"
22
+#endif
23
+
24
+#include "lemma.h"
25
+
26
+namespace Lemma {
27
+
28
+/** \brief Simple timer class.
29
+  * \details Can be used either with multithreaded applications, using
30
+  * OpenMP defined functions, or using system wall time. System wall time
31
+  * is not good for parallel programs as it reports cpu core execution time.
32
+  */
33
+class jsw_timer {
34
+
35
+    public:
36
+
37
+        /**
38
+          * Constructor that automatically starts the timer.
39
+          */
40
+        jsw_timer(): start ( std::clock() ), elapsed ( 0.0 ) {
41
+
42
+        }
43
+
44
+        /** begins the timer.
45
+          */
46
+        void begin() {
47
+            #ifdef LEMMAUSEOMP
48
+            start =  omp_get_wtime();
49
+            #else
50
+            start = std::clock();
51
+            #endif
52
+            elapsed = 0.0;
53
+        }
54
+
55
+        /** Ends the timer.
56
+          * @return the time that the stopwatch ended at.
57
+          */
58
+        Real end() {
59
+
60
+            #ifdef LEMMAUSEOMP
61
+            elapsed = static_cast<Real> (omp_get_wtime()) - start;
62
+            return elapsed;
63
+            #else
64
+            elapsed = static_cast<Real> ( std::clock() ) - start;
65
+            return elapsed /= CLOCKS_PER_SEC;
66
+            #endif
67
+
68
+        }
69
+
70
+        /**
71
+          * @return the elapsed time between start and end.
72
+          */
73
+        Real last() const { return elapsed; }
74
+
75
+    private:
76
+        std::clock_t start;
77
+        Real    elapsed;
78
+};
79
+
80
+}       // -----  end of Lemma  name  -----
81
+
82
+#endif   // ----- #ifndef TIMER_H_INC  -----

+ 238
- 0
Modules/LemmaCore/src/ASCIIParser.cpp Zobrazit soubor

@@ -0,0 +1,238 @@
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      09/23/2013 02:33:41 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2013, Trevor Irons
17
+ */
18
+
19
+#include "ASCIIParser.h"
20
+
21
+namespace Lemma {
22
+
23
+
24
+    // ====================  FRIEND METHODS  =====================
25
+
26
+    std::ostream &operator << (std::ostream &stream, const ASCIIParser &ob) {
27
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
28
+        return stream;
29
+    }
30
+
31
+    // ====================  LIFECYCLE     =======================
32
+
33
+    //--------------------------------------------------------------------------------------
34
+    //       Class:  ASCIIParser
35
+    //      Method:  ASCIIParser
36
+    // Description:  constructor (protected)
37
+    //--------------------------------------------------------------------------------------
38
+    ASCIIParser::ASCIIParser ( ) : LemmaObject( ),
39
+            CommentString("//"), BufferSize(255) {
40
+
41
+    }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
42
+
43
+
44
+    //--------------------------------------------------------------------------------------
45
+    //       Class:  ASCIIParser
46
+    //      Method:  NewSP()
47
+    // Description:  public smart pointer factory constructor
48
+    //--------------------------------------------------------------------------------------
49
+    std::shared_ptr< ASCIIParser > ASCIIParser::NewSP() {
50
+        std::shared_ptr<ASCIIParser> sp(new  ASCIIParser( ), LemmaObjectDeleter() );
51
+        return sp;
52
+        //return  std::make_shared<ASCIIParser>();
53
+    }
54
+
55
+    //--------------------------------------------------------------------------------------
56
+    //       Class:  ASCIIParser
57
+    //      Method:  Serialize
58
+    //--------------------------------------------------------------------------------------
59
+    YAML::Node  ASCIIParser::Serialize (  ) const {
60
+        YAML::Node node = LemmaObject::Serialize();;
61
+        node.SetTag( GetName() );
62
+        node["CommentString"] = CommentString;
63
+        node["BufferSize"] = BufferSize;
64
+        return node;
65
+    }		// -----  end of method ASCIIParser::Serialize  -----
66
+
67
+    //--------------------------------------------------------------------------------------
68
+    //       Class:  ASCIIParser
69
+    //      Method:  DeSerialize
70
+    //--------------------------------------------------------------------------------------
71
+    std::shared_ptr<ASCIIParser> ASCIIParser::DeSerialize ( const YAML::Node& node  ) {
72
+        if (node.Tag() != "ASCIIParser") {
73
+            throw  DeSerializeTypeMismatch( "ASCIIParser", node.Tag());
74
+        }
75
+        std::shared_ptr<ASCIIParser> Object(new  ASCIIParser(node), LemmaObjectDeleter() );
76
+        return Object ;
77
+    }		// -----  end of method ASCIIParser::DeSerialize  -----
78
+
79
+    //--------------------------------------------------------------------------------------
80
+    //       Class:  ASCIIParser
81
+    //      Method:  ~ASCIIParser
82
+    // Description:  destructor (protected)
83
+    //--------------------------------------------------------------------------------------
84
+    ASCIIParser::~ASCIIParser () {
85
+
86
+    }  // -----  end of method ASCIIParser::~ASCIIParser  (destructor)  -----
87
+
88
+    //--------------------------------------------------------------------------------------
89
+    //       Class:  ASCIIParser
90
+    //      Method:  ASCIIParser
91
+    // Description:  DeSerializing constructor (protected)
92
+    //--------------------------------------------------------------------------------------
93
+    ASCIIParser::ASCIIParser (const YAML::Node& node) : LemmaObject(node) {
94
+        this->CommentString = node["CommentString"].as<std::string>();
95
+        this->BufferSize = node["BufferSize"].as<int>();
96
+    }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
97
+
98
+    //--------------------------------------------------------------------------------------
99
+    //       Class:  ASCIIParser
100
+    //      Method:  Release
101
+    // Description:  destructor (protected)
102
+    //--------------------------------------------------------------------------------------
103
+    void ASCIIParser::Release() {
104
+        delete this;
105
+    }
106
+
107
+    //--------------------------------------------------------------------------------------
108
+    //       Class:  ASCIIParser
109
+    //      Method:  Open
110
+    //--------------------------------------------------------------------------------------
111
+    void ASCIIParser::Open ( const std::string& fname ) {
112
+        input.open(fname.c_str(), std::ios::in);
113
+        if (input.fail()) {
114
+           throw  GenericFileIOError(this, fname);
115
+        }
116
+        return ;
117
+    }		// -----  end of method ASCIIParser::Open  -----
118
+
119
+
120
+    //--------------------------------------------------------------------------------------
121
+    //       Class:  ASCIIParser
122
+    //      Method:  Close
123
+    //--------------------------------------------------------------------------------------
124
+    void ASCIIParser::Close (  ) {
125
+        input.close();
126
+        return ;
127
+    }		// -----  end of method ASCIIParser::Close  -----
128
+
129
+
130
+    //--------------------------------------------------------------------------------------
131
+    //       Class:  ASCIIParser
132
+    //      Method:  ReadReals
133
+    //--------------------------------------------------------------------------------------
134
+    std::vector<Real> ASCIIParser::ReadReals ( const int& nr ) {
135
+        std::string buf;
136
+        char *dump = new char[BufferSize];
137
+        std::vector<Real> vals(0);
138
+        while (input >> buf) {
139
+            if (buf.substr(0, CommentString.size()) == CommentString) {
140
+                input.getline(dump, BufferSize);
141
+            } else {
142
+                vals.push_back( atof(buf.c_str() ));
143
+            }
144
+            if (static_cast<int>(vals.size()) == nr) {
145
+                delete [] dump;
146
+                return vals;
147
+            }
148
+        }
149
+        delete [] dump;
150
+        return vals;
151
+    }		// -----  end of method ASCIIParser::ReadReals  -----
152
+
153
+    //--------------------------------------------------------------------------------------
154
+    //       Class:  ASCIIParser
155
+    //      Method:  ReadInts
156
+    //--------------------------------------------------------------------------------------
157
+    std::vector<int> ASCIIParser::ReadInts ( const int& nr ) {
158
+        std::string buf;
159
+        char *dump = new char[BufferSize];
160
+        std::vector<int> vals(0);
161
+        while (input >> buf) {
162
+            if (buf.substr(0, CommentString.size()) == CommentString) {
163
+                input.getline(dump, BufferSize);
164
+            } else {
165
+                vals.push_back( atoi(buf.c_str() ));
166
+            }
167
+            if (static_cast<int>(vals.size()) == nr) {
168
+                delete [] dump;
169
+                return vals;
170
+            }
171
+
172
+        }
173
+        delete [] dump;
174
+        return vals;
175
+    }		// -----  end of method ASCIIParser::ReadInts  -----
176
+
177
+    //--------------------------------------------------------------------------------------
178
+    //       Class:  ASCIIParser
179
+    //      Method:  ReadStings
180
+    //--------------------------------------------------------------------------------------
181
+    std::vector<std::string> ASCIIParser::ReadStrings ( const int& nr ) {
182
+        std::string buf;
183
+        char *dump = new char[BufferSize];
184
+        std::vector<std::string> vals(0);
185
+        while (input >> buf) {
186
+            if (buf.substr(0, CommentString.size()) == CommentString) {
187
+                input.getline(dump, BufferSize);
188
+            } else {
189
+                vals.push_back( buf );
190
+            }
191
+            if (static_cast<int>(vals.size()) == nr) {
192
+                delete [] dump;
193
+                return vals;
194
+            }
195
+
196
+        }
197
+        delete [] dump;
198
+        return vals;
199
+    }		// -----  end of method ASCIIParser::ReadInts  -----
200
+
201
+
202
+    //--------------------------------------------------------------------------------------
203
+    //       Class:  ASCIIParser
204
+    //      Method:  SetCommentString
205
+    //--------------------------------------------------------------------------------------
206
+    void ASCIIParser::SetCommentString ( const std::string& key ) {
207
+        CommentString = key;
208
+    }		// -----  end of method ASCIIParser::SetCommentString  -----
209
+
210
+    //--------------------------------------------------------------------------------------
211
+    //       Class:  ASCIIParser
212
+    //      Method:  SetBufferSize
213
+    //--------------------------------------------------------------------------------------
214
+    void ASCIIParser::SetBufferSize ( const int& size ) {
215
+        BufferSize = size;
216
+    }		// -----  end of method ASCIIParser::SetCommentString  -----
217
+
218
+    //--------------------------------------------------------------------------------------
219
+    //       Class:  ASCIIParser
220
+    //      Method:  GetFileLocation
221
+    //--------------------------------------------------------------------------------------
222
+    int ASCIIParser::GetFileLocation (  ) {
223
+        return input.tellg();
224
+    }		// -----  end of method ASCIIParser::GetFileLocation  -----
225
+
226
+    //--------------------------------------------------------------------------------------
227
+    //       Class:  ASCIIParser
228
+    //      Method:  JumpToLocation
229
+    //--------------------------------------------------------------------------------------
230
+    void ASCIIParser::JumpToLocation ( const int& loc ) {
231
+        input.seekg( loc );
232
+        return ;
233
+    }		// -----  end of method ASCIIParser::JumpToLocation  -----
234
+
235
+
236
+}		// -----  end of Lemma  name  -----
237
+
238
+

+ 20
- 0
Modules/LemmaCore/src/CMakeLists.txt Zobrazit soubor

@@ -0,0 +1,20 @@
1
+set (SOURCE 
2
+	${SOURCE}
3
+	${CMAKE_CURRENT_SOURCE_DIR}/helper.cpp
4
+	${CMAKE_CURRENT_SOURCE_DIR}/banner.cpp
5
+	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp
6
+	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp
7
+	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp
8
+	${CMAKE_CURRENT_SOURCE_DIR}/DataReader.cpp
9
+	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp
10
+	${CMAKE_CURRENT_SOURCE_DIR}/Instrument.cpp
11
+	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp
12
+	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
13
+	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp       
14
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp
15
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp
16
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridVTKExporter.cpp
17
+	${CMAKE_CURRENT_SOURCE_DIR}/Filter.cpp
18
+	${CMAKE_CURRENT_SOURCE_DIR}/WindowFilter.cpp
19
+	PARENT_SCOPE
20
+)

+ 355
- 0
Modules/LemmaCore/src/CubicSplineInterpolator.cpp Zobrazit soubor

@@ -0,0 +1,355 @@
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      02/07/2014 12:50:52 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, Trevor Irons
17
+ */
18
+
19
+#include "CubicSplineInterpolator.h"
20
+
21
+#include<iostream>
22
+#include<fstream>
23
+#include<vector>
24
+#include<algorithm>
25
+#include<cmath>
26
+
27
+namespace Lemma {
28
+
29
+    // ====================  FRIEND METHODS  =====================
30
+
31
+    std::ostream &operator << (std::ostream &stream, const CubicSplineInterpolator &ob) {
32
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
33
+        return stream;
34
+    }
35
+
36
+    // ====================  LIFECYCLE     =======================
37
+
38
+    //--------------------------------------------------------------------------------------
39
+    //       Class:  CubicSplineInterpolator
40
+    //      Method:  CubicSplineInterpolator
41
+    // Description:  constructor (protected)
42
+    //--------------------------------------------------------------------------------------
43
+    CubicSplineInterpolator::CubicSplineInterpolator ( ) : LemmaObject( ) {
44
+
45
+    }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
46
+
47
+    //--------------------------------------------------------------------------------------
48
+    //       Class:  CubicSplineInterpolator
49
+    //      Method:  CubicSplineInterpolator
50
+    // Description:  DeSerializing constructor (protected)
51
+    //--------------------------------------------------------------------------------------
52
+    CubicSplineInterpolator::CubicSplineInterpolator (const YAML::Node& node) : LemmaObject(node) {
53
+    }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
54
+
55
+    //--------------------------------------------------------------------------------------
56
+    //       Class:  CubicSplineInterpolator
57
+    //      Method:  NewSP()
58
+    // Description:  public constructor
59
+    //--------------------------------------------------------------------------------------
60
+    std::shared_ptr<CubicSplineInterpolator> CubicSplineInterpolator::NewSP() {
61
+        std::shared_ptr<CubicSplineInterpolator> sp(new  CubicSplineInterpolator( ), LemmaObjectDeleter() );
62
+        return sp;
63
+    }
64
+
65
+    //--------------------------------------------------------------------------------------
66
+    //       Class:  CubicSplineInterpolator
67
+    //      Method:  Serialize
68
+    //--------------------------------------------------------------------------------------
69
+    YAML::Node  CubicSplineInterpolator::Serialize (  ) const {
70
+        YAML::Node node = LemmaObject::Serialize();;
71
+        node.SetTag( GetName() );
72
+        // FILL IN CLASS SPECIFICS HERE
73
+        return node;
74
+    }		// -----  end of method CubicSplineInterpolator::Serialize  -----
75
+
76
+    //--------------------------------------------------------------------------------------
77
+    //       Class:  CubicSplineInterpolator
78
+    //      Method:  DeSerialize
79
+    //--------------------------------------------------------------------------------------
80
+    std::shared_ptr<CubicSplineInterpolator> CubicSplineInterpolator::DeSerialize ( const YAML::Node& node  ) {
81
+        if (node.Tag() != "CubicSplineInterpolator") {
82
+            throw  DeSerializeTypeMismatch( "CubicSplineInterpolator", node.Tag());
83
+        }
84
+        std::shared_ptr<CubicSplineInterpolator> Object(new  CubicSplineInterpolator(node), LemmaObjectDeleter() );
85
+        return Object ;
86
+    }
87
+
88
+    //--------------------------------------------------------------------------------------
89
+    //       Class:  CubicSplineInterpolator
90
+    //      Method:  ~CubicSplineInterpolator
91
+    // Description:  destructor (protected)
92
+    //--------------------------------------------------------------------------------------
93
+    CubicSplineInterpolator::~CubicSplineInterpolator () {
94
+
95
+    }  // -----  end of method CubicSplineInterpolator::~CubicSplineInterpolator  (destructor)  -----
96
+
97
+    //--------------------------------------------------------------------------------------
98
+    //       Class:  CubicSplineInterpolator
99
+    //      Method:  Release
100
+    // Description:  destructor (protected)
101
+    //--------------------------------------------------------------------------------------
102
+    void CubicSplineInterpolator::Release() {
103
+        delete this;
104
+    }
105
+
106
+    // ====================  OPERATIONS    =======================
107
+
108
+    //--------------------------------------------------------------------------------------
109
+    //       Class:  CubicSplineInterpolator
110
+    //      Method:  SetKnots
111
+    //--------------------------------------------------------------------------------------
112
+    void CubicSplineInterpolator::SetKnots ( const VectorXr& x, const VectorXr& y ) {
113
+
114
+        int n = x.size()-1;
115
+
116
+        Spline = SplineSet(n);
117
+
118
+        Spline.a = y;
119
+        Spline.x = x;
120
+        VectorXr h = VectorXr::Zero(n);
121
+        for(int i=0; i<n; ++i)
122
+            h(i) = Spline.x(i+1)-Spline.x(i);
123
+
124
+        VectorXr alpha(n-1);
125
+        for(int i=1; i<n-1; ++i)
126
+            alpha(i) =  3.*(Spline.a[i+1]-Spline.a[i])/h[i] - 3.*(Spline.a[i]-Spline.a[i-1])/h[i-1] ;
127
+
128
+        VectorXr l = VectorXr::Zero(n+1);
129
+        VectorXr mu  = VectorXr::Zero(n+1);
130
+        VectorXr z = VectorXr::Zero(n+1);
131
+        l[0] = 1;
132
+        mu[0] = 0;
133
+        z[0] = 0;
134
+
135
+        for(int i = 1; i < n-1; ++i) {
136
+            l[i] = 2 *(Spline.x[i+1]-Spline.x[i-1])-h[i-1]*mu[i-1];
137
+            mu[i] = h[i]/l[i];
138
+            z[i] = (alpha[i]-h[i-1]*z[i-1])/l[i];
139
+        }
140
+        l[n] = 1;
141
+        z[n] = 0;
142
+
143
+        for(int j = n-1; j >= 0; --j) {
144
+            Spline.c[j] = z[j] - mu[j] * Spline.c[j+1];
145
+            Spline.b[j] = (Spline.a[j+1]-Spline.a[j])/h[j]-h[j]*(Spline.c[j+1]+2*Spline.c[j])/3;
146
+            Spline.d[j] = (Spline.c[j+1]-Spline.c[j])/3/h[j];
147
+        }
148
+        // On OSX, this causes a strange bug 'sometimes', alignment?
149
+        //Spline.c = Spline.c.head(n);
150
+
151
+        return;
152
+    }		// -----  end of method CubicSplineInterpolator::SetKnots  -----
153
+
154
+
155
+    //--------------------------------------------------------------------------------------
156
+    //       Class:  CubicSplineInterplator
157
+    //      Method:  ResetKnotOrdinate
158
+    //--------------------------------------------------------------------------------------
159
+    void CubicSplineInterpolator::ResetKnotOrdinate ( const VectorXr& y ) {
160
+        VectorXr x = Spline.x;
161
+        SetKnots(x, y);
162
+        return ;
163
+    }		// -----  end of method CubicSplineInterplator::ResetKnotOrdinate  -----
164
+
165
+
166
+    //--------------------------------------------------------------------------------------
167
+    //       Class:  CubicSplineInterpolator
168
+    //      Method:  InterpolateOrderedSet
169
+    //--------------------------------------------------------------------------------------
170
+    VectorXr CubicSplineInterpolator::InterpolateOrderedSet ( const VectorXr& x ) {
171
+        VectorXr y = VectorXr::Zero(x.size());
172
+        int ii = 0;
173
+        for (int iy=0; iy<y.size(); ++iy) {
174
+            y[iy] = Interpolate(x[iy], ii);
175
+        }
176
+        return y;
177
+    }		// -----  end of method CubicSplineInterpolator::InterpolateOrderedSet  -----
178
+
179
+
180
+    //--------------------------------------------------------------------------------------
181
+    //       Class:  CubicSplineInterpolator
182
+    //      Method:  Interpolate
183
+    //--------------------------------------------------------------------------------------
184
+    Real CubicSplineInterpolator::Interpolate ( const Real& x, int& i) {
185
+        // O(n) search, could do bisection, but if these are sorted, then this is quick
186
+        while(Spline.x[i] < x && i<Spline.x.size()) {
187
+            ++i;
188
+        }
189
+        --i;
190
+
191
+        //if ( x > Spline.x[i] ) {
192
+        //    throw std::runtime_error("CubicSplineInterpolator::Interpolate ATTEMPT TO INTERPOLATE PAST LAST KNOT");
193
+        //}
194
+
195
+        return Spline.a[i] + Spline.b[i]*(x-Spline.x[i]) + Spline.c[i]*((x-Spline.x[i])*(x-Spline.x[i])) +
196
+               Spline.d[i]*((x-Spline.x[i])*(x-Spline.x[i])*(x-Spline.x[i]) );
197
+    }		// -----  end of method CubicSplineInterpolator::Interpolate  -----
198
+
199
+    //--------------------------------------------------------------------------------------
200
+    //       Class:  CubicSplineInterpolator
201
+    //      Method:  Interpolate
202
+    //--------------------------------------------------------------------------------------
203
+    Real CubicSplineInterpolator::Interpolate ( const Real& x ) {
204
+        int ii(0);
205
+        return Interpolate(x, ii);
206
+    }
207
+
208
+
209
+    //--------------------------------------------------------------------------------------
210
+    //       Class:  CubicSplineInterpolator
211
+    //      Method:  Integrate
212
+    //--------------------------------------------------------------------------------------
213
+    Real CubicSplineInterpolator::Integrate ( const Real& x0, const Real& x1, const int& n ) {
214
+
215
+        assert(n > 0);
216
+        // force n to be even?
217
+        //n += (n % 2);
218
+
219
+        Real S = Interpolate(x0) + Interpolate(x1);
220
+        Real h = (x1 - x0) / Real(n);
221
+
222
+        int ik = 0;
223
+        for (int i=1; i<n; i+=2) {
224
+            S += 4. * Interpolate(x0 + (Real)(i)*h, ik);
225
+        }
226
+
227
+        ik = 0;
228
+        for (int i=2; i<n-1; i+=2) {
229
+            S += 2. * Interpolate(x0 + (Real)(i)*h, ik);
230
+        }
231
+
232
+        return  S * h / 3.;
233
+    }
234
+
235
+
236
+    //--------------------------------------------------------------------------------------
237
+    //       Class:  CubicSplineInterpolator
238
+    //      Method:  Integrate
239
+    //--------------------------------------------------------------------------------------
240
+    Real CubicSplineInterpolator::Integrate ( const Real& x0, const Real& x1 ) {
241
+
242
+
243
+        int i0 = Interval(x0);
244
+        int i1 = Interval(x1);
245
+
246
+        Real h0 = x0 - Spline.x(i0);
247
+        if (mflag == -1) h0 = 0;
248
+        Real h1 = x1 - Spline.x(i1);
249
+
250
+        Real cubint = (((Spline.d(i1)*h1/4.0 + Spline.c(i1) )*h1/3.0 +
251
+                         Spline.b(i1) )*h1/2.0 + Spline.a(i1) )*h1
252
+                    - (((Spline.d(i0)*h0/4.0 + Spline.c(i0) )*h0/3.0 +
253
+                         Spline.b(i0) )*h0/2.0 + Spline.a(i0) )*h0;
254
+
255
+        // Include integrals over intervening intervals.
256
+        if (i1 > i0) {
257
+            for (int i=i0; i<i1-1; ++i) {
258
+                Real h = Spline.x(i+1) - Spline.x(i);
259
+                cubint +=  (((Spline.d(i)*h/4.0 + Spline.c(i) )*h/3.0 +
260
+                              Spline.b(i))*h/2.0 + Spline.a(i) )*h;
261
+            }
262
+        }
263
+        return cubint;
264
+    }		// -----  end of method CubicSplineInterpolator::Integrate  -----
265
+
266
+
267
+
268
+    //--------------------------------------------------------------------------------------
269
+    //       Class:  CubicSplineInterpolator
270
+    //      Method:  Interval
271
+    //--------------------------------------------------------------------------------------
272
+    int CubicSplineInterpolator::Interval ( const Real& x ) {
273
+
274
+        std::cerr << "ENTERING CubicSplineInterpolator::Inverval. Known bugs here"  << std::endl;
275
+        int nx = Spline.x.size() - 2; // TODO check if this is correct or just -1
276
+        // when x not in range
277
+        if (x <= Spline.x(0) || nx <= 1 ) {
278
+            mflag = -1;
279
+            return 1;
280
+        }
281
+
282
+        if (x >= Spline.x(nx)) {
283
+            mflag = 1;
284
+            return nx;
285
+        }
286
+
287
+        mflag = 0;
288
+        if (ilo >= nx) ilo = nx-1;
289
+        int ihi = ilo+1;
290
+
291
+        // if x is already in the interval
292
+        if ( x<Spline.x(ihi) && x >= Spline.x(ilo) ) {
293
+            //std::cout << "TRIVIAL INTERVAL " << Spline.x(ilo) << "\t" << x << "\t" << Spline.x(ihi) << std::endl;
294
+            return ilo;
295
+        }
296
+
297
+        if (x <= Spline.x(ilo)) { // decrease ilo to capture
298
+            int istep = 1;
299
+            for (int ix=1; ix<nx; ++ix) {
300
+                ihi = ilo;
301
+                ilo = ihi - istep;
302
+                ilo = std::max(1, ilo);
303
+                if (x >= Spline.x(ilo) || ilo == 1) break;
304
+                istep *= 2;
305
+            }
306
+        } else if (x >= Spline.x(ihi)) { // increase ihi to capture
307
+            int istep = 1;
308
+            for (int ix=1; ix<nx; ++ix) {
309
+                ilo = ihi;
310
+                ihi = ilo + istep;
311
+                ihi = std::min(ihi, nx);
312
+                if (x <= Spline.x(ihi) || ihi == nx) break;
313
+                istep *= 2;
314
+            }
315
+        }
316
+
317
+        // Now Spline.x(ilo) <= x < Spline.x(ihi) --> Narrow the interval.
318
+        //std::cout << "WIDE INTERVAL " << Spline.x(ilo) << "\t" << x << "\t" << Spline.x(ihi) << std::endl;
319
+        for (int ix=1; ix<nx; ++ix) {
320
+            int middle = (ilo+ihi) / 2;
321
+            if (middle == ilo) break;
322
+            if (x < Spline.x(middle)) {
323
+                ihi = middle;
324
+            } else {
325
+                ilo = middle;
326
+            }
327
+        }
328
+        assert ( Spline.x(ilo) < x && x < Spline.x(ihi) );
329
+        return ilo;
330
+    }		// -----  end of method CubicSplineInterpolator::Inverval  -----
331
+
332
+
333
+
334
+    //--------------------------------------------------------------------------------------
335
+    //       Class:  CubicSplineInterplator
336
+    //      Method:  GetAbscissa
337
+    //--------------------------------------------------------------------------------------
338
+    VectorXr CubicSplineInterpolator::GetKnotAbscissa (  ) {
339
+        return Spline.x;
340
+    }		// -----  end of method CubicSplineInterplator::get_GetAbscissa  -----
341
+
342
+
343
+    //--------------------------------------------------------------------------------------
344
+    //       Class:  CubicSplineInterpolator
345
+    //      Method:  GetKnotOrdinate
346
+    //--------------------------------------------------------------------------------------
347
+    VectorXr CubicSplineInterpolator::GetKnotOrdinate (  ) {
348
+        return Spline.a;
349
+    }		// -----  end of method CubicSplineInterpolator::GetKnotOrdinate  -----
350
+
351
+
352
+}		// -----  end of Lemma  name  -----
353
+
354
+/* vim: set tabstop=4 expandtab: */
355
+/* vim: set filetype=cpp: */

+ 30
- 0
Modules/LemmaCore/src/Data.cpp Zobrazit soubor

@@ -0,0 +1,30 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/01/2010
11
+  @version  $Id: data.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "Data.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const Data &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+	Data::Data(  ) : LemmaObject( ) {
24
+	}
25
+
26
+
27
+	Data::~Data() {
28
+	}
29
+
30
+}		// -----  end of Lemma  name  -----

+ 29
- 0
Modules/LemmaCore/src/DataReader.cpp Zobrazit soubor

@@ -0,0 +1,29 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/01/2010
11
+  @version  $Id: datareader.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "DataReader.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const DataReader &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+	DataReader::DataReader( ) : LemmaObject( ) {
24
+	}
25
+
26
+	DataReader::~DataReader() {
27
+	}
28
+
29
+}		// -----  end of Lemma  name  -----

+ 129
- 0
Modules/LemmaCore/src/EarthModel.cpp Zobrazit soubor

@@ -0,0 +1,129 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     03/23/2010
11
+  @version  $Id: earthmodel.cpp 210 2015-02-25 02:57:03Z tirons $
12
+ **/
13
+
14
+#include "EarthModel.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const EarthModel &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+	// ====================  LIFECYCLE     =======================
24
+
25
+	EarthModel::EarthModel() : LemmaObject( ),
26
+        BField(0,0,0), BFieldUnit(0,0,0), BInc(0), BDec(0), BMag(0) {
27
+	}
28
+
29
+    EarthModel::EarthModel(const YAML::Node& node) : LemmaObject(node) {
30
+        BInc = node["BInc"].as<double>();
31
+        BDec = node["BDec"].as<double>();
32
+        BMag = node["BMag"].as<double>();
33
+        BField = node["BField"].as<Vector3r>();
34
+    }
35
+
36
+
37
+    YAML::Node EarthModel::Serialize() const {
38
+        YAML::Node node = LemmaObject::Serialize();
39
+        node.SetTag( this->GetName() );
40
+        node["BField"] = BField;
41
+        node["BInc"] = BInc;
42
+        node["BDec"] = BDec;
43
+        node["BMag"] = BMag;
44
+        return node;
45
+    }
46
+
47
+	EarthModel::~EarthModel() {
48
+	}
49
+
50
+ 	// ====================  ACCESS        ===================================
51
+	void EarthModel::SetMagneticFieldComponents(const Vector3r &bfield,
52
+					const MAGUNITS &unit) {
53
+
54
+ 		this->BField = bfield;
55
+
56
+		switch (unit) {
57
+			case TESLA:
58
+				break;
59
+			case NANOTESLA:
60
+				BField *= 1e-9;
61
+				break;
62
+		  	case GAUSS:
63
+				BField *= 1e-4;
64
+				break;
65
+			default:
66
+				throw "MAGUNITS UNDEFINED\n";
67
+		}
68
+
69
+		BMag = bfield.norm(  );
70
+	    BInc = std::acos (bfield.dot(Vector3r(0,0,1)) / BMag) ;
71
+	    BDec = std::acos (bfield.dot(Vector3r(1,0,0)) / BMag) ;
72
+		BFieldUnit = BField.array() / BMag;
73
+ 	}
74
+
75
+	void EarthModel::SetMagneticFieldIncDecMag(const Real &inc,
76
+			const Real &dec, const Real &mag, const MAGUNITS &unit) {
77
+		BMag = mag;
78
+		BInc = inc;
79
+		BDec = dec;
80
+
81
+		switch (unit) {
82
+			case TESLA:
83
+				break;
84
+			case NANOTESLA:
85
+				BMag *= 1e-9;
86
+				break;
87
+		  	case GAUSS:
88
+				BMag *= 1e-4;
89
+				break;
90
+			default:
91
+				throw "MAGUNITS UNDEFINED\n";
92
+		}
93
+
94
+		BField(0) = BMag * cos(BInc*(PI/180.)) * cos(BDec*(PI/180.));
95
+		BField(1) = BMag * cos(BInc*(PI/180.)) * sin(BDec*(PI/180.));
96
+		BField(2) = BMag * sin(BInc*(PI/180.))  ;
97
+		BFieldUnit = BField.array() / BMag;
98
+	}
99
+
100
+	// ====================  INQUIRY       =======================
101
+
102
+	Vector3r EarthModel::GetMagneticField( ) {
103
+		return this->BField;
104
+	}
105
+
106
+    Vector3r EarthModel::GetMagneticFieldInGauss( ) {
107
+		return this->BField*1e4;
108
+	}
109
+
110
+	Vector3r EarthModel::GetMagneticFieldUnitVector() {
111
+		return this->BFieldUnit;
112
+	}
113
+
114
+	Real  EarthModel::GetMagneticFieldMagnitude() {
115
+		return this->BMag;
116
+	}
117
+
118
+	Real  EarthModel::GetMagneticFieldMagnitudeInGauss() {
119
+		return this->BMag*1e4;
120
+	}
121
+
122
+    ////////////////////////////////////////////////////////
123
+    // Error Classes
124
+
125
+    NullEarth::NullEarth() :
126
+        runtime_error( "NULL VALUED LAYERED EARTH MODEL") {}
127
+
128
+
129
+}		// -----  end of Lemma  name  -----

+ 22
- 0
Modules/LemmaCore/src/Filter.cpp Zobrazit soubor

@@ -0,0 +1,22 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     07/20/2010
11
+  @version  $Id: filter.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "Filter.h"
15
+
16
+namespace Lemma {
17
+
18
+    Filter::Filter( ) : LemmaObject( ) { }
19
+
20
+    Filter::~Filter( ) { }
21
+
22
+}		// -----  end of Lemma  name  -----

+ 43
- 0
Modules/LemmaCore/src/Grid.cpp Zobrazit soubor

@@ -0,0 +1,43 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     10/25/2009
11
+  @version  $Id: grid.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "Grid.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const Grid &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+    // ====================  LIFECYCLE     ===================================
24
+
25
+	Grid::Grid( ) : LemmaObject( ) {
26
+	}
27
+
28
+    Grid::Grid( const YAML::Node& node ) : LemmaObject(node) {
29
+
30
+    }
31
+
32
+	Grid::~Grid  ( ) {
33
+	}
34
+
35
+    YAML::Node Grid::Serialize() const {
36
+
37
+        YAML::Node node = LemmaObject::Serialize();
38
+        node.SetTag( this->GetName() );
39
+        return node;
40
+
41
+    }
42
+
43
+}

+ 29
- 0
Modules/LemmaCore/src/Instrument.cpp Zobrazit soubor

@@ -0,0 +1,29 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     02/05/2010
11
+  @version  $Id: instrument.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "Instrument.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const Instrument &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+	Instrument::Instrument( ) : LemmaObject() {
24
+	}
25
+
26
+	Instrument::~Instrument() {
27
+	}
28
+
29
+}		// -----  end of Lemma  name  -----

+ 130
- 0
Modules/LemmaCore/src/LayeredEarth.cpp Zobrazit soubor

@@ -0,0 +1,130 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     06/24/2009
11
+  @version  $Id: layeredearth.cpp 210 2015-02-25 02:57:03Z tirons $
12
+ **/
13
+
14
+#include "LayeredEarth.h"
15
+
16
+namespace Lemma {
17
+
18
+	// ====================    FRIENDS     ======================
19
+
20
+    std::ostream &operator << (std::ostream &stream, const LayeredEarth &ob) {
21
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
22
+        return stream;
23
+    }
24
+
25
+	// ====================  LIFECYCLE     ===================================
26
+
27
+	LayeredEarth::LayeredEarth( ) : EarthModel( ),
28
+		NumberOfLayers(0), 	NumberOfInterfaces(0) {
29
+	}
30
+
31
+
32
+
33
+	LayeredEarth::~LayeredEarth() {
34
+	}
35
+
36
+    LayeredEarth::LayeredEarth(const YAML::Node& node) : EarthModel(node)
37
+    {
38
+        NumberOfLayers = node["NumberOfLayers"].as<int>();
39
+        NumberOfInterfaces = node["NumberOfInterfaces"].as<int>();
40
+        LayerThickness = node["LayerThickness"].as<VectorXr>();
41
+	}
42
+
43
+    YAML::Node LayeredEarth::Serialize() const {
44
+        YAML::Node node = EarthModel::Serialize();
45
+        node["NumberOfLayers"] = NumberOfLayers;
46
+        node["NumberOfInterfaces"] = NumberOfInterfaces;
47
+        node["LayerThickness"] = LayerThickness;
48
+        node.SetTag( this->GetName() );
49
+        return node;
50
+    }
51
+
52
+	// ====================  OPERATIONS    ===================================
53
+
54
+	// ====================  ACCESS        ===================================
55
+
56
+	void LayeredEarth::SetLayerThickness(const VectorXr &thick) {
57
+		if (thick.size() != this->NumberOfLayers - 2)
58
+			throw EarthModelParametersDoNotMatchNumberOfLayers( );
59
+		LayerThickness = thick;
60
+	}
61
+
62
+	// ====================  INQUIRY       ===================================
63
+
64
+	int LayeredEarth::GetNumberOfLayers () {
65
+		return this->NumberOfLayers;
66
+	}
67
+
68
+	int LayeredEarth::GetNumberOfNonAirLayers () {
69
+		return this->NumberOfLayers - 1;
70
+	}
71
+
72
+	Real LayeredEarth::GetLayerThickness(const int &ilay) {
73
+		// Take into account infinite top and bottom layers
74
+		// estimate infinity by 1000 m
75
+		if (ilay < 0 || ilay > NumberOfLayers - 1) {
76
+			throw RequestForNonValidEarthModelParameter( );
77
+		} else if (ilay == 0) {
78
+			return 1000.;
79
+		} else if (ilay == NumberOfLayers - 1) {
80
+			return 1000.;
81
+		} else {
82
+			return this->LayerThickness(ilay-1);
83
+		}
84
+	}
85
+
86
+	Real LayeredEarth::GetLayerDepth(const int &ilay) {
87
+
88
+		Real depth = 0;
89
+
90
+
91
+		if (ilay == 0) {
92
+			return depth;
93
+		} else {
94
+			for (int i=1; i<=ilay; ++i) {
95
+				depth += GetLayerThickness(i);
96
+			}
97
+		}
98
+		return depth;
99
+	}
100
+
101
+	int LayeredEarth::GetLayerAtThisDepth(const Real& depth) {
102
+
103
+		if (depth <= 0 || NumberOfLayers < 2) {
104
+			return 0;
105
+		}
106
+
107
+		Real laydep = 0;
108
+		for (int ilay=0; ilay<NumberOfLayers-2; ++ilay) {
109
+			laydep += LayerThickness[ilay];
110
+			if (laydep >= depth) { return ilay+1; }
111
+		}
112
+
113
+		return NumberOfLayers-1;
114
+	}
115
+
116
+    EarthModelWithLessThanTwoLayers::EarthModelWithLessThanTwoLayers() :
117
+        runtime_error( "EARTH MODEL WITH LESS THAN TWO LAYERS") { }
118
+
119
+    EarthModelWithMoreThanMaxLayers::EarthModelWithMoreThanMaxLayers() :
120
+        runtime_error( "EARTH MODEL WITH MORE THAN MAX LAYERS") { }
121
+
122
+    EarthModelParametersDoNotMatchNumberOfLayers::
123
+        EarthModelParametersDoNotMatchNumberOfLayers( ) :
124
+        runtime_error( "EARTH MODEL PARAMETERS DO NOT MATCH NUMBER OF LAYERS")
125
+        {}
126
+
127
+    RequestForNonValidEarthModelParameter::
128
+        RequestForNonValidEarthModelParameter() :
129
+        runtime_error( "REQUEST FOR NON VALID EARTH MODEL PARAMETER") {}
130
+}

+ 86
- 0
Modules/LemmaCore/src/LemmaObject.cpp Zobrazit soubor

@@ -0,0 +1,86 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     06/25/2009
11
+  @version  $Id: LemmaObject.cpp 266 2015-04-01 03:24:00Z tirons $
12
+ **/
13
+
14
+#include "LemmaObject.h"
15
+
16
+namespace Lemma {
17
+
18
+    YAML::Emitter& operator << (YAML::Emitter& out, const LemmaObject& ob) {
19
+        out << YAML::BeginMap;
20
+        out << YAML::Key <<"Class Name"    << YAML::Value << ob.GetName();
21
+        return out;
22
+    }
23
+
24
+    // ====================  LIFECYCLE     ==============================
25
+
26
+    // Constructor
27
+    LemmaObject::LemmaObject(  ) {
28
+
29
+    }
30
+
31
+    LemmaObject::LemmaObject(const YAML::Node &node) {
32
+
33
+    }
34
+
35
+    // Destructor
36
+    LemmaObject::~LemmaObject() {
37
+    }
38
+
39
+    // ====================  OPERATIONS    ==============================
40
+
41
+    // ====================  INQUIRY       ==============================
42
+
43
+    // ====================  ACCESS        ==============================
44
+
45
+    // ====================  ACCESS        ==============================
46
+
47
+    // ====================  OPERATORS     ==============================
48
+
49
+    //////////////////////////////////////////////////////////////////////
50
+    //////////////////////////////////////////////////////////////////////
51
+
52
+    DeSerializeTypeMismatch::DeSerializeTypeMismatch(const std::string& expected, const std::string& got) :
53
+        runtime_error("DESERIALIZE TYPE MISMATCH") {
54
+            std::cerr << "Expected " << expected << " got " << got << std::endl;
55
+        }
56
+
57
+    RequestToReturnNullPointer::
58
+        RequestToReturnNullPointer(LemmaObject *ptr) :
59
+        runtime_error("REQUEST TO RETURN NULL POINTER"){
60
+            std::cerr << "Thrown by instance of "
61
+                      << ptr->GetName() << std::endl;
62
+        }
63
+
64
+    MatFileCannotBeOpened::
65
+        MatFileCannotBeOpened() :
66
+        runtime_error("MATFILE CANNOT BE OPENED"){}
67
+
68
+    AssignmentOutOfBounds::
69
+        AssignmentOutOfBounds(LemmaObject *ptr) :
70
+        runtime_error("ASSIGNMENT OUT OF BOUNDS"){
71
+            std::cerr << "Thrown by instance of "
72
+                      << ptr->GetName() << std::endl;
73
+       }
74
+
75
+	GenericFileIOError::
76
+		GenericFileIOError(LemmaObject *ptr, const std::string &filename) : runtime_error("FILE I/O ERROR"){
77
+			std::cerr << std::endl;
78
+			std::cerr << "FILE I/O ERROR" << std::endl;
79
+			std::cerr << std::endl;
80
+			std::cerr << "Thrown by instance of "
81
+				<< ptr->GetName() << std::endl;
82
+			std::cerr << "  while trying to access " << filename << std::endl;
83
+			std::cerr << std::endl;
84
+		}
85
+
86
+} // end of namespace Lemma

+ 215
- 0
Modules/LemmaCore/src/RectilinearGrid.cpp Zobrazit soubor

@@ -0,0 +1,215 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     10/28/2010
11
+  @version  $Id: rectilineargrid.cpp 193 2014-11-10 23:51:41Z tirons $
12
+ **/
13
+
14
+#include "RectilinearGrid.h"
15
+
16
+namespace Lemma {
17
+
18
+    std::ostream &operator << (std::ostream &stream, const RectilinearGrid &ob) {
19
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
20
+        return stream;
21
+    }
22
+
23
+    // ====================  LIFECYCLE     =======================
24
+
25
+    RectilinearGrid::RectilinearGrid( ) : Grid( ), nx(0), ny(0), nz(0) {
26
+
27
+    }
28
+
29
+    RectilinearGrid::RectilinearGrid( const YAML::Node& node ) : Grid(node) {
30
+
31
+        nx = node["nx"].as<int>( );
32
+        ny = node["ny"].as<int>( );
33
+        nz = node["nz"].as<int>( );
34
+
35
+        ox = node["ox"].as<Real>( );
36
+        oy = node["oy"].as<Real>( );
37
+        oz = node["oz"].as<Real>( );
38
+
39
+        dx = node["dx"].as< VectorXr >();
40
+        dy = node["dy"].as< VectorXr >();
41
+        dz = node["dz"].as< VectorXr >();
42
+
43
+    }
44
+
45
+    RectilinearGrid::~RectilinearGrid() {
46
+
47
+    }
48
+
49
+    std::shared_ptr< RectilinearGrid > RectilinearGrid::NewSP() {
50
+        std::shared_ptr<RectilinearGrid> sp(new  RectilinearGrid( ), LemmaObjectDeleter() );
51
+        return sp;
52
+    }
53
+
54
+    YAML::Node RectilinearGrid::Serialize() const {
55
+        YAML::Node node = Grid::Serialize();
56
+
57
+        node["nx"] = nx;
58
+        node["ny"] = ny;
59
+        node["nz"] = nz;
60
+
61
+        node["ox"] = ox;
62
+        node["oy"] = oy;
63
+        node["oz"] = oz;
64
+
65
+        node["dx"] = dx;
66
+        node["dy"] = dy;
67
+        node["dz"] = dz;
68
+
69
+        node.SetTag( this->GetName() );
70
+        return node;
71
+    }
72
+
73
+
74
+    //--------------------------------------------------------------------------------------
75
+    //       Class:  RectilinearGrid
76
+    //      Method:  DeSerialize
77
+    //--------------------------------------------------------------------------------------
78
+    std::shared_ptr<RectilinearGrid> RectilinearGrid::DeSerialize ( const YAML::Node& node  ) {
79
+        if (node.Tag() != "RectilinearGrid") {
80
+            throw  DeSerializeTypeMismatch( "RectilinearGrid", node.Tag());
81
+        }
82
+        std::shared_ptr<RectilinearGrid> Object(new  RectilinearGrid(node), LemmaObjectDeleter() );
83
+        return Object ;
84
+    }
85
+
86
+
87
+    // ====================  OPERATIONS    =======================
88
+
89
+    void RectilinearGrid::SetDimensions (const int &inx, const int &iny,
90
+            const int &inz) {
91
+        dx.resize(inx);
92
+        dy.resize(iny);
93
+        dz.resize(inz);
94
+        nx = inx;
95
+        ny = iny;
96
+        nz = inz;
97
+    }
98
+
99
+
100
+    void RectilinearGrid::SetOffset (const Real& iox, const Real& ioy, const Real& ioz) {
101
+        ox = iox;
102
+        oy = ioy;
103
+        oz = ioz;
104
+    }
105
+
106
+    void RectilinearGrid::SetSpacing (const VectorXr &idx, const VectorXr &idy,
107
+                const VectorXr &idz) {
108
+        nx = idx.size();
109
+        ny = idy.size();
110
+        nz = idz.size();
111
+        dx = idx;
112
+        dy = idy;
113
+        dz = idz;
114
+    }
115
+
116
+    //--------------------------------------------------------------------------------------
117
+    //       Class:  RectilinearGrid
118
+    //      Method:  GetNx
119
+    //--------------------------------------------------------------------------------------
120
+    int RectilinearGrid::GetNx (  ) {
121
+        return nx;
122
+    }		// -----  end of method RectilinearGrid::GetNx  -----
123
+
124
+    //--------------------------------------------------------------------------------------
125
+    //       Class:  RectilinearGrid
126
+    //      Method:  GetNy
127
+    //--------------------------------------------------------------------------------------
128
+    int RectilinearGrid::GetNy (  ) {
129
+        return ny;
130
+    }		// -----  end of method RectilinearGrid::GetNy  -----
131
+
132
+    //--------------------------------------------------------------------------------------
133
+    //       Class:  RectilinearGrid
134
+    //      Method:  GetNz
135
+    //--------------------------------------------------------------------------------------
136
+    int RectilinearGrid::GetNz (  ) {
137
+        return nz;
138
+    }		// -----  end of method RectilinearGrid::GetNz  -----
139
+
140
+    //--------------------------------------------------------------------------------------
141
+    //       Class:  RectilinearGrid
142
+    //      Method:  GetOx
143
+    //--------------------------------------------------------------------------------------
144
+    Real RectilinearGrid::GetOx (  ) {
145
+        return ox;
146
+    }		// -----  end of method RectilinearGrid::GetOx  -----
147
+
148
+    //--------------------------------------------------------------------------------------
149
+    //       Class:  RectilinearGrid
150
+    //      Method:  GetOy
151
+    //--------------------------------------------------------------------------------------
152
+    Real RectilinearGrid::GetOy (  ) {
153
+        return oy;
154
+    }		// -----  end of method RectilinearGrid::GetOy  -----
155
+
156
+    //--------------------------------------------------------------------------------------
157
+    //       Class:  RectilinearGrid
158
+    //      Method:  GetOz
159
+    //--------------------------------------------------------------------------------------
160
+    Real RectilinearGrid::GetOz (  ) {
161
+        return oz;
162
+    }		// -----  end of method RectilinearGrid::GetOz  -----
163
+
164
+    //--------------------------------------------------------------------------------------
165
+    //       Class:  RectilinearGrid
166
+    //      Method:  GetDx
167
+    //--------------------------------------------------------------------------------------
168
+    VectorXr RectilinearGrid::GetDx (  ) {
169
+        return dx;
170
+    }		// -----  end of method RectilinearGrid::GetDx  -----
171
+
172
+    //--------------------------------------------------------------------------------------
173
+    //       Class:  RectilinearGrid
174
+    //      Method:  GetDx
175
+    //--------------------------------------------------------------------------------------
176
+    Real RectilinearGrid::GetDx ( const int& ix  ) {
177
+        return dx[ix];
178
+    }		// -----  end of method RectilinearGrid::GetDx  -----
179
+
180
+    //--------------------------------------------------------------------------------------
181
+    //       Class:  RectilinearGrid
182
+    //      Method:  GetDy
183
+    //--------------------------------------------------------------------------------------
184
+    VectorXr RectilinearGrid::GetDy (  ) {
185
+        return dy;
186
+    }		// -----  end of method RectilinearGrid::GetDy  -----
187
+
188
+    //--------------------------------------------------------------------------------------
189
+    //       Class:  RectilinearGrid
190
+    //      Method:  GetDy
191
+    //--------------------------------------------------------------------------------------
192
+    Real RectilinearGrid::GetDy ( const int& iy  ) {
193
+        return dy[iy];
194
+    }		// -----  end of method RectilinearGrid::GetDy  -----
195
+
196
+    //--------------------------------------------------------------------------------------
197
+    //       Class:  RectilinearGrid
198
+    //      Method:  GetDz
199
+    //--------------------------------------------------------------------------------------
200
+    VectorXr RectilinearGrid::GetDz (  ) {
201
+        return dz;
202
+    }		// -----  end of method RectilinearGrid::GetDz  -----
203
+
204
+    //--------------------------------------------------------------------------------------
205
+    //       Class:  RectilinearGrid
206
+    //      Method:  GetDz
207
+    //--------------------------------------------------------------------------------------
208
+    Real RectilinearGrid::GetDz ( const int& iz  ) {
209
+        return dz[iz];
210
+    }		// -----  end of method RectilinearGrid::GetDz  -----
211
+
212
+}		// -----  end of Lemma  name  -----
213
+
214
+/* vim: set tabstop=4 expandtab: */
215
+/* vim: set filetype=cpp: */

+ 113
- 0
Modules/LemmaCore/src/RectilinearGridReader.cpp Zobrazit soubor

@@ -0,0 +1,113 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+
8
+/**
9
+  @file
10
+  @date      09/23/2013 11:05:48 AM
11
+  @version   $Id$
12
+  @author    Trevor Irons (ti)
13
+  @email     Trevor.Irons@xri-geo.com
14
+  @copyright Copyright (c) 2013, XRI Geophysics, LLC
15
+  @copyright Copyright (c) 2013, Trevor Irons
16
+ **/
17
+
18
+#include "RectilinearGridReader.h"
19
+
20
+namespace Lemma {
21
+
22
+    // ====================  FRIEND METHODS  =====================
23
+
24
+    std::ostream &operator << (std::ostream &stream, const RectilinearGridReader &ob) {
25
+        stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
26
+        return stream;
27
+    }
28
+
29
+    // ====================  LIFECYCLE     =======================
30
+
31
+    //--------------------------------------------------------------------------------------
32
+    //       Class:  RectilinearGridReader
33
+    //      Method:  RectilinearGridReader
34
+    // Description:  constructor (protected)
35
+    //--------------------------------------------------------------------------------------
36
+    RectilinearGridReader::RectilinearGridReader ( ) : GridReader( ),
37
+        rGrid( nullptr ), Parser( nullptr ) {
38
+
39
+    }  // -----  end of method RectilinearGridReader::RectilinearGridReader  (constructor)  -----
40
+
41
+
42
+    //--------------------------------------------------------------------------------------
43
+    //       Class:  RectilinearGridReader
44
+    //      Method:  NewSP()
45
+    // Description:  constructor
46
+    //--------------------------------------------------------------------------------------
47
+    std::shared_ptr< RectilinearGridReader > RectilinearGridReader::NewSP() {
48
+        std::shared_ptr<RectilinearGridReader> sp(new  RectilinearGridReader( ), LemmaObjectDeleter() );
49
+        return sp;
50
+    }
51
+
52
+
53
+
54
+    //--------------------------------------------------------------------------------------
55
+    //       Class:  RectilinearGridReader
56
+    //      Method:  ~RectilinearGridReader
57
+    // Description:  destructor (protected)
58
+    //--------------------------------------------------------------------------------------
59
+    RectilinearGridReader::~RectilinearGridReader () {
60
+    }  // -----  end of method RectilinearGridReader::~RectilinearGridReader  (destructor)  -----
61
+
62
+    //--------------------------------------------------------------------------------------
63
+    //       Class:  RectilinearGridReader
64
+    //      Method:  ReadASCIIGridFile
65
+    //--------------------------------------------------------------------------------------
66
+    void RectilinearGridReader::ReadASCIIGridFile ( const std::string& name  ) {
67
+
68
+        rGrid = RectilinearGrid::NewSP();
69
+        Parser = ASCIIParser::NewSP();
70
+
71
+        Parser->SetCommentString("//");
72
+
73
+        Parser->Open(name);
74
+
75
+        std::vector<int> vals = Parser->ReadInts(3);
76
+        rGrid->SetDimensions(vals[0], vals[1], vals[2]);
77
+
78
+        std::vector<Real> rvals = Parser->ReadReals(3);
79
+        rGrid->SetOffset(rvals[0], rvals[1], rvals[2]);
80
+        rvals.clear();
81
+
82
+        rvals = Parser->ReadReals( vals[0] );
83
+        VectorXr temp = VectorXr::Map(&rvals[0], vals[0]);
84
+        VectorXr hx = temp;
85
+
86
+        rvals.clear();
87
+        rvals = Parser->ReadReals( vals[1] );
88
+        VectorXr hy = VectorXr::Map(&rvals[0], vals[1]);
89
+
90
+        rvals.clear();
91
+        rvals = Parser->ReadReals( vals[2] );
92
+        VectorXr hz = VectorXr::Map(&rvals[0], vals[2]);
93
+
94
+        rGrid->SetSpacing(hx, hy, hz);
95
+
96
+        // Read in model(s)/data? Where should this be done?
97
+        Parser->Close();
98
+
99
+        return;
100
+
101
+    }		// -----  end of method RectilinearGridReader::ReadSCIIGridFile  -----
102
+
103
+
104
+    //--------------------------------------------------------------------------------------
105
+    //       Class:  RectilinearGridReader
106
+    //      Method:  GetGrid
107
+    //--------------------------------------------------------------------------------------
108
+    std::shared_ptr<Grid> RectilinearGridReader::GetGrid (  ) {
109
+        return std::static_pointer_cast<Grid> (rGrid);
110
+    }		// -----  end of method RectilinearGridReader::GetGrid  -----
111
+
112
+
113
+}		// -----  end of Lemma  name  -----

+ 147
- 0
Modules/LemmaCore/src/RectilinearGridVTKExporter.cpp Zobrazit soubor

@@ -0,0 +1,147 @@
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      09/25/2013 08:20:14 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2013, Trevor Irons
17
+ */
18
+
19
+#if  LEMMAUSEVTK
20
+
21
+#include "RectilinearGridVTKExporter.h"
22
+
23
+namespace Lemma {
24
+
25
+// ====================  FRIEND METHODS  =====================
26
+
27
+std::ostream &operator << (std::ostream &stream, const RectilinearGridVTKExporter &ob) {
28
+    stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
29
+    return stream;
30
+}
31
+
32
+
33
+// ====================  LIFECYCLE     =======================
34
+
35
+//--------------------------------------------------------------------------------------
36
+//       Class:  RectilinearGridVTKExporter
37
+//      Method:  RectilinearGridVTKExporter
38
+// Description:  constructor (protected)
39
+//--------------------------------------------------------------------------------------
40
+RectilinearGridVTKExporter::RectilinearGridVTKExporter ( ) : LemmaObject( ), Grid(nullptr), VTKGrid(nullptr) {
41
+
42
+}  // -----  end of method RectilinearGridVTKExporter::RectilinearGridVTKExporter  (constructor)  -----
43
+
44
+
45
+//--------------------------------------------------------------------------------------
46
+//       Class:  RectilinearGridVTKExporter
47
+//      Method:  NewSP()
48
+// Description:  public constructor
49
+//--------------------------------------------------------------------------------------
50
+std::shared_ptr< RectilinearGridVTKExporter > RectilinearGridVTKExporter::NewSP() {
51
+    std::shared_ptr<RectilinearGridVTKExporter> sp(new  RectilinearGridVTKExporter( ), LemmaObjectDeleter() );
52
+    return sp;
53
+}
54
+
55
+
56
+
57
+//--------------------------------------------------------------------------------------
58
+//       Class:  RectilinearGridVTKExporter
59
+//      Method:  ~RectilinearGridVTKExporter
60
+// Description:  destructor (protected)
61
+//--------------------------------------------------------------------------------------
62
+RectilinearGridVTKExporter::~RectilinearGridVTKExporter () {
63
+}  // -----  end of method RectilinearGridVTKExporter::~RectilinearGridVTKExporter  (destructor)  -----
64
+
65
+//--------------------------------------------------------------------------------------
66
+//       Class:  RectilinearGridVTKExporter
67
+//      Method:  SetGrid
68
+//--------------------------------------------------------------------------------------
69
+void RectilinearGridVTKExporter::SetGrid ( std::shared_ptr<RectilinearGrid> GridIn ) {
70
+    Grid = GridIn;
71
+    // I see no harm in just doing this now.
72
+    BuildVTKRectilinearGrid();
73
+    return ;
74
+}		// -----  end of method RectilinearGridVTKExporter::SetGrid  -----
75
+
76
+//--------------------------------------------------------------------------------------
77
+//       Class:  RectilinearGridVTKExporter
78
+//      Method:  GetVTKRectilinearGrid
79
+//--------------------------------------------------------------------------------------
80
+vtkSmartPointer<vtkRectilinearGrid> RectilinearGridVTKExporter::GetVTKGrid (  ) {
81
+    return VTKGrid;
82
+}		// -----  end of method RectilinearGridVTKExporter::GetVTKRectilinearGrid  -----
83
+
84
+//--------------------------------------------------------------------------------------
85
+//       Class:  RectilinearGridVTKExporter
86
+//      Method:  WriteVTKGrid
87
+//--------------------------------------------------------------------------------------
88
+void RectilinearGridVTKExporter::WriteVTKGrid ( const std::string& fname  ) {
89
+    vtkXMLRectilinearGridWriter *gridWrite = vtkXMLRectilinearGridWriter::New();
90
+        gridWrite->SetInputData(VTKGrid);
91
+        gridWrite->SetFileName( (fname+std::string(".vtr")).c_str() );
92
+        gridWrite->Update();
93
+        gridWrite->Write();
94
+        gridWrite->Delete();
95
+    return ;
96
+}		// -----  end of method RectilinearGridVTKExporter::WriteVTKGrid  -----
97
+
98
+//--------------------------------------------------------------------------------------
99
+//       Class:  RectilinearGridVTKExporter
100
+//      Method:  BuildVTKRectilinearGrid
101
+//--------------------------------------------------------------------------------------
102
+void RectilinearGridVTKExporter::BuildVTKRectilinearGrid (  ) {
103
+
104
+    // Set Coordinate>s
105
+    vtkDoubleArray *xCoords = vtkDoubleArray::New();
106
+    xCoords->InsertNextValue(Grid->GetOx()-Grid->GetDx(0)/2.);
107
+    double xm1 = Grid->GetOx() - Grid->GetDx(0)/2.;
108
+    for (int ix=0; ix<Grid->GetNx(); ix++) {
109
+        xCoords->InsertNextValue(xm1 + Grid->GetDx(ix));
110
+        xm1 += Grid->GetDx(ix);
111
+    }
112
+
113
+    vtkDoubleArray *yCoords = vtkDoubleArray::New();
114
+    yCoords->InsertNextValue(Grid->GetOy()-Grid->GetDy(0)/2.);
115
+    double ym1 = Grid->GetOy()-Grid->GetDy(0)/2.;
116
+    for (int iy=0; iy<Grid->GetNy(); iy++) {
117
+        yCoords->InsertNextValue(ym1 + Grid->GetDy(iy));
118
+        ym1 += Grid->GetDy(iy);
119
+    }
120
+
121
+    vtkDoubleArray *zCoords = vtkDoubleArray::New();
122
+    zCoords->InsertNextValue(Grid->GetOz()-Grid->GetDz(0)/2.);
123
+    double zm1 = Grid->GetOz()-Grid->GetDz(0)/2.;
124
+    for (int iz=0; iz<Grid->GetNz(); iz++) {
125
+        zCoords->InsertNextValue(zm1 + Grid->GetDz(iz));
126
+        zm1 += Grid->GetDz(iz);
127
+    }
128
+
129
+    VTKGrid = vtkSmartPointer<vtkRectilinearGrid>::New();
130
+        VTKGrid->SetDimensions(Grid->GetNx()+1, Grid->GetNy()+1, Grid->GetNz()+1);
131
+        VTKGrid->SetXCoordinates(xCoords);
132
+        VTKGrid->SetYCoordinates(yCoords);
133
+        VTKGrid->SetZCoordinates(zCoords);
134
+
135
+    // Clean up
136
+    xCoords->Delete();
137
+    yCoords->Delete();
138
+    zCoords->Delete();
139
+
140
+    return ;
141
+}		// -----  end of method RectilinearGridVTKExporter::BuildVTKRectilinearGrid  -----
142
+
143
+
144
+
145
+}		// -----  end of Lemma  name  -----
146
+
147
+#endif     // -----  not LEMMAUSEVTK  -----

+ 83
- 0
Modules/LemmaCore/src/WindowFilter.cpp Zobrazit soubor

@@ -0,0 +1,83 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   Trevor Irons
10
+  @date     07/20/2010
11
+  @version  $Id: windowfilter.cpp 87 2013-09-05 22:44:05Z tirons $
12
+ **/
13
+
14
+#include "WindowFilter.h"
15
+
16
+namespace Lemma {
17
+
18
+    // ====================  LIFECYCLE     =======================
19
+
20
+    WindowFilter::WindowFilter( ) : Filter( ),
21
+        Width(0), SamplingRate(0), Bandwidth(0), Coefficients(),
22
+        Type(RECTANGULAR) {}
23
+
24
+    std::shared_ptr< WindowFilter > WindowFilter::NewSP() {
25
+        std::shared_ptr<WindowFilter> sp(new  WindowFilter( ), LemmaObjectDeleter() );
26
+        return sp;
27
+    }
28
+
29
+    WindowFilter::~WindowFilter() {
30
+    }
31
+
32
+
33
+    // ====================  OPERATIONS    =======================
34
+
35
+    void WindowFilter::SetWindowType(const WINDOWTYPE &type) {
36
+        Type = type;
37
+    }
38
+
39
+    void WindowFilter::SetBandwidth(const Real& width) {
40
+        Bandwidth = width;
41
+    }
42
+
43
+    void WindowFilter::SetSamplingInterval(const Real& rate) {
44
+        SamplingRate = rate;
45
+    }
46
+
47
+    int WindowFilter::GetNumberOfFrequencyBins() {
48
+        return this->Nw;
49
+    }
50
+
51
+    void WindowFilter::SetNumberOfSamples(const int& nt) {
52
+        Nt = nt;
53
+        Nw = Nt%2 ? (Nt-1)/2+1 : (Nt)/2+1;  // odd , even
54
+    }
55
+
56
+    VectorXr WindowFilter::GetFilterCoefficients() {
57
+        Real  Nyquist = .5/SamplingRate;
58
+        std::cout << "Window nyquist " << Nyquist << std::endl;
59
+        std::cout << "Window Nw  " << Nw << std::endl;
60
+        Real  df      = (Nyquist)/((Real)(Nw)); // df Hz per bin
61
+        Width         = Bandwidth/df;
62
+        Coefficients.resize(Width);
63
+        switch (Type) {
64
+            case HAMMING:
65
+           	    for (int n=0; n<Width; ++n) {
66
+		            Coefficients(n) = 0.5 * (1.- std::cos( (2.*PI*(Real)(n)) /
67
+                                       ((Real)(Width)-1.) ) );
68
+	            }
69
+                break;
70
+            case HANNING:
71
+	            for (int n=0; n<Width; ++n) {
72
+		            Coefficients(n) = 0.54 - 0.46 *
73
+                                std::cos( (2.*PI*(Real)(n)) /
74
+                                    ((Real)(Width)-1.) ) ;
75
+	            }
76
+                break;
77
+            case RECTANGULAR:
78
+                Coefficients.setOnes();
79
+                break;
80
+        }
81
+        return Coefficients;
82
+    }
83
+}		// -----  end of Lemma  name  -----

+ 36
- 0
Modules/LemmaCore/src/banner.cpp Zobrazit soubor

@@ -0,0 +1,36 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+
7
+/**
8
+  @file
9
+  @author   M. Andy Kass
10
+  @date     05/03/2010
11
+  @version  $Id: banner.cpp 87 2013-09-05 22:44:05Z tirons $
12
+ **/
13
+
14
+#include "banner.h"
15
+
16
+///Prints banner information to the screen
17
+void banner(const std::string &name, const std::string &version,
18
+		const std::string &usage) {
19
+
20
+	std::cout << std::endl;
21
+	std::cout << "  " << name.c_str() << version.c_str() << std::endl;
22
+	std::cout << std::endl;
23
+	std::cout << "  A program built from Lemma v 1.0b" << std::endl;
24
+	std::cout << "  Usage: " << usage.c_str() << std::endl;
25
+	std::cout << std::endl;
26
+	std::cout << "  Developed jointly by the Center for Gravity, " <<
27
+		"Electrical, and Magnetic" <<std::endl;
28
+	std::cout << "   Studies (CGEM), the United States Geologic " <<
29
+		"Survey (USGS), and Broken" << std::endl;
30
+	std::cout << "   Spoke Development, LLC." <<std::endl;
31
+	std::cout << std::endl;
32
+	std::cout << "  (C) Copyright 2010, Trevor Irons and M. Andy Kass.  " <<
33
+		"Some rights reserved." << std::endl;
34
+	std::cout << "  Please see license for details." << std::endl;
35
+	std::cout << std::endl;
36
+}

+ 201
- 0
Modules/LemmaCore/src/helper.cpp Zobrazit soubor

@@ -0,0 +1,201 @@
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      10/02/2014 03:21:07 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "helper.h"
21
+
22
+namespace Lemma {
23
+
24
+std::string enum2String(const FREQUENCYUNITS& FreqUnits) {
25
+    std::string t;
26
+    switch (FreqUnits) {
27
+        case HZ:
28
+            t = std::string("HZ");
29
+            break;
30
+        case KHZ:
31
+            t = std::string("KHZ");
32
+            break;
33
+        case MHZ:
34
+            t = std::string("MHZ");
35
+            break;
36
+        case GHZ:
37
+            t = std::string("GHZ");
38
+            break;
39
+    }
40
+    return t;
41
+}
42
+
43
+std::string enum2String(const TIMEUNITS& Units) {
44
+    std::string t;
45
+    switch (Units) {
46
+        case SEC:
47
+            t = std::string("SEC");
48
+            break;
49
+        case MILLISEC:
50
+            t = std::string("MILLISEC");
51
+            break;
52
+        case MICROSEC:
53
+            t = std::string("MICROSEC");
54
+            break;
55
+        case NANOSEC:
56
+            t = std::string("NANOSEC");
57
+            break;
58
+        case PICOSEC:
59
+            t = std::string("PICOSEC");
60
+            break;
61
+    }
62
+    return t;
63
+}
64
+
65
+
66
+std::string enum2String(const MAGUNITS& Units) {
67
+    std::string t;
68
+    switch (Units) {
69
+        case TESLA:
70
+            t = std::string("TESLA");
71
+            break;
72
+        case NANOTESLA:
73
+            t = std::string("NANOTESLA");
74
+            break;
75
+        case GAUSS:
76
+            t = std::string("GAUSS");
77
+            break;
78
+    }
79
+    return t;
80
+}
81
+
82
+std::string enum2String(const FIELDCALCULATIONS& Field) {
83
+    std::string t;
84
+    switch (Field) {
85
+        case E:
86
+            t = std::string("E");
87
+            break;
88
+        case H:
89
+            t = std::string("H");
90
+            break;
91
+        case BOTH:
92
+            t = std::string("BOTH");
93
+            break;
94
+    }
95
+    return t;
96
+}
97
+
98
+
99
+std::string enum2String(const TEMPUNITS& Units) {
100
+    std::string t;
101
+    switch (Units) {
102
+        case CELCIUS:
103
+            t = std::string("CELCIUS");
104
+            break;
105
+        case KELVIN:
106
+            t = std::string("KELVIN");
107
+            break;
108
+    }
109
+    return t;
110
+}
111
+
112
+std::string enum2String(const FIELDCOMPONENT& Comp) {
113
+    std::string t;
114
+    switch (Comp) {
115
+        case XCOMPONENT:
116
+            t = std::string("XCOMPONENT");
117
+            break;
118
+        case YCOMPONENT:
119
+            t = std::string("YCOMPONENT");
120
+            break;
121
+        case ZCOMPONENT:
122
+            t = std::string("ZCOMPONENT");
123
+            break;
124
+    }
125
+    return t;
126
+}
127
+
128
+std::string enum2String(const HANKELTRANSFORMTYPE& Type) {
129
+    std::string t;
130
+    switch (Type) {
131
+        case ANDERSON801:
132
+            t = std::string("ANDERSON801");
133
+            break;
134
+        case CHAVE:
135
+            t = std::string("CHAVE");
136
+            break;
137
+        case QWEKEY:
138
+            t = std::string("QWEKEY");
139
+            break;
140
+        case FHTKEY201:
141
+            t = std::string("FHTKEY201");
142
+            break;
143
+        case FHTKEY101:
144
+            t = std::string("FHTKEY101");
145
+            break;
146
+        case FHTKEY51:
147
+            t = std::string("FHTKEY51");
148
+            break;
149
+    }
150
+    return t;
151
+}
152
+
153
+template<>
154
+FREQUENCYUNITS string2Enum<FREQUENCYUNITS>( const std::string& str ) {
155
+    if       (str ==  "HZ") return   HZ;
156
+    else if  (str == "KHZ") return  KHZ;
157
+    else if  (str == "MHZ") return  MHZ;
158
+    else if  (str == "GHZ") return  GHZ;
159
+    else {
160
+        throw std::runtime_error("string not recognized as FREUENCYUNIT");
161
+    }
162
+}
163
+
164
+template<>
165
+HANKELTRANSFORMTYPE string2Enum<HANKELTRANSFORMTYPE>( const std::string& str ) {
166
+    if       (str ==  "ANDERSON801") return   ANDERSON801;
167
+    else if  (str == "CHAVE") return  CHAVE;
168
+    else if  (str == "QWEKEY") return  QWEKEY;
169
+    else if  (str == "FHTKEY201") return  FHTKEY201;
170
+    else if  (str == "FHTKEY51") return  FHTKEY51;
171
+    else if  (str == "FHTKEY101") return  FHTKEY101;
172
+    else {
173
+        throw std::runtime_error("string not recognized as HANKELTRANSFORMTYPE");
174
+    }
175
+}
176
+
177
+
178
+template<>
179
+TIMEUNITS string2Enum<TIMEUNITS>( const std::string& str ) {
180
+    if       (str == "SEC")      return      SEC;
181
+    else if  (str == "MILLISEC") return MILLISEC;
182
+    else if  (str == "MICROSEC") return MICROSEC;
183
+    else if  (str == "NANOSEC")  return  NANOSEC;
184
+    else if  (str == "PICOSEC")  return  PICOSEC;
185
+    else {
186
+        throw std::runtime_error("string not recognized as TIMEUNIT");
187
+    }
188
+}
189
+
190
+template<>
191
+FIELDCOMPONENT string2Enum<FIELDCOMPONENT>( const std::string& str) {
192
+    if       (str == "XCOMPONENT")      return XCOMPONENT;
193
+    else if  (str == "YCOMPONENT")      return YCOMPONENT;
194
+    else if  (str == "ZCOMPONENT")      return ZCOMPONENT;
195
+    else {
196
+        throw std::runtime_error("string not recognized as FieldComponent");
197
+    }
198
+}
199
+
200
+}		// -----  end of Lemma  name  -----
201
+

+ 12
- 0
Modules/LemmaCore/testing/CMakeLists.txt Zobrazit soubor

@@ -0,0 +1,12 @@
1
+#add_executable(testOne testOne.cpp)
2
+#add_executable(testTwo testTwo.cpp)
3
+#add_test( testLemmaCoreOne testOne )
4
+#add_test( testLemmaCoreTwo testTwo )
5
+    	
6
+include_directories(${CXXTEST_INCLUDE_DIR})
7
+CXXTEST_ADD_TEST(unittest_GetNameCheck GetNameCheck.cc ${CMAKE_CURRENT_SOURCE_DIR}/GetNameCheck.h)
8
+target_link_libraries(unittest_GetNameCheck "lemmacore")
9
+
10
+CXXTEST_ADD_TEST(unittest_SerializeCheck SerializeCheck.cc ${CMAKE_CURRENT_SOURCE_DIR}/SerializeCheck.h)
11
+target_link_libraries(unittest_SerializeCheck "lemmacore")
12
+ 

+ 69
- 0
Modules/LemmaCore/testing/GetNameCheck.h Zobrazit soubor

@@ -0,0 +1,69 @@
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      06/16/2016 09:12:46 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, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include <cxxtest/TestSuite.h>
21
+#include <LemmaCore>
22
+
23
+using namespace Lemma;
24
+
25
+class MyTestSuite : public CxxTest::TestSuite
26
+{
27
+    public:
28
+
29
+    void testASCIIParser( void )
30
+    {
31
+        auto Obj = ASCIIParser::NewSP();
32
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("ASCIIParser") );
33
+    }
34
+
35
+    void testCubicSplineInterpolator(void)
36
+    {
37
+        auto Obj = CubicSplineInterpolator::NewSP();
38
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("CubicSplineInterpolator") );
39
+    }
40
+
41
+    void testRectilinearGrid( void )
42
+    {
43
+        auto Obj = RectilinearGrid::NewSP();
44
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGrid") );
45
+    }
46
+
47
+    void testRectilinearGridReader( void )
48
+    {
49
+        auto Obj = RectilinearGridReader::NewSP();
50
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridReader") );
51
+    }
52
+
53
+// INCLUDE GUARDS DON'T WORK WITH CXXTEST, NEED TO MOVE VTK TESTS OUT
54
+// #ifdef LEMMAUSEVTK
55
+//     void testRectilinearGridVTKExporter( void )
56
+//     {
57
+//         auto Obj = RectilinearGridVTKExporter::NewSP();
58
+//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridVTKExporter") );
59
+//     }
60
+// #endif
61
+
62
+    void testWindowFilter( void )
63
+    {
64
+        auto Obj = WindowFilter::NewSP();
65
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("WindowFilter") );
66
+    }
67
+
68
+};
69
+

+ 75
- 0
Modules/LemmaCore/testing/SerializeCheck.h Zobrazit soubor

@@ -0,0 +1,75 @@
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      06/16/2016 09:12:46 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, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include <cxxtest/TestSuite.h>
21
+#include <LemmaCore>
22
+
23
+using namespace Lemma;
24
+
25
+class MyTestSuite : public CxxTest::TestSuite
26
+{
27
+    public:
28
+
29
+    void testASCIIParser( void )
30
+    {
31
+        auto Obj = ASCIIParser::NewSP();
32
+        YAML::Node node = Obj->Serialize();
33
+        auto Obj2 = ASCIIParser::DeSerialize(node);
34
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
35
+    }
36
+
37
+
38
+    void testCubicSplineInterpolator(void)
39
+    {
40
+        auto Obj = CubicSplineInterpolator::NewSP();
41
+        YAML::Node node = Obj->Serialize();
42
+        auto Obj2 = CubicSplineInterpolator::DeSerialize(node);
43
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
44
+    }
45
+
46
+    void testRectilinearGrid( void )
47
+    {
48
+        auto Obj = RectilinearGrid::NewSP();
49
+        YAML::Node node = Obj->Serialize();
50
+        auto Obj2 = RectilinearGrid::DeSerialize(node);
51
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
52
+    }
53
+
54
+// /*
55
+//     void testRectilinearGridReader( void )
56
+//     {
57
+//         auto Obj = RectilinearGridReader::NewSP();
58
+//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridReader") );
59
+//     }
60
+//
61
+//     void testRectilinearGridVTKExporter( void )
62
+//     {
63
+//         auto Obj = RectilinearGridVTKExporter::NewSP();
64
+//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGridVTKExporter") );
65
+//     }
66
+//
67
+//     void testWindowFilter( void )
68
+//     {
69
+//         auto Obj = WindowFilter::NewSP();
70
+//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("WindowFilter") );
71
+//     }
72
+// */
73
+
74
+};
75
+

+ 23
- 0
Modules/LemmaCore/testing/testOne.cpp Zobrazit soubor

@@ -0,0 +1,23 @@
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      06/14/2016 09:30:38 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, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+int main() {
21
+    return 0;
22
+}
23
+

+ 23
- 0
Modules/LemmaCore/testing/testTwo.cpp Zobrazit soubor

@@ -0,0 +1,23 @@
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      06/14/2016 09:43:43 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, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+int main() {
21
+    return 0;
22
+}
23
+

+ 25
- 0
config/LemmaConfig.h.in Zobrazit soubor

@@ -0,0 +1,25 @@
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      01/15/2016 09:52:10 PM
13
+ * @author    Trevor Irons (ti)
14
+ * @email     tirons@egi.utah.edu
15
+ * @copyright Copyright (c) 2016, University of Utah
16
+ * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
17
+ */
18
+
19
+// the configured options and settings for Tutorial
20
+#define LEMMA_VERSION_MAJOR @LEMMA_VERSION_MAJOR@
21
+#define LEMMA_VERSION_MINOR @LEMMA_VERSION_MINOR@
22
+#define LEMMA_VERSION_PATCH @LEMMA_VERSION_PATCH@
23
+//#define LEMMA_VERSION @LEMMA_VERSION@
24
+
25
+

Načítá se…
Zrušit
Uložit