Debian Codegraph @

src/math/aslTemplatesExtras.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 "aslTemplatesExtras.h"
25 #include "acl/aclMath/aclVectorOfElements.h"
26 #include "acl/aclGenerators.h"
27 #include "aslBarycentric.h"
28
29 namespace asl
30 {
31
32 VTObjects::VTObjects (const VectorTemplate* vt,
33 const std::vector<unsigned int> & ep1,
34 const std::vector<unsigned int> & ep2,
35 const std::vector<AVec<int>> & elCells):
36 vt(vt),
37 edgePoint1(ep1),
38 edgePoint2(ep2),
39 elementaryCells(elCells)
40 {
41 initCellMatrices();
42 }
43
44 void VTObjects::getCellPoints(unsigned int ic, vector<AVec<>> & points) const
45 {
46 points.resize(elementaryCells[ic].getSize());
47 for(unsigned int i(0); i < points.size(); ++i)
48 {
49 points[i] = vt->vectors[elementaryCells[ic][i]];
50 }
51 }
52
53 void VTObjects::initCellMatrices()
54 {
55 unsigned int n(elementaryCells.size());
56 cellMatrices.resize(n);
57 for(unsigned int i(0); i < n; ++i)
58 {
59 vector<AVec<>> points;
60 getCellPoints(i, points);
61 asl::Barycentric b(points);
62 cellMatrices[i] = b.tInv;
63 }
64 }
65
66 acl::VectorOfElements VTObjects::cellGradient(const acl::VectorOfElements & val,
67 unsigned int i) const
68 {
69 if(i >= elementaryCells.size())
70 errorMessage("VTObjects::cellGradient: i larger than the number of cells");
71 auto cell(elementaryCells[i]);
72 unsigned int nv(cell.getSize());
73
74 acl::VectorOfElements val0(subVE(val,cell[0]));
75 acl::VectorOfElements valI(nv-1);
76 for(unsigned int ii(1); ii < nv; ++ii)
77 valI[ii-1] = (subVE(val,cell[ii])-val0)[0];
78
79 return valI * acl::generateMEConstant(cellMatrices[i]);
80 }
81
82 double edgeWeight(const VTObjects & vto, unsigned int iEl, unsigned int i, unsigned int j)
83 {
84 auto & cell(vto.elementaryCells[iEl]);
85 auto v(vto.vt->vectors[cell[i]]-vto.vt->vectors[cell[j]]);
86 unsigned int nDir(vto.vt->vectors.size());
87 unsigned int ii(0);
88 bool test(true);
89 for(; test && ii < nDir; ++ii)
90 {
91 test = (l2(v) != l2(vto.vt->vectors[ii]));
92 }
93 double res(0);
94 if (!test)
95 res=vto.vt->laplasCoefs[ii];
96 return res;
97 }
98
99 const VTObjects & d2q5Objs()
100 {
101 static VTObjects vto(&d2q5(),
102 {0,0,0,0,1,1,3,3},
103 {1,2,3,4,2,4,2,4},
104 {makeAVec(0,1,2), makeAVec(0,2,3), makeAVec(0,3,4), makeAVec(0,4,1)});
105 return vto;
106 }
107
108 const VTObjects & d2q9Objs()
109 {
110 static VTObjects vto(&d2q9(),
111 {0,0,0,0,0,0,0,0,1,5,2,6,3,7,4,8},
112 {1,2,3,4,5,6,7,8,5,2,6,3,7,4,8,1},
113 {makeAVec(1,0,8), makeAVec(1,0,5),
114 makeAVec(2,0,5), makeAVec(2,0,6),
115 makeAVec(3,0,6), makeAVec(3,0,7),
116 makeAVec(4,0,7), makeAVec(4,0,8)});
117 return vto;
118 }
119
120
121 const VTObjects & d3q7Objs()
122 {
123 static VTObjects vto(&d3q7(),
124 {0,0,0,0,0,0,1,1,1,1,4,4,4,4},
125 {1,2,3,4,5,6,2,3,5,6,2,3,5,6},
126 {makeAVec(0,1,2,3), makeAVec(0,2,4,3), makeAVec(0,4,5,3),
127 makeAVec(0,5,1,3), makeAVec(0,2,1,6), makeAVec(0,4,2,6),
128 makeAVec(0,5,4,6), makeAVec(0,1,5,6)});
129 return vto;
130 }
131
132 const VTObjects & d3q15Objs()
133 {
134 static VTObjects vto(&d3q15(),
135 {0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0,1,1,1, 1,2,2, 2, 2,3,3, 3, 3, 4, 4, 4, 4,5, 5, 5, 5,6, 6, 6, 6},
136 {1,2,3,4,5,6,7,8,9,10,11,12,13,14,7,8,9,10,7,8,11,12,7,9,11,13,11,12,13,14,9,10,13,14,8,10,12,14},
137 {makeAVec(0,1, 7, 9), makeAVec(0,1, 9,10), makeAVec(0,1,10, 8), makeAVec(0,1, 8, 7),
138 makeAVec(0,2, 7, 8), makeAVec(0,2, 8,12), makeAVec(0,2,12,11), makeAVec(0,2,11, 7),
139 makeAVec(0,3, 7,11), makeAVec(0,3,11,13), makeAVec(0,3,13, 9), makeAVec(0,3, 9, 7),
140 makeAVec(0,4,11,13), makeAVec(0,4,13,14), makeAVec(0,4,14,12), makeAVec(0,4,12,11),
141 makeAVec(0,5, 9,10), makeAVec(0,5,10,14), makeAVec(0,5,14,13), makeAVec(0,5,13, 9),
142 makeAVec(0,6, 8,12), makeAVec(0,6,12,14), makeAVec(0,6,14,10), makeAVec(0,6,10, 8)});
143 return vto;
144 }
145
146 const VTObjects & d3q19Objs()
147 {
148 static VTObjects vto(&d3q19(),
149 {0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1, 1,1, 1, 2, 2,2, 2, 3, 3, 3, 3,4, 4, 4, 4,5, 5,5, 5, 6, 6, 6, 6, 7,15, 8,16,10,11, 7,12,11,18,14,15,10,18, 9,17, 9,14, 8,13,12,17,13,16},
150 {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,7,15,8,16,10,11,7,12,11,18,14,15,9,17,10,18,9,14,8,13,12,17,13,16,15, 8,16, 7,11, 7,12,10,18,14,15,11,18, 9,17,10,14, 8,13, 9,17,13,16,12},
151 {makeAVec(0,1, 7,15), makeAVec(0,1,15, 8), makeAVec(0,1, 8,16), makeAVec(0,1,16, 7),
152 makeAVec(0,2,10,11), makeAVec(0,2,11, 7), makeAVec(0,2, 7,12), makeAVec(0,2,12,10),
153 makeAVec(0,3,11,18), makeAVec(0,3,18,14), makeAVec(0,3,14,15), makeAVec(0,3,15,11),
154 makeAVec(0,4,10,18), makeAVec(0,4,18, 9), makeAVec(0,4, 9,17), makeAVec(0,4,17,10),
155 makeAVec(0,5, 9,14), makeAVec(0,5,14, 8), makeAVec(0,5, 8,13), makeAVec(0,5,13, 9),
156 makeAVec(0,6,12,17), makeAVec(0,6,17,13), makeAVec(0,6,13,16), makeAVec(0,6,16,12),
157 makeAVec(0,7,16,12), makeAVec(0,7,11,15), makeAVec(0,8,16,13), makeAVec(0,8,15,14),
158 makeAVec(0,9,14,18), makeAVec(0,9,13,17), makeAVec(0,10,18,11), makeAVec(0,10,17,12)});
159 return vto;
160 }
161
162 const VTObjects* vtObject(const VectorTemplate *vt)
163 {
164 const VTObjects* vto(NULL);
165
166 if (vt == &d2q5())
167 vto=&d2q5Objs();
168 if (vt == &d2q9())
169 vto=&d2q9Objs();
170 if (vt == &d3q7())
171 vto=&d3q7Objs();
172 if (vt == &d3q15())
173 vto=&d3q15Objs();
174 if (vt == &d3q19())
175 vto=&d3q19Objs();
176
177 // if (vto == NULL)
178 // errorMessage("vtObject: VTObjects* is undefined for the given VectorTemplate");
179 return vto;
180 }
181
182 }// asl