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

190{
191 if (mesh == nullptr)
192 {
193 ERR("Input mesh not found...");
194 return false;
195 }
196 if (!isVoxelGrid(*mesh))
197 {
198 ERR("The input mesh is not a voxel grid. The input mesh must be "
199 "a voxel grid (i.e. an equally sized axis "
200 "aligned hexahedra mesh).");
201 return false;
202 }
203
204 if (fault == nullptr)
205 {
206 ERR("Fault mesh not found...");
207 return false;
208 }
209 if (fault->getDimension() != 2)
210 {
211 ERR("Fault needs to be a 2D mesh.");
212 return false;
213 }
214
215 Eigen::Vector3d half_cell_size;
216 {
217 auto const n = *mesh->getElement(0)->getNode(0);
218 auto const c = MeshLib::getCenterOfGravity(*mesh->getElement(0));
219 half_cell_size[0] = std::abs(c[0] - n[0]);
220 half_cell_size[1] = std::abs(c[1] - n[1]);
221 half_cell_size[2] = std::abs(c[2] - n[2]);
222 }
223
224 markFaults(*mesh, *fault, fault_id, half_cell_size);
225
226 return true;
227}
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 156 of file AddFaultToVoxelGrid.cpp.

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

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

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