Skip to content

Commit

Permalink
Merge pull request #298 from scottaiton/feature-patch-threshold-api-n…
Browse files Browse the repository at this point in the history
…ew-semantic

Add patch threshold to api and add user option
  • Loading branch information
scottaiton authored Jan 18, 2024
2 parents 1c18e4e + 1a8cb4f commit e905560
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/patches/clawpatch/fclaw2d_clawpatch_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ clawpatch_register(fclaw2d_clawpatch_options_t *clawpatch_options,
&clawpatch_options->save_aux,0,
"Save aux variables when re-taking a time step [F]");

/* ---------------------- vtk options -------------------------- */
sc_options_add_int(opt, 0, "vtk-patch-threshold",
&clawpatch_options->vtk_patch_threshold, 0,
"Number of patches to buffer before each write in vtk output. 0 means buffer all patches before writing [0]");

/* Set verbosity level for reporting timing */
sc_keyvalue_t *kv = clawpatch_options->kv_refinement_criteria = kv_refinement_criterea_new();
sc_options_add_keyvalue (opt, 0, "refinement-criteria",
Expand Down Expand Up @@ -159,6 +164,13 @@ clawpatch_check(fclaw2d_clawpatch_options_t *clawpatch_opt)
return FCLAW_EXIT_ERROR;
}

if (clawpatch_opt->vtk_patch_threshold < 0)
{
fclaw_global_essentialf("Clawpatch error : vtk-patch-threshold must be " \
"non-negative.\n");
return FCLAW_EXIT_ERROR;
}

return FCLAW_NOEXIT;
}

Expand Down
2 changes: 2 additions & 0 deletions src/patches/clawpatch/fclaw2d_clawpatch_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ struct fclaw2d_clawpatch_options
int save_aux; /**< Save the aux array when retaking a time step */


int vtk_patch_threshold; /**< The buffer threshold for vtk output */

int is_registered; /**< true if options have been registered */

};
Expand Down
20 changes: 12 additions & 8 deletions src/patches/clawpatch/fclaw2d_clawpatch_output_vtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fclaw2d_vtk_write_header (fclaw2d_domain_t * domain, fclaw2d_vtk_state_t * s)
*
* This function assumes that the buffer consists of patch data of the size
* \b psize_field. This means it must hold
* \b s->sink->buffer_bytes % \b s->sink->buffer_bytes == 0.
* \b s->sink->buffer_bytes % \b psize_field == 0.
*
* \param [in,out] s The VTK state.
* \param [in] psize_field The number of bytes, which are intended to
Expand All @@ -232,7 +232,7 @@ fclaw2d_vtk_write_header (fclaw2d_domain_t * domain, fclaw2d_vtk_state_t * s)
* stored in the buffer + 1 is greater than
* \b threshold, the buffer is flushed to disk.
* Then the new patch is added to the buffer.
* -1 means that there is no threshold and
* 0 means that there is no threshold and
* the data just added to \b s->sink.
*/
static void
Expand Down Expand Up @@ -723,10 +723,13 @@ fclaw2d_vtk_write_file (fclaw2d_global_t * glob, const char *basename,
int meqn,
double vtkspace, int vtkwrite,
fclaw2d_vtk_patch_data_t coordinate_cb,
fclaw2d_vtk_patch_data_t value_cb)
fclaw2d_vtk_patch_data_t value_cb,
int patch_threshold)
{
fclaw2d_domain_t *domain = glob->domain;

FCLAW_ASSERT (patch_threshold >= 0);

int retval, gretval;
int mpiret;
fclaw2d_vtk_state_t ps, *s = &ps;
Expand Down Expand Up @@ -788,10 +791,8 @@ fclaw2d_vtk_write_file (fclaw2d_global_t * glob, const char *basename,

s->buf = NULL;
s->sink = NULL;
/* The threshold may be adjusted; see the documentation of
* fclaw2d_vtk_state_t for further information.
*/
s->patch_threshold = 0;
/* See the documentation of fclaw2d_vtk_state_t for further information. */
s->patch_threshold = patch_threshold;
s->num_buffered_patches = 0;

/* write header meta data and check for error */
Expand Down Expand Up @@ -1018,6 +1019,9 @@ void fclaw2d_clawpatch_output_vtk (fclaw2d_global_t * glob, int iframe)
char basename[BUFSIZ];
snprintf (basename, BUFSIZ, "%s_frame_%04d", fclaw_opt->prefix, iframe);

/* The last parameter of the call of fclaw2d_vtk_write_file can be replaced
* by a value from flcaw_opt or clawpatch_opt.
*/
(void) fclaw2d_vtk_write_file (glob, basename,
clawpatch_opt->mx, clawpatch_opt->my,
#if PATCH_DIM == 3
Expand All @@ -1026,7 +1030,7 @@ void fclaw2d_clawpatch_output_vtk (fclaw2d_global_t * glob, int iframe)
clawpatch_opt->meqn,
fclaw_opt->vtkspace, 0,
fclaw2d_output_vtk_coordinate_cb,
fclaw2d_output_vtk_value_cb);
fclaw2d_output_vtk_value_cb, clawpatch_opt->vtk_patch_threshold);
}


