magnet.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) 2011-2019 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 Class
25  Foam::magnet
26 
27 Description
28  Class to hold the defining data for a permanent magnet, in particular
29  the name, relative permeability and remanence.
30 
31 SourceFiles
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef magnet_H
36 #define magnet_H
37 
38 #include "dimensionedVector.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class Istream;
47 class Ostream;
48 
49 // Forward declaration of friend functions and operators
50 class magnet;
51 Istream& operator>>(Istream&, magnet&);
52 Ostream& operator<<(Ostream&, const magnet&);
53 
54 /*---------------------------------------------------------------------------*\
55  Class magnet Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class magnet
59 {
60  // Private Data
61 
62  word name_;
63  scalar relativePermeability_;
64  dimensionedScalar remanence_;
65  vector orientation_;
66 
67 public:
68 
69  // Constructors
70 
71  //- Null constructor for lists
72  inline magnet()
73  :
74  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), 0),
75  orientation_(Zero)
76  {}
77 
78  //- Construct from components
79  inline magnet
80  (
81  const word& name,
82  const scalar mur,
83  const scalar Mr,
84  const vector& orientation
85  )
86  :
87  name_(name),
88  relativePermeability_(mur),
89  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), Mr),
90  orientation_(orientation)
91  {}
92 
93  //- Construct from Istream
94  inline magnet(Istream& is)
95  :
96  remanence_("Mr", dimensionSet(0, -1, 0, 0, 0, 1, 0), 0),
97  orientation_(Zero)
98  {
99  is >> *this;
100  }
101 
102 
103  // Member Functions
104 
105  //- Return name
106  inline const word& name() const
107  {
108  return name_;
109  }
110 
111  //- Return relative permeability
112  inline scalar mur() const
113  {
114  return relativePermeability_;
115  }
116 
117  //- Return remenance
118  inline const dimensionedScalar& Mr() const
119  {
120  return remanence_;
121  }
122 
123  //- Return orientation
124  inline const vector& orientation() const
125  {
126  return orientation_;
127  }
128 
129 
130  // IOstream Operators
132  inline friend Istream& operator>>(Istream& is, magnet& m)
133  {
134  is.readBegin("magnet");
135  is >> m.name_
136  >> m.relativePermeability_
137  >> m.remanence_.value()
138  >> m.orientation_;
139  is.readEnd("magnet");
140 
141  // Check state of Istream
142  is.check("operator>>(Istream&, magnet&)");
143 
144  return is;
145  }
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 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
Class to hold the defining data for a permanent magnet, in particular the name, relative permeability...
Definition: magnet.H:57
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionedScalar & Mr() const
Return remenance.
Definition: magnet.H:117
friend Istream & operator>>(Istream &is, magnet &m)
Definition: magnet.H:131
friend Ostream & operator<<(Ostream &os, const magnet &m)
Definition: magnet.H:146
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
Dimension set for the base types.
Definition: dimensionSet.H:120
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
const Type & value() const
Return const reference to value.
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
magnet()
Null constructor for lists.
Definition: magnet.H:71
const vector & orientation() const
Return orientation.
Definition: magnet.H:123
Ostream & operator<<(Ostream &, const ensightPart &)
const word & name() const
Return name.
Definition: magnet.H:105
Namespace for OpenFOAM.
scalar mur() const
Return relative permeability.
Definition: magnet.H:111