Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / codedFixedValue / codedFixedValueFvPatchField.H
blob096c02da004c2a889fc7745a1ed2766c1dac666f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011-2011 OpenCFD Ltd.
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"
83 #include <dlfcn.h>
84 #include <link.h>
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 namespace Foam
91 // Forward declaration of classes
92 class dynamicCode;
93 class dynamicCodeContext;
94 class IOdictionary;
96 /*---------------------------------------------------------------------------*\
97                      Class codedFixedValueFvPatch Declaration
98 \*---------------------------------------------------------------------------*/
100 template<class Type>
101 class codedFixedValueFvPatchField
103     public fixedValueFvPatchField<Type>
105     // Private data
107         //- Dictionary contents for the boundary condition
108         mutable dictionary dict_;
110         const word redirectType_;
112         //- Previously loaded library
113         mutable fileName oldLibPath_;
115         mutable autoPtr<fvPatchField<Type> > redirectPatchFieldPtr_;
118     // Private Member Functions
120         const IOdictionary& dict() const;
122         //- Global loader/unloader function type
123         typedef void (*loaderFunctionType)(bool);
125         static int collectLibsCallback
126         (
127             struct dl_phdr_info *info,
128             size_t size,
129             void *data
130         );
132         //- Load specified library and execute globalFuncName(true)
133         void* loadLibrary
134         (
135             const fileName& libPath,
136             const string& globalFuncName,
137             const dictionary& contextDict
138         ) const;
140         //- Execute globalFuncName(false) and unload specified library
141         void unloadLibrary
142         (
143             const fileName& libPath,
144             const string& globalFuncName,
145             const dictionary& contextDict
146         ) const;
148         //- Set the rewrite vars controlling the Type
149         static void setFieldTemplates(dynamicCode& dynCode);
151         //- Create library based on the dynamicCodeContext
152         void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
154         //- Update library as required
155         void updateLibrary() const;
158 public:
160     // Static data members
162         //- Name of the C code template to be used
163         static const word codeTemplateC;
165         //- Name of the H code template to be used
166         static const word codeTemplateH;
169     //- Runtime type information
170     TypeName("codedFixedValue");
173     // Constructors
175         //- Construct from patch and internal field
176         codedFixedValueFvPatchField
177         (
178             const fvPatch&,
179             const DimensionedField<Type, volMesh>&
180         );
182         //- Construct from patch, internal field and dictionary
183         codedFixedValueFvPatchField
184         (
185             const fvPatch&,
186             const DimensionedField<Type, volMesh>&,
187             const dictionary&
188         );
190         //- Construct by mapping given codedFixedValueFvPatchField
191         //  onto a new patch
192         codedFixedValueFvPatchField
193         (
194             const codedFixedValueFvPatchField<Type>&,
195             const fvPatch&,
196             const DimensionedField<Type, volMesh>&,
197             const fvPatchFieldMapper&
198         );
200         //- Construct as copy
201         codedFixedValueFvPatchField
202         (
203             const codedFixedValueFvPatchField<Type>&
204         );
206         //- Construct and return a clone
207         virtual tmp<fvPatchField<Type> > clone() const
208         {
209             return tmp<fvPatchField<Type> >
210             (
211                 new codedFixedValueFvPatchField<Type>(*this)
212             );
213         }
215         //- Construct as copy setting internal field reference
216         codedFixedValueFvPatchField
217         (
218             const codedFixedValueFvPatchField<Type>&,
219             const DimensionedField<Type, volMesh>&
220         );
222         //- Construct and return a clone setting internal field reference
223         virtual tmp<fvPatchField<Type> > clone
224         (
225             const DimensionedField<Type, volMesh>& iF
226         ) const
227         {
228             return tmp<fvPatchField<Type> >
229             (
230                 new codedFixedValueFvPatchField<Type>(*this, iF)
231             );
232         }
237     // Member functions
239         //- Get reference to the underlying patch
240         const fvPatchField<Type>& redirectPatchField() const;
242         //- Update the coefficients associated with the patch field
243         virtual void updateCoeffs();
245         //- Evaluate the patch field, sets Updated to false
246         virtual void evaluate
247         (
248             const Pstream::commsTypes commsType=Pstream::blocking
249         );
251         //- Write
252         virtual void write(Ostream&) const;
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 } // End namespace Foam
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 #ifdef NoRepository
263 #   include "codedFixedValueFvPatchField.C"
264 #endif
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 #endif
270 // ************************************************************************* //