34 #include "world_builder/config.h" 40 #include "vtu11/vtu11.hpp" 46 #define OMPI_SKIP_MPICXX 1 47 #define MPICH_SKIP_MPICXX 52 #ifdef WB_USE_FP_EXCEPTIONS 76 const std::vector<bool> &include_tag,
77 vtu11::Vtu11UnstructuredMesh &input_mesh,
78 const std::vector<vtu11::DataSetData> &input_data,
79 vtu11::Vtu11UnstructuredMesh &output_mesh,
80 std::vector<vtu11::DataSetData> &output_data);
83 const std::vector<bool> &include_tag,
84 vtu11::Vtu11UnstructuredMesh &input_mesh,
85 const std::vector<vtu11::DataSetData> &input_data,
86 vtu11::Vtu11UnstructuredMesh &output_mesh,
87 std::vector<vtu11::DataSetData> &output_data)
89 output_data.resize(input_data.size());
90 const std::int64_t
invalid = -1;
91 std::vector<std::int64_t> vertex_index_map(input_mesh.points().size(),
invalid);
93 const unsigned int n_vert_per_cell = (dim==3)?8:4;
95 const std::size_t n_cells = input_mesh.types().size();
96 std::uint64_t dst_cellid = 0;
97 unsigned int tag_index = 3;
98 for (std::size_t cellidx = 0; cellidx <n_cells; ++cellidx)
100 int highest_tag = -1;
101 for (
size_t idx=cellidx*n_vert_per_cell; idx<(cellidx+1)*n_vert_per_cell; ++idx)
103 const std::size_t src_vid =
static_cast<size_t>(input_mesh.connectivity()[idx]);
104 highest_tag = std::max(highest_tag,static_cast<int>(input_data[tag_index][src_vid]));
106 if (highest_tag < 0 || include_tag[static_cast<size_t>(highest_tag)]==
false)
111 for (
size_t idx=cellidx*n_vert_per_cell; idx<(cellidx+1)*n_vert_per_cell; ++idx)
113 const size_t src_vid =
static_cast<size_t>(input_mesh.connectivity()[idx]);
115 std::int64_t dst_vid = vertex_index_map[src_vid];
116 if (dst_vid == invalid)
118 dst_vid =
static_cast<std::int64_t
>(output_mesh.points().size()/3);
119 vertex_index_map[src_vid] = dst_vid;
121 for (
unsigned int i=0; i<3; ++i)
122 output_mesh.points().emplace_back(input_mesh.points()[src_vid*3+i]);
124 for (
unsigned int d=0; d<input_data.size(); ++d)
130 for (
unsigned int i=0; i<3; ++i)
131 output_data[d].push_back(input_data[d][src_vid*3+i]);
135 output_data[d].push_back(input_data[d][src_vid]);
139 output_mesh.connectivity().push_back(dst_vid);
142 output_mesh.offsets().push_back(static_cast<long int>(dst_cellid*n_vert_per_cell));
144 output_mesh.types().push_back(input_mesh.types()[cellidx]);
163 pool.resize(number_of_threads);
169 template<
typename Callable>
173 const size_t n = end - start + 1;
174 size_t slice =
static_cast<size_t>(std::round(n / static_cast<size_t>((pool.size()))));
175 slice = std::max(slice, static_cast<size_t>(1));
178 auto loop_function = [&func] (
size_t k1,
size_t k2)
180 for (
size_t k = k1; k < k2; k++)
188 size_t i2 = std::min(start + slice, end);
189 for (
size_t i = 0; i + 1 < pool.size() && i1 < end; ++i)
191 pool[i] = std::thread(loop_function, i1, i2);
193 i2 = std::min(i2 + slice, end);
197 pool[pool.size()-1] = std::thread(loop_function, i1, end);
201 for (std::thread &t : pool)
223 const double r = in_point.
norm();
224 const double theta = std::atan2(in_point[1],in_point[0]);
225 const double phi = std::acos(in_point[2]/r);
234 double x2,
double y2,
double z2,
235 double x3,
double y3,
double z3,
236 double x4,
double y4,
double z4,
237 std::vector<double> &x, std::vector<double> &y, std::vector<double> &z,
238 std::vector<bool> &hull,
size_t level)
242 for (
size_t j = 0; j < level+1; ++j)
244 for (
size_t i = 0; i < level+1; ++i)
252 const double x0 = -pi4 +
static_cast<double>(i) * 2.0 * static_cast<double>(pi4)/
static_cast<double>(level);
253 const double y0 = -pi4 +
static_cast<double>(j) * 2.0 * static_cast<double>(pi4)/
static_cast<double>(level);
254 const double r = std::tan(x0);
255 const double s = std::tan(y0);
258 const double N1 = 0.25 * (1.0 - r) * (1.0 - s);
259 const double N2 = 0.25 * (1.0 + r) * (1.0 - s);
260 const double N3 = 0.25 * (1.0 + r) * (1.0 + s);
261 const double N4 = 0.25 * (1.0 - r) * (1.0 + s);
263 x[counter] = x1 * N1 + x2 * N2 + x3 * N3 + x4 * N4;
264 y[counter] = y1 * N1 + y2 * N2 + y3 * N3 + y4 * N4;
265 z[counter] = z1 * N1 + z2 * N2 + z3 * N3 + z4 * N4;
267 if (i == 0) hull[counter] =
true;
268 if (j == 0) hull[counter] =
true;
269 if (i == level) hull[counter] =
true;
270 if (j == level) hull[counter] =
true;
279 std::vector<std::string> vector;
280 for (
int i=1; i < argc; ++i)
281 vector.emplace_back(argv[i]);
288 return std::find(begin, end, option) != end;
291 int main(
int argc,
char **argv)
295 #ifdef WB_USE_FP_EXCEPTIONS 298 feclearexcept(FE_DIVBYZERO|FE_INVALID);
301 feenableexcept(FE_DIVBYZERO|FE_INVALID);
309 std::string data_file;
313 bool output_by_tag =
false;
315 bool output_filtered =
false;
318 size_t compositions = 0;
321 std::string grid_type =
"chunk";
337 size_t number_of_threads = std::min(20u,1+std::thread::hardware_concurrency()/2);
338 unsigned int max_resolution = std::numeric_limits<unsigned int>::max();
344 std::cout <<
"World Builder Grid Visualization tool.\n" 345 <<
"GWB Version: " << WorldBuilder::Version::MAJOR <<
"." 346 << WorldBuilder::Version::MINOR <<
"." 347 << WorldBuilder::Version::PATCH <<
"." 348 << WorldBuilder::Version::LABEL <<
"\n" 349 <<
"git hash: " << WorldBuilder::Version::GIT_SHA1 <<
" branch: " << WorldBuilder::Version::GIT_BRANCH
356 std::cout <<
"World Builder Grid Visualization tool.\n" 357 <<
"This program loads a world builder file and generates a visualization on a structured grid " 358 <<
"based on information specified in a separate .grid configuration file.\n\n" 360 << argv[0] <<
" [-j N] [--filtered] [--by-tag] example.wb example.grid\n\n" 361 <<
"Available options:\n" 362 <<
" -j N Specify the number of threads the visualizer is allowed to use. Default: " << number_of_threads <<
".\n" 363 <<
" --filtered Also produce a .filtered.vtu that removes cells only containing mantle or background.\n" 364 <<
" --by-tag Also produce a sequence of .N.vtu files that only contain cells of a specific tag.\n" 365 <<
" --resolution-limit X Specify a maximum resolution." 366 <<
" -h or --help To get this help screen.\n" 367 <<
" -v or --version To see version information.\n";
373 for (
size_t i = 0; i < options_vector.size(); ++i)
375 if (options_vector[i] ==
"-j")
378 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
379 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
383 if (options_vector[i] ==
"--filtered")
385 output_filtered =
true;
386 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
390 if (options_vector[i] ==
"--by-tag")
392 output_by_tag =
true;
393 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
397 if (options_vector[i] ==
"--resolution-limit")
400 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
401 options_vector.erase(options_vector.begin()+
static_cast<std::vector<std::string>::difference_type
>(i));
407 if (options_vector.size() != 2)
409 std::cout <<
"World Builder Grid Visualization tool.\n" 410 <<
"Usage: " << argv[0] <<
" example.wb example.grid\n" 411 <<
"Try '" << argv[0] <<
" --help' for more information." << std::endl;
416 wb_file = options_vector[0];
417 data_file = options_vector[1];
420 catch (std::exception &e)
422 std::cerr <<
"error: " << e.what() <<
"\n";
427 std::cerr <<
"Exception of unknown type!\n";
434 MPI_Init(&argc,&argv);
435 MPI_Comm_rank(MPI_COMM_WORLD, &MPI_RANK);
438 std::cout <<
"[1/6] Parsing file... \r";
445 std::cout <<
"[2/6] Starting the world builder with " << number_of_threads <<
" threads... \r";
448 std::unique_ptr<WorldBuilder::World> world;
451 world = std::make_unique<WorldBuilder::World>(wb_file);
453 catch (std::exception &e)
455 std::cerr <<
"Could not start the World builder from file '" << wb_file <<
"', error: " << e.what() <<
"\n";
464 std::cerr <<
"Exception of unknown type!\n";
480 std::cout <<
"[3/6] Reading grid file... \r";
484 std::ifstream data_stream(data_file);
488 "Could not find the provided config file at the specified location: " + data_file);
492 std::vector<std::vector<std::string> > data;
495 while (std::getline(data_stream, temp))
497 std::istringstream buffer(temp);
498 std::vector<std::string> line((std::istream_iterator<std::string>(buffer)),
499 std::istream_iterator<std::string>());
503 for (
auto &line_i : line)
504 line_i.erase(std::remove(line_i.begin(), line_i.end(),
','), line_i.end());
506 data.push_back(line);
509 std::string vtu_output_format =
"ASCII";
511 for (
auto &line_i : data)
516 if (line_i[0] ==
"#")
519 if (line_i[0] ==
"grid_type" && line_i[1] ==
"=")
521 grid_type = line_i[2];
524 if (line_i[0] ==
"dim" && line_i[1] ==
"=")
529 if (line_i[0] ==
"vtu_output_format" && line_i[1] ==
"=")
531 vtu_output_format = line_i[2];
534 if (line_i[0] ==
"compositions" && line_i[1] ==
"=")
537 if (line_i[0] ==
"x_min" && line_i[1] ==
"=")
539 if (line_i[0] ==
"x_max" && line_i[1] ==
"=")
541 if (line_i[0] ==
"y_min" && line_i[1] ==
"=")
543 if (line_i[0] ==
"y_max" && line_i[1] ==
"=")
545 if (line_i[0] ==
"z_min" && line_i[1] ==
"=")
547 if (line_i[0] ==
"z_max" && line_i[1] ==
"=")
550 if (line_i[0] ==
"n_cell_x" && line_i[1] ==
"=")
552 if (line_i[0] ==
"n_cell_y" && line_i[1] ==
"=")
554 if (line_i[0] ==
"n_cell_z" && line_i[1] ==
"=")
559 WBAssertThrow(dim == 2 || dim == 3,
"dim should be set in the grid file and can only be 2 or 3.");
561 WBAssertThrow(!std::isnan(x_min),
"x_min is not a number:" << x_min <<
". This value has probably not been provided in the grid file.");
562 WBAssertThrow(!std::isnan(x_max),
"x_max is not a number:" << x_max <<
". This value has probably not been provided in the grid file.");
563 WBAssertThrow(dim == 2 || !std::isnan(y_min),
"y_min is not a number:" << y_min <<
". This value has probably not been provided in the grid file.");
564 WBAssertThrow(dim == 2 || !std::isnan(y_max),
"y_max is not a number:" << y_max <<
". This value has probably not been provided in the grid file.");
565 WBAssertThrow(!std::isnan(z_min),
"z_min is not a number:" << z_min <<
". This value has probably not been provided in the grid file.");
566 WBAssertThrow(!std::isnan(z_max),
"z_max is not a number:" << z_max <<
". This value has probably not been provided in the grid file.");
569 WBAssertThrow(n_cell_x != 0,
"n_cell_z may not be equal to zero: " << n_cell_x <<
'.');
574 WBAssertThrow(dim == 3 || n_cell_z != 0,
"In 3d n_cell_z may not be equal to zero: " << n_cell_y <<
'.');
579 WBAssertThrow(n_cell_z != 0,
"n_cell_z may not be equal to zero: " << n_cell_z <<
'.');
592 if (grid_type ==
"sphere")
593 WBAssert(n_cell_x == n_cell_y,
"For the sphere grid the amount of cells in the x (long) and y (lat) direction have to be the same.");
595 if (grid_type ==
"spherical" ||
596 grid_type ==
"chunk" ||
597 grid_type ==
"annulus")
613 std::vector<double> grid_x(0);
614 std::vector<double> grid_y(0);
615 std::vector<double> grid_z(0);
616 std::vector<double> grid_depth(0);
618 std::vector<std::vector<size_t> > grid_connectivity(0);
621 const bool compress_size =
true;
629 std::cout <<
"[4/6] Building the grid... \r";
631 WBAssertThrow(dim == 2 || dim == 3,
"Dimension should be 2d or 3d.");
632 if (grid_type ==
"cartesian")
634 n_cell = n_cell_x * n_cell_z * (dim == 3 ? n_cell_y : 1);
635 if (!compress_size && dim == 3)
638 n_p = (n_cell_x + 1) * (n_cell_z + 1) * (dim == 3 ? (n_cell_y + 1) : 1);
641 const double dx = (x_max - x_min) / static_cast<double>(n_cell_x);
642 const double dy = dim == 2 ? 0 : (y_max - y_min) / static_cast<double>(n_cell_y);
643 const double dz = (z_max - z_min) / static_cast<double>(n_cell_z);
646 WBAssertThrow(!std::isnan(dx),
"dz is not a number:" << dz <<
'.');
647 WBAssertThrow(dim == 2 || !std::isnan(dy),
"dz is not a number:" << dz <<
'.');
648 WBAssertThrow(!std::isnan(dz),
"dz is not a number:" << dz <<
'.');
651 const double surface = z_max;
659 grid_depth.resize(n_p);
665 for (
size_t j = 0; j <= n_cell_z; ++j)
667 for (
size_t i = 0; i <= n_cell_x; ++i)
669 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
670 grid_z[counter] = z_min +
static_cast<double>(j) * dz;
671 grid_depth[counter] = (surface - z_min) - static_cast<double>(j) * dz;
680 for (
size_t i = 0; i <= n_cell_x; ++i)
682 for (
size_t j = 0; j <= n_cell_y; ++j)
684 for (
size_t k = 0; k <= n_cell_z; ++k)
686 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
687 grid_y[counter] = y_min +
static_cast<double>(j) * dy;
688 grid_z[counter] = z_min +
static_cast<double>(k) * dz;
689 grid_depth[counter] = (surface - z_min) - static_cast<double>(k) * dz;
697 for (
size_t i = 0; i < n_cell_x; ++i)
699 for (
size_t j = 0; j < n_cell_y; ++j)
701 for (
size_t k = 0; k < n_cell_z; ++k)
705 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
706 grid_y[counter] = y_min +
static_cast<double>(j) * dy;
707 grid_z[counter] = z_min +
static_cast<double>(k) * dz;
708 grid_depth[counter] = (surface - z_min) - static_cast<double>(k) * dz;
711 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dx;
712 grid_y[counter] = y_min +
static_cast<double>(j) * dy;
713 grid_z[counter] = z_min +
static_cast<double>(k) * dz;
714 grid_depth[counter] = (surface - z_min) - static_cast<double>(k) * dz;
717 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dx;
718 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dy;
719 grid_z[counter] = z_min +
static_cast<double>(k) * dz;
720 grid_depth[counter] = (surface - z_min) - static_cast<double>(k) * dz;
723 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
724 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dy;
725 grid_z[counter] = z_min +
static_cast<double>(k) * dz;
726 grid_depth[counter] = (surface - z_min) - static_cast<double>(k) * dz;
729 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
730 grid_y[counter] = y_min +
static_cast<double>(j) * dy;
731 grid_z[counter] = z_min + (
static_cast<double>(k) + 1.0) * dz;
732 grid_depth[counter] = (surface - z_min) - (static_cast<double>(k) + 1.0) * dz;
735 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dx;
736 grid_y[counter] = y_min +
static_cast<double>(j) * dy;
737 grid_z[counter] = z_min + (
static_cast<double>(k) + 1.0) * dz;
738 grid_depth[counter] = (surface - z_min) - (static_cast<double>(k) + 1.0) * dz;
741 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dx;
742 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dy;
743 grid_z[counter] = z_min + (
static_cast<double>(k) + 1.0) * dz;
744 grid_depth[counter] = (surface - z_min) - (static_cast<double>(k) + 1.0) * dz;
747 grid_x[counter] = x_min +
static_cast<double>(i) * dx;
748 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dy;
749 grid_z[counter] = z_min + (
static_cast<double>(k) + 1.0) * dz;
750 grid_depth[counter] = (surface - z_min) - (static_cast<double>(k) + 1.0) * dz;
751 WBAssert(counter < n_p,
"Assert counter smaller then n_P: counter = " << counter <<
", n_p = " << n_p);
760 grid_connectivity.resize(n_cell,std::vector<size_t>((dim-1)*4));
765 for (
size_t j = 1; j <= n_cell_z; ++j)
767 for (
size_t i = 1; i <= n_cell_x; ++i)
769 grid_connectivity[counter][0] = i + (j - 1) * (n_cell_x + 1) - 1;
770 grid_connectivity[counter][1] = i + 1 + (j - 1) * (n_cell_x + 1) - 1;
771 grid_connectivity[counter][2] = i + 1 + j * (n_cell_x + 1) - 1;
772 grid_connectivity[counter][3] = i + j * (n_cell_x + 1) - 1;
781 for (
size_t i = 1; i <= n_cell_x; ++i)
783 for (
size_t j = 1; j <= n_cell_y; ++j)
785 for (
size_t k = 1; k <= n_cell_z; ++k)
787 grid_connectivity[counter][0] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j - 1) + k - 1;
788 grid_connectivity[counter][1] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j - 1) + k - 1;
789 grid_connectivity[counter][2] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j ) + k - 1;
790 grid_connectivity[counter][3] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j ) + k - 1;
791 grid_connectivity[counter][4] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j - 1) + k;
792 grid_connectivity[counter][5] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j - 1) + k;
793 grid_connectivity[counter][6] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j ) + k;
794 grid_connectivity[counter][7] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j ) + k;
802 for (
size_t i = 0; i < n_cell; ++i)
804 grid_connectivity[i][0] = counter;
805 grid_connectivity[i][1] = counter + 1;
806 grid_connectivity[i][2] = counter + 2;
807 grid_connectivity[i][3] = counter + 3;
808 grid_connectivity[i][4] = counter + 4;
809 grid_connectivity[i][5] = counter + 5;
810 grid_connectivity[i][6] = counter + 6;
811 grid_connectivity[i][7] = counter + 7;
812 counter = counter + 8;
817 else if (grid_type ==
"annulus")
826 const double inner_radius = z_min;
827 const double outer_radius = z_max;
829 const double l_outer = 2.0 *
Consts::PI * outer_radius;
831 const double lr = outer_radius - inner_radius;
832 const double dr = lr /
static_cast<double>(n_cell_z);
834 const size_t n_cell_t =
static_cast<size_t>((2.0 *
Consts::PI * outer_radius)/dr);
837 n_cell = n_cell_t *n_cell_z;
838 n_p = n_cell_t *(n_cell_z + 1);
840 const double sx = l_outer /
static_cast<double>(n_cell_t);
841 const double sz = dr;
845 grid_depth.resize(n_p);
848 for (
size_t j = 0; j <= n_cell_z; ++j)
850 for (
size_t i = 1; i <= n_cell_t; ++i)
852 grid_x[counter] = (
static_cast<double>(i) - 1.0) * sx;
853 grid_z[counter] =
static_cast<double>(j) * sz;
859 for (
size_t j = 1; j <= n_cell_z+1; ++j)
861 for (
size_t i = 1; i <= n_cell_t; ++i)
863 const double xi = grid_x[counter];
864 const double zi = grid_z[counter];
865 const double theta = xi / l_outer * 2.0 *
Consts::PI;
866 grid_x[counter] =
std::cos(theta) * (inner_radius + zi);
867 grid_z[counter] =
std::sin(theta) * (inner_radius + zi);
868 grid_depth[counter] = outer_radius - std::sqrt(grid_x[counter] * grid_x[counter] + grid_z[counter] * grid_z [counter]);
869 grid_depth[counter] = (std::fabs(grid_depth[counter]) < 1e-8 ? 0 : grid_depth[counter]);
874 grid_connectivity.resize(n_cell,std::vector<size_t>(4));
876 for (
size_t j = 1; j <= n_cell_z; ++j)
878 for (
size_t i = 1; i <= n_cell_t; ++i)
880 std::vector<size_t> cell_connectivity(4);
881 cell_connectivity[0] = counter + 1;
882 cell_connectivity[1] = counter + 1 + 1;
883 cell_connectivity[2] = i + j * n_cell_t + 1;
884 cell_connectivity[3] = i + j * n_cell_t;
887 cell_connectivity[1] = cell_connectivity[1] - n_cell_t;
888 cell_connectivity[2] = cell_connectivity[2] - n_cell_t;
890 grid_connectivity[counter][0] = cell_connectivity[1] - 1;
891 grid_connectivity[counter][1] = cell_connectivity[0] - 1;
892 grid_connectivity[counter][2] = cell_connectivity[3] - 1;
893 grid_connectivity[counter][3] = cell_connectivity[2] - 1;
898 else if (grid_type ==
"chunk")
900 const double inner_radius = z_min;
901 const double outer_radius = z_max;
903 WBAssertThrow(x_min <= x_max,
"The minimum longitude must be less than the maximum longitude.");
904 WBAssertThrow(y_min <= y_max,
"The minimum latitude must be less than the maximum latitude.");
905 WBAssertThrow(inner_radius < outer_radius,
"The inner radius must be less than the outer radius.");
908 " must be less than or equal to 360 degree.");
910 WBAssertThrow(y_min >= - 0.5 *
Consts::PI,
"The minimum latitude must be larger then or equal to -90 degree.");
913 const double opening_angle_long_rad = (x_max - x_min);
914 const double opening_angle_lat_rad = (y_max - y_min);
916 n_cell = n_cell_x * n_cell_z * (dim == 3 ? n_cell_y : 1);
917 if (!compress_size && dim == 3)
920 n_p = (n_cell_x + 1) * (n_cell_z + 1) * (dim == 3 ? (n_cell_y + 1) : 1);
922 const double dlong = opening_angle_long_rad /
static_cast<double>(n_cell_x);
923 const double dlat = dim == 3 ? opening_angle_lat_rad /
static_cast<double>(n_cell_y) : 0.;
924 const double lr = outer_radius - inner_radius;
925 const double dr = lr /
static_cast<double>(n_cell_z);
928 grid_y.resize(dim == 3 ? n_p : 0);
930 grid_depth.resize(n_p);
932 std::cout <<
"[4/6] Building the grid: stage 1 of 3 \r";
937 for (
size_t i = 1; i <= n_cell_x + 1; ++i)
938 for (
size_t j = 1; j <= n_cell_z + 1; ++j)
940 grid_x[counter] = x_min + (
static_cast<double>(i) - 1.0) * dlong;
941 grid_z[counter] = inner_radius + (
static_cast<double>(j) - 1.0) * dr;
942 grid_depth[counter] = lr - (
static_cast<double>(j) - 1.0) * dr;
950 for (
size_t i = 1; i <= n_cell_x + 1; ++i)
951 for (
size_t j = 1; j <= n_cell_y + 1; ++j)
952 for (
size_t k = 1; k <= n_cell_z + 1; ++k)
954 grid_x[counter] = x_min + (
static_cast<double>(i) - 1.0) * dlong;
955 grid_y[counter] = y_min + (
static_cast<double>(j) - 1.0) * dlat;
956 grid_z[counter] = inner_radius + (
static_cast<double>(k) - 1.0) * dr;
957 grid_depth[counter] = lr - (
static_cast<double>(k) - 1.0) * dr;
963 for (
size_t i = 0; i < n_cell_x; ++i)
965 for (
size_t j = 0; j < n_cell_y; ++j)
967 for (
size_t k = 0; k < n_cell_z; ++k)
971 grid_x[counter] = x_min +
static_cast<double>(i) * dlong;
972 grid_y[counter] = y_min +
static_cast<double>(j) * dlat;
973 grid_z[counter] = inner_radius +
static_cast<double>(k) * dr;
974 grid_depth[counter] = lr -
static_cast<double>(k) * dr;
977 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dlong;
978 grid_y[counter] = y_min +
static_cast<double>(j) * dlat;
979 grid_z[counter] = inner_radius +
static_cast<double>(k) * dr;
980 grid_depth[counter] = lr -
static_cast<double>(k) * dr;
983 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dlong;
984 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dlat;
985 grid_z[counter] = inner_radius +
static_cast<double>(k) * dr;
986 grid_depth[counter] = lr -
static_cast<double>(k) * dr;
989 grid_x[counter] = x_min +
static_cast<double>(i) * dlong;
990 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dlat;
991 grid_z[counter] = inner_radius +
static_cast<double>(k) * dr;
992 grid_depth[counter] = lr -
static_cast<double>(k) * dr;
995 grid_x[counter] = x_min +
static_cast<double>(i) * dlong;
996 grid_y[counter] = y_min +
static_cast<double>(j) * dlat;
997 grid_z[counter] = inner_radius + (
static_cast<double>(k) + 1.0) * dr;
998 grid_depth[counter] = lr - (
static_cast<double>(k) + 1.0) * dr;
1001 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dlong;
1002 grid_y[counter] = y_min +
static_cast<double>(j) * dlat;
1003 grid_z[counter] = inner_radius + (
static_cast<double>(k) + 1.0) * dr;
1004 grid_depth[counter] = lr - (
static_cast<double>(k) + 1.0) * dr;
1007 grid_x[counter] = x_min + (
static_cast<double>(i) + 1.0) * dlong;
1008 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dlat;
1009 grid_z[counter] = inner_radius + (
static_cast<double>(k) + 1.0) * dr;
1010 grid_depth[counter] = lr - (
static_cast<double>(k) + 1.0) * dr;
1013 grid_x[counter] = x_min +
static_cast<double>(i) * dlong;
1014 grid_y[counter] = y_min + (
static_cast<double>(j) + 1.0) * dlat;
1015 grid_z[counter] = inner_radius + (
static_cast<double>(k) + 1.0) * dr;
1016 grid_depth[counter] = lr - (
static_cast<double>(k) + 1.0) * dr;
1017 WBAssert(counter < n_p,
"Assert counter smaller then n_P: counter = " << counter <<
", n_p = " << n_p);
1025 std::cout <<
"[4/6] Building the grid: stage 2 of 3 \r";
1029 for (
size_t i = 0; i < n_p; ++i)
1032 const double longitude = grid_x[i];
1033 const double radius = grid_z[i];
1035 grid_x[i] = radius *
std::cos(longitude);
1036 grid_z[i] = radius *
std::sin(longitude);
1041 for (
size_t i = 0; i < n_p; ++i)
1044 const double longitude = grid_x[i];
1045 const double latitutde = grid_y[i];
1046 const double radius = grid_z[i];
1050 grid_z[i] = radius *
std::sin(latitutde);
1053 std::cout <<
"[4/6] Building the grid: stage 3 of 3 \r";
1056 grid_connectivity.resize(n_cell,std::vector<size_t>((dim-1)*4));
1061 for (
size_t i = 1; i <= n_cell_x; ++i)
1063 for (
size_t j = 1; j <= n_cell_z; ++j)
1065 grid_connectivity[counter][0] = (n_cell_z + 1) * (i - 1) + j - 1;
1066 grid_connectivity[counter][1] = (n_cell_z + 1) * (i - 1) + j;
1067 grid_connectivity[counter][2] = (n_cell_z + 1) * (i ) + j;
1068 grid_connectivity[counter][3] = (n_cell_z + 1) * (i ) + j - 1;
1070 counter = counter+1;
1071 std::cout <<
"[4/6] Building the grid: stage 3 of 3 [" << (
static_cast<double>(i)/static_cast<double>(n_cell))*100.0 <<
"%] \r";
1080 for (
size_t i = 1; i <= n_cell_x; ++i)
1082 for (
size_t j = 1; j <= n_cell_y; ++j)
1084 for (
size_t k = 1; k <= n_cell_z; ++k)
1086 grid_connectivity[counter][0] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j - 1) + k - 1;
1087 grid_connectivity[counter][1] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j - 1) + k - 1;
1088 grid_connectivity[counter][2] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j ) + k - 1;
1089 grid_connectivity[counter][3] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j ) + k - 1;
1090 grid_connectivity[counter][4] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j - 1) + k;
1091 grid_connectivity[counter][5] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j - 1) + k;
1092 grid_connectivity[counter][6] = (n_cell_y + 1) * (n_cell_z + 1) * (i ) + (n_cell_z + 1) * (j ) + k;
1093 grid_connectivity[counter][7] = (n_cell_y + 1) * (n_cell_z + 1) * (i - 1) + (n_cell_z + 1) * (j ) + k;
1101 for (
size_t i = 0; i < n_cell; ++i)
1103 grid_connectivity[i][0] = counter;
1104 grid_connectivity[i][1] = counter + 1;
1105 grid_connectivity[i][2] = counter + 2;
1106 grid_connectivity[i][3] = counter + 3;
1107 grid_connectivity[i][4] = counter + 4;
1108 grid_connectivity[i][5] = counter + 5;
1109 grid_connectivity[i][6] = counter + 6;
1110 grid_connectivity[i][7] = counter + 7;
1111 counter = counter + 8;
1112 std::cout <<
"[4/6] Building the grid: stage 3 of 3 [" << (
static_cast<double>(i)/static_cast<double>(n_cell))*100.0 <<
"%] \r";
1118 else if (grid_type ==
"sphere")
1124 const double inner_radius = z_min;
1125 const double outer_radius = z_max;
1127 const size_t n_block = 12;
1129 const size_t block_n_cell = n_cell_x*n_cell_x;
1130 const size_t block_n_p = (n_cell_x + 1) * (n_cell_x + 1);
1131 const size_t block_n_v = 4;
1134 std::vector<std::vector<double> > block_grid_x(n_block,std::vector<double>(block_n_p));
1135 std::vector<std::vector<double> > block_grid_y(n_block,std::vector<double>(block_n_p));
1136 std::vector<std::vector<double> > block_grid_z(n_block,std::vector<double>(block_n_p));
1137 std::vector<std::vector<std::vector<size_t> > > block_grid_connectivity(n_block,std::vector<std::vector<size_t> >(block_n_cell,std::vector<size_t>(block_n_v)));
1138 std::vector<std::vector<bool> > block_grid_hull(n_block,std::vector<bool>(block_n_p));
1143 for (
size_t i_block = 0; i_block < n_block; ++i_block)
1145 const size_t block_n_cell_x = n_cell_x;
1146 const size_t block_n_cell_y = n_cell_x;
1147 const double Lx = 1.0;
1148 const double Ly = 1.0;
1151 for (
size_t j = 0; j <= block_n_cell_y; ++j)
1153 for (
size_t i = 0; i <= block_n_cell_y; ++i)
1155 block_grid_x[i_block][counter] =
static_cast<double>(i) * Lx / static_cast<double>(block_n_cell_x);
1156 block_grid_y[i_block][counter] =
static_cast<double>(j) * Ly / static_cast<double>(block_n_cell_y);
1157 block_grid_z[i_block][counter] = 0.0;
1165 for (
size_t j = 1; j <= block_n_cell_y; ++j)
1167 for (
size_t i = 1; i <= block_n_cell_x; ++i)
1169 block_grid_connectivity[i_block][counter][0] = i + (j - 1) * (block_n_cell_x + 1) - 1;
1170 block_grid_connectivity[i_block][counter][1] = i + 1 + (j - 1) * (block_n_cell_x + 1) - 1;
1171 block_grid_connectivity[i_block][counter][2] = i + 1 + j * (block_n_cell_x + 1) - 1;
1172 block_grid_connectivity[i_block][counter][3] = i + j * (block_n_cell_x + 1) - 1;
1186 double zA = -1.0 / std::sqrt(2.0);
1190 double zB = -1.0 / std::sqrt(2.0);
1194 double zC = 1.0 / std::sqrt(2.0);
1198 double zD = 1.0 / std::sqrt(2.0);
1201 double xM = (xA+xB+xC)/3.0;
1202 double yM = (yA+yB+yC)/3.0;
1203 double zM = (zA+zB+zC)/3.0;
1205 double xN = (xA+xD+xC)/3.0;
1206 double yN = (yA+yD+yC)/3.0;
1207 double zN = (zA+zD+zC)/3.0;
1209 double xP = (xA+xD+xB)/3.0;
1210 double yP = (yA+yD+yB)/3.0;
1211 double zP = (zA+zD+zB)/3.0;
1213 double xQ = (xC+xD+xB)/3.0;
1214 double yQ = (yC+yD+yB)/3.0;
1215 double zQ = (zC+zD+zB)/3.0;
1218 double xF = (xB+xC)/2.0;
1219 double yF = (yB+yC)/2.0;
1220 double zF = (zB+zC)/2.0;
1222 double xG = (xA+xC)/2.0;
1223 double yG = (yA+yC)/2.0;
1224 double zG = (zA+zC)/2.0;
1226 double xE = (xB+xA)/2.0;
1227 double yE = (yB+yA)/2.0;
1228 double zE = (zB+zA)/2.0;
1230 double xH = (xD+xC)/2.0;
1231 double yH = (yD+yC)/2.0;
1232 double zH = (zD+zC)/2.0;
1234 double xJ = (xD+xA)/2.0;
1235 double yJ = (yD+yA)/2.0;
1236 double zJ = (zD+zA)/2.0;
1238 double xK = (xD+xB)/2.0;
1239 double yK = (yD+yB)/2.0;
1240 double zK = (zD+zB)/2.0;
1258 lay_points(xM,yM,zM,xG,yG,zG,xA,yA,zA,xE,yE,zE,block_grid_x[0], block_grid_y[0], block_grid_z[0],block_grid_hull[0], n_cell_x);
1259 lay_points(xF,yF,zF,xM,yM,zM,xE,yE,zE,xB,yB,zB,block_grid_x[1], block_grid_y[1], block_grid_z[1],block_grid_hull[1], n_cell_x);
1260 lay_points(xC,yC,zC,xG,yG,zG,xM,yM,zM,xF,yF,zF,block_grid_x[2], block_grid_y[2], block_grid_z[2],block_grid_hull[2], n_cell_x);
1261 lay_points(xG,yG,zG,xN,yN,zN,xJ,yJ,zJ,xA,yA,zA,block_grid_x[3], block_grid_y[3], block_grid_z[3],block_grid_hull[3], n_cell_x);
1262 lay_points(xC,yC,zC,xH,yH,zH,xN,yN,zN,xG,yG,zG,block_grid_x[4], block_grid_y[4], block_grid_z[4],block_grid_hull[4], n_cell_x);
1263 lay_points(xH,yH,zH,xD,yD,zD,xJ,yJ,zJ,xN,yN,zN,block_grid_x[5], block_grid_y[5], block_grid_z[5],block_grid_hull[5], n_cell_x);
1264 lay_points(xA,yA,zA,xJ,yJ,zJ,xP,yP,zP,xE,yE,zE,block_grid_x[6], block_grid_y[6], block_grid_z[6],block_grid_hull[6], n_cell_x);
1265 lay_points(xJ,yJ,zJ,xD,yD,zD,xK,yK,zK,xP,yP,zP,block_grid_x[7], block_grid_y[7], block_grid_z[7],block_grid_hull[7], n_cell_x);
1266 lay_points(xP,yP,zP,xK,yK,zK,xB,yB,zB,xE,yE,zE,block_grid_x[8], block_grid_y[8], block_grid_z[8],block_grid_hull[8], n_cell_x);
1267 lay_points(xQ,yQ,zQ,xK,yK,zK,xD,yD,zD,xH,yH,zH,block_grid_x[9], block_grid_y[9], block_grid_z[9],block_grid_hull[9], n_cell_x);
1268 lay_points(xQ,yQ,zQ,xH,yH,zH,xC,yC,zC,xF,yF,zF,block_grid_x[10], block_grid_y[10], block_grid_z[10],block_grid_hull[10], n_cell_x);
1269 lay_points(xQ,yQ,zQ,xF,yF,zF,xB,yB,zB,xK,yK,zK,block_grid_x[11], block_grid_y[11], block_grid_z[11],block_grid_hull[11], n_cell_x);
1272 for (
size_t i_block = 0; i_block < n_block; ++i_block)
1274 for (
size_t i_point = 0; i_point < block_n_p; ++i_point)
1276 project_on_sphere(radius,block_grid_x[i_block][i_point],block_grid_y[i_block][i_point],block_grid_z[i_block][i_point]);
1283 std::vector<double> temp_x(n_block * block_n_p);
1284 std::vector<double> temp_y(n_block * block_n_p);
1285 std::vector<double> temp_z(n_block * block_n_p);
1286 std::vector<bool> sides(n_block * block_n_p);
1288 for (
size_t i = 0; i < n_block; ++i)
1291 for (
size_t j = i * block_n_p; j < i * block_n_p + block_n_p; ++j)
1293 WBAssert(j < temp_x.size(),
"j should be smaller then the size of the array temp_x.");
1294 WBAssert(j < temp_y.size(),
"j should be smaller then the size of the array temp_y.");
1295 WBAssert(j < temp_z.size(),
"j should be smaller then the size of the array temp_z.");
1296 temp_x[j] = block_grid_x[i][counter];
1297 temp_y[j] = block_grid_y[i][counter];
1298 temp_z[j] = block_grid_z[i][counter];
1299 sides[j] = block_grid_hull[i][counter];
1305 std::vector<bool> double_points(n_block * block_n_p,
false);
1306 std::vector<size_t> point_to(n_block * block_n_p);
1308 for (
size_t i = 0; i < n_block * block_n_p; ++i)
1312 const double distance = 1e-12*outer_radius;
1315 size_t amount_of_double_points = 0;
1316 for (
size_t i = 1; i < n_block * block_n_p; ++i)
1320 const double gxip = temp_x[i];
1321 const double gyip = temp_y[i];
1322 const double gzip = temp_z[i];
1323 for (
size_t j = 0; j < i-1; ++j)
1327 if (std::fabs(gxip-temp_x[j]) < distance &&
1328 std::fabs(gyip-temp_y[j]) < distance &&
1329 std::fabs(gzip-temp_z[j]) < distance)
1331 double_points[i] =
true;
1333 amount_of_double_points++;
1342 const size_t shell_n_p = n_block * block_n_p - amount_of_double_points;
1343 const size_t shell_n_cell = n_block * block_n_cell;
1344 const size_t shell_n_v = block_n_v;
1346 std::vector<double> shell_grid_x(shell_n_p);
1347 std::vector<double> shell_grid_y(shell_n_p);
1348 std::vector<double> shell_grid_z(shell_n_p);
1349 std::vector<std::vector<size_t> > shell_grid_connectivity(shell_n_cell,std::vector<size_t>(shell_n_v));
1352 for (
size_t i = 0; i < n_block * block_n_p; ++i)
1354 if (!double_points[i])
1356 shell_grid_x[counter] = fabs(temp_x[i]) < 1e-8 ? 0. : temp_x[i];
1357 shell_grid_y[counter] = fabs(temp_y[i]) < 1e-8 ? 0. : temp_y[i];
1358 shell_grid_z[counter] = fabs(temp_z[i]) < 1e-8 ? 0. : temp_z[i];
1364 for (
size_t i = 0; i < n_block; ++i)
1367 for (
size_t j = i * block_n_cell; j < i * block_n_cell + block_n_cell; ++j)
1369 for (
size_t k = 0; k < shell_n_v; ++k)
1371 shell_grid_connectivity[j][k] = block_grid_connectivity[i][counter][k] + i * block_n_p;
1377 for (
size_t i = 0; i < shell_n_cell; ++i)
1379 for (
size_t j = 0; j < shell_n_v; ++j)
1381 shell_grid_connectivity[i][j] = point_to[shell_grid_connectivity[i][j]];
1385 std::vector<size_t> compact(n_block * block_n_p);
1388 for (
size_t i = 0; i < n_block * block_n_p; ++i)
1390 if (!double_points[i])
1392 compact[i] = counter;
1398 for (
size_t i = 0; i < shell_n_cell; ++i)
1400 for (
size_t j = 0; j < shell_n_v; ++j)
1402 shell_grid_connectivity[i][j] = compact[shell_grid_connectivity[i][j]];
1411 std::vector<double> temp_shell_grid_x(shell_n_p);
1412 std::vector<double> temp_shell_grid_y(shell_n_p);
1413 std::vector<double> temp_shell_grid_z(shell_n_p);
1415 const size_t n_v = shell_n_v * 2;
1416 n_p = (n_cell_z + 1) * shell_n_p;
1417 n_cell = (n_cell_z) * shell_n_cell;
1422 grid_depth.resize(n_p);
1423 grid_connectivity.resize(n_cell,std::vector<size_t>(n_v));
1426 for (
size_t i = 0; i < n_cell_z + 1; ++i)
1428 temp_shell_grid_x = shell_grid_x;
1429 temp_shell_grid_y = shell_grid_y;
1430 temp_shell_grid_z = shell_grid_z;
1436 radius = inner_radius + ((outer_radius - inner_radius) / static_cast<double>(n_cell_z)) * static_cast<double>(i);
1437 for (
size_t j = 0; j < shell_n_p; ++j)
1439 WBAssert(j < temp_shell_grid_x.size(),
"ERROR: j = " << j <<
", temp_shell_grid_x.size() = " << temp_shell_grid_x.size());
1440 WBAssert(j < temp_shell_grid_y.size(),
"ERROR: j = " << j <<
", temp_shell_grid_y.size() = " << temp_shell_grid_y.size());
1441 WBAssert(j < temp_shell_grid_z.size(),
"ERROR: j = " << j <<
", temp_shell_grid_z.size() = " << temp_shell_grid_z.size());
1442 project_on_sphere(radius, temp_shell_grid_x[j], temp_shell_grid_y[j], temp_shell_grid_z[j]);
1445 const size_t i_beg = i * shell_n_p;
1446 const size_t i_end = (i+1) * shell_n_p;
1448 for (
size_t j = i_beg; j < i_end; ++j)
1450 WBAssert(j < grid_x.size(),
"ERROR: j = " << j <<
", grid_x.size() = " << grid_x.size());
1451 WBAssert(j < grid_y.size(),
"ERROR: j = " << j <<
", grid_y.size() = " << grid_y.size());
1452 WBAssert(j < grid_z.size(),
"ERROR: j = " << j <<
", grid_z.size() = " << grid_z.size());
1453 grid_x[j] = temp_shell_grid_x[counter];
1454 grid_y[j] = temp_shell_grid_y[counter];
1455 grid_z[j] = temp_shell_grid_z[counter];
1456 grid_depth[j] = outer_radius - std::sqrt(grid_x[j] * grid_x[j] + grid_y[j] * grid_y[j] + grid_z[j] * grid_z[j]);
1457 grid_depth[j] = (std::fabs(grid_depth[j]) < 1e-8 ? 0 : grid_depth[j]);
1463 for (
size_t i = 0; i < n_cell_z; ++i)
1465 const size_t i_beg = i * shell_n_cell;
1466 const size_t i_end = (i+1) * shell_n_cell;
1468 for (
size_t j = i_beg; j < i_end; ++j)
1470 for (
size_t k = 0; k < shell_n_v; ++k)
1472 grid_connectivity[j][k] = shell_grid_connectivity[counter][k] + i * shell_n_p;
1479 for (
size_t j = i_beg; j < i_end; ++j)
1481 for (
size_t k = shell_n_v ; k < 2 * shell_n_v; ++k)
1483 WBAssert(k-shell_n_v < shell_grid_connectivity[counter].size(),
"k - shell_n_v is larger then shell_grid_connectivity[counter]: k= " << k <<
", shell_grid_connectivity[counter].size() = " << shell_grid_connectivity[counter].size());
1484 grid_connectivity[j][k] = shell_grid_connectivity[counter][k-shell_n_v] + (i+1) * shell_n_p;
1492 WBAssertThrow(
false,
"Geometry type '" << grid_type <<
"' is not a valid geometry type. Valid geometry types are: " 1493 <<
"'cartesian', 'annulus', 'chunk' and 'sphere'. " 1494 <<
"Please note that the annulus can only be used in 2d and the sphere can only be used in 3d.");
1498 std::cout <<
"[5/6] Preparing to write the paraview file... \r";
1501 const std::string base_filename = wb_file.substr(wb_file.find_last_of(
"/\\") + 1);
1502 std::string::size_type
const p(base_filename.find_last_of(
'.'));
1503 const std::string file_without_extension = base_filename.substr(0, p);
1505 const std::stringstream buffer;
1506 const std::ofstream myfile;
1508 std::cout <<
"[5/6] Preparing to write the paraview file: stage 1 of 6, converting the points \r";
1510 std::vector<double> points(grid_x.size()*3, 0.0);
1512 for (
size_t i = 0; i < n_p; ++i)
1514 points[i*3] = grid_x[i];
1515 points[i*3+1] = grid_z[i];
1520 for (
size_t i = 0; i < n_p; ++i)
1522 points[i*3] = grid_x[i];
1523 points[i*3+1] = grid_y[i];
1524 points[i*3+2] = grid_z[i];
1527 std::cout <<
"[5/6] Preparing to write the paraview file: stage 2 of 6, converting the connectivity \r";
1529 const size_t pow_2_dim = dim == 2 ? 4 : 8;
1530 std::vector<vtu11::VtkIndexType> connectivity(n_cell*pow_2_dim);
1532 for (
size_t i = 0; i < n_cell; ++i)
1534 connectivity[i*pow_2_dim] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][0]);
1535 connectivity[i*pow_2_dim+1] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][1]);
1536 connectivity[i*pow_2_dim+2] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][2]);
1537 connectivity[i*pow_2_dim+3] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][3]);
1540 for (
size_t i = 0; i < n_cell; ++i)
1543 connectivity[i*pow_2_dim] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][0]);
1544 connectivity[i*pow_2_dim+1] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][1]);
1545 connectivity[i*pow_2_dim+2] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][2]);
1546 connectivity[i*pow_2_dim+3] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][3]);
1547 connectivity[i*pow_2_dim+4] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][4]);
1548 connectivity[i*pow_2_dim+5] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][5]);
1549 connectivity[i*pow_2_dim+6] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][6]);
1550 connectivity[i*pow_2_dim+7] =
static_cast<vtu11::VtkIndexType
>(grid_connectivity[i][7]);
1552 std::cout <<
"[5/6] Preparing to write the paraview file: stage 3 of 6, creating the offsets \r";
1554 std::vector<vtu11::VtkIndexType> offsets(n_cell);
1556 for (
size_t i = 0; i < n_cell; ++i)
1557 offsets[i] = static_cast<vtu11::VtkIndexType>((i+1) * 4);
1559 for (
size_t i = 0; i < n_cell; ++i)
1560 offsets[i] = static_cast<vtu11::VtkIndexType>((i+1) * 8);
1562 std::cout <<
"[5/6] Preparing to write the paraview file: stage 4 of 6, creating the Data set info \r";
1564 std::vector<vtu11::VtkCellType> types(n_cell, dim == 2 ? 9 : 12);
1567 std::vector<vtu11::DataSetInfo> dataSetInfo
1569 {
"Depth", vtu11::DataSetType::PointData, 1 },
1570 {
"Temperature", vtu11::DataSetType::PointData, 1 },
1571 {
"velocity", vtu11::DataSetType::PointData, 3 },
1572 {
"Tag", vtu11::DataSetType::PointData, 1 },
1574 for (
size_t c = 0; c < compositions; ++c)
1576 dataSetInfo.emplace_back(
"Composition "+std::to_string(c), vtu11::DataSetType::PointData, 1 );
1579 std::cout <<
"[5/6] Preparing to write the paraview file: stage 5 of 5, computing the properties \r";
1582 std::vector<std::array<unsigned ,3>> properties;
1583 properties.push_back({{1,0,0}});
1585 properties.push_back({{5,0,0}});
1587 properties.push_back({{4,0,0}});
1589 for (
unsigned int c = 0; c < compositions; ++c)
1590 properties.push_back({{2,c,0}});
1594 std::vector<vtu11::DataSetData> data_set(4+compositions);
1595 data_set[0] = grid_depth;
1596 data_set[1].resize(n_p);
1597 data_set[2].resize(n_p*3);
1598 data_set[3].resize(n_p);
1599 for (
size_t c = 0; c < compositions; ++c)
1600 data_set[4+c].resize(n_p);
1604 pool.parallel_for(0, n_p, [&] (
size_t i)
1606 const std::array<double,2> coords = {{grid_x[i], grid_z[i]}};
1607 std::vector<double> output = world->properties(coords, grid_depth[i],properties);
1608 data_set[1][i] = output[0];
1609 data_set[2][3*i] = output[1];
1610 data_set[2][3*i+1] = output[2];
1611 data_set[2][3*i+2] = output[3];
1612 data_set[3][i] = output[4];
1613 for (
size_t c = 0; c < compositions; ++c)
1615 data_set[4+c][i] = output[5+c];
1621 pool.parallel_for(0, n_p, [&] (
size_t i)
1623 const std::array<double,3> coords = {{grid_x[i], grid_y[i], grid_z[i]}};
1624 std::vector<double> output = world->properties(coords, grid_depth[i],properties);
1625 data_set[1][i] = output[0];
1626 data_set[2][3*i] = output[1];
1627 data_set[2][3*i+1] = output[2];
1628 data_set[2][3*i+2] = output[3];
1629 data_set[3][i] = output[4];
1630 for (
size_t c = 0; c < compositions; ++c)
1632 data_set[4+c][i] = output[5+c];
1636 std::cout <<
"[6/6] Writing the paraview file \r";
1640 vtu11::Vtu11UnstructuredMesh mesh { points, connectivity, offsets, types };
1641 vtu11::writeVtu( file_without_extension +
".vtu", mesh, dataSetInfo, data_set, vtu_output_format );
1643 if (output_filtered)
1645 std::vector<bool> include_tag(world->feature_tags.size(),
true);
1646 for (
unsigned int idx = 0; idx<include_tag.size(); ++idx)
1648 if (world->feature_tags[idx]==
"mantle layer")
1649 include_tag[idx] =
false;
1651 std::vector<double> filtered_points;
1652 std::vector<vtu11::VtkIndexType> filtered_connectivity;
1653 std::vector<vtu11::VtkIndexType> filtered_offsets;
1654 std::vector<vtu11::VtkCellType> filtered_types;
1656 vtu11::Vtu11UnstructuredMesh filtered_mesh {filtered_points, filtered_connectivity, filtered_offsets, filtered_types};
1657 std::vector<vtu11::DataSetData> filtered_data_set;
1659 filter_vtu_mesh(static_cast<int>(dim), include_tag, mesh, data_set, filtered_mesh, filtered_data_set);
1660 vtu11::writeVtu( file_without_extension +
".filtered.vtu", filtered_mesh, dataSetInfo, filtered_data_set, vtu_output_format );
1665 for (
unsigned int idx = 0; idx<world->feature_tags.size(); ++idx)
1667 if (world->feature_tags[idx]==
"mantle layer")
1670 std::vector<double> filtered_points;
1671 std::vector<vtu11::VtkIndexType> filtered_connectivity;
1672 std::vector<vtu11::VtkIndexType> filtered_offsets;
1673 std::vector<vtu11::VtkCellType> filtered_types;
1675 vtu11::Vtu11UnstructuredMesh filtered_mesh {filtered_points, filtered_connectivity, filtered_offsets, filtered_types};
1676 std::vector<vtu11::DataSetData> filtered_data_set;
1678 std::vector<bool> include_tag(world->feature_tags.size(),
false);
1679 include_tag[idx]=
true;
1680 filter_vtu_mesh(static_cast<int>(dim), include_tag, mesh, data_set, filtered_mesh, filtered_data_set);
1681 const std::string filename = file_without_extension +
"."+ std::to_string(idx)+
".vtu";
1682 vtu11::writeVtu( filename, filtered_mesh, dataSetInfo, filtered_data_set, vtu_output_format );
void project_on_sphere(double radius, double &x_, double &y_, double &z_)
ThreadPool(size_t number_of_threads)
void lay_points(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, std::vector< double > &x, std::vector< double > &y, std::vector< double > &z, std::vector< bool > &hull, size_t level)
void parallel_for(size_t start, size_t end, Callable func)
bool find_command_line_option(char **begin, char **end, const std::string &option)
#define WBAssert(condition, message)
int main(int argc, char **argv)
double cos(const double angle)
#define WBAssertThrow(condition, message)
double string_to_double(const std::string &string)
unsigned int string_to_unsigned_int(const std::string &string)
std::vector< std::thread > pool
double sin(const double raw_angle)
void filter_vtu_mesh(int dim, const std::vector< bool > &include_tag, vtu11::Vtu11UnstructuredMesh &input_mesh, const std::vector< vtu11::DataSetData > &input_data, vtu11::Vtu11UnstructuredMesh &output_mesh, std::vector< vtu11::DataSetData > &output_data)
std::vector< std::string > get_command_line_options_vector(int argc, char **argv)