/[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 2271 - (show annotations)
Mon Feb 16 05:08:29 2009 UTC (10 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 7047 byte(s)
Merging version 2269 to trunk

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 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;
47 __const double *D_p, *Y_p;
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->ReferenceElement->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,row_index,q, s,r,rtmp, rtmp_D,add_EM_F, add_EM_S)
62 {
63 EM_S=THREAD_MEMALLOC(p.row_NN*p.col_NN,double);
64 EM_F=THREAD_MEMALLOC(p.row_NN,double);
65 row_index=THREAD_MEMALLOC(p.row_NN,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 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
75 add_EM_F=FALSE;
76 add_EM_S=FALSE;
77 /************************************************************* */
78 /* process D */
79 /**************************************************************/
80 D_p=getSampleDataRO(D,e,DBuff);
81 if (NULL!=D_p) {
82 add_EM_S=TRUE;
83 if (extendedD) {
84 for (s=0;s<p.row_NS;s++) {
85 for (r=0;r<p.col_NS;r++) {
86 rtmp=0;
87 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[q]*S[INDEX2(r,q,p.row_NS)];
88 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_NN)]= rtmp;
89 EM_S[INDEX4(0,0,s ,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]=-rtmp;
90 EM_S[INDEX4(0,0,s+p.row_NS,r ,p.numEqu,p.numComp,p.row_NN)]=-rtmp;
91 EM_S[INDEX4(0,0,s+p.row_NS,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]= rtmp;
92 }
93 }
94 } else {
95 for (s=0;s<p.row_NS;s++) {
96 for (r=0;r<p.col_NS;r++) {
97 rtmp=0;
98 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
99 rtmp_D=rtmp*D_p[0];
100 EM_S[INDEX4(0,0,s ,r ,p.numEqu,p.numComp,p.row_NN)]= rtmp_D;
101 EM_S[INDEX4(0,0,s ,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]=-rtmp_D;
102 EM_S[INDEX4(0,0,s+p.row_NS,r ,p.numEqu,p.numComp,p.row_NN)]=-rtmp_D;
103 EM_S[INDEX4(0,0,s+p.row_NS,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]= rtmp_D;
104 }
105 }
106 }
107 }
108 /**************************************************************/
109 /* process Y: */
110 /**************************************************************/
111 Y_p=getSampleDataRO(Y,e,YBuff);
112 if (NULL!=Y_p) {
113 add_EM_F=TRUE;
114 if (extendedY) {
115 for (s=0;s<p.row_NS;s++) {
116 rtmp=0;
117 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
118 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp;
119 EM_F[INDEX2(0,s+p.row_NS,p.numEqu)]= rtmp;
120 }
121 } else {
122 for (s=0;s<p.row_NS;s++) {
123 rtmp=0;
124 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
125 rtmp_D=rtmp*Y_p[0];
126 EM_F[INDEX2(0,s ,p.numEqu)]=-rtmp_D;
127 EM_F[INDEX2(0,s+p.row_NS,p.numEqu)]= rtmp_D;
128 }
129 }
130 }
131 /***********************************************************************************************/
132 /* add the element matrices onto the matrix and right hand side */
133 /***********************************************************************************************/
134 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.row_NN)]];
135
136 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
137 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
138
139 } /* end color check */
140 } /* end element loop */
141 } /* end color loop */
142
143 THREAD_MEMFREE(EM_S);
144 THREAD_MEMFREE(EM_F);
145 THREAD_MEMFREE(row_index);
146
147 } /* end of pointer check */
148 } /* end parallel region */
149 freeSampleBuffer(DBuff);
150 freeSampleBuffer(YBuff);
151 }
152 /*
153 * $Log$
154 */

  ViewVC Help
Powered by ViewVC 1.1.26