Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / equationReader / equationOperation / equationOperation.H
blob413d1f8105bac1926ba55fa2f5e68b4e5e45093e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::equationOperation
27 Description
28     Defines a single operation to be performed in sequence while evaluating an
29     equation read from a dictionary.
31 SourceFiles
32     equationOperationI.H
33     equationOperation.C
35 Author
36     David L. F. Gaden
38 \*---------------------------------------------------------------------------*/
40 #ifndef equationOperation_H
41 #define equationOperation_H
43 #include "word.H"
44 #include "label.H"
45 #include "IOstreams.H"
46 #include "dimensionedScalar.H"
47 // #include "Istream.H"
48 // #include "Ostream.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 // Forward declaration of friend functions and operators
57 class equationOperation;
58 class equationReader;
60 // Friend Operators
62 int operator==(const equationOperation&, const equationOperation&);
63 int operator!=(const equationOperation&, const equationOperation&);
65 // Friend IOstream Operators
67 Istream& operator>>(Istream&, equationOperation&);
68 Ostream& operator<<(Ostream&, const equationOperation&);
72 /*---------------------------------------------------------------------------*\
73                         Class equationOperation Declaration
74 \*---------------------------------------------------------------------------*/
76 class equationOperation
79 public:
81         enum sourceTypeEnum
82         {
83             stnone,
84             ststorage,
85             stactiveSource,
86             stequation,
87             stinternalScalar,
88             stdictSource,
89             stscalarSource,
90             stscalarFieldSource,
91             stvectorSource,
92             stvectorFieldSource,
93             sttensorSource,
94             sttensorFieldSource,
95             stdiagTensorSource,
96             stdiagTensorFieldSource,
97             stsymmTensorSource,
98             stsymmTensorFieldSource,
99             stsphericalTensorSource,
100             stsphericalTensorFieldSource
101         };
103         enum operationType
104         {
105             otnone,
106             otretrieve,
107             otstore,
108             otplus,
109             otminus,
110             ottimes,
111             otdivide,
112             otpow,
113             otsign,
114             otpos,
115             otneg,
116             otmag,
117             otlimit,
118             otminMod,
119             otsqrtSumSqr,
120             otsqr,
121             otpow3,
122             otpow4,
123             otpow5,
124             otpow6,
125             otinv,
126             otsqrt,
127             otcbrt,
128             othypot,
129             otexp,
130             otlog,
131             otlog10,
132             otsin,
133             otcos,
134             ottan,
135             otasin,
136             otacos,
137             otatan,
138             otatan2,
139             otsinh,
140             otcosh,
141             ottanh,
142             otasinh,
143             otacosh,
144             otatanh,
145             oterf,
146             oterfc,
147             otlgamma,
148             otj0,
149             otj1,
150             otjn,
151             oty0,
152             oty1,
153             otyn,
154             otmax,
155             otmin,
156             otstabilise
157         };
159 private:
161     // Source to read the data from
162     sourceTypeEnum source_;
164     // Index in the field where the data is located.  Note, the
165     // equationOperation lists created by equationReader make this variable a
166     // 1-indexed (i.e. starts from 1, not zero) in order to use its sign to
167     // store the sign of the variable.  The sourceTypes are zero-indexed, so
168     // equationReader will constantly be adding / subtracting 1 to get these
169     // to match
170     label sourceIndex_;
172     // Component index - for Types with multiple components
173     label componentIndex_;
175     // Rather than store the keywords that have to be searched in a dictionary,
176     // equationReader keeps its own list of keywords, and the dictLookupIndex
177     // is the index in this list.  This is only applicable if the sourceType is
178     // of type sldictSource
179     label dictLookupIndex_;
181     // The operation to be performed (+ - sin exp min, etc...)
182     operationType operation_;
184     // A pointer to the scalarField source data retrieval function
185     mutable const scalarField&
186     (Foam::equationReader::*getSourceScalarFieldFunction_)
187     (
188         const equationReader * eqnReader,
189         const label equationIndex,
190         const label equationOperationIndex,
191         const label maxStoreIndex,
192         const label storageOffset
193     ) const;
195     // A pointer to the scalarField operation to be performed
196     mutable void (Foam::equationReader::*opScalarFieldFunction_)
197     (
198         const equationReader * eqnReader,
199         const label index,
200         const label i,
201         const label storageOffset,
202         label& storageIndex,
203         scalarField& x,
204         const scalarField& source
205     ) const;
207     // A pointer to the scalar source data retrieval function
208     mutable scalar (Foam::equationReader::*getSourceScalarFunction_)
209     (
210         const equationReader * eqnReader,
211         const label equationIndex,
212         const label equationOperationIndex,
213         const label maxStoreIndex,
214         const label storageOffset
215     ) const;
217     // A pointer to the scalar operation to be performed
218     mutable void (Foam::equationReader::*opScalarFunction_)
219     (
220         const equationReader * eqnReader,
221         const label index,
222         const label i,
223         const label storageOffset,
224         label& storageIndex,
225         scalar& x,
226         scalar source
227     ) const;
229     // A pointer to the dimensions source data retrieval function
230     mutable dimensionSet (Foam::equationReader::*getSourceDimsFunction_)
231     (
232         const equationReader * eqnReader,
233         const label equationIndex,
234         const label equationOperationIndex,
235         const label maxStoreIndex,
236         const label storageOffset
237     ) const;
239     // A pointer to the dimension operation to be performed
240     mutable void (Foam::equationReader::*opDimsFunction_)
241     (
242         const equationReader * eqnReader,
243         const label index,
244         const label i,
245         const label storageOffset,
246         label& storageIndex,
247         dimensionSet& xDims,
248         dimensionSet sourceDims
249     ) const;
252 public:
254     // Static data members
256         static const char* const typeName;
258     // Constructors
260         //- Construct null
261         equationOperation();
263         //- Construct copy
264         equationOperation(const equationOperation& eqop);
266         //- Construct from components
267         equationOperation
268         (
269             sourceTypeEnum source,
270             label sourceIndex,
271             label componentIndex,
272             label dictLookupIndex,
273             operationType operation,
274             const scalarField&
275             (Foam::equationReader::*getSourceScalarFieldFunction_)
276             (
277                 const equationReader *,
278                 const label,
279                 const label,
280                 const label,
281                 const label
282             ) const = NULL,
283             void (Foam::equationReader::*opScalarFieldFunction_)
284             (
285                 const equationReader *,
286                 const label,
287                 const label,
288                 const label,
289                 label&,
290                 scalarField&,
291                 const scalarField&
292             ) const = NULL,
293             scalar (Foam::equationReader::*getSourceScalarFunction)
294             (
295                 const equationReader *,
296                 const label,
297                 const label,
298                 const label,
299                 const label
300             ) const = NULL,
301             void (Foam::equationReader::*opScalarFunction)
302             (
303                 const equationReader *,
304                 const label,
305                 const label,
306                 const label,
307                 label&,
308                 scalar&,
309                 scalar
310             ) const = NULL,
311             dimensionSet (Foam::equationReader::*getSourceDimsFunction)
312             (
313                 const equationReader *,
314                 const label,
315                 const label,
316                 const label,
317                 const label
318             ) const = NULL,
319             void (Foam::equationReader::*opDimsFunction)
320             (
321                 const equationReader *,
322                 const label,
323                 const label,
324                 const label,
325                 label&,
326                 dimensionSet&,
327                 dimensionSet
328             ) const = NULL
329         );
332     // Destructor
333     ~equationOperation();
335     // Member functions
337         // Access
339             //- Const access to source
340             inline const sourceTypeEnum& sourceType() const;
342             //- Access to source
343             inline sourceTypeEnum& sourceType();
345             //- Const access to source index
346             inline const label& sourceIndex() const;
348             //- Access to source index
349             inline label& sourceIndex();
351             //- Const access to componentIndex
352             inline const label& componentIndex() const;
354             //- Access to componentIndex
355             inline label& componentIndex();
357             //- Const access to dictionary lookup name index
358             inline const label& dictLookupIndex() const;
360             //- Access to dictionary lookup name index
361             inline label& dictLookupIndex();
363             //- Const access to operation
364             inline const operationType& operation() const;
366             //- Access to operation
367             inline operationType& operation();
369         // Function pointers
371             //- Assign the source scalarField function
372             void assignSourceScalarFieldFunction
373             (
374                 const scalarField&
375                 (Foam::equationReader::*getSourceScalarFieldFunction)
376                 (
377                     const equationReader *,
378                     const label,
379                     const label,
380                     const label,
381                     const label
382                 ) const
383             ) const;
385             //- Assign the operation scalarField function
386             void assignOpScalarFieldFunction
387             (
388                 void (Foam::equationReader::*opScalarFieldFunction)
389                 (
390                     const equationReader *,
391                     const label,
392                     const label,
393                     const label,
394                     label&,
395                     scalarField&,
396                     const scalarField&
397                 ) const
398             ) const;
400             //- Assign the source scalar function
401             void assignSourceScalarFunction
402             (
403                 scalar (Foam::equationReader::*getSourceScalarFunction)
404                 (
405                     const equationReader *,
406                     const label,
407                     const label,
408                     const label,
409                     const label
410                 ) const
411             ) const;
413             //- Assign the operation scalar function
414             void assignOpScalarFunction
415             (
416                 void (Foam::equationReader::*opScalarFunction)
417                 (
418                     const equationReader *,
419                     const label,
420                     const label,
421                     const label,
422                     label&,
423                     scalar&,
424                     scalar
425                 ) const
426             ) const;
428             //- Assign the source dimensions function
429             void assignSourceDimsFunction
430             (
431                 dimensionSet (Foam::equationReader::*getSourceDimsFunction)
432                 (
433                     const equationReader *,
434                     const label,
435                     const label,
436                     const label,
437                     const label
438                 ) const
439             ) const;
441             //- Assign the operation dimensions function
442             void assignOpDimsFunction
443             (
444                 void (Foam::equationReader::*opDimsFunction)
445                 (
446                     const equationReader *,
447                     const label,
448                     const label,
449                     const label,
450                     label&,
451                     dimensionSet&,
452                     dimensionSet
453                 ) const
454             ) const;
456             //- Call the getSourceScalarField function
457             const scalarField& getSourceScalarFieldFunction
458             (
459                 const equationReader * eqnReader,
460                 const label equationIndex,
461                 const label equationOperationIndex,
462                 const label maxStoreIndex,
463                 const label storageOffset
464             ) const;
466             //- Call the operation scalarField function
467             void opScalarFieldFunction
468             (
469                 const equationReader * eqnReader,
470                 const label index,
471                 const label i,
472                 const label storageOffset,
473                 label& storageIndex,
474                 scalarField& x,
475                 const scalarField& source
476             ) const;
478             //- Call the getSourceScalar function
479             scalar getSourceScalarFunction
480             (
481                 const equationReader * eqnReader,
482                 const label equationIndex,
483                 const label equationOperationIndex,
484                 const label maxStoreIndex,
485                 const label storageOffset
486             ) const;
488             //- Call the operation scalar function
489             void opScalarFunction
490             (
491                 const equationReader * eqnReader,
492                 const label index,
493                 const label i,
494                 const label storageOffset,
495                 label& storageIndex,
496                 scalar& x,
497                 scalar source
498             ) const;
500             //- Call the getSourceDims function
501             dimensionSet getSourceDimsFunction
502             (
503                 const equationReader * eqnReader,
504                 const label equationIndex,
505                 const label equationOperationIndex,
506                 const label maxStoreIndex,
507                 const label storageOffset
508             ) const;
510             void opDimsFunction
511             (
512                 const equationReader * eqnReader,
513                 const label index,
514                 const label i,
515                 const label storageOffset,
516                 label& storageIndex,
517                 dimensionSet& xDims,
518                 dimensionSet sourceDims
519             ) const;
521         // Convenience
523             //- Look up operation number, given a word
524             static operationType findOp(const word& opName);
526             //- Look up operation name
527             static word opName(const operationType& op);
529             //- Look up sourceType name
530             static word sourceName(const sourceTypeEnum& st);
532     // Operators
534         void operator=(equationOperation&);
537     // Friend IOstream Operators
539         friend Istream& operator>>(Istream&, equationOperation&);
540         friend Ostream& operator<<(Ostream&, const equationOperation&);
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 } // End namespace Foam
549 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
551 #include "equationOperationI.H"
553 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
555 #endif
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //