diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.C b/src/OpenFOAM/dimensionSet/dimensionSet.C index eb13cdf60b..1c7275b166 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSet.C +++ b/src/OpenFOAM/dimensionSet/dimensionSet.C @@ -430,6 +430,20 @@ Foam::dimensionSet Foam::trans(const dimensionSet& ds) } +Foam::dimensionSet Foam::atan2(const dimensionSet& ds1, const dimensionSet& ds2) +{ + if (dimensionSet::debug && ds1 != ds2) + { + FatalErrorIn("atan2(const dimensionSet&, const dimensionSet&)") + << "Arguments of atan2 have different dimensions" << endl + << " dimensions : " << ds1 << " and " << ds2 << endl + << abort(FatalError); + } + + return dimless; +} + + Foam::dimensionSet Foam::transform(const dimensionSet& ds) { return ds; diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.H b/src/OpenFOAM/dimensionSet/dimensionSet.H index 7a6faf95c4..1b03e9e27d 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSet.H +++ b/src/OpenFOAM/dimensionSet/dimensionSet.H @@ -354,6 +354,8 @@ public: // for transcendental functions friend dimensionSet trans(const dimensionSet&); + friend dimensionSet atan2(const dimensionSet&, const dimensionSet&); + //- Return the argument; transformations do not change the dimensions friend dimensionSet transform(const dimensionSet&); diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C index b5aea0e571..895dee69e1 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C @@ -277,6 +277,21 @@ transFunc(yn) #undef transFunc +dimensionedScalar atan2 +( + const dimensionedScalar& x, + const dimensionedScalar& y +) +{ + return dimensionedScalar + ( + "atan2(" + x.name() + ',' + y.name() + ')', + atan2(x.dimensions(), y.dimensions()), + ::atan2(x.value(), y.value()) + ); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H index bf57a98eb9..97522bab8c 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H @@ -79,6 +79,7 @@ dimensionedScalar tan(const dimensionedScalar&); dimensionedScalar asin(const dimensionedScalar&); dimensionedScalar acos(const dimensionedScalar&); dimensionedScalar atan(const dimensionedScalar&); +dimensionedScalar atan2(const dimensionedScalar&, const dimensionedScalar&); dimensionedScalar sinh(const dimensionedScalar&); dimensionedScalar cosh(const dimensionedScalar&); dimensionedScalar tanh(const dimensionedScalar&); diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C index a4296ff91b..eedd2ac9bd 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C @@ -369,6 +369,263 @@ tmp > pow return pow(dimensionedScalar(s), tdsf); } + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +tmp > atan2 +( + const DimensionedField& dsf1, + const DimensionedField& dsf2 +) +{ + tmp > tAtan2 + ( + new DimensionedField + ( + IOobject + ( + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + dsf1.instance(), + dsf1.db() + ), + dsf1.mesh(), + atan2(dsf1.dimensions(), dsf2.dimensions()) + ) + ); + + atan2(tAtan2().field(), dsf1.field(), dsf2.field()); + + return tAtan2; +} + + +template +tmp > atan2 +( + const tmp >& tdsf1, + const DimensionedField& dsf2 +) +{ + const DimensionedField& dsf1 = tdsf1(); + + tmp > tAtan2 = + reuseTmpDimensionedField::New + ( + tdsf1, + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + atan2(dsf1.dimensions(), dsf2.dimensions()) + ); + + atan2(tAtan2().field(), dsf1.field(), dsf2.field()); + + reuseTmpDimensionedField::clear(tdsf1); + + return tAtan2; +} + + +template +tmp > atan2 +( + const DimensionedField& dsf1, + const tmp >& tdsf2 +) +{ + const DimensionedField& dsf2 = tdsf2(); + + tmp > tAtan2 = + reuseTmpDimensionedField::New + ( + tdsf2, + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + atan2(dsf1.dimensions(), dsf2.dimensions()) + ); + + atan2(tAtan2().field(), dsf1.field(), dsf2.field()); + + reuseTmpDimensionedField::clear(tdsf2); + + return tAtan2; +} + +template +tmp > atan2 +( + const tmp >& tdsf1, + const tmp >& tdsf2 +) +{ + const DimensionedField& dsf1 = tdsf1(); + const DimensionedField& dsf2 = tdsf2(); + + tmp > tAtan2 = + reuseTmpTmpDimensionedField:: + New + ( + tdsf1, + tdsf2, + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + atan2(dsf1.dimensions(), dsf2.dimensions()) + ); + + atan2(tAtan2().field(), dsf1.field(), dsf2.field()); + + reuseTmpTmpDimensionedField::clear + ( + tdsf1, + tdsf2 + ); + + return tAtan2; +} + + +template +tmp > atan2 +( + const DimensionedField& dsf, + const dimensionedScalar& ds +) +{ + tmp > tAtan2 + ( + new DimensionedField + ( + IOobject + ( + "atan2(" + dsf.name() + ',' + ds.name() + ')', + dsf.instance(), + dsf.db() + ), + dsf.mesh(), + atan2(dsf.dimensions(), ds) + ) + ); + + atan2(tAtan2().field(), dsf.field(), ds.value()); + + return tAtan2; +} + +template +tmp > atan2 +( + const tmp >& tdsf, + const dimensionedScalar& ds +) +{ + const DimensionedField& dsf = tdsf(); + + tmp > tAtan2 = + reuseTmpDimensionedField::New + ( + tdsf, + "atan2(" + dsf.name() + ',' + ds.name() + ')', + atan2(dsf.dimensions(), ds) + ); + + atan2(tAtan2().field(), dsf.field(), ds.value()); + + reuseTmpDimensionedField::clear(tdsf); + + return tAtan2; +} + +template +tmp > atan2 +( + const DimensionedField& dsf, + const scalar& s +) +{ + return atan2(dsf, dimensionedScalar(s)); +} + +template +tmp > atan2 +( + const tmp >& tdsf, + const scalar& s +) +{ + return atan2(tdsf, dimensionedScalar(s)); +} + + +template +tmp > atan2 +( + const dimensionedScalar& ds, + const DimensionedField& dsf +) +{ + tmp > tAtan2 + ( + new DimensionedField + ( + IOobject + ( + "atan2(" + ds.name() + ',' + dsf.name() + ')', + dsf.instance(), + dsf.db() + ), + dsf.mesh(), + atan2(ds, dsf.dimensions()) + ) + ); + + atan2(tAtan2().field(), ds.value(), dsf.field()); + + return tAtan2; +} + + +template +tmp > atan2 +( + const dimensionedScalar& ds, + const tmp >& tdsf +) +{ + const DimensionedField& dsf = tdsf(); + + tmp > tAtan2 = + reuseTmpDimensionedField::New + ( + tdsf, + "atan2(" + ds.name() + ',' + dsf.name() + ')', + atan2(ds, dsf.dimensions()) + ); + + atan2(tAtan2().field(), ds.value(), dsf.field()); + + reuseTmpDimensionedField::clear(tdsf); + + return tAtan2; +} + +template +tmp > atan2 +( + const scalar& s, + const DimensionedField& dsf +) +{ + return atan2(dimensionedScalar(s), dsf); +} + +template +tmp > atan2 +( + const scalar& s, + const tmp >& tdsf +) +{ + return atan2(dimensionedScalar(s), tdsf); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // UNARY_FUNCTION(scalar, scalar, pow3, pow3) diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.H index b6e76631e0..1503c2567b 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.H @@ -76,6 +76,9 @@ BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide) BINARY_FUNCTION(scalar, scalar, scalar, pow) BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow) +BINARY_FUNCTION(scalar, scalar, scalar, atan2) +BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C index ce78313efb..4c7ee46b89 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C @@ -115,6 +115,7 @@ BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide) BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template class PatchField, class GeoMesh> @@ -440,6 +441,315 @@ tmp > pow } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template class PatchField, class GeoMesh> +void atan2 +( + GeometricField& Atan2, + const GeometricField& gsf1, + const GeometricField& gsf2 +) +{ + atan2(Atan2.internalField(), gsf1.internalField(), gsf2.internalField()); + atan2(Atan2.boundaryField(), gsf1.boundaryField(), gsf2.boundaryField()); +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const GeometricField& gsf1, + const GeometricField& gsf2 +) +{ + tmp > tAtan2 + ( + new GeometricField + ( + IOobject + ( + "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', + gsf1.instance(), + gsf1.db(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + gsf1.mesh(), + atan2(gsf1.dimensions(), gsf2.dimensions()) + ) + ); + + atan2(tAtan2(), gsf1, gsf2); + + return tAtan2; +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const tmp >& tgsf1, + const GeometricField& gsf2 +) +{ + const GeometricField& gsf1 = tgsf1(); + + tmp > tAtan2 + ( + reuseTmpGeometricField::New + ( + tgsf1, + "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', + atan2(gsf1.dimensions(), gsf2.dimensions()) + ) + ); + + atan2(tAtan2(), gsf1, gsf2); + + reuseTmpGeometricField::clear(tgsf1); + + return tAtan2; +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const GeometricField& gsf1, + const tmp >& tgsf2 +) +{ + const GeometricField& gsf2 = tgsf2(); + + tmp > tAtan2 + ( + reuseTmpGeometricField::New + ( + tgsf2, + "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', + atan2( gsf1.dimensions(), gsf2.dimensions()) + ) + ); + + atan2(tAtan2(), gsf1, gsf2); + + reuseTmpGeometricField::clear(tgsf2); + + return tAtan2; +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const tmp >& tgsf1, + const tmp >& tgsf2 +) +{ + const GeometricField& gsf1 = tgsf1(); + const GeometricField& gsf2 = tgsf2(); + + tmp > tAtan2 + ( + reuseTmpTmpGeometricField + ::New + ( + tgsf1, + tgsf2, + "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', + atan2(gsf1.dimensions(), gsf2.dimensions()) + ) + ); + + atan2(tAtan2(), gsf1, gsf2); + + reuseTmpTmpGeometricField + + ::clear(tgsf1, tgsf2); + + return tAtan2; +} + + +template class PatchField, class GeoMesh> +void atan2 +( + GeometricField& tAtan2, + const GeometricField& gsf, + const dimensioned& ds +) +{ + atan2(tAtan2.internalField(), gsf.internalField(), ds.value()); + atan2(tAtan2.boundaryField(), gsf.boundaryField(), ds.value()); +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const GeometricField& gsf, + const dimensionedScalar& ds +) +{ + tmp > tAtan2 + ( + new GeometricField + ( + IOobject + ( + "atan2(" + gsf.name() + ',' + ds.name() + ')', + gsf.instance(), + gsf.db(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + gsf.mesh(), + atan2(gsf.dimensions(), ds) + ) + ); + + atan2(tAtan2(), gsf, ds); + + return tAtan2; +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const tmp >& tgsf, + const dimensionedScalar& ds +) +{ + const GeometricField& gsf = tgsf(); + + tmp > tAtan2 + ( + reuseTmpGeometricField::New + ( + tgsf, + "atan2(" + gsf.name() + ',' + ds.name() + ')', + atan2(gsf.dimensions(), ds) + ) + ); + + atan2(tAtan2(), gsf, ds); + + reuseTmpGeometricField::clear(tgsf); + + return tAtan2; +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const GeometricField& gsf, + const scalar& s +) +{ + return atan2(gsf, dimensionedScalar(s)); +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const tmp >& tgsf, + const scalar& s +) +{ + return atan2(tgsf, dimensionedScalar(s)); +} + + +template class PatchField, class GeoMesh> +void atan2 +( + GeometricField& tAtan2, + const dimensioned& ds, + const GeometricField& gsf +) +{ + atan2(tAtan2.internalField(), ds.value(), gsf.internalField()); + atan2(tAtan2.boundaryField(), ds.value(), gsf.boundaryField()); +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const dimensionedScalar& ds, + const GeometricField& gsf +) +{ + tmp > tAtan2 + ( + new GeometricField + ( + IOobject + ( + "atan2(" + ds.name() + ',' + gsf.name() + ')', + gsf.instance(), + gsf.db(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + gsf.mesh(), + atan2(ds, gsf.dimensions()) + ) + ); + + atan2(tAtan2(), ds, gsf); + + return tAtan2; +} + + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const dimensionedScalar& ds, + const tmp >& tgsf +) +{ + const GeometricField& gsf = tgsf(); + + tmp > tAtan2 + ( + reuseTmpGeometricField::New + ( + tgsf, + "atan2(" + ds.name() + ',' + gsf.name() + ')', + atan2(ds, gsf.dimensions()) + ) + ); + + atan2(tAtan2(), ds, gsf); + + reuseTmpGeometricField::clear(tgsf); + + return tAtan2; +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const scalar& s, + const GeometricField& gsf +) +{ + return atan2(dimensionedScalar(s), gsf); +} + +template class PatchField, class GeoMesh> +tmp > atan2 +( + const scalar& s, + const tmp >& tgsf +) +{ + return atan2(dimensionedScalar(s), tgsf); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // UNARY_FUNCTION(scalar, scalar, pow3, pow3) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.H b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.H index fd20e171c9..9c41fb1fec 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.H @@ -84,6 +84,9 @@ BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide) BINARY_FUNCTION(scalar, scalar, scalar, pow) BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow) +BINARY_FUNCTION(scalar, scalar, scalar, atan2) +BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2) + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //