/[escript]/branches/domexper/dudley/src/Assemble_PDE_System2_1D.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Assemble_PDE_System2_1D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3144 - (show annotations)
Fri Sep 3 00:49:02 2010 UTC (8 years, 9 months ago) by jfenwick
File MIME type: text/plain
File size: 15999 byte(s)
row_node, col_node (Assemble params), node_selection 
removed
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 right hand side F */
18 /* the shape functions for test and solution must be identical */
19
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 and -(X_{k,i})_i + Y_k */
22
23 /* u has p.numComp components in a 1D domain. The shape functions for test and solution must be identical */
24 /* and row_NS == row_NN */
25
26 /* Shape of the coefficients: */
27
28 /* A = p.numEqu x 1 x p.numComp x 1 */
29 /* B = 1 x numEqu x p.numComp */
30 /* C = p.numEqu x 1 x p.numComp */
31 /* D = p.numEqu x p.numComp */
32 /* X = p.numEqu x 1 */
33 /* Y = p.numEqu */
34
35
36 /**************************************************************/
37
38
39 #include "Assemble.h"
40 #include "Util.h"
41 #ifdef _OPENMP
42 #include <omp.h>
43 #endif
44
45
46 /**************************************************************/
47
48 void Dudley_Assemble_PDE_System2_1D(Assemble_Parameters p, Dudley_ElementFile* elements,
49 Paso_SystemMatrix* Mat, escriptDataC* F,
50 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
51
52 #define DIM 1
53 index_t color;
54 dim_t e;
55 __const double *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p, *A_q, *B_q, *C_q, *D_q, *X_q, *Y_q;
56 double *EM_S, *EM_F, *Vol, *DSDX;
57 index_t *row_index;
58 register dim_t q, s,r,k,m;
59 register double rtmp;
60 bool_t add_EM_F, add_EM_S;
61
62 bool_t extendedA=isExpanded(A);
63 bool_t extendedB=isExpanded(B);
64 bool_t extendedC=isExpanded(C);
65 bool_t extendedD=isExpanded(D);
66 bool_t extendedX=isExpanded(X);
67 bool_t extendedY=isExpanded(Y);
68 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 double *S=p.row_jac->BasisFunctions->S;
70 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
72
73 #pragma omp parallel private(color, EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p, A_q, B_q, C_q, D_q, X_q, Y_q,row_index, q, s,r,k,m,rtmp,add_EM_F, add_EM_S)
74 {
75 EM_S=THREAD_MEMALLOC(len_EM_S,double);
76 EM_F=THREAD_MEMALLOC(len_EM_F,double);
77 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
78
79 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
80
81 for (color=elements->minColor;color<=elements->maxColor;color++) {
82 /* open loop over all elements: */
83 #pragma omp for private(e) schedule(static)
84 for(e=0;e<elements->numElements;e++){
85 if (elements->Color[e]==color) {
86
87 A_p=getSampleDataRO(A,e);
88 B_p=getSampleDataRO(B,e);
89 C_p=getSampleDataRO(C,e);
90 D_p=getSampleDataRO(D,e);
91 X_p=getSampleDataRO(X,e);
92 Y_p=getSampleDataRO(Y,e);
93
94 Vol=&(p.row_jac->volume[INDEX3(0,0,e, p.numQuadTotal,1)]);
95 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e, p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
96 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
97 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
98 add_EM_F=FALSE;
99 add_EM_S=FALSE;
100
101 /**************************************************************/
102 /* process A: */
103 /**************************************************************/
104
105 if (NULL!=A_p) {
106 add_EM_S=TRUE;
107 if (extendedA) {
108 A_q=&(A_p[INDEX6(0,0,0,0,0,0, p.numEqu,DIM,p.numComp,DIM,p.numQuadTotal)]);
109 for (s=0;s<p.row_numShapes;s++) {
110 for (r=0;r<p.col_numShapes;r++) {
111 for (k=0;k<p.numEqu;k++) {
112 for (m=0;m<p.numComp;m++) {
113 rtmp=0.;
114 for (q=0;q<p.numQuadTotal;q++) {
115 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
116 A_q[INDEX5(k,0,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
117 }
118 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
119 }
120 }
121 }
122 }
123 } else {
124 for (s=0;s<p.row_numShapes;s++) {
125 for (r=0;r<p.col_numShapes;r++) {
126 rtmp=0;
127 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
128 for (k=0;k<p.numEqu;k++) {
129 for (m=0;m<p.numComp;m++) {
130 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)];
131 }
132 }
133 }
134 }
135 }
136 }
137 /**************************************************************/
138 /* process B: */
139 /**************************************************************/
140
141 if (NULL!=B_p) {
142 add_EM_S=TRUE;
143 if (extendedB) {
144 B_q=&(B_p[INDEX5(0,0,0,0,0, p.numEqu,DIM,p.numComp,p.numQuadTotal)]);
145 for (s=0;s<p.row_numShapes;s++) {
146 for (r=0;r<p.col_numShapes;r++) {
147 for (k=0;k<p.numEqu;k++) {
148 for (m=0;m<p.numComp;m++) {
149 rtmp=0.;
150 for (q=0;q<p.numQuadTotal;q++) {
151 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
152 B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
153 }
154 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
155 }
156 }
157 }
158 }
159 } else {
160 for (s=0;s<p.row_numShapes;s++) {
161 for (r=0;r<p.col_numShapes;r++) {
162 rtmp=0;
163 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
164 for (k=0;k<p.numEqu;k++) {
165 for (m=0;m<p.numComp;m++) {
166 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[INDEX3(k,0,m,p.numEqu,DIM)];
167 }
168 }
169 }
170 }
171 }
172 }
173 /**************************************************************/
174 /* process C: */
175 /**************************************************************/
176
177 if (NULL!=C_p) {
178 add_EM_S=TRUE;
179 if (extendedC) {
180 C_q=&(C_p[INDEX5(0,0,0,0,0, p.numEqu,p.numComp,DIM, p.numQuadTotal)]);
181 for (s=0;s<p.row_numShapes;s++) {
182 for (r=0;r<p.col_numShapes;r++) {
183 for (k=0;k<p.numEqu;k++) {
184 for (m=0;m<p.numComp;m++) {
185 rtmp=0;
186 for (q=0;q<p.numQuadTotal;q++) {
187 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
188 }
189 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
190 }
191 }
192 }
193 }
194 } else {
195 for (s=0;s<p.row_numShapes;s++) {
196 for (r=0;r<p.col_numShapes;r++) {
197 rtmp=0;
198 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
199 for (k=0;k<p.numEqu;k++) {
200 for (m=0;m<p.numComp;m++) {
201 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[INDEX3(k,m,0,p.numEqu,p.numComp)];
202 }
203 }
204 }
205 }
206 }
207 }
208 /************************************************************* */
209 /* process D */
210 /**************************************************************/
211
212 if (NULL!=D_p) {
213 add_EM_S=TRUE;
214 if (extendedD) {
215 D_q=&(D_p[INDEX4(0,0,0,0, p.numEqu,p.numComp,p.numQuadTotal)]);
216 for (s=0;s<p.row_numShapes;s++) {
217 for (r=0;r<p.col_numShapes;r++) {
218 for (k=0;k<p.numEqu;k++) {
219 for (m=0;m<p.numComp;m++) {
220 rtmp=0;
221 for (q=0;q<p.numQuadTotal;q++) {
222 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
223 }
224 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
225
226 }
227 }
228 }
229 }
230 } else {
231 for (s=0;s<p.row_numShapes;s++) {
232 for (r=0;r<p.col_numShapes;r++) {
233 rtmp=0;
234 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
235 for (k=0;k<p.numEqu;k++) {
236 for (m=0;m<p.numComp;m++) {
237 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
238 }
239 }
240 }
241 }
242 }
243 }
244 /**************************************************************/
245 /* process X: */
246 /**************************************************************/
247
248 if (NULL!=X_p) {
249 add_EM_F=TRUE;
250 if (extendedX) {
251 X_q=&(X_p[INDEX4(0,0,0,0, p.numEqu,DIM,p.numQuadTotal)]);
252 for (s=0;s<p.row_numShapes;s++) {
253 for (k=0;k<p.numEqu;k++) {
254 rtmp=0;
255 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)];
256 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
257 }
258 }
259 } else {
260 for (s=0;s<p.row_numShapes;s++) {
261 rtmp=0;
262 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
263 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*X_p[INDEX2(k,0,p.numEqu)];
264 }
265 }
266 }
267 /**************************************************************/
268 /* process Y: */
269 /**************************************************************/
270
271 if (NULL!=Y_p) {
272 add_EM_F=TRUE;
273 if (extendedY) {
274 Y_q=&(Y_p[INDEX3(0,0,0, p.numEqu,p.numQuadTotal)]);
275 for (s=0;s<p.row_numShapes;s++) {
276 for (k=0;k<p.numEqu;k++) {
277 rtmp=0;
278 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
279 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
280 }
281 }
282 } else {
283 for (s=0;s<p.row_numShapes;s++) {
284 rtmp=0;
285 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
286 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
287 }
288 }
289 }
290 /***********************************************************************************************/
291 /* add the element matrices onto the matrix and right hand side */
292 /***********************************************************************************************/
293
294 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(q,e,p.NN)]];
295
296 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
297 if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
298
299 } /* end color check */
300 } /* end element loop */
301 } /* end color loop */
302
303 THREAD_MEMFREE(EM_S);
304 THREAD_MEMFREE(EM_F);
305 THREAD_MEMFREE(row_index);
306
307 } /* end of pointer check */
308 } /* end parallel region */
309 }
310 /*
311 * $Log$
312 */

  ViewVC Help
Powered by ViewVC 1.1.26