Просмотр исходного кода

More work on Python wrapper

iss7
Trevor Irons 5 лет назад
Родитель
Сommit
dd85c872aa

+ 1
- 0
Modules/FDEM1D/include/DipoleSource.h Просмотреть файл

@@ -41,6 +41,7 @@ namespace Lemma {
41 41
     ///           dipoles.
42 42
     // ==========================================================================
43 43
     class DipoleSource : public std::enable_shared_from_this<DipoleSource>,  LemmaObject {
44
+    //class DipoleSource : public LemmaObject {
44 45
 
45 46
         // ====================    FRIENDS     ======================
46 47
 

+ 27
- 12
Modules/FDEM1D/python/pyFDEM1D.cpp Просмотреть файл

@@ -31,22 +31,24 @@ PYBIND11_MODULE(FDEM1D, m) {
31 31
     m.doc() = "Python binding of Lemma::FDEM1D, additional details can be found at https://lemmasoftware.org";
32 32
 
33 33
 
34
-    py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna"); //, py::dynamic_attr());
34
+    py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna");
35 35
 
36 36
         // lifecycle
37 37
         WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
38
-        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
39 38
         .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize), "Construct object from yaml representation")
40 39
 
41 40
         // print
41
+        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
42 42
         .def("__repr__", &Lemma::WireAntenna::Print)
43 43
 
44 44
         // modifiers
45 45
         .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
46 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")
47
+        .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint),
48
+            "Sets a point in the antenna")
48 49
         .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("SetNumberOfFrequencies", &Lemma::WireAntenna::SetNumberOfFrequencies,
51
+            "Sets the number of frequencies of the transmitter")
50 52
         .def("SetFrequency", &Lemma::WireAntenna::SetFrequency, "Sets a single frequency of the transmitter")
51 53
         .def("SetCurrent", &Lemma::WireAntenna::SetCurrent, "Sets the current of the transmitter in amps")
52 54
 
@@ -54,20 +56,24 @@ PYBIND11_MODULE(FDEM1D, m) {
54 56
         .def("GetCurrent", &Lemma::WireAntenna::GetCurrent, "Returns the current of the transmitter in amps")
55 57
         .def("GetPoints", &Lemma::WireAntenna::GetPoints, "Returns the points defining the transmitter")
56 58
         .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")
59
+        .def("GetNumberOfFrequencies", &Lemma::WireAntenna::GetNumberOfFrequencies,
60
+            "Returns the number of frequencies for the transmitter")
58 61
         .def("IsHorizontallyPlanar", &Lemma::WireAntenna::IsHorizontallyPlanar, "Returns true if the transmitter is flat")
59 62
         .def("GetName", &Lemma::WireAntenna::GetName, "Returns the class name of the object")
60 63
 
61 64
         // operations
62
-        .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles, "Approximates loop with electric dipoles")
65
+        .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles,
66
+            "Approximates loop with electric dipoles")
63 67
 
64 68
     ;
65 69
 
66
-    py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m, "PolygonalWireAntenna", WireAntenna); //, py::dynamic_attr())
70
+    py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m,
71
+            "PolygonalWireAntenna", WireAntenna);
67 72
 
68 73
         // lifecycle
69 74
         PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
70
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize), "Construct object from yaml representation")
75
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize),
76
+            "Construct object from yaml representation")
71 77
 
72 78
         // print
73 79
         .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
@@ -76,14 +82,23 @@ PYBIND11_MODULE(FDEM1D, m) {
76 82
         // accessors
77 83
         .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
78 84
 
79
-        // modifiers
80
-        //.def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
81
-
82 85
         // operations
83
-        .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles, "Approximates loop with series of electric dipoles around loop")
86
+        .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles,
87
+            "Approximates loop with series of electric dipoles around loop")
84 88
 
85 89
     ;
86 90
 
91
+    //py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
92
+
93
+        // lifecycle
94
+        //DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
95
+        //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize), "Construct object from yaml representation")
96
+
97
+        // print
98
+        //.def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
99
+        //.def("__repr__", &Lemma::DipoleSource::Print)
100
+
101
+        //;
87 102
 }
88 103
 
89 104
 

+ 8
- 0
Modules/LemmaCore/include/RectilinearGridReader.h Просмотреть файл

