12 #ifndef BEMBEL_SRC_GEOMETRY_GEOMETRYIO_HPP_
13 #define BEMBEL_SRC_GEOMETRY_GEOMETRYIO_HPP_
26 const std::string &file_name) noexcept {
27 std::vector<Bembel::Patch> out;
28 std::stringstream iss;
35 std::cerr <<
"File " << file_name <<
" doesn't exist!";
39 for (
int i = 0; i < 5; i++) {
44 for (
int i = 0; i < 5; i++) {
47 infoInt[i] = stoi(word);
50 for (
int patchNr = 1; patchNr <= infoInt[2]; patchNr++) {
52 std::vector<double> tempknt1;
53 std::vector<double> tempknt2;
54 std::vector<int> info;
55 std::vector<Eigen::MatrixXd> tmp;
62 info.push_back(stoi(word));
70 info.push_back(stoi(word));
83 for (
int k = 0; k < info[0] + info[2] + 1; k++) {
85 tempknt1.push_back(atof(word.c_str()));
92 for (
int k = 0; k < info[1] + info[3] + 1; k++) {
94 tempknt2.push_back(atof(word.c_str()));
100 for (
int k = 0; k < 4; k++) {
101 Eigen::Matrix<double, -1, -1> tempMatrix(
105 for (
int i = 0; i < M; i++)
106 for (
int j = 0; j < N; j++) {
109 tempMatrix(i, j) = atof(word.c_str());
112 tmp.push_back(tempMatrix);
116 tempPatch.
init_Patch(tmp, tempknt1, tempknt2);
117 out.push_back(tempPatch);
131 int number_of_patches) noexcept {
133 file.open(file_name);
134 file <<
"# nurbs mesh v.2.1"
136 file <<
"# " << file_name <<
"\r\n";
137 file <<
"# Generated by BEMBEL, see www.bembel.eu"
141 file <<
"2 3 " << number_of_patches <<
" 0 0 "
154 void WritePatch(
const std::string &file_name,
int current_patch_number,
155 const std::vector<Eigen::MatrixXd> &xyzw,
156 const std::vector<double> &knt1,
157 const std::vector<double> &knt2) noexcept {
158 std::ofstream file(file_name, std::ios::app);
159 int N = xyzw[0].cols();
160 int M = xyzw[0].rows();
161 int p1 = knt1.size() - N - 1;
162 int p2 = knt2.size() - M - 1;
163 file <<
"PATCH " << current_patch_number <<
" \r\n";
164 file << p1 <<
" " << p2 <<
" \r\n";
165 file << N <<
" " << M <<
" \r\n";
167 for (
unsigned int i = 0; i < knt1.size() - 1; i++) {
168 file << std::fixed << std::setprecision(15) << knt1[i] <<
" ";
170 file << std::fixed << std::setprecision(15) << knt1[knt1.size() - 1]
172 for (
unsigned int i = 0; i < knt2.size() - 1; i++) {
173 file << std::fixed << std::setprecision(15) << knt2[i] <<
" ";
175 file << std::fixed << std::setprecision(15) << knt2[knt2.size() - 1]
179 for (
unsigned int n = 0; n < xyzw.size(); n++) {
180 for (
int i = 0; i < M; i++)
181 for (
int j = 0; j < N; j++) {
182 file << std::fixed << std::setprecision(15) << xyzw[n](i, j);
183 if (N * i + j == M * N - 1) {
205 const std::string &file_name) {
206 const int number_of_patches =
Geometry.size();
207 MakeFile(file_name, number_of_patches);
211 assert(patch.unique_knots_x_.size() == 2 &&
212 "I assume 0 and 1 as unique knots!");
213 assert(patch.unique_knots_y_.size() == 2 &&
214 "I assume 0 and 1 as unique knots!");
216 const int polynomial_degree_x = patch.polynomial_degree_x_;
217 const int polynomial_degree_y = patch.polynomial_degree_y_;
219 std::vector<double> knt_x(2 * polynomial_degree_x, 1.0);
220 std::vector<double> knt_y(2 * polynomial_degree_y, 1.0);
221 for (
auto i = 0; i < polynomial_degree_x; ++i) knt_x[i] = 0.0;
222 for (
auto i = 0; i < polynomial_degree_y; ++i) knt_y[i] = 0.0;
224 const int number_of_points_x = knt_x.size() - polynomial_degree_x;
225 const int number_of_points_y = knt_y.size() - polynomial_degree_y;
227 std::vector<Eigen::MatrixXd> data(
228 4, Eigen::MatrixXd::Zero(number_of_points_y, number_of_points_x));
230 const int matrix_size = number_of_points_x * number_of_points_y;
231 for (
auto i = 0; i < matrix_size; ++i) {
232 const int rowIndex = i % number_of_points_y;
233 const int colIndex = i / number_of_points_y;
234 data[0](rowIndex, colIndex) = patch.data_[4 * i];
235 data[1](rowIndex, colIndex) = patch.data_[4 * i + 1];
236 data[2](rowIndex, colIndex) = patch.data_[4 * i + 2];
237 data[3](rowIndex, colIndex) = patch.data_[4 * i + 3];
240 WritePatch(file_name, patch_count, data, knt_x, knt_y);
this class wraps a GeometryVector and provides some basic functionality, like reading Geometry files
void init_Patch(const std::vector< Eigen::Matrix< double, -1, -1 >> &xyzw, const std::vector< double > &x_knots, const std::vector< double > &y_knots)
init
void WriteDATFile(const std::vector< Patch > &Geometry, const std::string &file_name)
exports a geometry from Bembel to a .dat file.
std::vector< Patch > LoadGeometryFileDAT(const std::string &file_name) noexcept
loads geometry from file with GEOPDE-format. Note that the direction of the normals must be consisten...
Routines for the evalutation of pointwise errors.
void WritePatch(const std::string &file_name, int current_patch_number, const std::vector< Eigen::MatrixXd > &xyzw, const std::vector< double > &knt1, const std::vector< double > &knt2) noexcept
method to write Patch information into textfile
void MakeFile(const std::string &file_name, int number_of_patches) noexcept
method to generate textfile for the geometry