/[escript]/branches/doubleplusgood/finley/src/Assemble_interpolate.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/finley/src/Assemble_interpolate.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4327 - (show annotations)
Wed Mar 20 05:09:11 2013 UTC (6 years, 7 months ago) by jfenwick
File size: 6647 byte(s)
some finley memory
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* assemblage routines: interpolates nodal data in a data array onto elements (=integration points) */
20
21 /************************************************************************************/
22
23 #include "Assemble.h"
24 #include "Util.h"
25 #ifdef _OPENMP
26 #include <omp.h>
27 #endif
28
29 /************************************************************************************/
30
31
32 void Finley_Assemble_interpolate(Finley_NodeFile *nodes, Finley_ElementFile* elements,escriptDataC* data,escriptDataC* interpolated_data) {
33 __const double *data_array;
34 double* local_data=NULL;
35 index_t dof_offset;
36 bool_t reduced_integration=FALSE;
37 dim_t q, i, NS_DOF, NN, numNodes=0, e, numQuad=0, numSub=0, isub, numShapesTotal2;
38 Finley_ReferenceElement* reference_element=NULL;
39 Finley_ShapeFunction *basis=NULL;
40 dim_t numComps=getDataPointSize(data);
41 index_t *resort_nodes=NULL, *map=NULL;
42 type_t data_type=getFunctionSpaceType(data);
43 size_t numComps_size;
44 Finley_resetError();
45 if (nodes==NULL || elements==NULL) return;
46 reduced_integration = Finley_Assemble_reducedIntegrationOrder(interpolated_data);
47 reference_element= Finley_ReferenceElementSet_borrowReferenceElement(elements->referenceElementSet, reduced_integration);
48 NN=elements->numNodes;
49
50 /* set some parameter */
51
52 if (data_type==FINLEY_NODES) {
53 resort_nodes=reference_element->Type->subElementNodes;
54 numSub=reference_element->Type->numSubElements;
55 basis=reference_element->BasisFunctions;
56 numNodes=Finley_NodeFile_getNumNodes(nodes);
57 map=Finley_NodeFile_borrowTargetNodes(nodes);
58 if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
59 dof_offset=reference_element->Type->offsets[1];
60 } else {
61 dof_offset=reference_element->Type->offsets[0];
62 }
63 } else if (data_type==FINLEY_REDUCED_NODES) {
64 numSub=1;
65 resort_nodes=reference_element->Type->linearNodes;
66 basis=reference_element->LinearBasisFunctions;
67 numNodes=Finley_NodeFile_getNumReducedNodes(nodes);
68 map=Finley_NodeFile_borrowTargetReducedNodes(nodes);
69 if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
70 dof_offset=reference_element->LinearType->offsets[1];
71 } else {
72 dof_offset=reference_element->LinearType->offsets[0];
73 }
74 } else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {
75 if (elements->MPIInfo->size>1) {
76 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: for more than one processor DEGREES_OF_FREEDOM data are not accepted as input.");
77 return;
78 }
79 numSub=reference_element->Type->numSubElements;
80 resort_nodes=reference_element->Type->subElementNodes;
81 basis=reference_element->BasisFunctions;
82 numNodes=Finley_NodeFile_getNumDegreesOfFreedom(nodes);
83 map=Finley_NodeFile_borrowTargetDegreesOfFreedom(nodes);
84 if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
85 dof_offset=reference_element->Type->offsets[1];
86 } else {
87 dof_offset=reference_element->Type->offsets[0];
88 }
89 } else if (data_type==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
90 if (elements->MPIInfo->size>1) {
91 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: for more than one processor REDUCED_DEGREES_OF_FREEDOM data are not accepted as input.");
92 return;
93 }
94 numSub=1;
95 resort_nodes=reference_element->Type->linearNodes;
96 basis=reference_element->LinearBasisFunctions;
97 numNodes=Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes);
98 map=Finley_NodeFile_borrowTargetReducedDegreesOfFreedom(nodes);
99 if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
100 dof_offset=reference_element->LinearType->offsets[1];
101 } else {
102 dof_offset=reference_element->LinearType->offsets[0];
103 }
104 } else {
105 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: Cannot interpolate data");
106 return;
107 }
108
109 numQuad=basis->numQuadNodes;
110 numShapesTotal2=basis->Type->numShapes * reference_element->Type->numSides;
111 NS_DOF=basis->Type->numShapes;
112
113 /* check the dimensions of interpolated_data and data */
114
115 if (! numSamplesEqual(interpolated_data,numQuad*numSub,elements->numElements)) {
116 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of output Data object");
117 } else if (! numSamplesEqual(data,1,numNodes)) {
118 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of input Data object");
119 } else if (numComps!=getDataPointSize(interpolated_data)) {
120 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: number of components of input and interpolated Data do not match.");
121 } else if (!isExpanded(interpolated_data)) {
122 Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: expanded Data object is expected for output data.");
123 }
124
125 /* now we can start */
126
127 if (Finley_noError()) {
128 requireWrite(interpolated_data);
129 #pragma omp parallel private(local_data, numComps_size, isub)
130 {
131 local_data=NULL;
132 /* allocation of work arrays */
133 local_data=new double[NS_DOF*numComps*numSub];
134 if (! Finley_checkPtr(local_data)) {
135 numComps_size=(size_t)numComps*sizeof(double);
136 /* open the element loop */
137 #pragma omp for private(e,q,i,data_array,isub) schedule(static)
138 for(e=0;e<elements->numElements;e++) {
139 for (isub=0; isub<numSub; isub++) {
140 for (q=0;q<NS_DOF;q++) {
141 i=elements->Nodes[INDEX2(resort_nodes[INDEX2(dof_offset+q,isub,numShapesTotal2)],e,NN)];
142 data_array=getSampleDataRO(data,map[i]);
143 memcpy(&(local_data[INDEX3(0,q,isub, numComps,NS_DOF)]), data_array, numComps_size);
144 }
145 }
146 /* calculate interpolated_data=local_data*S */
147 Finley_Util_SmallMatSetMult1(numSub,numComps,numQuad,getSampleDataRW(interpolated_data,e),NS_DOF,local_data,basis->S);
148 } /* end of element loop */
149 }
150 delete[] local_data;
151 } /* end of parallel region */
152 }
153 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26