Skip to content

Commit

Permalink
Merge branch 'main' into specification-of-testlevel2
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaploetzke authored Feb 24, 2025
2 parents 610300e + d1d2231 commit 24c49a1
Show file tree
Hide file tree
Showing 48 changed files with 1,552 additions and 934 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,10 @@ We provide a short guide to install t8code in our Wiki [Installation guide](http

### Documentation

t8code uses [Doxygen](https://doxygen.nl/) to generate the code documentation. You can build the documentation with
t8code uses [Doxygen](https://doxygen.nl/) to generate the code documentation.
You can find the documentation of our releases on the [t8code website](https://dlr-amr.github.io/t8code/pages/documentation.html).
Follow the steps described in our Wiki [Documentation](https://github.com/DLR-AMR/t8code/wiki/Documentation) to create the documentation locally.

```
make doxygen
```

and then find the generated files in the `/doc` subfolder.

You can also find the documentation of our releases on the [t8code website](https://dlr-amr.github.io/t8code/pages/documentation.html).

### License and contributing
t8code is licensed under GPLv2 (see [COPYING](COPYING)). We appreciate
Expand Down
50 changes: 11 additions & 39 deletions benchmarks/t8_time_forest_partition.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#include <t8_forest/t8_forest_geometrical.h>
#include <t8_forest/t8_forest_profiling.h>
#include <t8_schemes/t8_default/t8_default.hxx>
#include <example/common/t8_example_common.h>
#include <example/common/t8_example_common.hxx>
#include <t8_types/t8_vec.hxx>

/* This is the user defined data used to define the
* region in which we partition.
Expand All @@ -48,29 +49,11 @@
typedef struct
{
double c_min, c_max; /* constants that define the thickness of the refinement region */
double normal[3]; /* normal vector to the plane E */
t8_3D_vec normal; /* normal vector to the plane E */
int base_level; /* A given level that is not coarsend further, see -l argument */
int max_level; /* A max level that is not refined further, see -L argument */
} adapt_data_t;

/* Simple 3 dimensional vector product */
static double
t8_vec3_dot (double *v1, double *v2)
{
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
}

/* Set x = x - alpha*y
* for 2 3dim vectors x,y and a constant alpha */
static void
t8_vec3_xmay (double *x, double alpha, double *y)
{
int i;
for (i = 0; i < 3; i++) {
x[i] -= alpha * y[i];
}
}

#if 0
/* TODO: deprecated. was replaced by t8_common_midpoint. */
static void
Expand Down Expand Up @@ -106,33 +89,32 @@ t8_band_adapt (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tr
t8_element_t *elements[])
{
int level, base_level, max_level;
double elem_midpoint[3];
double *normal;
t8_3D_vec elem_midpoint;
adapt_data_t *adapt_data;

T8_ASSERT (!is_family || num_elements == scheme->element_get_num_children (tree_class, elements[0]));
level = scheme->element_get_level (tree_class, elements[0]);
/* Get the minimum and maximum x-coordinate from the user data pointer of forest */
adapt_data = (adapt_data_t *) t8_forest_get_user_data (forest);
normal = adapt_data->normal;
t8_3D_vec normal = adapt_data->normal;
base_level = adapt_data->base_level;
max_level = adapt_data->max_level;
/* Compute the coordinates of the anchor node. */
t8_forest_element_centroid (forest_from, which_tree, elements[0], elem_midpoint);
t8_forest_element_centroid (forest_from, which_tree, elements[0], elem_midpoint.data ());

/* Calculate elem_midpoint - c_min n */
t8_vec3_xmay (elem_midpoint, adapt_data->c_min, normal);
t8_axy (elem_midpoint, normal, adapt_data->c_min);

/* The purpose of the factor C*h is that the levels get smaller, the
* closer we get to the interface. We refine a cell if it is at most
* C times its own height away from the interface */
if (t8_vec3_dot (elem_midpoint, normal) >= 0) {
if (t8_dot (elem_midpoint, normal) >= 0) {
/* if the anchor node is to the right of c_min*E,
* check if it is to the left of c_max*E */

/* set elem_midpoint to the original anchor - c_max*normal */
t8_vec3_xmay (elem_midpoint, adapt_data->c_max - adapt_data->c_min, normal);
if (t8_vec3_dot (elem_midpoint, normal) <= 0) {
t8_axy (elem_midpoint, normal, adapt_data->c_max - adapt_data->c_min);
if (t8_dot (elem_midpoint, normal) <= 0) {
if (level < max_level) {
/* We do refine if level smaller 1+base level and the anchor is
* to the left of c_max*E */
Expand All @@ -154,16 +136,6 @@ t8_band_adapt (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tr
return 0;
}

static void
t8_vec3_normalize (double *v)
{
double norm = sqrt (t8_vec3_dot (v, v));

v[0] /= norm;
v[1] /= norm;
v[2] /= norm;
}

/* Create a cmesh from a .msh files uniform level 0
* partitioned. */
static void
Expand Down Expand Up @@ -212,7 +184,7 @@ t8_time_forest_cmesh_mshfile (t8_cmesh_t cmesh, const char *vtu_prefix, sc_MPI_C
adapt_data.normal[0] = 0.8;
adapt_data.normal[1] = 0.3;
adapt_data.normal[2] = 0.0;
t8_vec3_normalize (adapt_data.normal);
t8_normalize (adapt_data.normal);
adapt_data.base_level = init_level;
adapt_data.max_level = max_level;
/* Start the time loop, in each time step the refinement front moves
Expand Down
27 changes: 5 additions & 22 deletions example/IO/cmesh/gmsh/t8_load_and_refine_square_w_hole.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,7 @@
#include <t8_forest/t8_forest_io.h>
#include <t8_forest/t8_forest_geometrical.h>
#include <t8_schemes/t8_default/t8_default.hxx>

/* Simple 3 dimensional vector product */
static double
t8_vec3_dot (double *v1, double *v2)
{
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
}

/* Set x = x - alpha*y
* for 2 3dim vectors x,y and a constant alpha */
static void
t8_vec3_xmay (double *x, double alpha, double *y)
{
int i;
for (i = 0; i < 3; i++) {
x[i] -= alpha * y[i];
}
}
#include <t8_types/t8_vec.h>

/* Compute the coordinates of the midpoint
* and a measure for the length of a triangle or square */
Expand Down Expand Up @@ -86,7 +69,7 @@ t8_midpoint (t8_forest_t forest, t8_locidx_t which_tree, t8_element_t *element,
for (j = 0; j < 3; j++) {
corner[0][j] -= elem_mid_point[j];
}
*h = sqrt (t8_vec3_dot (corner[0], corner[0]));
*h = t8_norm (corner[0]);

T8_FREE (corner[0]);
T8_FREE (corner[1]);
Expand All @@ -105,10 +88,10 @@ t8_midpoint (t8_forest_t forest, t8_locidx_t which_tree, t8_element_t *element,
/* Now that we now the midpoint, we can compute h */
for (i = 0; i < 3; i++) {
/* Compute the difference of the mid vertex and the i-th vertex */
t8_vec3_xmay (corner[i], 1, elem_mid_point);
t8_axy (corner[i], elem_mid_point, 1);
/* Set the size of the element to the euclidean distance of the two
* vertices if it is bigger than the previous distance */
*h = SC_MAX (sqrt (t8_vec3_dot (corner[i], corner[i])), *h);
*h = SC_MAX (t8_norm (corner[i]), *h);
T8_FREE (corner[i]);
}
}
Expand Down Expand Up @@ -137,7 +120,7 @@ t8_load_refine_adapt (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t w
}
/* Refine along the inner boundary.
* The factor in front of h controls the width of the refinement region. */
if (tree_class == T8_ECLASS_TRIANGLE && t8_vec3_dot (elem_midpoint, elem_midpoint) < 1 + 5 * h) {
if (tree_class == T8_ECLASS_TRIANGLE && t8_dot (elem_midpoint, elem_midpoint) < 1 + 5 * h) {
return 1;
}

Expand Down
16 changes: 8 additions & 8 deletions example/IO/forest/netcdf/t8_write_forest_netcdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define NC_COLLECTIVE 1
#endif
#include <t8_eclass.h>
#include <t8_vec.h>
#include <t8_types/t8_vec.hxx>
#include <t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_examples.h>
#include <t8_forest/t8_forest_general.h>
Expand All @@ -60,7 +60,7 @@ T8_EXTERN_C_BEGIN ();
*/
struct t8_example_netcdf_adapt_data
{
double midpoint[3]; /* Midpoint of a aphere */
t8_3D_point midpoint; /* Midpoint of a aphere */
double refine_if_inside_radius; /* refine all elements inside this radius from the sphere's midpoint */
double coarsen_if_outside_radius; /* coarsen all element families outside of this radius from the sphere's midpoint */
};
Expand All @@ -74,18 +74,18 @@ t8_example_netcdf_adapt_fn (t8_forest_t forest, t8_forest_t forest_from, t8_loci
const t8_eclass_t tree_class, t8_locidx_t lelement_id, const t8_scheme *scheme,
const int is_family, const int num_elements, t8_element_t *elements[])
{
double element_centroid[3];
t8_3D_point element_centroid;
double distance;

/* Retrieve the adapt_data which holds the information regarding the adaption process of a forest */
const struct t8_example_netcdf_adapt_data *adapt_data
= (const struct t8_example_netcdf_adapt_data *) t8_forest_get_user_data (forest);

/* Compute the element's centroid */
t8_forest_element_centroid (forest_from, which_tree, elements[0], element_centroid);
t8_forest_element_centroid (forest_from, which_tree, elements[0], element_centroid.data ());

/* Compute the distance from the element's midpoint to the midpoint of the centered sphere inside the hypercube */
distance = t8_vec_dist (element_centroid, adapt_data->midpoint);
distance = t8_dist (element_centroid, adapt_data->midpoint);

/* Decide whether the element (or its family) has to be refined or coarsened */
if (distance < adapt_data->refine_if_inside_radius) {
Expand Down Expand Up @@ -116,9 +116,9 @@ t8_example_netcdf_adapt (t8_forest_t forest)

/* The adapt data which controls which elements will be refined or corsened based on the given radii */
struct t8_example_netcdf_adapt_data adapt_data = {
{ 0.5, 0.5, 0.5 }, /* Midpoints of the sphere. */
0.2, /* Refine if inside this radius. */
0.4 /* Coarsen if outside this radius. */
t8_3D_point ({ 0.5, 0.5, 0.5 }), /* Midpoints of the sphere. */
0.2, /* Refine if inside this radius. */
0.4 /* Coarsen if outside this radius. */
};

/* Create the adapted forest with the given adapt_function. */
Expand Down
33 changes: 17 additions & 16 deletions example/advect/t8_advection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include <t8_forest/t8_forest_iterate.h>
#include <t8_forest/t8_forest_partition.h>
#include <t8_forest/t8_forest_ghost.h>
#include <example/common/t8_example_common.h>
#include <example/common/t8_example_common.hxx>
#include <t8_cmesh.h>
#include <t8_cmesh_readmshfile.h>
#include <t8_vtk/t8_vtk_writer.h>
#include <t8_cmesh/t8_cmesh_examples.h>
#include <t8_vec.h>
#include <t8_types/t8_vec.hxx>

#define MAX_FACES 8 /* The maximum number of faces of an element */
/* TODO: This is not memory efficient. If we run out of memory, we can optimize here. */
Expand Down Expand Up @@ -139,7 +139,7 @@ typedef struct
/** The per element data */
typedef struct
{
double midpoint[3]; /**< coordinates of element midpoint in R^3 */
t8_3D_point midpoint; /**< coordinates of element midpoint in R^3 */
double vol; /**< Volume of this element */
double phi_new; /**< Value of solution at midpoint in next time step */
double *fluxes[MAX_FACES]; /**< The fluxes to each neeighbor at a given face */
Expand Down Expand Up @@ -324,9 +324,9 @@ static double
t8_advect_flux_upwind_1d (const t8_advect_problem_t *problem, const t8_locidx_t el_plus, const t8_locidx_t el_minus,
int face)
{
double x_j_half[3];
t8_3D_point x_j_half;
int idim;
double u_at_x_j_half[3];
t8_3D_vec u_at_x_j_half;
double phi;
int sign;
t8_advect_element_data_t *el_data_plus;
Expand Down Expand Up @@ -366,10 +366,10 @@ static double
t8_advect_flux_upwind (const t8_advect_problem_t *problem, double el_plus_phi, double el_minus_phi, t8_locidx_t ltreeid,
const t8_element_t *element_plus, int face)
{
double face_center[3];
double u_at_face_center[3];
double normal[3], normal_times_u;
double area;
t8_3D_point face_center;
t8_3D_vec u_at_face_center;
t8_3D_vec normal;
double area, normal_times_u;

/*
* | --x-- | --x-- | Two elements, midpoints marked with 'x'
Expand All @@ -378,16 +378,16 @@ t8_advect_flux_upwind (const t8_advect_problem_t *problem, double el_plus_phi, d
*/

/* Compute the center coordinate of the face */
t8_forest_element_face_centroid (problem->forest, ltreeid, element_plus, face, face_center);
t8_forest_element_face_centroid (problem->forest, ltreeid, element_plus, face, face_center.data ());
/* Compute u at the face center. */
problem->u (face_center, problem->t, u_at_face_center);
/* Compute the normal of the element at this face */
t8_forest_element_face_normal (problem->forest, ltreeid, element_plus, face, normal);
t8_forest_element_face_normal (problem->forest, ltreeid, element_plus, face, normal.data ());
/* Compute the area of the face */
area = t8_forest_element_face_area (problem->forest, ltreeid, element_plus, face);

/* Compute the dot-product of u and the normal vector */
normal_times_u = t8_vec_dot (normal, u_at_face_center);
normal_times_u = t8_dot (normal, u_at_face_center);

if (normal_times_u >= 0) {
return -el_plus_phi * normal_times_u * area;
Expand Down Expand Up @@ -519,7 +519,7 @@ t8_advect_compute_element_data (t8_advect_problem_t *problem, t8_advect_element_
const t8_element_t *element, const t8_locidx_t ltreeid)
{
/* Compute the midpoint coordinates of element */
t8_forest_element_centroid (problem->forest, ltreeid, element, elem_data->midpoint);
t8_forest_element_centroid (problem->forest, ltreeid, element, elem_data->midpoint.data ());
/* Compute the length of this element */
elem_data->vol = t8_forest_element_volume (problem->forest, ltreeid, element);
}
Expand Down Expand Up @@ -989,7 +989,7 @@ t8_advect_problem_init_elements (t8_advect_problem_t *problem)
const t8_scheme *scheme = t8_forest_get_scheme (problem->forest);
t8_eclass_t neigh_eclass;
double speed, max_speed = 0, min_diam = -1, delta_t, min_delta_t;
double u[3];
t8_3D_vec u;
double diam;
double min_vol = 1e9;

Expand All @@ -1010,7 +1010,7 @@ t8_advect_problem_init_elements (t8_advect_problem_t *problem)
min_diam = min_diam < 0 ? diam : SC_MIN (min_diam, diam);
/* Compute the maximum velocity */
problem->u (elem_data->midpoint, problem->t, u);
speed = t8_vec_norm (u);
speed = t8_norm (u);
max_speed = SC_MAX (max_speed, speed);

/* Compute minimum necessary time step */
Expand Down Expand Up @@ -1068,7 +1068,8 @@ t8_advect_problem_init_elements (t8_advect_problem_t *problem)
static void
t8_advect_write_vtk (t8_advect_problem_t *problem)
{
double *u_and_phi_array[4], u_temp[3];
double *u_and_phi_array[4];
t8_3D_vec u_temp;
t8_locidx_t num_local_elements, ielem;
t8_vtk_data_field_t vtk_data[5];
t8_advect_element_data_t *elem_data;
Expand Down
Loading

0 comments on commit 24c49a1

Please sign in to comment.