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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 2 months ago) by ksteube
File MIME type: text/plain
File size: 14311 byte(s)
Copyright updated in all files

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_{i,j} u_,j)_i-(B_{i} u)_i+C_{j} u_,j-D u_m and -(X_,i)_i + Y */
22
23 /* in a 2D 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 = 2 x 2 */
29 /* B = 2 */
30 /* C = 2 */
31 /* D = scalar */
32 /* X = 2 */
33 /* Y = scalar */
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 void Finley_Assemble_PDE_Single2_2D(Assemble_Parameters p, Finley_ElementFile* elements,
48 Paso_SystemMatrix* Mat, escriptDataC* F,
49 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
50
51 #define DIM 2
52 index_t color;
53 dim_t e;
54 double *EM_S, *EM_F, *Vol, *DSDX, *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p;
55 index_t *row_index;
56 register dim_t q, s,r;
57 register double rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
58 bool_t add_EM_F, add_EM_S;
59
60 bool_t extendedA=isExpanded(A);
61 bool_t extendedB=isExpanded(B);
62 bool_t extendedC=isExpanded(C);
63 bool_t extendedD=isExpanded(D);
64 bool_t extendedX=isExpanded(X);
65 bool_t extendedY=isExpanded(Y);
66 double *F_p=getSampleData(F,0);
67 double *S=p.row_jac->ReferenceElement->S;
68 dim_t len_EM_S=p.row_NN*p.col_NN;
69 dim_t len_EM_F=p.row_NN;
70
71
72 #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,rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1,add_EM_F, add_EM_S)
73 {
74 EM_S=THREAD_MEMALLOC(len_EM_S,double);
75 EM_F=THREAD_MEMALLOC(len_EM_F,double);
76 row_index=THREAD_MEMALLOC(p.row_NN,index_t);
77
78 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
79
80 for (color=elements->minColor;color<=elements->maxColor;color++) {
81 /* open loop over all elements: */
82 #pragma omp for private(e) schedule(static)
83 for(e=0;e<elements->numElements;e++){
84 if (elements->Color[e]==color) {
85 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
86 DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
87 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
88 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
89 add_EM_F=FALSE;
90 add_EM_S=FALSE;
91 /**************************************************************/
92 /* process A: */
93 /**************************************************************/
94 A_p=getSampleData(A,e);
95 if (NULL!=A_p) {
96 add_EM_S=TRUE;
97 if (extendedA) {
98 for (s=0;s<p.row_NS;s++) {
99 for (r=0;r<p.col_NS;r++) {
100 rtmp=0;
101 for (q=0;q<p.numQuad;q++) {
102 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
103 + DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
104 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
105 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)] );
106 }
107 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
108 }
109 }
110 } else {
111 for (s=0;s<p.row_NS;s++) {
112 for (r=0;r<p.col_NS;r++) {
113 rtmp00=0;
114 rtmp01=0;
115 rtmp10=0;
116 rtmp11=0;
117 for (q=0;q<p.numQuad;q++) {
118 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
119 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
120 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
121 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
122 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
123 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
124 }
125 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
126 + rtmp01*A_p[INDEX2(0,1,DIM)]
127 + rtmp10*A_p[INDEX2(1,0,DIM)]
128 + rtmp11*A_p[INDEX2(1,1,DIM)];
129 }
130 }
131 }
132 }
133 /**************************************************************/
134 /* process B: */
135 /**************************************************************/
136 B_p=getSampleData(B,e);
137 if (NULL!=B_p) {
138 add_EM_S=TRUE;
139 if (extendedB) {
140 for (s=0;s<p.row_NS;s++) {
141 for (r=0;r<p.col_NS;r++) {
142 rtmp=0.;
143 for (q=0;q<p.numQuad;q++) {
144 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX2(0,q,DIM)]
145 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX2(1,q,DIM)]);
146 }
147 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
148 }
149 }
150 } else {
151 for (s=0;s<p.row_NS;s++) {
152 for (r=0;r<p.col_NS;r++) {
153 rtmp0=0;
154 rtmp1=0;
155 for (q=0;q<p.numQuad;q++) {
156 rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
157 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
158 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
159 }
160 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
161 }
162 }
163 }
164 }
165 /**************************************************************/
166 /* process C: */
167 /**************************************************************/
168 C_p=getSampleData(C,e);
169 if (NULL!=C_p) {
170 add_EM_S=TRUE;
171 if (extendedC) {
172 for (s=0;s<p.row_NS;s++) {
173 for (r=0;r<p.col_NS;r++) {
174 rtmp=0;
175 for (q=0;q<p.numQuad;q++) {
176 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*(C_p[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
177 + C_p[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
178 }
179 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
180 }
181 }
182 } else {
183 for (s=0;s<p.row_NS;s++) {
184 for (r=0;r<p.col_NS;r++) {
185 rtmp0=0;
186 rtmp1=0;
187 for (q=0;q<p.numQuad;q++) {
188 rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
189 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
190 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
191 }
192 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
193 }
194 }
195 }
196 }
197 /************************************************************* */
198 /* process D */
199 /**************************************************************/
200 D_p=getSampleData(D,e);
201 if (NULL!=D_p) {
202 add_EM_S=TRUE;
203 if (extendedD) {
204 for (s=0;s<p.row_NS;s++) {
205 for (r=0;r<p.col_NS;r++) {
206 rtmp=0;
207 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[q]*S[INDEX2(r,q,p.row_NS)];
208 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
209 }
210 }
211 } else {
212 for (s=0;s<p.row_NS;s++) {
213 for (r=0;r<p.col_NS;r++) {
214 rtmp=0;
215 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
216 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[0];
217 }
218 }
219 }
220 }
221 /**************************************************************/
222 /* process X: */
223 /**************************************************************/
224 X_p=getSampleData(X,e);
225 if (NULL!=X_p) {
226 add_EM_F=TRUE;
227 if (extendedX) {
228 for (s=0;s<p.row_NS;s++) {
229 rtmp=0.;
230 for (q=0;q<p.numQuad;q++) {
231 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX2(0,q,DIM)]
232 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX2(1,q,DIM)]);
233 }
234 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
235 }
236 } else {
237 for (s=0;s<p.row_NS;s++) {
238 rtmp0=0.;
239 rtmp1=0.;
240 for (q=0;q<p.numQuad;q++) {
241 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
242 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
243 }
244 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
245 }
246 }
247 }
248 /**************************************************************/
249 /* process Y: */
250 /**************************************************************/
251 Y_p=getSampleData(Y,e);
252 if (NULL!=Y_p) {
253 add_EM_F=TRUE;
254 if (extendedY) {
255 for (s=0;s<p.row_NS;s++) {
256 rtmp=0;
257 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
258 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
259 }
260 } else {
261 for (s=0;s<p.row_NS;s++) {
262 rtmp=0;
263 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
264 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
265 }
266 }
267 }
268 /***********************************************************************************************/
269 /* add the element matrices onto the matrix and right hand side */
270 /***********************************************************************************************/
271 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
272 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
273 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
274
275 } /* end color check */
276 } /* end element loop */
277 } /* end color loop */
278
279 THREAD_MEMFREE(EM_S);
280 THREAD_MEMFREE(EM_F);
281 THREAD_MEMFREE(row_index);
282
283 } /* end of pointer check */
284 } /* end parallel region */
285 }
286 /*
287 * $Log$
288 */

  ViewVC Help
Powered by ViewVC 1.1.26