Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change storage of options and vtables #344

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/fclaw_diagnostics.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <fclaw_options.h>

#include <fclaw_gauges.h>
#include <fclaw_pointer_map.h>

static
fclaw_diagnostics_vtable_t* diagnostics_vt_new()
Expand All @@ -56,7 +55,7 @@ void diagnostics_accumulator_destroy(void* acc)
fclaw_diagnostics_vtable_t* fclaw_diagnostics_vt(fclaw_global_t* glob)
{
fclaw_diagnostics_vtable_t* diagnostics_vt = (fclaw_diagnostics_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw2d_diagnostics");
fclaw_global_get_vtable(glob, "fclaw2d_diagnostics");
FCLAW_ASSERT(diagnostics_vt != NULL);
FCLAW_ASSERT(diagnostics_vt->is_set != 0);
return diagnostics_vt;
Expand Down Expand Up @@ -97,8 +96,7 @@ void fclaw_diagnostics_vtable_initialize(fclaw_global_t* glob)

diag_vt->is_set = 1;

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw2d_diagnostics") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw2d_diagnostics", diag_vt, diagnostics_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw2d_diagnostics", diag_vt, diagnostics_vt_destroy);
}


Expand Down
6 changes: 3 additions & 3 deletions src/fclaw_diagnostics.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ TEST_CASE("fclaw_diagnostics_vtable_initialize sets is_set flag")

#ifdef FCLAW_ENABLE_DEBUG

TEST_CASE("fclaw_diagnostics_vtable_initialize fails if called twice on a glob")
TEST_CASE("fclaw_diagnostics_vtable_initialize called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_diagnostics_vtable_initialize(glob1);
CHECK_SC_ABORTED(fclaw_diagnostics_vtable_initialize(glob1));
fclaw_diagnostics_vtable_initialize(glob1);
fclaw_diagnostics_vtable_initialize(glob2);
fclaw_diagnostics_vtable_initialize(glob2);
CHECK_SC_ABORTED(fclaw_diagnostics_vtable_initialize(glob2));

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
Expand Down
7 changes: 2 additions & 5 deletions src/fclaw_elliptic_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <fclaw_pointer_map.h>

#include <fclaw_elliptic_solver.h>
#include <fclaw_global.h>

Expand Down Expand Up @@ -142,16 +140,15 @@ void fclaw_elliptic_vtable_initialize(fclaw_global_t* glob)
/* User should set the setup, rhs and solve routines */
elliptic_vt->is_set = 1;

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw2d_elliptic") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw2d_elliptic", elliptic_vt, elliptic_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw2d_elliptic", elliptic_vt, elliptic_vt_destroy);
}

/*----------------------------------- Access functions -------------------------------- */

fclaw_elliptic_vtable_t* fclaw_elliptic_vt(fclaw_global_t* glob)
{
fclaw_elliptic_vtable_t* elliptic_vt = (fclaw_elliptic_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw2d_elliptic");
fclaw_global_get_vtable(glob, "fclaw2d_elliptic");
FCLAW_ASSERT(elliptic_vt != NULL);
FCLAW_ASSERT(elliptic_vt->is_set != 0);
return elliptic_vt;
Expand Down
6 changes: 3 additions & 3 deletions src/fclaw_elliptic_solver.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ TEST_CASE("fclaw_elliptic_vtable_initialize sets is_set flag")

#ifdef FCLAW_ENABLE_DEBUG

TEST_CASE("fclaw_elliptic_vtable_initialize fails if called twice on a glob")
TEST_CASE("fclaw_elliptic_vtable_initialize called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_elliptic_vtable_initialize(glob1);
CHECK_SC_ABORTED(fclaw_elliptic_vtable_initialize(glob1));
fclaw_elliptic_vtable_initialize(glob1);
fclaw_elliptic_vtable_initialize(glob2);
fclaw_elliptic_vtable_initialize(glob2);
CHECK_SC_ABORTED(fclaw_elliptic_vtable_initialize(glob2));

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
Expand Down
7 changes: 2 additions & 5 deletions src/fclaw_gauges.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <fclaw_gauges.h>

#include <fclaw_pointer_map.h>

#include <fclaw_options.h>
#include <fclaw_global.h>
#include <fclaw_convenience.h> /* Needed to get search function for gauges */
Expand Down Expand Up @@ -459,7 +457,7 @@ void fclaw_gauges_vt_destroy(void* vt)
fclaw_gauges_vtable_t* fclaw_gauges_vt(fclaw_global_t* glob)
{
fclaw_gauges_vtable_t* gauges_vt = (fclaw_gauges_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw_gauges");
fclaw_global_get_vtable(glob, "fclaw_gauges");
FCLAW_ASSERT(gauges_vt != NULL);
FCLAW_ASSERT(gauges_vt->is_set != 0);

Expand All @@ -478,8 +476,7 @@ void fclaw_gauges_vtable_initialize(fclaw_global_t* glob)

gauges_vt->is_set = 1;

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw_gauges") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw_gauges", gauges_vt, fclaw_gauges_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw_gauges", gauges_vt, fclaw_gauges_vt_destroy);
}
/* ---------------------------- Virtualized Functions --------------------------------- */

Expand Down
6 changes: 3 additions & 3 deletions src/fclaw_gauges.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ TEST_CASE("fclaw_gauges_vtable_initialize sets is_set flag")

#ifdef FCLAW_ENABLE_DEBUG

TEST_CASE("fclaw_guages_vtable_initialize fails if called twice on a glob")
TEST_CASE("fclaw_guages_vtable_initialize called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_diagnostics_vtable_initialize(glob1);
fclaw_gauges_vtable_initialize(glob1);
CHECK_SC_ABORTED(fclaw_gauges_vtable_initialize(glob1));
fclaw_gauges_vtable_initialize(glob1);

fclaw_diagnostics_vtable_initialize(glob2);
fclaw_gauges_vtable_initialize(glob2);
CHECK_SC_ABORTED(fclaw_gauges_vtable_initialize(glob2));
fclaw_gauges_vtable_initialize(glob2);

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
Expand Down
1 change: 0 additions & 1 deletion src/fclaw_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ void fclaw_global_iterate_partitioned (fclaw_global_t * glob,
void fclaw_global_options_store (fclaw_global_t* glob, const char* key, void* options)
{

FCLAW_ASSERT(fclaw_pointer_map_get(glob->options,key) == NULL);
fclaw_pointer_map_insert(glob->options, key, options, NULL);
}

Expand Down
7 changes: 4 additions & 3 deletions src/fclaw_global.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") {
const char** retrieved_option2 = static_cast<const char**>(fclaw_global_get_options(glob, key2));
CHECK_EQ(retrieved_option2, &option2);

#ifdef FCLAW_ENABLE_DEBUG
// TEST inserting twice
CHECK_SC_ABORTED(fclaw_global_options_store(glob, key2, &option2));
#endif
const char* option3 = "Test string 2";
fclaw_global_options_store(glob, key2, &option3);
CHECK_EQ(fclaw_global_get_options(glob, key2), &option3);

// Test with a non-existing key
const char* key3 = "non-existing key";
#ifdef FCLAW_ENABLE_DEBUG
Expand Down
20 changes: 15 additions & 5 deletions src/fclaw_options.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,29 @@ TEST_CASE("fclaw_get_options fails if not intialized")
fclaw_global_destroy(glob2);
}

TEST_CASE("fclaw_options_store fails if called twice on a glob")
TEST_CASE("fclaw_options_store called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_options_t,1));
CHECK_SC_ABORTED(fclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_options_t,1)));
fclaw_options_t *opts1_1 = FCLAW_ALLOC_ZERO(fclaw_options_t,1);
fclaw_options_t *opts1_2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1);
fclaw_options_store(glob1, opts1_1);
fclaw_options_store(glob1, opts1_2);
CHECK_EQ(fclaw_get_options(glob1), opts1_2);

fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1));
CHECK_SC_ABORTED(fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)));
fclaw_options_t *opts2_1 = FCLAW_ALLOC_ZERO(fclaw_options_t,1);
fclaw_options_t *opts2_2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1);
fclaw_options_store(glob2, opts2_1);
fclaw_options_store(glob2, opts2_2);
CHECK_EQ(fclaw_get_options(glob2), opts2_2);

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
FCLAW_FREE(opts1_1);
FCLAW_FREE(opts1_2);
FCLAW_FREE(opts2_1);
FCLAW_FREE(opts2_2);
}

