/[escript]/branches/doubleplusgood/dudley/src/Assemble_PDE_Single2_1D.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/dudley/src/Assemble_PDE_Single2_1D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3184 - (show annotations)
Wed Sep 15 00:23:42 2010 UTC (8 years, 7 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/Assemble_PDE_Single2_1D.c
File MIME type: text/plain
File size: 13348 byte(s)
Removed volume from ElementFile_Jacobeans

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_{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 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 = 1 x 1 */
29 /* B = 1 */
30 /* C = 1 */
31 /* D = scalar */
32 /* X = 1 */
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
48 void Dudley_Assemble_PDE_Single2_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, *DSDX;
57 index_t *row_index;
58 register dim_t q, s,r;
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;
71 dim_t len_EM_F=p.row_numShapesTotal;
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,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
80 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
81
82 for (color=elements->minColor;color<=elements->maxColor;color++) {
83 /* open loop over all elements: */
84 #pragma omp for private(e) schedule(static)
85 for(e=0;e<elements->numElements;e++){
86 if (elements->Color[e]==color) {
87
88 A_p=getSampleDataRO(A,e);
89 C_p=getSampleDataRO(C,e);
90 B_p=getSampleDataRO(B,e);
91 D_p=getSampleDataRO(D,e);
92 X_p=getSampleDataRO(X,e);
93 Y_p=getSampleDataRO(Y,e);
94
95 double vol=p.row_jac->absD[e]*p.row_jac->quadweight;
96 // Vol=&(p.row_jac->volume[INDEX3(0,0,e, p.numQuadTotal,1)]);
97 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e, p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
98 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
99 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
100 add_EM_F=FALSE;
101 add_EM_S=FALSE;
102 /**************************************************************/
103 /* process A: */
104 /**************************************************************/
105 if (NULL!=A_p) {
106 add_EM_S=TRUE;
107 if (extendedA) {
108 A_q=&(A_p[INDEX4(0,0,0,0, DIM,DIM,p.numQuadTotal)]);
109 for (s=0;s<p.row_numShapes;s++) {
110 for (r=0;r<p.col_numShapes;r++) {
111 rtmp=0;
112 for (q=0;q<p.numQuadTotal;q++) {
113 rtmp+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
114 }
115 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
116 }
117 }
118 } else {
119 for (s=0;s<p.row_numShapes;s++) {
120 for (r=0;r<p.col_numShapes;r++) {
121 rtmp=0;
122 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
123 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX2(0,0,DIM)];
124 }
125 }
126 }
127 }
128 /**************************************************************/
129 /* process B: */
130 /**************************************************************/
131 if (NULL!=B_p) {
132 add_EM_S=TRUE;
133 if (extendedB) {
134 B_q=&(B_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
135 for (s=0;s<p.row_numShapes;s++) {
136 for (r=0;r<p.col_numShapes;r++) {
137 rtmp=0;
138 for (q=0;q<p.numQuadTotal;q++) {
139 rtmp+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
140 }
141 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
142 }
143 }
144 } else {
145 for (s=0;s<p.row_numShapes;s++) {
146 for (r=0;r<p.col_numShapes;r++) {
147 rtmp=0;
148 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
149 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[0];
150 }
151 }
152 }
153 }
154 /**************************************************************/
155 /* process C: */
156 /**************************************************************/
157 if (NULL!=C_p) {
158 add_EM_S=TRUE;
159 if (extendedC) {
160 C_q=&(C_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
161 for (s=0;s<p.row_numShapes;s++) {
162 for (r=0;r<p.col_numShapes;r++) {
163 rtmp=0;
164 for (q=0;q<p.numQuadTotal;q++) {
165 rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
166 }
167 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
168 }
169 }
170 } else {
171 for (s=0;s<p.row_numShapes;s++) {
172 for (r=0;r<p.col_numShapes;r++) {
173 rtmp=0;
174 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
175 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[0];
176 }
177 }
178 }
179 }
180 /************************************************************* */
181 /* process D */
182 /**************************************************************/
183 if (NULL!=D_p) {
184 add_EM_S=TRUE;
185 if (extendedD) {
186 D_q=&(D_p[INDEX2(0,0, p.numQuadTotal)]);
187 for (s=0;s<p.row_numShapes;s++) {
188 for (r=0;r<p.col_numShapes;r++) {
189 rtmp=0;
190 for (q=0;q<p.numQuadTotal;q++) {
191 rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
192 }
193 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
194 }
195 }
196 } else {
197 for (s=0;s<p.row_numShapes;s++) {
198 for (r=0;r<p.col_numShapes;r++) {
199 rtmp=0;
200 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
201 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
202 }
203 }
204 }
205 }
206 /**************************************************************/
207 /* process X: */
208 /**************************************************************/
209 if (NULL!=X_p) {
210 add_EM_F=TRUE;
211 if (extendedX) {
212 X_q=&(X_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
213 for (s=0;s<p.row_numShapes;s++) {
214 rtmp=0;
215 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)];
216 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
217 }
218 } else {
219 for (s=0;s<p.row_numShapes;s++) {
220 rtmp=0;
221 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*DSDX[INDEX3(s,0,q, p.row_numShapesTotal,DIM)];
222 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*X_p[0];
223 }
224 }
225 }
226 /**************************************************************/
227 /* process Y: */
228 /**************************************************************/
229 if (NULL!=Y_p) {
230 add_EM_F=TRUE;
231 if (extendedY) {
232 Y_q=&(Y_p[INDEX2(0,0, p.numQuadTotal)]);
233 for (s=0;s<p.row_numShapes;s++) {
234 rtmp=0;
235 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
236 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
237 }
238 } else {
239 for (s=0;s<p.row_numShapes;s++) {
240 rtmp=0;
241 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)];
242 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
243 }
244 }
245 }
246 /***********************************************************************************************/
247 /* add the element matrices onto the matrix and right hand side */
248 /***********************************************************************************************/
249 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(q,e,p.NN)]];
250
251 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
252 if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
253
254 } /* end color check */
255 } /* end element loop */
256 } /* end color loop */
257
258 THREAD_MEMFREE(EM_S); /* these FREEs appear to be inside the if because if any of the allocs */
259 THREAD_MEMFREE(EM_F); /* failed it means an out of memory (which is not recoverable anyway) */
260 THREAD_MEMFREE(row_index);
261
262 } /* end of pointer check */
263 } /* end parallel region */
264 }
265 /*
266 * $Log$
267 */

  ViewVC Help
Powered by ViewVC 1.1.26