14#include <vtkPointData.h>
31 void append(Eigen::Vector3d
const& natural_coords,
32 Eigen::Vector3d
const& real_coords,
33 vtkIdType bulk_element_id,
34 vtkIdType point_cloud_node_id)
45 Eigen::VectorXd
const& initial_anchor_stress,
46 Eigen::VectorXd
const& maximum_anchor_stress,
47 Eigen::VectorXd
const& residual_anchor_stress,
48 Eigen::VectorXd
const& anchor_cross_sectional_area,
49 Eigen::VectorXd
const& anchor_stiffness)
51 auto bei = Eigen::Map<Eigen::VectorX<vtkIdType>>(
53 auto pcni = Eigen::Map<Eigen::VectorX<vtkIdType>>(
57 initial_anchor_stress,
58 maximum_anchor_stress,
59 residual_anchor_stress,
60 anchor_cross_sectional_area,
68 static Eigen::MatrixXd
conv(std::vector<Eigen::Vector3d>
const& in)
70 Eigen::MatrixXd out(in.size(), 3);
71 for (std::size_t i = 0; i < in.size(); ++i)
73 out.row(i).noalias() = in[i].transpose();
86 vtkUnstructuredGrid*
const bulk_mesh,
94 OGS_FATAL(
"Wrong number of input coordinates");
98 using SolverRegistry =
102 double const real_coords_tolerance = tolerance;
111 for (Eigen::Index rc_idx = 0; rc_idx < json_data.
real_coords.rows();
114 Eigen::RowVector3d
const real_coords_single_point =
118 auto const filtered_bulk_mesh =
119 findCellsForPoints.
find(real_coords_single_point, tolerance);
122 int const actual_multiplicity = filtered_bulk_mesh->GetNumberOfCells();
123 if (actual_multiplicity == 0)
126 "Did not find any cell for the point {} (coordinates: {})",
127 rc_idx, real_coords_single_point);
129 assert(actual_multiplicity > 0);
130 if (actual_multiplicity != 1)
133 "Found more then one cell (namely {}) for point #{} "
135 actual_multiplicity, rc_idx, real_coords_single_point);
139 std::unique_ptr<MeshLib::Mesh> ogs_mesh(
141 filtered_bulk_mesh,
"filtered_bulk_mesh"));
145 auto const& elements = ogs_mesh->getElements();
150 constexpr std::size_t elt_idx = 0;
151 auto const& element = *elements[elt_idx];
152 auto const bulk_element_id = bulk_element_ids->getComponent(elt_idx, 0);
154 auto const& solver = SolverRegistry::getFor(element);
155 auto const opt_natural_coords = solver.solve(
156 element, real_coords_single_point, max_iter, real_coords_tolerance);
158 result.
append(opt_natural_coords, real_coords_single_point,
159 bulk_element_id, rc_idx);
170 Eigen::MatrixX<T>
const& data)
172 INFO(
"converting {}", name);
173 vtkNew<vtkAOSDataArrayTemplate<T>> array;
174 array->SetName(name.c_str());
175 array->SetNumberOfComponents(data.cols());
176 array->SetNumberOfTuples(grid->GetNumberOfPoints());
178 if (grid->GetNumberOfPoints() != data.rows())
181 "Got {} rows in the table but expected {} rows, same as number of "
182 "points in the grid.",
183 data.rows(), grid->GetNumberOfPoints());
185 for (Eigen::Index i = 0; i < data.rows(); ++i)
188 Eigen::RowVectorX<T>
const row = data.row(i);
190 array->SetTypedTuple(i, row.data());
194 grid->GetPointData()->AddArray(array);
198void addCellData(vtkUnstructuredGrid* grid, std::string
const& name,
199 Eigen::MatrixX<T>
const& data)
201 INFO(
"converting {}", name);
202 vtkNew<vtkAOSDataArrayTemplate<T>> array;
203 array->SetName(name.c_str());
204 array->SetNumberOfComponents(data.cols());
205 array->SetNumberOfTuples(grid->GetNumberOfCells());
207 if (grid->GetNumberOfCells() != data.rows())
210 "Got {} rows in the table but expected {} rows, same as number of "
211 "cells in the grid.",
212 data.rows(), grid->GetNumberOfCells());
214 for (Eigen::Index i = 0; i < data.rows(); ++i)
217 Eigen::RowVectorX<T>
const row = data.row(i);
219 array->SetTypedTuple(i, row.data());
223 grid->GetCellData()->AddArray(array);
235 INFO(
"converting points");
240 "No point was found in the mesh. Please check whether all anchors "
241 "are within the model region.");
246 "Only one point was found in the mesh. Please check whether all "
247 "anchors are within the model region.");
249 else if (n_pts % 2 != 0)
253 "Number of points is not even. Anchors are believed to consist of "
254 "a start and an end point.");
257 vtkNew<vtkUnstructuredGrid> grid;
260 vtkNew<vtkPoints> points;
261 points->SetDataTypeToDouble();
262 points->SetNumberOfPoints(n_pts);
265 for (Eigen::Index i = 0; i < css.rows(); ++i)
267 points->SetPoint(i, css(i, 0), css(i, 1), css(i, 2));
271 vtkNew<vtkLine> line;
272 line->GetPointIds()->SetId(0, i - 1);
273 line->GetPointIds()->SetId(1, i);
274 grid->InsertNextCell(line->GetCellType(), line->GetPointIds());
278 grid->SetPoints(points);
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the VtkMeshConverter class.
vtkSmartPointer< vtkUnstructuredGrid > find(Eigen::Vector3d const &coords, double const tolerance)
void initialize(vtkUnstructuredGrid *const bulk_mesh)
static MeshLib::Mesh * convertUnstructuredGrid(vtkUnstructuredGrid *grid, bool const compute_element_neighbors=false, std::string const &mesh_name="vtkUnstructuredGrid")
Converts a vtkUnstructuredGrid object to a Mesh.
void addPointData(vtkUnstructuredGrid *grid, std::string const &name, Eigen::MatrixX< T > const &data)
void addCellData(vtkUnstructuredGrid *grid, std::string const &name, Eigen::MatrixX< T > const &data)
vtkSmartPointer< vtkUnstructuredGrid > toVTKGrid(ComputeNaturalCoordsResult const &result)
ComputeNaturalCoordsResult computeNaturalCoords(vtkUnstructuredGrid *const bulk_mesh, ComputeNaturalCoordsResult const &json_data, double const tolerance, int const max_iter)
PropertyVector< std::size_t > const * bulkElementIDs(Mesh const &mesh)
Eigen::VectorXd anchor_cross_sectional_area
Eigen::VectorXd maximum_anchor_stress
Eigen::VectorXd anchor_stiffness
Eigen::VectorX< vtkIdType > bulk_element_ids
Eigen::MatrixXd real_coords
Eigen::VectorXd residual_anchor_stress
Eigen::VectorXd initial_anchor_stress
Eigen::MatrixXd natural_coords
Eigen::VectorX< vtkIdType > point_cloud_node_ids