Quellcode durchsuchen

Added to wrapper for WireAntenna including serialize

iss7
Trevor Irons vor 5 Jahren
Ursprung
Commit
dcea3eb768

+ 5
- 0
Modules/FDEM1D/CMakeLists.txt Datei anzeigen

@@ -29,6 +29,11 @@ if (LEMMA_ENABLE_TESTING)
29 29
 	add_subdirectory(testing)
30 30
 endif()
31 31
 
32
+# Python Bindings
33
+if (LEMMA_PYTHON3_BINDINGS)
34
+	add_subdirectory(python)
35
+endif()
36
+
32 37
 # Install
33 38
 install ( TARGETS fdem1d DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
34 39
 install ( FILES include/FDEM1D  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 

+ 8
- 0
Modules/FDEM1D/include/PolygonalWireAntenna.h Datei anzeigen

@@ -67,6 +67,14 @@ namespace Lemma {
67 67
              */
68 68
             static std::shared_ptr<PolygonalWireAntenna> DeSerialize(const YAML::Node& node);
69 69
 
70
+            /**
71
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
72
+             *   used in Python wrapping
73
+             */
74
+            static std::shared_ptr<PolygonalWireAntenna> DeSerialize( const std::string& node ) {
75
+                return PolygonalWireAntenna::DeSerialize(YAML::Load(node));
76
+            }
77
+
70 78
             // ====================  OPERATORS     =======================
71 79
 
72 80
             // ====================  OPERATIONS    =======================

+ 8
- 0
Modules/FDEM1D/include/WireAntenna.h Datei anzeigen

@@ -69,6 +69,14 @@ namespace Lemma {
69 69
              */
70 70
             static std::shared_ptr<WireAntenna> DeSerialize( const YAML::Node& node );
71 71
 
72
+            /**
73
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
74
+             *   used in Python wrapping
75
+             */
76
+            static std::shared_ptr<WireAntenna> DeSerialize( const std::string& node ) {
77
+                return WireAntenna::DeSerialize(YAML::Load(node));
78
+            }
79
+
72 80
             // ====================  OPERATORS     =======================
73 81
 
74 82
             // ====================  OPERATIONS    =======================

+ 5
- 0
Modules/FDEM1D/python/CMakeLists.txt Datei anzeigen

@@ -0,0 +1,5 @@
1
+add_library(pyFDEM1D MODULE pyFDEM1D.cpp)
2
+target_link_libraries(pyFDEM1D PRIVATE pybind11::module lemmacore fdem1d )
3
+set_target_properties(pyFDEM1D PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
4
+                                       SUFFIX "${PYTHON_MODULE_EXTENSION}")
5
+

+ 108
- 0
Modules/FDEM1D/python/pyFDEM1D.cpp Datei anzeigen

@@ -0,0 +1,108 @@
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      22/04/19 14:06:32
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
+#include <pybind11/pybind11.h>
21
+#include <pybind11/iostream.h>
22
+#include <pybind11/eigen.h>
23
+#include "FDEM1D"
24
+
25
+namespace py = pybind11;
26
+
27
+PYBIND11_MODULE(pyFDEM1D, m) {
28
+
29
+    py::add_ostream_redirect(m, "ostream_redirect");
30
+
31
+    m.doc() = "Python binding of Lemma::FDEM1D, additional details can be found at https://lemmasoftware.org";
32
+
33
+
34
+    py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna"); //, py::dynamic_attr());
35
+
36
+        // lifecycle
37
+        WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
38
+
39
+        // print
40
+        .def("__repr__", &Lemma::WireAntenna::Print)
41
+        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
42
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize), "Construct object from yaml representation")
43
+
44
+        // modifiers
45
+        .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
46
+        .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint), "Sets a point in the antenna")
47
+        .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint), "Sets a point in the antenna")
48
+        .def("SetNumberOfTurns", &Lemma::WireAntenna::SetNumberOfTurns, "Sets the number of turns of the antenna")
49
+        .def("SetNumberOfFrequencies", &Lemma::WireAntenna::SetNumberOfFrequencies, "Sets the number of frequencies of the transmitter")
50
+        .def("SetFrequency", &Lemma::WireAntenna::SetFrequency, "Sets a single frequency of the transmitter")
51
+        .def("SetCurrent", &Lemma::WireAntenna::SetCurrent, "Sets the current of the transmitter in amps")
52
+
53
+        // accessors
54
+        .def("GetCurrent", &Lemma::WireAntenna::GetCurrent, "Returns the current of the transmitter in amps")
55
+        .def("GetPoints", &Lemma::WireAntenna::GetPoints, "Returns the points defining the transmitter")
56
+        .def("GetNumberOfDipoles", &Lemma::WireAntenna::GetNumberOfDipoles, "Returns the number of dipoles defining the transmitter")
57
+        .def("GetNumberOfFrequencies", &Lemma::WireAntenna::GetNumberOfFrequencies, "Returns the number of frequencies for the transmitter")
58
+        .def("IsHorizontallyPlanar", &Lemma::WireAntenna::IsHorizontallyPlanar, "Returns true if the transmitter is flat")
59
+        .def("GetName", &Lemma::WireAntenna::GetName, "Returns the class name of the object")
60
+
61
+        // operations
62
+        .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles, "Approximates loop with electric dipoles")
63
+
64
+    ;
65
+
66
+    py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m, "PolygonalWireAntenna", WireAntenna); //, py::dynamic_attr())
67
+
68
+        // lifecycle
69
+        PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
70
+
71
+        // print
72
+        .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
73
+        .def("Serialize", &Lemma::PolygonalWireAntenna::Print, "YAML representation of the class")
74
+
75
+        // accessors
76
+        .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
77
+
78
+        // modifiers
79
+        //.def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
80
+
81
+        // operations
82
+        .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles, "Approximates loop with series of electric dipoles around loop")
83
+
84
+    ;
85
+
86
+}
87
+
88
+
89
+/*
90
+BOOST_PYTHON_MODULE(pyLemmaCore)
91
+{
92
+    Py_Initialize();
93
+    np::initialize();
94
+
95
+ 	bp::class_<Lemma::PolygonalWireAntenna, boost::noncopyable> ("PolygonalWireAntenna", boost::python::no_init)
96
+
97
+        // print
98
+        .def(boost::python::self_ns::str(bp::self))
99
+
100
+        // Lifecycle
101
+        .def("__init__", boost::python::make_constructor(&Lemma::PolygonalWireAntenna::NewSP))
102
+        //.def("Serialize", &Lemma::PolygonalWireAntenna::Serialize)
103
+        //.def("DeSerialize", &Lemma::PolygonalWireAntenna::DeSerialize)
104
+
105
+        // Accessors
106
+    ;
107
+}
108
+*/

