📄 cptc_free_geomsh.c
字号:
/*
// ------------------------------------------------------------------
// freegeo.c
//
// This file contains the function for deleting a geo.
// ------------------------------------------------------------------
// Author: Stephen A. Vavasis
// Copyright (c) 1998 by Cornell University. All rights reserved.
//
// See the accompanying file 'Copyright' for authorship information,
// the terms of the license governing this software, and disclaimers
// concerning this software.
// ------------------------------------------------------------------
// This file is part of the QMG software.
// Version 2.0 of QMG, release date RELDATE.
// ------------------------------------------------------------------
*/
#include <stdlib.h>
#include "GeoFmt.h"
#include "MshFmt.h"
#include <string.h>
#ifdef USE_DEBUG_MALLOC
#define malloc(x) debug_malloc(x,__LINE__,__FILE__)
#define free(x) debug_free(x,__LINE__,__FILE__)
extern void* debug_malloc();
extern void debug_free();
#endif
/* Free a property-value list for a topological face */
void cptc_free_prop_or_val(int count, char **array)
{
int i;
if (array == 0) return;
for (i = 0; i < count; ++i)
free(array[i]);
free(array);
}
/* Free the whole geo */
void cptc_free_geo(Cptc_GeomDesc* geo)
{
int i, j;
if (geo == 0) return;
if (geo -> props) {
cptc_free_prop_or_val(geo -> num_properties, geo -> props);
cptc_free_prop_or_val(geo -> num_properties, geo -> values);
}
if (geo -> control_points != 0)
free(geo -> control_points);
if (geo -> top_vertices) {
for (i = 0; i < geo -> num_top_vertices; ++i) {
free(geo -> top_vertices[i].id);
cptc_free_prop_or_val(geo -> top_vertices[i].num_properties,
geo -> top_vertices[i].props);
cptc_free_prop_or_val(geo -> top_vertices[i].num_properties,
geo -> top_vertices[i].values);
}
free(geo -> top_vertices);
}
if (geo -> top_edges) {
for (i = 0; i < geo -> num_top_edges; ++i) {
free(geo -> top_edges[i].id);
cptc_free_prop_or_val(geo -> top_edges[i].num_properties,
geo -> top_edges[i].props);
cptc_free_prop_or_val(geo -> top_edges[i].num_properties,
geo -> top_edges[i].values);
if (geo -> top_edges[i].bound_vertices != 0)
free(geo -> top_edges[i].bound_vertices);
if (geo -> top_edges[i].curves != 0) {
for (j = 0; j < geo -> top_edges[i].num_curves; ++j) {
free(geo -> top_edges[i].curves[j].control_pnt_indx);
}
free (geo -> top_edges[i].curves);
}
}
free(geo -> top_edges);
}
if (geo -> top_surfaces) {
for (i = 0; i < geo -> num_top_surfaces; ++i) {
free(geo -> top_surfaces[i].id);
cptc_free_prop_or_val(geo -> top_surfaces[i].num_properties,
geo -> top_surfaces[i].props);
cptc_free_prop_or_val(geo -> top_surfaces[i].num_properties,
geo -> top_surfaces[i].values);
if (geo -> top_surfaces[i].bound_vertices != 0)
free(geo -> top_surfaces[i].bound_vertices);
if (geo -> top_surfaces[i].bound_edges != 0)
free(geo -> top_surfaces[i].bound_edges);
if (geo -> top_surfaces[i].patches != 0) {
for (j = 0; j < geo -> top_surfaces[i].num_patches; ++j) {
free(geo -> top_surfaces[i].patches[j].control_pnt_indx);
}
free (geo -> top_surfaces[i].patches);
}
}
free(geo -> top_surfaces);
}
if (geo -> top_regions) {
for (i = 0; i < geo -> num_top_regions; ++i) {
free(geo -> top_regions[i].id);
cptc_free_prop_or_val(geo -> top_regions[i].num_properties,
geo -> top_regions[i].props);
cptc_free_prop_or_val(geo -> top_regions[i].num_properties,
geo -> top_regions[i].values);
if (geo -> top_regions[i].bound_vertices != 0)
free(geo -> top_regions[i].bound_vertices);
if (geo -> top_regions[i].bound_edges != 0)
free(geo -> top_regions[i].bound_edges);
if (geo -> top_regions[i].bound_surfaces != 0)
free(geo -> top_regions[i].bound_surfaces);
if (geo -> top_regions[i].surface_orientation != 0)
free(geo -> top_regions[i].surface_orientation);
}
free(geo -> top_regions);
}
free(geo);
}
void cptc_free_mesh(Cptc_MshDesc* mesh)
{
int j;
if (mesh == 0) return;
if (mesh -> geo_global_id)
free(mesh -> geo_global_id);
for (j = 0; j < mesh -> num_elems; ++j) {
free(mesh -> elems[j].node_list);
free(mesh -> elems[j].edge_incidence);
free(mesh -> elems[j].facet_incidence);
}
free(mesh -> nodes);
free(mesh -> elems);
free(mesh);
}
void clone_id(char **dest, char *src)
{
*dest = (char*) malloc(strlen(src) + 1);
strcpy(*dest, src);
}
static void clone_prop_vals(int* destnumprops, char*** destprops,
char*** destvals, int numprop,
char** srcprops, char** srcvals)
{
int i;
*destprops = (char**) malloc(numprop * sizeof(char*));
*destvals = (char**) malloc(numprop * sizeof(char*));
*destnumprops = numprop;
for (i = 0; i < numprop; ++i) {
clone_id(&((*destprops)[i]), srcprops[i]);
clone_id(&((*destvals)[i]), srcvals[i]);
}
}
static void clone_int_list(int* destsize, int** destlist, int srcsize,
int* srclist)
{
int i;
*destsize = srcsize;
*destlist = (int*) malloc(sizeof(int) * srcsize);
for (i = 0; i < srcsize; ++i)
(*destlist)[i] = srclist[i];
}
Cptc_GeomDesc* cptc_clone_geo(Cptc_GeomDesc* geo)
{
int i, j, k, ncp, ntv, nte, ncurve, nts, ord, npatch, ntr, ou, ov;
Cptc_GeomDesc* newgeo;
if (geo == 0) return 0;
newgeo = (Cptc_GeomDesc*) malloc(sizeof(Cptc_GeomDesc));
*newgeo = *geo;
if (geo -> props) {
clone_prop_vals(&(newgeo -> num_properties),
&(newgeo -> props), &(newgeo -> values),
geo -> num_properties, geo -> props, geo -> values);
}
if (geo -> control_points) {
ncp = geo -> num_control_pts;
newgeo -> num_control_pts = ncp;
newgeo -> control_points = (Cptc_GPoint*) malloc(sizeof(Cptc_GPoint) * ncp);
for (i = 0; i < ncp; ++i)
newgeo -> control_points[i] = geo -> control_points[i];
}
if (geo -> top_vertices) {
ntv = geo -> num_top_vertices;
newgeo -> num_top_vertices = ntv;
newgeo -> top_vertices = (Cptc_TVertex*) malloc(sizeof(Cptc_TVertex) * ntv);
for (i = 0; i < ntv; ++i) {
newgeo -> top_vertices[i] = geo -> top_vertices[i];
clone_id(&(newgeo -> top_vertices[i].id), geo -> top_vertices[i].id);
clone_prop_vals(&(newgeo -> top_vertices[i].num_properties),
&(newgeo -> top_vertices[i].props),
&(newgeo -> top_vertices[i].values),
geo -> top_vertices[i].num_properties,
geo -> top_vertices[i].props,
geo -> top_vertices[i].values);
}
}
if (geo -> top_edges) {
nte = geo -> num_top_edges;
newgeo -> num_top_edges = nte;
newgeo -> top_edges = (Cptc_TEdge*) malloc(sizeof(Cptc_TEdge) * nte);
for (i = 0; i < nte; ++i) {
newgeo -> top_edges[i] = geo -> top_edges[i];
clone_id(&(newgeo -> top_edges[i].id), geo -> top_edges[i].id);
ncurve = geo -> top_edges[i].num_curves;
newgeo -> top_edges[i].curves =
(Cptc_GCurve*) malloc(sizeof(Cptc_GCurve) * ncurve);
newgeo -> top_edges[i].num_curves = ncurve;
for (j = 0; j < ncurve; ++j) {
ord = geo -> top_edges[i].curves[j].order;
newgeo -> top_edges[i].curves[j].order = ord;
newgeo -> top_edges[i].curves[j].control_pnt_indx =
(int*) malloc(sizeof(int) * (ord + 1));
for (k = 0; k < ord + 1; ++k) {
newgeo -> top_edges[i].curves[j].control_pnt_indx[k] =
geo -> top_edges[i].curves[j].control_pnt_indx[k];
}
}
clone_prop_vals(&(newgeo -> top_edges[i].num_properties),
&(newgeo -> top_edges[i].props),
&(newgeo -> top_edges[i].values),
geo -> top_edges[i].num_properties,
geo -> top_edges[i].props,
geo -> top_edges[i].values);
clone_int_list(&(newgeo -> top_edges[i].num_bound_vertices),
&(newgeo -> top_edges[i].bound_vertices),
geo -> top_edges[i].num_bound_vertices,
geo -> top_edges[i].bound_vertices);
}
}
if (geo -> top_surfaces) {
nts = geo -> num_top_surfaces;
newgeo -> top_surfaces = (Cptc_TSurface*) malloc(sizeof(Cptc_TSurface) * nts);
newgeo -> num_top_surfaces = nts;
for (i = 0; i < nts; ++i) {
newgeo -> top_surfaces[i] = geo -> top_surfaces[i];
clone_id(&(newgeo -> top_surfaces[i].id), geo -> top_surfaces[i].id);
npatch = geo -> top_surfaces[i].num_patches;
newgeo -> top_surfaces[i].patches =
(Cptc_GPatch*) malloc(sizeof(Cptc_GPatch) * npatch);
newgeo -> top_surfaces[i].num_patches = npatch;
for (j = 0; j < npatch; ++j) {
newgeo -> top_surfaces[i].patches[j] =
geo -> top_surfaces[i].patches[j];
ou = geo -> top_surfaces[i].patches[j].order_u;
ov = geo -> top_surfaces[i].patches[j].order_v;
ncp = (geo -> top_surfaces[i].patches[j].type == CPTC_PATCHTYPE_TRIANGLE)?
(ou + 1) * (ou + 2) / 2 : (ou + 1) * (ov + 1);
newgeo -> top_surfaces[i].patches[j].control_pnt_indx =
(int*) malloc(sizeof(int) * ncp);
for (k = 0; k < ncp; ++k) {
newgeo -> top_surfaces[i].patches[j].control_pnt_indx[k] =
geo -> top_surfaces[i].patches[j].control_pnt_indx[k];
}
}
clone_prop_vals(&(newgeo -> top_surfaces[i].num_properties),
&(newgeo -> top_surfaces[i].props),
&(newgeo -> top_surfaces[i].values),
geo -> top_surfaces[i].num_properties,
geo -> top_surfaces[i].props,
geo -> top_surfaces[i].values);
clone_int_list(&(newgeo -> top_surfaces[i].num_bound_vertices),
&(newgeo -> top_surfaces[i].bound_vertices),
geo -> top_surfaces[i].num_bound_vertices,
geo -> top_surfaces[i].bound_vertices);
clone_int_list(&(newgeo -> top_surfaces[i].num_bound_edges),
&(newgeo -> top_surfaces[i].bound_edges),
geo -> top_surfaces[i].num_bound_edges,
geo -> top_surfaces[i].bound_edges);
}
}
if (geo -> top_regions) {
ntr = geo -> num_top_regions;
newgeo -> top_regions = (Cptc_TRegion*)
malloc(sizeof(Cptc_TRegion) * ntr);
newgeo -> num_top_regions = ntr;
for (i = 0; i < ntr; ++i) {
clone_id(&(newgeo -> top_regions[i].id), geo -> top_regions[i].id);
clone_prop_vals(&(newgeo -> top_regions[i].num_properties),
&(newgeo -> top_regions[i].props),
&(newgeo -> top_regions[i].values),
geo -> top_regions[i].num_properties,
geo -> top_regions[i].props,
geo -> top_regions[i].values);
clone_int_list(&(newgeo -> top_regions[i].num_bound_vertices),
&(newgeo -> top_regions[i].bound_vertices),
geo -> top_regions[i].num_bound_vertices,
geo -> top_regions[i].bound_vertices);
clone_int_list(&(newgeo -> top_regions[i].num_bound_edges),
&(newgeo -> top_regions[i].bound_edges),
geo -> top_regions[i].num_bound_edges,
geo -> top_regions[i].bound_edges);
clone_int_list(&(newgeo -> top_regions[i].num_bound_surfaces),
&(newgeo -> top_regions[i].bound_surfaces),
geo -> top_regions[i].num_bound_surfaces,
geo -> top_regions[i].bound_surfaces);
clone_int_list(&(newgeo -> top_regions[i].num_bound_surfaces),
&(newgeo -> top_regions[i].surface_orientation),
geo -> top_regions[i].num_bound_surfaces,
geo -> top_regions[i].surface_orientation);
}
}
return newgeo;
}
Cptc_MshDesc* cptc_clone_mesh(Cptc_MshDesc* mesh)
{
int i, j, nn, ne, nne, ord, gdim;
Cptc_MshDesc* newmesh;
if (mesh == 0) return 0;
newmesh = (Cptc_MshDesc*) malloc(sizeof(Cptc_MshDesc));
*newmesh = *mesh;
if (mesh -> geo_global_id) {
newmesh -> geo_global_id = (char *)malloc(strlen(mesh -> geo_global_id) + 1);
strcpy(newmesh -> geo_global_id, mesh -> geo_global_id);
}
nn = mesh -> num_nodes;
newmesh -> nodes = (Cptc_Mnode*) malloc(sizeof(Cptc_Mnode) * nn);
gdim = mesh -> intrinsic_dimension;
for (i = 0; i < nn; ++i)
newmesh -> nodes[i] = mesh -> nodes[i];
ne = mesh -> num_elems;
for (i = 0; i < ne; ++i) {
newmesh -> elems[i] = mesh -> elems[i];
if (mesh -> elems[i].type != CPTC_P_TET)
return 0;
ord = mesh -> elems[i].p_order;
if (gdim == 1) {
nne = ord + 1;
}
else if (gdim == 2) {
nne = (ord + 1) * (ord + 2) / 2;
}
else {
nne = (ord + 1) * (ord + 2) * (ord + 3) / 6;
}
newmesh -> elems[i].node_list = (int*) malloc(sizeof(int) * nne);
for (j = 0; j < nne; ++j)
newmesh -> elems[i].node_list[j] = mesh -> elems[i].node_list[j];
newmesh -> elems[i].edge_incidence =
(Cptc_TopIncdnc*) malloc(sizeof(Cptc_TopIncdnc) * 6);
newmesh -> elems[i].facet_incidence = (Cptc_TopIncdnc*)
malloc(sizeof(Cptc_TopIncdnc) * 4);
for (j = 0; j < 6; ++j)
newmesh -> elems[i].edge_incidence[j] =
mesh -> elems[i].edge_incidence[j];
for (j = 0; j < 4; ++j)
newmesh -> elems[i].facet_incidence[j] =
mesh -> elems[i].facet_incidence[j];
}
return newmesh;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -