Loading...
Searching...
No Matches
pointConstraintI.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33{}
34
43(
44 const label count,
45 const vector& n
46)
47:
48 Tuple2<label, vector>(count, n)
49{}
50
51
54 Tuple2<label, vector>(is)
55{}
56
57
58// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59
61{
62 if (first() == 0)
63 {
64 first() = 1;
65 second() = cd;
66 }
67 else if (first() == 1)
68 {
69 vector planeNormal = cd ^ second();
70 scalar magPlaneNormal = mag(planeNormal);
71
72 if (magPlaneNormal > 1e-3)
73 {
74 first() = 2;
75 second() = planeNormal/magPlaneNormal;
76 }
77 }
78 else if (first() == 2)
79 {
80 if (mag(cd & second()) > 1e-3)
81 {
82 first() = 3;
83 second() = Zero;
84 }
85 }
86}
87
88
90{
91 if (first() == 0)
92 {
93 operator=(pc);
94 }
95 else if (first() == 1)
96 {
97 // Save single normal
98 vector n = second();
99 // Apply to supplied point constaint
100 operator=(pc);
101 applyConstraint(n);
102 }
103 else if (first() == 2)
104 {
105 if (pc.first() == 0)
106 {}
107 else if (pc.first() == 1)
108 {
109 applyConstraint(pc.second());
110 }
111 else if (pc.first() == 2)
112 {
113 // Both constrained to line. Same (+-)direction?
114 if (mag(second() & pc.second()) <= (1.0-1e-3))
115 {
116 // Different directions
117 first() = 3;
118 second() = Zero;
119 }
120 }
121 else
122 {
123 first() = 3;
124 second() = Zero;
125 }
126 }
127}
128
129
131{
132 if (first() == 0)
133 {
134 return I;
135 }
136 else if (first() == 1)
137 {
138 return I - sqr(second());
139 }
140 else if (first() == 2)
141 {
142 return sqr(second());
143 }
144 else
145 {
146 return Zero;
147 }
148}
149
150
152(
153 label& n,
154 tensor& tt
155) const
156{
157 n = 3-first();
158
159 FixedList<vector, 3> vecs;
160
161 if (first() == 0)
162 {
163 vecs[0] = vector(1, 0, 0);
164 vecs[1] = vector(0, 1, 0);
165 vecs[2] = vector(0, 0, 1);
166 }
167 else if (first() == 1)
168 {
169 const vector& planeDir = second();
170
171 vecs[0] = vector(1, 0, 0) - planeDir.x()*planeDir;
172
173 if (mag(vecs[0].x()) < 1e-3)
174 {
175 vecs[0] = vector(0, 1, 0) - planeDir.y()*planeDir;
176 }
177
178 vecs[0] /= mag(vecs[0]);
179 vecs[1] = vecs[0] ^ planeDir;
180 vecs[1] /= mag(vecs[1]);
181 }
182 else if (first() == 2)
183 {
184 vecs[0] = second();
185 }
186
187 // Knock out remaining vectors
188 for (direction dir = n; dir < vecs.size(); dir++)
189 {
190 vecs[dir] = Zero;
191 }
192
193 tt = tensor(vecs[0], vecs[1], vecs[2]);
194}
195
196
198(
199 const vector& d
200) const
201{
202 vector cd;
203
204 if (first() == 0)
205 {
206 cd = d;
207 }
208 else if (first() == 1)
209 {
210 // Remove plane normal
211 cd = d-(d&second())*second();
212 }
213 else if (first() == 2)
214 {
215 // Keep line direction only
216 cd = (d&second())*second();
217 }
218 else
220 cd = Zero;
221 }
222 return cd;
223}
224
225
226inline Foam::pointConstraint Foam::transform
227(
228 const tensor& tt,
229 const pointConstraint& v
230)
231{
232 return pointConstraint(v.first(), transform(tt, v.second()));
233}
234
235
236// ************************************************************************* //
label n
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
static constexpr label size() noexcept
Return the number of elements in the FixedList.
Definition FixedList.H:619
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
const label & first() const noexcept
Definition Tuple2.H:132
const vector & second() const noexcept
Definition Tuple2.H:142
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
Accumulates point constraints through successive applications of the applyConstraint function.
void combine(const pointConstraint &)
Combine constraints.
void applyConstraint(const vector &cd)
Apply and accumulate the effect of the given constraint direction.
pointConstraint()
Default construct zero-initialized.
tensor constraintTransformation() const
Return the accumulated constraint transformation tensor.
void unconstrainedDirections(label &n, tensor &vecs) const
Return the accumulated unconstrained directions. Directions coded as first n rows of tensor.
vector constrainDisplacement(const vector &disp) const
Constrain a displacement.
Tensor of scalars, i.e. Tensor<scalar>.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
dimensionedSymmTensor sqr(const dimensionedVector &dv)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
static const Identity< scalar > I
Definition Identity.H:100
Tensor< scalar > tensor
Definition symmTensor.H:57
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
uint8_t direction
Definition direction.H:49
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
Vector< scalar > vector
Definition vector.H:57
volScalarField & e