6 changes: 5 additions & 1 deletion src/patches/clawpatch/fclaw2d_clawpatch_output_vtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef void (*fclaw2d_vtk_patch_data_t) (struct fclaw2d_global * glob,
* 1 for MPI_File_write (less memory usage).
* @param[in] coordniate_cb the callback to write a patch's coordinate binary data
* @param[in] value_cb the callback to write a patch's value binary data
* @param[in] patch_threshold The maximal number of buffered patches.
* 0 means that an unlimited number of patches is
* buffered and flushed to disk at the end.
* @return 0 if successful, negative otherwise.
* Collective with identical value on all ranks.
*/
Expand All @@ -85,7 +88,8 @@ fclaw2d_vtk_write_file (struct fclaw2d_global * glob, const char *basename,
int meqn,
double vtkspace, int vtkwrite,
fclaw2d_vtk_patch_data_t coordinate_cb,
fclaw2d_vtk_patch_data_t value_cb);
fclaw2d_vtk_patch_data_t value_cb,
int patch_threshold);

/**
* @brief Output vtu file
Expand Down
2 changes: 2 additions & 0 deletions src/patches/clawpatch/fclaw3dx_clawpatch_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ struct fclaw3dx_clawpatch_options
int ghost_patch_pack_aux; /**< True if aux equations should be packed */
int save_aux; /**< Save the aux array when retaking a time step */

int vtk_patch_threshold; /**< The buffer threshold for vtk output */

int is_registered; /**< true if options have been registered */

};
Expand Down
6 changes: 5 additions & 1 deletion src/patches/clawpatch/fclaw3dx_clawpatch_output_vtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef void (*fclaw3dx_vtk_patch_data_t) (struct fclaw2d_global * glob,
* 1 for MPI_File_write (less memory usage).
* @param[in] coordniate_cb the callback to write a patch's coordinate binary data
* @param[in] value_cb the callback to write a patch's value binary data
* @param[in] patch_threshold The maximal number of buffered patches.
* 0 means that an unlimited number of patches is
* buffered and flushed to disk at the end.
* @return 0 if successful, negative otherwise.
* Collective with identical value on all ranks.
*/
Expand All @@ -82,7 +85,8 @@ fclaw3dx_vtk_write_file (struct fclaw2d_global * glob, const char *basename,
int meqn,
double vtkspace, int vtkwrite,
fclaw3dx_vtk_patch_data_t coordinate_cb,
fclaw3dx_vtk_patch_data_t value_cb);
fclaw3dx_vtk_patch_data_t value_cb,
int patch_threshold);

/**
* @brief Output vtu file
Expand Down

0 comments on commit e905560

Please sign in to comment.