29
29
30
30
#include < Eigen/Core>
31
31
32
- #include " utils/cnpy.hpp"
33
32
#include " utils/MathUtils.hpp"
34
33
#include " utils/Sphere.hpp"
35
34
#include " utils/Symmetry.hpp"
35
+ #include " utils/cnpy.hpp"
36
36
37
37
namespace pcm {
38
38
ICavity::ICavity () : nElements_(0 ), built(false ) {}
@@ -102,10 +102,15 @@ void ICavity::loadCavity(const std::string & fname) {
102
102
PCMSOLVER_ERROR (" elementArea_: incoherent dimensions read in" );
103
103
elementArea_ = cnpy::custom::npy_to_eigen<double >(raw_weights);
104
104
// 2. Get the element sphere center
105
- cnpy::NpyArray raw_elSphCenter = loaded_cavity[" elSphCenter" ];
106
- if (raw_elSphCenter.shape [1 ] != nElements_)
107
- PCMSOLVER_ERROR (" elementSphereCenter_: incoherent dimensions read in" );
108
- elementSphereCenter_ = cnpy::custom::npy_to_eigen<double >(raw_elSphCenter);
105
+ if (loaded_cavity.find (" elSphCenter" ) == loaded_cavity.end ()) {
106
+ // Element sphere center was not found on file, fill it up with zeros
107
+ elementSphereCenter_ = Eigen::Matrix3Xd::Zero (3 , nElements_);
108
+ } else {
109
+ cnpy::NpyArray raw_elSphCenter = loaded_cavity[" elSphCenter" ];
110
+ if (raw_elSphCenter.shape [1 ] != nElements_)
111
+ PCMSOLVER_ERROR (" elementSphereCenter_: incoherent dimensions read in" );
112
+ elementSphereCenter_ = cnpy::custom::npy_to_eigen<double >(raw_elSphCenter);
113
+ }
109
114
// 3. Get the element radius
110
115
cnpy::NpyArray raw_elRadius = loaded_cavity[" elRadius" ];
111
116
if (raw_elRadius.shape [0 ] != nElements_)
@@ -122,6 +127,9 @@ void ICavity::loadCavity(const std::string & fname) {
122
127
PCMSOLVER_ERROR (" elementNormal_: incoherent dimensions read in" );
123
128
elementNormal_ = cnpy::custom::npy_to_eigen<double >(raw_normals);
124
129
130
+ bool has_arcs = loaded_cavity.find (" arcs_0" ) == loaded_cavity.end () ? false : true ;
131
+ bool has_vertices =
132
+ loaded_cavity.find (" vertices_0" ) == loaded_cavity.end () ? false : true ;
125
133
// Reconstruct the elements_ vector
126
134
for (PCMSolverIndex i = 0 ; i < nElements_; ++i) {
127
135
bool irr = false ;
@@ -131,10 +139,20 @@ void ICavity::loadCavity(const std::string & fname) {
131
139
Sphere sph (elementSphereCenter_.col (i), elementRadius_ (i));
132
140
Eigen::Matrix3Xd vertices, arcs;
133
141
// 6. Get vertices and arcs
134
- cnpy::NpyArray raw_vertices = loaded_cavity[" vertices_" + pcm::to_string (i)];
135
- vertices = cnpy::custom::npy_to_eigen<double >(raw_vertices);
136
- cnpy::NpyArray raw_arcs = loaded_cavity[" arcs_" + pcm::to_string (i)];
137
- arcs = cnpy::custom::npy_to_eigen<double >(raw_arcs);
142
+ if (has_vertices) {
143
+ cnpy::NpyArray raw_vertices = loaded_cavity[" vertices_" + pcm::to_string (i)];
144
+ vertices = cnpy::custom::npy_to_eigen<double >(raw_vertices);
145
+ } else {
146
+ // Vertices were not found on file, fill them up with zeros
147
+ vertices = Eigen::Matrix3Xd::Zero (3 , 3 );
148
+ }
149
+ if (has_arcs) {
150
+ cnpy::NpyArray raw_arcs = loaded_cavity[" arcs_" + pcm::to_string (i)];
151
+ arcs = cnpy::custom::npy_to_eigen<double >(raw_arcs);
152
+ } else {
153
+ // Arcs were not found on file, fill them up with zeros
154
+ arcs = Eigen::Matrix3Xd::Zero (3 , 3 );
155
+ }
138
156
if (arcs.cols () != vertices.cols ())
139
157
PCMSOLVER_ERROR (" Inconsistent number of vertices read from file for element " +
140
158
pcm::to_string (i));
0 commit comments