magnet.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 Class
27  Foam::magnet
28 
29 Description
30  Class to hold the defining data for a permanent magnet, in particular
31  the name, relative permeability and remanence.
32 
33 SourceFiles
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef magnet_H
38 #define magnet_H
39 
40 #include "dimensionedVector.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of classes
48 class Istream;
49 class Ostream;
50 
51 // Forward declaration of friend functions and operators
52 class magnet;
53 Istream& operator>>(Istream&, magnet&);
54 Ostream& operator<<(Ostream&, const magnet&);
55 
56 /*---------------------------------------------------------------------------*\
57  Class magnet Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class magnet
61 {
62  // Private data
63 
64  word name_;
65  scalar relativePermeability_;
66  dimensionedScalar remanence_;
67  vector orientation_;
68 
69 public:
70 
71  // Constructors
72 
73  //- Null constructor for lists
74  inline magnet()
75  :
76  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), 0),
77  orientation_(Zero)
78  {}
79 
80  //- Construct from components
81  inline magnet
82  (
83  const word& name,
84  const scalar mur,
85  const scalar Mr,
86  const vector& orientation
87  )
88  :
89  name_(name),
90  relativePermeability_(mur),
91  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), Mr),
92  orientation_(orientation)
93  {}
94 
95  //- Construct from Istream
96  inline magnet(Istream& is)
97  :
98  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), 0),
99  orientation_(Zero)
100  {
101  is >> *this;
102  }
103 
104 
105  // Member Functions
106 
107  //- Return name
108  inline const word& name() const
109  {
110  return name_;
111  }
112 
113  //- Return relative permeability
114  inline scalar mur() const
115  {
116  return relativePermeability_;
117  }
118 
119  //- Return remenance
120  inline const dimensionedScalar& Mr() const
121  {
122  return remanence_;
123  }
124 
125  //- Return orientation
126  inline const vector& orientation() const
127  {
128  return orientation_;
129  }
130 
131 
132  // IOstream operators
133 
134  inline friend Istream& operator>>(Istream& is, magnet& m)
135  {
136  is.readBegin("magnet");
137  is >> m.name_
138  >> m.relativePermeability_
139  >> m.remanence_.value()
140  >> m.orientation_;
141  is.readEnd("magnet");
142 
143  is.check(FUNCTION_NAME);
144  return is;
145  }
146 
147  inline friend Ostream& operator<<(Ostream& os, const magnet& m)
148  {
149  os << token::BEGIN_LIST
150  << m.name_ << token::SPACE
151  << m.relativePermeability_ << token::SPACE
152  << m.remanence_.value()
153  << m.orientation_
154  << token::END_LIST;
155 
156  return os;
157  }
158 };
159 
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 } // End namespace Foam
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #endif
168 
169 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::magnet::magnet
magnet()
Null constructor for lists.
Definition: magnet.H:73
Foam::magnet::operator>>
friend Istream & operator>>(Istream &is, magnet &m)
Definition: magnet.H:133
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:65
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:127
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:109
Foam::magnet::mur
scalar mur() const
Return relative permeability.
Definition: magnet.H:113
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::magnet::orientation
const vector & orientation() const
Return orientation.
Definition: magnet.H:125
Foam::magnet::name
const word & name() const
Return name.
Definition: magnet.H:107
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::magnet
Class to hold the defining data for a permanent magnet, in particular the name, relative permeability...
Definition: magnet.H:59
Foam::magnet::magnet
magnet(Istream &is)
Construct from Istream.
Definition: magnet.H:95
dimensionedVector.H
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::dimensioned< scalar >
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::magnet::Mr
const dimensionedScalar & Mr() const
Return remenance.
Definition: magnet.H:119
Foam::Vector< scalar >
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::magnet::operator<<
friend Ostream & operator<<(Ostream &os, const magnet &m)
Definition: magnet.H:146