/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/finley/src/Assemble_interpolate.c revision 1811 by ksteube, Thu Sep 25 23:11:13 2008 UTC
# Line 1  Line 1 
 /* $Id$ */  
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  /*   Copyrights by ACcESS Australia, 2003,2004 */  /*    assemblage routines: interpolates nodal data in a data array onto elements (=integration points) */
 /*   author: gross@access.edu.au */  
 /*   Version: $Id$ */  
18    
19  /**************************************************************/  /**************************************************************/
20    
 #include "Common.h"  
 #include "escript/Data/DataC.h"  
 #include "Finley.h"  
21  #include "Assemble.h"  #include "Assemble.h"
 #include "NodeFile.h"  
 #include "ElementFile.h"  
22  #include "Util.h"  #include "Util.h"
23  #ifdef _OPENMP  #ifdef _OPENMP
24  #include <omp.h>  #include <omp.h>
# Line 28  Line 29 
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;    double* local_data=NULL,*S=NULL,*data_array;
32    int dof_offset,q,*resort_nodes,type,i,NS_DOF,NN_DOF,numNodes,e;    index_t dof_offset, NN, NS;
33      bool_t reduced_integration=FALSE;
34      dim_t q,i,NS_DOF,NN_DOF,numNodes,e, numQuad;
35      Finley_RefElement* reference_element=NULL;
36      dim_t numComps=getDataPointSize(data);
37      index_t id[MAX_numNodes], *resort_nodes, *map;
38      type_t data_type=getFunctionSpaceType(data);
39      type_t type;
40      size_t numComps_size;
41      Finley_resetError();
42    #define NODES 0    #define NODES 0
43      #define REDUCED_NODES 3
44    #define DOF 1    #define DOF 1
45    #define REDUCED_DOF 2    #define REDUCED_DOF 2
46    if (nodes==NULL || elements==NULL) return;    if (nodes==NULL || elements==NULL) return;
47    int NN=elements->ReferenceElement->Type->numNodes;    
48    int NS=elements->ReferenceElement->Type->numShapes;    NN=elements->numNodes;
49    int numComps=getDataPointSize(data);    NS=elements->ReferenceElement->Type->numShapes;
50    int data_type=getFunctionSpaceType(data);    reduced_integration = Finley_Assemble_reducedIntegrationOrder(interpolated_data);
   int numQuad=elements->ReferenceElement->numQuadNodes;  
   int id[NN];  
51    for (i=0;i<NN;i++) id[i]=i;    for (i=0;i<NN;i++) id[i]=i;
52    
53    /* set some parameter */    /* set some parameter */
# Line 46  void Finley_Assemble_interpolate(Finley_ Line 55  void Finley_Assemble_interpolate(Finley_
55    if (data_type==FINLEY_NODES) {    if (data_type==FINLEY_NODES) {
56         type=NODES;         type=NODES;
57         resort_nodes=id;         resort_nodes=id;
58         NN_DOF=elements->ReferenceElement->Type->numNodes;         if (reduced_integration) {
59         NS_DOF=elements->ReferenceElement->Type->numShapes;            reference_element=elements->ReferenceElementReducedOrder;
60         S=elements->ReferenceElement->S;         } else {
61         numNodes=nodes->numNodes;            reference_element=elements->ReferenceElement;
62           }
63           numNodes=Finley_NodeFile_getNumNodes(nodes);
64           map=Finley_NodeFile_borrowTargetNodes(nodes);
65      } else if (data_type==FINLEY_REDUCED_NODES) {
66           type=REDUCED_NODES;
67           resort_nodes=elements->ReferenceElement->Type->linearNodes;
68           if (reduced_integration) {
69               reference_element=elements->LinearReferenceElementReducedOrder;
70           } else {
71               reference_element=elements->LinearReferenceElement;
72           }
73           numNodes=Finley_NodeFile_getNumReducedNodes(nodes);
74           map=Finley_NodeFile_borrowTargetReducedNodes(nodes);
75    } else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {    } else if (data_type==FINLEY_DEGREES_OF_FREEDOM) {
76           if (elements->MPIInfo->size>1) {
77              Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: for more than one processor DEGREES_OF_FREEDOM data are not accepted as input.");
78              return;
79           }
80         type=DOF;         type=DOF;
81         resort_nodes=id;         resort_nodes=id;
82         NN_DOF=elements->ReferenceElement->Type->numNodes;         if (reduced_integration) {
83         NS_DOF=elements->ReferenceElement->Type->numShapes;             reference_element=elements->ReferenceElementReducedOrder;
84         S=elements->ReferenceElement->S;         } else {
85         numNodes=nodes->numDegreesOfFreedom;             reference_element=elements->ReferenceElement;
86           }
87           numNodes=Finley_NodeFile_getNumDegreesOfFreedom(nodes);
88           map=Finley_NodeFile_borrowTargetDegreesOfFreedom(nodes);
89    } else if (data_type==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {    } 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         type=REDUCED_DOF;         type=REDUCED_DOF;
95         resort_nodes=elements->ReferenceElement->Type->linearNodes;         resort_nodes=elements->ReferenceElement->Type->linearNodes;
96         NN_DOF=elements->LinearReferenceElement->Type->numNodes;         if (reduced_integration) {
97         NS_DOF=elements->LinearReferenceElement->Type->numShapes;             reference_element=elements->LinearReferenceElementReducedOrder;
98         S=elements->LinearReferenceElement->S;         } else {
99         numNodes=nodes->reducedNumDegreesOfFreedom;             reference_element=elements->LinearReferenceElement;
100           }
101           numNodes=Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes);
102           map=Finley_NodeFile_borrowTargetReducedDegreesOfFreedom(nodes);
103     } else {     } else {
104         Finley_ErrorCode=TYPE_ERROR;         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: Cannot interpolate data");
        sprintf(Finley_ErrorMsg,"Cannot interpolate data");  
105    }    }
106      NN_DOF=reference_element->Type->numNodes;
107      NS_DOF=reference_element->Type->numShapes;
108      S=reference_element->S;
109      numQuad=reference_element->numQuadNodes;
110    if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {    if (getFunctionSpaceType(interpolated_data)==FINLEY_CONTACT_ELEMENTS_2) {
111         dof_offset=NN_DOF-NS_DOF;         dof_offset=NN_DOF-NS_DOF;
112    } else {    } else {
# Line 78  void Finley_Assemble_interpolate(Finley_ Line 116  void Finley_Assemble_interpolate(Finley_
116    /* check the dimensions of interpolated_data and data */    /* check the dimensions of interpolated_data and data */
117    
118    if (! numSamplesEqual(interpolated_data,numQuad,elements->numElements)) {    if (! numSamplesEqual(interpolated_data,numQuad,elements->numElements)) {
119         Finley_ErrorCode=TYPE_ERROR;         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of output Data object");
        sprintf(Finley_ErrorMsg,"illegal number of samples of output Data object");  
120    } else if (! numSamplesEqual(data,1,numNodes)) {    } else if (! numSamplesEqual(data,1,numNodes)) {
121         Finley_ErrorCode=TYPE_ERROR;         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: illegal number of samples of input Data object");
        sprintf(Finley_ErrorMsg,"illegal number of samples of input Data object");  
122    } else if (numComps!=getDataPointSize(interpolated_data)) {    } else if (numComps!=getDataPointSize(interpolated_data)) {
123         Finley_ErrorCode=TYPE_ERROR;         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: number of components of input and interpolated Data do not match.");
        sprintf(Finley_ErrorMsg,"number of components of input and interpolated Data do not match.");  
124    }  else if (!isExpanded(interpolated_data)) {    }  else if (!isExpanded(interpolated_data)) {
125         Finley_ErrorCode=TYPE_ERROR;         Finley_setError(TYPE_ERROR,"Finley_Assemble_interpolate: expanded Data object is expected for output data.");
        sprintf(Finley_ErrorMsg,"expanded Data object is expected for output data.");  
126    }    }
127    
128    /* now we can start */    /* now we can start */
129    
130    if (Finley_ErrorCode==NO_ERROR) {    if (Finley_noError()) {
131         #pragma omp parallel private(local_data)         #pragma omp parallel private(local_data, numComps_size)
132         {         {
133            local_data=NULL;            local_data=NULL;
134            /* allocation of work arrays */            /* allocation of work arrays */
135            local_data=THREAD_MEMALLOC(NS*numComps,double);            local_data=THREAD_MEMALLOC(NS*numComps,double);
136            if (! Finley_checkPtr(local_data)) {            if (! Finley_checkPtr(local_data)) {
137    
138                numComps_size=(size_t)numComps*sizeof(double);
139          /* open the element loop */          /* open the element loop */
140    
141              #pragma omp for private(e,q,i,data_array) schedule(static)              #pragma omp for private(e,q,i,data_array) schedule(static)
142          for(e=0;e<elements->numElements;e++) {          for(e=0;e<elements->numElements;e++) {
143            /* gather local data into local_data(numComps,NS_DOF): */                for (q=0;q<NS_DOF;q++) {
144                switch (type) {                        i=elements->Nodes[INDEX2(resort_nodes[dof_offset+q],e,NN)];
145                   case NODES:                        data_array=getSampleData(data,map[i]);
146                          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;  
147                }                }
   
148            /*  calculate interpolated_data=local_data*S */            /*  calculate interpolated_data=local_data*S */
149    
150            Finley_Util_SmallMatMult(numComps,numQuad,getSampleData(interpolated_data,e),NS_DOF,local_data,S);            Finley_Util_SmallMatMult(numComps,numQuad,getSampleData(interpolated_data,e),NS_DOF,local_data,S);
# Line 141  void Finley_Assemble_interpolate(Finley_ Line 156  void Finley_Assemble_interpolate(Finley_
156       } /* end of parallel region */       } /* end of parallel region */
157    }    }
158    #undef NODES    #undef NODES
159      #undef REDUCED_NODES
160    #undef DOF    #undef DOF
161    #undef REDUCED_DOF    #undef REDUCED_DOF
162  }  }
 /*  
  * $Log$  
  * Revision 1.2  2004/12/14 05:39:30  jgs  
  * *** empty log message ***  
  *  
  * 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  
  *  
  * Revision 1.1.1.1.2.1  2004/10/27 23:39:21  gross  
  * bug in finley interpolation fixed. GradTest is running now  
  *  
  * Revision 1.1.1.1  2004/10/26 06:53:57  jgs  
  * initial import of project esys2  
  *  
  * Revision 1.2  2004/07/21 05:00:54  gross  
  * name changes in DataC  
  *  
  * Revision 1.1  2004/07/02 04:21:13  gross  
  * Finley C code has been included  
  *  
  *  
  */  

Legend:
Removed from v.97  
changed lines
  Added in v.1811

  ViewVC Help
Powered by ViewVC 1.1.26