1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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,
66 label dictLookupIndex,
67 operationType operation,
68 const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction)
70 const equationReader *,
76 void (Foam::equationReader::*opScalarFieldFunction)
78 const equationReader *,
86 scalar (Foam::equationReader::*getSourceScalarFunction)
88 const equationReader *,
94 void (Foam::equationReader::*opScalarFunction)
96 const equationReader *,
104 dimensionSet (Foam::equationReader::*getSourceDimsFunction)
106 const equationReader *,
112 void (Foam::equationReader::*opDimsFunction)
114 const equationReader *,
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")
151 else if (opName == "store")
155 else if (opName == "plus")
159 else if (opName == "minus")
163 else if (opName == "times")
167 else if (opName == "divide")
171 else if (opName == "pow")
175 else if (opName == "sign")
179 else if (opName == "pos")
183 else if (opName == "neg")
187 else if (opName == "mag")
191 else if (opName == "limit")
195 else if (opName == "minMod")
199 else if (opName == "sqrtSumSqr")
203 else if (opName == "sqr")
207 else if (opName == "pow3")
211 else if (opName == "pow4")
215 else if (opName == "pow5")
219 else if (opName == "pow6")
223 else if (opName == "inv")
227 else if (opName == "sqrt")
231 else if (opName == "cbrt")
235 else if (opName == "hypot")
239 else if (opName == "exp")
243 else if (opName == "log")
247 else if (opName == "log10")
251 else if (opName == "sin")
255 else if (opName == "cos")
259 else if (opName == "tan")
263 else if (opName == "asin")
267 else if (opName == "acos")
271 else if (opName == "atan")
275 else if (opName == "atan2")
279 else if (opName == "sinh")
283 else if (opName == "cosh")
287 else if (opName == "tanh")
291 else if (opName == "asinh")
295 else if (opName == "acosh")
299 else if (opName == "atanh")
303 else if (opName == "erf")
307 else if (opName == "erfc")
311 else if (opName == "lgamma")
315 else if (opName == "j0")
319 else if (opName == "j1")
323 else if (opName == "jn")
327 else if (opName == "y0")
331 else if (opName == "y1")
335 else if (opName == "yn")
339 else if (opName == "max")
343 else if (opName == "min")
347 else if (opName == "stabilise")
358 Foam::word Foam::equationOperation::opName
360 const Foam::equationOperation::operationType& op
475 Foam::word Foam::equationOperation::sourceName
477 const Foam::equationOperation::sourceTypeEnum& st
487 return "activeEquationVariable";
490 case stinternalScalar:
496 case stscalarFieldSource:
497 return "scalarField";
500 case stvectorFieldSource:
501 return "vectorField";
504 case sttensorFieldSource:
505 return "tensorField";
506 case stdiagTensorSource:
508 case stdiagTensorFieldSource:
509 return "diagTensorField";
510 case stsymmTensorSource:
512 case stsymmTensorFieldSource:
513 return "symmTensorField";
514 case stsphericalTensorSource:
515 return "sphericalTensor";
516 case stsphericalTensorFieldSource:
517 return "sphericalTensorField";
524 void Foam::equationOperation::assignSourceScalarFieldFunction
526 const scalarField& (Foam::equationReader::*getSourceScalarFieldFunction)
528 const equationReader *,
536 getSourceScalarFieldFunction_ = getSourceScalarFieldFunction;
540 void Foam::equationOperation::assignOpScalarFieldFunction
542 void (Foam::equationReader::*opScalarFieldFunction)
544 const equationReader *,
554 opScalarFieldFunction_ = opScalarFieldFunction;
558 void Foam::equationOperation::assignSourceScalarFunction
560 scalar (Foam::equationReader::*getSourceScalarFunction)
562 const equationReader *,
570 getSourceScalarFunction_ = getSourceScalarFunction;
574 void Foam::equationOperation::assignOpScalarFunction
576 void (Foam::equationReader::*opScalarFunction)
578 const equationReader *,
588 opScalarFunction_ = opScalarFunction;
592 void Foam::equationOperation::assignSourceDimsFunction
594 dimensionSet (Foam::equationReader::*getSourceDimsFunction)
596 const equationReader *,
604 getSourceDimsFunction_ = getSourceDimsFunction;
608 void Foam::equationOperation::assignOpDimsFunction
610 void (Foam::equationReader::*opDimsFunction)
612 const equationReader *,
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
635 return (eqnReader->*getSourceScalarFieldFunction_)
639 equationOperationIndex,
646 void Foam::equationOperation::opScalarFieldFunction
648 const equationReader * eqnReader,
651 const label storageOffset,
654 const scalarField& source
657 (eqnReader->*opScalarFieldFunction_)
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
679 return (eqnReader->*getSourceScalarFunction_)
683 equationOperationIndex,
690 void Foam::equationOperation::opScalarFunction
692 const equationReader * eqnReader,
695 const label storageOffset,
701 (eqnReader->*opScalarFunction_)
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
723 return (eqnReader->*getSourceDimsFunction_)
727 equationOperationIndex,
734 void Foam::equationOperation::opDimsFunction
736 const equationReader * eqnReader,
739 const label storageOffset,
742 dimensionSet sourceDims
745 (eqnReader->*opDimsFunction_)
758 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
760 int Foam::operator==(const equationOperation& I1, const equationOperation& I2)
764 I1.sourceType() == I2.sourceType()
765 && I1.sourceIndex() == I2.sourceIndex()
766 && I1.dictLookupIndex() == I2.dictLookupIndex()
767 && I1.operation() == I2.operation()
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)
802 label op(I.operation_);
804 is >> st >> I.sourceIndex_ >> I.dictLookupIndex_ >> op;
809 Foam::Ostream& Foam::operator<<(Ostream& os, const equationOperation& I)
812 label op(I.operation_);
814 return os << nl << "/* sourceType: */\t" << st
816 << equationOperation::sourceName(I.source_)
818 << "/* sourceIndex: */\t" << I.sourceIndex_ << nl
819 << "/* componentIndex:*/\t" << I.componentIndex_ << nl
820 << "/* dictIndex */\t" << I. dictLookupIndex_ << nl
821 << "/* operation: */\t" << op
823 << equationOperation::opName(I.operation_)
827 // ************************************************************************* //