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

  ViewVC Help
Powered by ViewVC 1.1.26