Bläddra i källkod

Towards a new Python wrapper

iss7
Trevor Irons 5 år sedan
förälder
incheckning
986324fbd5

+ 2
- 2
CMake/SuperBuild.cmake Visa fil

@@ -102,7 +102,7 @@ if (LEMMA_ENABLE_TESTING)
102 102
 endif()
103 103
 
104 104
 # tinyxml2, this library is used for XML IO 
105
-option( LEMMA_TINYXML_SUPPORT  "TinyXML library support for .xml files" OFF)
105
+#option( LEMMA_TINYXML_SUPPORT  "TinyXML library support for .xml files" OFF)
106 106
 if ( LEMMA_TINYXML_SUPPORT )
107 107
 	ExternalProject_Add(TINYXML2
108 108
 		GIT_REPOSITORY "https://github.com/leethomason/tinyxml2.git"
@@ -116,7 +116,7 @@ if ( LEMMA_TINYXML_SUPPORT )
116 116
 	add_compile_options(-DTINYXMLSUPPORT) 
117 117
 endif()
118 118
 
119
-option( LEMMA_MATIO_SUPPORT  "MATIO library support for MATLAB .mat files" OFF)
119
+#option( LEMMA_MATIO_SUPPORT  "MATIO library support for MATLAB .mat files" OFF)
120 120
 if ( LEMMA_MATIO_SUPPORT )
121 121
 	add_compile_options(-DHAVE_MATIO) 
122 122
 	# matio, this library is used for MATLAB file IO

+ 17
- 1
CMakeLists.txt Visa fil

@@ -47,6 +47,7 @@ option ( LEMMA_BUILD_EXAMPLES       "Compile example Lemma applications" OFF )
47 47
 option ( LEMMA_USE_OPENMP           "Use OpenMP in Lemma" OFF )
48 48
 option ( LEMMA_BUILD_DOCUMENTATION  "Build Doxygen man pages" OFF )
49 49
 option ( LEMMA_VTK8_SUPPORT         "VTK 8.x library for visualisation and grids" OFF )
50
+option ( LEMMA_PYTHON3_BINDINGS     "Compile Python 3 bindings" OFF )
50 51
 
51 52
 # We end up using this for all builds, TODO remove this variable but follow same path
52 53
 #option (CMAKE_CROSSCOMPILING "Target different arch than you are on" OFF)
@@ -118,6 +119,7 @@ else()
118 119
 endif()
119 120
 
120 121
 INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIR})
122
+
121 123
 if (VTK_VERSION VERSION_GREATER "8.2.0")
122 124
     message( STATUS "${VTK_VERSION} is compatible: ${VTK_VERSION_COMPATIBLE} exact? ${VTK_VERSION_EXACT}" )
123 125
     set (VTK_FOUND False) 
@@ -226,7 +228,7 @@ endif()
226 228
 option (LEMMA_USE_BOOST "Boost is required by gaussian quadrature classes" OFF)
227 229
 if (LEMMA_USE_BOOST)
228 230
 	find_package(Boost
229
-  		1.58.0                         # Minimum or EXACT version e.g. 1.36.0
231
+  		1.64.0                         # Minimum or EXACT version e.g. 1.36.0
230 232
 #  		COMPONENTS math                # Boost libraries by their canonical name
231 233
 	)  
232 234
 	if(Boost_FOUND)
@@ -242,6 +244,20 @@ if (LEMMA_USE_BOOST)
242 244
 	endif()
243 245
 endif()
244 246
 
247
+if (LEMMA_PYTHON3_BINDINGS)
248
+
249
+    find_package(PythonLibs 3.0 REQUIRED)
250
+    find_package(Boost 1.64.0   REQUIRED COMPONENTS system python3 numpy3)
251
+
252
+    # Is this OK for portability of non-python libraries
253
+    include_directories(${PYTHON_INCLUDE_DIRS})
254
+    include_directories(${Boost_INCLUDE_DIRS})
255
+
256
+endif()
257
+
258
+####################
259
+# MSVC error fix 
260
+####################
245 261
 option( MSVC_EXTENDED_ALIGNMENT "Turn on MSVC compiler definition _ENABLE_EXTENDED_ALIGNED_STORAGE " OFF  )
