Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to use axis-aligned geometry for hex/quad/lines in hype… #747

Merged
merged 34 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f09ca12
Add an option to use axis-aligned geometry for hex/quad/lines in hype…
Davknapp Sep 13, 2023
636abd2
Adapt construction of tree-vertices
Davknapp Sep 14, 2023
4d15fe0
Make use_axis_aligned const
Davknapp Sep 14, 2023
b5af4a8
Update variable name
Davknapp Sep 14, 2023
07b6474
Add documentation
Davknapp Sep 14, 2023
bce7486
Merge remote-tracking branch 'origin/main' into enhance_hypercube_pad
Davknapp Sep 14, 2023
e753f3a
Merge branch 'main' into enhance_hypercube_pad
sandro-elsweijer Sep 15, 2023
72ef89a
restructre hypercube_pad for axis_aligned geometries
Davknapp Sep 15, 2023
335880c
add documentation
Davknapp Sep 15, 2023
1411fcc
Add another check
Davknapp Sep 15, 2023
af2497b
Correct index
Davknapp Sep 15, 2023
1b94268
Use the geometry as an argument to pass to hypercube_pad
Davknapp Oct 6, 2023
f2fd9d6
Merge remote-tracking branch 'origin/main' into enhance_hypercube_pad
Davknapp Oct 6, 2023
41651c9
Indentation
Davknapp Oct 6, 2023
954d101
Remove debug-flags from is_axis_aligned_check
Davknapp Oct 6, 2023
48bb7d9
Clean-up
Davknapp Oct 6, 2023
cbf9d32
Merge branch 'main' into enhance_hypercube_pad
Davknapp Nov 22, 2023
23a300a
Merge branch 'main' into enhance_hypercube_pad
Davknapp Nov 23, 2023
cbdc704
Merge branch 'main' into enhance_hypercube_pad
sandro-elsweijer Nov 27, 2023
e5694d2
Remove DEBUG-Makros
Davknapp Nov 28, 2023
ccf1f3d
Simplify check
Davknapp Nov 28, 2023
2311415
Remove Debug-Makros
Davknapp Nov 28, 2023
30a2b50
Simplify check
Davknapp Nov 28, 2023
7d25f63
Update src/t8_geometry/t8_geometry_implementations/t8_geometry_linear…
Davknapp Nov 28, 2023
5d403fb
Update src/t8_geometry/t8_geometry_implementations/t8_geometry_linear…
Davknapp Nov 28, 2023
76433f9
Update geometry_check
Davknapp Nov 28, 2023
81aebc7
Merge remote-tracking branch 'origin/enhance_hypercube_pad' into enha…
Davknapp Nov 28, 2023
45f9af2
Merge branch 'main' into enhance_hypercube_pad
sandro-elsweijer Jan 15, 2024
2f4843f
remove deprecated indent markers
sandro-elsweijer Jan 15, 2024
0145609
add include
sandro-elsweijer Jan 15, 2024
254e12a
streamline geometries and make them all structs
sandro-elsweijer Jan 15, 2024
ed0896a
add missing c implementation of t8_geom_get_type
sandro-elsweijer Jan 16, 2024
d134c7c
add missing include
sandro-elsweijer Jan 16, 2024
fd7278d
use c implementation of t8_geom_get_type
sandro-elsweijer Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/cmesh/t8_cmesh_hypercube_pad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main (int argc, char **argv)
t8_init (SC_LP_PRODUCTION);

/* Add hypercube with given element class. */
t8_cmesh_t cmesh = t8_cmesh_new_hypercube_pad (T8_ECLASS_HEX, sc_MPI_COMM_WORLD, boundary_coords, 3, 3, 3);
t8_cmesh_t cmesh = t8_cmesh_new_hypercube_pad (T8_ECLASS_HEX, sc_MPI_COMM_WORLD, boundary_coords, 3, 3, 3, 0);

/* Compute local and global number of trees. */
local_num_trees = t8_cmesh_get_num_local_trees (cmesh);
Expand Down
3 changes: 2 additions & 1 deletion example/remove/t8_example_empty_trees.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ t8_strip_of_quads (t8_gloidx_t num_trees, t8_gloidx_t empty_tree, const char **v

const double boundary_coords[12] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0 };

