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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 14937 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 different types nodal representation */
18
19 /**************************************************************/
20
21 #include "Util.h"
22 #include "Assemble.h"
23 #include "esysUtils/Esys_MPI.h"
24 #ifdef _OPENMP
25 #include <omp.h>
26 #endif
27
28 void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
29 dim_t n,k,l, mpiSize;
30 dim_t numComps=getDataPointSize(out);
31 Paso_Coupler *coupler=NULL;
32 type_t in_data_type=getFunctionSpaceType(in);
33 type_t out_data_type=getFunctionSpaceType(out);
34 index_t upperBound;
35 double* recv_buffer;
36 size_t numComps_size=0;
37 Finley_resetError();
38 if (nodes==NULL) return;
39 mpiSize=nodes->MPIInfo->size;
40
41 /* check out and in */
42 if (numComps!=getDataPointSize(in)) {
43 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
44 } else if (!isExpanded(out)) {
45 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
46 }
47
48 /* more sophisticated test needed for overlapping node/DOF counts */
49 if (in_data_type == FINLEY_NODES) {
50 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumNodes(nodes))) {
51 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
52 }
53 } else if (in_data_type == FINLEY_REDUCED_NODES) {
54 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
55 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
56 }
57 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
58 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
59 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
60 }
61 if ( (((out_data_type == FINLEY_NODES) || (out_data_type == FINLEY_DEGREES_OF_FREEDOM)) && !isExpanded(in) && (mpiSize>1))) {
62
63 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.");
64 }
65 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
66 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
67 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
68 }
69 if ( (out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !isExpanded(in) && (mpiSize>1)) {
70
71 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.");
72 }
73 } else {
74 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for target object");
75 }
76
77 if (out_data_type == FINLEY_NODES) {
78 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumNodes(nodes))) {
79 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
80 }
81 } else if (out_data_type == FINLEY_REDUCED_NODES) {
82 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
83 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
84 }
85 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
86 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
87 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
88 }
89 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
90 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
91 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
92 }
93 } else {
94 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for source object");
95 }
96
97 /* now we can start */
98
99 if (Finley_noError()) {
100 /*********************** FINLEY_NODES **************************************************/
101 numComps_size=(size_t)numComps*sizeof(double);
102 if (in_data_type == FINLEY_NODES) {
103 requireWrite(out);
104 if (out_data_type == FINLEY_NODES) {
105 #pragma omp parallel private(n)
106 {
107
108 #pragma omp parallel for private(n) schedule(static)
109 for (n=0;n<nodes->nodesMapping->numNodes;n++) {
110 memcpy(getSampleDataRWFast(out,n), getSampleDataROFast(in,n), numComps_size);
111 }
112 }
113 } else if (out_data_type == FINLEY_REDUCED_NODES) {
114 #pragma omp parallel private(n)
115 {
116 #pragma omp for schedule(static)
117 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
118 memcpy(getSampleDataRWFast(out,n),
119 getSampleDataROFast(in,nodes->reducedNodesMapping->map[n]),
120 numComps_size);
121 }
122 }
123 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
124 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
125 #pragma omp parallel private(n)
126 {
127 #pragma omp for schedule(static)
128 for (n=0;n<nComps;n++) {
129 memcpy(getSampleDataRWFast(out,n),
130 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->map[n]),
131 numComps_size);
132 }
133 }
134 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
135 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
136 #pragma omp parallel private(n)
137 {
138 #pragma omp for schedule(static)
139 for (n=0;n<nComps;n++) {
140 memcpy(getSampleDataRWFast(out,n),
141 getSampleDataROFast(in,nodes->reducedDegreesOfFreedomMapping->map[n]),
142 numComps_size);
143 }
144 }
145 }
146 /*********************** FINLEY_REDUCED_NODES **************************************************/
147 } else if (in_data_type == FINLEY_REDUCED_NODES) {
148 requireWrite(out);
149 if (out_data_type == FINLEY_NODES) {
150 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
151
152 } else if (out_data_type == FINLEY_REDUCED_NODES) {
153 #pragma omp parallel private(n)
154 {
155 #pragma omp for schedule(static)
156 for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
157 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
158 }
159 }
160 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
161 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
162 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
163 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
164 #pragma omp parallel private(n,k)
165 {
166 #pragma omp for schedule(static)
167 for (n=0;n<nComps;n++) {
168 k=nodes->reducedDegreesOfFreedomMapping->map[n];
169 memcpy(getSampleDataRWFast(out,n),
170 getSampleDataROFast(in,nodes->reducedNodesMapping->target[k]),
171 numComps_size);
172 }
173 }
174 }
175
176 /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
177 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
178 requireWrite(out);
179 if (out_data_type == FINLEY_NODES) {
180 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
181 if (Esys_noError()) {
182 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
183 /* Also, it holds pointers so it might not be safe to use on lazy data anyway?*/
184 requireWrite(in);
185 Paso_Coupler_startCollect(coupler,getDataRW(in));
186 recv_buffer=Paso_Coupler_finishCollect(coupler);
187 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
188 #pragma omp parallel private(n,k)
189 {
190 #pragma omp for schedule(static)
191 for (n=0;n<nodes->numNodes;n++) {
192 k=nodes->degreesOfFreedomMapping->target[n];
193 if (k < upperBound) {
194 memcpy(getSampleDataRWFast(out,n),
195 getSampleDataROFast(in,k),
196 numComps_size);
197 } else {
198 memcpy(getSampleDataRWFast(out,n),
199 &recv_buffer[(k-upperBound)*numComps],
200 numComps_size);
201 }
202 }
203 }
204 }
205 Paso_Coupler_free(coupler);
206 } else if (out_data_type == FINLEY_REDUCED_NODES) {
207 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
208 if (Esys_noError()) {
209 requireWrite(in); /* See comment above about coupler and const */
210 Paso_Coupler_startCollect(coupler,getDataRW(in));
211 recv_buffer=Paso_Coupler_finishCollect(coupler);
212 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
213 requireWrite(out);
214
215 #pragma omp parallel private(n,k,l)
216 {
217 #pragma omp for schedule(static)
218 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
219 l=nodes->reducedNodesMapping->map[n];
220 k=nodes->degreesOfFreedomMapping->target[l];
221 if (k < upperBound) {
222 memcpy(getSampleDataRWFast(out,n),
223 getSampleDataROFast(in,k),
224 numComps_size);
225 } else {
226 memcpy(getSampleDataRWFast(out,n),
227 &recv_buffer[(k-upperBound)*numComps],
228 numComps_size);
229 }
230 }
231 }
232 }
233 Paso_Coupler_free(coupler);
234 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
235 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
236 requireWrite(out);
237 #pragma omp parallel private(n)
238 {
239 #pragma omp for schedule(static)
240 for (n=0;n<nComps;n++) {
241 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
242 }
243 }
244 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
245 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
246 requireWrite(out);
247 #pragma omp parallel private(n,k)
248 {
249 #pragma omp for schedule(static)
250 for (n=0;n<nComps;n++) {
251 k=nodes->reducedDegreesOfFreedomMapping->map[n];
252 memcpy(getSampleDataRWFast(out,n),
253 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->target[k]),
254 numComps_size);
255 }
256 }
257 }
258
259 /*********************** FINLEY_REDUCED_DEGREES_OF_FREEDOM **************************************************/
260 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
261
262 if (out_data_type == FINLEY_NODES) {
263 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
264 } else if (out_data_type == FINLEY_REDUCED_NODES) {
265 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
266 if (Esys_noError()) {
267 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
268 requireWrite(in); /* See comment about coupler and const */
269 Paso_Coupler_startCollect(coupler,getDataRW(in));
270 recv_buffer=Paso_Coupler_finishCollect(coupler);
271 requireWrite(out);
272 #pragma omp parallel private(n,k,l)
273 {
274 #pragma omp for schedule(static)
275 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
276 l=nodes->reducedNodesMapping->map[n];
277 k=nodes->reducedDegreesOfFreedomMapping->target[l];
278 if (k < upperBound) {
279 memcpy(getSampleDataRWFast(out,n),
280 getSampleDataROFast(in,k),
281 numComps_size);
282 } else {
283 memcpy(getSampleDataRWFast(out,n),
284 &recv_buffer[(k-upperBound)*numComps],
285 numComps_size);
286 }
287 }
288 }
289 }
290 Paso_Coupler_free(coupler);
291 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
292 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
293 requireWrite(out);
294 #pragma omp parallel private(n)
295 {
296 #pragma omp for schedule(static)
297 for (n=0;n<nComps;n++) {
298 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
299 }
300 }
301 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
302 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
303 }
304 }
305 }
306 return;
307 }
308

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26