#endif
7 changes: 2 additions & 5 deletions src/fclaw_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <fclaw_pointer_map.h>

#include <fclaw_patch.h>
#include <fclaw_global.h>
#include <fclaw_domain.h>
Expand Down Expand Up @@ -915,16 +913,15 @@ void fclaw_patch_vtable_initialize(fclaw_global_t* glob)

patch_vt->is_set = 1;

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw2d_patch") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw2d_patch", patch_vt, patch_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw2d_patch", patch_vt, patch_vt_destroy);
}

/* ------------------------------ User access functions ------------------------------- */

fclaw_patch_vtable_t* fclaw_patch_vt(fclaw_global_t* glob)
{
fclaw_patch_vtable_t* patch_vt = (fclaw_patch_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw2d_patch");
fclaw_global_get_vtable(glob, "fclaw2d_patch");
FCLAW_ASSERT(patch_vt != NULL);
FCLAW_ASSERT(patch_vt->is_set != 0);
return patch_vt;
Expand Down
6 changes: 3 additions & 3 deletions src/fclaw_patch.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ TEST_CASE("fclaw_patch_vtable_initialize sets is_set flag")

#ifdef FCLAW_ENABLE_DEBUG

TEST_CASE("fclaw_patch_vtable_initialize fails if called twice on a glob")
TEST_CASE("fclaw_patch_vtable_initialize called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_patch_vtable_initialize(glob1);
CHECK_SC_ABORTED(fclaw_patch_vtable_initialize(glob1));
fclaw_patch_vtable_initialize(glob1);
fclaw_patch_vtable_initialize(glob2);
fclaw_patch_vtable_initialize(glob2);
CHECK_SC_ABORTED(fclaw_patch_vtable_initialize(glob2));

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
Expand Down
7 changes: 2 additions & 5 deletions src/fclaw_rays.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <fclaw_convenience.h>

#include <fclaw_pointer_map.h>


//static fclaw2d_ray_vtable_t s_ray_vt;

Expand Down Expand Up @@ -311,8 +309,7 @@ void fclaw_ray_vtable_initialize(fclaw_global_t *glob)

fclaw_ray_vtable_t* rays_vt = fclaw2d_ray_vt_new();

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw2d_rays") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw2d_rays", rays_vt, fclaw2d_ray_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw2d_rays", rays_vt, fclaw2d_ray_vt_destroy);

rays_vt->is_set = 1;
}
Expand All @@ -324,7 +321,7 @@ void fclaw_ray_vtable_initialize(fclaw_global_t *glob)
fclaw_ray_vtable_t* fclaw_ray_vt(fclaw_global_t* glob)
{
fclaw_ray_vtable_t* ray_vt = (fclaw_ray_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw2d_rays");
fclaw_global_get_vtable(glob, "fclaw2d_rays");
FCLAW_ASSERT(ray_vt != NULL);
FCLAW_ASSERT(ray_vt->is_set != 0);
return ray_vt;
Expand Down
6 changes: 2 additions & 4 deletions src/fclaw_vtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <fclaw_pointer_map.h>
#include <fclaw_vtable.h>
#include <fclaw_output.h>
#include <fclaw_global.h>
Expand All @@ -45,7 +44,7 @@ void vt_destroy(void* vt)
fclaw_vtable_t* fclaw_vt(fclaw_global_t *glob)
{
fclaw_vtable_t* vt = (fclaw_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw2d");
fclaw_global_get_vtable(glob, "fclaw2d");
FCLAW_ASSERT(vt != NULL);
FCLAW_ASSERT(vt->is_set != 0);
return vt;
Expand All @@ -69,6 +68,5 @@ void fclaw_vtable_initialize(fclaw_global_t *glob)

vt->is_set = 1;

FCLAW_ASSERT(fclaw_pointer_map_get(glob->vtables,"fclaw2d") == NULL);
fclaw_pointer_map_insert(glob->vtables, "fclaw2d", vt, vt_destroy);
fclaw_global_vtable_store(glob, "fclaw2d", vt, vt_destroy);
}
6 changes: 3 additions & 3 deletions src/fclaw_vtable.h.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ TEST_CASE("fclaw_vtable_initialize sets is_set flag")

#ifdef FCLAW_ENABLE_DEBUG

TEST_CASE("fclaw_vtable_initialize fails if called twice on a glob")
TEST_CASE("fclaw_vtable_initialize called twice on a glob")
{
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;

fclaw_vtable_initialize(glob1);
CHECK_SC_ABORTED(fclaw_vtable_initialize(glob1));
fclaw_vtable_initialize(glob1);
fclaw_vtable_initialize(glob2);
fclaw_vtable_initialize(glob2);
CHECK_SC_ABORTED(fclaw_vtable_initialize(glob2));

fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
Expand Down
11 changes: 2 additions & 9 deletions src/patches/clawpatch/fclaw_clawpatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <fclaw_map_query.h>

#include <fclaw_pointer_map.h>



/* ------------------------------- Static function defs ------------------------------- */
Expand Down Expand Up @@ -1952,12 +1950,7 @@ void fclaw_clawpatch_vtable_initialize(fclaw_global_t* glob,

clawpatch_vt->is_set = 1;

if(fclaw_pointer_map_get(glob->vtables, "fclaw_clawpatch") != NULL)
{
fclaw_abortf("fclaw_clawpatch_vtable_initialize : " \
"fclaw_clawpatch already initialized\n");
}
fclaw_pointer_map_insert(glob->vtables, "fclaw_clawpatch", clawpatch_vt, clawpatch_vt_destroy);
fclaw_global_vtable_store(glob, "fclaw_clawpatch", clawpatch_vt, clawpatch_vt_destroy);
}

/* ------------------------------- Public access functions ---------------------------- */
Expand All @@ -1975,7 +1968,7 @@ fclaw_clawpatch_vtable_t* fclaw_clawpatch_vt(fclaw_global_t* glob)
{

fclaw_clawpatch_vtable_t* clawpatch_vt = (fclaw_clawpatch_vtable_t*)
fclaw_pointer_map_get(glob->vtables, "fclaw_clawpatch");
fclaw_global_get_vtable(glob, "fclaw_clawpatch");
FCLAW_ASSERT(clawpatch_vt != nullptr);
FCLAW_ASSERT(clawpatch_vt->is_set != 0);
return clawpatch_vt;
Expand Down
12 changes: 6 additions & 6 deletions src/patches/clawpatch/fclaw_clawpatch.h.2d.TEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TEST_CASE("3dx fclaw_clawpatch_vtable_initialize sets is_set flag")



TEST_CASE("2d fclaw_clawpatch_vtable_initialize fails if called twice on a glob")
TEST_CASE("2d fclaw_clawpatch_vtable_initialize called twice on a glob")
{
fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1);
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
Expand All @@ -140,17 +140,17 @@ TEST_CASE("2d fclaw_clawpatch_vtable_initialize fails if called twice on a glob"
fclaw_vtables_initialize(glob2);

fclaw_clawpatch_vtable_initialize(glob1,4);
CHECK_SC_ABORTED(fclaw_clawpatch_vtable_initialize(glob1,4));
fclaw_clawpatch_vtable_initialize(glob1,4);
fclaw_clawpatch_vtable_initialize(glob2,4);
fclaw_clawpatch_vtable_initialize(glob2,4);
CHECK_SC_ABORTED(fclaw_clawpatch_vtable_initialize(glob2,4));

fclaw_clawpatch_options_destroy(opts);
fclaw_domain_destroy(domain);
fclaw_global_destroy(glob1);
fclaw_global_destroy(glob2);
}

TEST_CASE("3dx fclaw_clawpatch_vtable_initialize fails if called twice on a glob")
TEST_CASE("3dx fclaw_clawpatch_vtable_initialize called twice on a glob")
{
fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1);
fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);;
Expand All @@ -166,9 +166,9 @@ TEST_CASE("3dx fclaw_clawpatch_vtable_initialize fails if called twice on a glob
fclaw_vtables_initialize(glob2);

fclaw_clawpatch_vtable_initialize(glob1,4);
CHECK_SC_ABORTED(fclaw_clawpatch_vtable_initialize(glob1,4));
fclaw_clawpatch_vtable_initialize(glob1,4);
fclaw_clawpatch_vtable_initialize(glob2,4);
fclaw_clawpatch_vtable_initialize(glob2,4);
CHECK_SC_ABORTED(fclaw_clawpatch_vtable_initialize(glob2,4));

fclaw_clawpatch_options_destroy(opts);
fclaw_domain_destroy(domain);
Expand Down
Loading
Loading