// Destroys the given patch buffer. static void patch_buffer_free(patch_buffer_t* buffer) { polymec_free(buffer->patch_send_offsets); polymec_free(buffer->patch_receive_offsets); polymec_free(buffer->data); polymec_free(buffer); }
void gmls_functional_free(gmls_functional_t* functional) { if ((functional->context != NULL) && (functional->vtable.dtor != NULL)) functional->vtable.dtor(functional->context); polymec_free(functional->name); polymec_free(functional); }
static void polygon_free(void* ctx, void* dummy) { polygon_t* poly = ctx; polymec_free(poly->vertices); polymec_free(poly->ordering); poly->plane = NULL; }
static void mpi_message_free(mpi_message_t* msg) { if (msg->send_buffers != NULL) { for (int i = 0; i < msg->num_sends; ++i) { if (msg->send_buffers[i] != NULL) polymec_free(msg->send_buffers[i]); } polymec_free(msg->send_buffers); } if (msg->send_buffer_sizes != NULL) polymec_free(msg->send_buffer_sizes); if (msg->dest_procs != NULL) polymec_free(msg->dest_procs); if (msg->receive_buffers != NULL) { for (int i = 0; i < msg->num_receives; ++i) { if (msg->receive_buffers[i] != NULL) polymec_free(msg->receive_buffers[i]); } polymec_free(msg->receive_buffers); } if (msg->receive_buffer_sizes != NULL) polymec_free(msg->receive_buffer_sizes); if (msg->source_procs != NULL) polymec_free(msg->source_procs); if (msg->requests != NULL) polymec_free(msg->requests); polymec_free(msg); }
void polyhedron_integrator_free(polyhedron_integrator_t* integ) { polymec_free(integ->name); if ((integ->vtable.dtor != NULL) && (integ->context != NULL)) integ->vtable.dtor(integ->context); polymec_free(integ); }
static void bdm_dtor(void* context) { bdm_t* A = context; polymec_free(A->D); polymec_free(A->D_offsets); polymec_free(A->B_offsets); polymec_free(A); }
void str_grid_node_data_free(str_grid_node_data_t* node_data) { int_ptr_unordered_map_free(node_data->patches); polymec_free(node_data->patch_offsets); if (node_data->owns_buffer) polymec_free(node_data->buffer); polymec_free(node_data); }
void cpr_differencer_free(cpr_differencer_t* diff) { if ((diff->F_dtor != NULL) && (diff->F_context != NULL)) diff->F_dtor(diff->F_context); adj_graph_coloring_free(diff->coloring); adj_graph_free(diff->sparsity); polymec_free(diff->Jv); polymec_free(diff); }
void neighbor_pairing_free(neighbor_pairing_t* pairing) { polymec_free(pairing->name); polymec_free(pairing->pairs); if (pairing->weights != NULL) polymec_free(pairing->weights); exchanger_free(pairing->ex); polymec_free(pairing); }
void exchanger_free_metadata_receive_arrays(exchanger_t* ex, void** arrays) { #if POLYMEC_HAVE_MPI int num_arrays = exchanger_num_receives(ex); for (int i = 0; i < num_arrays; ++i) polymec_free(arrays[i]); polymec_free(arrays); #endif }
void str_grid_edge_data_free(str_grid_edge_data_t* edge_data) { int_ptr_unordered_map_free(edge_data->x_patches); int_ptr_unordered_map_free(edge_data->y_patches); int_ptr_unordered_map_free(edge_data->z_patches); polymec_free(edge_data->patch_offsets); if (edge_data->owns_buffer) polymec_free(edge_data->buffer); polymec_free(edge_data); }
static void exchanger_clear(exchanger_t* ex) { exchanger_map_clear(ex->send_map); exchanger_map_clear(ex->receive_map); polymec_free(ex->pending_msgs); polymec_free(ex->orig_buffers); polymec_free(ex->transfer_counts); ex->max_send = -1; ex->max_receive = -1; }
fe_mesh_t* fe_mesh_from_mesh(mesh_t* fv_mesh, string_array_t* element_block_tags) { fe_mesh_t* fe_mesh = fe_mesh_new(fv_mesh->comm, fv_mesh->num_nodes); if ((element_block_tags != NULL) && (element_block_tags->size > 1)) { // Block-by-block construction. for (int b = 0; b < element_block_tags->size; ++b) { char* tag_name = element_block_tags->data[b]; size_t num_elem; int* block_tag = mesh_tag(fv_mesh->cell_tags, tag_name, &num_elem); int* num_elem_faces = polymec_malloc(sizeof(int) * num_elem); int elem_faces_size = 0; for (int i = 0; i < num_elem; ++i) { int nef = fv_mesh->cell_face_offsets[block_tag[i]+1] - fv_mesh->cell_face_offsets[block_tag[i]]; num_elem_faces[i] = nef; elem_faces_size += nef; } int* elem_faces = polymec_malloc(sizeof(int) * elem_faces_size); int offset = 0; for (int i = 0; i < num_elem; ++i) { for (int f = 0; f < num_elem_faces[i]; ++f, ++offset) elem_faces[offset+f] = fv_mesh->cell_faces[fv_mesh->cell_face_offsets[block_tag[i]+f]]; } fe_block_t* block = polyhedral_fe_block_new((int)num_elem, num_elem_faces, fv_mesh->cell_faces); fe_mesh_add_block(fe_mesh, tag_name, block); polymec_free(num_elem_faces); polymec_free(elem_faces); } } else { // One honking block. int num_elem = fv_mesh->num_cells; int* num_elem_faces = polymec_malloc(sizeof(int) * num_elem); for (int i = 0; i < num_elem; ++i) num_elem_faces[i] = fv_mesh->cell_face_offsets[i+1] - fv_mesh->cell_face_offsets[i]; fe_block_t* block = polyhedral_fe_block_new(num_elem, num_elem_faces, fv_mesh->cell_faces); fe_mesh_add_block(fe_mesh, "block_1", block); polymec_free(num_elem_faces); } // Copy coordinates. memcpy(fe_mesh_node_positions(fe_mesh), fv_mesh->nodes, sizeof(point_t) * fv_mesh->num_nodes); return fe_mesh; }
void test_real_array6(void** state) { void* storage = polymec_malloc(sizeof(real_t)*2*2*2*2*2*2); DECLARE_6D_ARRAY(real_t, a, storage, 2, 2, 2, 2, 2, 2); for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) for (int l = 0; l < 2; ++l) for (int m = 0; m < 2; ++m) for (int n = 0; n < 2; ++n) a[i][j][k][l][m][n] = 32*i + 16*j + 8*k + 4*l + 2*m + n; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { for (int m = 0; m < 2; ++m) { for (int n = 0; n < 2; ++n) { assert_real_equal(32*i + 16*j + 8*k + 4*l + 2*m + n, a[i][j][k][l][m][n]); } } } } } } polymec_free(storage); }
void str_grid_cell_solver_free(str_grid_cell_solver_t* solver) { if ((solver->vtable.dtor != NULL) && (solver->context != NULL)) solver->vtable.dtor(solver->context); string_free(solver->name); polymec_free(solver); }
void str_grid_edge_data_set_buffer(str_grid_edge_data_t* edge_data, void* buffer, bool assume_control) { if ((edge_data->buffer != NULL) && edge_data->owns_buffer) polymec_free(edge_data->buffer); edge_data->buffer = buffer; edge_data->owns_buffer = assume_control; // Point the patches at the buffer. int pos = 0, l = 0, ip, jp, kp; str_grid_patch_t* patch; while (str_grid_edge_data_next_x_patch(edge_data, &pos, &ip, &jp, &kp, &patch, NULL)) { int patch_offset = edge_data->patch_offsets[l]; patch->data = &(((real_t*)buffer)[patch_offset]); ++l; } pos = 0; while (str_grid_edge_data_next_y_patch(edge_data, &pos, &ip, &jp, &kp, &patch, NULL)) { int patch_offset = edge_data->patch_offsets[l]; patch->data = &(((real_t*)buffer)[patch_offset]); ++l; } pos = 0; while (str_grid_edge_data_next_z_patch(edge_data, &pos, &ip, &jp, &kp, &patch, NULL)) { int patch_offset = edge_data->patch_offsets[l]; patch->data = &(((real_t*)buffer)[patch_offset]); ++l; } }
void test_int_array5(void** state) { void* storage = polymec_malloc(sizeof(int)*2*2*2*2*2); DECLARE_5D_ARRAY(int, a, storage, 2, 2, 2, 2, 2); for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) for (int l = 0; l < 2; ++l) for (int m = 0; m < 2; ++m) a[i][j][k][l][m] = 16*i + 8*j + 4*k + 2*l + m; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { for (int m = 0; m < 2; ++m) { assert_int_equal(16*i + 8*j + 4*k + 2*l + m, a[i][j][k][l][m]); } } } } } polymec_free(storage); }
void exchanger_free(exchanger_t* ex) { exchanger_clear(ex); exchanger_map_free(ex->send_map); exchanger_map_free(ex->receive_map); polymec_free(ex); }
// Destructor function -- called by garbage collector. static void div_free_poly_basis_free(void* ctx, void* dummy) { div_free_poly_basis_t* basis = ctx; for (int i = 0; i < basis->dim; ++i) basis->vectors[i].x = basis->vectors[i].y = basis->vectors[i].z = NULL; polymec_free(basis->vectors); }
static void euler_dtor(void* context) { euler_ode_t* integ = context; if (integ->f1 != NULL) polymec_free(integ->f1); if (integ->f2 != NULL) polymec_free(integ->f2); polymec_free(integ->x_new); polymec_free(integ->x_old); if (integ->newton != NULL) newton_solver_free(integ->newton); ptr_array_free(integ->observers); if ((integ->context != NULL) && (integ->dtor != NULL)) integ->dtor(integ->context); polymec_free(integ); }
static void st_func_free(void* ctx, void* dummy) { st_func_t* func = ctx; if ((func->vtable.dtor != NULL) && (func->context != NULL)) func->vtable.dtor(func->context); func->context = NULL; polymec_free(func->name); }
static void options_free(void* ctx, void* dummy) { options_t* opts = (options_t*)ctx; for (int i = 0; i < opts->num_args; ++i) polymec_free(opts->args[i]); polymec_free(opts->args); // Delete all parameter data. int pos = 0; char *key, *value; while (string_string_unordered_map_next(opts->params, &pos, &key, &value)) { polymec_free(key); polymec_free(value); } }
void fe_mesh_free(fe_mesh_t* mesh) { tagger_free(mesh->elem_sets); tagger_free(mesh->face_sets); tagger_free(mesh->edge_sets); tagger_free(mesh->node_sets); tagger_free(mesh->side_sets); if (mesh->face_nodes != NULL) { polymec_free(mesh->face_nodes); polymec_free(mesh->face_node_offsets); } ptr_array_free(mesh->blocks); string_array_free(mesh->block_names); int_array_free(mesh->block_elem_offsets); polymec_free(mesh->node_coords); polymec_free(mesh); }
void amr_grid_free(amr_grid_t* grid) { int_ptr_unordered_map_free(grid->pending_data); for (int n = 0; n < 6; ++n) { if (grid->neighbor_interpolators[n] != NULL) amr_grid_interpolator_free(grid->neighbor_interpolators[n]); } if (grid->coarse_interpolator != NULL) amr_grid_interpolator_free(grid->coarse_interpolator); if (grid->fine_interpolator != NULL) amr_grid_interpolator_free(grid->fine_interpolator); polymec_free(grid->patch_types); polymec_free(grid->remote_owners); if (grid->local_patch_indices != NULL) polymec_free(grid->local_patch_indices); if (grid->cell_ex != NULL) exchanger_free(grid->cell_ex); if (grid->x_face_ex != NULL) exchanger_free(grid->x_face_ex); if (grid->y_face_ex != NULL) exchanger_free(grid->y_face_ex); if (grid->z_face_ex != NULL) exchanger_free(grid->z_face_ex); if (grid->x_edge_ex != NULL) exchanger_free(grid->x_edge_ex); if (grid->y_edge_ex != NULL) exchanger_free(grid->y_edge_ex); if (grid->z_edge_ex != NULL) exchanger_free(grid->z_edge_ex); if (grid->node_ex != NULL) exchanger_free(grid->node_ex); for (int centering = 0; centering < 8; ++centering) ptr_array_free(grid->local_buffers[centering]); polymec_free(grid); }
static void mls_dtor(void* context) { mls_t* mls = context; mls->P = NULL; polymec_free(mls->basis); polymec_free(mls->basis_ddx); polymec_free(mls->basis_ddy); polymec_free(mls->basis_ddz); polymec_free(mls->xj); polymec_free(mls->hj); polymec_free(mls); }
mesh_t* create_uniform_mesh(MPI_Comm comm, int nx, int ny, int nz, bbox_t* bbox) { ASSERT(nx > 0); ASSERT(ny > 0); ASSERT(nz > 0); ASSERT(bbox != NULL); ASSERT(bbox->x2 > bbox->x1); ASSERT(bbox->y2 > bbox->y1); ASSERT(bbox->z2 > bbox->z1); // Grid spacings. real_t Lx = bbox->x2 - bbox->x1; real_t Ly = bbox->y2 - bbox->y1; real_t Lz = bbox->z2 - bbox->z1; real_t dx = Lx/nx, dy = Ly/ny, dz = Lz/nz; // Create a uniform rectilinear mesh! real_t* xs = polymec_malloc(sizeof(real_t) * (nx+1)); real_t* ys = polymec_malloc(sizeof(real_t) * (ny+1)); real_t* zs = polymec_malloc(sizeof(real_t) * (nz+1)); for (int i = 0; i <= nx; ++i) xs[i] = bbox->x1 + i*dx; for (int i = 0; i <= ny; ++i) ys[i] = bbox->y1 + i*dy; for (int i = 0; i <= nz; ++i) zs[i] = bbox->z1 + i*dz; mesh_t* mesh = create_rectilinear_mesh(comm, xs, nx+1, ys, ny+1, zs, nz+1); // Clean up. polymec_free(zs); polymec_free(ys); polymec_free(xs); return mesh; }
void exodus_file_close(exodus_file_t* file) { if (file->writing) { // Write a QA record. char* qa_record[1][4]; qa_record[0][0] = string_dup(polymec_executable_name()); qa_record[0][1] = string_dup(polymec_executable_name()); time_t invocation_time = polymec_invocation_time(); struct tm* time_data = localtime(&invocation_time); char date[20], instant[20]; snprintf(date, 19, "%02d/%02d/%02d", time_data->tm_mon, time_data->tm_mday, time_data->tm_year % 100); qa_record[0][2] = string_dup(date); snprintf(instant, 19, "%02d:%02d:%02d", time_data->tm_hour, time_data->tm_min, time_data->tm_sec % 60); qa_record[0][3] = string_dup(instant); ex_put_qa(file->ex_id, 1, qa_record); for (int i = 0; i < 4; ++i) string_free(qa_record[0][i]); } // Clean up. if (file->elem_block_ids != NULL) polymec_free(file->elem_block_ids); if (file->face_block_ids != NULL) polymec_free(file->face_block_ids); if (file->edge_block_ids != NULL) polymec_free(file->edge_block_ids); free_all_variable_names(file); #if POLYMEC_HAVE_MPI MPI_Info_free(&file->mpi_info); #endif ex_close(file->ex_id); }
void test_real_array2(void** state) { void* storage = polymec_malloc(sizeof(real_t)*10*10); DECLARE_2D_ARRAY(real_t, a, storage, 10, 10); for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) a[i][j] = 10*i + j; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { assert_real_equal(10*i+j, a[i][j]); } } polymec_free(storage); }
adj_graph_t* graph_from_point_cloud_and_neighbors(point_cloud_t* points, neighbor_pairing_t* neighbors) { // Create a graph whose vertices are the cloud's points. int rank, nproc; MPI_Comm_size(points->comm, &nproc); MPI_Comm_rank(points->comm, &rank); adj_graph_t* g = adj_graph_new(points->comm, points->num_points); // Allocate space in the graph for the edges (neighbors associating points). int num_points = points->num_points; int* num_edges = polymec_malloc(sizeof(int) * num_points); memset(num_edges, 0, sizeof(int) * num_points); int pos = 0, i, j; while (neighbor_pairing_next(neighbors, &pos, &i, &j, NULL)) { if (i < num_points) ++num_edges[i]; if (j < num_points) ++num_edges[j]; } for (int i = 0; i < num_points; ++i) adj_graph_set_num_edges(g, i, num_edges[i]); // Now fill in the edges. memset(num_edges, 0, sizeof(int) * num_points); pos = 0; while (neighbor_pairing_next(neighbors, &pos, &i, &j, NULL)) { if (i < num_points) { int* edges = adj_graph_edges(g, i); edges[num_edges[i]++] = j; } if (j < num_points) { int* edges = adj_graph_edges(g, j); edges[num_edges[j]++] = i; } } // Clean up. polymec_free(num_edges); return g; }
static void supermatrix_free(SuperMatrix* matrix) { switch(matrix->Stype) { case SLU_DN: Destroy_Dense_Matrix(matrix); break; case SLU_NR: Destroy_CompRow_Matrix(matrix); break; case SLU_NC: Destroy_CompCol_Matrix(matrix); break; default: printf("ERROR: unknown matrix type passed to supermatrix_free!"); break; } polymec_free(matrix); }