Browse Source

Python wrapper for DipoleSource added

master
Trevor Irons 5 years ago
parent
commit
085af030ae

+ 7
- 0
Modules/FDEM1D/include/DipoleSource.h View File

@@ -85,6 +85,13 @@ namespace Lemma {
85 85
              */
86 86
             static std::shared_ptr< DipoleSource > DeSerialize(const YAML::Node& node);
87 87
 
88
+            /**
89
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
90
+             *   used in Python wrapping
91
+             */
92
+            static std::shared_ptr<DipoleSource> DeSerialize( const std::string& node ) {
93
+                return DipoleSource::DeSerialize(YAML::Load(node));
94
+            }
88 95
 
89 96
             /** Returns a deep copy of the dipole. Used to make thread safe methods. Does not
90 97
                 copy attachments.

+ 29
- 1
Modules/FDEM1D/python/pyFDEM1D.cpp View File

@@ -92,12 +92,40 @@ PYBIND11_MODULE(FDEM1D, m) {
92 92
 
93 93
         // lifecycle
94 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")
95
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize),
96
+            "Construct object from yaml representation")
96 97
 
97 98
         // print
98 99
         .def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
99 100
         .def("__repr__", &Lemma::DipoleSource::Print)
100 101
 
102
+        // accessors
103
+        .def("GetName", &Lemma::DipoleSource::GetName, "Returns the name of the class")
104
+        .def("GetNumberOfFrequencies", &Lemma::DipoleSource::GetNumberOfFrequencies,
105
+                "Returns the number of frequencies")
106
+        .def("GetFrequencies", &Lemma::DipoleSource::GetFrequencies, "Returns an array of frequencies")
107
+        .def("GetFrequency", &Lemma::DipoleSource::GetFrequency, "Returns the frequency of the argument index")
108
+        .def("GetAngularFrequency", &Lemma::DipoleSource::GetAngularFrequency,
109
+            "Returns the angular frequency of the argument index")
110
+        .def("GetPhase", &Lemma::DipoleSource::GetPhase, "Returns the phase of the dipole")
111
+        .def("GetMoment", &Lemma::DipoleSource::GetMoment, "Returns the moment of the dipole")
112
+        .def("GetLocation", py::overload_cast< >(&Lemma::DipoleSource::GetLocation), "Returns the location of the dipole")
113
+        .def("GetPolarisation", &Lemma::DipoleSource::GetPolarisation, "Returns the polarisation of the dipole")
114
+
115
+        // modifiers
116
+        .def("SetLocation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetLocation),
117
+            "Sets the location of the dipole")
118
+        .def("SetPolarisation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetPolarisation),
119
+            "Sets the polarisation of the dipole")
120
+        .def("SetType", &Lemma::DipoleSource::SetType, "Sets the type")
121
+        .def("SetMoment", &Lemma::DipoleSource::SetMoment, "Sets the moment of the dipole")
122
+        .def("SetPhase", &Lemma::DipoleSource::SetPhase, "Sets the phase of the dipole")
123
+        .def("SetNumberOfFrequencies", &Lemma::DipoleSource::SetNumberOfFrequencies,
124
+            "Sets the number of frequencies to calculate for the dipole")
125
+        .def("SetFrequency", &Lemma::DipoleSource::SetFrequency,
126
+            "Sets a single frequency, first argument is index, second argument is frequency")
127
+        .def("SetFrequencies", &Lemma::DipoleSource::SetFrequencies,
128
+            "Sets all frequencies, argument is numpy array of frequencies")
101 129
         ;
102 130
 }
103 131
 

+ 80
- 0
Modules/LemmaCore/python/pyLemmaCore.cpp View File

@@ -30,6 +30,86 @@ PYBIND11_MODULE(LemmaCore, m) {
30 30
 
31 31
     m.doc() = "Python binding of LemmaCore, additional details can be found at https://lemmasoftware.org";
32 32
 
33
+    //////////////////
34
+    // Enumerations //
35
+    //////////////////
36
+
37
+    py::enum_<Lemma::MAGUNITS>(m, "MAGUNITS")
38
+        .value("TESLA", Lemma::TESLA)
39
+        .value("NANOTESLA", Lemma::NANOTESLA)
40
+        .value("GAUSS", Lemma::GAUSS)
41
+        .export_values();
42
+
43
+    py::enum_<Lemma::TEMPUNITS>(m, "TEMPUNITS")
44
+        .value("CELCIUS", Lemma::CELCIUS)
45
+        .value("KELVIN", Lemma::KELVIN)
46
+        .export_values();
47
+
48
+    py::enum_<Lemma::TIMEUNITS>(m, "TIMEUNITS")
49
+        .value("SEC", Lemma::SEC)
50
+        .value("MILLISEC", Lemma::MILLISEC)
51
+        .value("MICROSEC", Lemma::MICROSEC)
52
+        .value("NANOSEC", Lemma::NANOSEC)
53
+        .value("PICOSEC", Lemma::PICOSEC)
54
+        .export_values();
55
+
56
+    py::enum_<Lemma::FREQUENCYUNITS>(m, "FREQUENCYUNITS")
57
+        .value("HZ", Lemma::HZ)
58
+        .value("KHZ", Lemma::KHZ)
59
+        .value("MHZ", Lemma::MHZ)
60
+        .value("GHZ", Lemma::GHZ)
61
+        .export_values();
62
+
63
+    py::enum_<Lemma::FEMCOILORIENTATION>(m, "FEMCOILORIENTATION")
64
+        .value("COAXIAL", Lemma::COAXIAL)
65
+        .value("COPLANAR", Lemma::COPLANAR)
66
+        .export_values();
67
+
68
+    py::enum_<Lemma::DIPOLESOURCETYPE>(m, "DIPOLESOURCETYPE")
69
+        .value("NOSOURCETYPE", Lemma::NOSOURCETYPE)
70
+        .value("GROUNDEDELECTRICDIPOLE", Lemma::GROUNDEDELECTRICDIPOLE )
71
+        .value("UNGROUNDEDELECTRICDIPOLE", Lemma::UNGROUNDEDELECTRICDIPOLE )
72
+        .value("MAGNETICDIPOLE", Lemma::MAGNETICDIPOLE )
73
+        .export_values();
74
+
75
+    py::enum_<Lemma::HANKELTRANSFORMTYPE>(m, "HANKELTRANSFORMTYPE")
76
+        .value("ANDERSON801", Lemma::ANDERSON801)
77
+        .value("CHAVE", Lemma::CHAVE)
78
+        .value("FHTKEY201", Lemma::FHTKEY201)
79
+        .value("FHTKEY101", Lemma::FHTKEY101)
80
+        .value("FHTKEY51", Lemma::FHTKEY51)
81
+        .value("QWEKEY", Lemma::QWEKEY)
82
+        .value("FHTKONG61", Lemma::FHTKONG61)
83
+        .value("FHTKONG121", Lemma::FHTKONG121)
84
+        .value("FHTKONG241", Lemma::FHTKONG241)
85
+        .value("IRONS", Lemma::IRONS)
86
+        .export_values();
87
+
88
+
89
+    py::enum_<Lemma::FIELDCALCULATIONS>(m, "FIELDCALCULATIONS")
90
+        .value("E", Lemma::E)
91
+        .value("H", Lemma::H)
92
+        .value("BOTH", Lemma::BOTH)
93
+        .export_values();
94
+
95
+    //what the what? This won't compile on gcc?? Maybe because not all caps?
96
+    /*
97
+    py::enum_<Lemma::DipoleSourcePolarity>(m "DipoleSourcePolarity")
98
+        .value("NEGATIVE", Lemma::NEGATIVE)
99
+        .value("POSITIVE", Lemma::POSITIVE)
100
+        .export_values();
101
+
102
+    py::enum_<Lemma::DipoleSourcePolarisation>(m "DipoleSourcePolarisation")
103
+        .value("NOPOLARISATION", Lemma::NOPOLARISATION)
104
+        .value("XPOLARISATION", Lemma::XPOLARISATION)
105
+        .value("YPOLARISATION", Lemma::YPOLARISATION)
106
+        .value("ZPOLARISATION", Lemma::ZPOLARISATION)
107
+        .export_values();
108
+    */
109
+
110
+    ///////////////////////
111
+    // LemmaCore Classes //
112
+    ///////////////////////
33 113
     py::class_<Lemma::RectilinearGrid, std::shared_ptr<Lemma::RectilinearGrid> > RectilinearGrid(m, "RectilinearGrid");
34 114
 
35 115
         // lifecycle

Loading…
Cancel
Save