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.C
blob3becdc0f46afa022426b2d45cfb6cee942b9f1b9
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 \*---------------------------------------------------------------------------*/
26 #include "objectRegistry.H"
27 #include "dimensionedScalar.H"
28 #include "equationReader.H"
29 #include "equationOperation.H"
30 //#include "equationOperationList.H"
32 class dimensionedScalar;
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 const char* const Foam::equationOperation::typeName = "equationOperation";
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 Foam::equationOperation::equationOperation()
45 Foam::equationOperation::equationOperation(const equationOperation& eqop)
47     source_(eqop.source_),
48     sourceIndex_(eqop.sourceIndex_),
49     componentIndex_(eqop.componentIndex_),
50     dictLookupIndex_(eqop.dictLookupIndex_),
51     operation_(eqop.operation_),
52     getSourceScalarFieldFunction_(eqop.getSourceScalarFieldFunction_),
53     opScalarFieldFunction_(eqop.opScalarFieldFunction_),
54     getSourceScalarFunction_(eqop.getSourceScalarFunction_),
55     opScalarFunction_(eqop.opScalarFunction_),
56     getSourceDimsFunction_(eqop.getSourceDimsFunction_),
57     opDimsFunction_(eqop.opDimsFunction_)
61 Foam::equationOperation::equationOperation
63     sourceTypeEnum source,
64     label sourceIndex,
65     label componentIndex,
66     label dictLookupIndex,
67     operationType operation,
68     const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction)
69     (
70         const equationReader *,
71         const label,
72         const label,
73         const label,
74         const label
75     ) const,
76     void (Foam::equationReader::*opScalarFieldFunction)
77     (
78         const equationReader *,
79         const label,
80         const label,
81         const label,
82         label&,
83         scalarField&,
84         const scalarField&
85     ) const,
86     scalar (Foam::equationReader::*getSourceScalarFunction)
87     (
88         const equationReader *,
89         const label,
90         const label,
91         const label,
92         const label
93     ) const,
94     void (Foam::equationReader::*opScalarFunction)
95     (
96         const equationReader *,
97         const label,
98         const label,
99         const label,
100         label&,
101         scalar&,
102         scalar
103     ) const,
104     dimensionSet (Foam::equationReader::*getSourceDimsFunction)
105     (
106         const equationReader *,
107         const label,
108         const label,
109         const label,
110         const label
111     ) const,
112     void (Foam::equationReader::*opDimsFunction)
113     (
114         const equationReader *,
115         const label,
116         const label,
117         const label,
118         label&,
119         dimensionSet&,
120         dimensionSet
121     ) const
124     source_(source),
125     sourceIndex_(sourceIndex),
126     componentIndex_(componentIndex),
127     dictLookupIndex_(dictLookupIndex),
128     operation_(operation),
129     getSourceScalarFieldFunction_(getSourceScalarFieldFunction),
130     opScalarFieldFunction_(opScalarFieldFunction),
131     getSourceScalarFunction_(getSourceScalarFunction),
132     opScalarFunction_(opScalarFunction),
133     getSourceDimsFunction_(getSourceDimsFunction),
134     opDimsFunction_(opDimsFunction)
138 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
140 Foam::equationOperation::~equationOperation()
143 // * * * * * * * * * * * * * * Member functions  * * * * * * * * * * * * * * //
144 Foam::equationOperation::operationType
145     Foam::equationOperation::findOp(const Foam::word& opName)
147     if (opName == "retrieve")
148     {
149         return otretrieve;
150     }
151     else if (opName == "store")
152     {
153         return otstore;
154     }
155     else if (opName == "plus")
156     {
157         return otplus;
158     }
159     else if (opName == "minus")
160     {
161         return otminus;
162     }
163     else if (opName == "times")
164     {
165         return ottimes;
166     }
167     else if (opName == "divide")
168     {
169         return otdivide;
170     }
171     else if (opName == "pow")
172     {
173         return otpow;
174     }
175     else if (opName == "sign")
176     {
177         return otsign;
178     }
179     else if (opName == "pos")
180     {
181         return otpos;
182     }
183     else if (opName == "neg")
184     {
185         return otneg;
186     }
187     else if (opName == "mag")
188     {
189         return otmag;
190     }
191     else if (opName == "limit")
192     {
193         return otlimit;
194     }
195     else if (opName == "minMod")
196     {
197         return otminMod;
198     }
199     else if (opName == "sqrtSumSqr")
200     {
201         return otsqrtSumSqr;
202     }
203     else if (opName == "sqr")
204     {
205         return otsqr;
206     }
207     else if (opName == "pow3")
208     {
209         return otpow3;
210     }
211     else if (opName == "pow4")
212     {
213         return otpow4;
214     }
215     else if (opName == "pow5")
216     {
217         return otpow5;
218     }
219     else if (opName == "pow6")
220     {
221         return otpow6;
222     }
223     else if (opName == "inv")
224     {
225         return otinv;
226     }
227     else if (opName == "sqrt")
228     {
229         return otsqrt;
230     }
231     else if (opName == "cbrt")
232     {
233         return otcbrt;
234     }
235     else if (opName == "hypot")
236     {
237         return othypot;
238     }
239     else if (opName == "exp")
240     {
241         return otexp;
242     }
243     else if (opName == "log")
244     {
245         return otlog;
246     }
247     else if (opName == "log10")
248     {
249         return otlog10;
250     }
251     else if (opName == "sin")
252     {
253         return otsin;
254     }
255     else if (opName == "cos")
256     {
257         return otcos;
258     }
259     else if (opName == "tan")
260     {
261         return ottan;
262     }
263     else if (opName == "asin")
264     {
265         return otasin;
266     }
267     else if (opName == "acos")
268     {
269         return otacos;
270     }
271     else if (opName == "atan")
272     {
273         return otatan;
274     }
275     else if (opName == "atan2")
276     {
277         return otatan2;
278     }
279     else if (opName == "sinh")
280     {
281         return otsinh;
282     }
283     else if (opName == "cosh")
284     {
285         return otcosh;
286     }
287     else if (opName == "tanh")
288     {
289         return ottanh;
290     }
291     else if (opName == "asinh")
292     {
293         return otasinh;
294     }
295     else if (opName == "acosh")
296     {
297         return otacosh;
298     }
299     else if (opName == "atanh")
300     {
301         return otatanh;
302     }
303     else if (opName == "erf")
304     {
305         return oterf;
306     }
307     else if (opName == "erfc")
308     {
309         return oterfc;
310     }
311     else if (opName == "lgamma")
312     {
313         return otlgamma;
314     }
315     else if (opName == "j0")
316     {
317         return otj0;
318     }
319     else if (opName == "j1")
320     {
321         return otj1;
322     }
323     else if (opName == "jn")
324     {
325         return otjn;
326     }
327     else if (opName == "y0")
328     {
329         return oty0;
330     }
331     else if (opName == "y1")
332     {
333         return oty1;
334     }
335     else if (opName == "yn")
336     {
337         return otyn;
338     }
339     else if (opName == "max")
340     {
341         return otmax;
342     }
343     else if (opName == "min")
344     {
345         return otmin;
346     }
347     else if (opName == "stabilise")
348     {
349         return otstabilise;
350     }
351     else
352     {
353         return otnone;
354     }
358 Foam::word Foam::equationOperation::opName
360     const Foam::equationOperation::operationType& op
363     switch (op)
364     {
365         case otnone:
366             return "none";
367         case otretrieve:
368             return "retrieve";
369         case otstore:
370             return "store";
371         case otplus:
372             return "plus";
373         case otminus:
374             return "minus";
375         case ottimes:
376             return "times";
377         case otdivide:
378             return "divide";
379         case otpow:
380             return "pow";
381         case otsign:
382             return "sign";
383         case otpos:
384             return "pos";
385         case otneg:
386             return "neg";
387         case otmag:
388             return "mag";
389         case otlimit:
390             return "limit";
391         case otminMod:
392             return "minMod";
393         case otsqrtSumSqr:
394             return "sqrtSumSqr";
395         case otsqr:
396             return "sqr";
397         case otpow3:
398             return "pow3";
399         case otpow4:
400             return "pow4";
401         case otpow5:
402             return "pow5";
403         case otpow6:
404             return "pow6";
405         case otinv:
406             return "inv";
407         case otsqrt:
408             return "sqrt";
409         case otcbrt:
410             return "cbrt";
411         case othypot:
412             return "hypot";
413         case otexp:
414             return "exp";
415         case otlog:
416             return "log";
417         case otlog10:
418             return "log10";
419         case otsin:
420             return "sin";
421         case otcos:
422             return "cos";
423         case ottan:
424             return "tan";
425         case otasin:
426             return "asin";
427         case otacos:
428             return "acos";
429         case otatan:
430             return "atan";
431         case otatan2:
432             return "atan2";
433         case otsinh:
434             return "sinh";
435         case otcosh:
436             return "cosh";
437         case ottanh:
438             return "tanh";
439         case otasinh:
440             return "asinh";
441         case otacosh:
442             return "acosh";
443         case otatanh:
444             return "atanh";
445         case oterf:
446             return "erf";
447         case oterfc:
448             return "erfc";
449         case otlgamma:
450             return "lgamma";
451         case otj0:
452             return "j0";
453         case otj1:
454             return "j1";
455         case otjn:
456             return "jn";
457         case oty0:
458             return "y0";
459         case oty1:
460             return "y1";
461         case otyn:
462             return "yn";
463         case otmax:
464             return "max";
465         case otmin:
466             return "min";
467         case otstabilise:
468             return "stabilise";
469         default:
470             return "unlisted";
471     }
475 Foam::word Foam::equationOperation::sourceName
477     const Foam::equationOperation::sourceTypeEnum& st
480     switch (st)
481     {
482         case stnone:
483             return "none";
484         case ststorage:
485             return "memory";
486         case stactiveSource:
487             return "activeEquationVariable";
488         case stequation:
489             return "equation";
490         case stinternalScalar:
491             return "constant";
492         case stdictSource:
493             return "dictionary";
494         case stscalarSource:
495             return "scalar";
496         case stscalarFieldSource:
497             return "scalarField";
498         case stvectorSource:
499             return "vector";
500         case stvectorFieldSource:
501             return "vectorField";
502         case sttensorSource:
503             return "tensor";
504         case sttensorFieldSource:
505             return "tensorField";
506         case stdiagTensorSource:
507             return "diagTensor";
508         case stdiagTensorFieldSource:
509             return "diagTensorField";
510         case stsymmTensorSource:
511             return "symmTensor";
512         case stsymmTensorFieldSource:
513             return "symmTensorField";
514         case stsphericalTensorSource:
515             return "sphericalTensor";
516         case stsphericalTensorFieldSource:
517             return "sphericalTensorField";
518         default:
519             return "unlisted";
520     }
524 void Foam::equationOperation::assignSourceScalarFieldFunction
526     const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction)
527     (
528         const equationReader *,
529         const label,
530         const label,
531         const label,
532         const label
533     ) const
534 ) const
536     getSourceScalarFieldFunction_ = getSourceScalarFieldFunction;
540 void Foam::equationOperation::assignOpScalarFieldFunction
542     void (Foam::equationReader::*opScalarFieldFunction)
543     (
544         const equationReader *,
545         const label,
546         const label,
547         const label,
548         label&,
549         scalarField&,
550         const scalarField&
551     ) const
552 ) const
554     opScalarFieldFunction_ = opScalarFieldFunction;
558 void Foam::equationOperation::assignSourceScalarFunction
560     scalar (Foam::equationReader::*getSourceScalarFunction)
561     (
562         const equationReader *,
563         const label,
564         const label,
565         const label,
566         const label
567     ) const
568 ) const
570     getSourceScalarFunction_ = getSourceScalarFunction;
574 void Foam::equationOperation::assignOpScalarFunction
576     void (Foam::equationReader::*opScalarFunction)
577     (
578         const equationReader *,
579         const label,
580         const label,
581         const label,
582         label&,
583         scalar&,
584         scalar
585     ) const
586 ) const
588     opScalarFunction_ = opScalarFunction;
592 void Foam::equationOperation::assignSourceDimsFunction
594     dimensionSet (Foam::equationReader::*getSourceDimsFunction)
595     (
596         const equationReader *,
597         const label,
598         const label,
599         const label,
600         const label
601     ) const
602 ) const
604     getSourceDimsFunction_ = getSourceDimsFunction;
608 void Foam::equationOperation::assignOpDimsFunction
610     void (Foam::equationReader::*opDimsFunction)
611     (
612         const equationReader *,
613         const label,
614         const label,
615         const label,
616         label&,
617         dimensionSet&,
618         dimensionSet
619     ) const
620 ) const
622     opDimsFunction_ = opDimsFunction;
626 const Foam::scalarField& Foam::equationOperation::getSourceScalarFieldFunction
628     const equationReader * eqnReader,
629     const label equationIndex,
630     const label equationOperationIndex,
631     const label maxStoreIndex,
632     const label storageOffset
633 ) const
635     return (eqnReader->*getSourceScalarFieldFunction_)
636     (
637         eqnReader,
638         equationIndex,
639         equationOperationIndex,
640         maxStoreIndex,
641         storageOffset
642     );
646 void Foam::equationOperation::opScalarFieldFunction
648     const equationReader * eqnReader,
649     const label index,
650     const label i,
651     const label storageOffset,
652     label& storageIndex,
653     scalarField& x,
654     const scalarField& source
655 ) const
657     (eqnReader->*opScalarFieldFunction_)
658     (
659         eqnReader,
660         index,
661         i,
662         storageOffset,
663         storageIndex,
664         x,
665         source
666     );
670 Foam::scalar Foam::equationOperation::getSourceScalarFunction
672     const equationReader * eqnReader,
673     const label equationIndex,
674     const label equationOperationIndex,
675     const label maxStoreIndex,
676     const label storageOffset
677 ) const
679     return (eqnReader->*getSourceScalarFunction_)
680     (
681         eqnReader,
682         equationIndex,
683         equationOperationIndex,
684         maxStoreIndex,
685         storageOffset
686     );
690 void Foam::equationOperation::opScalarFunction
692     const equationReader * eqnReader,
693     const label index,
694     const label i,
695     const label storageOffset,
696     label& storageIndex,
697     scalar& x,
698     scalar source
699 ) const
701     (eqnReader->*opScalarFunction_)
702     (
703         eqnReader,
704         index,
705         i,
706         storageOffset,
707         storageIndex,
708         x,
709         source
710     );
714 Foam::dimensionSet Foam::equationOperation::getSourceDimsFunction
716     const equationReader * eqnReader,
717     const label equationIndex,
718     const label equationOperationIndex,
719     const label maxStoreIndex,
720     const label storageOffset
721 ) const
723     return (eqnReader->*getSourceDimsFunction_)
724     (
725         eqnReader,
726         equationIndex,
727         equationOperationIndex,
728         maxStoreIndex,
729         storageOffset
730     );
734 void Foam::equationOperation::opDimsFunction
736     const equationReader * eqnReader,
737     const label index,
738     const label i,
739     const label storageOffset,
740     label& storageIndex,
741     dimensionSet& xDims,
742     dimensionSet sourceDims
743 ) const
745     (eqnReader->*opDimsFunction_)
746     (
747         eqnReader,
748         index,
749         i,
750         storageOffset,
751         storageIndex,
752         xDims,
753         sourceDims
754     );
758 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
760 int Foam::operator==(const equationOperation& I1, const equationOperation& I2)
762     return
763     (
764         I1.sourceType() == I2.sourceType()
765      && I1.sourceIndex() == I2.sourceIndex()
766      && I1.dictLookupIndex() == I2.dictLookupIndex()
767      && I1.operation() == I2.operation()
768     );
772 int Foam::operator!=(const equationOperation& I1, const equationOperation& I2)
774     // Invert the '==' operator ('0'='false')
775     return I1 == I2 ? 0 : 1;
779 // * * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * //
781 void Foam::equationOperation::operator=(Foam::equationOperation& eqn)
783     source_ = eqn.source_;
784     sourceIndex_ = eqn.sourceIndex_;
785     componentIndex_ = eqn.componentIndex_;
786     dictLookupIndex_ = eqn.dictLookupIndex_;
787     operation_ = eqn.operation_;
788     getSourceScalarFieldFunction_ = eqn.getSourceScalarFieldFunction_;
789     opScalarFieldFunction_ = eqn.opScalarFieldFunction_;
790     getSourceScalarFunction_ = eqn.getSourceScalarFunction_;
791     opScalarFunction_ = eqn.opScalarFunction_;
792     getSourceDimsFunction_ = eqn.getSourceDimsFunction_;
793     opDimsFunction_ = eqn.opDimsFunction_;
797 // * * * * * * * * * * * * * Friend IOstream Operators * * * * * * * * * * * //
799 Foam::Istream& Foam::operator>>(Istream& is, equationOperation& I)
801     label st(I.source_);
802     label op(I.operation_);
804     is >> st >> I.sourceIndex_ >> I.dictLookupIndex_ >> op;
805     return is;
809 Foam::Ostream& Foam::operator<<(Ostream& os, const equationOperation& I)
811     label st(I.source_);
812     label op(I.operation_);
814     return os   << nl << "/* sourceType:    */\t" << st
815                     << " /* "
816                     << equationOperation::sourceName(I.source_)
817                     << " */" << nl
818                 << "/* sourceIndex:   */\t" << I.sourceIndex_ << nl
819                 << "/* componentIndex:*/\t" << I.componentIndex_ << nl
820                 << "/* dictIndex      */\t" << I. dictLookupIndex_ << nl
821                 << "/* operation:     */\t" << op
822                     << " /* "
823                     << equationOperation::opName(I.operation_)
824                     << " */" << nl;
827 // ************************************************************************* //