+ 0
- 1
Modules/LemmaCore/CMakeLists.txt Datei anzeigen

@@ -46,7 +46,6 @@ endif()
46 46
 # Python Bindings
47 47
 if (LEMMA_PYTHON3_BINDINGS)
48 48
 	add_subdirectory(python)
49
-	#pybind11_add_module(Lemma pyLemmaCore.cpp)
50 49
 endif()
51 50
 
52 51
 # Install

+ 1
- 1
Modules/LemmaCore/include/ASCIIParser.h Datei anzeigen

@@ -169,4 +169,4 @@ class ASCIIParser : public LemmaObject {
169 169
 #endif   // ----- #ifndef ASCIIPARSER_INC  -----
170 170
 
171 171
 /* vim: set tabstop=4 expandtab: */
172
-/* vim: set filetype=cpp syntax=cpp.doxygen: */
172
+/* vim: set filetype=cpp syntax=cpp.doxygen */

+ 6
- 0
Modules/LemmaCore/include/LemmaObject.h Datei anzeigen

@@ -111,6 +111,12 @@ class LemmaObject {
111 111
 
112 112
         // ====================  ACCESS        ==============================
113 113
 
114
+        virtual std::string Print() {
115
+            YAML::Emitter out;
116
+            out << this->Serialize();
117
+            return out.c_str();
118
+        }
119
+
114 120
         // ====================  INQUIRY       ==============================
115 121
 
116 122
         /** Returns the name of the underlying class; Run-time type information (RTTI). This approach

+ 0
- 6
Modules/LemmaCore/include/RectilinearGrid.h Datei anzeigen

@@ -72,12 +72,6 @@ namespace Lemma {
72 72
             virtual YAML::Node Serialize() const;
73 73
 
74 74
             /**
75
-             *  Uses YAML to serialize this object.
76
-             *  @return a YAML::Node
77
-             */
78
-            virtual std::string Print() const;
79
-
80
-            /**
81 75
              *  Factory method for generating concrete class.
82 76
              *  @return a std::shared_ptr of type RectilinearGrid
83 77
              */

+ 0
- 17
Modules/LemmaCore/python/CMakeLists.txt Datei anzeigen

@@ -1,6 +1,3 @@
1
-# include directories
2
-#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/python)
3
-
4 1
 # create the lib
5 2
 #add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR} )
6 3
 #pybind11_add_module(pyLemmaCore pyLemmaCore.cpp)
@@ -10,17 +7,3 @@ target_link_libraries(pyLemmaCore PRIVATE pybind11::module lemmacore )
10 7
 set_target_properties(pyLemmaCore PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
11 8
                                          SUFFIX "${PYTHON_MODULE_EXTENSION}")
12 9
 
13
-#target_include_directories( lemmacore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include" )
14
-
15
-#add_library(pyLemmaCore SHARED ${CMAKE_CURRENT_SOURCE_DIR}/pyLemmaCore.cpp)
16
-
17
-# link
18
-#target_link_libraries(pyLemmaCore lemmacore)
19
-
20
-# Copy the __init__.py file
21
-#configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py COPYONLY)
22
-
23
-# Suppress prefix "lib" because Python does not allow this prefix
24
-#set_target_properties(pyLemmaCore PROPERTIES PREFIX "")
25
-
26
-#install(TARGETS pyLemmaCore __init__.py DESTINATION "${PYTHON_INSTALL_PATH}")

+ 29
- 5
Modules/LemmaCore/python/pyLemmaCore.cpp Datei anzeigen

@@ -37,7 +37,7 @@ PYBIND11_MODULE(pyLemmaCore, m) {
37 37
 
38 38
         // print
39 39
         .def("__repr__", &Lemma::RectilinearGrid::Print)
40
-        .def("Serialize", &Lemma::RectilinearGrid::Print)
40
+        .def("Serialize", &Lemma::RectilinearGrid::Print, "YAML representation of the class")
41 41
 
42 42
         // accessors
43 43
         .def("GetName", &Lemma::RectilinearGrid::GetName, "Returns the name of the class")
@@ -51,9 +51,37 @@ PYBIND11_MODULE(pyLemmaCore, m) {
51 51
         .def("GetDy", &Lemma::RectilinearGrid::GetDy, "Returns the grid spacing in the y direction")
52 52
         .def("GetDz", &Lemma::RectilinearGrid::GetDz, "Returns the grid spacing in the z direction")
53 53
 
54
+        // modifiers
54 55
         .def("SetDimensions", &Lemma::RectilinearGrid::SetDimensions, "Sets the number of cells in x, y, and z")
55 56
         .def("SetOffset", &Lemma::RectilinearGrid::SetOffset, "Sets the origin offset in x, y, and z")
56 57
         .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z");
58
+
59
+    py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> >(m, "ASCIIParser")
60
+
61
+        // lifecycle
62
+        .def(py::init(&Lemma::ASCIIParser::NewSP))
63
+
64
+        // print
65
+        .def("__repr__", &Lemma::ASCIIParser::Print)
66
+        .def("Serialize", &Lemma::ASCIIParser::Print, "YAML representation of the class")
67
+
68
+        // accessors
69
+        .def("GetName", &Lemma::ASCIIParser::GetName, "Returns the name of the class")
70
+        .def("GetFileLocation", &Lemma::ASCIIParser::GetFileLocation, "Returns the current file location")
71
+
72
+        // modifiers
73
+        .def("SetCommentString", &Lemma::ASCIIParser::SetCommentString, "Sets the comment string after which all text is ignored")
74
+        .def("SetBufferSize", &Lemma::ASCIIParser::SetBufferSize, "Sets the buffer size")
75
+
76
+        // methods
77
+        .def("Open", &Lemma::ASCIIParser::Open, "Opens file specified by argument")
78
+        .def("Close", &Lemma::ASCIIParser::Close, "Closes current file object")
79
+        .def("ReadReals", &Lemma::ASCIIParser::ReadReals, "Returns vector of nr reals")
80
+        .def("ReadInts", &Lemma::ASCIIParser::ReadInts, "Returns vector of ni ints")
81
+        .def("ReadStrings", &Lemma::ASCIIParser::ReadStrings, "Returns vector of ns strings")
82
+        .def("JumpToLocation", &Lemma::ASCIIParser::JumpToLocation, "File object jumps to specified location")
83
+
84
+    ;
57 85
 }
58 86
 
59 87
 
@@ -74,10 +102,6 @@ BOOST_PYTHON_MODULE(pyLemmaCore)
74 102
         //.def("DeSerialize", &Lemma::RectilinearGrid::DeSerialize)
75 103
 
76 104
         // Accessors
77
-
78
-
79
-
80 105
     ;
81
-
82 106
 }
83 107
 */

+ 1
- 0
Modules/LemmaCore/src/EarthModel.cpp Datei anzeigen

@@ -31,6 +31,7 @@ namespace Lemma {
31 31
         BDec = node["BDec"].as<double>();
32 32
         BMag = node["BMag"].as<double>();
33 33
         BField = node["BField"].as<Vector3r>();
34
+	    SetMagneticFieldIncDecMag(BInc, BDec, BMag, TESLA);
34 35
     }
35 36
 
36 37
 

+ 0
- 7
Modules/LemmaCore/src/RectilinearGrid.cpp Datei anzeigen

@@ -69,13 +69,6 @@ namespace Lemma {
69 69
         return node;
70 70
     }
71 71
 
72
-    std::string RectilinearGrid::Print() const {
73
-        YAML::Emitter out;
74
-        out << this->Serialize();
75
-        return out.c_str();
76
-    }
77
-
78
-
79 72
     //--------------------------------------------------------------------------------------
80 73
     //       Class:  RectilinearGrid
81 74
     //      Method:  DeSerialize

Laden…
Abbrechen
Speichern