16 #include <tclap/CmdLine.h>
32 Eigen::Vector3d
const& aabb_extent,
33 Eigen::Vector3d
const& plane_normal,
36 double const r = aabb_extent.dot(plane_normal.cwiseAbs());
37 double const s = plane_normal.dot(aabb_centre) - pd;
38 return std::abs(s) >
r;
46 Eigen::Vector3d
const&
c,
47 Eigen::Vector3d
const& e)
56 if (((v.rowwise().minCoeff() - e).array() > 0).any() ||
57 ((v.rowwise().maxCoeff() + e).array() < 0).any())
63 std::array<Eigen::Vector3d, 3> tri_edge{
64 {v.col(1) - v.col(0), v.col(2) - v.col(1), v.col(0) - v.col(2)}};
65 std::array<Eigen::Vector3d, 9>
const axx{
66 {Eigen::Vector3d({0, -tri_edge[0].z(), tri_edge[0].y()}),
67 Eigen::Vector3d({0, -tri_edge[1].z(), tri_edge[1].y()}),
68 Eigen::Vector3d({0, -tri_edge[2].z(), tri_edge[2].y()}),
69 Eigen::Vector3d({tri_edge[0].z(), 0, -tri_edge[0].x()}),
70 Eigen::Vector3d({tri_edge[1].z(), 0, -tri_edge[1].x()}),
71 Eigen::Vector3d({tri_edge[2].z(), 0, -tri_edge[2].x()}),
72 Eigen::Vector3d({-tri_edge[0].y(), tri_edge[0].x(), 0}),
73 Eigen::Vector3d({-tri_edge[1].y(), tri_edge[1].x(), 0}),
74 Eigen::Vector3d({-tri_edge[2].y(), tri_edge[2].x(), 0})}};
79 for (
auto const& a : axx)
81 Eigen::Vector3d
p = v.transpose() * a;
82 double const r = e.dot(a.cwiseAbs());
83 if (std::max(-
p.maxCoeff(),
p.minCoeff()) >
r)
90 Eigen::Vector3d
const plane_normal(tri_edge[0].cross(tri_edge[1]));
91 double const pd = plane_normal.dot(v.row(0));
96 int const fault_id, std::array<double, 3> half_cell_size)
101 auto const& fnodes = fault.
getNodes();
103 GeoLib::AABB const fault_aabb(fnodes.cbegin(), fnodes.cend());
108 for (std::size_t i = 0; i < 3; ++i)
110 min_pnt[i] -= half_cell_size[i];
111 max_pnt[i] += half_cell_size[i];
113 std::array<Eigen::Vector3d, 2>
const fault_extent{{min_pnt, max_pnt}};
114 GeoLib::AABB const fault_aabb_ext(fault_extent.cbegin(),
115 fault_extent.cend());
118 Eigen::Vector3d
const extent(
119 {half_cell_size[0], half_cell_size[1], half_cell_size[2]});
120 for (std::size_t j = 0; j < n_elems; ++j)
130 Eigen::Vector3d
const c(centre_pnt.getCoords());
131 for (
auto const*
const fault_elem : felems)
133 if (fault_elem->getDimension() != 2)
139 *fault_elem->getNode(0), *fault_elem->getNode(1),
140 *fault_elem->getNode(2),
c, extent))
142 (*mat_ids)[j] = fault_id;
149 *fault_elem->getNode(0), *fault_elem->getNode(2),
150 *fault_elem->getNode(3),
c, extent))
152 (*mat_ids)[j] = fault_id;
164 if (std::any_of(elements.cbegin(), elements.cend(),
166 return (e->getGeomType() !=
167 MeshLib::MeshElemType::HEXAHEDRON);
170 ERR(
"Input mesh needs to be voxel grid (i.e. equally sized axis "
171 "aligned hexahedra).");
175 for (
auto const& e : elements)
177 auto const n = e->getNodes();
178 if ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
179 (*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
180 (*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
181 (*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0])
183 ERR(
"Input mesh needs to be voxel grid (i.e. equally sized axis "
184 "aligned hexahedra).");
191 int main(
int argc,
char* argv[])
193 constexpr
int mat_not_set = std::numeric_limits<int>::max();
196 "Marks all elements in a voxel grid (i.e. a structured hex grid, for "
197 "instance created with Layers2Grid or Vtu2Grid) that are intersected "
198 "by a triangulated 2D mesh representing a fault or some other "
199 "significant structure. The material group for those intersected "
200 "elements can be explicitly specified, otherwise the largest existing "
201 "MaterialID will be increased by one.\n\n"
202 "OpenGeoSys-6 software, version " +
205 "Copyright (c) 2012-2021, OpenGeoSys Community "
206 "(http://www.opengeosys.org)",
208 TCLAP::ValueArg<int> id_arg(
"m",
"material",
209 "material id for cells intersected by fault",
210 false, mat_not_set,
"non-negative integer");
213 TCLAP::ValueArg<std::string> output_arg(
214 "o",
"output",
"name of output mesh (*.vtu)",
true,
"",
"string");
217 TCLAP::ValueArg<std::string> fault_arg(
218 "f",
"fault",
"name of mesh representing fault (*.vtu)",
true,
"",
222 TCLAP::ValueArg<std::string> input_arg(
224 "name of the input file list containing the paths the all input layers "
225 "in correct order from top to bottom",
228 cmd.parse(argc, argv);
230 std::string
const input_name = input_arg.getValue();
231 std::string
const fault_name = fault_arg.getValue();
232 std::string
const output_name = output_arg.getValue();
234 std::unique_ptr<MeshLib::Mesh> mesh(
238 ERR(
"Input mesh not found...");
248 ERR(
"Input mesh has no material IDs");
252 std::unique_ptr<MeshLib::Mesh> fault(
256 ERR(
"Fault mesh not found...");
259 if (fault->getDimension() != 2)
261 ERR(
"Fault needs to be a 2D mesh.");
265 int fault_id = id_arg.getValue();
268 auto it = std::max_element(mat_ids->cbegin(), mat_ids->cend());
272 std::array<double, 3> half_cell_size;
274 auto const n = *mesh->getElement(0)->getNode(0);
276 half_cell_size[0] = std::abs(
c[0] - n[0]);
277 half_cell_size[1] = std::abs(
c[1] - n[1]);
278 half_cell_size[2] = std::abs(
c[2] - n[2]);
281 markFaults(*mesh, *fault, fault_id, half_cell_size);
Definition of the AABB class.
int main(int argc, char *argv[])
static std::string mat_name
bool isVoxelGrid(MeshLib::Mesh const &mesh)
bool testAABBIntersectingPlane(Eigen::Vector3d const &aabb_centre, Eigen::Vector3d const &aabb_extent, Eigen::Vector3d const &plane_normal, double const pd)
bool testTriangleIntersectingAABB(MeshLib::Node const &n0, MeshLib::Node const &n1, MeshLib::Node const &n2, Eigen::Vector3d const &c, Eigen::Vector3d const &e)
void markFaults(MeshLib::Mesh &mesh, MeshLib::Mesh const &fault, int const fault_id, std::array< double, 3 > half_cell_size)
Definition of the Element class.
void ERR(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
Definition of the Point3d class.
Implementation of the VtuInterface class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMinPoint() const
bool containsPoint(T const &pnt, double eps) const
Eigen::Vector3d const & getMaxPoint() const
const T * getCoords() const
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
std::size_t getNumberOfElements() const
Get the number of elements.
PropertyVector< T > const * getPropertyVector(std::string const &name) const
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
MeshLib::Node getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition of readMeshFromFile function.