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

Diff of /trunk/finley/src/Assemble_interpolate.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/finley/src/finleyC/Assemble_interpolate.c revision 150 by jgs, Thu Sep 15 03:44:45 2005 UTC trunk/finley/src/Assemble_interpolate.c revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2003,2004,2005 -  All Rights Reserved              *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
1    
2  /**************************************************************/  /*******************************************************
3    *
4    * Copyright (c) 2003-2008 by University of Queensland
5    * Earth Systems Science Computational Center (ESSCC)
6    * http://www.uq.edu.au/esscc
7    *
8    * Primary Business: Queensland, Australia
9    * Licensed under the Open Software License version 3.0
10    * http://www.opensource.org/licenses/osl-3.0.php
11    *
12    *******************************************************/
13    
 /*    assemblage routines: interpolates nodal data in a data array onto elements (=integration points) */  
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /*  Author: gross@access.edu.au */  /*    assemblage routines: interpolates nodal data in a data array onto elements (=integration points) */
 /*  Version: $Id$ */  
18    
19  /**************************************************************/  /**************************************************************/
20    
# Line 33  Line 28 
28    
29    
30  void Finley_Assemble_interpolate(Finley_NodeFile *nodes, Finley_ElementFile* elements,escriptDataC* data,escriptDataC* interpolated_data) {  void Finley_Assemble_interpolate(Finley_NodeFile *nodes, Finley_ElementFile* elements,escriptDataC* data,escriptDataC* interpolated_data) {
31    double* local_data=NULL,*S=NULL,*data_array;    __const double *data_array;
32    index_t dof_offset,*resort_nodes;    double* local_data=NULL,*S=NULL;
33    dim_t q,i,NS_DOF,NN_DOF,numNodes,e;    index_t dof_offset, NN, NS;
34      bool_t reduced_integration=FALSE;
35      dim_t q,i,NS_DOF,NN_DOF,numNodes=0,e, numQuad;
36      Finley_RefElement* reference_element=NULL;
37      dim_t numComps=getDataPointSize(data);
38      index_t id[MAX_numNodes], *resort_nodes=0, *map=0;
39      type_t data_type=getFunctionSpaceType(data);
40    type_t type;    type_t type;
41      size_t numComps_size;
42      Finley_resetError();
43    #define NODES 0    #define NODES 0
44      #define REDUCED_NODES 3
45    #define DOF 1    #define DOF 1
46    #define REDUCED_DOF 2    #define REDUCED_DOF 2
47    if (nodes==NULL || elements==NULL) return;    if (nodes==NULL || elements==NULL) return;
48    dim_t NN=elements->ReferenceElement->Type->numNodes;    
49    dim_t NS=elements->ReferenceElement->Type->numShapes;    NN=elements->numNodes;
50    dim_t numComps=getDataPointSize(data);    NS=elements->ReferenceElement->Type->numShapes;
51    type_t data_type=getFunctionSpaceType(data);    reduced_integration = Finley_Assemble_reducedIntegrationOrder(interpolated_data);
   dim_t numQuad=elements->ReferenceElement->numQuadNodes;  
   index_t id[NN];  
52    for (i=0;i<NN;i++) id[i]=i;    for (i=0;i<NN;i++) id[i]=i;
   Finley_resetError();  
53    
54    /* set some parameter */    /* set some parameter */
55    
56    if (data_type==FINLEY_NODES) {    if (data_type==FINLEY_NODES) {
57         type=NODES;         type=NODES;
58         resort_nodes=id;         resort_nodes=id;
59         NN_DOF=elements->ReferenceElement->Type->numNodes;         if (reduced_integration) {
60         NS_DOF=elements->ReferenceElement->Type->numShapes;            reference_element=elements->ReferenceElementReducedOrder;
61         S=elements->ReferenceElement->S;         } else {
62         numNodes=nodes->numNodes;            reference_element=elements->ReferenceElement;
63           }
64           numNodes=Finley_NodeFile_getNumNodes(nodes);
65           map=Finley_NodeFile_borrowTargetNodes(nodes);
66      } else if (data_type==FINLEY_REDUCED_NODES) {
67           type=REDUCED_NODES;
68           resort_nodes=elements->ReferenceElement->Type->linearNodes;
69           if (reduced_integration) {
70               reference_element=elements->LinearReferenceElementReducedOrder;
71           } else {
72               reference_element=elements->LinearReferenceElement;
73           }
74           numNodes=Finley_NodeFile_getNumReducedNodes(nodes);
75           map=Finley_NodeFile_borrowTargetReducedNodes(nodes);
76    } else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {    } else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {
77           if (elements->MPIInfo->size>1) {
78              Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: for more than one processor DEGREES_OF_FREEDOM data are not accepted as input.");
79              return;
80           }
81         type=DOF;         type=DOF;
82         resort_nodes=id;         resort_nodes=id;
83         NN_DOF=elements->ReferenceElement->Type->numNodes;         if (reduced_integration) {
84         NS_DOF=elements->ReferenceElement->Type->numShapes;             reference_element=elements->ReferenceElementReducedOrder;
85         S=elements->ReferenceElement->S;         } else {
86         numNodes=nodes->numDegreesOfFreedom;             reference_element=elements->ReferenceElement;
87           }
88           numNodes=Finley_NodeFile_getNumDegreesOfFreedom(nodes);
89           map=Finley_NodeFile_borrowTargetDegreesOfFreedom(nodes);
90    } else if (data_type==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {    } else if (data_type==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
91           if (elements->MPIInfo->size>1) {
92              Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: for more than one processor REDUCED_DEGREES_OF_FREEDOM data are not accepted as input.");
93              return;
94           }
95         type=REDUCED_DOF;         type=REDUCED_DOF;
96         resort_nodes=elements->ReferenceElement->Type->linearNodes;         resort_nodes=elements->ReferenceElement->Type->linearNodes;
97         NN_DOF=elements->LinearReferenceElement->Type->numNodes;         if (reduced_integration) {
98         NS_DOF=elements->LinearReferenceElement->Type->numShapes;             reference_element=elements->LinearReferenceElementReducedOrder;
99         S=elements->LinearReferenceElement->S;         } else {
100         numNodes=nodes->reducedNumDegreesOfFreedom;             reference_element=elements->LinearReferenceElement;
101           }
102           numNodes=Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes);
103           map=Finley_NodeFile_borrowTargetReducedDegreesOfFreedom(nodes);
104     } else {     } else {
105         Finley_setError(TYPE_ERROR,"__FILE__: Cannot interpolate data");         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: Cannot interpolate data");
106    }    }
107      NN_DOF=reference_element->Type->numNodes;
108      NS_DOF=reference_element->Type->numShapes;
109      S=reference_element->S;
110      numQuad=reference_element->numQuadNodes;
111    if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {    if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
112         dof_offset=NN_DOF-NS_DOF;         dof_offset=NN_DOF-NS_DOF;
113    } else {    } else {
# Line 86  void Finley_Assemble_interpolate(Finley_ Line 117  void Finley_Assemble_interpolate(Finley_
117    /* check the dimensions of interpolated_data and data */    /* check the dimensions of interpolated_data and data */
118    
119    if (! numSamplesEqual(interpolated_data,numQuad,elements->numElements)) {    if (! numSamplesEqual(interpolated_data,numQuad,elements->numElements)) {
120         Finley_setError(TYPE_ERROR,"__FILE__: illegal number of samples of output Data object");         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of output Data object");
121    } else if (! numSamplesEqual(data,1,numNodes)) {    } else if (! numSamplesEqual(data,1,numNodes)) {
122         Finley_setError(TYPE_ERROR,"__FILE__: illegal number of samples of input Data object");         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of input Data object");
123    } else if (numComps!=getDataPointSize(interpolated_data)) {    } else if (numComps!=getDataPointSize(interpolated_data)) {
124         Finley_setError(TYPE_ERROR,"__FILE__: number of components of input and interpolated Data do not match.");         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: number of components of input and interpolated Data do not match.");
125    }  else if (!isExpanded(interpolated_data)) {    }  else if (!isExpanded(interpolated_data)) {
126         Finley_setError(TYPE_ERROR,"__FILE__: expanded Data object is expected for output data.");         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: expanded Data object is expected for output data.");
127    }    }
128    
129    /* now we can start */    /* now we can start */
130    
131    if (Finley_noError()) {    if (Finley_noError()) {
132         #pragma omp parallel private(local_data)         void* buffer=allocSampleBuffer(data);
133           requireWrite(interpolated_data);
134           #pragma omp parallel private(local_data, numComps_size)
135         {         {
136    
137            local_data=NULL;            local_data=NULL;
138            /* allocation of work arrays */            /* allocation of work arrays */
139            local_data=THREAD_MEMALLOC(NS*numComps,double);            local_data=THREAD_MEMALLOC(NS*numComps,double);
140            if (! Finley_checkPtr(local_data)) {            if (! Finley_checkPtr(local_data)) {
141    
142                numComps_size=(size_t)numComps*sizeof(double);
143          /* open the element loop */          /* open the element loop */
144    
145              #pragma omp for private(e,q,i,data_array) schedule(static)              #pragma omp for private(e,q,i,data_array) schedule(static)
146          for(e=0;e<elements->numElements;e++) {          for(e=0;e<elements->numElements;e++) {
147            /* gather local data into local_data(numComps,NS_DOF): */                for (q=0;q<NS_DOF;q++) {
148                switch (type) {                        i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];
149                   case NODES:                        data_array=getSampleDataRO(data,map[i],buffer);
150                          for (q=0;q<NS_DOF;q++) {                        memcpy(local_data+q*numComps, data_array, numComps_size);
                            i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];  
                            data_array=getSampleData(data,i);  
                            Finley_copyDouble(numComps,data_array,local_data+q*numComps);  
                         }  
                         break;  
                  case DOF:  
                         for (q=0;q<NS_DOF;q++) {  
                            i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];  
                            data_array=getSampleData(data,nodes->degreeOfFreedom[i]);  
                            Finley_copyDouble(numComps,data_array,local_data+q*numComps);  
                         }  
                         break;  
                  case REDUCED_DOF:  
                         for (q=0;q<NS_DOF;q++) {  
                            i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];  
                            data_array=getSampleData(data,nodes->reducedDegreeOfFreedom[i]);  
                            Finley_copyDouble(numComps,data_array,local_data+q*numComps);  
                         }  
                         break;  
151                }                }
   
152            /*  calculate interpolated_data=local_data*S */            /*  calculate interpolated_data=local_data*S */
153    
154            Finley_Util_SmallMatMult(numComps,numQuad,getSampleData(interpolated_data,e),NS_DOF,local_data,S);            Finley_Util_SmallMatMult(numComps,numQuad,getSampleDataRW(interpolated_data,e),NS_DOF,local_data,S);
155    
156          } /* end of element loop */          } /* end of element loop */
157    
158            }            }
159        THREAD_MEMFREE(local_data);        THREAD_MEMFREE(local_data);
160       } /* end of parallel region */       } /* end of parallel region */
161         freeSampleBuffer(buffer);
162    }    }
163    #undef NODES    #undef NODES
164      #undef REDUCED_NODES
165    #undef DOF    #undef DOF
166    #undef REDUCED_DOF    #undef REDUCED_DOF
167  }  }
 /*  
  * $Log$  
  * Revision 1.6  2005/09/15 03:44:21  jgs  
  * Merge of development branch dev-02 back to main trunk on 2005-09-15  
  *  
  * Revision 1.5.2.1  2005/09/07 06:26:18  gross  
  * the solver from finley are put into the standalone package paso now  
  *  
  * Revision 1.5  2005/07/08 04:07:48  jgs  
  * Merge of development branch back to main trunk on 2005-07-08  
  *  
  * Revision 1.4  2004/12/15 07:08:32  jgs  
  * *** empty log message ***  
  * Revision 1.1.1.1.2.3  2005/06/29 02:34:48  gross  
  * some changes towards 64 integers in finley  
  *  
  * Revision 1.1.1.1.2.2  2004/11/24 01:37:12  gross  
  * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now  
  *  
  *  
  *  
  */  

Legend:
Removed from v.150  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26