/[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 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 7764 byte(s)
Merging dudley and scons updates from branches

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 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(Finley_Assemble_Parameters p,
43 Finley_ElementFile* elements,
44 Paso_SystemMatrix* Mat, escriptDataC* F, escriptDataC* D, escriptDataC* Y) {
45
46 index_t color;
47 dim_t e, isub;
48 __const double *D_p, *Y_p, *D_q, *Y_q;
49 double *EM_S, *EM_F, *Vol;
50 index_t *row_index;
51 register dim_t q, s,r;
52 register double rtmp, rtmp_D;
53 bool_t add_EM_F, add_EM_S;
54
55 bool_t extendedD=isExpanded(D);
56 bool_t extendedY=isExpanded(Y);
57 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
58 double *S=p.row_jac->BasisFunctions->S;
59
60 #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)
61 {
62 EM_S=THREAD_MEMALLOC(p.row_numShapesTotal*p.col_numShapesTotal,double);
63 EM_F=THREAD_MEMALLOC(p.row_numShapesTotal,double);
64 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
65
66 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
67
68 for (color=elements->minColor;color<=elements->maxColor;color++) {
69 /* open loop over all elements: */
70 #pragma omp for private(e) schedule(static)
71 for(e=0;e<elements->numElements;e++){
72 if (elements->Color[e]==color) {
73
74 D_p=getSampleDataRO(D,e);
75 Y_p=getSampleDataRO(Y,e);
76
77 for (isub=0; isub<p.numSub; isub++) {
78
79 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
80 add_EM_F=FALSE;
81 add_EM_S=FALSE;
82
83 /************************************************************* */
84 /* process D */
85 /**************************************************************/
86
87 if (NULL!=D_p) {
88 add_EM_S=TRUE;
89 if (extendedD) {
90 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
91 for (s=0;s<p.row_numShapes;s++) {
92 for (r=0;r<p.col_numShapes;r++) {
93 rtmp=0;
94 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)];
95 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
96 EM_S[INDEX4(0,0,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
97 EM_S[INDEX4(0,0,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp;
98 EM_S[INDEX4(0,0,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp;
99 }
100 }
101 } else {
102 for (s=0;s<p.row_numShapes;s++) {
103 for (r=0;r<p.col_numShapes;r++) {
104 rtmp=0;
105 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
106 rtmp_D=rtmp*D_p[0];
107 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
108 EM_S[INDEX4(0,0,s ,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
109 EM_S[INDEX4(0,0,s+p.row_numShapes,r ,p.numEqu,p.numComp,p.row_numShapesTotal)]=-rtmp_D;
110 EM_S[INDEX4(0,0,s+p.row_numShapes,r+p.col_numShapes,p.numEqu,p.numComp,p.row_numShapesTotal)]= rtmp_D;
111 }
112 }
113 }
114 }
115 /**************************************************************/
116 /* process Y: */
117 /**************************************************************/
118
119 if (NULL!=Y_p) {
120 add_EM_F=TRUE;
121 if (extendedY) {
122 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
123 for (s=0;s<p.row_numShapes;s++) {
124 rtmp=0;
125 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
126 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp;
127 EM_F[INDEX2(0,s+p.row_numShapes,p.numEqu)]= rtmp;
128 }
129 } else {
130 for (s=0;s<p.row_numShapes;s++) {
131 rtmp=0;
132 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
133 rtmp_D=rtmp*Y_p[0];
134 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp_D;
135 EM_F[INDEX2(0,s+p.row_numShapes,p.numEqu)]= rtmp_D;
136 }
137 }
138 }
139 /***********************************************************************************************/
140 /* add the element matrices onto the matrix and right hand side */
141 /***********************************************************************************************/
142 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)]];
143
144 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
145 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
146
147 } /* end of isub */
148 } /* end color check */
149 } /* end element loop */
150 } /* end color loop */
151
152 THREAD_MEMFREE(EM_S);
153 THREAD_MEMFREE(EM_F);
154 THREAD_MEMFREE(row_index);
155
156 } /* end of pointer check */
157 } /* end parallel region */
158 }
159 /*
160 * $Log$
161 */

  ViewVC Help
Powered by ViewVC 1.1.26