79 vtkUnstructuredGrid*
const bulk_mesh, Eigen::MatrixXd
const& real_coords,
80 double const tolerance,
int const max_iter)
84 if (real_coords.cols() != 3)
86 OGS_FATAL(
"Wrong number of input coordinates");
90 using SolverRegistry =
94 double const real_coords_tolerance = tolerance;
103 for (Eigen::Index rc_idx = 0; rc_idx < real_coords.rows(); ++rc_idx)
105 Eigen::RowVector3d
const real_coords_single_point =
106 real_coords.row(rc_idx);
109 auto const filtered_bulk_mesh =
110 findCellsForPoints.
find(real_coords_single_point, tolerance);
113 int const actual_multiplicity = filtered_bulk_mesh->GetNumberOfCells();
114 if (actual_multiplicity == 0)
117 "Did not find any cell for the point {} (coordinates: {})",
118 rc_idx, real_coords_single_point);
120 assert(actual_multiplicity > 0);
121 if (actual_multiplicity != 1)
124 "Found more then one cell (namely {}) for point #{} "
126 actual_multiplicity, rc_idx, real_coords_single_point);
130 std::unique_ptr<MeshLib::Mesh> ogs_mesh(
132 filtered_bulk_mesh,
"filtered_bulk_mesh"));
136 auto const& elements = ogs_mesh->getElements();
141 constexpr std::size_t elt_idx = 0;
142 auto const& element = *elements[elt_idx];
143 auto const bulk_element_id = bulk_element_ids->getComponent(elt_idx, 0);
145 auto const& solver = SolverRegistry::getFor(element);
146 auto const opt_natural_coords = solver.solve(
147 element, real_coords_single_point, max_iter, real_coords_tolerance);
149 result.
append(opt_natural_coords, real_coords_single_point,
150 bulk_element_id, rc_idx);
158 Eigen::MatrixX<T>
const& data)
160 INFO(
"converting {}", name);
161 vtkNew<vtkAOSDataArrayTemplate<T>> array;
162 array->SetName(name.c_str());
163 array->SetNumberOfComponents(data.cols());
164 array->SetNumberOfTuples(grid->GetNumberOfPoints());
166 if (grid->GetNumberOfPoints() != data.rows())
169 "Got {} rows in the table but expected {} rows, same as number of "
170 "points in the grid.",
171 data.rows(), grid->GetNumberOfPoints());
173 for (Eigen::Index i = 0; i < data.rows(); ++i)
176 Eigen::RowVectorX<T>
const row = data.row(i);
178 array->SetTypedTuple(i, row.data());
182 grid->GetPointData()->AddArray(array);
194 INFO(
"converting points");
199 "No point was found in the mesh. Please check whether all anchors "
200 "are within the model region.");
205 "Only one point was found in the mesh. Please check whether all "
206 "anchors are within the model region.");
208 else if (n_pts % 2 != 0)
212 "Number of points is not even. Anchors are believed to consist of "
213 "a start and an end point.");
216 vtkNew<vtkUnstructuredGrid> grid;
219 vtkNew<vtkPoints> points;
220 points->SetNumberOfPoints(n_pts);
223 for (Eigen::Index i = 0; i < css.rows(); ++i)
225 points->SetPoint(i, css(i, 0), css(i, 1), css(i, 2));
229 vtkNew<vtkLine> line;
230 line->GetPointIds()->SetId(0, i - 1);
231 line->GetPointIds()->SetId(1, i);
232 grid->InsertNextCell(line->GetCellType(), line->GetPointIds());
236 grid->SetPoints(points);