fvConstraint.C
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) 2021-2024 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 #include "fvConstraint.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 template<class Type>
41 bool Foam::fvConstraint::constrainType
42 (
43  fvMatrix<Type>& eqn,
44  const word& fieldName
45 ) const
46 {
47  return false;
48 }
49 
50 
51 template<class Type>
52 bool Foam::fvConstraint::constrainType(VolField<Type>& field) const
53 {
54  return false;
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 (
62  const word& name,
63  const word& constraintType,
64  const fvMesh& mesh,
65  const dictionary& dict
66 )
67 :
68  name_(name),
69  constraintType_(constraintType),
70  mesh_(mesh)
71 {
72  Info<< incrIndent << indent << "Name: " << name_
73  << endl << decrIndent;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
78 
80 (
81  const word& name,
82  const fvMesh& mesh,
83  const dictionary& dict
84 )
85 {
86  const word constraintType(dict.lookup("type"));
87 
88  Info<< indent
89  << "Selecting finite volume constraint type " << constraintType << endl;
90 
91  if
92  (
93  !dictionaryConstructorTablePtr_
94  || dictionaryConstructorTablePtr_->find(constraintType)
95  == dictionaryConstructorTablePtr_->end()
96  )
97  {
98  if
99  (
100  !libs.open
101  (
102  dict,
103  "libs",
104  dictionaryConstructorTablePtr_
105  )
106  )
107  {
108  libs.open("lib" + constraintType.remove(':') + ".so", false);
109  }
110 
111  if (!dictionaryConstructorTablePtr_)
112  {
114  << "Unknown constraint type "
115  << constraintType << nl << nl
116  << "Table of fvConstraints is empty"
117  << exit(FatalError);
118  }
119  }
120 
121  dictionaryConstructorTable::iterator cstrIter =
122  dictionaryConstructorTablePtr_->find(constraintType);
123 
124  if (cstrIter == dictionaryConstructorTablePtr_->end())
125  {
127  << "Unknown fvConstraint " << constraintType << nl << nl
128  << "Valid fvConstraints are:" << nl
129  << dictionaryConstructorTablePtr_->sortedToc()
130  << exit(FatalIOError);
131  }
132 
133  return autoPtr<fvConstraint>
134  (
135  cstrIter()(name, constraintType, mesh, dict)
136  );
137 }
138 
139 
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
147 {
148  return wordList::null();
149 }
150 
151 
152 bool Foam::fvConstraint::constrainsField(const word& fieldName) const
153 {
154  return findIndex(constrainedFields(), fieldName) != -1;
155 }
156 
157 
159 
160 
162 
163 
165 {
166  return true;
167 }
168 
169 
170 // ************************************************************************* //
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
Finite volume options abstract base class.
Definition: fvConstraint.H:57
fvConstraint(const word &name, const word &constraintType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
Definition: fvConstraint.C:61
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:164
virtual bool constrainsField(const word &fieldName) const
Return true if the given field is constrained.
Definition: fvConstraint.C:152
virtual wordList constrainedFields() const
Return the list of constrained fields.
Definition: fvConstraint.C:146
virtual ~fvConstraint()
Destructor.
Definition: fvConstraint.C:140
static autoPtr< fvConstraint > New(const word &name, const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected fvConstraint.
Definition: fvConstraint.C:80
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
bool remove(const char)
Remove all occurrences of character returning true if string changed.
Definition: string.C:132
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IMPLEMENT_FV_CONSTRAINT_CONSTRAIN_FIELD(Type, constraintType)
Definition: fvConstraintM.H:49
#define IMPLEMENT_FV_CONSTRAINT_CONSTRAIN(Type, constraintType)
Definition: fvConstraintM.H:33
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:242
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:235
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:228
static const char nl
Definition: Ostream.H:267
dictionary dict