/[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 471 - (show annotations)
Fri Jan 27 01:33:02 2006 UTC (13 years, 8 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 /*
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
15 /**************************************************************/
16
17 /* assemblage routines: calculate the gradient of nodal data at quadrature points */
18
19 /**************************************************************/
20
21 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
22 /* author: gross@access.edu.au */
23 /* version: $Id$ */
24
25 /**************************************************************/
26
27 #include "Assemble.h"
28 #include "Util.h"
29 #ifdef _OPENMP
30 #include <omp.h>
31 #endif
32 /*****************************************************************/
33
34
35 #define NODES 0
36 #define DOF 1
37 #define REDUCED_DOF 2
38
39 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 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 if (nodes==NULL || elements==NULL) return;
47 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 for (i=0;i<NN;i++) id[i]=i;
55 Finley_resetError();
56
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 Finley_setError(TYPE_ERROR,"__FILE__: Cannot calculate gradient of data");
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 Finley_setError(TYPE_ERROR,"__FILE__: Spatial and element dimension must match.");
95 } else if (! numSamplesEqual(grad_data,numQuad,elements->numElements)) {
96 Finley_setError(TYPE_ERROR,"__FILE__: illegal number of samples in gradient Data object");
97 } else if (! numSamplesEqual(data,1,numNodes)) {
98 Finley_setError(TYPE_ERROR,"__FILE__: illegal number of samples of input Data object");
99 } else if (numDim*numComps!=getDataPointSize(grad_data)) {
100 Finley_setError(TYPE_ERROR,"__FILE__: illegal number of components in gradient data object.");
101 } else if (!isExpanded(grad_data)) {
102 Finley_setError(TYPE_ERROR,"__FILE__: expanded Data object is expected for output data.");
103 }
104
105 /* now we can start */
106
107 if (Finley_noError()) {
108 #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 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 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 #undef NODES
169 #undef DOF
170 #undef REDUCED_DOF
171 /*
172 * $Log$
173 * 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 * 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 * Revision 1.4 2004/12/15 07:08:32 jgs
183 * *** empty log message ***
184 * Revision 1.1.1.1.2.2 2005/06/29 02:34:48 gross
185 * some changes towards 64 integers in finley
186 *
187 * 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 *
190 *
191 *
192 */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26