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 190 of file AddFaultToVoxelGrid.cpp.

193{
194 if (mesh == nullptr)
195 {
196 ERR("Input mesh not found...");
197 return false;
198 }
199 if (!isVoxelGrid(*mesh))
200 {
201 ERR("The input mesh is not a voxel grid. The input mesh must be "
202 "a voxel grid (i.e. an equally sized axis "
203 "aligned hexahedra mesh).");
204 return false;
205 }
206
207 if (fault == nullptr)
208 {
209 ERR("Fault mesh not found...");
210 return false;
211 }
212 if (fault->getDimension() != 2)
213 {
214 ERR("Fault needs to be a 2D mesh.");
215 return false;
216 }
217
218 Eigen::Vector3d half_cell_size;
219 {
220 auto const n = *mesh->getElement(0)->getNode(0);
221 auto const c = MeshLib::getCenterOfGravity(*mesh->getElement(0));
222 half_cell_size[0] = std::abs(c[0] - n[0]);
223 half_cell_size[1] = std::abs(c[1] - n[1]);
224 half_cell_size[2] = std::abs(c[2] - n[2]);
225 }
226
227 markFaults(*mesh, *fault, fault_id, half_cell_size);
228
229 return true;
230}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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:94
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:124
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().

◆ isVoxelGrid()

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

Definition at line 159 of file AddFaultToVoxelGrid.cpp.

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

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

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