Skip to content

Commit

Permalink
Merge pull request #336 from scottaiton/feature_restart
Browse files Browse the repository at this point in the history
Feature restart
  • Loading branch information
scottaiton authored Jun 20, 2024
2 parents 0140f86 + 99d5f32 commit b423c13
Show file tree
Hide file tree
Showing 48 changed files with 3,799 additions and 1,282 deletions.
16 changes: 12 additions & 4 deletions applications/clawpack/advection/2d/swirl/swirl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ void run_program(fclaw_global_t* glob)
/* ---------------------------------------------------------------
Run
--------------------------------------------------------------- */
fclaw_initialize(glob);

fclaw_options_t *fclaw_opt = fclaw_get_options(glob);
if(fclaw_opt->restart)
{
fclaw_restart(glob);
}
else
{
fclaw_initialize(glob);
}

fclaw_run(glob);

fclaw_finalize(glob);
Expand Down Expand Up @@ -109,9 +119,7 @@ main (int argc, char **argv)
if (!vexit)
{
/* Create global structure which stores the domain, timers, etc */
int size, rank;
sc_MPI_Comm mpicomm = fclaw_app_get_mpi_size_rank (app, &size, &rank);
fclaw_global_t *glob = fclaw_global_new_comm (mpicomm, size, rank);
fclaw_global_t *glob = fclaw_global_new (app);

/* Store option packages in glob */
fclaw_options_store (glob, fclaw_opt);
Expand Down
41 changes: 0 additions & 41 deletions applications/clawpack/advection/2d/swirl/swirl_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,6 @@ swirl_destroy(user_options_t *user)
FCLAW_FREE (user);
}

static void
swirl_destroy_void(void *user)
{
swirl_destroy((user_options_t*) user);
}

static size_t
options_packsize(void* user)
{
return sizeof(user_options_t);
}

static size_t
options_pack(void* user, char* buffer)
{
user_options_t* opts = (user_options_t*) user;

//pack entire struct
return FCLAW_PACK(*opts, buffer);
}

static size_t
options_unpack(char* buffer, void** user)
{
user_options_t** opts_ptr = (user_options_t**) user;

*opts_ptr = FCLAW_ALLOC(user_options_t,1);

return FCLAW_UNPACK(buffer, *opts_ptr);
}

static fclaw_packing_vtable_t packing_vt =
{
options_pack,
options_unpack,
options_packsize,
swirl_destroy_void
};

/* ------- Generic option handling routines that call above routines ----- */
static void*
options_register (fclaw_app_t * app, void *package, sc_options_t * opt)
Expand Down Expand Up @@ -189,8 +150,6 @@ user_options_t* swirl_options_register (fclaw_app_t * app,

fclaw_app_set_attribute(app,"user",user);

fclaw_app_register_options_packing_vtable("user", &packing_vt);

return user;
}

Expand Down
17 changes: 13 additions & 4 deletions applications/clawpack/advection/3d/swirl/swirl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,18 @@ void run_program(fclaw_global_t* glob)
/* ---------------------------------------------------------------
Run
--------------------------------------------------------------- */
fclaw_initialize(glob);

fclaw_options_t *fclaw_opt = fclaw_get_options(glob);
if(fclaw_opt->restart)
{
fclaw_restart(glob);
}
else
{
fclaw_initialize(glob);
}


fclaw_run(glob);
fclaw_finalize(glob);
}
Expand Down Expand Up @@ -205,9 +216,7 @@ main (int argc, char **argv)
if (!vexit)
{
/* Options have been checked and are valid */
int size, rank;
sc_MPI_Comm mpicomm = fclaw_app_get_mpi_size_rank (app, &size, &rank);
fclaw_global_t *glob = fclaw_global_new_comm (mpicomm, size, rank);
fclaw_global_t *glob = fclaw_global_new(app);

/* Store option packages in glob */
fclaw_options_store (glob, fclaw_opt);
Expand Down
41 changes: 0 additions & 41 deletions applications/demo/2d/swirl_restart/swirl_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,6 @@ swirl_destroy(user_options_t *user)
FCLAW_FREE (user);
}

static void
swirl_destroy_void(void *user)
{
swirl_destroy((user_options_t*) user);
}

static size_t
options_packsize(void* user)
{
return sizeof(user_options_t);
}

static size_t
options_pack(void* user, char* buffer)
{
user_options_t* opts = (user_options_t*) user;

//pack entire struct
return FCLAW_PACK(*opts, buffer);
}

