/* * test for GCRM - there will be two sets of polygons, * one will be interface and the other will be layers * each polygon will have 6 vertices. For the vertices * in the layers, we will also create edges, because * we need to tag the edges in layers. * In this example we will create 13*3 vertices, first 13 vertices * will be used to create 3 polygons (interface) and 13 edges, * and then next vertices will be used to create 3 polygon at layer. * Then last 13 vertices will be used to create 3 poylgons and 13 edges. * * Each polygon at interface will be tagged with cell-centered variable * Each vertex at layer will be tagged with corner variables * Each edge at an interface will be tagged with edge-centered variable. */ #include #include #include #include "mpi.h" #include "damsel.h" #define FILENAME "output/gcrm.h5" damsel_handle *define_grid_dim_tags(); int main(int argc, char **argv) { #ifndef DAMSEL_SINGLETHREAD int res; #endif short int vertex_data_layer[13]; short int edge_data_interface[26]; short int cell_data_interface[6]; damsel_handle connectivity_interface[] = { 0, 1, 2, 3, 4, 5, // polygon 1 4, 5, 6, 7, 8, 9, // polygon 2 3, 4, 9, 10, 11, 12, // polygon 3 13, 14, 15, 16, 17, 18, 17, 18, 19, 20, 21, 22, 16, 17, 22, 23, 24, 25 }; damsel_handle connectivity_layer[] = { 40, 41, 42, 43, 44, 45, // polygon 1 at layers 44, 45, 46, 47, 48, 49, // polygon 2 ... 43, 44, 49, 50, 51, 52, // polygon 3 ... }; printf("%s\n", argv[0]); #ifndef DAMSEL_SINGLETHREAD MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &res); assert(res == MPI_THREAD_MULTIPLE); #else MPI_Init(&argc, &argv); #endif damsel_library lib; damsel_err_t err = DMSLlib_init(&lib); damsel_model model; err = DMSLmodel_create(DAMSEL_HANDLE_TYPE_HANDLE64, &model); assert(model != NULL); int i; for(i =0; i< 26; i++) { if(i < 13) vertex_data_layer[i] = 900+i; edge_data_interface[i] = 800 + i; if(i < 6) cell_data_interface[i] = 500+i; } damsel_handle vertex_data_tag_handle = 1000; DMSLtag_define(model, &vertex_data_tag_handle, DAMSEL_DATA_TYPE_SHORTINT, "corner_variables"); damsel_handle edge_data_tag_handle = 1001; DMSLtag_define(model, &edge_data_tag_handle, DAMSEL_DATA_TYPE_SHORTINT, "edge_centered_variables"); damsel_handle cell_data_tag_handle = 1002; DMSLtag_define(model, &cell_data_tag_handle, DAMSEL_DATA_TYPE_SHORTINT, "cell_centered_variables"); /* we'll create a sequence handle container with 6 handles in it, and call it interface. */ damsel_container vertex_interface_handles_container_id; err = DMSLcontainer_create_sequence(model, 0, 26, 1, &vertex_interface_handles_container_id); damsel_container edge_interface_handles_container_id; err = DMSLcontainer_create_sequence(model, 200, 26, 1, &edge_interface_handles_container_id); damsel_container vertex_layer_handles_container_id; err = DMSLcontainer_create_sequence(model, 40, 13, 1, &vertex_layer_handles_container_id); damsel_container polyInterface_handles_container_id; err = DMSLcontainer_create_sequence(model, 100, 6, 1, &polyInterface_handles_container_id); damsel_container polyLayer_handles_container_id; err = DMSLcontainer_create_sequence(model, 110, 3, 1, &polyLayer_handles_container_id); /* now set the values of the somedata tag on the handles */ // DMSLmodel_map_tag(vertex_data, vertex_handles_container_id, &vertex_data_tag_handle); DMSLentity_define_fast(edge_interface_handles_container_id, DAMSEL_ENTITY_TYPE_EDGE, 2, connectivity_interface); DMSLentity_define_fast(polyInterface_handles_container_id, DAMSEL_ENTITY_TYPE_POLYGON, 6, connectivity_interface); DMSLentity_define_fast(polyLayer_handles_container_id, DAMSEL_ENTITY_TYPE_POLYGON, 6, connectivity_layer); DMSLmodel_map_tag(vertex_data_layer, vertex_layer_handles_container_id, &vertex_data_tag_handle); DMSLmodel_map_tag(edge_data_interface, edge_interface_handles_container_id, &edge_data_tag_handle); DMSLmodel_map_tag(cell_data_interface, polyInterface_handles_container_id, &cell_data_tag_handle); /* at this point, the in-memory store knows about all the data that we have. next we will write the data out to disk. we need to invent some handles for the file store too. They can overlap with memstore handles, though here I make sure that they do not. */ unlink(FILENAME); // maybe it doesn't exist, so we'll just silently ignore any error damsel_trait_bundle tb; err = DMSLtrait_create(&tb); DMSLtrait_put(tb, "mode", "WRITE"); DMSLmodel_attach(model, FILENAME, MPI_COMM_WORLD, tb); DMSLtrait_release(tb); DMSLmodel_map_handles_inventing_file_handles(vertex_interface_handles_container_id); DMSLmodel_map_handles_inventing_file_handles(edge_interface_handles_container_id); DMSLmodel_map_handles_inventing_file_handles(vertex_layer_handles_container_id); DMSLmodel_map_handles_inventing_file_handles(polyInterface_handles_container_id); DMSLmodel_map_handles_inventing_file_handles(polyLayer_handles_container_id); /* we also need to map the handles for the tags which contain values that we want to store. This happens by creating a container containing the tag to map, and mapping that into the file store. */ DMSLmodel_map_single_handle_inventing_file_handle(model, vertex_data_tag_handle); DMSLmodel_map_single_handle_inventing_file_handle(model, edge_data_tag_handle); DMSLmodel_map_single_handle_inventing_file_handle(model, cell_data_tag_handle); /* Now we can tell damsel to execute everything. */ damsel_request_t req; DMSLmodel_transfer_async(model, DAMSEL_TRANSFER_TYPE_WRITE, &req); damsel_status_t status; DMSLmodel_wait(req, &status); DMSLmodel_close(model); model=NULL; DMSLcontainer_close(vertex_interface_handles_container_id); vertex_interface_handles_container_id=NULL; DMSLcontainer_close(vertex_layer_handles_container_id); vertex_layer_handles_container_id=NULL; DMSLcontainer_close(polyInterface_handles_container_id); polyInterface_handles_container_id=NULL; DMSLcontainer_close(edge_interface_handles_container_id); edge_interface_handles_container_id=NULL; DMSLcontainer_close(polyLayer_handles_container_id); polyLayer_handles_container_id=NULL; DMSLlib_finalize(lib); lib=NULL; MPI_Finalize(); return 0; }