2929
3030#include < Eigen/Core>
3131
32- #include " utils/cnpy.hpp"
3332#include " utils/MathUtils.hpp"
3433#include " utils/Sphere.hpp"
3534#include " utils/Symmetry.hpp"
35+ #include " utils/cnpy.hpp"
3636
3737namespace pcm {
3838ICavity::ICavity () : nElements_(0 ), built(false ) {}
@@ -102,10 +102,15 @@ void ICavity::loadCavity(const std::string & fname) {
102102 PCMSOLVER_ERROR (" elementArea_: incoherent dimensions read in" );
103103 elementArea_ = cnpy::custom::npy_to_eigen<double >(raw_weights);
104104 // 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+ }
109114 // 3. Get the element radius
110115 cnpy::NpyArray raw_elRadius = loaded_cavity[" elRadius" ];
111116 if (raw_elRadius.shape [0 ] != nElements_)
@@ -122,6 +127,9 @@ void ICavity::loadCavity(const std::string & fname) {
122127 PCMSOLVER_ERROR (" elementNormal_: incoherent dimensions read in" );
123128 elementNormal_ = cnpy::custom::npy_to_eigen<double >(raw_normals);
124129
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 ;
125133 // Reconstruct the elements_ vector
126134 for (PCMSolverIndex i = 0 ; i < nElements_; ++i) {
127135 bool irr = false ;
@@ -131,10 +139,20 @@ void ICavity::loadCavity(const std::string & fname) {
131139 Sphere sph (elementSphereCenter_.col (i), elementRadius_ (i));
132140 Eigen::Matrix3Xd vertices, arcs;
133141 // 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+ }
138156 if (arcs.cols () != vertices.cols ())
139157 PCMSOLVER_ERROR (" Inconsistent number of vertices read from file for element " +
140158 pcm::to_string (i));
0 commit comments