ENH: codedFixedValue: refactored codedFixedValue and codedFunctionObject
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / codedFixedValue / codedFixedValueFvPatchField.H
blob56fef9354e49b159835194a49a8e38c2080f38b1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::codedFixedValueFvPatchField
27 Description
28     Constructs on-the-fly a new boundary condition (derived from
29     fixedValueFvPatchField) which is then used to evaluate.
31     Example:
32     \verbatim
33         movingWall
34         {
35             type            codedFixedValue;
36             value           uniform 0;
37             redirectType    rampedFixedValue;   // name of generated bc
39             code
40             #{
41                 operator==(min(10, 0.1*this->db().time().value()));
42             #};
44             //codeInclude
45             //#{
46             //    #include "fvCFD.H"
47             //#};
49             //codeOptions
50             //#{
51             //    -I$(LIB_SRC)/finiteVolume/lnInclude
52             //#};
53         }
54     \endverbatim
56     A special form is if the 'code' section is not supplied. In this case
57     the code gets read from a (runTimeModifiable!) dictionary system/codeDict
58     which would have a corresponding entry
60     \verbatim
61     rampedFixedValue
62     {
63         code
64         #{
65             operator==(min(10, 0.1*this->db().time().value()));
66         #};
67     }
68     \endverbatim
70 SeeAlso
71     Foam::dynamicCode and Foam::functionEntries::codeStream
73 SourceFiles
74     codedFixedValueFvPatchField.C
76 \*---------------------------------------------------------------------------*/
78 #ifndef codedFixedValueFvPatchField_H
79 #define codedFixedValueFvPatchField_H
81 #include "fixedValueFvPatchFields.H"
82 #include "codedBase.H"
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 namespace Foam
89 // Forward declaration of classes
90 class dynamicCode;
91 class dynamicCodeContext;
92 class IOdictionary;
94 /*---------------------------------------------------------------------------*\
95                      Class codedFixedValueFvPatch Declaration
96 \*---------------------------------------------------------------------------*/
98 template<class Type>
99 class codedFixedValueFvPatchField
101     public fixedValueFvPatchField<Type>,
102     public codedBase
104     // Private data
106         //- Dictionary contents for the boundary condition
107         mutable dictionary dict_;
109         const word redirectType_;
111         mutable autoPtr<fvPatchField<Type> > redirectPatchFieldPtr_;
113     // Private Member Functions
115         const IOdictionary& dict() const;
117         //- Set the rewrite vars controlling the Type
118         static void setFieldTemplates(dynamicCode& dynCode);
120         //- get the loaded dynamic libraries
121         virtual dlLibraryTable& libs() const;
123         //- adapt the context for the current object
124         virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
126         // Return a description (type + name) for the output
127         virtual string description() const;
129         // Clear the ptr to the redirected object
130         virtual void clearRedirect() const;
132         // Get the dictionary to initialize the codeContext
133         virtual const dictionary& codeDict() const;
135 public:
137     // Static data members
139         //- Name of the C code template to be used
140         static const word codeTemplateC;
142         //- Name of the H code template to be used
143         static const word codeTemplateH;
146     //- Runtime type information
147     TypeName("codedFixedValue");
150     // Constructors
152         //- Construct from patch and internal field
153         codedFixedValueFvPatchField
154         (
155             const fvPatch&,
156             const DimensionedField<Type, volMesh>&
157         );
159         //- Construct from patch, internal field and dictionary
160         codedFixedValueFvPatchField
161         (
162             const fvPatch&,
163             const DimensionedField<Type, volMesh>&,
164             const dictionary&
165         );
167         //- Construct by mapping given codedFixedValueFvPatchField
168         //  onto a new patch
169         codedFixedValueFvPatchField
170         (
171             const codedFixedValueFvPatchField<Type>&,
172             const fvPatch&,
173             const DimensionedField<Type, volMesh>&,
174             const fvPatchFieldMapper&
175         );
177         //- Construct as copy
178         codedFixedValueFvPatchField
179         (
180             const codedFixedValueFvPatchField<Type>&
181         );
183         //- Construct and return a clone
184         virtual tmp<fvPatchField<Type> > clone() const
185         {
186             return tmp<fvPatchField<Type> >
187             (
188                 new codedFixedValueFvPatchField<Type>(*this)
189             );
190         }
192         //- Construct as copy setting internal field reference
193         codedFixedValueFvPatchField
194         (
195             const codedFixedValueFvPatchField<Type>&,
196             const DimensionedField<Type, volMesh>&
197         );
199         //- Construct and return a clone setting internal field reference
200         virtual tmp<fvPatchField<Type> > clone
201         (
202             const DimensionedField<Type, volMesh>& iF
203         ) const
204         {
205             return tmp<fvPatchField<Type> >
206             (
207                 new codedFixedValueFvPatchField<Type>(*this, iF)
208             );
209         }
214     // Member functions
216         //- Get reference to the underlying patch
217         const fvPatchField<Type>& redirectPatchField() const;
219         //- Update the coefficients associated with the patch field
220         virtual void updateCoeffs();
222         //- Evaluate the patch field, sets Updated to false
223         virtual void evaluate
224         (
225             const Pstream::commsTypes commsType=Pstream::blocking
226         );
228         //- Write
229         virtual void write(Ostream&) const;
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 } // End namespace Foam
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 #ifdef NoRepository
240 #   include "codedFixedValueFvPatchField.C"
241 #endif
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 #endif
247 // ************************************************************************* //