|
40 | 40 |
|
41 | 41 | void Cavity::saveCavity(const std::string & fname)
|
42 | 42 | {
|
43 |
| - /* |
44 |
| - std::ofstream weights("weights.txt", std::ios_base::out); |
45 |
| - // First line in the weights file is the number of elements. |
46 |
| - // This is for a sanity-check on the save/load operations. |
47 |
| - weights << std::setprecision(std::numeric_limits<double>::digits10) << nElements_ << std::endl; |
48 |
| - weights << std::setprecision(std::numeric_limits<double>::digits10) << elementArea_ << std::endl; |
49 |
| - std::ofstream elRadius("element_radius.txt", std::ios_base::out); |
50 |
| - elRadius << std::setprecision(std::numeric_limits<double>::digits10) << elementRadius_ << std::endl; |
51 |
| - std::ofstream centers("centers.txt", std::ios_base::out); |
52 |
| - centers << std::setprecision(std::numeric_limits<double>::digits10) << elementCenter_ << std::endl; |
53 |
| - std::ofstream normals("normals.txt", std::ios_base::out); |
54 |
| - normals << std::setprecision(std::numeric_limits<double>::digits10) << elementNormal_ << std::endl; |
55 |
| - */ |
| 43 | + /* |
| 44 | + std::ofstream weights("weights.txt", std::ios_base::out); |
| 45 | + // First line in the weights file is the number of elements. |
| 46 | + // This is for a sanity-check on the save/load operations. |
| 47 | + weights << std::setprecision(std::numeric_limits<double>::digits10) << nElements_ << std::endl; |
| 48 | + weights << std::setprecision(std::numeric_limits<double>::digits10) << elementArea_ << std::endl; |
| 49 | + std::ofstream elRadius("element_radius.txt", std::ios_base::out); |
| 50 | + elRadius << std::setprecision(std::numeric_limits<double>::digits10) << elementRadius_ << std::endl; |
| 51 | + std::ofstream centers("centers.txt", std::ios_base::out); |
| 52 | + centers << std::setprecision(std::numeric_limits<double>::digits10) << elementCenter_ << std::endl; |
| 53 | + std::ofstream normals("normals.txt", std::ios_base::out); |
| 54 | + normals << std::setprecision(std::numeric_limits<double>::digits10) << elementNormal_ << std::endl; |
| 55 | + */ |
56 | 56 |
|
57 |
| - // Write everything in a single .npz binary file |
58 |
| - unsigned int dim = static_cast<unsigned int>(nElements_); |
59 |
| - // Write the number of elements, it will be used to check sanity of the save/load operations. |
60 |
| - const unsigned int shape[] = {1}; |
61 |
| - cnpy::npz_save(fname, "elements", &dim, shape, 1, "w", false); |
62 |
| - // Write weights |
63 |
| - const unsigned int weights_shape[] = {dim}; |
64 |
| - cnpy::npz_save(fname, "weights", elementArea_.data(), weights_shape, 1, "a", true); |
65 |
| - // Write element sphere center |
66 |
| - const unsigned int elSphCenter_shape[] = {3, dim}; |
67 |
| - cnpy::npz_save(fname, "elSphCenter", elementSphereCenter_.data(), elSphCenter_shape, 2, "a", |
68 |
| - true); |
69 |
| - // Write element radius |
70 |
| - const unsigned int elRadius_shape[] = {dim}; |
71 |
| - cnpy::npz_save(fname, "elRadius", elementRadius_.data(), elRadius_shape, 1, "a", |
72 |
| - true); |
73 |
| - // Write centers |
74 |
| - const unsigned int centers_shape[] = {3, dim}; |
75 |
| - cnpy::npz_save(fname, "centers", elementCenter_.data(), centers_shape, 2, "a", true); |
76 |
| - // Write normals |
77 |
| - const unsigned int normals_shape[] = {3, dim}; |
78 |
| - cnpy::npz_save(fname, "normals", elementNormal_.data(), normals_shape, 2, "a", true); |
79 |
| - // Write vertices TODO!!!! |
80 |
| - //const unsigned int vertices_shape[] = {dim, 10, 3}; |
81 |
| - // Write arcs TODO!!!! |
82 |
| - //const unsigned int arcs_shape[] = {dim, 10, 3}; |
| 57 | + // Write everything in a single .npz binary file |
| 58 | + unsigned int dim = static_cast<unsigned int>(nElements_); |
| 59 | + // Write the number of elements, it will be used to check sanity of the save/load operations. |
| 60 | + const unsigned int shape[] = {1}; |
| 61 | + cnpy::npz_save(fname, "elements", &dim, shape, 1, "w", false); |
| 62 | + // Write weights |
| 63 | + cnpy::custom::npz_save(fname, "weights", elementArea_); |
| 64 | + // Write element sphere center |
| 65 | + cnpy::custom::npz_save(fname, "elSphCenter", elementSphereCenter_); |
| 66 | + // Write element radius |
| 67 | + cnpy::custom::npz_save(fname, "elRadius", elementRadius_); |
| 68 | + // Write centers |
| 69 | + cnpy::custom::npz_save(fname, "centers", elementCenter_); |
| 70 | + // Write normals |
| 71 | + cnpy::custom::npz_save(fname, "normals", elementNormal_); |
| 72 | + // Write vertices TODO!!!! |
| 73 | + //const unsigned int vertices_shape[] = {dim, 10, 3}; |
| 74 | + // Write arcs TODO!!!! |
| 75 | + //const unsigned int arcs_shape[] = {dim, 10, 3}; |
83 | 76 | }
|
84 | 77 |
|
85 | 78 | void Cavity::loadCavity(const std::string & fname)
|
86 | 79 | {
|
87 |
| - // We initialize molecule_ to a dummy Molecule |
88 |
| - molecule_ = Molecule(); |
89 |
| - // Load the .npz binary file and then traverse it to get the data needed to rebuild the cavity. |
90 |
| - cnpy::npz_t loaded_cavity = cnpy::npz_load(fname); |
91 |
| - // 0. Get the number of elements |
92 |
| - cnpy::NpyArray raw_ele = loaded_cavity["elements"]; |
93 |
| - int * ne = reinterpret_cast<int*>(raw_ele.data); |
94 |
| - nElements_ = *ne; |
95 |
| - // Set the size of the irreducible portion of the cavity |
96 |
| - // it will be the same as the total size, since a restarted cavity is always C1 |
97 |
| - nIrrElements_ = nElements_; |
| 80 | + // We initialize molecule_ to a dummy Molecule |
| 81 | + molecule_ = Molecule(); |
| 82 | + // Load the .npz binary file and then traverse it to get the data needed to rebuild the cavity. |
| 83 | + cnpy::npz_t loaded_cavity = cnpy::npz_load(fname); |
| 84 | + // 0. Get the number of elements |
| 85 | + cnpy::NpyArray raw_ele = loaded_cavity["elements"]; |
| 86 | + int * ne = reinterpret_cast<int*>(raw_ele.data); |
| 87 | + nElements_ = *ne; |
| 88 | + // Set the size of the irreducible portion of the cavity |
| 89 | + // it will be the same as the total size, since a restarted cavity is always C1 |
| 90 | + nIrrElements_ = nElements_; |
98 | 91 |
|
99 |
| - // 1. Get the weights |
100 |
| - cnpy::NpyArray raw_weights = loaded_cavity["weights"]; |
101 |
| - int dim = raw_weights.shape[0]; |
102 |
| - if (dim != nElements_) { |
103 |
| - PCMSOLVER_ERROR("A problem occurred while loading the cavity. Inconsistent dimension of weights vector!"); |
104 |
| - } else { |
105 |
| - elementArea_ = getFromRawBuffer<double>(dim, 1, raw_weights.data); |
106 |
| - } |
| 92 | + // 1. Get the weights |
| 93 | + cnpy::NpyArray raw_weights = loaded_cavity["weights"]; |
| 94 | + if (raw_weights.shape[0] != nElements_) PCMSOLVER_ERROR("elementArea_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION); |
| 95 | + elementArea_ = cnpy::custom::npy_to_eigen(raw_weights); |
| 96 | + // 2. Get the element sphere center |
| 97 | + cnpy::NpyArray raw_elSphCenter = loaded_cavity["elSphCenter"]; |
| 98 | + if (raw_elSphCenter.shape[1] != nElements_) PCMSOLVER_ERROR("elementSphereCenter_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION); |
| 99 | + elementSphereCenter_ = cnpy::custom::npy_to_eigen(raw_elSphCenter); |
| 100 | + // 3. Get the element radius |
| 101 | + cnpy::NpyArray raw_elRadius = loaded_cavity["elRadius"]; |
| 102 | + if (raw_elRadius.shape[0] != nElements_) PCMSOLVER_ERROR("elementRadius_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION); |
| 103 | + elementRadius_ = cnpy::custom::npy_to_eigen(raw_elRadius); |
| 104 | + // 4. Get the centers |
| 105 | + cnpy::NpyArray raw_centers = loaded_cavity["centers"]; |
| 106 | + if (raw_centers.shape[1] != nElements_) PCMSOLVER_ERROR("elementCenter_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION); |
| 107 | + elementCenter_ = cnpy::custom::npy_to_eigen(raw_centers); |
| 108 | + // 5. Get the normal vectors |
| 109 | + cnpy::NpyArray raw_normals = loaded_cavity["normals"]; |
| 110 | + if (raw_normals.shape[1] != nElements_) PCMSOLVER_ERROR("elementNormal_: incoherent dimensions read in", BOOST_CURRENT_FUNCTION); |
| 111 | + elementNormal_ = cnpy::custom::npy_to_eigen(raw_normals); |
107 | 112 |
|
108 |
| - // 2. Get the element sphere center |
109 |
| - cnpy::NpyArray raw_elSphCenter = loaded_cavity["elSphCenter"]; |
110 |
| - dim = raw_elSphCenter.shape[1]; |
111 |
| - if (dim != nElements_) { |
112 |
| - PCMSOLVER_ERROR("A problem occurred while loading the cavity. Inconsistent dimension of element sphere radius matrix!"); |
113 |
| - } else { |
114 |
| - elementSphereCenter_ = getFromRawBuffer<double>(3, dim, raw_elSphCenter.data); |
115 |
| - } |
116 |
| - |
117 |
| - // 3. Get the element radius |
118 |
| - cnpy::NpyArray raw_elRadius = loaded_cavity["elRadius"]; |
119 |
| - dim = raw_elRadius.shape[0]; |
120 |
| - if (dim != nElements_) { |
121 |
| - PCMSOLVER_ERROR("A problem occurred while loading the cavity. Inconsistent dimension of element radius vector!"); |
122 |
| - } else { |
123 |
| - elementRadius_ = getFromRawBuffer<double>(dim, 1, raw_elRadius.data); |
124 |
| - } |
125 |
| - |
126 |
| - // 4. Get the centers |
127 |
| - cnpy::NpyArray raw_centers = loaded_cavity["centers"]; |
128 |
| - dim = raw_centers.shape[1]; |
129 |
| - if (dim != nElements_) { |
130 |
| - PCMSOLVER_ERROR("A problem occurred while loading the cavity. Inconsistent dimension of centers matrix!"); |
131 |
| - } else { |
132 |
| - elementCenter_ = getFromRawBuffer<double>(3, dim, raw_centers.data); |
133 |
| - } |
134 |
| - |
135 |
| - // 5. Get the normal vectors |
136 |
| - cnpy::NpyArray raw_normals = loaded_cavity["normals"]; |
137 |
| - dim = raw_normals.shape[1]; |
138 |
| - if (dim != nElements_) { |
139 |
| - PCMSOLVER_ERROR("A problem occurred while loading the cavity. Inconsistent dimension of normals matrix!"); |
140 |
| - } else { |
141 |
| - elementNormal_ = getFromRawBuffer<double>(3, dim, raw_normals.data); |
142 |
| - } |
143 |
| - |
144 |
| - // Reconstruct the elements_ vector |
145 |
| - for (int i = 0; i < nElements_; ++i) { |
146 |
| - bool irr = false; |
147 |
| - // PEDRA puts the irreducible tesserae first |
148 |
| - if (i < nIrrElements_) irr = true; |
149 |
| - Sphere sph(elementSphereCenter_.col(i), elementRadius_(i)); |
150 |
| - int nv = 3; // BOGUS!!! |
151 |
| - Eigen::Matrix3Xd vertices, arcs; |
152 |
| - vertices.resize(Eigen::NoChange, nv); // BOGUS!!! |
153 |
| - arcs.resize(Eigen::NoChange, nv); // BOGUS!! |
154 |
| - // Populate vertices and arcs |
155 |
| - elements_.push_back(Element(nv, 0, |
156 |
| - elementArea_(i), |
157 |
| - elementCenter_.col(i), |
158 |
| - elementNormal_.col(i), |
159 |
| - irr, sph, |
160 |
| - vertices, arcs)); |
161 |
| - } |
| 113 | + // Reconstruct the elements_ vector |
| 114 | + for (int i = 0; i < nElements_; ++i) { |
| 115 | + bool irr = false; |
| 116 | + // PEDRA puts the irreducible tesserae first |
| 117 | + if (i < nIrrElements_) irr = true; |
| 118 | + Sphere sph(elementSphereCenter_.col(i), elementRadius_(i)); |
| 119 | + int nv = 3; // BOGUS!!! |
| 120 | + Eigen::Matrix3Xd vertices, arcs; |
| 121 | + vertices.resize(Eigen::NoChange, nv); // BOGUS!!! |
| 122 | + arcs.resize(Eigen::NoChange, nv); // BOGUS!! |
| 123 | + // Populate vertices and arcs |
| 124 | + elements_.push_back(Element(nv, 0, |
| 125 | + elementArea_(i), |
| 126 | + elementCenter_.col(i), |
| 127 | + elementNormal_.col(i), |
| 128 | + irr, sph, |
| 129 | + vertices, arcs)); |
| 130 | + } |
162 | 131 | }
|
0 commit comments