refineCell.C
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-2017 OpenFOAM Foundation
9  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "refineCell.H"
30 #include "error.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
36  cellNo_(-1),
37  direction_(Zero)
38 {}
39 
40 
41 Foam::refineCell::refineCell(const label celli, const vector& direction)
42 :
43  cellNo_(celli),
44  direction_(direction)
45 {
46  scalar magDir = mag(direction_);
47 
48  if (magDir < SMALL)
49  {
51  << "(almost)zero vector as direction for cell " << cellNo_
52  << abort(FatalError);
53  }
54  else if (mag(magDir - 1) > SMALL)
55  {
56  // Normalize
57  direction_ /= mag(direction_);
58  }
59 }
60 
61 
63 :
64  cellNo_(readLabel(is)),
65  direction_(is)
66 {
67  scalar magDir = mag(direction_);
68 
69  if (magDir < SMALL)
70  {
72  << "(almost)zero vector as direction for cell " << cellNo_
73  << abort(FatalError);
74  }
75  else if (mag(magDir - 1) > SMALL)
76  {
77  // Normalize
78  direction_ /= mag(direction_);
79  }
80 }
81 
82 
83 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
84 
85 Foam::Ostream& Foam::operator<<(Ostream& os, const refineCell& r)
86 {
88  {
89  os << r.cellNo() << token::SPACE << r.direction();
90  }
91  else
92  {
93  os << r.cellNo() << r.direction();
94  }
95  return os;
96 }
97 
98 
99 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
refineCell()
Default construct.
Definition: refineCell.C:27
"ascii" (normal default)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
Space [isspace].
Definition: token.H:131
errorManip< error > abort(error &err)
Definition: errorManip.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
streamFormat format() const noexcept
Get the current stream format.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127