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-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 "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  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::fv::fixedValueConstraint::readCoeffs()
53 {
54  fieldValues_.clear();
55  forAllConstIter(dictionary, coeffs().subDict("fieldValues"), iter)
56  {
57  fieldValues_.set
58  (
59  iter().keyword(),
60  new unknownTypeFunction1
61  (
62  iter().keyword(),
63  coeffs().subDict("fieldValues")
64  )
65  );
66  }
67 
68  fraction_ =
69  coeffs().found("fraction")
70  ? Function1<scalar>::New("fraction", coeffs())
71  : autoPtr<Function1<scalar>>();
72 }
73 
74 
75 template<class Type>
76 bool Foam::fv::fixedValueConstraint::constrainType
77 (
78  fvMatrix<Type>& eqn,
79  const word& fieldName
80 ) const
81 {
82  const scalar t = mesh().time().userTimeValue();
83 
84  const List<Type> values
85  (
86  set_.nCells(),
87  fieldValues_[fieldName]->value<Type>(t)
88  );
89 
90  if (fraction_.valid())
91  {
92  eqn.setValues
93  (
94  set_.cells(),
95  values,
96  scalarList(set_.nCells(), fraction_->value(t))
97  );
98  }
99  else
100  {
101  eqn.setValues(set_.cells(), values);
102  }
103 
104  return set_.nCells();
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
111 (
112  const word& name,
113  const word& modelType,
114  const fvMesh& mesh,
115  const dictionary& dict
116 )
117 :
118  fvConstraint(name, modelType, mesh, dict),
119  set_(mesh, coeffs())
120 {
121  readCoeffs();
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 {
129  return fieldValues_.toc();
130 }
131 
132 
134 (
136  fv::fixedValueConstraint
137 );
138 
139 
141 {
142  set_.movePoints();
143  return true;
144 }
145 
146 
148 {
149  set_.topoChange(map);
150 }
151 
152 
154 {
155  set_.mapMesh(map);
156 }
157 
158 
160 (
161  const polyDistributionMap& map
162 )
163 {
164  set_.distribute(map);
165 }
166 
167 
169 {
171  {
172  set_.read(coeffs());
173  readCoeffs();
174  return true;
175  }
176  else
177  {
178  return false;
179  }
180 }
181 
182 
183 // ************************************************************************* //
#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 dictionary &dict)
Selector.
Definition: Function1New.C:32
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:659
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
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
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)
Namespace for OpenFOAM.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
FOR_ALL_FIELD_TYPES(DefineContiguousFvWallLocationDataType)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList fv(nPoints)
dictionary dict