diff --git a/src/meshes/t8code_mesh.jl b/src/meshes/t8code_mesh.jl index f19cd4fba17..9fd70c45f63 100644 --- a/src/meshes/t8code_mesh.jl +++ b/src/meshes/t8code_mesh.jl @@ -1162,3 +1162,412 @@ function output_data_to_vtu(mesh::T8codeMesh, equations, solver, write_level, write_element_id, write_ghosts, 0, 0, num_data, pointer(vtk_data)) end + +# Simple meshes +# Temporary routines to create simple `cmesh`s by hand + +# Directly ported from: `src/t8_cmesh/t8_cmesh_examples.c: t8_cmesh_new_periodic_hybrid`. +function cmesh_new_periodic_hybrid(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -1.0, -1.0, 0, # tree 0, triangle + 0, -1.0, 0, + 0, 0, 0, + -1.0, -1.0, 0, # tree 1, triangle + 0, 0, 0, + -1.0, 0, 0, + 0, -1.0, 0, # tree 2, quad + 1.0, -1.0, 0, + 0, 0, 0, + 1.0, 0, 0, + -1.0, 0, 0, # tree 3, quad + 0, 0, 0, + -1.0, 1.0, 0, + 0, 1.0, 0, + 0, 0, 0, # tree 4, triangle + 1.0, 0, 0, + 1.0, 1.0, 0, + 0, 0, 0, # tree 5, triangle + 1.0, 1.0, 0, + 0, 1.0, 0, + ] + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # Domain size [-1,1]^2 + # + # +---+---+ + # | |5 /| + # | 3 | / | + # | |/ 4| + # +---+---+ + # |1 /| | + # | / | 2 | + # |/0 | | + # +---+---+ + # + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # Use linear geometry + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 1, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 2, T8_ECLASS_QUAD) + t8_cmesh_set_tree_class(cmesh, 3, T8_ECLASS_QUAD) + t8_cmesh_set_tree_class(cmesh, 4, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 5, T8_ECLASS_TRIANGLE) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 1, @views(vertices[(1 + 9):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 2, @views(vertices[(1 + 18):end]), 4) + t8_cmesh_set_tree_vertices(cmesh, 3, @views(vertices[(1 + 30):end]), 4) + t8_cmesh_set_tree_vertices(cmesh, 4, @views(vertices[(1 + 42):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 5, @views(vertices[(1 + 51):end]), 3) + + t8_cmesh_set_join(cmesh, 0, 1, 1, 2, 0) + t8_cmesh_set_join(cmesh, 0, 2, 0, 0, 0) + t8_cmesh_set_join(cmesh, 0, 3, 2, 3, 0) + + t8_cmesh_set_join(cmesh, 1, 3, 0, 2, 1) + t8_cmesh_set_join(cmesh, 1, 2, 1, 1, 0) + + t8_cmesh_set_join(cmesh, 2, 4, 3, 2, 0) + t8_cmesh_set_join(cmesh, 2, 5, 2, 0, 1) + + t8_cmesh_set_join(cmesh, 3, 5, 1, 1, 0) + t8_cmesh_set_join(cmesh, 3, 4, 0, 0, 0) + + t8_cmesh_set_join(cmesh, 4, 5, 1, 2, 0) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end + +function cmesh_new_periodic_quad_nonperiodic(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -1.0, -1.0, 0, # tree 0, quad + 1.0, -1.0, 0, + -1.0, 1.0, 0, + 1.0, 1.0, 0, + + # rotated: + # -1.0, 0.0, 0, # tree 0, quad + # 0.0, -1.0, 0, + # 0.0, 1.0, 0, + # 1.0, 0.0, 0, + ] + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # + # +---+ + # | | + # | 0 | + # | | + # +---+ + # + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # Use linear geometry + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_QUAD) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 4) + + # t8_cmesh_set_join(cmesh, 0, 0, 0, 1, 0) + # t8_cmesh_set_join(cmesh, 0, 0, 2, 3, 0) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end + +function cmesh_new_periodic_quad(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -1.0, -1.0, 0, # tree 0, quad + 1.0, -1.0, 0, + -1.0, 1.0, 0, + 1.0, 1.0, 0, + + # rotated: + # -1.0, 0.0, 0, # tree 0, quad + # 0.0, -1.0, 0, + # 0.0, 1.0, 0, + # 1.0, 0.0, 0, + ] + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # + # +---+ + # | | + # | 0 | + # | | + # +---+ + # + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # Use linear geometry + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_QUAD) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 4) + + t8_cmesh_set_join(cmesh, 0, 0, 0, 1, 0) + t8_cmesh_set_join(cmesh, 0, 0, 2, 3, 0) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end + +function cmesh_new_periodic_tri(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -1.0, -1.0, 0, # tree 0, triangle + 1.0, -1.0, 0, + 1.0, 1.0, 0, + -1.0, -1.0, 0, # tree 1, triangle + 1.0, 1.0, 0, + -1.0, 1.0, 0, + + # rotated: + # -1.0, 0, 0, # tree 0, triangle + # 0, -1.0, 0, + # 1.0, 0, 0, + # -1.0, 0, 0, # tree 1, triangle + # 1.0, 0, 0, + # 0, 1.0, 0, + ] + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # + # +---+ + # |1 /| + # | / | + # |/0 | + # +---+ + # + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # /* Use linear geometry */ + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 1, T8_ECLASS_TRIANGLE) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 1, @views(vertices[(1 + 9):end]), 3) + + t8_cmesh_set_join(cmesh, 0, 1, 1, 2, 0) + t8_cmesh_set_join(cmesh, 0, 1, 0, 1, 0) + t8_cmesh_set_join(cmesh, 0, 1, 2, 0, 1) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end + +function cmesh_new_periodic_tri2(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -1.0, -1.0, 0, # tree 0, triangle + 0, -1.0, 0, + 0, 0, 0, + -1.0, -1.0, 0, # tree 1, triangle + 0, 0, 0, + -1.0, 0, 0, + 0, -1.0, 0, # tree 2, triangle + 1.0, -1.0, 0, + 1.0, 0, 0, + 0, -1.0, 0, # tree 3, triangle + 1.0, 0, 0, + 0, 0, 0, + -1.0, 0, 0, # tree 4, triangle + 0, 0, 0, + -1.0, 1.0, 0, + -1.0, 1.0, 0, # tree 5, triangle + 0, 0, 0, + 0, 1.0, 0, + 0, 0, 0, # tree 6, triangle + 1.0, 0, 0, + 0, 1.0, 0, + 0, 1.0, 0, # tree 7, triangle + 1.0, 0, 0, + 1.0, 1.0, 0, + ] + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # + # +---+---+ + # |\ 5|\ 7| + # | \ | \ | + # |4 \| 6\| + # +---+---+ + # |1 /|3 /| + # | / | / | + # |/0 |/ 2| + # +---+---+ + # + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # /* Use linear geometry */ + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 1, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 2, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 3, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 4, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 5, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 6, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 7, T8_ECLASS_TRIANGLE) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 1, @views(vertices[(1 + 9):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 2, @views(vertices[(1 + 18):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 3, @views(vertices[(1 + 27):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 4, @views(vertices[(1 + 36):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 5, @views(vertices[(1 + 45):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 6, @views(vertices[(1 + 54):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 7, @views(vertices[(1 + 63):end]), 3) + + t8_cmesh_set_join(cmesh, 0, 1, 1, 2, 0) + t8_cmesh_set_join(cmesh, 0, 3, 0, 1, 0) + t8_cmesh_set_join(cmesh, 0, 5, 2, 1, 0) + + t8_cmesh_set_join(cmesh, 1, 4, 0, 2, 1) + t8_cmesh_set_join(cmesh, 1, 2, 1, 0, 0) + + t8_cmesh_set_join(cmesh, 2, 3, 1, 2, 0) + t8_cmesh_set_join(cmesh, 2, 7, 2, 1, 0) + + t8_cmesh_set_join(cmesh, 3, 6, 0, 2, 1) + + t8_cmesh_set_join(cmesh, 4, 5, 0, 2, 1) + t8_cmesh_set_join(cmesh, 4, 7, 1, 0, 0) + + t8_cmesh_set_join(cmesh, 5, 6, 0, 1, 0) + + t8_cmesh_set_join(cmesh, 6, 7, 0, 2, 1) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end + +# Directly ported from: `src/t8_cmesh/t8_cmesh_examples.c: t8_cmesh_new_periodic_hybrid`. +function cmesh_new_periodic_hybrid2(comm)::t8_cmesh_t + n_dims = 2 + vertices = [ # Just all vertices of all trees. partly duplicated + -2.0, -2.0, 0, # tree 0, triangle + 0, -2.0, 0, + -2.0, 0, 0, + -2.0, 2.0, 0, # tree 1, triangle + -2.0, 0, 0, + 0, 2.0, 0, + 2.0, -2.0, 0, # tree 2, triangle + 2.0, 0, 0, + 0, -2.0, 0, + 2.0, 2.0, 0, # tree 3, triangle + 0, 2.0, 0, + 2.0, 0, 0, + 0, -2.0, 0, # tree 4, quad + 2.0, 0, 0, + -2.0, 0, 0, + 0, 2.0, 0, + ] + # + # This is how the cmesh looks like. The numbers are the tree numbers: + # Domain size [-2,2]^2 + # + # +----------+ + # | 1 /\ 3 | + # | / \ | + # | / \ | + # | / \ | + # |/ 4 \| + # |\ /| + # | \ / | + # | \ / | + # | 0 \ / 2 | + # | \/ | + # +----------+ + # + + # Generally, one can define other geometries. But besides linear the other + # geometries in t8code do not have C interface yet. + linear_geom = t8_geometry_linear_new(n_dims) + + cmesh_ref = Ref(t8_cmesh_t()) + t8_cmesh_init(cmesh_ref) + cmesh = cmesh_ref[] + + # Use linear geometry + t8_cmesh_register_geometry(cmesh, linear_geom) + t8_cmesh_set_tree_class(cmesh, 0, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 1, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 2, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 3, T8_ECLASS_TRIANGLE) + t8_cmesh_set_tree_class(cmesh, 4, T8_ECLASS_QUAD) + + t8_cmesh_set_tree_vertices(cmesh, 0, @views(vertices[(1 + 0):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 1, @views(vertices[(1 + 9):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 2, @views(vertices[(1 + 18):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 3, @views(vertices[(1 + 27):end]), 3) + t8_cmesh_set_tree_vertices(cmesh, 4, @views(vertices[(1 + 36):end]), 4) + + t8_cmesh_set_join(cmesh, 0, 4, 0, 0, 0) + t8_cmesh_set_join(cmesh, 0, 2, 1, 2, 0) + t8_cmesh_set_join(cmesh, 0, 1, 2, 1, 0) + + t8_cmesh_set_join(cmesh, 1, 4, 0, 3, 0) + t8_cmesh_set_join(cmesh, 1, 3, 2, 1, 0) + + t8_cmesh_set_join(cmesh, 2, 4, 0, 2, 1) + t8_cmesh_set_join(cmesh, 2, 3, 1, 2, 0) + + t8_cmesh_set_join(cmesh, 3, 4, 0, 1, 1) + + t8_cmesh_commit(cmesh, comm) + + return cmesh +end \ No newline at end of file