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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4327 - (show annotations)
Wed Mar 20 05:09:11 2013 UTC (6 years, 7 months ago) by jfenwick
File size: 13895 byte(s)
some finley memory
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* assembles the system of numEq PDEs into the stiffness matrix S and right hand side F */
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 Finley_Assemble_PDE_Single2_1D(Finley_Assemble_Parameters p,
49 Finley_ElementFile* elements,
50 Paso_SystemMatrix* Mat, escriptDataC* F,
51 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
52
53 #define DIM 1
54 index_t color;
55 dim_t e, isub;
56 __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;
57 double *EM_S, *EM_F, *Vol, *DSDX;
58 index_t *row_index;
59 register dim_t q, s,r;
60 register double rtmp;
61 bool_t add_EM_F, add_EM_S;
62
63 bool_t extendedA=isExpanded(A);
64 bool_t extendedB=isExpanded(B);
65 bool_t extendedC=isExpanded(C);
66 bool_t extendedD=isExpanded(D);
67 bool_t extendedX=isExpanded(X);
68 bool_t extendedY=isExpanded(Y);
69 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
70 double *S=p.row_jac->BasisFunctions->S;
71 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal;
72 dim_t len_EM_F=p.row_numShapesTotal;
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, A_q, B_q, C_q, D_q, X_q, Y_q, row_index, q, s,r,rtmp,add_EM_F, add_EM_S, isub)
75 {
76 EM_S=new double[len_EM_S];
77 EM_F=new double[len_EM_F];
78 row_index=new index_t[p.row_numShapesTotal];
79
80
81 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
82
83 for (color=elements->minColor;color<=elements->maxColor;color++) {
84 /* open loop over all elements: */
85 #pragma omp for private(e) schedule(static)
86 for(e=0;e<elements->numElements;e++){
87 if (elements->Color[e]==color) {
88
89 A_p=getSampleDataRO(A,e);
90 C_p=getSampleDataRO(C,e);
91 B_p=getSampleDataRO(B,e);
92 D_p=getSampleDataRO(D,e);
93 X_p=getSampleDataRO(X,e);
94 Y_p=getSampleDataRO(Y,e);
95
96 for (isub=0; isub<p.numSub; isub++) {
97 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
98 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
99 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
100 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
101 add_EM_F=FALSE;
102 add_EM_S=FALSE;
103 /************************************************************************************/
104 /* process A: */
105 /************************************************************************************/
106 if (NULL!=A_p) {
107 add_EM_S=TRUE;
108 if (extendedA) {
109 A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
110 for (s=0;s<p.row_numShapes;s++) {
111 for (r=0;r<p.col_numShapes;r++) {
112 rtmp=0;
113 for (q=0;q<p.numQuadSub;q++) {
114 rtmp+=Vol[q]*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)];
115 }
116 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
117 }
118 }
119 } else {
120 for (s=0;s<p.row_numShapes;s++) {
121 for (r=0;r<p.col_numShapes;r++) {
122 rtmp=0;
123 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
124 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX2(0,0,DIM)];
125 }
126 }
127 }
128 }
129 /************************************************************************************/
130 /* process B: */
131 /************************************************************************************/
132 if (NULL!=B_p) {
133 add_EM_S=TRUE;
134 if (extendedB) {
135 B_q=&(B_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
136 for (s=0;s<p.row_numShapes;s++) {
137 for (r=0;r<p.col_numShapes;r++) {
138 rtmp=0;
139 for (q=0;q<p.numQuadSub;q++) {
140 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
141 }
142 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
143 }
144 }
145 } else {
146 for (s=0;s<p.row_numShapes;s++) {
147 for (r=0;r<p.col_numShapes;r++) {
148 rtmp=0;
149 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
150 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[0];
151 }
152 }
153 }
154 }
155 /************************************************************************************/
156 /* process C: */
157 /************************************************************************************/
158 if (NULL!=C_p) {
159 add_EM_S=TRUE;
160 if (extendedC) {
161 C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
162 for (s=0;s<p.row_numShapes;s++) {
163 for (r=0;r<p.col_numShapes;r++) {
164 rtmp=0;
165 for (q=0;q<p.numQuadSub;q++) {
166 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
167 }
168 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
169 }
170 }
171 } else {
172 for (s=0;s<p.row_numShapes;s++) {
173 for (r=0;r<p.col_numShapes;r++) {
174 rtmp=0;
175 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
176 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[0];
177 }
178 }
179 }
180 }
181 /*********************************************************************************** */
182 /* process D */
183 /************************************************************************************/
184 if (NULL!=D_p) {
185 add_EM_S=TRUE;
186 if (extendedD) {
187 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
188 for (s=0;s<p.row_numShapes;s++) {
189 for (r=0;r<p.col_numShapes;r++) {
190 rtmp=0;
191 for (q=0;q<p.numQuadSub;q++) {
192 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
193 }
194 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
195 }
196 }
197 } else {
198 for (s=0;s<p.row_numShapes;s++) {
199 for (r=0;r<p.col_numShapes;r++) {
200 rtmp=0;
201 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
202 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
203 }
204 }
205 }
206 }
207 /************************************************************************************/
208 /* process X: */
209 /************************************************************************************/
210 if (NULL!=X_p) {
211 add_EM_F=TRUE;
212 if (extendedX) {
213 X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
214 for (s=0;s<p.row_numShapes;s++) {
215 rtmp=0;
216 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)];
217 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
218 }
219 } else {
220 for (s=0;s<p.row_numShapes;s++) {
221 rtmp=0;
222 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q, p.row_numShapesTotal,DIM)];
223 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*X_p[0];
224 }
225 }
226 }
227 /************************************************************************************/
228 /* process Y: */
229 /************************************************************************************/
230 if (NULL!=Y_p) {
231 add_EM_F=TRUE;
232 if (extendedY) {
233 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
234 for (s=0;s<p.row_numShapes;s++) {
235 rtmp=0;
236 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
237 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
238 }
239 } else {
240 for (s=0;s<p.row_numShapes;s++) {
241 rtmp=0;
242 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
243 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
244 }
245 }
246 }
247 /*********************************************************************************************************************/
248 /* add the element matrices onto the matrix and right hand side */
249 /*********************************************************************************************************************/
250 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
251
252 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
253 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
254 } /* end of isub */
255
256 } /* end color check */
257 } /* end element loop */
258 } /* end color loop */
259
260 delete[] EM_S; /* these FREEs appear to be inside the if because if any of the allocs */
261 delete[] EM_F; /* failed it means an out of memory (which is not recoverable anyway) */
262 delete[] row_index;
263
264 } /* end of pointer check */
265 } /* end parallel region */
266 }
267 /*
268 * $Log$
269 */

  ViewVC Help
Powered by ViewVC 1.1.26