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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4492 - (show annotations)
Tue Jul 2 01:44:11 2013 UTC (5 years, 9 months ago) by caltinay
File size: 12577 byte(s)
Finley changes that were held back while in release mode - moved more stuff
into finley namespace.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 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
20 representations
21
22 *****************************************************************************/
23
24 #include "Assemble.h"
25 #include "Util.h"
26
27 namespace finley {
28
29 void Assemble_CopyNodalData(const NodeFile* nodes, escript::Data& out,
30 const escript::Data& in)
31 {
32 Finley_resetError();
33 if (!nodes)
34 return;
35
36 const int mpiSize = nodes->MPIInfo->size;
37 const int numComps = out.getDataPointSize();
38 const int in_data_type=in.getFunctionSpace().getTypeCode();
39 const int out_data_type=out.getFunctionSpace().getTypeCode();
40
41 // check out and in
42 if (numComps != in.getDataPointSize()) {
43 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: number of components of input and output Data do not match.");
44 } else if (!out.actsExpanded()) {
45 Finley_setError(TYPE_ERROR,"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 (!in.numSamplesEqual(1, nodes->getNumNodes())) {
51 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
52 }
53 } else if (in_data_type == FINLEY_REDUCED_NODES) {
54 if (!in.numSamplesEqual(1, nodes->getNumReducedNodes())) {
55 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
56 }
57 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
58 if (!in.numSamplesEqual(1, nodes->getNumDegreesOfFreedom())) {
59 Finley_setError(TYPE_ERROR,"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)) && !in.actsExpanded() && (mpiSize>1)) {
62 Finley_setError(TYPE_ERROR,"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 (!in.numSamplesEqual(1, nodes->getNumReducedDegreesOfFreedom())) {
66 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
67 }
68 if ((out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !in.actsExpanded() && (mpiSize>1)) {
69 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: FINLEY_REDUCED_DEGREES_OF_FREEDOM to FINLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
70 }
71 } else {
72 Finley_setError(TYPE_ERROR, "Assemble_CopyNodalData: illegal function space type for target object");
73 }
74
75 int numOut=0;
76 switch (out_data_type) {
77 case FINLEY_NODES:
78 numOut=nodes->getNumNodes();
79 break;
80
81 case FINLEY_REDUCED_NODES:
82 numOut=nodes->getNumReducedNodes();
83 break;
84
85 case FINLEY_DEGREES_OF_FREEDOM:
86 numOut=nodes->getNumDegreesOfFreedom();
87 break;
88
89 case FINLEY_REDUCED_DEGREES_OF_FREEDOM:
90 numOut=nodes->getNumReducedDegreesOfFreedom();
91 break;
92
93 default:
94 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal function space type for source object");
95 }
96
97 if (!out.numSamplesEqual(1, numOut)) {
98 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of output Data object");
99 }
100
101 if (!Finley_noError())
102 return;
103
104 const size_t numComps_size = numComps*sizeof(double);
105 escript::Data& _in(*const_cast<escript::Data*>(&in));
106
107 /*********************** FINLEY_NODES ********************************/
108 if (in_data_type == FINLEY_NODES) {
109 out.requireWrite();
110 if (out_data_type == FINLEY_NODES) {
111 #pragma omp parallel for
112 for (int n=0; n<numOut; n++) {
113 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(n), numComps_size);
114 }
115 } else if (out_data_type == FINLEY_REDUCED_NODES) {
116 const std::vector<int>& map = nodes->borrowReducedNodesTarget();
117 #pragma omp parallel for
118 for (int n=0; n<map.size(); n++) {
119 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(map[n]),
120 numComps_size);
121 }
122 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
123 const std::vector<int>& map = nodes->borrowDegreesOfFreedomTarget();
124 #pragma omp parallel for
125 for (int n=0; n<numOut; n++) {
126 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(map[n]),
127 numComps_size);
128 }
129 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
130 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
131 #pragma omp parallel for
132 for (int n=0; n<numOut; n++) {
133 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(map[n]),
134 numComps_size);
135 }
136 }
137
138 /*********************** FINLEY_REDUCED_NODES ***************************/
139 } else if (in_data_type == FINLEY_REDUCED_NODES) {
140 if (out_data_type == FINLEY_NODES) {
141 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
142 } else if (out_data_type == FINLEY_REDUCED_NODES) {
143 out.requireWrite();
144 #pragma omp parallel for
145 for (int n=0; n<nodes->getNumNodes(); n++) {
146 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(n), numComps_size);
147 }
148 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
149 Finley_setError(TYPE_ERROR,"Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
150 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
151 out.requireWrite();
152 const int* target = nodes->borrowTargetReducedNodes();
153 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
154 #pragma omp parallel for
155 for (int n=0; n<numOut; n++) {
156 memcpy(out.getSampleDataRW(n),
157 _in.getSampleDataRO(target[map[n]]), numComps_size);
158 }
159 }
160
161 /******************** FINLEY_DEGREES_OF_FREEDOM *********************/
162 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
163 out.requireWrite();
164 if (out_data_type == FINLEY_NODES) {
165 Paso_Coupler *coupler = Paso_Coupler_alloc(nodes->degreesOfFreedomConnector, numComps);
166 if (Esys_noError()) {
167 // It is not immediately clear whether coupler can be
168 // trusted with constant data so I'll assume RW.
169 // Also, it holds pointers so it might not be safe to use
170 // on lazy data anyway?
171 _in.requireWrite();
172 Paso_Coupler_startCollect(coupler, _in.getSampleDataRW(0));
173 const double *recv_buffer=Paso_Coupler_finishCollect(coupler);
174 const int upperBound=nodes->getNumDegreesOfFreedom();
175 const int* target = nodes->borrowTargetDegreesOfFreedom();
176 #pragma omp parallel for
177 for (int n=0; n<nodes->numNodes; n++) {
178 const int k=target[n];
179 if (k < upperBound) {
180 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(k),
181 numComps_size);
182 } else {
183 memcpy(out.getSampleDataRW(n),
184 &recv_buffer[(k-upperBound)*numComps],
185 numComps_size);
186 }
187 }
188 }
189 Paso_Coupler_free(coupler);
190 } else if (out_data_type == FINLEY_REDUCED_NODES) {
191 Paso_Coupler *coupler = Paso_Coupler_alloc(nodes->degreesOfFreedomConnector, numComps);
192 if (Esys_noError()) {
193 _in.requireWrite(); // See comment above about coupler and const
194 Paso_Coupler_startCollect(coupler, _in.getSampleDataRW(0));
195 const double *recv_buffer=Paso_Coupler_finishCollect(coupler);
196 const int upperBound=nodes->getNumDegreesOfFreedom();
197 const std::vector<int>& map = nodes->borrowReducedNodesTarget();
198 const int* target = nodes->borrowTargetDegreesOfFreedom();
199
200 #pragma omp parallel for
201 for (int n=0; n<map.size(); n++) {
202 const int k=target[map[n]];
203 if (k < upperBound) {
204 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(k),
205 numComps_size);
206 } else {
207 memcpy(out.getSampleDataRW(n),
208 &recv_buffer[(k-upperBound)*numComps],
209 numComps_size);
210 }
211 }
212 }
213 Paso_Coupler_free(coupler);
214 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
215 #pragma omp parallel for
216 for (int n=0; n<numOut; n++) {
217 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(n),
218 numComps_size);
219 }
220 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
221 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
222 const int* target = nodes->borrowTargetDegreesOfFreedom();
223 #pragma omp parallel for
224 for (int n=0; n<numOut; n++) {
225 memcpy(out.getSampleDataRW(n),
226 _in.getSampleDataRO(target[map[n]]), numComps_size);
227 }
228 }
229
230 /**************** FINLEY_REDUCED_DEGREES_OF_FREEDOM *****************/
231 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
232 if (out_data_type == FINLEY_NODES) {
233 Finley_setError(TYPE_ERROR, "Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
234 } else if (out_data_type == FINLEY_REDUCED_NODES) {
235 Paso_Coupler *coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
236 if (Esys_noError()) {
237 _in.requireWrite(); // See comment about coupler and const
238 Paso_Coupler_startCollect(coupler, _in.getSampleDataRW(0));
239 out.requireWrite();
240 const int upperBound=nodes->getNumReducedDegreesOfFreedom();
241 const std::vector<int>& map=nodes->borrowReducedNodesTarget();
242 const int* target=nodes->borrowTargetReducedDegreesOfFreedom();
243 const double *recv_buffer=Paso_Coupler_finishCollect(coupler);
244 #pragma omp parallel for
245 for (int n=0; n<map.size(); n++) {
246 const int k=target[map[n]];
247 if (k < upperBound) {
248 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(k),
249 numComps_size);
250 } else {
251 memcpy(out.getSampleDataRW(n),
252 &recv_buffer[(k-upperBound)*numComps],
253 numComps_size);
254 }
255 }
256 }
257 Paso_Coupler_free(coupler);
258 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
259 out.requireWrite();
260 #pragma omp parallel for
261 for (int n=0; n<numOut; n++) {
262 memcpy(out.getSampleDataRW(n), _in.getSampleDataRO(n), numComps_size);
263 }
264 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
265 Finley_setError(TYPE_ERROR, "Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
266 }
267 } // in_data_type
268 }
269
270 } // namespace finley
271

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/Assemble_CopyNodalData.cpp:2682-2741 /branches/pasowrap/finley/src/Assemble_CopyNodalData.cpp:3661-3674 /branches/py3_attempt2/finley/src/Assemble_CopyNodalData.cpp:3871-3891 /branches/restext/finley/src/Assemble_CopyNodalData.cpp:2610-2624 /branches/ripleygmg_from_3668/finley/src/Assemble_CopyNodalData.cpp:3669-3791 /branches/stage3.0/finley/src/Assemble_CopyNodalData.cpp:2569-2590 /branches/symbolic_from_3470/finley/src/Assemble_CopyNodalData.cpp:3471-3974 /release/3.0/finley/src/Assemble_CopyNodalData.cpp:2591-2601 /trunk/finley/src/Assemble_CopyNodalData.cpp:4257-4344

  ViewVC Help
Powered by ViewVC 1.1.26