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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 751 - (hide annotations)
Mon Jun 26 01:46:34 2006 UTC (13 years, 4 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 jgs 150 /*
2 elspeth 616 ************************************************************
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 jgs 150 */
12 jgs 82
13     /**************************************************************/
14    
15     /* assemblage routines: calculate the gradient of nodal data at quadrature points */
16    
17     /**************************************************************/
18    
19 jgs 150 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
20 jgs 82 /* author: gross@access.edu.au */
21 jgs 150 /* version: $Id$ */
22 jgs 82
23     /**************************************************************/
24    
25     #include "Assemble.h"
26     #include "Util.h"
27     #ifdef _OPENMP
28     #include <omp.h>
29     #endif
30     /*****************************************************************/
31    
32    
33 jgs 123 #define NODES 0
34     #define DOF 1
35     #define REDUCED_DOF 2
36    
37 jgs 82 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 jgs 123 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 jgs 82 if (nodes==NULL || elements==NULL) return;
45 jgs 123 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 jgs 82 for (i=0;i<NN;i++) id[i]=i;
53 jgs 150 Finley_resetError();
54 jgs 82
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 bcumming 751 }
65     /* lock these two options out for the MPI version */
66     #ifndef PASO_MPI
67     else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {
68 jgs 82 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 bcumming 751 }
82     #endif
83     else {
84 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: Cannot calculate gradient of data");
85 jgs 82 }
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 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: Spatial and element dimension must match.");
98 jgs 82 } else if (! numSamplesEqual(grad_data,numQuad,elements->numElements)) {
99 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of samples in gradient Data object");
100 jgs 82 } else if (! numSamplesEqual(data,1,numNodes)) {
101 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of samples of input Data object");
102 jgs 82 } else if (numDim*numComps!=getDataPointSize(grad_data)) {
103 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: illegal number of components in gradient data object.");
104 jgs 82 } else if (!isExpanded(grad_data)) {
105 gross 532 Finley_setError(TYPE_ERROR,"Finley_Assemble_gradient: expanded Data object is expected for output data.");
106 jgs 82 }
107    
108     /* now we can start */
109    
110 jgs 150 if (Finley_noError()) {
111 jgs 82 #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 jgs 102 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 jgs 82 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 gross 532 /* 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 jgs 82 /* 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 gross 532 /* calculate grad_data(l,i,q)=d_datadv(l,k,q)*dvdV(k,i,q) */
162 jgs 82 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 jgs 123 #undef NODES
175     #undef DOF
176     #undef REDUCED_DOF
177 jgs 82 /*
178     * $Log$
179 jgs 150 * 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 jgs 123 * 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 jgs 102 * Revision 1.4 2004/12/15 07:08:32 jgs
189 jgs 97 * *** empty log message ***
190 jgs 123 * Revision 1.1.1.1.2.2 2005/06/29 02:34:48 gross
191     * some changes towards 64 integers in finley
192 jgs 82 *
193 jgs 123 * 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 jgs 97 *
196 jgs 82 *
197 jgs 123 *
198 jgs 82 */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26