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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26