8#include <vtkPointData.h>
25 void append(Eigen::Vector3d
const& natural_coords,
26 Eigen::Vector3d
const& real_coords,
27 vtkIdType bulk_element_id,
28 vtkIdType point_cloud_node_id)
39 Eigen::VectorXd
const& initial_anchor_stress,
40 Eigen::VectorXd
const& maximum_anchor_stress,
41 Eigen::VectorXd
const& residual_anchor_stress,
42 Eigen::VectorXd
const& anchor_cross_sectional_area,
43 Eigen::VectorXd
const& anchor_stiffness)
45 auto bei = Eigen::Map<Eigen::VectorX<vtkIdType>>(
47 auto pcni = Eigen::Map<Eigen::VectorX<vtkIdType>>(
51 initial_anchor_stress,
52 maximum_anchor_stress,
53 residual_anchor_stress,
54 anchor_cross_sectional_area,
62 static Eigen::MatrixXd
conv(std::vector<Eigen::Vector3d>
const& in)
64 Eigen::MatrixXd out(in.size(), 3);
65 for (std::size_t i = 0; i < in.size(); ++i)
67 out.row(i).noalias() = in[i].transpose();
80 vtkUnstructuredGrid*
const bulk_mesh,
88 OGS_FATAL(
"Wrong number of input coordinates");
92 using SolverRegistry =
96 double const real_coords_tolerance = tolerance;
105 for (Eigen::Index rc_idx = 0; rc_idx < json_data.
real_coords.rows();
108 Eigen::RowVector3d
const real_coords_single_point =
112 auto const filtered_bulk_mesh =
113 findCellsForPoints.
find(real_coords_single_point, tolerance);
116 int const actual_multiplicity = filtered_bulk_mesh->GetNumberOfCells();
117 if (actual_multiplicity == 0)
120 "Did not find any cell for the point {} (coordinates: {})",
121 rc_idx, real_coords_single_point);
123 assert(actual_multiplicity > 0);
124 if (actual_multiplicity != 1)
127 "Found more then one cell (namely {}) for point #{} "
129 actual_multiplicity, rc_idx, real_coords_single_point);
133 std::unique_ptr<MeshLib::Mesh> ogs_mesh(
135 filtered_bulk_mesh,
"filtered_bulk_mesh"));
139 auto const& elements = ogs_mesh->getElements();
144 constexpr std::size_t elt_idx = 0;
145 auto const& element = *elements[elt_idx];
146 auto const bulk_element_id = bulk_element_ids->getComponent(elt_idx, 0);
148 auto const& solver = SolverRegistry::getFor(element);
149 auto const opt_natural_coords = solver.solve(
150 element, real_coords_single_point, max_iter, real_coords_tolerance);
152 result.
append(opt_natural_coords, real_coords_single_point,
153 bulk_element_id, rc_idx);
164 Eigen::MatrixX<T>
const& data)
166 INFO(
"converting {}", name);
167 vtkNew<vtkAOSDataArrayTemplate<T>> array;
168 array->SetName(name.c_str());
169 array->SetNumberOfComponents(data.cols());
170 array->SetNumberOfTuples(grid->GetNumberOfPoints());
172 if (grid->GetNumberOfPoints() != data.rows())
175 "Got {} rows in the table but expected {} rows, same as number of "
176 "points in the grid.",
177 data.rows(), grid->GetNumberOfPoints());
179 for (Eigen::Index i = 0; i < data.rows(); ++i)
182 Eigen::RowVectorX<T>
const row = data.row(i);
184 array->SetTypedTuple(i, row.data());
188 grid->GetPointData()->AddArray(array);
192void addCellData(vtkUnstructuredGrid* grid, std::string
const& name,
193 Eigen::MatrixX<T>
const& data)
195 INFO(
"converting {}", name);
196 vtkNew<vtkAOSDataArrayTemplate<T>> array;
197 array->SetName(name.c_str());
198 array->SetNumberOfComponents(data.cols());
199 array->SetNumberOfTuples(grid->GetNumberOfCells());
201 if (grid->GetNumberOfCells() != data.rows())
204 "Got {} rows in the table but expected {} rows, same as number of "
205 "cells in the grid.",
206 data.rows(), grid->GetNumberOfCells());
208 for (Eigen::Index i = 0; i < data.rows(); ++i)
211 Eigen::RowVectorX<T>
const row = data.row(i);
213 array->SetTypedTuple(i, row.data());
217 grid->GetCellData()->AddArray(array);
229 INFO(
"converting points");
234 "No point was found in the mesh. Please check whether all anchors "
235 "are within the model region.");
240 "Only one point was found in the mesh. Please check whether all "
241 "anchors are within the model region.");
243 else if (n_pts % 2 != 0)
247 "Number of points is not even. Anchors are believed to consist of "
248 "a start and an end point.");
251 vtkNew<vtkUnstructuredGrid> grid;
254 vtkNew<vtkPoints> points;
255 points->SetDataTypeToDouble();
256 points->SetNumberOfPoints(n_pts);
259 for (Eigen::Index i = 0; i < css.rows(); ++i)
261 points->SetPoint(i, css(i, 0), css(i, 1), css(i, 2));
265 vtkNew<vtkLine> line;
266 line->GetPointIds()->SetId(0, i - 1);
267 line->GetPointIds()->SetId(1, i);
268 grid->InsertNextCell(line->GetCellType(), line->GetPointIds());
272 grid->SetPoints(points);
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
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