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 * * * * * * * * * * * * * * //
29
31:
32 Tuple2<label, vector>(0, Zero)
33{}
34
35
37:
38 Tuple2<label, vector>(pc)
39{}
40
41
43:
44 Tuple2<label, vector>(is)
45{}
46
47
48// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49
51{
52 if (first() == 0)
53 {
54 first() = 1;
55 second() = cd;
56 }
57 else if (first() == 1)
58 {
59 vector planeNormal = cd ^ second();
60 scalar magPlaneNormal = mag(planeNormal);
61
62 if (magPlaneNormal > 1e-3)
63 {
64 first() = 2;
65 second() = planeNormal/magPlaneNormal;
66 }
67 }
68 else if (first() == 2)
69 {
70 if (mag(cd & second()) > 1e-3)
71 {
72 first() = 3;
73 second() = Zero;
74 }
75 }
76}
77
78
80{
81 if (first() == 0)
82 {
83 operator=(pc);
84 }
85 else if (first() == 1)
86 {
87 // Save single normal
88 vector n = second();
89 // Apply to supplied point constaint
90 operator=(pc);
91 applyConstraint(n);
92 }
93 else if (first() == 2)
94 {
95 if (pc.first() == 0)
96 {}
97 else if (pc.first() == 1)
98 {
99 applyConstraint(pc.second());
100 }
101 else if (pc.first() == 2)
102 {
103 // Both constrained to line. Same (+-)direction?
104 if (mag(second() & pc.second()) <= (1.0-1e-3))
105 {
106 // Different directions
107 first() = 3;
108 second() = Zero;
109 }
110 }
111 else
112 {
113 first() = 3;
114 second() = Zero;
115 }
116 }
117}
118
119
121{
122 if (first() == 0)
123 {
124 return I;
125 }
126 else if (first() == 1)
127 {
128 return I - sqr(second());
129 }
130 else if (first() == 2)
131 {
132 return sqr(second());
133 }
134 else
135 {
136 return Zero;
137 }
138}
139
140
142(
143 label& n,
144 tensor& tt
145) const
146{
147 n = 3-first();
148
150
151 if (first() == 0)
152 {
153 vecs[0] = vector(1, 0, 0);
154 vecs[1] = vector(0, 1, 0);
155 vecs[2] = vector(0, 0, 1);
156 }
157 else if (first() == 1)
158 {
159 const vector& planeDir = second();
160
161 vecs[0] = vector(1, 0, 0) - planeDir.x()*planeDir;
162
163 if (mag(vecs[0].x()) < 1e-3)
164 {
165 vecs[0] = vector(0, 1, 0) - planeDir.y()*planeDir;
166 }
167
168 vecs[0] /= mag(vecs[0]);
169 vecs[1] = vecs[0] ^ planeDir;
170 vecs[1] /= mag(vecs[1]);
171 }
172 else if (first() == 2)
173 {
174 vecs[0] = second();
175 }
176
177 // Knock out remaining vectors
178 for (direction dir = n; dir < vecs.size(); dir++)
179 {
180 vecs[dir] = Zero;
181 }
182
183 tt = tensor(vecs[0], vecs[1], vecs[2]);
184}
185
186
188(
189 const vector& d
190) const
191{
192 vector cd;
193
194 if (first() == 0)
195 {
196 cd = d;
197 }
198 else if (first() == 1)
199 {
200 // Remove plane normal
201 cd = d-(d&second())*second();
202 }
203 else if (first() == 2)
204 {
205 // Keep line direction only
206 cd = (d&second())*second();
207 }
208 else
209 {
210 cd = Zero;
211 }
212 return cd;
213}
214
215
217(
219 const pointConstraint& y
220) const
221{
222 x.combine(y);
223}
224
225
227(
228 const tensor& tt,
229 const pointConstraint& v
230)
231{
232 return pointConstraint
233 (
235 );
236}
237
238
239// ************************************************************************* //
scalar y
label n
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
static constexpr label size() noexcept
Return the number of elements in the FixedList.
Definition: FixedList.H:416
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Accumulates point constraints through successive applications of the applyConstraint function.
void applyConstraint(const vector &cd)
Apply and accumulate the effect of the given constraint direction.
pointConstraint()
Construct null.
tensor constraintTransformation() const
Return the accumulated constraint transformation tensor.
void unconstrainedDirections(label &n, tensor &vecs) const
Return the accumulated unconstrained directions. Directions.
vector constrainDisplacement(const vector &disp) const
Constrain a displacement.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
dimensionedSymmTensor sqr(const dimensionedVector &dv)
static const Identity< scalar > I
Definition: Identity.H:94
Tensor< scalar > tensor
Definition: symmTensor.H:61
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
uint8_t direction
Definition: direction.H:56
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Vector< scalar > vector
Definition: vector.H:61
volScalarField & e
Definition: createFields.H:11