/[escript]/trunk/finley/src/Assemble_PDE.c
ViewVC logotype

Contents of /trunk/finley/src/Assemble_PDE.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 15005 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* assembles the system of numEq PDEs into the stiffness matrix S and right hand side F */
18
19 /* -div(A*grad u)-div(B*u)+C*grad u + D*u= -div X + Y */
20
21 /* -(A_{k,i,m,j} u_m,j)_i-(B_{k,i,m} u_m)_i+C_{k,m,j} u_m,j-D_{k,m} u_m = -(X_{k,i})_i + Y_k */
22
23 /* u has numComp components. */
24
25 /* Shape of the coefficients: */
26
27 /* A = numEqu x numDim x numComp x numDim */
28 /* B = numDim x numEqu x numComp */
29 /* C = numEqu x numDim x numComp */
30 /* D = numEqu x numComp */
31 /* X = numEqu x numDim */
32 /* Y = numEqu */
33
34 /* The coefficients A,B,C,D,X and Y have to be defined on the integartion points or not present (=NULL). */
35
36 /* S and F have to be initialized before the routine is called. S or F can be NULL. In this case the left or */
37 /* the right hand side of the PDE is not processed. */
38
39 /* The routine does not consider any boundary conditions. */
40
41 /**************************************************************/
42
43 #include "Assemble.h"
44 #include "Util.h"
45 #include "esysUtils/blocktimer.h"
46 #ifdef _OPENMP
47 #include <omp.h>
48 #endif
49
50
51 /**************************************************************/
52
53 void Finley_Assemble_PDE(Finley_NodeFile* nodes,Finley_ElementFile* elements,Paso_SystemMatrix* S, escriptDataC* F,
54 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y ) {
55
56 bool_t reducedIntegrationOrder=FALSE;
57 char error_msg[LenErrorMsg_MAX];
58 Finley_Assemble_Parameters p;
59 double time0;
60 dim_t dimensions[ESCRIPT_MAX_DATA_RANK];
61 type_t funcspace;
62 double blocktimer_start = blocktimer_time();
63
64 Finley_resetError();
65
66 if (nodes==NULL || elements==NULL) return;
67 if (S==NULL && isEmpty(F)) return;
68
69 if (isEmpty(F) && !isEmpty(X) && !isEmpty(F)) {
70 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: right hand side coefficients are non-zero bat no right hand side vector given.");
71 }
72
73 if (S==NULL && !isEmpty(A) && !isEmpty(B) && !isEmpty(C) && !isEmpty(D)) {
74 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: coefficients are non-zero but no matrix is given.");
75 }
76
77 /* get the functionspace for this assemblage call */
78 funcspace=UNKNOWN;
79 updateFunctionSpaceType(funcspace,A);
80 updateFunctionSpaceType(funcspace,B);
81 updateFunctionSpaceType(funcspace,C);
82 updateFunctionSpaceType(funcspace,D);
83 updateFunctionSpaceType(funcspace,X);
84 updateFunctionSpaceType(funcspace,Y);
85 if (funcspace==UNKNOWN) return; /* all data are empty */
86
87 /* check if all function spaces are the same */
88 if (! functionSpaceTypeEqual(funcspace,A) ) {
89 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient A");
90 }
91 if (! functionSpaceTypeEqual(funcspace,B) ) {
92 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient B");
93 }
94 if (! functionSpaceTypeEqual(funcspace,C) ) {
95 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient C");
96 }
97 if (! functionSpaceTypeEqual(funcspace,D) ) {
98 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient D");
99 }
100 if (! functionSpaceTypeEqual(funcspace,X) ) {
101 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient X");
102 }
103 if (! functionSpaceTypeEqual(funcspace,Y) ) {
104 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: unexpected function space type for coefficient Y");
105 }
106 if (! Finley_noError()) return;
107
108 /* check if all function spaces are the same */
109 if (funcspace==FINLEY_ELEMENTS) {
110 reducedIntegrationOrder=FALSE;
111 } else if (funcspace==FINLEY_FACE_ELEMENTS) {
112 reducedIntegrationOrder=FALSE;
113 } else if (funcspace==FINLEY_CONTACT_ELEMENTS_1) {
114 reducedIntegrationOrder=FALSE;
115 } else if (funcspace==FINLEY_CONTACT_ELEMENTS_2) {
116 reducedIntegrationOrder=FALSE;
117 } else if (funcspace==FINLEY_REDUCED_ELEMENTS) {
118 reducedIntegrationOrder=TRUE;
119 } else if (funcspace==FINLEY_REDUCED_FACE_ELEMENTS) {
120 reducedIntegrationOrder=TRUE;
121 } else if (funcspace==FINLEY_REDUCED_CONTACT_ELEMENTS_1) {
122 reducedIntegrationOrder=TRUE;
123 } else if (funcspace==FINLEY_REDUCED_CONTACT_ELEMENTS_2) {
124 reducedIntegrationOrder=TRUE;
125 } else {
126 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: assemblage failed because of illegal function space.");
127 }
128 if (! Finley_noError()) return;
129
130 /* set all parameters in p*/
131 Finley_Assemble_getAssembleParameters(nodes,elements,S,F, reducedIntegrationOrder, &p);
132 if (! Finley_noError()) return;
133
134 /* check if all function spaces are the same */
135
136 if (! numSamplesEqual(A,p.numQuadTotal,elements->numElements) ) {
137 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient A don't match (%d,%d)",p.numQuadTotal,elements->numElements);
138 Finley_setError(TYPE_ERROR,error_msg);
139 }
140
141 if (! numSamplesEqual(B,p.numQuadTotal,elements->numElements) ) {
142 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient B don't match (%d,%d)",p.numQuadTotal,elements->numElements);
143 Finley_setError(TYPE_ERROR,error_msg);
144 }
145
146 if (! numSamplesEqual(C,p.numQuadTotal,elements->numElements) ) {
147 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient C don't match (%d,%d)",p.numQuadTotal,elements->numElements);
148 Finley_setError(TYPE_ERROR,error_msg);
149 }
150
151 if (! numSamplesEqual(D,p.numQuadTotal,elements->numElements) ) {
152 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient D don't match (%d,%d)",p.numQuadTotal,elements->numElements);
153 Finley_setError(TYPE_ERROR,error_msg);
154 }
155
156 if (! numSamplesEqual(X,p.numQuadTotal,elements->numElements) ) {
157 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient X don't match (%d,%d)",p.numQuadTotal,elements->numElements);
158 Finley_setError(TYPE_ERROR,error_msg);
159 }
160
161 if (! numSamplesEqual(Y,p.numQuadTotal,elements->numElements) ) {
162 sprintf(error_msg,"Finley_Assemble_PDE: sample points of coefficient Y don't match (%d,%d)",p.numQuadTotal,elements->numElements);
163 Finley_setError(TYPE_ERROR,error_msg);
164 }
165
166 /* check the dimensions: */
167
168 if (p.numEqu==1 && p.numComp==1) {
169 if (!isEmpty(A)) {
170 dimensions[0]=p.numDim;
171 dimensions[1]=p.numDim;
172 if (!isDataPointShapeEqual(A,2,dimensions)) {
173 sprintf(error_msg,"Finley_Assemble_PDE: coefficient A: illegal shape, expected shape (%d,%d)",dimensions[0],dimensions[1]);
174 Finley_setError(TYPE_ERROR,error_msg);
175 }
176 }
177 if (!isEmpty(B)) {
178 dimensions[0]=p.numDim;
179 if (!isDataPointShapeEqual(B,1,dimensions)) {
180 sprintf(error_msg,"Finley_Assemble_PDE: coefficient B: illegal shape (%d,)",dimensions[0]);
181 Finley_setError(TYPE_ERROR,error_msg);
182 }
183 }
184 if (!isEmpty(C)) {
185 dimensions[0]=p.numDim;
186 if (!isDataPointShapeEqual(C,1,dimensions)) {
187 sprintf(error_msg,"Finley_Assemble_PDE: coefficient C, expected shape (%d,)",dimensions[0]);
188 Finley_setError(TYPE_ERROR,error_msg);
189 }
190 }
191 if (!isEmpty(D)) {
192 if (!isDataPointShapeEqual(D,0,dimensions)) {
193 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: coefficient D, rank 0 expected.");
194 }
195 }
196 if (!isEmpty(X)) {
197 dimensions[0]=p.numDim;
198 if (!isDataPointShapeEqual(X,1,dimensions)) {
199 sprintf(error_msg,"Finley_Assemble_PDE: coefficient X, expected shape (%d,",dimensions[0]);
200 Finley_setError(TYPE_ERROR,error_msg);
201 }
202 }
203 if (!isEmpty(Y)) {
204 if (!isDataPointShapeEqual(Y,0,dimensions)) {
205 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: coefficient Y, rank 0 expected.");
206 }
207 }
208 } else {
209 if (!isEmpty(A)) {
210 dimensions[0]=p.numEqu;
211 dimensions[1]=p.numDim;
212 dimensions[2]=p.numComp;
213 dimensions[3]=p.numDim;
214 if (!isDataPointShapeEqual(A,4,dimensions)) {
215 sprintf(error_msg,"Finley_Assemble_PDE: coefficient A, expected shape (%d,%d,%d,%d)",dimensions[0],dimensions[1],dimensions[2],dimensions[3]);
216 Finley_setError(TYPE_ERROR,error_msg);
217 }
218 }
219 if (!isEmpty(B)) {
220 dimensions[0]=p.numEqu;
221 dimensions[1]=p.numDim;
222 dimensions[2]=p.numComp;
223 if (!isDataPointShapeEqual(B,3,dimensions)) {
224 sprintf(error_msg,"Finley_Assemble_PDE: coefficient B, expected shape (%d,%d,%d)",dimensions[0],dimensions[1],dimensions[2]);
225 Finley_setError(TYPE_ERROR,error_msg);
226 }
227 }
228 if (!isEmpty(C)) {
229 dimensions[0]=p.numEqu;
230 dimensions[1]=p.numComp;
231 dimensions[2]=p.numDim;
232 if (!isDataPointShapeEqual(C,3,dimensions)) {
233 sprintf(error_msg,"Finley_Assemble_PDE: coefficient C, expected shape (%d,%d,%d)",dimensions[0],dimensions[1],dimensions[2]);
234 Finley_setError(TYPE_ERROR,error_msg);
235 }
236 }
237 if (!isEmpty(D)) {
238 dimensions[0]=p.numEqu;
239 dimensions[1]=p.numComp;
240 if (!isDataPointShapeEqual(D,2,dimensions)) {
241 sprintf(error_msg,"Finley_Assemble_PDE: coefficient D, expected shape (%d,%d)",dimensions[0],dimensions[1]);
242 Finley_setError(TYPE_ERROR,error_msg);
243 }
244 }
245 if (!isEmpty(X)) {
246 dimensions[0]=p.numEqu;
247 dimensions[1]=p.numDim;
248 if (!isDataPointShapeEqual(X,2,dimensions)) {
249 sprintf(error_msg,"Finley_Assemble_PDE: coefficient X, expected shape (%d,%d)",dimensions[0],dimensions[1]);
250 Finley_setError(TYPE_ERROR,error_msg);
251 }
252 }
253 if (!isEmpty(Y)) {
254 dimensions[0]=p.numEqu;
255 if (!isDataPointShapeEqual(Y,1,dimensions)) {
256 sprintf(error_msg,"Finley_Assemble_PDE: coefficient Y, expected shape (%d,)",dimensions[0]);
257 Finley_setError(TYPE_ERROR,error_msg);
258 }
259 }
260 }
261 if (Finley_noError()) {
262 time0=Finley_timer();
263 if (p.numEqu == p. numComp) {
264 if (p.numEqu > 1) {
265 /* system of PDESs */
266 if (p.numDim==3) {
267 if ( p.numSides == 1 ) {
268 Finley_Assemble_PDE_System2_3D(p,elements,S,F,A,B,C,D,X,Y);
269 } else if ( p.numSides == 2 ) {
270 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
271 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
272 } else {
273 Finley_Assemble_PDE_System2_C(p,elements,S,F,D,Y);
274 }
275 } else {
276 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
277 }
278 } else if (p.numDim==2) {
279 if ( p.numSides == 1 ) {
280 Finley_Assemble_PDE_System2_2D(p,elements,S,F,A,B,C,D,X,Y);
281 } else if ( p.numSides == 2 ) {
282 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
283 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
284 } else {
285 Finley_Assemble_PDE_System2_C(p,elements,S,F,D,Y);
286 }
287 } else {
288 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
289 }
290 } else if (p.numDim==1) {
291 if ( p.numSides == 1 ) {
292 Finley_Assemble_PDE_System2_1D(p,elements,S,F,A,B,C,D,X,Y);
293 } else if ( p.numSides == 2 ) {
294 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
295 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
296 } else {
297 Finley_Assemble_PDE_System2_C(p,elements,S,F,D,Y);
298 }
299 } else {
300 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
301 }
302 } else {
303 Finley_setError(VALUE_ERROR,"Finley_Assemble_PDE supports spatial dimensions 1,2,3 only.");
304 }
305 } else {
306 /* single PDES */
307 if (p.numDim==3) {
308 if ( p.numSides == 1 ) {
309 Finley_Assemble_PDE_Single2_3D(p,elements,S,F,A,B,C,D,X,Y);
310 } else if ( p.numSides == 2 ) {
311 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
312 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
313 } else {
314 Finley_Assemble_PDE_Single2_C(p,elements,S,F,D,Y);
315 }
316 } else {
317 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
318 }
319 } else if (p.numDim==2) {
320 if ( p.numSides == 1 ) {
321 Finley_Assemble_PDE_Single2_2D(p,elements,S,F,A,B,C,D,X,Y);
322 } else if ( p.numSides == 2 ) {
323 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
324 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
325 } else {
326 Finley_Assemble_PDE_Single2_C(p,elements,S,F,D,Y);
327 }
328 } else {
329 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
330 }
331 } else if (p.numDim==1) {
332 if ( p.numSides == 1 ) {
333 Finley_Assemble_PDE_Single2_1D(p,elements,S,F,A,B,C,D,X,Y);
334 } else if ( p.numSides == 2 ) {
335 if ( !isEmpty(A) || !isEmpty(B) || !isEmpty(C) || !isEmpty(X) ) {
336 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE: Contact elements require A, B, C and X to be empty.");
337 } else {
338 Finley_Assemble_PDE_Single2_C(p,elements,S,F,D,Y);
339 }
340 } else {
341 Finley_setError(TYPE_ERROR,"Finley_Assemble_PDE supports numShape=NumNodes or 2*numShape=NumNodes only.");
342 }
343 } else {
344 Finley_setError(VALUE_ERROR,"Finley_Assemble_PDE supports spatial dimensions 1,2,3 only.");
345 }
346 }
347 } else {
348 Finley_setError(VALUE_ERROR,"Finley_Assemble_PDE requires number of equations == number of solutions .");
349 }
350 }
351 blocktimer_increment("Finley_Assemble_PDE()", blocktimer_start);
352 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26