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 -------------------------------------------------------------------------------
10 License
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  const label count,
45  const vector& n
46 )
47 :
48  Tuple2<label, vector>(count, n)
49 {}
50 
51 
53 :
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 
89 inline void Foam::pointConstraint::combine(const pointConstraint& pc)
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
219  {
220  cd = Zero;
221  }
222  return cd;
223 }
224 
225 
226 inline void Foam::combineConstraintsEqOp::operator()
227 (
228  pointConstraint& x,
229  const pointConstraint& y
230 ) const
231 {
232  x.combine(y);
233 }
234 
235 
237 (
238  const tensor& tt,
239  const pointConstraint& v
240 )
241 {
242  return pointConstraint
243  (
244  Tuple2<label, vector>(v.first(), transform(tt, v.second()))
245  );
246 }
247 
248 
249 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:56
void unconstrainedDirections(label &n, tensor &vecs) const
Return the accumulated unconstrained directions. Directions.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Tensor< scalar > tensor
Definition: symmTensor.H:57
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector.H:140
void combine(const pointConstraint &)
Combine constraints.
void applyConstraint(const vector &cd)
Apply and accumulate the effect of the given constraint direction.
scalar y
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
static const Identity< scalar > I
Definition: Identity.H:100
Vector< scalar > vector
Definition: vector.H:57
Accumulates point constraints through successive applications of the applyConstraint function...
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
tensor constraintTransformation() const
Return the accumulated constraint transformation tensor.
vector constrainDisplacement(const vector &disp) const
Constrain a displacement.
label n
Tensor of scalars, i.e. Tensor<scalar>.
pointConstraint()
Construct null.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127