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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 751 - (show annotations)
Mon Jun 26 01:46:34 2006 UTC (12 years, 10 months ago) by bcumming
File MIME type: text/plain
File size: 8696 byte(s)
Changes relating to the MPI version of escript
The standard OpenMP version of escript is unchanged

- updated data types (Finley_Mesh, Finley_NodeFile, etc) to store meshes
  over multiple MPI processes.
- added CommBuffer code in Paso for communication of Data associated
  with distributed meshes
- updates in Finley and Escript to support distributed data and operations
  on distributed data (such as interpolation).
- construction of RHS in MPI, so that simple explicit schemes (such as
  /docs/examples/wave.py without IO and the Locator) can run in MPI.
- updated mesh generation for first order line, rectangle and brick
  meshes and second order line meshes in MPI.        
- small changes to trunk/SConstruct and trunk/scons/ess_options.py to
  build the MPI version, these changes are turned off by default.

1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* assemblage routines: calculate the gradient of nodal data at quadrature points */
16
17 /**************************************************************/
18
19 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
20 /* author: gross@access.edu.au */
21 /* version: $Id$ */
22
23 /**************************************************************/
24
25 #include "Assemble.h"
26 #include "Util.h"
27 #ifdef _OPENMP
28 #include <omp.h>
29 #endif
30 /*****************************************************************/
31
32
33 #define NODES 0
34 #define DOF 1
35 #define REDUCED_DOF 2
36
37 void Finley_Assemble_gradient(Finley_NodeFile* nodes, Finley_ElementFile* elements,
38 escriptDataC* grad_data,escriptDataC* data) {
39
40 double *local_X=NULL, *local_data=NULL, *dVdv=NULL, *dvdV=NULL, *Vol=NULL, *d_datadv=NULL, *gradS=NULL,*data_array;
41 index_t node_offset,*resort_nodes=FALSE,dof_offset;
42 dim_t numNodes=0,e,i,q,NS_DOF=0,NN_DOF=0;
43 type_t type=DOF;
44 if (nodes==NULL || elements==NULL) return;
45 dim_t NN=elements->ReferenceElement->Type->numNodes;
46 dim_t NS=elements->ReferenceElement->Type->numShapes;
47 index_t id[NN];
48 dim_t numDim=nodes->numDim;
49 type_t data_type=getFunctionSpaceType(data);
50 dim_t numComps=getDataPointSize(data);
51 dim_t numQuad=elements->ReferenceElement->numQuadNodes;
52 for (i=0;i<NN;i++) id[i]=i;
53 Finley_resetError();
54
55 /* set some parameter */
56
57 if (data_type==FINLEY_NODES) {
58 type=NODES;
59 resort_nodes=id;
60 NN_DOF=elements->ReferenceElement->Type->numNodes;
61 NS_DOF=elements->ReferenceElement->Type->numShapes;
62 gradS=elements->ReferenceElement->dSdv;
63 numNodes=nodes->numNodes;
64 }
65 /* lock these two options out for the MPI version */
66 #ifndef PASO_MPI
67 else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {
68 type=DOF;
69 resort_nodes=id;
70 NN_DOF=elements->ReferenceElement->Type->numNodes;
71 NS_DOF=elements->ReferenceElement->Type->numShapes;
72 gradS=elements->ReferenceElement->dSdv;
73 numNodes=nodes->numDegreesOfFreedom;
74 } else if (data_type==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
75 type=REDUCED_DOF;
76 resort_nodes=elements->ReferenceElement->Type->linearNodes;
77 NN_DOF=elements->LinearReferenceElement->Type->numNodes;
78 NS_DOF=elements->LinearReferenceElement->Type->numShapes;
79 gradS=elements->LinearReferenceElement->dSdv;
80 numNodes=nodes->reducedNumDegreesOfFreedom;
81 }
82 #endif
83 else {
84 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: Cannot calculate gradient of data");
85 }
86 if (getFunctionSpaceType(grad_data)==FINLEY_CONTACT_ELEMENTS_2) {
87 node_offset=NN-NS;
88 dof_offset=NN_DOF-NS_DOF;
89 } else {
90 node_offset=0;
91 dof_offset=0;
92 }
93
94 /* check the dimensions of interpolated_data and data */
95
96 if (numDim!=elements->ReferenceElement->Type->numDim) {
97 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: Spatial and element dimension must match.");
98 } else if (! numSamplesEqual(grad_data,numQuad,elements->numElements)) {
99 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of samples in gradient Data object");
100 } else if (! numSamplesEqual(data,1,numNodes)) {
101 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of samples of input Data object");
102 } else if (numDim*numComps!=getDataPointSize(grad_data)) {
103 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of components in gradient data object.");
104 } else if (!isExpanded(grad_data)) {
105 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: expanded Data object is expected for output data.");
106 }
107
108 /* now we can start */
109
110 if (Finley_noError()) {
111 #pragma omp parallel private(local_X,local_data,dvdV,dVdv,Vol,d_datadv)
112 {
113 local_X=local_data=dVdv=dvdV=Vol=d_datadv=NULL;
114 /* allocation of work arrays */
115 local_X=THREAD_MEMALLOC(NS*numDim,double);
116 local_data=THREAD_MEMALLOC(NS*numComps,double);
117 dVdv=THREAD_MEMALLOC(numQuad*numDim*numDim,double);
118 dvdV=THREAD_MEMALLOC(numQuad*numDim*numDim,double);
119 Vol=THREAD_MEMALLOC(numQuad,double);
120 d_datadv=THREAD_MEMALLOC(numQuad*numComps*numDim,double);
121 if (!(Finley_checkPtr(local_X) || Finley_checkPtr(dVdv) || Finley_checkPtr(dvdV) || Finley_checkPtr(Vol) || Finley_checkPtr(d_datadv) || Finley_checkPtr(local_data) )) {
122 /* open the element loop */
123 #pragma omp for private(e,i,q,data_array) schedule(static)
124 for(e=0;e<elements->numElements;e++) {
125 /* gather local coordinates of nodes into local_X: */
126 Finley_Util_Gather_double(NS,&(elements->Nodes[INDEX2(node_offset,e,NN)]),numDim,nodes->Coordinates,local_X);
127 /* calculate dVdv(i,j,q)=local_X(i,n)*DSDv(n,j,q) */
128 Finley_Util_SmallMatMult(numDim,numDim*numQuad,dVdv,NS,local_X,elements->ReferenceElement->dSdv);
129 /* dvdV=invert(dVdv) */
130 Finley_Util_InvertSmallMat(numQuad,numDim,dVdv,dvdV,Vol);
131 /* gather local data into local_data(numComps,NS_DOF): */
132 switch (type) {
133 case NODES:
134 for (q=0;q<NS_DOF;q++) {
135 i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];
136 data_array=getSampleData(data,i);
137 Finley_copyDouble(numComps,data_array,local_data+q*numComps);
138 }
139 break;
140 case DOF:
141 for (q=0;q<NS_DOF;q++) {
142 i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];
143 data_array=getSampleData(data,nodes->degreeOfFreedom[i]);
144 Finley_copyDouble(numComps,data_array,local_data+q*numComps);
145
146 }
147 break;
148 case REDUCED_DOF:
149 for (q=0;q<NS_DOF;q++) {
150 i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];
151 data_array=getSampleData(data,nodes->reducedDegreeOfFreedom[i]);
152 Finley_copyDouble(numComps,data_array,local_data+q*numComps);
153 }
154 break;
155 }
156 /* calculate grad_data(l,i,q)=local_data(l,n)* DSDV(n,i,q) */
157 // Finley_Util_SmallMatMult(numQuad,numComps,numQuad*numDim,getSampleData(grad_data,e),NS_DOF,local_data,dSdV);
158
159 /* calculate d_datadv(l,i,q)=local_data(l,n)*DSDv(n,i,q) */
160 Finley_Util_SmallMatMult(numComps,numDim*numQuad,d_datadv,NS_DOF,local_data,gradS);
161 /* calculate grad_data(l,i,q)=d_datadv(l,k,q)*dvdV(k,i,q) */
162 Finley_Util_SmallMatSetMult(numQuad,numComps,numDim,getSampleData(grad_data,e),numDim,d_datadv,dvdV);
163 } /* for */
164 }
165 THREAD_MEMFREE(local_X);
166 THREAD_MEMFREE(dVdv);
167 THREAD_MEMFREE(dvdV);
168 THREAD_MEMFREE(Vol);
169 THREAD_MEMFREE(local_data);
170 THREAD_MEMFREE(d_datadv);
171 }
172 }
173 }
174 #undef NODES
175 #undef DOF
176 #undef REDUCED_DOF
177 /*
178 * $Log$
179 * Revision 1.6 2005/09/15 03:44:21 jgs
180 * Merge of development branch dev-02 back to main trunk on 2005-09-15
181 *
182 * Revision 1.5.2.1 2005/09/07 06:26:17 gross
183 * the solver from finley are put into the standalone package paso now
184 *
185 * Revision 1.5 2005/07/08 04:07:47 jgs
186 * Merge of development branch back to main trunk on 2005-07-08
187 *
188 * Revision 1.4 2004/12/15 07:08:32 jgs
189 * *** empty log message ***
190 * Revision 1.1.1.1.2.2 2005/06/29 02:34:48 gross
191 * some changes towards 64 integers in finley
192 *
193 * Revision 1.1.1.1.2.1 2004/11/24 01:37:12 gross
194 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
195 *
196 *
197 *
198 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26