1 |
/******************************************************* |
2 |
* |
3 |
* Copyright (c) 2003-2008 by University of Queensland |
4 |
* Earth Systems Science Computational Center (ESSCC) |
5 |
* http://www.uq.edu.au/esscc |
6 |
* |
7 |
* Primary Business: Queensland, Australia |
8 |
* Licensed under the Open Software License version 3.0 |
9 |
* http://www.opensource.org/licenses/osl-3.0.php |
10 |
* |
11 |
*******************************************************/ |
12 |
|
13 |
|
14 |
/**************************************************************/ |
15 |
|
16 |
/* Finley: Mesh */ |
17 |
|
18 |
/**************************************************************/ |
19 |
|
20 |
#include "Mesh.h" |
21 |
|
22 |
/**************************************************************/ |
23 |
|
24 |
/* allocates a Mesh with name name for elements of type id using an integration order. If order is negative, */ |
25 |
/* the most appropriate order is selected indepently. */ |
26 |
|
27 |
extern Finley_RefElementInfo Finley_RefElement_InfoList[]; |
28 |
|
29 |
Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, index_t order, index_t reduced_order, Paso_MPIInfo *mpi_info) |
30 |
{ |
31 |
Finley_Mesh *out; |
32 |
|
33 |
/* allocate the return value */ |
34 |
|
35 |
out=MEMALLOC(1,Finley_Mesh); |
36 |
if (Finley_checkPtr(out)) return NULL; |
37 |
out->Name=NULL; |
38 |
out->Nodes=NULL; |
39 |
out->Elements=NULL; |
40 |
out->FaceElements=NULL; |
41 |
out->Points=NULL; |
42 |
out->ContactElements=NULL; |
43 |
out->TagMap=NULL; |
44 |
out->reference_counter=0; |
45 |
|
46 |
out->FullFullPattern=NULL; |
47 |
out->FullReducedPattern=NULL; |
48 |
out->ReducedFullPattern=NULL; |
49 |
out->ReducedReducedPattern=NULL; |
50 |
out->MPIInfo = Paso_MPIInfo_getReference( mpi_info ); |
51 |
if (! Finley_noError()) { |
52 |
Finley_Mesh_free(out); |
53 |
return NULL; |
54 |
} |
55 |
/* copy name: */ |
56 |
|
57 |
out->Name=MEMALLOC(strlen(name)+1,char); |
58 |
if (Finley_checkPtr(out->Name)) { |
59 |
Finley_Mesh_free(out); |
60 |
return NULL; |
61 |
} |
62 |
strcpy(out->Name,name); |
63 |
|
64 |
/* allocate node table: */ |
65 |
out->Nodes=Finley_NodeFile_alloc( numDim, mpi_info ); |
66 |
if (! Finley_noError()) { |
67 |
Finley_Mesh_free(out); |
68 |
return NULL; |
69 |
} |
70 |
out->order=order; |
71 |
out->reduced_order=reduced_order; |
72 |
out->Elements=NULL; |
73 |
out->FaceElements=NULL; |
74 |
out->Points=NULL; |
75 |
out->ContactElements=NULL; |
76 |
out->reference_counter++; |
77 |
return out; |
78 |
} |
79 |
|
80 |
/* returns a reference to Finley_Mesh in */ |
81 |
|
82 |
Finley_Mesh* Finley_Mesh_reference(Finley_Mesh* in) { |
83 |
if (in!=NULL) ++(in->reference_counter); |
84 |
return in; |
85 |
} |
86 |
|
87 |
/* freeates a mesh: */ |
88 |
|
89 |
void Finley_Mesh_free(Finley_Mesh* in) { |
90 |
if (in!=NULL) { |
91 |
in->reference_counter--; |
92 |
if (in->reference_counter<1) { |
93 |
#ifdef Finley_TRACE |
94 |
if (in->Name!=NULL) { |
95 |
printf("Finley_Mesh_free: mesh %s is freed.\n",in->Name); |
96 |
} else { |
97 |
printf("Finley_Mesh_free\n"); |
98 |
} |
99 |
#endif |
100 |
MEMFREE(in->Name); |
101 |
Finley_NodeFile_free(in->Nodes); |
102 |
Finley_ElementFile_free(in->FaceElements); |
103 |
Finley_ElementFile_free(in->Elements); |
104 |
Finley_ElementFile_free(in->ContactElements); |
105 |
Finley_ElementFile_free(in->Points); |
106 |
Finley_TagMap_free(in->TagMap); |
107 |
Paso_SystemMatrixPattern_free(in->FullFullPattern); |
108 |
Paso_SystemMatrixPattern_free(in->FullReducedPattern); |
109 |
Paso_SystemMatrixPattern_free(in->ReducedFullPattern); |
110 |
Paso_SystemMatrixPattern_free(in->ReducedReducedPattern); |
111 |
Paso_MPIInfo_free( in->MPIInfo ); |
112 |
MEMFREE(in); |
113 |
} |
114 |
} |
115 |
} |
116 |
|
117 |
/**************************************************************/ |
118 |
|
119 |
/* returns the spatial dimension of the mesh: */ |
120 |
|
121 |
dim_t Finley_Mesh_getDim(Finley_Mesh *in) { |
122 |
return in->Nodes->numDim; |
123 |
} |
124 |
|
125 |
void Finley_Mesh_setElements(Finley_Mesh* self,Finley_ElementFile *elements) { |
126 |
Finley_ElementFile_free(self->Elements); |
127 |
self->Elements=elements; |
128 |
} |
129 |
void Finley_Mesh_setFaceElements(Finley_Mesh* self,Finley_ElementFile *elements) { |
130 |
Finley_ElementFile_free(self->FaceElements); |
131 |
self->FaceElements=elements; |
132 |
} |
133 |
void Finley_Mesh_setContactElements(Finley_Mesh* self,Finley_ElementFile *elements) { |
134 |
Finley_ElementFile_free(self->ContactElements); |
135 |
self->ContactElements=elements; |
136 |
} |
137 |
void Finley_Mesh_setPoints(Finley_Mesh* self,Finley_ElementFile *elements) { |
138 |
Finley_ElementFile_free(self->Points); |
139 |
self->Points=elements; |
140 |
} |
141 |
|