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-2023 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  dict_(dict),
72  coeffs_(dict.optionalSubDict(constraintType + "Coeffs"))
73 {
74  Info<< incrIndent << indent << "Name: " << name_
75  << endl << decrIndent;
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
80 
82 (
83  const word& name,
84  const fvMesh& mesh,
85  const dictionary& dict
86 )
87 {
88  const word constraintType(dict.lookup("type"));
89 
90  Info<< indent
91  << "Selecting finite volume constraint type " << constraintType << endl;
92 
93  if
94  (
95  !dictionaryConstructorTablePtr_
96  || dictionaryConstructorTablePtr_->find(constraintType)
97  == dictionaryConstructorTablePtr_->end()
98  )
99  {
100  if
101  (
102  !libs.open
103  (
104  dict,
105  "libs",
106  dictionaryConstructorTablePtr_
107  )
108  )
109  {
110  libs.open("lib" + constraintType.remove(':') + ".so", false);
111  }
112 
113  if (!dictionaryConstructorTablePtr_)
114  {
116  << "Unknown constraint type "
117  << constraintType << nl << nl
118  << "Table of fvConstraints is empty"
119  << exit(FatalError);
120  }
121  }
122 
123  dictionaryConstructorTable::iterator cstrIter =
124  dictionaryConstructorTablePtr_->find(constraintType);
125 
126  if (cstrIter == dictionaryConstructorTablePtr_->end())
127  {
129  << "Unknown fvConstraint " << constraintType << nl << nl
130  << "Valid fvConstraints are:" << nl
131  << dictionaryConstructorTablePtr_->sortedToc()
132  << exit(FatalIOError);
133  }
134 
135  return autoPtr<fvConstraint>
136  (
137  cstrIter()(name, constraintType, mesh, dict)
138  );
139 }
140 
141 
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  return wordList::null();
151 }
152 
153 
154 bool Foam::fvConstraint::constrainsField(const word& fieldName) const
155 {
156  return findIndex(constrainedFields(), fieldName) != -1;
157 }
158 
159 
161 
162 
164 
165 
167 {
168  coeffs_ = dict.optionalSubDict(constraintType_ + "Coeffs");
169 
170  return true;
171 }
172 
173 
174 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:1076
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:166
virtual bool constrainsField(const word &fieldName) const
Return true if the given field is constrained.
Definition: fvConstraint.C:154
virtual wordList constrainedFields() const
Return the list of constrained fields.
Definition: fvConstraint.C:148
virtual ~fvConstraint()
Destructor.
Definition: fvConstraint.C:142
static autoPtr< fvConstraint > New(const word &name, const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected fvConstraint.
Definition: fvConstraint.C:82
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
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
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
#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:235
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
FOR_ALL_FIELD_TYPES(DefineContiguousFvWallLocationDataType)
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
static const char nl
Definition: Ostream.H:260
dictionary dict