diff --git a/src/fileFormats/coordSet/coordSet.C b/src/fileFormats/coordSet/coordSet.C index bb311a62ed..56a398131c 100644 --- a/src/fileFormats/coordSet/coordSet.C +++ b/src/fileFormats/coordSet/coordSet.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,6 +41,21 @@ Foam::coordSet::coordFormatNames_ }; +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::coordSet::checkDimensions() const +{ + if (size() != curveDist_.size()) + { + FatalErrorInFunction + << "Size of points and curve distance must be the same" << nl + << " points size : " << size() + << " curve size : " << curveDist_.size() + << abort(FatalError); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::coordSet::coordSet @@ -68,49 +83,61 @@ Foam::coordSet::coordSet name_(name), axis_(coordFormatNames_[axis]), curveDist_(curveDist) -{} +{ + checkDimensions(); +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::coordSet::hasVectorAxis() const { - return axis_ == XYZ; + return axis_ == coordFormat::XYZ; } -Foam::scalar Foam::coordSet::scalarCoord -( - const label index -) const +Foam::scalar Foam::coordSet::scalarCoord(const label index) const { const point& p = operator[](index); - if (axis_ == X) + switch (axis_) { - return p.x(); - } - else if (axis_ == Y) - { - return p.y(); - } - else if (axis_ == Z) - { - return p.z(); - } - else if (axis_ == DISTANCE) - { - // Use distance to reference point - return curveDist_[index]; - } - else - { - FatalErrorInFunction - << "Illegal axis specification " << axis_ - << " for sampling line " << name_ - << exit(FatalError); + case coordFormat::X: + { + return p.x(); + } + case coordFormat::Y: + { + return p.y(); + } + case coordFormat::Z: + { + return p.z(); + } + case coordFormat::DISTANCE: + { + // Note: If this has been constructed from the 'name' and 'axis' + // constructor the curveDist list will not have been set - return 0; + if (curveDist_.empty()) + { + FatalErrorInFunction + << "Axis type '" << coordFormatNames_[axis_] + << "' requested but curve distance has not been set" + << abort(FatalError); + } + + return curveDist_[index]; + } + default: + { + FatalErrorInFunction + << "Illegal axis specification '" << coordFormatNames_[axis_] + << "' for sampling line " << name_ + << exit(FatalError); + + return 0; + } } } @@ -125,14 +152,14 @@ Foam::point Foam::coordSet::vectorCoord(const label index) const Foam::Ostream& Foam::coordSet::write(Ostream& os) const { - os << "name:" << name_ << " axis:" << axis_ - << endl - << endl << "\t(coord)" + os << "name:" << name_ << " axis:" << coordFormatNames_[axis_] + << nl + << nl << "\t(coord)" << endl; - forAll(*this, sampleI) + for (const point& pt : *this) { - os << '\t' << operator[](sampleI) << endl; + os << '\t' << pt << endl; } return os; diff --git a/src/fileFormats/coordSet/coordSet.H b/src/fileFormats/coordSet/coordSet.H index bf764cc143..179e4f2adc 100644 --- a/src/fileFormats/coordSet/coordSet.H +++ b/src/fileFormats/coordSet/coordSet.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,7 +45,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class coordSet Declaration + Class coordSet Declaration \*---------------------------------------------------------------------------*/ class coordSet @@ -58,7 +58,7 @@ public: // Public data types //- Enumeration defining the output format for coordinates - enum coordFormat + enum class coordFormat { XYZ, X, @@ -73,6 +73,9 @@ private: //- String representation of coordFormat enums static const Enum coordFormatNames_; + //- Check for consistent dimensions of points and curve distance + void checkDimensions() const; + protected: @@ -91,11 +94,8 @@ public: // Constructors //- Construct from components - coordSet - ( - const word& name, - const word& axis - ); + // Note: curveDist will be empty + coordSet(const word& name, const word& axis); //- Construct from components @@ -126,6 +126,13 @@ public: return curveDist_; } + //- Set cumulative distance + void setCurveDist(const scalarList& curveDist) + { + curveDist_ = curveDist; + checkDimensions(); + } + //- Is axis specification a vector bool hasVectorAxis() const; @@ -136,6 +143,7 @@ public: //- Get point according to axis="xyz" specification vector vectorCoord(const label index) const; + //- Write to stream Ostream& write(Ostream& os) const; };