OGS
MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid Namespace Reference

Functions

bool isVoxelGrid (MeshLib::Mesh const &mesh)
bool addFaultToVoxelGrid (MeshLib::Mesh *mesh, MeshLib::Mesh const *fault, int const fault_id)

Function Documentation

◆ addFaultToVoxelGrid()

bool MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid::addFaultToVoxelGrid ( MeshLib::Mesh * mesh,
MeshLib::Mesh const * fault,
int const fault_id )

Definition at line 181 of file MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp.

184{
185 if (mesh == nullptr)
186 {
187 ERR("Input mesh not found...");
188 return false;
189 }
190 if (!isVoxelGrid(*mesh))
191 {
192 ERR("The input mesh is not a voxel grid. The input mesh must be "
193 "a voxel grid (i.e. an equally sized axis "
194 "aligned hexahedra mesh).");
195 return false;
196 }
197
198 if (fault == nullptr)
199 {
200 ERR("Fault mesh not found...");
201 return false;
202 }
203 if (fault->getDimension() != 2)
204 {
205 ERR("Fault needs to be a 2D mesh.");
206 return false;
207 }
208
209 Eigen::Vector3d half_cell_size;
210 {
211 auto const n = *mesh->getElement(0)->getNode(0);
212 auto const c = MeshLib::getCenterOfGravity(*mesh->getElement(0));
213 half_cell_size[0] = std::abs(c[0] - n[0]);
214 half_cell_size[1] = std::abs(c[1] - n[1]);
215 half_cell_size[2] = std::abs(c[2] - n[2]);
216 }
217
218 markFaults(*mesh, *fault, fault_id, half_cell_size);
219
220 return true;
221}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
virtual const Node * getNode(unsigned idx) const =0
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:85
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:131
void markFaults(MeshLib::Mesh &mesh, MeshLib::Mesh const &fault, int const fault_id, Eigen::Vector3d const &half_cell_size)

References ERR(), MeshLib::getCenterOfGravity(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElement(), MeshLib::Element::getNode(), and isVoxelGrid().

Referenced by AddFaultsToVoxelGridDialog::accept(), and main().

◆ isVoxelGrid()

bool MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid::isVoxelGrid ( MeshLib::Mesh const & mesh)

Definition at line 150 of file MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp.

151{
152 auto const& elements = mesh.getElements();
153 if (std::any_of(elements.cbegin(), elements.cend(),
154 [&](auto const& e) {
155 return (e->getGeomType() !=
156 MeshLib::MeshElemType::HEXAHEDRON);
157 }))
158 {
159 return false;
160 }
161 auto is_voxel = [](auto const& e)
162 {
163 auto const n = e->getNodes();
164 return ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
165 (*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
166 (*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
167 (*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0]);
168 };
169
170 if (std::any_of(elements.cbegin(), elements.cend(), is_voxel))
171 {
172 ERR("Input mesh needs to be voxel grid (i.e. equally sized axis "
173 "aligned hexahedra).");
174 return false;
175 }
176 return true;
177}

References ERR(), and MeshLib::Mesh::getElements().

Referenced by AddFaultsToVoxelGridDialog::AddFaultsToVoxelGridDialog(), and addFaultToVoxelGrid().