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

Contents of /trunk/finley/src/Assemble_AverageElementData.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2548 - (show annotations)
Mon Jul 20 06:20:06 2009 UTC (9 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 4001 byte(s)
Updating copyright notices
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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
14
15 /**************************************************************/
16
17 /* assemblage routines: copies data between elements */
18
19 /**************************************************************/
20
21 #include "Assemble.h"
22 #include "Util.h"
23 #ifdef _OPENMP
24 #include <omp.h>
25 #endif
26 /******************************************************************************************************/
27
28
29 void Finley_Assemble_AverageElementData(Finley_ElementFile* elements,escriptDataC* out,escriptDataC* in) {
30 dim_t n,q, numElements, numQuad_in, numQuad_out, i;
31 __const double *in_array;
32 double *out_array, vol, volinv, *wq;
33 register double rtmp;
34 dim_t numComps=getDataPointSize(out);
35 size_t numComps_size;
36
37 Finley_resetError();
38 if( elements == NULL )
39 {
40 return;
41 }
42
43 numElements=elements->numElements;
44 if (Finley_Assemble_reducedIntegrationOrder(in)) {
45 numQuad_in=elements->ReferenceElementReducedOrder->numQuadNodes;
46 wq=elements->ReferenceElementReducedOrder->QuadWeights;
47 } else {
48 numQuad_in=elements->ReferenceElement->numQuadNodes;
49 wq=elements->ReferenceElement->QuadWeights;
50 }
51 if (Finley_Assemble_reducedIntegrationOrder(out)) {
52 numQuad_out=elements->ReferenceElementReducedOrder->numQuadNodes;
53 } else {
54 numQuad_out=elements->ReferenceElement->numQuadNodes;
55 }
56
57 /* check out and in */
58 if (numComps!=getDataPointSize(in)) {
59 Finley_setError(TYPE_ERROR,"Finley_Assemble_AverageElementData: number of components of input and output Data do not match.");
60 } else if (!numSamplesEqual(in,numQuad_in,numElements)) {
61 Finley_setError(TYPE_ERROR,"Finley_Assemble_AverageElementData: illegal number of samples of input Data object");
62 } else if (!numSamplesEqual(out,numQuad_out,numElements)) {
63 Finley_setError(TYPE_ERROR,"Finley_Assemble_AverageElementData: illegal number of samples of output Data object");
64 } else if (!isExpanded(out)) {
65 Finley_setError(TYPE_ERROR,"Finley_Assemble_AverageElementData: expanded Data object is expected for output data.");
66 }
67
68 /* now we can start */
69
70 if (Finley_noError()) {
71 if (isExpanded(in)) {
72 void* buffer=allocSampleBuffer(in);
73 vol=0;
74 for (q=0; q< numQuad_in;++q) vol+=wq[q];
75 volinv=1./vol;
76 requireWrite(out);
77 #pragma omp parallel private(n, i, rtmp, q, in_array, out_array)
78 {
79 # pragma omp for schedule(static)
80 for (n=0;n<numElements;n++) {
81 in_array=getSampleDataRO(in,n,buffer);
82 out_array=getSampleDataRW(out,n);
83 for (i=0; i<numComps; ++i) {
84 rtmp=0;
85 for (q=0; q< numQuad_in;++q) rtmp+=in_array[INDEX2(i,q,numComps)]*wq[q];
86 rtmp*=volinv;
87 for (q=0; q< numQuad_out;++q) out_array[INDEX2(i,q,numComps)]=rtmp;
88 }
89 }
90 }
91 freeSampleBuffer(buffer);
92 } else {
93 void* buffer=allocSampleBuffer(in);
94 numComps_size=numComps*sizeof(double);
95 requireWrite(out);
96 #pragma omp parallel private(q,n,out_array,in_array)
97 {
98 # pragma omp for schedule(static)
99 for (n=0;n<numElements;n++) {
100 in_array=getSampleDataRO(in,n,buffer);
101 out_array=getSampleDataRW(out,n);
102 for (q=0;q<numQuad_out;q++) memcpy(out_array+q*numComps,in_array,numComps_size);
103 }
104 }
105 freeSampleBuffer(buffer);
106 }
107 }
108 return;
109 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26