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-2026 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 
73 
74 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
75 
77 (
78  const word& name,
79  const fvMesh& mesh,
80  const dictionary& dict
81 )
82 {
83  const word type(dict.lookup("type"));
84 
85  Info<< indentOrNl << "Selecting " << type
86  << " with name " << name << endl;
87 
88  if
89  (
90  !dictionaryConstructorTablePtr_
91  || dictionaryConstructorTablePtr_->find(type)
92  == dictionaryConstructorTablePtr_->end()
93  )
94  {
95  if
96  (
97  !libs.open
98  (
99  dict,
100  "libs",
101  dictionaryConstructorTablePtr_
102  )
103  )
104  {
105  libs.open("lib" + type.remove(':') + ".so", false);
106  }
107 
108  if (!dictionaryConstructorTablePtr_)
109  {
111  << "Unknown constraint type "
112  << type << nl << nl
113  << "Table of fvConstraints is empty"
114  << exit(FatalError);
115  }
116  }
117 
118  dictionaryConstructorTable::iterator cstrIter =
119  dictionaryConstructorTablePtr_->find(type);
120 
121  if (cstrIter == dictionaryConstructorTablePtr_->end())
122  {
124  << "Unknown fvConstraint " << type << nl << nl
125  << "Valid fvConstraints are:" << nl
126  << dictionaryConstructorTablePtr_->sortedToc()
127  << exit(FatalIOError);
128  }
129 
130  printDictionary print(dict);
131 
132  return autoPtr<fvConstraint>
133  (
134  cstrIter()(name, type, mesh, dict)
135  );
136 }
137 
138 
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 {
147  return wordList::null();
148 }
149 
150 
151 bool Foam::fvConstraint::constrainsField(const word& fieldName) const
152 {
153  return findIndex(constrainedFields(), fieldName) != -1;
154 }
155 
156 
158 
159 
161 
162 
164 {
165  return true;
166 }
167 
168 
169 // ************************************************************************* //
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:669
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:163
virtual bool constrainsField(const word &fieldName) const
Return true if the given field is constrained.
Definition: fvConstraint.C:151
virtual wordList constrainedFields() const
Return the list of constrained fields.
Definition: fvConstraint.C:145
virtual ~fvConstraint()
Destructor.
Definition: fvConstraint.C:139
static autoPtr< fvConstraint > New(const word &name, const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected fvConstraint.
Definition: fvConstraint.C:77
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
Enables the printing of a dictionary and subsequently looked-up defaulted entries.
A class for handling words, derived from string.
Definition: word.H:63
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 & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
messageStream Info
defineRunTimeSelectionTable(fvConstraint, dictionary)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict