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

1
2 /*******************************************************
3 *
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
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 #ifdef _OPENMP
24 #include <omp.h>
25 #endif
26
27 void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
28 dim_t n,k,l, mpiSize;
29 dim_t numComps=getDataPointSize(out);
30 Paso_Coupler *coupler=NULL;
31 type_t in_data_type=getFunctionSpaceType(in);
32 type_t out_data_type=getFunctionSpaceType(out);
33 index_t upperBound;
34 double* recv_buffer;
35 size_t numComps_size=0;
36 Finley_resetError();
37 if (nodes==NULL) return;
38 mpiSize=nodes->MPIInfo->size;
39
40 /* check out and in */
41 if (numComps!=getDataPointSize(in)) {
42 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
43 } else if (!isExpanded(out)) {
44 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
45 }
46
47 /* more sophisticated test needed for overlapping node/DOF counts */
48 if (in_data_type == FINLEY_NODES) {
49 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumNodes(nodes))) {
50 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
51 }
52 } else if (in_data_type == FINLEY_REDUCED_NODES) {
53 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 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
57 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
58 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
59 }
60 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 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
65 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 }
68 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 } else {
73 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for target object");
74 }
75
76 if (out_data_type == FINLEY_NODES) {
77 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumNodes(nodes))) {
78 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
79 }
80 } else if (out_data_type == FINLEY_REDUCED_NODES) {
81 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 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
85 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
86 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
87 }
88 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
89 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
90 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
91 }
92 } else {
93 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for source object");
94 }
95
96 /* now we can start */
97
98 if (Finley_noError()) {
99 /*********************** FINLEY_NODES **************************************************/
100 numComps_size=(size_t)numComps*sizeof(double);
101 if (in_data_type == FINLEY_NODES) {
102
103 if (out_data_type == FINLEY_NODES) {
104 #pragma omp parallel for private(n) schedule(static)
105 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) 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 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
117 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
118 #pragma omp parallel for private(n) schedule(static)
119 for (n=0;n<nComps;n++) {
120 memcpy(getSampleDataFast(out,n),
121 getSampleDataFast(in,nodes->degreesOfFreedomMapping->map[n]),
122 numComps_size);
123 }
124
125 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
126 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
127 #pragma omp parallel for private(n) schedule(static)
128 for (n=0;n<nComps;n++) {
129 memcpy(getSampleDataFast(out,n),
130 getSampleDataFast(in,nodes->reducedDegreesOfFreedomMapping->map[n]),
131 numComps_size);
132 }
133 }
134 /*********************** FINLEY_REDUCED_NODES **************************************************/
135 } else if (in_data_type == FINLEY_REDUCED_NODES) {
136
137 if (out_data_type == FINLEY_NODES) {
138 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
139
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 } 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 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 }
158
159 /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
160 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
161
162 if (out_data_type == FINLEY_NODES) {
163 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
164 if (Paso_noError()) {
165 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
166 recv_buffer=Paso_Coupler_finishCollect(coupler);
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 }
182 Paso_Coupler_free(coupler);
183 } else if (out_data_type == FINLEY_REDUCED_NODES) {
184 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
185 if (Paso_noError()) {
186 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
187 recv_buffer=Paso_Coupler_finishCollect(coupler);
188 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 Paso_Coupler_free(coupler);
205 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
206 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
207 #pragma omp parallel for private(n) schedule(static)
208 for (n=0;n<nComps;n++) {
209 memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
210 }
211
212 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
213 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 }
221 }
222
223 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
224
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 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
229 if (Paso_noError()) {
230 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
231 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
232 recv_buffer=Paso_Coupler_finishCollect(coupler);
233 #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 Paso_Coupler_free(coupler);
249 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
250 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
251 #pragma omp parallel for private(n) schedule(static)
252 for (n=0;n<nComps;n++) {
253 memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
254 }
255
256 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
257 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
258 }
259 }
260 }
261 return;
262 }
263

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26