/[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 1811 - (hide annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 5 months ago) by ksteube
File MIME type: text/plain
File size: 13878 byte(s)
Copyright updated in all files

1 jgs 82
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17 ksteube 1312 /* assemblage routines: copies data between different types nodal representation */
18 jgs 82
19     /**************************************************************/
20    
21     #include "Util.h"
22     #include "Assemble.h"
23     #ifdef _OPENMP
24     #include <omp.h>
25     #endif
26    
27     void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
28 phornby 1628 dim_t n,k,l, mpiSize;
29 jgs 123 dim_t numComps=getDataPointSize(out);
30 gross 1552 Paso_Coupler *coupler=NULL;
31 jgs 123 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 phornby 1628 #pragma omp parallel for private(n) schedule(static)
111 ksteube 1312 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 phornby 1628 #pragma omp parallel for private(n) 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 gross 1552 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
164 ksteube 1312 if (Paso_noError()) {
165 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
166     recv_buffer=Paso_Coupler_finishCollect(coupler);
167 ksteube 1312 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     }
182 gross 1552 Paso_Coupler_free(coupler);
183 ksteube 1312 } else if (out_data_type == FINLEY_REDUCED_NODES) {
184 gross 1552 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
185 ksteube 1312 if (Paso_noError()) {
186 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
187     recv_buffer=Paso_Coupler_finishCollect(coupler);
188 ksteube 1312 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
189     #pragma omp parallel for private(n,k,l) schedule(static)
190     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
191     l=nodes->reducedNodesMapping->map[n];
192     k=nodes->degreesOfFreedomMapping->target[l];
193     if (k < upperBound) {
194     memcpy(getSampleDataFast(out,n),
195     getSampleDataFast(in,k),
196     numComps_size);
197     } else {
198     memcpy(getSampleDataFast(out,n),
199     &recv_buffer[(k-upperBound)*numComps],
200     numComps_size);
201     }
202     }
203     }
204 gross 1552 Paso_Coupler_free(coupler);
205 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
206 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
207 jgs 82 #pragma omp parallel for private(n) schedule(static)
208 ksteube 1312 for (n=0;n<nComps;n++) {
209     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
210     }
211    
212 jgs 82 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
213 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
214     #pragma omp parallel for private(n,k) schedule(static)
215     for (n=0;n<nComps;n++) {
216     k=nodes->reducedDegreesOfFreedomMapping->map[n];
217     memcpy(getSampleDataFast(out,n),
218     getSampleDataFast(in,nodes->degreesOfFreedomMapping->target[k]),
219     numComps_size);
220 jgs 82 }
221     }
222 ksteube 1312
223 gross 1062 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
224 ksteube 1312
225     if (out_data_type == FINLEY_NODES) {
226     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
227     } else if (out_data_type == FINLEY_REDUCED_NODES) {
228 gross 1552 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
229 ksteube 1312 if (Paso_noError()) {
230 gross 1763 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
231 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
232     recv_buffer=Paso_Coupler_finishCollect(coupler);
233 ksteube 1312 #pragma omp parallel for private(n,k,l) schedule(static)
234     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
235     l=nodes->reducedNodesMapping->map[n];
236     k=nodes->reducedDegreesOfFreedomMapping->target[l];
237     if (k < upperBound) {
238     memcpy(getSampleDataFast(out,n),
239     getSampleDataFast(in,k),
240     numComps_size);
241     } else {
242     memcpy(getSampleDataFast(out,n),
243     &recv_buffer[(k-upperBound)*numComps],
244     numComps_size);
245     }
246     }
247     }
248 gross 1552 Paso_Coupler_free(coupler);
249 ksteube 1312 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
250     int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
251 jgs 82 #pragma omp parallel for private(n) schedule(static)
252 ksteube 1312 for (n=0;n<nComps;n++) {
253     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
254     }
255    
256 bcumming 782 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
257 ksteube 1312 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
258 jgs 82 }
259 jgs 147 }
260 jgs 82 }
261     return;
262     }
263 bcumming 751

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26