246 262
 if (MSVC_EXTENDED_ALIGNMENT)
247 263
     add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)

+ 3
- 0
Modules/FDEM1D/examples/CircularLoop.cpp Visa fil

@@ -46,6 +46,9 @@ int main(int argc, char** argv) {
46 46
         }
47 47
         wire->SetPoint(np-1, cx, cy+rad, -1e-3);
48 48
 
49
+    wire->SetNumberOfFrequencies(1);
50
+        wire->SetFrequency(0, 1);
51
+
49 52
     std::cout << *wire << std::endl;
50 53
 
51 54
     //auto wire2 = wire->Clone();

+ 151
- 0
Modules/FDEM1D/include/ChargedWellCasing.h Visa fil

@@ -0,0 +1,151 @@
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      14/04/19 14:25:07
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@utah.edu
16
+ * @copyright Copyright (c) 2019, University of Utah
17
+ * @copyright Copyright (c) 2019, Lemma Software, LLC
18
+ */
19
+
20
+
21
+#pragma once
22
+#include "LemmaObject.h"
23
+
24
+namespace Lemma {
25
+
26
+    /**
27
+     * \ingroup FDEM1D
28
+     * \brief
29
+     * \details
30
+     */
31
+    class ChargedWellCasing : public LemmaObject {
32
+
33
+        friend std::ostream &operator<<(std::ostream &stream, const ChargedWellCasing &ob);
34
+
35
+        protected:
36
+        /*
37
+         *  This key is used to lock the constructor. It is protected so that inhereted
38
+         *  classes also have the key to contruct their base class.
39
+         */
40
+        struct ctor_key {};
41
+
42
+        public:
43
+
44
+        // ====================  LIFECYCLE     =======================
45
+
46
+        /**
47
+         * Default constructor.
48
+         * @note This method is locked, and cannot be called directly.
49
+         *       The reason that the method is public is to enable the use
50
+         *       of make_shared whilst enforcing the use of shared_ptr,
51
+         *       in c++-17, this curiosity may be resolved.
52
+         * @see ChargedWellCasing::NewSP
53
+         */
54
+        explicit ChargedWellCasing ( const ctor_key& );
55
+
56
+        /**
57
+         * DeSerializing constructor.
58
+         * @note This method is locked, and cannot be called directly.
59
+         *       The reason that the method is public is to enable the use
60
+         *       of make_shared whilst enforcing the use of shared_ptr,
61
+         *       in c++-17, this curiosity may be resolved.
62
+         * @see ChargedWellCasing::DeSerialize
63
+         */
64
+        ChargedWellCasing ( const YAML::Node& node, const ctor_key& );
65
+
66
+        /**
67
+         * Default destructor.
68
+         * @note This method should never be called due to the mandated
69
+         *       use of smart pointers. It is necessary to keep the method
70
+         *       public in order to allow for the use of the more efficient
71
+         *       make_shared constructor.
72
+         */
73
+        virtual ~ChargedWellCasing ();
74
+
75
+        /**
76
+         *  Uses YAML to serialize this object.
77
+         *  @return a YAML::Node
78
+         *  @see ChargedWellCasing::DeSerialize
79
+         */
80
+        virtual YAML::Node Serialize() const;
81
+
82
+        /*
83
+         *  Factory method for generating concrete class.
84
+         *  @return a std::shared_ptr of type ChargedWellCasing
85
+         */
86
+        static std::shared_ptr< ChargedWellCasing > NewSP();
87
+
88
+        /**
89
+         *   Constructs an ChargedWellCasing object from a YAML::Node.
90
+         *   @see ChargedWellCasing::Serialize
91
+         */
92
+        static std::shared_ptr<ChargedWellCasing> DeSerialize(const YAML::Node& node);
93
+
94
+        // ====================  OPERATORS     =======================
95
+
96
+        // ====================  OPERATIONS    =======================
97
+
98
+        // ====================  ACCESS        =======================
99
+
100
+        /**
101
+         *  Many boreholes have numerous segments of varying thickness.
102
+         *  @param[in] The number of segments that the borehole contains.
103
+         */
104
+        void SetNumberOfSegments( const int& ns ) {
105
+            NumberOfSegments = ns;
106
+        }
107
+
108
+        /**
109
+         * @return The number of segments
110
+         */
111
+        int GetNumberOfSegments( void );
112
+
113
+        // ====================  INQUIRY       =======================
114
+        /**
115
+         *  Returns the name of the underlying class, similiar to Python's type
116
+         *  @return string of class name
117
+         */
118
+        virtual inline std::string GetName() const {
119
+            return CName;
120
+        }
121
+
122
+        protected:
123
+
124
+        // ====================  LIFECYCLE     =======================
125
+
126
+        /** Copy is disabled */
127
+        ChargedWellCasing( const ChargedWellCasing& ) = delete;
128
+
129
+        // ====================  DATA MEMBERS  =========================
130
+
131
+        private:
132
+
133
+        /** ASCII string representation of the class name */
134
+        static constexpr auto CName = "ChargedWellCasing";
135
+
136
+        /** Total number of casing segments */
137
+        int NumberOfSegments;
138
+
139
+        VectorXr OutsideDiameter;
140
+
141
+        VectorXr InsideDiameter;
142
+
143
+        VectorXr SegmentConductivity;
144
+
145
+    }; // -----  end of class  ChargedWellCasing  -----
146
+}  // -----  end of namespace Lemma ----
147
+
148
+/* vim: set tabstop=4 expandtab: */
149
+/* vim: set filetype=cpp: */
150
+
151
+

+ 1
- 0
Modules/FDEM1D/include/FDEM1D Visa fil

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include "WireAntenna.h"
9 9
 #include "PolygonalWireAntenna.h"
10
+#include "ChargedWellCasing.h"
10 11
 
11 12
 #include "DipoleSource.h"
12 13
 

+ 2
- 0
Modules/FDEM1D/src/CMakeLists.txt Visa fil

@@ -16,6 +16,8 @@ set (FDEM1DSOURCE
16 16
 	${CMAKE_CURRENT_SOURCE_DIR}/WireAntenna.cpp
17 17
 	${CMAKE_CURRENT_SOURCE_DIR}/PolygonalWireAntenna.cpp
18 18
 
19
+	${CMAKE_CURRENT_SOURCE_DIR}/ChargedWellCasing.cpp
20
+
19 21
 	# Kernel management	
20 22
 	${CMAKE_CURRENT_SOURCE_DIR}/KernelEM1DManager.cpp
21 23
 	${CMAKE_CURRENT_SOURCE_DIR}/KernelEM1DSpec.cpp

+ 97
- 0
Modules/FDEM1D/src/ChargedWellCasing.cpp Visa fil

@@ -0,0 +1,97 @@
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      14/04/19 15:39:02
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@utah.edu
16
+ * @copyright Copyright (c) 2019, University of Utah
17
+ * @copyright Copyright (c) 2019, Lemma Software, LLC
18
+ */
19
+
20
+
21
+#include "ChargedWellCasing.h"
22
+
23
+namespace Lemma {
24
+
25
+    // ====================  FRIEND METHODS  =====================
26
+
27
+    std::ostream &operator << (std::ostream &stream, const ChargedWellCasing &ob) {
28
+        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
29
+        return stream;
30
+    }
31
+
32
+    // ====================  LIFECYCLE     =======================
33
+
34
+    //--------------------------------------------------------------------------------------
35
+    //       Class:  ChargedWellCasing
36
+    //      Method:  ChargedWellCasing
37
+    // Description:  constructor (locked)
38
+    //--------------------------------------------------------------------------------------
39
+    ChargedWellCasing::ChargedWellCasing (const ctor_key&) : LemmaObject( LemmaObject::ctor_key()  ) {
40
+
41
+    }  // -----  end of method ChargedWellCasing::ChargedWellCasing  (constructor)  -----
42
+
43
+    //--------------------------------------------------------------------------------------
44
+    //       Class:  ChargedWellCasing
45
+    //      Method:  ChargedWellCasing
46
+    // Description:  DeSerializing constructor (locked)
47
+    //--------------------------------------------------------------------------------------
48
+    ChargedWellCasing::ChargedWellCasing (const YAML::Node& node, const ctor_key&) :
49
+        LemmaObject(node, LemmaObject::ctor_key()) {
50
+
51
+    }  // -----  end of method ChargedWellCasing::ChargedWellCasing  (constructor)  -----
52
+
53
+    //--------------------------------------------------------------------------------------
54
+    //       Class:  ChargedWellCasing
55
+    //      Method:  NewSP()
56
+    // Description:  public constructor returing a shared_ptr
57
+    //--------------------------------------------------------------------------------------
58
+    std::shared_ptr< ChargedWellCasing >  ChargedWellCasing::NewSP() {
59
+        return std::make_shared< ChargedWellCasing >( ctor_key() );
60
+    }
61
+
62
+    //--------------------------------------------------------------------------------------
63
+    //       Class:  ChargedWellCasing
64
+    //      Method:  ~ChargedWellCasing
65
+    // Description:  destructor (protected)
66
+    //--------------------------------------------------------------------------------------
67
+    ChargedWellCasing::~ChargedWellCasing () {
68
+
69
+    }  // -----  end of method ChargedWellCasing::~ChargedWellCasing  (destructor)  -----
70
+
71
+    //--------------------------------------------------------------------------------------
72
+    //       Class:  ChargedWellCasing
73
+    //      Method:  Serialize
74
+    //--------------------------------------------------------------------------------------
75
+    YAML::Node  ChargedWellCasing::Serialize (  ) const {
76
+        YAML::Node node = LemmaObject::Serialize();
77
+        node.SetTag( GetName() );
78
+        // FILL IN CLASS SPECIFICS HERE
79
+        return node;
80
+    }		// -----  end of method ChargedWellCasing::Serialize  -----
81
+
82
+    //--------------------------------------------------------------------------------------
83
+    //       Class:  ChargedWellCasing
84
+    //      Method:  DeSerialize
85
+    //--------------------------------------------------------------------------------------
86
+    std::shared_ptr<ChargedWellCasing> ChargedWellCasing::DeSerialize ( const YAML::Node& node  ) {
87
+        if (node.Tag() !=  "ChargedWellCasing" ) {
88
+            throw  DeSerializeTypeMismatch( "ChargedWellCasing", node.Tag());
89
+        }
90
+        return std::make_shared< ChargedWellCasing > ( node, ctor_key() );
91
+    }		// -----  end of method ChargedWellCasing::DeSerialize  -----
92
+
93
+} // ----  end of namespace Lemma  ----
94
+
95
+/* vim: set tabstop=4 expandtab: */
96
+/* vim: set filetype=cpp: */
97
+

+ 6
- 0
Modules/FDEM1D/testing/GetNameCheck.h Visa fil

@@ -87,6 +87,12 @@ class MyTestSuite : public CxxTest::TestSuite
87 87
         TS_ASSERT_EQUALS( Obj->GetName(), std::string("AEMSurveyReader") );
88 88
     }
