/[escript]/branches/arrexp_2137_win_merge/finley/src/Assemble_PDE_System2_1D.c
ViewVC logotype

Contents of /branches/arrexp_2137_win_merge/finley/src/Assemble_PDE_System2_1D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2222 - (show annotations)
Tue Jan 20 04:52:39 2009 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 14775 byte(s)
Saving work
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 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 Finley_Assemble_PDE_System2_1D(Assemble_Parameters p, Finley_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;
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->ReferenceElement->S;
70 dim_t len_EM_S=p.row_NN*p.col_NN*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_NN*p.numEqu;
72
73
74 #pragma omp parallel private(color, EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p,row_index, q, s,r,k,m,rtmp,add_EM_F, add_EM_S)
75 {
76 void* ABuff=allocSampleBuffer(A);
77 void* BBuff=allocSampleBuffer(B);
78 void* CBuff=allocSampleBuffer(C);
79 void* DBuff=allocSampleBuffer(D);
80 void* XBuff=allocSampleBuffer(X);
81 void* YBuff=allocSampleBuffer(Y);
82 EM_S=THREAD_MEMALLOC(len_EM_S,double);
83 EM_F=THREAD_MEMALLOC(len_EM_F,double);
84 row_index=THREAD_MEMALLOC(p.row_NN,index_t);
85
86 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
87
88 for (color=elements->minColor;color<=elements->maxColor;color++) {
89 /* open loop over all elements: */
90 #pragma omp for private(e) schedule(static)
91 for(e=0;e<elements->numElements;e++){
92 if (elements->Color[e]==color) {
93 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
94 DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
95 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
96 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
97 add_EM_F=FALSE;
98 add_EM_S=FALSE;
99 /**************************************************************/
100 /* process A: */
101 /**************************************************************/
102 A_p=getSampleDataRO(A,e,ABuff);
103 if (NULL!=A_p) {
104 add_EM_S=TRUE;
105 if (extendedA) {
106 for (s=0;s<p.row_NS;s++) {
107 for (r=0;r<p.col_NS;r++) {
108 for (k=0;k<p.numEqu;k++) {
109 for (m=0;m<p.numComp;m++) {
110 rtmp=0.;
111 for (q=0;q<p.numQuad;q++) {
112 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*
113 A_p[INDEX5(k,0,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
114 }
115 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
116 }
117 }
118 }
119 }
120 } else {
121 for (s=0;s<p.row_NS;s++) {
122 for (r=0;r<p.col_NS;r++) {
123 rtmp=0;
124 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
125 for (k=0;k<p.numEqu;k++) {
126 for (m=0;m<p.numComp;m++) {
127 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)];
128 }
129 }
130 }
131 }
132 }
133 }
134 /**************************************************************/
135 /* process B: */
136 /**************************************************************/
137 B_p=getSampleDataRO(B,e,BBuff);
138 if (NULL!=B_p) {
139 add_EM_S=TRUE;
140 if (extendedB) {
141 for (s=0;s<p.row_NS;s++) {
142 for (r=0;r<p.col_NS;r++) {
143 for (k=0;k<p.numEqu;k++) {
144 for (m=0;m<p.numComp;m++) {
145 rtmp=0.;
146 for (q=0;q<p.numQuad;q++) {
147 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*
148 B_p[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]*S[INDEX2(r,q,p.row_NS)];
149 }
150 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
151 }
152 }
153 }
154 }
155 } else {
156 for (s=0;s<p.row_NS;s++) {
157 for (r=0;r<p.col_NS;r++) {
158 rtmp=0;
159 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*S[INDEX2(r,q,p.row_NS)];
160 for (k=0;k<p.numEqu;k++) {
161 for (m=0;m<p.numComp;m++) {
162 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*B_p[INDEX3(k,0,m,p.numEqu,DIM)];
163 }
164 }
165 }
166 }
167 }
168 }
169 /**************************************************************/
170 /* process C: */
171 /**************************************************************/
172 C_p=getSampleDataRO(C,e,CBuff);
173 if (NULL!=C_p) {
174 add_EM_S=TRUE;
175 if (extendedC) {
176 for (s=0;s<p.row_NS;s++) {
177 for (r=0;r<p.col_NS;r++) {
178 for (k=0;k<p.numEqu;k++) {
179 for (m=0;m<p.numComp;m++) {
180 rtmp=0;
181 for (q=0;q<p.numQuad;q++) {
182 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*C_p[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
183 }
184 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
185 }
186 }
187 }
188 }
189 } else {
190 for (s=0;s<p.row_NS;s++) {
191 for (r=0;r<p.col_NS;r++) {
192 rtmp=0;
193 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
194 for (k=0;k<p.numEqu;k++) {
195 for (m=0;m<p.numComp;m++) {
196 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*C_p[INDEX3(k,m,0,p.numEqu,p.numComp)];
197 }
198 }
199 }
200 }
201 }
202 }
203 /************************************************************* */
204 /* process D */
205 /**************************************************************/
206 D_p=getSampleDataRO(D,e,DBuff);
207 if (NULL!=D_p) {
208 add_EM_S=TRUE;
209 if (extendedD) {
210 for (s=0;s<p.row_NS;s++) {
211 for (r=0;r<p.col_NS;r++) {
212 for (k=0;k<p.numEqu;k++) {
213 for (m=0;m<p.numComp;m++) {
214 rtmp=0;
215 for (q=0;q<p.numQuad;q++) {
216 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_NS)];
217 }
218 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
219
220 }
221 }
222 }
223 }
224 } else {
225 for (s=0;s<p.row_NS;s++) {
226 for (r=0;r<p.col_NS;r++) {
227 rtmp=0;
228 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
229 for (k=0;k<p.numEqu;k++) {
230 for (m=0;m<p.numComp;m++) {
231 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
232 }
233 }
234 }
235 }
236 }
237 }
238 /**************************************************************/
239 /* process X: */
240 /**************************************************************/
241 X_p=getSampleDataRO(X,e,XBuff);
242 if (NULL!=X_p) {
243 add_EM_F=TRUE;
244 if (extendedX) {
245 for (s=0;s<p.row_NS;s++) {
246 for (k=0;k<p.numEqu;k++) {
247 rtmp=0;
248 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX3(k,0,q,p.numEqu,DIM)];
249 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
250 }
251 }
252 } else {
253 for (s=0;s<p.row_NS;s++) {
254 rtmp=0;
255 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
256 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*X_p[INDEX2(k,0,p.numEqu)];
257 }
258 }
259 }
260 /**************************************************************/
261 /* process Y: */
262 /**************************************************************/
263 Y_p=getSampleDataRO(Y,e,YBuff);
264 if (NULL!=Y_p) {
265 add_EM_F=TRUE;
266 if (extendedY) {
267 for (s=0;s<p.row_NS;s++) {
268 for (k=0;k<p.numEqu;k++) {
269 rtmp=0;
270 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[INDEX2(k,q,p.numEqu)];
271 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
272 }
273 }
274 } else {
275 for (s=0;s<p.row_NS;s++) {
276 rtmp=0;
277 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
278 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
279 }
280 }
281 }
282 /***********************************************************************************************/
283 /* add the element matrices onto the matrix and right hand side */
284 /***********************************************************************************************/
285 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
286 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
287 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
288
289 } /* end color check */
290 } /* end element loop */
291 } /* end color loop */
292
293 THREAD_MEMFREE(EM_S);
294 THREAD_MEMFREE(EM_F);
295 THREAD_MEMFREE(row_index);
296
297 } /* end of pointer check */
298 freeSampleBuffer(ABuff);
299 freeSampleBuffer(BBuff);
300 freeSampleBuffer(CBuff);
301 freeSampleBuffer(DBuff);
302 freeSampleBuffer(XBuff);
303 freeSampleBuffer(YBuff);
304 } /* end parallel region */
305 }
306 /*
307 * $Log$
308 */

  ViewVC Help
Powered by ViewVC 1.1.26