static size_t
options_unpack(char* buffer, void** user)
{
user_options_t** opts_ptr = (user_options_t**) user;

*opts_ptr = FCLAW_ALLOC(user_options_t,1);

return FCLAW_UNPACK(buffer, *opts_ptr);
}

static fclaw_packing_vtable_t packing_vt =
{
options_pack,
options_unpack,
options_packsize,
swirl_destroy_void
};

/* ------- Generic option handling routines that call above routines ----- */
static void*
options_register (fclaw_app_t * app, void *package, sc_options_t * opt)
Expand Down Expand Up @@ -189,8 +150,6 @@ user_options_t* swirl_options_register (fclaw_app_t * app,

fclaw_app_set_attribute(app,"user",user);

fclaw_app_register_options_packing_vtable("user", &packing_vt);

return user;
}

Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_library(forestclaw_c OBJECT
fclaw_physical_bc.c
fclaw_ghost_fill.c
fclaw_output.c
fclaw_restart.c
fclaw_run.c
fclaw_diagnostics.c
fclaw_rays.c
Expand All @@ -43,6 +44,8 @@ add_library(forestclaw_c OBJECT
fclaw_edge_neighbors.c
fclaw_face_neighbors.c
fclaw_farraybox.cpp
fclaw_file.c
fclaw_context.c
fclaw2d_convenience.c
fclaw2d_output_tikz.c
fclaw2d_file.c
Expand Down Expand Up @@ -112,6 +115,7 @@ install(FILES
fclaw_patch.h
fclaw_vtable.h
fclaw_output.h
fclaw_restart.h
fclaw_time_sync.h
fclaw_update_single_step.h
fclaw_physical_bc.h
Expand All @@ -129,6 +133,8 @@ install(FILES
fclaw_map_query.h
fclaw_map_query_defs.h
fclaw_diagnostics.h
fclaw_file.h
fclaw_context.h
forestclaw2d.h
fp_exception_glibc_extension.h
fclaw2d_convenience.h
Expand All @@ -155,6 +161,7 @@ if(BUILD_TESTING)
fclaw_options.h.TEST.cpp
fclaw_patch.h.TEST.cpp
fclaw_vtable.h.TEST.cpp
fclaw_context.h.TEST.cpp
)

target_link_libraries(forestclaw.TEST testutils forestclaw)
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ libforestclaw_installed_headers = \
src/fclaw_patch.h \
src/fclaw_vtable.h \
src/fclaw_output.h \
src/fclaw_restart.h \
src/fclaw_time_sync.h \
src/fclaw_update_single_step.h \
src/fclaw_physical_bc.h \
Expand All @@ -47,6 +48,8 @@ libforestclaw_installed_headers = \
src/fclaw_map_query.h \
src/fclaw_map_query_defs.h \
src/fclaw_diagnostics.h \
src/fclaw_file.h \
src/fclaw_context.h \
src/forestclaw2d.h \
src/fclaw2d_convenience.h \
src/fp_exception_glibc_extension.h \
Expand Down Expand Up @@ -92,6 +95,7 @@ libforestclaw_compiled_sources = \
src/fclaw_rays.c \
src/fclaw_ghost_fill.c \
src/fclaw_output.c \
src/fclaw_restart.c \
src/fclaw_run.c \
src/fclaw_diagnostics.c \
src/fclaw_update_single_step.c \
Expand All @@ -107,6 +111,8 @@ libforestclaw_compiled_sources = \
src/fclaw_edge_neighbors.c \
src/fclaw_face_neighbors.c \
src/fclaw_farraybox.cpp \
src/fclaw_file.c \
src/fclaw_context.c \
src/fclaw2d_convenience.c \
src/fclaw2d_output_tikz.c \
src/fclaw2d_file.c \
Expand Down Expand Up @@ -194,6 +200,7 @@ src_forestclaw_TEST_SOURCES = \
src/fclaw_global.h.TEST.cpp \
src/fclaw_options.h.TEST.cpp \
src/fclaw_patch.h.TEST.cpp \
src/fclaw_context.h.TEST.cpp \
src/fclaw_vtable.h.TEST.cpp

src_forestclaw_TEST_CPPFLAGS = \
Expand Down
1 change: 1 addition & 0 deletions src/fclaw2d_to_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define fclaw2d_match_wrap_cb fclaw3d_match_wrap_cb
#define fclaw2d_intersect_wrap_cb fclaw3d_intersect_wrap_cb
#define fclaw2d_interpolate_point_wrap_cb fclaw3d_interpolate_point_wrap_cb
#define fclaw2d_file_error_wrap fclaw3d_file_error_wrap

#endif /* !FCLAW2D_TO_3D_H */
60 changes: 60 additions & 0 deletions src/fclaw2d_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <forestclaw.h>
#include <fclaw_file.h>

#ifndef P4_TO_P8

#include <fclaw2d_wrap.h>
#include <fclaw2d_defs.h>
#include <fclaw2d_file.h>

#else

#include <fclaw3d_wrap.h>
#include <fclaw3d_defs.h>
#include <fclaw3d_file.h>

#endif

Expand Down Expand Up @@ -322,3 +325,60 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain_2d,

return retval;
}

int fclaw2d_file_error_wrap(int errcode)
{
switch(errcode)
{
case FCLAW2D_FILE_ERR_SUCCESS:
return FCLAW_FILE_ERR_SUCCESS;
case FCLAW2D_FILE_ERR_FILE:
return FCLAW_FILE_ERR_FILE;
case FCLAW2D_FILE_ERR_NOT_SAME:
return FCLAW_FILE_ERR_NOT_SAME;
case FCLAW2D_FILE_ERR_AMODE:
return FCLAW_FILE_ERR_AMODE;
case FCLAW2D_FILE_ERR_NO_SUCH_FILE:
return FCLAW_FILE_ERR_NO_SUCH_FILE;
case FCLAW2D_FILE_ERR_FILE_EXIST:
return FCLAW_FILE_ERR_FILE_EXIST;
case FCLAW2D_FILE_ERR_BAD_FILE:
return FCLAW_FILE_ERR_BAD_FILE;
case FCLAW2D_FILE_ERR_ACCESS:
return FCLAW_FILE_ERR_ACCESS;
case FCLAW2D_FILE_ERR_NO_SPACE:
return FCLAW_FILE_ERR_NO_SPACE;
case FCLAW2D_FILE_ERR_QUOTA:
return FCLAW_FILE_ERR_QUOTA;
case FCLAW2D_FILE_ERR_READ_ONLY:
return FCLAW_FILE_ERR_READ_ONLY;
case FCLAW2D_FILE_ERR_IN_USE:
return FCLAW_FILE_ERR_IN_USE;
case FCLAW2D_FILE_ERR_IO:
return FCLAW_FILE_ERR_IO;
case FCLAW2D_FILE_ERR_FORMAT:
return FCLAW_FILE_ERR_FORMAT;
case FCLAW2D_FILE_ERR_SECTION_TYPE:
return FCLAW_FILE_ERR_SECTION_TYPE;
case FCLAW2D_FILE_ERR_CONN:
return FCLAW_FILE_ERR_CONN;
case FCLAW2D_FILE_ERR_P4EST:
return FCLAW_FILE_ERR_P4EST;
case FCLAW2D_FILE_ERR_IN_DATA:
return FCLAW_FILE_ERR_IN_DATA;
case FCLAW2D_FILE_ERR_COUNT:
return FCLAW_FILE_ERR_COUNT;
case FCLAW2D_FILE_ERR_DIM:
return FCLAW_FILE_ERR_DIM;
case FCLAW2D_FILE_ERR_UNKNOWN:
return FCLAW_FILE_ERR_UNKNOWN;
case FCLAW2D_FILE_ERR_PART:
return FCLAW_FILE_ERR_PART;
case FCLAW2D_FILE_ERR_NOT_IMPLEMENTED:
return FCLAW_FILE_ERR_NOT_IMPLEMENTED;
case FCLAW2D_FILE_ERR_LASTCODE:
return FCLAW_FILE_ERR_LASTCODE;
default:
SC_ABORT_NOT_REACHED();
}
}
9 changes: 9 additions & 0 deletions src/fclaw2d_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain,
int blockno, int patchno,
void *point, void *user);

/**
* @brief Wrap get dimension independent domain from a 2d error code.
*
* @param errcode the 2d error code
* @return int the dimension independent error code
*/
int
fclaw2d_file_error_wrap(int errcode);

#ifdef __cplusplus
#if 0
{
Expand Down
9 changes: 9 additions & 0 deletions src/fclaw3d_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ fclaw3d_interpolate_point_wrap_cb (fclaw3d_domain_t * domain,
int blockno, int patchno,
void *point, void *user);

/**
* @brief Wrap get dimension independent domain from a 3d error code.
*
* @param errcode the 3d error code
* @return int the dimension independent error code
*/
int
fclaw3d_file_error_wrap(int errcode);

#ifdef __cplusplus
#if 0
{
Expand Down
Loading

0 comments on commit b423c13

Please sign in to comment.