@@ -78,6 +78,14 @@ namespace Lemma {
78 78
             static std::shared_ptr< RectilinearGridReader >  DeSerialize( const YAML::Node& node );
79 79
 
80 80
             /**
81
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
82
+             *   used in Python wrapping
83
+             */
84
+            static std::shared_ptr<RectilinearGridReader> DeSerialize( const std::string& node ) {
85
+                return RectilinearGridReader::DeSerialize(YAML::Load(node));
86
+            }
87
+
88
+            /**
81 89
              *  Uses YAML to serialize this object.
82 90
              *  @return a YAML::Node
83 91
              */

+ 39
- 8
Modules/LemmaCore/python/pyLemmaCore.cpp Просмотреть файл

@@ -34,7 +34,8 @@ PYBIND11_MODULE(LemmaCore, m) {
34 34
 
35 35
         // lifecycle
36 36
         RectilinearGrid.def(py::init(&Lemma::RectilinearGrid::NewSP))
37
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize), "Construct object from yaml representation")
37
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize),
38
+            "Construct object from yaml representation")
38 39
 
39 40
         // print
40 41
         .def("__repr__", &Lemma::RectilinearGrid::Print)
@@ -58,11 +59,35 @@ PYBIND11_MODULE(LemmaCore, m) {
58 59
         .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
59 60
     ;
60 61
 
62
+    py::class_<Lemma::RectilinearGridReader, std::shared_ptr<Lemma::RectilinearGridReader> > RectilinearGridReader(m, "RectilinearGridReader");
63
+
64
+        // lifecycle
65
+        RectilinearGridReader.def(py::init(&Lemma::RectilinearGridReader::NewSP))
66
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGridReader::DeSerialize),
67
+            "Construct object from yaml representation")
68
+
69
+        // print
70
+        .def("__repr__", &Lemma::RectilinearGridReader::Print)
71
+        .def("Serialize", &Lemma::RectilinearGridReader::Print, "YAML representation of the class")
72
+
73
+        // accessors
74
+        .def("GetName", &Lemma::RectilinearGridReader::GetName, "Returns the name of the class")
75
+
76
+        // modifiers
77
+
78
+        //methods
79
+        .def("ReadASCIIGridFile", &Lemma::RectilinearGridReader::ReadASCIIGridFile, "Opens file specified by argument")
80
+
81
+        //methods
82
+        .def("GetGrid", &Lemma::RectilinearGridReader::GetGrid, "Returns the grid object")
83
+    ;
84
+
61 85
     py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
62 86
 
63 87
         // lifecycle
64 88
         ASCIIParser.def(py::init(&Lemma::ASCIIParser::NewSP))
65
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize), "Construct object from yaml representation")
89
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize),
90
+            "Construct object from yaml representation")
66 91
 
67 92
         // print
68 93
         .def("__repr__", &Lemma::ASCIIParser::Print)
@@ -90,7 +115,8 @@ PYBIND11_MODULE(LemmaCore, m) {
90 115
 
91 116
         // lifecycle
92 117
         .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
93
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize), "Construct object from yaml representation")
118
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize),
119
+            "Construct object from yaml representation")
94 120
 
95 121
         // print
96 122
         .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
@@ -103,14 +129,19 @@ PYBIND11_MODULE(LemmaCore, m) {
103 129
 
104 130
         // modifiers
105 131
         .def("SetKnots", &Lemma::CubicSplineInterpolator::SetKnots, "Sets the knots to use for interpolation")
106
-        .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate, "Resets the knots to use for interpolation, when abscissa values haven't changed")
132
+        .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate,
133
+            "Resets the knots to use for interpolation, when abscissa values haven't changed")
107 134
 
108 135
         // methods
109 136
         .def("InterpolateOrderedSet", &Lemma::CubicSplineInterpolator::InterpolateOrderedSet, "Interpolate a monotonically increasing ordered set.")
110
-        .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate), "Integrates between the arguments using cubic spline values.")
111
-        .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate), "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
112
-        .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate), "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
113
-        .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate), "Interpolation at a single point, x is the interpolation abscissa point and i is the knot to begin searchin at returns the ordinate value at x")
137
+        .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate),
138
+                "Integrates between the arguments using cubic spline values.")
139
+        .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate),
140
+                "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
141
+        .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate),
142
+                "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
143
+        .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate),
144
+                "Interpolation at a single point, x is the interpolation abscissa point and i is the knot to begin searchin at returns the ordinate value at x")
114 145
 
115 146
     ;
116 147
 

Загрузка…
Отмена
Сохранить