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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26