RootsI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template <Foam::direction N>
30 :
31  types_(0)
32 {
33  forAll(*this, i)
34  {
35  type(i, roots::nan);
36  }
37 }
38 
39 
40 template <Foam::direction N>
41 inline Foam::Roots<N>::Roots(const roots::type t, const scalar x)
42 :
43  types_(0)
44 {
45  forAll(*this, i)
46  {
47  this->v_[i] = x;
48  type(i, t);
49  }
50 }
51 
52 
53 template <Foam::direction N>
55 (
56  const roots::type t,
57  const scalar x,
58  const Roots<N - 1>& xs
59 )
60 :
61  types_(0)
62 {
63  this->v_[0] = x;
64  type(0, t);
65  forAll(xs, i)
66  {
67  this->v_[i+1] = xs[i];
68  type(i + 1, xs.type(i));
69  }
70 }
71 
72 
73 template <Foam::direction N>
75 (
76  const Roots<N - 1>& xs,
77  const roots::type t,
78  const scalar x
79 )
80 :
81  types_(0)
82 {
83  forAll(xs, i)
84  {
85  this->v_[i] = xs[i];
86  type(i, xs.type(i));
87  }
88  this->v_[N-1] = x;
89  type(N - 1, t);
90 }
91 
92 
93 template <Foam::direction N>
94 template <Foam::direction M>
96 (
97  const Roots<M>& xs,
98  const Roots<N - M>& ys
99 )
100 :
101  types_(0)
102 {
103  forAll(xs, i)
104  {
105  this->v_[i] = xs[i];
106  type(i, xs.type(i));
107  }
108  forAll(ys, i)
109  {
110  this->v_[i + M] = ys[i];
111  type(i + M, ys.type(i));
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
118 template <Foam::direction N>
119 inline void Foam::Roots<N>::type
120 (
121  const direction i,
122  const roots::type t
123 )
124 {
125  types_ += (t - type(i)) << 3*i;
126 }
127 
128 
129 template <Foam::direction N>
131 {
132  return static_cast<roots::type>((types_ >> 3*i) & 7);
133 }
134 
135 
136 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
type
Types of root.
Definition: Roots.H:52
uint8_t direction
Definition: direction.H:45
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
Definition: Roots.H:68
Roots()
Construct null.
Definition: RootsI.H:29
void type(const direction i, const roots::type t)
Set the type of the i-th root.
Definition: RootsI.H:120
label N
Definition: createFields.H:22
#define M(I)
scalar v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81