diff --git a/applications/test/complex/Test-complex.C b/applications/test/complex/Test-complex.C index bc4d3d05dc..938f63fb8e 100644 --- a/applications/test/complex/Test-complex.C +++ b/applications/test/complex/Test-complex.C @@ -30,6 +30,8 @@ Description #include "argList.H" #include "complexFields.H" +#include "ops.H" +#include "ListOps.H" using namespace Foam; @@ -97,9 +99,6 @@ int main(int argc, char *argv[]) } - Info<< "sum = " << sum(fld1) << nl; - // Not yet Info<< "min = " << min(fld1) << nl; - fld1 *= 10; Info<< "scalar multiply: " << flatOutput(fld1) << nl; @@ -120,6 +119,36 @@ int main(int argc, char *argv[]) // Info<< "pow(2) : " << pow(fld1, 2) << nl; + // Make some changes + { + label i = 1; + for (complex& c : fld1) + { + c.Re() += i; + c.Im() -= 10 - i; + ++i; + } + } + + Info<< nl + << "field = " << fld1 << nl; + + Info<< "magSqr = " + << ListOps::create + ( + fld1, + [](const complex& c) { return magSqr(c); } + ) + << nl; + + Info + << "sum = " << sum(fld1) << nl + << "min = " << min(fld1) << nl + << "max = " << max(fld1) << nl; + + // MinMax fails since there is no less comparison operator + // Info<< "min/max = " << MinMax(fld1) << nl; + Info<< "\nEnd\n" << endl; return 0; } diff --git a/applications/test/minMax1/Test-minMax1.C b/applications/test/minMax1/Test-minMax1.C index 26d242a804..a33b3a3134 100644 --- a/applications/test/minMax1/Test-minMax1.C +++ b/applications/test/minMax1/Test-minMax1.C @@ -32,6 +32,7 @@ Description #include "HashOps.H" #include "ListOps.H" #include "scalarField.H" +#include "complexField.H" #include "MinMax.H" #include "dimensionedScalar.H" @@ -47,6 +48,19 @@ Ostream& printInfo(const MinMax& range) } +template +void testUniformField(const T& val) +{ + constexpr label N = 10; + + // Field fld(N, val); + List fld(N, val); + + Info<< "field: " << fld << nl + << "min/max: " << minMaxMag(fld) << nl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -225,6 +239,15 @@ int main(int argc, char *argv[]) Info<< "filtered: " << hashed << nl; } + + // Min/max of uniform fields + { + testUniformField(100); + // testUniformField(complex(100, 0)); + } + + Info<< "\nEnd\n" << nl; + return 0; } diff --git a/src/OpenFOAM/primitives/complex/complex.C b/src/OpenFOAM/primitives/complex/complex.C index 2afbfe8612..3926ff29d2 100644 --- a/src/OpenFOAM/primitives/complex/complex.C +++ b/src/OpenFOAM/primitives/complex/complex.C @@ -35,6 +35,41 @@ const Foam::complex Foam::complex::zero(0, 0); const Foam::complex Foam::complex::one(1, 0); +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +const char* const Foam::pTraits::typeName = "complex"; +const char* const Foam::pTraits::componentNames[] = {"re", "im"}; + +const Foam::complex Foam::pTraits::zero(0, 0); +const Foam::complex Foam::pTraits::one(1, 0); + +const Foam::complex Foam::pTraits::min(-VGREAT, -VGREAT); +const Foam::complex Foam::pTraits::max(VGREAT, VGREAT); + +const Foam::complex Foam::pTraits::rootMin +( + -ROOTVGREAT, -ROOTVGREAT +); + +const Foam::complex Foam::pTraits::rootMax +( + ROOTVGREAT, ROOTVGREAT +); + + +Foam::pTraits::pTraits(const complex& val) +: + p_(val) +{} + + +Foam::pTraits::pTraits(Istream& is) +{ + is >> p_; +} + + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::complex::complex(Istream& is) diff --git a/src/OpenFOAM/primitives/complex/complex.H b/src/OpenFOAM/primitives/complex/complex.H index aa7dee6c70..c67eafb6cc 100644 --- a/src/OpenFOAM/primitives/complex/complex.H +++ b/src/OpenFOAM/primitives/complex/complex.H @@ -232,6 +232,70 @@ public: }; +// Template specialisation for pTraits +template<> +class pTraits +{ + complex p_; + +public: + + //- Component type + typedef complex cmptType; + + //- Equivalent type of labels used for valid component indexing + typedef label labelType; + + + // Member constants + + //- Dimensionality of space + static constexpr direction dim = 3; + + //- Rank of complex is 0 + static constexpr direction rank = 0; + + //- Number of components in complex is 2 + static constexpr direction nComponents = 2; + + + // Static Data Members + + static const char* const typeName; + static const char* const componentNames[]; + static const complex zero; + static const complex one; + static const complex max; + static const complex min; + static const complex rootMax; + static const complex rootMin; + + + // Constructors + + //- Construct from primitive + explicit pTraits(const complex& val); + + //- Construct from Istream + pTraits(Istream& is); + + + // Member Functions + + //- Access to the value + operator complex() const + { + return p_; + } + + //- Access to the value + operator complex&() + { + return p_; + } +}; + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // Istream& operator>>(Istream& is, complex& c); diff --git a/src/OpenFOAM/primitives/complex/complexI.H b/src/OpenFOAM/primitives/complex/complexI.H index 58e564e5fb..7038d12da3 100644 --- a/src/OpenFOAM/primitives/complex/complexI.H +++ b/src/OpenFOAM/primitives/complex/complexI.H @@ -350,6 +350,7 @@ inline complex operator/(const scalar s, const complex& c) return complex(s/c.re, s/c.im); } + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam