Debian Codegraph @

src/acl/aclMath/aclMathAlg.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 "aclMathAlg.h"
25 #include "aclVectorOfElements.h"
26 #include <aclGenerators.h>
27 #include "aclUtilities.h"
28 #include "acl.h"
29 #include "DataTypes/aclConstant.h"
30 #include "../aslUtilities.h"
31 #include <algorithm>
32 #include "Kernels/aclKernel.h"
33
34 #include <acl/DataTypes/aclArray.h>
35
36 #include <acl/aclGenerators.h>
37
38 using asl::errorMessage;
39
40 using namespace std;
41
42 namespace acl
43 {
44
45 void findNearestDirectionCode(const vector<asl::AVec<>> & directions,
46 VectorOfElements v,
47 VectorOfElements iDir,
48 ExpressionContainer & k)
49 {
50 acl::TypeID type(getElementType(v));
51 VectorOfElements prod(generateVEPrivateVariable(1, type));
52 findNearestDirectionCode(directions, v, iDir, prod, k);
53 }
54
55 void findNearestDirectionCode(const vector<asl::AVec<>> & directions,
56 VectorOfElements v,
57 VectorOfElements iDir,
58 VectorOfElements scalProd,
59 ExpressionContainer & k)
60 {
61 acl::TypeID type(getElementType(v));
62 k << (iDir = generateVEConstant(0))
63 << (scalProd = v * generateVEConstant(asl::normalize(directions[0])));
64 for (unsigned int i(1); i < directions.size(); ++i){
65 VectorOfElements vd(generateVEConstant(asl::normalize(directions[i])));
66 k << (iDir = select(iDir, generateVEConstant(i), scalProd < v * vd , type))
67 << (scalProd = max(scalProd, v * vd, type));
68 }
69 }
70
71 acl::VectorOfElements differentSign(acl::VectorOfElements d)
72 {
73 return (acl::fabs(acl::sumOfElements(acl::sign(d))) < (d.size()-.2));
74 }
75
76 VectorOfElements generateVEOutOfBoundarySafe(const VectorOfElements & a)
77 {
78 unsigned int length(getElementsSize(a));
79 auto ind(generateVEIndex(length));
80 return excerpt(a, (length + ind) % length );
81 }
82
83 VectorOfElements generateVEOutOfBoundarySafe(const VectorOfElements & a,
84 const VectorOfElements & outVal)
85 {
86 acl::TypeID type(getElementType(a));
87 unsigned int length(getElementsSize(a));
88 auto ind(generateVEIndex(length));
89 auto indE(generateVEIndexExt(length));
90 return select(excerpt(a, (length + ind) % length),
91 outVal,
92 (indE < 0.) || (indE > (length-1)),
93 type);
94 }
95
96
97 } // namespace acl