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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years, 6 months ago) by gross
File MIME type: text/plain
File size: 7865 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 a single PDEs into the stiffness matrix S right hand side F */
18
19 /* D u_m and Y */
20
21 /* 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 = scalar */
27 /* Y = scalar */
28
29
30 /**************************************************************/
31
32
33 #include "Assemble.h"
34 #include "Util.h"
35 #ifdef _OPENMP
36 #include <omp.h>
37 #endif
38
39
40 /**************************************************************/
41
42 void Finley_Assemble_PDE_Single2_C(Assemble_Parameters p, Finley_ElementFile* elements,
43 Paso_SystemMatrix* Mat, escriptDataC* F, escriptDataC* D, escriptDataC* Y) {
44
45 index_t color;
46 dim_t e, isub;
47 __const double *D_p, *Y_p, *D_q, *Y_q;
48 double *EM_S, *EM_F, *Vol;
49 index_t *row_index;
50 register dim_t q, s,r;
51 register double rtmp, rtmp_D;
52 bool_t add_EM_F, add_EM_S;
53
54 bool_t extendedD=isExpanded(D);
55 bool_t extendedY=isExpanded(Y);
56 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
57 double *S=p.row_jac->BasisFunctions->S;
58
59 void* DBuff=allocSampleBuffer(D);
60 void* YBuff=allocSampleBuffer(Y);
61 #pragma omp parallel private(color,EM_S, EM_F, Vol, D_p, Y_p, D_q, Y_q,row_index,q, s,r,rtmp, rtmp_D,add_EM_F, add_EM_S, isub)
62 {
63 EM_S=THREAD_MEMALLOC(p.row_numShapesTotal*p.col_numShapesTotal,double);
64 EM_F=THREAD_MEMALLOC(p.row_numShapesTotal,double);
65 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
66
67 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
68
69 for (color=elements->minColor;color<=elements->maxColor;color++) {
70 /* open loop over all elements: */
71 #pragma omp for private(e) schedule(static)
72 for(e=0;e<elements->numElements;e++){
73 if (elements->Color[e]==color) {
74
75 D_p=getSampleDataRO(D,e,DBuff);
76 Y_p=getSampleDataRO(Y,e,YBuff);
77
78 for (isub=0; isub<p.numSub; isub++) {
79
80 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
81 add_EM_F=FALSE;
82 add_EM_S=FALSE;
83
84 /************************************************************* */
85 /* process D */
86 /**************************************************************/
87
88 if (NULL!=D_p) {
89 add_EM_S=TRUE;
90 if (extendedD) {
91 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
92 for (s=0;s<p.row_numShapes;s++) {
93 for (r=0;r<p.col_numShapes;r++) {
94 rtmp=0;
95 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
96 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
97 EM_S[INDEX4(0,0,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
98 EM_S[INDEX4(0,0,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
99 EM_S[INDEX4(0,0,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
100 }
101 }
102 } else {
103 for (s=0;s<p.row_numShapes;s++) {
104 for (r=0;r<p.col_numShapes;r++) {
105 rtmp=0;
106 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
107 rtmp_D=rtmp*D_p[0];
108 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
109 EM_S[INDEX4(0,0,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
110 EM_S[INDEX4(0,0,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
111 EM_S[INDEX4(0,0,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
112 }
113 }
114 }
115 }
116 /**************************************************************/
117 /* process Y: */
118 /**************************************************************/
119
120 if (NULL!=Y_p) {
121 add_EM_F=TRUE;
122 if (extendedY) {
123 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
124 for (s=0;s<p.row_numShapes;s++) {
125 rtmp=0;
126 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
127 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp;
128 EM_F[INDEX2(0,s+p.row_numShapes,p.numEqu)]= rtmp;
129 }
130 } else {
131 for (s=0;s<p.row_numShapes;s++) {
132 rtmp=0;
133 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
134 rtmp_D=rtmp*Y_p[0];
135 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp_D;
136 EM_F[INDEX2(0,s+p.row_numShapes,p.numEqu)]= rtmp_D;
137 }
138 }
139 }
140 /***********************************************************************************************/
141 /* add the element matrices onto the matrix and right hand side */
142 /***********************************************************************************************/
143 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)]];
144
145 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
146 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
147
148 } /* end of isub */
149 } /* end color check */
150 } /* end element loop */
151 } /* end color loop */
152
153 THREAD_MEMFREE(EM_S);
154 THREAD_MEMFREE(EM_F);
155 THREAD_MEMFREE(row_index);
156
157 } /* end of pointer check */
158 } /* end parallel region */
159 freeSampleBuffer(DBuff);
160 freeSampleBuffer(YBuff);
161 }
162 /*
163 * $Log$
164 */

  ViewVC Help
Powered by ViewVC 1.1.26