Debian Codegraph @

src/data/aslProbe.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 "aslProbe.h"
25 #include "aslDataWrapper.h"
26 #include <acl/acl.h>
27 #include <acl/aclGenerators.h>
28 #include <acl/DataTypes/aclArray.h>
29 #include <acl/aclMath/aclVectorOfElements.h>
30 #include <math/aslTemplateVE.h>
31 #include <aslGenerators.h>
32
33
34 namespace asl
35 {
36
37 Probe::Probe(SPAbstractData d):
38 data(d),
39 values(getNComponents())
40 {
41 }
42
43 void Probe::addPoint(AVec<int> p)
44 {
45 if (p.getSize() != nD(data->getBlock()))
46 errorMessage("Probe::addPoint() - attempt to add point that has wrong dimensions");
47
48 if (!in(data->getBlock(), p))
49 errorMessage("Probe::addPoint() - attempt to add point that is out of block range");
50
51 indices.push_back(data->getBlock().c2i(p));
52 }
53
54
55 const unsigned int Probe::getNComponents() const
56 {
57 return data->getEContainer().size();
58 }
59
60
61 const unsigned int Probe::getNDimensions() const
62 {
63 return nD(data->getBlock());
64 }
65
66
67 void Probe::loadIndicesToACL()
68 {
69 indicesACL = acl::SPVectorOfElementsData(new acl::VectorOfElementsData(1,
70 indices.size(),
71 int(0)));
72 acl::copy(indices, (*indicesACL)[0]);
73 }
74
75
76 void Probe::loadValuesFromACL()
77 {
78 unsigned int nC(getNComponents());
79 for (unsigned int i(0); i < nC; ++i)
80 acl::copy((*valuesACL)[i], values[i]);
81 }
82
83
84 void Probe::init()
85 {
86 loadIndicesToACL();
87 valuesACL = acl::SPVectorOfElementsData(new acl::VectorOfElementsData(getNComponents(),
88 indices.size(),
89 double(0)));
90 k << (*valuesACL = excerpt(data->getEContainer(), *indicesACL));
91 k.setup();
92 }
93
94
95 void Probe::update()
96 {
97 k.compute();
98 loadValuesFromACL();
99 }
100
101
102 ProbeLI::ProbeLI(SPAbstractData d):
103 data(d),
104 values(getNComponents())
105 {
106 }
107
108 void ProbeLI::addPoint(AVec<> p)
109 {
110 if (p.getSize() != nD(data->getBlock()))
111 errorMessage("Probe::addPoint() - attempt to add point that has wrong dimensions");
112
113 if (!in(data->getBlock(), p))
114 errorMessage("Probe::addPoint() - attempt to add point that is out of block range");
115
116 points.push_back(p);
117 }
118
119
120 const unsigned int ProbeLI::getNComponents() const
121 {
122 return data->getEContainer().size();
123 }
124
125
126 const unsigned int ProbeLI::getNDimensions() const
127 {
128 return nD(data->getBlock());
129 }
130
131 void ProbeLI::loadPointsToACL()
132 {
133 unsigned int nd(getNDimensions());
134 unsigned int length(points.size());
135 pointsACL = acl::SPVectorOfElementsData(new acl::VectorOfElementsData(nd, length, double(0)));
136 vector<vector<double>> pointsCompon(nd);
137 for(unsigned int i(0); i<nd; ++i)
138 pointsCompon[i].resize(points.size());
139
140 for(unsigned int j(0); j<length; ++j)
141 for(unsigned int i(0); i<nd; ++i)
142 pointsCompon[i][j]=points[j][i];
143
144 for(unsigned int i(0); i<nd; ++i)
145 acl::copy(pointsCompon[i], (*pointsACL)[i]);
146 }
147
148
149 void ProbeLI::loadValuesFromACL()
150 {
151 unsigned int nC(getNComponents());
152 for (unsigned int i(0); i < nC; ++i)
153 acl::copy((*valuesACL)[i], values[i]);
154 }
155
156
157 void ProbeLI::init()
158 {
159 loadPointsToACL();
160 auto & bl(data->getBlock());
161 unsigned int nd(pointsACL->size());
162 valuesACL = acl::SPVectorOfElementsData(new acl::VectorOfElementsData(getNComponents(),
163 points.size(),
164 double(0)));
165 auto ind(acl::generateVEPrivateVariable<int>(1));
166 auto e(acl::generateVEPrivateVariable<double>(nd));
167
168 k << (e = (*pointsACL - bl.position)/bl.dx);
169 k << (ind = floor(e) * bl.c2iTransformVector);
170 k << (e = e - acl::floor(e));
171
172 TemplateVE dTVE;
173 auto d(generateDataContainer_SP(data->getBlock(), data->getEContainer(),0));
174 for(unsigned int i(0); i < valuesACL->size(); ++i)
175 {
176 dTVE.init(*d, *elementaryCellVT(nd), i);
177 k << excerpt(dTVE.initValues,ind);
178 k << (subVE(*valuesACL,i) = interpolate(dTVE, e));
179 }
180 k.setup();
181 }
182
183
184 void ProbeLI::update()
185 {
186 k.compute();
187 loadValuesFromACL();
188 }
189
190
191 }// namespace asl