Skip to content

Commit 411e935

Browse files
robertodrarnfinn
authored andcommitted
Save also vertices and arcs when saving cavity to file
This commit fixes #41
1 parent 7b16c4e commit 411e935

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/cavity/Element.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ class Element __final {
116116
Eigen::Matrix3Xd arcs_;
117117
virtual std::ostream & printElement(std::ostream & os) {
118118
os << "Finite element" << std::endl;
119-
os << "Number of vertices = " << nVertices_ << std::endl;
120-
os << "Area = " << area_;
119+
os << "Center\n" << center_.transpose() << std::endl;
120+
os << "Normal\n" << normal_.transpose() << std::endl;
121+
os << "Weight " << area_ << std::endl;
122+
os << sphere_ << std::endl;
123+
os << "Number of vertices and arcs " << nVertices_ << std::endl;
124+
os << "Vertices\n" << vertices_ << std::endl;
125+
os << "Arcs\n" << arcs_;
121126
return os;
122127
}
123128
};

src/cavity/ICavity.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ void ICavity::saveCavity(const std::string & fname) {
7373
cnpy::custom::npz_save(fname, "centers", elementCenter_);
7474
// Write normals
7575
cnpy::custom::npz_save(fname, "normals", elementNormal_);
76-
// Write vertices TODO!!!!
77-
// const unsigned int vertices_shape[] = {dim, 10, 3};
78-
// Write arcs TODO!!!!
79-
// const unsigned int arcs_shape[] = {dim, 10, 3};
76+
for (PCMSolverIndex i = 0; i < nElements_; ++i) {
77+
// Write vertices
78+
cnpy::custom::npz_save(fname, "vertices_" + std::to_string(i), elements_[i].vertices());
79+
// Write arcs
80+
cnpy::custom::npz_save(fname, "arcs_" + std::to_string(i), elements_[i].arcs());
81+
}
8082
}
8183

8284
void ICavity::loadCavity(const std::string & fname) {
@@ -126,10 +128,17 @@ void ICavity::loadCavity(const std::string & fname) {
126128
if (i < nIrrElements_)
127129
irr = true;
128130
Sphere sph(elementSphereCenter_.col(i), elementRadius_(i));
129-
int nv = 3; // BOGUS!!!
130131
Eigen::Matrix3Xd vertices, arcs;
131-
vertices.resize(Eigen::NoChange, nv); // BOGUS!!!
132-
arcs.resize(Eigen::NoChange, nv); // BOGUS!!
132+
// 6. Get vertices and arcs
133+
for (PCMSolverIndex i = 0; i < nElements_; ++i) {
134+
cnpy::NpyArray raw_vertices = loaded_cavity["vertices_" + std::to_string(i)];
135+
vertices = cnpy::custom::npy_to_eigen<double>(raw_vertices);
136+
cnpy::NpyArray raw_arcs = loaded_cavity["arcs_" + std::to_string(i)];
137+
arcs = cnpy::custom::npy_to_eigen<double>(raw_arcs);
138+
}
139+
if (arcs.cols() != vertices.cols())
140+
PCMSOLVER_ERROR("Inconsistent number of vertices read from file for element " + to_string(i));
141+
int nv = vertices.cols();
133142
// Populate vertices and arcs
134143
elements_.push_back(Element(nv,
135144
0,

src/utils/Sphere.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using utils::Sphere;
3535

3636
std::ostream & operator<<(std::ostream & os, Sphere & sph) {
3737
os << "Sphere radius " << sph.radius << std::endl;
38-
os << "Sphere center\n" << sph.center;
38+
os << "Sphere center\n" << sph.center.transpose();
3939

4040
return os;
4141
}

0 commit comments

Comments
 (0)