Skip to content

Commit

Permalink
Example userdata: move global structure to header
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Feb 11, 2025
1 parent 14ee56e commit e4a4ab2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 28 deletions.
2 changes: 1 addition & 1 deletion doc/doxygen/example_userdata.dox
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* 1. In-place element data
* 2. User-allocated element data
*
* In p4est, an element is the leave of a quadtree (2D) or octree (3D).
* In p4est, an element is the leaf of a quadtree (2D) or octree (3D).
*
* The source code for this demonstration resides in \ref
* userdata/userdata2.c (2D) and \ref userdata/userdata3.c (3D).
Expand Down
6 changes: 4 additions & 2 deletions example/userdata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

if P4EST_ENABLE_BUILD_2D
bin_PROGRAMS += example/userdata/p4est_userdata
example_userdata_p4est_userdata_SOURCES = example/userdata/userdata2.c
example_userdata_p4est_userdata_SOURCES = \
example/userdata/userdata2.c example/userdata/userdata_global.h
endif

if P4EST_ENABLE_BUILD_3D
bin_PROGRAMS += example/userdata/p8est_userdata
example_userdata_p8est_userdata_SOURCES = example/userdata/userdata3.c
example_userdata_p8est_userdata_SOURCES = \
example/userdata/userdata3.c example/userdata/userdata_global.h
endif
29 changes: 4 additions & 25 deletions example/userdata/userdata2.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,10 @@ static const char *p4est_userdata_usage =
"No more than two non-option arguments may be specified.\n";
#endif

/* This file is used to compile both the 2D and the 3D code, separately. */
#include <sc_options.h>
#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

/* we maintain application data in a global structure and pass it around */
typedef struct p4est_userdata_global_t
{
sc_MPI_Comm mpicomm;
sc_options_t *options;
int help;
int maxlevel;
const char *configuration;
p4est_connectivity_t *conn;
p4est_geometry_t *geom;
}
p4est_userdata_global_t;
/* This source file is used to compile both the 2D and the 3D code. */
#include "userdata_global.h"

/* process the command line */
static int
p4est_userdata_process (p4est_userdata_global_t *g)
{
Expand Down Expand Up @@ -220,7 +199,7 @@ p4est_userdata_options (int argc, char **argv, p4est_userdata_global_t *g)
}

/* execute the demonstration */
static int
int
p4est_userdata_run (p4est_userdata_global_t *g)
{
P4EST_ASSERT (g != NULL);
Expand Down
62 changes: 62 additions & 0 deletions example/userdata/userdata_global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
This file is part of p4est.
p4est is a C library to manage a collection (a forest) of multiple
connected adaptive quadtrees or octrees in parallel.
Copyright (C) 2010 The University of Texas System
Additional copyright (C) 2011 individual authors
Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac
p4est is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
p4est is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with p4est; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*
* This is an internal header that must not be installed.
* It may be included from 2D code or alternatively
* from 3D code after including p4est_to_p8est.h.
*/

#ifndef P4EST_USERDATA_GLOBAL_H
#define P4EST_USERDATA_GLOBAL_H

#include <sc_options.h>
#ifndef P4_TO_P8
#include <p4est_connectivity.h>
#include <p4est_geometry.h>
#else
#include <p8est_connectivity.h>
#include <p8est_geometry.h>
#define p4est_userdata_run p8est_userdata_run
#define p4est_userdata_global p8est_userdata_global
#define p4est_userdata_global_t p8est_userdata_global_t
#endif

/* we maintain application data in a global structure and pass it around */
typedef struct p4est_userdata_global
{
sc_MPI_Comm mpicomm;
sc_options_t *options;
int help;
int maxlevel;
const char *configuration;
p4est_connectivity_t *conn;
p4est_geometry_t *geom;
}
p4est_userdata_global_t;

/* this function contains the core of the demonstration program */
int p4est_userdata_run (p4est_userdata_global_t *g);

#endif /* !P4EST_USERDATA_GLOBAL_H */

0 comments on commit e4a4ab2

Please sign in to comment.