Skip to content

Commit

Permalink
example balance corner: combine 2d and 3d
Browse files Browse the repository at this point in the history
  • Loading branch information
SAutum committed Oct 17, 2023
1 parent 056d81b commit d76e6b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 119 deletions.
17 changes: 17 additions & 0 deletions example/balance/balance_corner2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef P4_TO_P8
#include <p4est_bits.h>
#include <p4est_extended.h>
#include <p4est_vtk.h>
#else
#include <p8est_bits.h>
#include <p8est_extended.h>
#include <p8est_vtk.h>
#endif

typedef struct
{
Expand Down Expand Up @@ -116,9 +122,16 @@ main (int argc, char **argv)

/* create connectivity and forest structures */
geom = NULL;
#ifndef P4_TO_P8
connectivity = p4est_connectivity_new_bowtie ();
p4est = p4est_new_ext (mpi->mpicomm, connectivity, 15, 0, 0,
sizeof (user_data_t), init_fn, geom);
#else
connectivity = p8est_connectivity_new_drop ();
p4est = p8est_new_ext (mpi->mpicomm, connectivity, 15, 0, 0,
sizeof (user_data_t), init_fn, geom);
#endif
p4est_vtk_write_file (p4est, geom, "test");

/* refinement */
p4est_refine (p4est, 1, refine_fn, init_fn);
Expand All @@ -128,7 +141,11 @@ main (int argc, char **argv)

/* partition */
p4est_partition (p4est, 0, NULL);
#ifndef P4_TO_P8
p4est_vtk_write_file (p4est, geom, "balance_corner2_partition");
#else
p4est_vtk_write_file (p4est, geom, "balance_corner3_partition");
#endif

/* destroy p4est and its connectivity */
p4est_destroy (p4est);
Expand Down
121 changes: 2 additions & 119 deletions example/balance/balance_corner3.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,122 +22,5 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <p8est_bits.h>
#include <p8est_extended.h>
#include <p8est_vtk.h>

typedef struct
{
p4est_topidx_t a;
}
user_data_t;

typedef struct
{
sc_MPI_Comm mpicomm;
int mpisize;
int mpirank;
}
mpi_context_t;

/* refinement level initialization */
static int refine_level = 0;

/* connectivity initialization function */
static void
init_fn (p8est_t * p8est, p4est_topidx_t which_tree,
p8est_quadrant_t * quadrant)
{
user_data_t *data = (user_data_t *) quadrant->p.user_data;

data->a = which_tree;
}

/* refinement function */
static int
refine_fn (p8est_t * p8est, p4est_topidx_t which_tree,
p8est_quadrant_t * quadrant)
{
if ((int) quadrant->level >= (refine_level - (int) (which_tree % 3))) {
return 0;
}
if (quadrant->level == 1 && p8est_quadrant_child_id (quadrant) == 3) {
return 1;
}
if (quadrant->x == P8EST_LAST_OFFSET (2) &&
quadrant->y == P8EST_LAST_OFFSET (2)) {
return 1;
}
if (quadrant->x >= P8EST_QUADRANT_LEN (2)) {
return 0;
}

return 1;
}

int
main (int argc, char **argv)
{
int mpiret;
int wrongusage;
const char *usage;
p8est_connectivity_t *connectivity;
mpi_context_t mpi_context, *mpi = &mpi_context;
p8est_geometry_t *geom;
p8est_t *p8est;

/* initialize MPI and p8est internals */
mpiret = sc_MPI_Init (&argc, &argv);
SC_CHECK_MPI (mpiret);
mpi->mpicomm = sc_MPI_COMM_WORLD;
mpiret = sc_MPI_Comm_size (mpi->mpicomm, &mpi->mpisize);
SC_CHECK_MPI (mpiret);
mpiret = sc_MPI_Comm_rank (mpi->mpicomm, &mpi->mpirank);
SC_CHECK_MPI (mpiret);

sc_init (mpi->mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
p4est_init (NULL, SC_LP_DEFAULT);

/* usage error if the input is not in the correct format */
usage =
"Arguments: <level>\n"
" Level: controls the maximum depth of refinement\n";
wrongusage = 0;
if (!wrongusage && argc != 2) {
wrongusage = 1;
}
if (wrongusage) {
P4EST_GLOBAL_LERROR (usage);
sc_abort_collective ("Usage error");
}

/* assign variables based on configuration */
refine_level = atoi (argv[1]);

/* create connectivity and forest structures */
geom = NULL;
connectivity = p8est_connectivity_new_drop ();
p8est = p8est_new_ext (mpi->mpicomm, connectivity, 15, 0, 0,
sizeof (user_data_t), init_fn, geom);

/* refinement */
p8est_refine (p8est, 1, refine_fn, init_fn);

/* balance */
p8est_balance (p8est, P8EST_CONNECT_FULL, init_fn);

/* partition */
p8est_partition (p8est, 0, NULL);
p8est_vtk_write_file (p8est, geom, "balance_corner3_partition");

/* destroy p8est and its connectivity */
p8est_destroy (p8est);
p8est_connectivity_destroy (connectivity);
/* clean up and exit */
sc_finalize ();

mpiret = sc_MPI_Finalize ();
SC_CHECK_MPI (mpiret);

return 0;
}
#include <p4est_to_p8est.h>
#include "balance_corner2.c"

0 comments on commit d76e6b0

Please sign in to comment.