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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years ago) by gross
File MIME type: text/plain
File size: 8947 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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
19 /* D_{k,m} u_m and Y_k */
20
21 /* u has p.numComp components in a 3D domain. The shape functions for test and solution must be identical */
22 /* and 2* row_NS == row_NN (contact elements) */
23
24 /* Shape of the coefficients: */
25
26 /* D = p.numEqu x p.numComp */
27 /* Y = p.numEqu */
28
29
30 /**************************************************************/
31
32 /* Author: Lutz Gross, l.gross@uq.edu.au */
33 /* Version: $Id:$ */
34
35 /**************************************************************/
36
37
38 #include "Assemble.h"
39 #include "Util.h"
40 #ifdef _OPENMP
41 #include <omp.h>
42 #endif
43
44
45 /**************************************************************/
46
47 void Finley_Assemble_PDE_System2_C(Assemble_Parameters p, Finley_ElementFile* elements,
48 Paso_SystemMatrix* Mat, escriptDataC* F, escriptDataC* D, escriptDataC* Y) {
49
50 index_t color;
51 dim_t e, isub;
52 __const double *D_p, *Y_p, *D_q, *Y_q;
53 double *EM_S, *EM_F, *Vol;
54 index_t *row_index;
55 register dim_t q, s,r,k,m;
56 register double rtmp, rtmp_D;
57 bool_t add_EM_F, add_EM_S;
58
59 bool_t extendedD=isExpanded(D);
60 bool_t extendedY=isExpanded(Y);
61 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
62 double *S=p.row_jac->BasisFunctions->S;
63
64 void* DBuff=allocSampleBuffer(D);
65 void* YBuff=allocSampleBuffer(Y);
66 #pragma omp parallel private(color,EM_S, EM_F, Vol, D_p, Y_p, D_q, Y_q, row_index,q, s,r,k,m,rtmp, rtmp_D,add_EM_F, add_EM_S, isub)
67 {
68 EM_S=THREAD_MEMALLOC(p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp,double);
69 EM_F=THREAD_MEMALLOC(p.row_numShapesTotal*p.numEqu,double);
70 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
71
72 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
73
74 for (color=elements->minColor;color<=elements->maxColor;color++) {
75 /* open loop over all elements: */
76 #pragma omp for private(e) schedule(static)
77 for(e=0;e<elements->numElements;e++){
78 if (elements->Color[e]==color) {
79
80 D_p=getSampleDataRO(D,e,DBuff);
81 Y_p=getSampleDataRO(Y,e,YBuff);
82
83 for (isub=0; isub<p.numSub; isub++) {
84
85 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
86 add_EM_F=FALSE;
87 add_EM_S=FALSE;
88
89 /*************************************************************/
90 /* process D */
91 /**************************************************************/
92 if (NULL!=D_p) {
93 add_EM_S=TRUE;
94 if (extendedD) {
95 D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp, p.numQuadSub)]);
96 for (s=0;s<p.row_numShapes;s++) {
97 for (r=0;r<p.col_numShapes;r++) {
98 for (k=0;k<p.numEqu;k++) {
99 for (m=0;m<p.numComp;m++) {
100 rtmp=0;
101 for (q=0;q<p.numQuadSub;q++) {
102 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)];
103 }
104 EM_S[INDEX4(k,m,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
105 EM_S[INDEX4(k,m,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
106 EM_S[INDEX4(k,m,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
107 EM_S[INDEX4(k,m,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
108 }
109 }
110 }
111 }
112 } else {
113 for (s=0;s<p.row_numShapes;s++) {
114 for (r=0;r<p.col_numShapes;r++) {
115 rtmp=0;
116 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
117 for (k=0;k<p.numEqu;k++) {
118 for (m=0;m<p.numComp;m++) {
119 rtmp_D=rtmp*D_p[INDEX2(k,m,p.numEqu)];
120 EM_S[INDEX4(k,m,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
121 EM_S[INDEX4(k,m,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
122 EM_S[INDEX4(k,m,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
123 EM_S[INDEX4(k,m,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
124 }
125 }
126 }
127 }
128 }
129 }
130 /**************************************************************/
131 /* process Y: */
132 /**************************************************************/
133 if (NULL!=Y_p) {
134 add_EM_F=TRUE;
135 if (extendedY) {
136 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
137 for (s=0;s<p.row_numShapes;s++) {
138 for (k=0;k<p.numEqu;k++) {
139 rtmp=0;
140 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
141 EM_F[INDEX2(k,s ,p.numEqu)]=-rtmp;
142 EM_F[INDEX2(k,s+p.row_numShapes,p.numEqu)]= rtmp;
143 }
144 }
145 } else {
146 for (s=0;s<p.row_numShapes;s++) {
147 rtmp=0;
148 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
149 for (k=0;k<p.numEqu;k++) {
150 rtmp_D=rtmp*Y_p[k];
151 EM_F[INDEX2(k,s ,p.numEqu)]=-rtmp_D;
152 EM_F[INDEX2(k,s+p.row_numShapes,p.numEqu)]= rtmp_D;
153 }
154 }
155 }
156 }
157 /***********************************************************************************************/
158 /* add the element matrices onto the matrix and right hand side */
159 /***********************************************************************************************/
160 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)] ];
161
162 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
163 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
164
165 } /* end of isub */
166 } /* end color check */
167 } /* end element loop */
168 } /* end color loop */
169
170 THREAD_MEMFREE(EM_S);
171 THREAD_MEMFREE(EM_F);
172 THREAD_MEMFREE(row_index);
173
174 } /* end of pointer check */
175 } /* end parallel region */
176 freeSampleBuffer(DBuff);
177 freeSampleBuffer(YBuff);
178 }
179

  ViewVC Help
Powered by ViewVC 1.1.26