Debian Codegraph @

src/num/aslDataResampling.cxx

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #include "aslDataResampling.h"
25 #include <aslGenerators.h>
26 #include <acl/aclGenerators.h>
27 #include <acl/acl.h>
28 #include <math/aslTemplateVE.h>
29
30 #include <data/aslDataWithGhostNodes.h>
31 #include <acl/Kernels/aclKernel.h>
32 #include <math/aslTemplates.h>
33 #include <math/aslIndex2Position.h>
34 #include <acl/aclMath/aclVectorOfElements.h>
35
36 #include <acl/Kernels/aclKernelConfigurationTemplates.h>
37
38 namespace asl
39 {
40
41 Block generateCoarsedBlock(const Block & b)
42 {
43 unsigned int n(nD(b));
44 AVec<int> s(b.getSize()/2-Block::DV(n,1));
45 double dx(b.dx*2);
46 AVec<> pos(b.position+Block::V(n,.75*dx));
47 return {s,dx,pos};
48 }
49
50 DataCoarser::DataCoarser():
51 SingleKernelNM(acl::KERNEL_BASIC),
52 dataIn(0),
53 dataOut(0),
54 vectorTemplate(NULL)
55 {
56 }
57
58
59 DataCoarser::DataCoarser(Data dIn):
60 SingleKernelNM(acl::KERNEL_BASIC),
61 dataIn(dIn),
62 dataOut(0),
63 vectorTemplate(elementaryCellVT(nD(dIn->getBlock())))
64 {
65 }
66
67
68
69 void DataCoarser::init0()
70 {
71
72 acl::TypeID type(getElementType(dataIn->getDContainer()));
73 unsigned int gN(dataIn->getGhostBorder());
74 Block bOut(generateCoarsedBlock(dataIn->getInternalBlock()));
75 acl::VectorOfElementsData veIn(dataIn->getDContainer());
76 unsigned int nc(veIn.size());
77
78 dataOut=generateDataContainerACL_SP(bOut,type,nc,gN);
79 acl::VectorOfElementsData veOut(dataOut->getDContainer());
80
81 acl::VectorOfElements v(acl::generateVEPrivateVariable(nc, type));
82
83 auto dataIn0(resizeGhostNodes(dataIn,0));
84
85 TemplateVE tVE(*dataIn0, *vectorTemplate);
86
87 Index2PositionDiscreteACL t2p(dataOut->getBlock());
88 (*kernel) << t2p.initPosition;
89 acl::VectorOfElements fineIndex(t2p.position * 2 *
90 dataIn0->getBlock().c2iTransformVector);
91
92 (*kernel) << (acl::excerpt(tVE.initValues,
93 fineIndex));
94 /// \todoZeev add support for unsigned long type in Hardware
95 /// and then remove (cl_uint) casting
96 (*kernel) << (veOut = acl::sumOfElements(tVE.values)/(cl_uint)tVE.values.size());
97 }
98
99
100 Block generateClippedBlock(const Block & b,
101 const AVec<int> & a0,
102 const AVec<int> & aE)
103 {
104 unsigned int nd(nD(a0));
105 return {aE-a0+AVec<int>(nd,1), b.dx, b.position+b.dx*Block::V(a0)};
106 }
107
108 DataClipper::DataClipper():
109 SingleKernelNM(acl::KERNEL_BASIC),
110 dataIn(0),
111 dataOut(0)
112 {
113 }
114
115
116 DataClipper::DataClipper(Data dIn, AVec<int> a0, AVec<int> aE):
117 SingleKernelNM(acl::KERNEL_BASIC),
118 dataIn(dIn),
119 dataOut(0),
120 a0(a0),
121 aE(aE)
122 {
123 }
124
125 void DataClipper::init0()
126 {
127 acl::TypeID type(getElementType(dataIn->getDContainer()));
128 unsigned int gN(dataIn->getGhostBorder());
129 Block bOut(generateClippedBlock(dataIn->getInternalBlock(), a0, aE));
130 acl::VectorOfElementsData veIn(dataIn->getDContainer());
131 unsigned int nc(veIn.size());
132
133 dataOut=generateDataContainerACL_SP(bOut,type,nc,gN);
134 acl::VectorOfElementsData veOut(dataOut->getDContainer());
135
136 Index2PositionDiscreteACL t2p(dataOut->getBlock());
137 (*kernel) << t2p.initPosition;
138 acl::VectorOfElements index((t2p.position + a0)*
139 dataIn->getBlock().c2iTransformVector);
140
141 (*kernel) << (veOut = acl::excerpt(veIn, index));
142 }
143
144
145 } //asl