fixedValueConstraint.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) 2016-2025 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 "fixedValueConstraint.H"
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "fvcSurfaceIntegrate.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
39 
41  (
45  );
47  (
50  dictionary,
52  "fixedValueConstraint"
53  );
54 }
55 }
56 
57 
58 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
59 
60 void Foam::fv::fixedValueConstraint::readCoeffs(const dictionary& dict)
61 {
62  fieldValues_.clear();
63  forAllConstIter(dictionary, dict.subDict("fieldValues"), iter)
64  {
65  fieldValues_.set
66  (
67  iter().keyword(),
68  new unknownTypeFunction1
69  (
70  iter().keyword(),
71  mesh().time().userUnits(),
72  dict.subDict("fieldValues")
73  )
74  );
75  }
76 
77  fraction_ =
78  dict.found("fraction")
80  (
81  "fraction",
82  mesh().time().userUnits(),
84  dict
85  )
86  : autoPtr<Function1<scalar>>();
87 }
88 
89 
90 template<class Type>
91 bool Foam::fv::fixedValueConstraint::constrainType
92 (
93  fvMatrix<Type>& eqn,
94  const word& fieldName
95 ) const
96 {
97  // Set the value units for the function
98  fieldValues_[fieldName]->template setValueUnits<Type>
99  (
100  eqn.psi().dimensions()
101  );
102 
103  const scalar t = mesh().time().value();
104 
105  const List<Type> values
106  (
107  zone_.nCells(),
108  fieldValues_[fieldName]->value<Type>(t)
109  );
110 
111  if (fraction_.valid())
112  {
113  eqn.setValues
114  (
115  zone_.zone(),
116  values,
117  scalarList(zone_.nCells(), fraction_->value(t))
118  );
119  }
120  else
121  {
122  eqn.setValues(zone_.zone(), values);
123  }
124 
125  return zone_.nCells();
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 (
133  const word& name,
134  const word& modelType,
135  const fvMesh& mesh,
136  const dictionary& dict
137 )
138 :
139  fvConstraint(name, modelType, mesh, dict),
140  zone_(mesh, coeffs(dict))
141 {
142  readCoeffs(coeffs(dict));
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  return fieldValues_.toc();
151 }
152 
153 
155 (
157  fv::fixedValueConstraint
158 );
159 
160 
162 {
163  zone_.movePoints();
164  return true;
165 }
166 
167 
169 {
170  zone_.topoChange(map);
171 }
172 
173 
175 {
176  zone_.mapMesh(map);
177 }
178 
179 
181 (
182  const polyDistributionMap& map
183 )
184 {
185  zone_.distribute(map);
186 }
187 
188 
190 {
192  {
193  zone_.read(coeffs(dict));
194  readCoeffs(coeffs(dict));
195  return true;
196  }
197  else
198  {
199  return false;
200  }
201 }
202 
203 
204 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
Macros for easy insertion into run-time selection tables.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Type & value() const
Return const reference to value.
Finite volume options abstract base class.
Definition: fvConstraint.H:57
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:164
const dictionary & coeffs(const dictionary &) const
Return the coefficients sub-dictionary.
Definition: fvConstraintI.H:41
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvConstraintI.H:34
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
Constrain the field values within a specified region.
virtual bool movePoints()
Update for mesh motion.
fixedValueConstraint(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool read(const dictionary &dict)
Read source dictionary.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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 IMPLEMENT_FV_CONSTRAINT_CONSTRAIN(Type, constraintType)
Definition: fvConstraintM.H:33
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField.
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
addBackwardCompatibleToRunTimeSelectionTable(fvConstraint, fixedTemperature, dictionary, fixedTemperatureConstraint, "fixedTemperatureConstraint")
Namespace for OpenFOAM.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
const unitConversion unitFraction
labelList fv(nPoints)
dictionary dict