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

Annotation of /trunk/finley/src/Assemble_CopyNodalData.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (hide annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 9 months ago) by trankine
File MIME type: text/plain
File size: 14139 byte(s)
And get the *(&(*&(* name right
1 jgs 82
2 ksteube 1312 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 82 /**************************************************************/
17    
18 ksteube 1312 /* assemblage routines: copies data between different types nodal representation */
19 jgs 82
20     /**************************************************************/
21    
22     #include "Util.h"
23     #include "Assemble.h"
24     #ifdef _OPENMP
25     #include <omp.h>
26     #endif
27    
28     void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
29 ksteube 1312 dim_t n,i,k,l, mpiSize;
30 jgs 123 dim_t numComps=getDataPointSize(out);
31     type_t in_data_type=getFunctionSpaceType(in);
32     type_t out_data_type=getFunctionSpaceType(out);
33 ksteube 1312 index_t upperBound;
34     double* recv_buffer;
35     size_t numComps_size=0;
36 jgs 150 Finley_resetError();
37 gross 1028 if (nodes==NULL) return;
38 ksteube 1312 mpiSize=nodes->MPIInfo->size;
39 jgs 82
40     /* check out and in */
41     if (numComps!=getDataPointSize(in)) {
42 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
43 jgs 82 } else if (!isExpanded(out)) {
44 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
45 jgs 82 }
46    
47 bcumming 751 /* more sophisticated test needed for overlapping node/DOF counts */
48 jgs 82 if (in_data_type == FINLEY_NODES) {
49 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumNodes(nodes))) {
50 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
51 jgs 82 }
52 gross 1062 } else if (in_data_type == FINLEY_REDUCED_NODES) {
53 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
54     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
55     }
56 jgs 82 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
57 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
58 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
59 jgs 82 }
60 ksteube 1312 if ( (((out_data_type == FINLEY_NODES) || (out_data_type == FINLEY_DEGREES_OF_FREEDOM)) && !isExpanded(in) && (mpiSize>1))) {
61    
62     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: FINLEY_DEGREES_OF_FREEDOM to FINLEY_NODES or FINLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
63     }
64 jgs 82 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
65 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
66     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
67 jgs 82 }
68 ksteube 1312 if ( (out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !isExpanded(in) && (mpiSize>1)) {
69    
70     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: FINLEY_REDUCED_DEGREES_OF_FREEDOM to FINLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
71     }
72 jgs 82 } else {
73 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for target object");
74 jgs 82 }
75    
76     if (out_data_type == FINLEY_NODES) {
77 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumNodes(nodes))) {
78 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
79 jgs 82 }
80 gross 1062 } else if (out_data_type == FINLEY_REDUCED_NODES) {
81 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
82     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
83     }
84 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
85 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
86 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
87 jgs 82 }
88     } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
89 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
90 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
91 jgs 82 }
92     } else {
93 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for source object");
94 jgs 82 }
95    
96     /* now we can start */
97 bcumming 751
98 jgs 150 if (Finley_noError()) {
99 ksteube 1312 /*********************** FINLEY_NODES **************************************************/
100     numComps_size=(size_t)numComps*sizeof(double);
101 jgs 82 if (in_data_type == FINLEY_NODES) {
102 ksteube 1312
103 jgs 82 if (out_data_type == FINLEY_NODES) {
104     #pragma omp parallel for private(n) schedule(static)
105 ksteube 1312 for (n=0;n<nodes->nodesMapping->numNodes;n++) {
106     memcpy(getSampleDataFast(out,n), getSampleDataFast(in,n), numComps_size);
107     }
108    
109     } else if (out_data_type == FINLEY_REDUCED_NODES) {
110     #pragma omp parallel for private(n,i) schedule(static)
111     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
112     memcpy(getSampleDataFast(out,n),
113     getSampleDataFast(in,nodes->reducedNodesMapping->map[n]),
114     numComps_size);
115     }
116 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
117 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
118 jgs 82 #pragma omp parallel for private(n) schedule(static)
119 ksteube 1312 for (n=0;n<nComps;n++) {
120     memcpy(getSampleDataFast(out,n),
121     getSampleDataFast(in,nodes->degreesOfFreedomMapping->map[n]),
122     numComps_size);
123     }
124    
125 jgs 82 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
126 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
127 jgs 82 #pragma omp parallel for private(n,i) schedule(static)
128 ksteube 1312 for (n=0;n<nComps;n++) {
129     memcpy(getSampleDataFast(out,n),
130     getSampleDataFast(in,nodes->reducedDegreesOfFreedomMapping->map[n]),
131     numComps_size);
132 jgs 82 }
133     }
134 ksteube 1312 /*********************** FINLEY_REDUCED_NODES **************************************************/
135 gross 1062 } else if (in_data_type == FINLEY_REDUCED_NODES) {
136 ksteube 1312
137 gross 1062 if (out_data_type == FINLEY_NODES) {
138     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
139 ksteube 1312
140     } else if (out_data_type == FINLEY_REDUCED_NODES) {
141     #pragma omp parallel for private(n) schedule(static)
142     for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
143     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
144     }
145    
146 gross 1062 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
147     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
148     } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
149 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
150     #pragma omp parallel for private(n,k) schedule(static)
151     for (n=0;n<nComps;n++) {
152     k=nodes->reducedDegreesOfFreedomMapping->map[n];
153     memcpy(getSampleDataFast(out,n),
154     getSampleDataFast(in,nodes->reducedNodesMapping->target[k]),
155     numComps_size);
156     }
157 gross 1062 }
158 ksteube 1312
159     /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
160 jgs 82 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
161 ksteube 1312
162     if (out_data_type == FINLEY_NODES) {
163     Paso_Coupler_allocBuffer(nodes->degreesOfFreedomCoupler,numComps);
164     if (Paso_noError()) {
165     Paso_Coupler_startCollect(nodes->degreesOfFreedomCoupler,getSampleDataFast(in,0));
166     recv_buffer=Paso_Coupler_finishCollect(nodes->degreesOfFreedomCoupler);
167     upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
168     #pragma omp parallel for private(n,k) schedule(static)
169     for (n=0;n<nodes->numNodes;n++) {
170     k=nodes->degreesOfFreedomMapping->target[n];
171     if (k < upperBound) {
172     memcpy(getSampleDataFast(out,n),
173     getSampleDataFast(in,k),
174     numComps_size);
175     } else {
176     memcpy(getSampleDataFast(out,n),
177     &recv_buffer[(k-upperBound)*numComps],
178     numComps_size);
179     }
180     }
181     Paso_Coupler_freeBuffer(nodes->degreesOfFreedomCoupler);
182     }
183    
184     } else if (out_data_type == FINLEY_REDUCED_NODES) {
185     Paso_Coupler_allocBuffer(nodes->degreesOfFreedomCoupler,numComps);
186     if (Paso_noError()) {
187     Paso_Coupler_startCollect(nodes->degreesOfFreedomCoupler,getSampleDataFast(in,0));
188     recv_buffer=Paso_Coupler_finishCollect(nodes->degreesOfFreedomCoupler);
189     upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
190     #pragma omp parallel for private(n,k,l) schedule(static)
191     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
192     l=nodes->reducedNodesMapping->map[n];
193     k=nodes->degreesOfFreedomMapping->target[l];
194     if (k < upperBound) {
195     memcpy(getSampleDataFast(out,n),
196     getSampleDataFast(in,k),
197     numComps_size);
198     } else {
199     memcpy(getSampleDataFast(out,n),
200     &recv_buffer[(k-upperBound)*numComps],
201     numComps_size);
202     }
203     }
204     Paso_Coupler_freeBuffer(nodes->degreesOfFreedomCoupler);
205     }
206 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
207 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
208 jgs 82 #pragma omp parallel for private(n) schedule(static)
209 ksteube 1312 for (n=0;n<nComps;n++) {
210     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
211     }
212    
213 jgs 82 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
214 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
215     #pragma omp parallel for private(n,k) schedule(static)
216     for (n=0;n<nComps;n++) {
217     k=nodes->reducedDegreesOfFreedomMapping->map[n];
218     memcpy(getSampleDataFast(out,n),
219     getSampleDataFast(in,nodes->degreesOfFreedomMapping->target[k]),
220     numComps_size);
221 jgs 82 }
222     }
223 ksteube 1312
224 gross 1062 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
225 ksteube 1312
226     if (out_data_type == FINLEY_NODES) {
227     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
228    
229     } else if (out_data_type == FINLEY_REDUCED_NODES) {
230     Paso_Coupler_allocBuffer(nodes->reducedDegreesOfFreedomCoupler,numComps);
231     if (Paso_noError()) {
232     Paso_Coupler_startCollect(nodes->reducedDegreesOfFreedomCoupler,getSampleDataFast(in,0));
233     recv_buffer=Paso_Coupler_finishCollect(nodes->reducedDegreesOfFreedomCoupler);
234     upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
235     #pragma omp parallel for private(n,k,l) schedule(static)
236     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
237     l=nodes->reducedNodesMapping->map[n];
238     k=nodes->reducedDegreesOfFreedomMapping->target[l];
239     if (k < upperBound) {
240     memcpy(getSampleDataFast(out,n),
241     getSampleDataFast(in,k),
242     numComps_size);
243     } else {
244     memcpy(getSampleDataFast(out,n),
245     &recv_buffer[(k-upperBound)*numComps],
246     numComps_size);
247     }
248     }
249     Paso_Coupler_freeBuffer(nodes->reducedDegreesOfFreedomCoupler);
250     }
251    
252     } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
253     int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
254 jgs 82 #pragma omp parallel for private(n) schedule(static)
255 ksteube 1312 for (n=0;n<nComps;n++) {
256     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
257     }
258    
259 bcumming 782 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
260 ksteube 1312 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
261 jgs 82 }
262 jgs 147 }
263 jgs 82 }
264     return;
265     }
266 bcumming 751

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26