t8_cmesh_t cmesh = t8_cmesh_new_hypercube_pad (T8_ECLASS_QUAD, sc_MPI_COMM_WORLD, boundary_coords, num_trees, 1, 0);
t8_cmesh_t cmesh
= t8_cmesh_new_hypercube_pad (T8_ECLASS_QUAD, sc_MPI_COMM_WORLD, boundary_coords, num_trees, 1, 0, 1);

t8_forest_t forest = t8_forest_new_uniform (cmesh, t8_scheme_new_default_cxx (), 0, 0, sc_MPI_COMM_WORLD);

Expand Down
64 changes: 51 additions & 13 deletions src/t8_cmesh/t8_cmesh_examples.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <t8_cmesh/t8_cmesh_helpers.h>
#include <t8_cmesh/t8_cmesh_geometry.h>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear.h>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.h>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_examples.h>
#include <t8_vec.h>
#include <t8_mat.h>
Expand Down Expand Up @@ -884,12 +885,13 @@ t8_resize_box (const int dim, double *box_corners, const double *box_dir, const
* \param [in] boundary The boundary vertices of \a cmesh.
* \param [in] quads_x The number of quads along the x-axis.
* \param [in] quads_y The number of quads along the y-axis.
* \param [in] use_axis_aligned_geom Flag if cmesh uses the axis_aligned_geometry. Only available for T8_ECLASS_QUAD
* \note each quad of \a quads_x * \a quads_y quads in \a boundary contains one
* tree of \a eclass T8_ECLASS_QUAD or two of T8_ECLASS_TRIANGLE.
*/
static void
t8_cmesh_set_vertices_2D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const double *boundary, const t8_locidx_t quads_x,
const t8_locidx_t quads_y)
const t8_locidx_t quads_y, const int use_axis_aligned_geom)
{
T8_ASSERT (!t8_cmesh_is_committed (cmesh));
T8_ASSERT (eclass == T8_ECLASS_QUAD || eclass == T8_ECLASS_TRIANGLE);
Expand Down Expand Up @@ -940,7 +942,7 @@ t8_cmesh_set_vertices_2D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub
for (t8_locidx_t quad_y_id = 0; quad_y_id < quads_y; quad_y_id++) {
for (t8_locidx_t quad_x_id = 0; quad_x_id < quads_x; quad_x_id++) {

t8_vec_axy (box, vertices, 1.0); /* Vertex 0 */
memcpy (vertices, box, 3 * sizeof (double)); /* Vertex 0 */
t8_vec_axpyz (box, box_dir, vertices + 6, 1.0); /* Vertex 2 */

/* Reduce box along x axis */
Expand All @@ -949,12 +951,23 @@ t8_cmesh_set_vertices_2D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub

t8_vec_axy (box, vertices + 3, 1.0); /* Vertex 1 */
t8_vec_axpyz (box, box_dir, vertices + 9, 1.0); /* Vertex 3 */
if (use_axis_aligned_geom && eclass == T8_ECLASS_QUAD) {
/* Copy vertex 3 into the place of vertex 1. The box-procedure has to be done to compute
* vertex 3 correctly. */
memcpy (vertices + 3, vertices + 9, 3 * sizeof (double));
}
#if T8_ENABLE_DEBUG
else if (use_axis_aligned_geom && eclass != T8_ECLASS_QUAD) {
SC_ABORTF ("Axis aligned geometry is not available for eclass %s!\n", t8_eclass_to_string[eclass]);
}
#endif
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved

/* Map vertices of current quad on to respective trees inside. */
if (eclass == T8_ECLASS_QUAD) {
/* No mapping is required. */
const t8_locidx_t tree_id = quad_y_id * quads_x + quad_x_id;
t8_cmesh_set_tree_vertices (cmesh, tree_id, vertices, 4);
t8_cmesh_set_tree_vertices (cmesh, tree_id, vertices,
(use_axis_aligned_geom && eclass == T8_ECLASS_QUAD) ? 2 : 4);
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved
}
else {
T8_ASSERT (eclass == T8_ECLASS_TRIANGLE);
Expand Down Expand Up @@ -997,12 +1010,13 @@ t8_cmesh_set_vertices_2D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub
* \param [in] hexs_x The number of hexs along the x-axis.
* \param [in] hexs_y The number of hexs along the y-axis.
* \param [in] hexs_z The number of hexs along the z-axis.
* \param [in] use_axis_aligned_geom Flag if cmesh uses the axis aligned_geometry. Only available for T8_ECLASS_QUAD
* \note each hex of \a hexs_x * \a hexs_y * \a hexs_z hexs in \a boundary
* contains several trees of class \a eclass.
*/
static void
t8_cmesh_set_vertices_3D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const double *boundary, const t8_locidx_t hexs_x,
const t8_locidx_t hexs_y, const t8_locidx_t hexs_z)
const t8_locidx_t hexs_y, const t8_locidx_t hexs_z, const int use_axis_aligned_geom)
{
T8_ASSERT (!t8_cmesh_is_committed (cmesh));
/* x axes */
Expand Down Expand Up @@ -1078,8 +1092,7 @@ t8_cmesh_set_vertices_3D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub
for (t8_locidx_t hex_z_id = 0; hex_z_id < hexs_z; hex_z_id++) {
for (t8_locidx_t hex_y_id = 0; hex_y_id < hexs_y; hex_y_id++) {
for (t8_locidx_t hex_x_id = 0; hex_x_id < hexs_x; hex_x_id++) {

t8_vec_axy (box, vertices, 1.0); /* Vertex 0 */
memcpy (vertices, box, 3 * sizeof (double)); /* Vertex 0 */
t8_vec_axpyz (box, box_dir + 12, vertices + 6, 1.0); /* Vertex 2 */

/* Reduce box along z axis and face 4. */
Expand All @@ -1103,11 +1116,23 @@ t8_cmesh_set_vertices_3D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub
t8_vec_axy (box, vertices + 3, 1.0); /* Vertex 1 */
t8_vec_axpyz (box, box_dir + 12, vertices + 9, 1.0); /* Vertex 3 */

if (use_axis_aligned_geom && eclass == T8_ECLASS_HEX) {
/* Copy vertex 7 into the place of vertex 1. The box-procedure has to be done to compute
* vertex 7 correctly. */
memcpy (vertices + 3, vertices + 21, 3 * sizeof (double));
}
#if T8_ENABLE_DEBUG
else if (use_axis_aligned_geom && eclass != T8_ECLASS_HEX) {
SC_ABORTF ("Axis aligned geometry is not available for eclass %s!\n", t8_eclass_to_string[eclass]);
}
#endif
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved

/* Map vertices of current hex on to respective trees inside. */
const t8_locidx_t hex_id = hex_z_id * hexs_y * hexs_x + hex_y_id * hexs_x + hex_x_id;
if (eclass == T8_ECLASS_HEX) {
/* No mapping is required. */
t8_cmesh_set_tree_vertices (cmesh, hex_id, vertices, 8);
t8_cmesh_set_tree_vertices (cmesh, hex_id, vertices,
(use_axis_aligned_geom && eclass == T8_ECLASS_HEX) ? 2 : 8);
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved
}
else if (eclass == T8_ECLASS_TET) {
const t8_locidx_t tree_id_0 = hex_id * 6;
Expand Down Expand Up @@ -1194,7 +1219,7 @@ t8_cmesh_set_vertices_3D (t8_cmesh_t cmesh, const t8_eclass_t eclass, const doub

t8_cmesh_t
t8_cmesh_new_hypercube_pad (const t8_eclass_t eclass, sc_MPI_Comm comm, const double *boundary, t8_locidx_t polygons_x,
t8_locidx_t polygons_y, t8_locidx_t polygons_z)
t8_locidx_t polygons_y, t8_locidx_t polygons_z, const int use_axis_aligned_geom)
{
SC_CHECK_ABORT (eclass != T8_ECLASS_PYRAMID, "Pyramids are not yet supported.");
const int dim = t8_eclass_to_dimension[eclass];
Expand All @@ -1215,9 +1240,22 @@ t8_cmesh_new_hypercube_pad (const t8_eclass_t eclass, sc_MPI_Comm comm, const do
t8_cmesh_t cmesh;
t8_cmesh_init (&cmesh);

/* We use standard linear geometry */
const t8_geometry_c *linear_geom = t8_geometry_linear_new (dim);
t8_cmesh_register_geometry (cmesh, linear_geom);
if (use_axis_aligned_geom && (eclass == T8_ECLASS_HEX || eclass == T8_ECLASS_QUAD || eclass == T8_ECLASS_LINE)) {
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved
/* We use axis aligned geometries */
const t8_geometry_c *axis_aligned_geom = t8_geometry_linear_axis_aligned_new (dim);
t8_cmesh_register_geometry (cmesh, axis_aligned_geom);
sandro-elsweijer marked this conversation as resolved.
Show resolved Hide resolved
}
#if T8_ENABLE_DEBUG
else if (use_axis_aligned_geom
&& !(eclass == T8_ECLASS_HEX || eclass == T8_ECLASS_QUAD || eclass == T8_ECLASS_LINE)) {
SC_ABORTF ("Axis aligned geometry is not available for eclass %s!\n", t8_eclass_to_string[eclass]);
}
#endif
else {
/* We use standard linear geometry */
const t8_geometry_c *linear_geom = t8_geometry_linear_new (dim);
t8_cmesh_register_geometry (cmesh, linear_geom);
}

/* Number of trees inside each polygon of given eclass. */
const t8_locidx_t num_trees_for_single_hypercube[T8_ECLASS_COUNT] = { 1, 1, 1, 2, 1, 6, 2, -1 };
Expand All @@ -1231,11 +1269,11 @@ t8_cmesh_new_hypercube_pad (const t8_eclass_t eclass, sc_MPI_Comm comm, const do
/* Set the vertices of all trees. */
if (dim == 3) {
T8_ASSERT (eclass == T8_ECLASS_HEX || eclass == T8_ECLASS_TET || eclass == T8_ECLASS_PRISM);
t8_cmesh_set_vertices_3D (cmesh, eclass, boundary, polygons_x, polygons_y, polygons_z);
t8_cmesh_set_vertices_3D (cmesh, eclass, boundary, polygons_x, polygons_y, polygons_z, use_axis_aligned_geom);
}
else if (dim == 2) {
T8_ASSERT (eclass == T8_ECLASS_QUAD || eclass == T8_ECLASS_TRIANGLE);
t8_cmesh_set_vertices_2D (cmesh, eclass, boundary, polygons_x, polygons_y);
t8_cmesh_set_vertices_2D (cmesh, eclass, boundary, polygons_x, polygons_y, use_axis_aligned_geom);
}
else if (dim == 1) {
T8_ASSERT (eclass == T8_ECLASS_LINE);
Expand Down
4 changes: 3 additions & 1 deletion src/t8_cmesh/t8_cmesh_examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ t8_cmesh_new_hypercube (t8_eclass_t eclass, sc_MPI_Comm comm, int do_bcast, int
* Only required if \a eclass is 2D or 3D.
* \param [in] polygons_z The number of polygons along the z-axis.
* Only required if \a eclass is 3D.
* \param [in] use_axis_aligned_geom Flag if cmesh uses the axis aligned_geometry. Only available for
* T8_ECLASS_LINE/QUAD/HEX
* \return A committed t8_cmesh structure with
* \a polygons_x * \a polygons_z * \a polygons_y many
* sub-hypercubes of class \a eclass.
Expand All @@ -132,7 +134,7 @@ t8_cmesh_new_hypercube (t8_eclass_t eclass, sc_MPI_Comm comm, int do_bcast, int
*/
t8_cmesh_t
t8_cmesh_new_hypercube_pad (const t8_eclass_t eclass, sc_MPI_Comm comm, const double *boundary, t8_locidx_t polygons_x,
t8_locidx_t polygons_y, t8_locidx_t polygons_z);
t8_locidx_t polygons_y, t8_locidx_t polygons_z, const int use_axis_aligned_geom);

/** Hybercube with 6 Tets, 6 Prism, 4 Hex.
* \param [in] comm The mpi communicator to be used.
Expand Down
2 changes: 1 addition & 1 deletion test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ TEST (t8_cmesh_set_join_by_vertices, test_cmesh_set_join_by_vertices)
const double boundary_coords[24] = { 1, 0, 0, 4, 0, 0, 0, 6, 0, 5, 5, 0, -1, -2, 8, 9, 0, 10, 0, 8, 9, 10, 10, 10 };

t8_eclass_t eclass = T8_ECLASS_HEX;
t8_cmesh_t cmesh = t8_cmesh_new_hypercube_pad (eclass, comm, boundary_coords, 2, 2, 2);
t8_cmesh_t cmesh = t8_cmesh_new_hypercube_pad (eclass, comm, boundary_coords, 2, 2, 2, 0);
test_with_cmesh (cmesh);
t8_cmesh_destroy (&cmesh);
}
Expand Down