Skip to content
Snippets Groups Projects
Commit e3ed5772 authored by Adrien Crovato's avatar Adrien Crovato
Browse files

Merge branch 'adri' into feat/xsonic

parents afb36db8 23090ab7
No related branches found
No related tags found
1 merge request!3Version 1.2
Pipeline #23749 passed
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
...@@ -91,6 +91,9 @@ threads="1" ...@@ -91,6 +91,9 @@ threads="1"
// SDPM typemaps // SDPM typemaps
%include "sdpm_def.h" // needed to access USE_CODI in SWIG interface %include "sdpm_def.h" // needed to access USE_CODI in SWIG interface
#ifndef USE_CODI
typedef double sdpmDouble; // needed so that SWIG does not convert sdpmDouble to double
#endif
%typemap(out) sdpmDouble { %typemap(out) sdpmDouble {
#ifndef USE_CODI #ifndef USE_CODI
$result = PyFloat_FromDouble($1); $result = PyFloat_FromDouble($1);
...@@ -107,6 +110,14 @@ threads="1" ...@@ -107,6 +110,14 @@ threads="1"
%template(std_vector_Elementp) std::vector<sdpm::Element *>; %template(std_vector_Elementp) std::vector<sdpm::Element *>;
%template(std_vector_Tagp) std::vector<sdpm::Tag *>; %template(std_vector_Tagp) std::vector<sdpm::Tag *>;
%template(std_map_string_Tagp) std::map<std::string, sdpm::Tag *>; %template(std_map_string_Tagp) std::map<std::string, sdpm::Tag *>;
%template(std_vector_vector3d) std::vector<sdpmVector3d>;
#ifndef USE_CODI
%rename(std_vector_double) std::vector<sdpmDouble>;
%rename(std_vector_vector_double) std::vector<std::vector<sdpmDouble>>;
#else
%template(std_vector_sdpmdouble) std::vector<sdpmDouble>;
%template(std_vector_vector_sdpmdouble) std::vector<std::vector<sdpmDouble>>;
#endif
// SDPM // SDPM
%include "sdpm.h" %include "sdpm.h"
...@@ -136,26 +147,40 @@ threads="1" ...@@ -136,26 +147,40 @@ threads="1"
// Interface to SDPM types // Interface to SDPM types
class sdpmVector3d {}; class sdpmVector3d {};
%extend sdpmVector3d { %extend sdpmVector3d {
double getitem(int i) double __getitem__(int i)
{ {
if (i > 2)
throw std::runtime_error("sdpmVector3d: index out of range (size 3)!\n");
#ifndef USE_CODI #ifndef USE_CODI
return (*self)(i); return (*self)(i);
#else #else
return (*self)(i).getValue(); return (*self)(i).getValue();
#endif #endif
} }
std::string __str__() // use repr instead of str so that iterables also print nicely
std::string __repr__()
{ {
std::ostringstream out; out << *self; return out.str(); std::ostringstream out; out << *self;
return out.str();
} }
}
%pythoncode { #ifdef USE_CODI
def __getitem__(self, idx): class sdpmDouble {};
return self.getitem(idx) %extend sdpmDouble {
double __float__()
{
return (*self).getValue();
}
// use repr instead of str so that iterables also print nicely
std::string __repr__()
{
std::ostringstream out; out << *self;
return out.str();
} }
} }
#endif
// Interface to SDPM classes // Interface to SDPM classes
namespace sdpm { namespace sdpm {
......
...@@ -80,8 +80,8 @@ class SdpmSolver(om.ExplicitComponent): ...@@ -80,8 +80,8 @@ class SdpmSolver(om.ExplicitComponent):
self.adj.solve() self.adj.solve()
# Set outputs # Set outputs
for i in range(self.nf): for i in range(self.nf):
outputs['Q_re'][i, :, :] = np.array(self.sol.getGafMatrixRe(i)) outputs['Q_re'][i, :, :] = np.array(self.sol.getGafMatrixRe(i), dtype=float)
outputs['Q_im'][i, :, :] = np.array(self.sol.getGafMatrixIm(i)) outputs['Q_im'][i, :, :] = np.array(self.sol.getGafMatrixIm(i), dtype=float)
class SdpmBuilder(Builder): class SdpmBuilder(Builder):
"""SDPM builder for OpenMDAO """SDPM builder for OpenMDAO
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <Eigen/Dense> #include <Eigen/Dense>
#include <complex> #include <complex>
#ifndef SWIG
#ifndef USE_CODI #ifndef USE_CODI
using sdpmDouble = double; using sdpmDouble = double;
#else // USE_CODI #else // USE_CODI
...@@ -51,6 +52,7 @@ using sdpmVector3d = Eigen::Matrix<sdpmDouble, 3, 1>; ...@@ -51,6 +52,7 @@ using sdpmVector3d = Eigen::Matrix<sdpmDouble, 3, 1>;
using sdpmMatrixXcd = Eigen::Matrix<sdpmComplex, Eigen::Dynamic, Eigen::Dynamic>; using sdpmMatrixXcd = Eigen::Matrix<sdpmComplex, Eigen::Dynamic, Eigen::Dynamic>;
using sdpmVectorXcd = Eigen::Matrix<sdpmComplex, Eigen::Dynamic, 1>; using sdpmVectorXcd = Eigen::Matrix<sdpmComplex, Eigen::Dynamic, 1>;
using sdpmVector3cd = Eigen::Matrix<sdpmComplex, 3, 1>; using sdpmVector3cd = Eigen::Matrix<sdpmComplex, 3, 1>;
#endif // SWIG
namespace sdpm namespace sdpm
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment