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-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 "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()
61 {
62  fieldValues_.clear();
63  forAllConstIter(dictionary, coeffs().subDict("fieldValues"), iter)
64  {
65  fieldValues_.set
66  (
67  iter().keyword(),
68  new unknownTypeFunction1
69  (
70  iter().keyword(),
71  mesh().time().userUnits(),
72  coeffs().subDict("fieldValues")
73  )
74  );
75  }
76 
77  fraction_ =
78  coeffs().found("fraction")
80  (
81  "fraction",
82  mesh().time().userUnits(),
84  coeffs()
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  set_.nCells(),
108  fieldValues_[fieldName]->value<Type>(t)
109  );
110 
111  if (fraction_.valid())
112  {
113  eqn.setValues
114  (
115  set_.cells(),
116  values,
117  scalarList(set_.nCells(), fraction_->value(t))
118  );
119  }
120  else
121  {
122  eqn.setValues(set_.cells(), values);
123  }
124 
125  return set_.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  set_(mesh, coeffs())
141 {
142  readCoeffs();
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  return fieldValues_.toc();
151 }
152 
153 
155 (
157  fv::fixedValueConstraint
158 );
159 
160 
162 {
163  set_.movePoints();
164  return true;
165 }
166 
167 
169 {
170  set_.topoChange(map);
171 }
172 
173 
175 {
176  set_.mapMesh(map);
177 }
178 
179 
181 (
182  const polyDistributionMap& map
183 )
184 {
185  set_.distribute(map);
186 }
187 
188 
190 {
192  {
193  set_.read(coeffs());
194  readCoeffs();
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:477
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
Finite volume options abstract base class.
Definition: fvConstraint.H:57
const dictionary & coeffs() const
Return dictionary.
Definition: fvConstraintI.H:40
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:166
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:99
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
#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.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
const unitConversion unitFraction
labelList fv(nPoints)
dictionary dict