89 89
 
90
+    void testChargedWellCasing( void )
91
+    {
92
+        auto Obj = ChargedWellCasing::NewSP();
93
+        TS_ASSERT_EQUALS( Obj->GetName(), std::string("ChargedWellCasing") );
94
+    }
95
+
90 96
 //     void testKernelEM1DManager( void )
91 97
 //     {
92 98
 //         auto Obj = KernelEM1DManager::NewSP();

+ 8
- 0
Modules/FDEM1D/testing/SerializeCheck.h Visa fil

@@ -109,6 +109,14 @@ class MyTestSuite : public CxxTest::TestSuite
109 109
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
110 110
     }
111 111
 
112
+    void testChargedWellCasing(void)
113
+    {
114
+        auto Obj = ChargedWellCasing::NewSP();
115
+        YAML::Node node = Obj->Serialize();
116
+        auto Obj2 = ChargedWellCasing::DeSerialize(node);
117
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
118
+    }
119
+
112 120
 
113 121
 };
114 122
 

+ 11
- 8
Modules/LemmaCore/CMakeLists.txt Visa fil

@@ -9,16 +9,14 @@ set_target_properties(lemmacore PROPERTIES
9 9
     CXX_STANDARD 14
10 10
     CXX_STANDARD_REQUIRED ON
11 11
 )
12
-
13
-# External project dependencies 
14 12
 #add_dependencies(lemmacore YAML_CPP)
15 13
 
16
-if (LEMMA_TINYXML_SUPPORT)
17
-	add_dependencies(lemmacore TINYXML2)
18
-endif()
19
-if (LEMMA_MATIO_SUPPORT)
20
-	add_dependencies(lemmacore MATIO)
21
-endif()
14
+#if (LEMMA_TINYXML_SUPPORT)
15
+#	add_dependencies(lemmacore TINYXML2)
16
+#endif()
17
+#if (LEMMA_MATIO_SUPPORT)
18
+#	add_dependencies(lemmacore MATIO)
19
+#endif()
22 20
 
23 21
 target_link_libraries (lemmacore Eigen3::Eigen)
24 22
 #target_link_libraries (lemmacore CxxTest)
@@ -45,6 +43,11 @@ if (LEMMA_ENABLE_TESTING)
45 43
 	add_subdirectory(testing)
46 44
 endif()
47 45
 
46
+# Python Bindings
47
+if (LEMMA_PYTHON3_BINDINGS)
48
+	add_subdirectory(python)
49
+endif()
50
+
48 51
 # Install
49 52
 install ( TARGETS lemmacore        DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
50 53
 install ( FILES include/LemmaCore  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 

+ 1
- 1
Modules/LemmaCore/include/LemmaObject.h Visa fil

@@ -131,7 +131,7 @@ class LemmaObject {
131 131
         /** Protected DeSerializing constructor */
132 132
         LemmaObject ( const YAML::Node& node, const ctor_key& );
133 133
 
134
-        /** Disable copying Lemma Object */
134
+        /* Disable copying Lemma Object */
135 135
         LemmaObject( const LemmaObject& ) = delete;
136 136
 
137 137
         /** Protected default destructor. This is an abstract class and

+ 2
- 2
Modules/LemmaCore/testing/CMakeLists.txt Visa fil

@@ -14,8 +14,8 @@ CXXTEST_ADD_TEST(unittest_LemmaCore_CopyDisableCheck CopyDisableCheck.cc ${CMAKE
14 14
 target_link_libraries(unittest_LemmaCore_CopyDisableCheck "lemmacore")
15 15
  
16 16
 set_target_properties( unittest_LemmaCore_GetNameCheck 
17
-	               unittest_LemmaCore_SerializeCheck
18
-		       unittest_LemmaCore_CopyDisableCheck
17
+	                   unittest_LemmaCore_SerializeCheck
18
+		               unittest_LemmaCore_CopyDisableCheck
19 19
 	PROPERTIES
20 20
 	CXX_STANDARD 14 
21 21
 	CXX_STANDARD_REQUIRED ON

Laddar…
Avbryt
Spara