/[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 471 - (hide annotations)
Fri Jan 27 01:33:02 2006 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 8637 byte(s)
reorganise finley src tree to remove inc dir and src/finley directory

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26