diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 65073700ab..fc8fab5178 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.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. @@ -42,7 +42,11 @@ See also #include "vector.H" #include "ListOps.H" -#include +#include "labelRange.H" +#include "ListOps.H" +#include "SubList.H" + +#include using namespace Foam; @@ -61,6 +65,19 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + if (false) + { + labelList intlist(IStringStream("(0 1 2)")()); + Info<<"construct from Istream: " << intlist << endl; + + IStringStream("(3 4 5)")() >> static_cast(intlist); + Info<<"is >>: " << intlist << endl; + + IStringStream("(6 7 8)")() >> intlist; + Info<<"is >>: " << intlist << endl; + } + + List list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; diff --git a/applications/test/labelRanges/Test-labelRanges.C b/applications/test/labelRanges/Test-labelRanges.C index 9f2be334d1..dec03a06f0 100644 --- a/applications/test/labelRanges/Test-labelRanges.C +++ b/applications/test/labelRanges/Test-labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) } + labelRange range; labelRanges ranges; bool removeMode = false; @@ -74,14 +75,16 @@ int main(int argc, char *argv[]) continue; } - label start = 0; - label size = 0; + { + label start = 0; + label size = 0; - IStringStream(args[argI])() >> start; - ++argI; - IStringStream(args[argI])() >> size; + IStringStream(args[argI])() >> start; + ++argI; + IStringStream(args[argI])() >> size; - labelRange range(start, size); + range.reset(start, size); + } Info<< "---------------" << nl; if (removeMode) @@ -107,10 +110,11 @@ int main(int argc, char *argv[]) ranges.add(range); } - Info<< "" << ranges << "" << nl; - forAllConstIter(labelRanges, ranges, iter) + Info<< "" << ranges << "" << nl + << "content:"; + for (auto i : ranges) { - Info<< " " << iter(); + Info<< " " << i; } Info<< nl; } diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index bbc55ec10d..6229cb9490 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -64,7 +64,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read L.setSize(s); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 52177d79bc..320b22f68f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -183,7 +183,7 @@ bool Foam::UList::operator<(const UList& a) const ( const_iterator vi = begin(), ai = a.begin(); vi < end() && ai < a.end(); - vi++, ai++ + ++vi, ++ai ) { if (*vi < *ai) diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 719df10a0f..a31416cc73 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -427,7 +427,7 @@ inline void reverse(UList&); // \endcode // \sa forAllReverse #define forAll(list, i) \ - for (Foam::label i=0; i<(list).size(); i++) + for (Foam::label i=0; i<(list).size(); ++i) //- Reverse loop across all elements in \a list // \par Usage @@ -439,7 +439,7 @@ inline void reverse(UList&); // \endcode // \sa forAll #define forAllReverse(list, i) \ - for (Foam::label i=(list).size()-1; i>=0; i--) + for (Foam::label i=(list).size()-1; i>=0; --i) //- Iterate across all elements in the \a container object of type // \a Container. @@ -472,8 +472,8 @@ inline void reverse(UList&); #define forAllConstIter(Container,container,iter) \ for \ ( \ - Container::const_iterator iter = (container).begin(); \ - iter != (container).end(); \ + Container::const_iterator iter = (container).cbegin(); \ + iter != (container).cend(); \ ++iter \ ) diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 0e4825c79c..bd9fe339eb 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,7 +33,7 @@ template inline Foam::UList::UList() : size_(0), - v_(0) + v_(nullptr) {} @@ -321,7 +321,7 @@ inline bool Foam::UList::empty() const template inline void Foam::reverse(UList& ul, const label n) { - for (int i=0; i>(Istream& is, UList& L) ) ); // Check list length - label s = elems.size(); + const label s = elems.size(); if (s != L.size()) { @@ -174,14 +174,14 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) << " expected " << L.size() << exit(FatalIOError); } - for (label i=0; i>(Istream& is, UList& L) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i> L[i]; @@ -226,7 +226,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) "reading the single entry" ); - for (label i=0; i>(Istream& is, UList& L) ( typename SLList::const_iterator iter = sll.begin(); iter != sll.end(); - ++iter + ++iter, ++i ) { L[i] = iter(); diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C index f1123f7519..5e055c1ca1 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,27 +43,35 @@ static const unsigned char base64Chars[64] = //! \endcond +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +std::size_t Foam::base64Layer::encodedLength(std::size_t n) +{ + return 4 * ((n / 3) + (n % 3 ? 1 : 0)); +} + + // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -inline unsigned char Foam::base64Layer::encode0() +inline unsigned char Foam::base64Layer::encode0() const { // Top 6 bits of char0 return base64Chars[((group_[0] & 0xFC) >> 2)]; } -inline unsigned char Foam::base64Layer::encode1() +inline unsigned char Foam::base64Layer::encode1() const { // Bottom 2 bits of char0, Top 4 bits of char1 return base64Chars[((group_[0] & 0x03) << 4) | ((group_[1] & 0xF0) >> 4)]; } -inline unsigned char Foam::base64Layer::encode2() +inline unsigned char Foam::base64Layer::encode2() const { // Bottom 4 bits of char1, Top 2 bits of char2 return base64Chars[((group_[1] & 0x0F) << 2) | ((group_[2] & 0xC0) >> 6)]; } -inline unsigned char Foam::base64Layer::encode3() +inline unsigned char Foam::base64Layer::encode3() const { // Bottom 6 bits of char2 return base64Chars[(group_[2] & 0x3F)]; diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H index 9aa4bc8d79..4eaaf87e83 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,7 +30,7 @@ Description Base64 encoding accoding to RFC 4648 specification (https://tools.ietf.org/html/rfc4648#page-5). It is the obligation of the caller to avoid using normal output - while the base-64 encoding layer is actively being used. + while the base-64 encoding layer is actively used. SourceFiles base64Layer.C @@ -70,10 +70,10 @@ class base64Layer // Private Member Functions - inline unsigned char encode0(); - inline unsigned char encode1(); - inline unsigned char encode2(); - inline unsigned char encode3(); + inline unsigned char encode0() const; + inline unsigned char encode1() const; + inline unsigned char encode2() const; + inline unsigned char encode3() const; //- Disallow default bitwise copy construct base64Layer(const base64Layer&) = delete; @@ -95,7 +95,7 @@ public: // Constructors //- Construct and attach to an output stream - base64Layer(std::ostream&); + base64Layer(std::ostream& os); //- Destructor @@ -104,6 +104,10 @@ public: // Member Functions + //- The encoded length has 4 bytes out for every 3 bytes in. + static std::size_t encodedLength(std::size_t n); + + //- Encode the character sequence, writing when possible. void write(const char* s, std::streamsize n); @@ -111,7 +115,7 @@ public: void reset(); //- End the encoding sequence, padding the final characters with '='. - // Return false if no encoding layer was actually used. + // Return false if no encoding was actually performed. bool close(); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C index 11aacf25cb..2bf9810f6c 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,8 +29,6 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::labelRange::const_iterator Foam::labelRange::endIter_; - int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0)); @@ -47,13 +45,24 @@ Foam::labelRange::labelRange(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::labelRange::intersects -( - const labelRange& range, - const bool touches -) const +void Foam::labelRange::adjust() { - label final = touches ? 1 : 0; + if (start_ < 0) + { + size_ += start_; + start_ = 0; + } + + if (size_ < 0) + { + size_ = 0; + } +} + + +bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const +{ + const label final = touches ? 1 : 0; return ( @@ -97,7 +106,7 @@ Foam::labelRange Foam::labelRange::join(const labelRange& range) const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) +void Foam::labelRange::operator+=(const labelRange& rhs) { if (!size_) { @@ -112,8 +121,6 @@ Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) start_ = lower; size_ = upper - lower + 1; } - - return *this; } @@ -127,10 +134,10 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) is.check("operator>>(Istream&, labelRange&)"); - // disallow invalid sizes - if (range.size_ <= 0) + // Disallow invalid sizes + if (range.size_ < 0) { - range.clear(); + range.size_ = 0; } return is; @@ -139,15 +146,11 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) Foam::Ostream& Foam::operator<<(Ostream& os, const labelRange& range) { - // write ASCII only for now + // Write ASCII only for now os << token::BEGIN_LIST << range.start_ << token::SPACE << range.size_ << token::END_LIST; -// os << token::BEGIN_BLOCK -// << range.start_ << "-" << range.last() -// << token::END_BLOCK; - os.check("operator<<(Ostream&, const labelRange&)"); return os; } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H index 24dd33729c..3fa69c4ff3 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::labelRange Description - A label range specifier. + A range of labels. SourceFiles labelRange.C @@ -47,8 +47,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRange; -Istream& operator>>(Istream&, labelRange&); -Ostream& operator<<(Ostream&, const labelRange&); +Istream& operator>>(Istream& is, labelRange& range); +Ostream& operator<<(Ostream& os, const labelRange& range); /*---------------------------------------------------------------------------*\ Class labelRange Declaration @@ -63,7 +63,7 @@ class labelRange public: - static int debug; + static int debug; // Public classes @@ -75,31 +75,50 @@ public: bool operator()(const labelRange& a, const labelRange& b) { - return a.first() < b.first(); + return a.operator<(b); } }; + // Constructors - //- Construct an empty range + //- Construct an empty range with zero as start and size. inline labelRange(); - //- Construct a range - // A negative size is autmatically changed to zero. - inline labelRange(const label start, const label size); + //- Construct a range from start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + inline labelRange + ( + const label start, + const label size, + const bool adjustStart = false + ); //- Construct from Istream. - labelRange(Istream&); + labelRange(Istream& is); // Member Functions - //- Reset to zero size + //- Alias for setSize(const label) + inline void resize(const label n); + + //- Adjust size + inline void setSize(const label n); + + //- Reset to zero start and zero size inline void clear(); //- Is the range empty? inline bool empty() const; + //- Adjust the start to avoid any negative indices + void adjust(); + + //- Is the range valid (non-empty)? + inline bool valid() const; + //- Return the effective size of the range inline label size() const; @@ -109,32 +128,44 @@ public: //- The (inclusive) upper value of the range inline label last() const; - //- Return true if the value is within the range - inline bool contains(const label) const; + //- Reset start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + // Return true if the updated range valid (non-empty). + inline bool reset + ( + const label start, + const label size, + const bool adjustStart = false + ); - //- Return true if the ranges intersect + //- Return true if the value is within the range + inline bool contains(const label value) const; + + //- Return true if the ranges overlap. // Optional test for ranges that also just touch each other - bool intersects(const labelRange&, const bool touches = false) const; + bool overlaps(const labelRange& range, bool touches=false) const; //- Return a joined range, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange join(const labelRange&) const; + // A prior overlaps() check can be used to avoid squashing gaps. + labelRange join(const labelRange& range) const; // Member Operators //- Return element in range, no bounds checking - inline label operator[](const label) const; + inline label operator[](const label i) const; - //- Comparison function for sorting, compares the start + //- Comparison function for sorting, compares the start. + // If the start values are equal, also compares the size. inline bool operator<(const labelRange& rhs) const; //- Join ranges, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange& operator+=(const labelRange&); + // A prior overlaps() check can be used to avoid squashing gaps. + void operator+=(const labelRange& rhs); - inline bool operator==(const labelRange&) const; - inline bool operator!=(const labelRange&) const; + inline bool operator==(const labelRange& rhs) const; + inline bool operator!=(const labelRange& rhs) const; // STL iterator @@ -142,6 +173,8 @@ public: //- An STL const_iterator class const_iterator { + friend class labelRange; + // Private data //- Reference to the range for which this is an iterator @@ -150,54 +183,48 @@ public: //- Current index label index_; - public: // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from range, moving to its 'begin' position - inline explicit const_iterator(const labelRange&); + //- Construct from range at 'begin' or 'end' position + inline const_iterator + ( + const labelRange& range, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; - inline bool operator!=(const const_iterator&) const; - - inline label operator*(); - inline label operator()(); + inline label operator*() const; + inline label operator()() const; inline const_iterator& operator++(); inline const_iterator operator++(int); }; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator begin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRange&); - friend Ostream& operator<<(Ostream&, const labelRange&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRange& range); + friend Ostream& operator<<(Ostream& os, const labelRange& range); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H index 21e839cf3c..927a6f57a0 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H @@ -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. @@ -33,32 +33,39 @@ inline Foam::labelRange::labelRange() {} -inline Foam::labelRange::labelRange(const label start, const label size) +inline Foam::labelRange::labelRange +( + const label start, + const label size, + const bool adjustStart +) : start_(start), size_(size) { - // disallow invalid sizes - if (size_ <= 0) + if (adjustStart) { - this->clear(); + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) + { + // Disallow invalid sizes + size_ = 0; } } // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRange::const_iterator::const_iterator() -: - range_(*reinterpret_cast(0)), - index_(-1) -{} - - -inline Foam::labelRange::const_iterator::const_iterator(const labelRange& range) +inline Foam::labelRange::const_iterator::const_iterator +( + const labelRange& range, + const bool endIter +) : range_(range), - index_(range_.empty() ? -1 : 0) + index_(endIter ? range_.size() : 0) {} @@ -76,17 +83,17 @@ inline bool Foam::labelRange::const_iterator::operator!= const const_iterator& iter ) const { - return !(this->operator==(iter)); + return (this->index_ != iter.index_); } -inline Foam::label Foam::labelRange::const_iterator::operator*() +inline Foam::label Foam::labelRange::const_iterator::operator*() const { return range_[index_]; } -inline Foam::label Foam::labelRange::const_iterator::operator()() +inline Foam::label Foam::labelRange::const_iterator::operator()() const { return range_[index_]; } @@ -95,12 +102,7 @@ inline Foam::label Foam::labelRange::const_iterator::operator()() inline Foam::labelRange::const_iterator& Foam::labelRange::const_iterator::operator++() { - if (++index_ >= range_.size()) - { - // equivalent to end iterator - index_ = -1; - } - + ++index_; return *this; } @@ -109,7 +111,7 @@ inline Foam::labelRange::const_iterator Foam::labelRange::const_iterator::operator++(int) { const_iterator old = *this; - this->operator++(); + ++index_; return old; } @@ -120,9 +122,9 @@ inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::cend() const +inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -132,14 +134,31 @@ inline Foam::labelRange::const_iterator Foam::labelRange::begin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::end() const +inline const Foam::labelRange::const_iterator Foam::labelRange::end() const { - return endIter_; + return const_iterator(*this, true); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +inline void Foam::labelRange::resize(const label n) +{ + setSize(n); +} + + +inline void Foam::labelRange::setSize(const label n) +{ + size_ = n; + + if (size_ < 0) + { + size_ = 0; + } +} + + inline void Foam::labelRange::clear() { start_ = size_ = 0; @@ -152,6 +171,12 @@ inline bool Foam::labelRange::empty() const } +inline bool Foam::labelRange::valid() const +{ + return size_; +} + + inline Foam::label Foam::labelRange::size() const { return size_; @@ -170,6 +195,31 @@ inline Foam::label Foam::labelRange::last() const } +inline bool Foam::labelRange::reset +( + const label start, + const label size, + const bool adjustStart +) +{ + start_ = start; + size_ = size; + + if (adjustStart) + { + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) + { + // Disallow invalid sizes + size_ = 0; + } + + return size_; +} + + inline bool Foam::labelRange::contains(const label value) const { return value >= this->first() && value <= this->last(); @@ -186,7 +236,11 @@ inline Foam::label Foam::labelRange::operator[](const label i) const inline bool Foam::labelRange::operator<(const labelRange& rhs) const { - return this->first() < rhs.first(); + return + ( + this->first() < rhs.first() + || (this->first() == rhs.first() && this->size() < rhs.size()) + ); } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C index 101c2bce98..d9edff0e47 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,11 +26,6 @@ License #include "labelRanges.H" #include "ListOps.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const Foam::labelRanges::const_iterator Foam::labelRanges::endIter_; - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::labelRanges::insertBefore @@ -141,7 +136,7 @@ bool Foam::labelRanges::add(const labelRange& range) { labelRange& currRange = ParentType::operator[](elemI); - if (currRange.intersects(range, true)) + if (currRange.overlaps(range, true)) { // absorb into the existing (adjacent/overlapping) range currRange += range; @@ -150,7 +145,7 @@ bool Foam::labelRanges::add(const labelRange& range) for (; elemI < this->size()-1; ++elemI) { labelRange& nextRange = ParentType::operator[](elemI+1); - if (currRange.intersects(nextRange, true)) + if (currRange.overlaps(nextRange, true)) { currRange += nextRange; nextRange.clear(); diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H index 6fa10b0aac..134acb0482 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,8 +49,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRanges; -Istream& operator>>(Istream&, labelRanges&); -Ostream& operator<<(Ostream&, const labelRanges&); +Istream& operator>>(Istream& is, labelRanges& ranges); +Ostream& operator<<(Ostream& is, const labelRanges& ranges); /*---------------------------------------------------------------------------*\ Class labelRanges Declaration @@ -68,13 +68,13 @@ class labelRanges // Private Member Functions //- Insert range before specified insertion index, by copying up - void insertBefore(const label, const labelRange&); + void insertBefore(const label insert, const labelRange& range); //- Purge empty ranges, by copying down void purgeEmpty(); //- Print the range for debugging purposes - Ostream& printRange(Ostream&, const labelRange&) const; + Ostream& printRange(Ostream& os, const labelRange& range) const; public: @@ -85,10 +85,10 @@ public: inline labelRanges(); //- Construct given size - inline explicit labelRanges(const label); + inline explicit labelRanges(const label nElem); //- Construct from Istream. - labelRanges(Istream&); + labelRanges(Istream& is); // Member Functions @@ -100,19 +100,22 @@ public: using DynamicList::empty; //- Return true if the value is within any of the ranges - inline bool contains(const label) const; + inline bool contains(const label value) const; //- Add the range to the list - bool add(const labelRange&); + bool add(const labelRange& range); //- Remove the range from the list - bool remove(const labelRange&); + bool remove(const labelRange& range); + // STL iterator //- An STL const_iterator class const_iterator { + friend class labelRanges; + // Private data //- Reference to the list for which this is an iterator @@ -124,22 +127,21 @@ public: //- Index of current element at listIndex label subIndex_; - public: - // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from list, moving to its 'begin' position - inline explicit const_iterator(const labelRanges&); + //- Construct from ranges at 'begin' or 'end' position + inline const_iterator + ( + const labelRanges& lst, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; - - inline bool operator!=(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; inline label operator*(); inline label operator()(); @@ -149,29 +151,23 @@ public: }; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator begin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRanges&); - friend Ostream& operator<<(Ostream&, const labelRanges&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRanges& ranges); + friend Ostream& operator<<(Ostream& os, const labelRanges& ranges); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H index 739d582e9f..9ccad0e300 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H @@ -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. @@ -40,28 +40,18 @@ inline Foam::labelRanges::labelRanges(const label nElem) // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRanges::const_iterator::const_iterator() +inline Foam::labelRanges::const_iterator::const_iterator +( + const labelRanges& lst, + const bool endIter +) : - list_(*reinterpret_cast(0)), - index_(-1), - subIndex_(-1) + list_(lst), + index_(endIter ? lst.size() : 0), + subIndex_(0) {} -inline Foam::labelRanges::const_iterator::const_iterator(const labelRanges& lst) -: - list_(lst), - index_(0), - subIndex_(0) -{ - if (list_.empty()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } -} - - inline bool Foam::labelRanges::const_iterator::operator== ( const const_iterator& iter @@ -69,7 +59,7 @@ inline bool Foam::labelRanges::const_iterator::operator== { return ( - this->index_ == iter.index_ + this->index_ == iter.index_ && this->subIndex_ == iter.subIndex_ ); } @@ -101,13 +91,9 @@ Foam::labelRanges::const_iterator::operator++() { if (++subIndex_ >= list_[index_].size()) { - // go to next list entry + // Next sub-list + ++index_; subIndex_ = 0; - if (++index_ >= list_.size()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } } return *this; @@ -129,9 +115,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::cbegin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::cend() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -141,9 +127,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::begin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::end() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::end() const { - return endIter_; + return const_iterator(*this, true); } diff --git a/src/conversion/vtk/part/foamVtkCells.C b/src/conversion/vtk/part/foamVtkCells.C index b4c7beacde..5846c8442d 100644 --- a/src/conversion/vtk/part/foamVtkCells.C +++ b/src/conversion/vtk/part/foamVtkCells.C @@ -326,7 +326,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 5; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_PYRAMID; @@ -373,7 +373,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 4; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_TETRA; diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 87fd35ee22..ab7fe26dc2 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -19,6 +19,7 @@ vtk/format/foamVtkAppendBase64Formatter.C vtk/format/foamVtkAppendRawFormatter.C vtk/format/foamVtkAsciiFormatter.C vtk/format/foamVtkBase64Formatter.C +vtk/format/foamVtkBase64Layer.C vtk/format/foamVtkLegacyFormatter.C vtk/format/foamVtkFormatter.C vtk/format/foamVtkOutputOptions.C diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C index ee8b84200f..3805b61812 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,8 +27,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; -const char* Foam::foamVtkAppendBase64Formatter::encoding_ = "base64"; +const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -38,14 +37,16 @@ Foam::foamVtkAppendBase64Formatter::foamVtkAppendBase64Formatter std::ostream& os ) : - foamVtkBase64Formatter(os) + foamVtkBase64Layer(os) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::foamVtkAppendBase64Formatter::~foamVtkAppendBase64Formatter() -{} +{ + base64Layer::close(); +} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // @@ -56,10 +57,4 @@ const char* Foam::foamVtkAppendBase64Formatter::name() const } -const char* Foam::foamVtkAppendBase64Formatter::encoding() const -{ - return encoding_; -} - - // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H index b7239ee7c6..db3e1d6694 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,7 @@ SourceFiles #ifndef foamVtkAppendBase64Formatter_H #define foamVtkAppendBase64Formatter_H -#include "foamVtkBase64Formatter.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,12 +49,11 @@ namespace Foam class foamVtkAppendBase64Formatter : - public foamVtkBase64Formatter + public foamVtkBase64Layer { // Private Data Members static const char* name_; - static const char* encoding_; // Private Member Functions @@ -71,7 +70,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendBase64Formatter(std::ostream&); + foamVtkAppendBase64Formatter(std::ostream& os); //- Destructor @@ -83,9 +82,6 @@ public: //- Output name for XML type ("append") virtual const char* name() const; - //- Name for the XML append encoding ("base64"). - virtual const char* encoding() const; - }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C index 9933970495..ae565323b8 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,9 +71,9 @@ const char* Foam::foamVtkAppendRawFormatter::encoding() const } -void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t val) +void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t nBytes) { - write(reinterpret_cast(&val), sizeof(uint64_t)); + write(reinterpret_cast(&nBytes), sizeof(uint64_t)); } @@ -85,28 +85,28 @@ void Foam::foamVtkAppendRawFormatter::write(const uint8_t val) void Foam::foamVtkAppendRawFormatter::write(const label val) { - // std::cerr<<"label is:" << sizeof(val) << '\n'; + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast(&val), sizeof(label)); } void Foam::foamVtkAppendRawFormatter::write(const float val) { - // std::cerr<<"float is:" << sizeof(val) << '\n'; + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast(&val), sizeof(float)); } void Foam::foamVtkAppendRawFormatter::write(const double val) { - // std::cerr<<"write double as float:" << val << '\n'; + // std::cerr<<"double as float=" << val << '\n'; float copy(val); write(copy); } void Foam::foamVtkAppendRawFormatter::flush() -{} +{/*nop*/} // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H index abc3db0929..1dcb9b8d55 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H @@ -77,7 +77,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendRawFormatter(std::ostream&); + foamVtkAppendRawFormatter(std::ostream& os); //- Destructor @@ -94,12 +94,14 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t nBytes); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- A no-op for this format virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C index 6a78f73f53..9ed22db233 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,16 @@ inline void Foam::foamVtkAsciiFormatter::next() } +inline void Foam::foamVtkAsciiFormatter::done() +{ + if (pos_) + { + os()<< '\n'; + } + pos_ = 0; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter(std::ostream& os) @@ -73,7 +83,7 @@ Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter Foam::foamVtkAsciiFormatter::~foamVtkAsciiFormatter() { - flush(); + done(); } @@ -91,7 +101,7 @@ const char* Foam::foamVtkAsciiFormatter::encoding() const } -void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t) +void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t ignored) {/*nop*/} @@ -125,11 +135,14 @@ void Foam::foamVtkAsciiFormatter::write(const double val) void Foam::foamVtkAsciiFormatter::flush() { - if (pos_) - { - os()<< '\n'; - } - pos_ = 0; + done(); +} + + +std::size_t +Foam::foamVtkAsciiFormatter::encodedLength(std::size_t ignored) const +{ + return 0; } diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H index 009d776f89..8b8e06b2a2 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,9 +62,12 @@ class foamVtkAsciiFormatter // Private Member Functions - //- Advance to next position, adding space or newline as required + //- Advance to next position, adding space or newline as needed inline void next(); + //- Finish an output line, adding newline as needed + inline void done(); + //- Disallow default bitwise copy construct foamVtkAsciiFormatter(const foamVtkAsciiFormatter&) = delete; @@ -78,10 +81,10 @@ public: // Constructors //- Construct and attach to an output stream, use default precision - foamVtkAsciiFormatter(std::ostream&); + foamVtkAsciiFormatter(std::ostream& os); //- Construct and attach to an output stream, use specified precision - foamVtkAsciiFormatter(std::ostream&, unsigned precision); + foamVtkAsciiFormatter(std::ostream& os, unsigned precision); //- Destructor @@ -95,18 +98,24 @@ public: virtual const char* name() const; //- Name for the XML append encoding - unused. - // Currently simply "ASCII", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - this is a no-op for ascii output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- Write a newline if needed to finish a line of output. virtual void flush(); + + //- The encoded length for ascii output is not applicable. + virtual std::size_t encodedLength(std::size_t ignored) const; + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C index a11d97bd49..f87efbb19f 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,28 +27,14 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkBase64Formatter::name_ = "binary"; -const char* Foam::foamVtkBase64Formatter::encoding_ = "base64"; - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void Foam::foamVtkBase64Formatter::write -( - const char* s, - std::streamsize n -) -{ - base64Layer::write(s, n); -} +const char* Foam::foamVtkBase64Formatter::name_ = "binary"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) : - foamVtkFormatter(os), - base64Layer(os) + foamVtkBase64Layer(os) {} @@ -56,7 +42,10 @@ Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) Foam::foamVtkBase64Formatter::~foamVtkBase64Formatter() { - flush(); + if (base64Layer::close()) + { + os().put('\n'); + } } @@ -68,46 +57,6 @@ const char* Foam::foamVtkBase64Formatter::name() const } -const char* Foam::foamVtkBase64Formatter::encoding() const -{ - return encoding_; -} - - -void Foam::foamVtkBase64Formatter::writeSize(const uint64_t val) -{ - write(reinterpret_cast(&val), sizeof(uint64_t)); -} - - -void Foam::foamVtkBase64Formatter::write(const uint8_t val) -{ - base64Layer::add(val); -} - - -void Foam::foamVtkBase64Formatter::write(const label val) -{ - // std::cerr<<"label is:" << sizeof(val) << '\n'; - write(reinterpret_cast(&val), sizeof(label)); -} - - -void Foam::foamVtkBase64Formatter::write(const float val) -{ - // std::cerr<<"float is:" << sizeof(val) << '\n'; - write(reinterpret_cast(&val), sizeof(float)); -} - - -void Foam::foamVtkBase64Formatter::write(const double val) -{ - // std::cerr<<"write double as float:" << val << '\n'; - float copy(val); - write(copy); -} - - void Foam::foamVtkBase64Formatter::flush() { if (base64Layer::close()) diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H index f01bec3d9a..e92fa4f9e3 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,8 +33,7 @@ Description #ifndef foamVtkBase64Formatter_H #define foamVtkBase64Formatter_H -#include "foamVtkFormatter.H" -#include "base64Layer.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,8 +46,7 @@ namespace Foam class foamVtkBase64Formatter : - public foamVtkFormatter, - private base64Layer + public foamVtkBase64Layer { // Private Data Members @@ -64,20 +62,12 @@ class foamVtkBase64Formatter //- Disallow default bitwise assignment void operator=(const foamVtkBase64Formatter&) = delete; -protected: - - // Protected Member Functions - - //- Write - void write(const char* s, std::streamsize n); - - public: // Constructors //- Construct and attach to an output stream - foamVtkBase64Formatter(std::ostream&); + foamVtkBase64Formatter(std::ostream& os); //- Destructor @@ -90,17 +80,9 @@ public: // The lowercase version of the Legacy output type. virtual const char* name() const; - //- Name for the XML append encoding. - virtual const char* encoding() const; - - //- Write leading size for binary output - virtual void writeSize(const uint64_t); - - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + //- End the encoding sequence (padding the final characters with '=') + // and write a newline to the output if any encoding was done. virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.C b/src/fileFormats/vtk/format/foamVtkBase64Layer.C new file mode 100644 index 0000000000..d66970d522 --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.C @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkBase64Layer.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding_ = "base64"; + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::foamVtkBase64Layer::write +( + const char* s, + std::streamsize n +) +{ + base64Layer::write(s, n); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os) +: + foamVtkFormatter(os), + base64Layer(os) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::~foamVtkBase64Layer() +{ + base64Layer::close(); +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding() const +{ + return encoding_; +} + + +void Foam::foamVtkBase64Layer::writeSize(const uint64_t nBytes) +{ + write(reinterpret_cast(&nBytes), sizeof(uint64_t)); +} + + +void Foam::foamVtkBase64Layer::write(const uint8_t val) +{ + base64Layer::add(val); +} + + +void Foam::foamVtkBase64Layer::write(const label val) +{ + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast(&val), sizeof(label)); +} + + +void Foam::foamVtkBase64Layer::write(const float val) +{ + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast(&val), sizeof(float)); +} + + +void Foam::foamVtkBase64Layer::write(const double val) +{ + // std::cerr<<"double as float=" << val << '\n'; + float copy(val); + write(copy); +} + + +void Foam::foamVtkBase64Layer::flush() +{ + base64Layer::close(); +} + + +std::size_t Foam::foamVtkBase64Layer::encodedLength(std::size_t n) const +{ + return base64Layer::encodedLength(n); +} + + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.H b/src/fileFormats/vtk/format/foamVtkBase64Layer.H new file mode 100644 index 0000000000..61527a11bc --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + foamVtkBase64Layer + +Description + Base-64 encoded output. + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkBase64Layer_H +#define foamVtkBase64Layer_H + +#include "foamVtkFormatter.H" +#include "base64Layer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamVtkBase64Layer Declaration +\*---------------------------------------------------------------------------*/ + +class foamVtkBase64Layer +: + public foamVtkFormatter, + protected base64Layer +{ + // Private Data Members + + static const char* encoding_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + foamVtkBase64Layer(const foamVtkBase64Layer&) = delete; + + //- Disallow default bitwise assignment + void operator=(const foamVtkBase64Layer&) = delete; + +protected: + + // Protected Member Functions + + //- Write + void write(const char* s, std::streamsize n); + + + // Constructors + + //- Construct and attach to an output stream + foamVtkBase64Layer(std::ostream& os); + +public: + + //- Destructor + virtual ~foamVtkBase64Layer(); + + + // Member Functions + + //- Name for the XML append encoding ("base64"). + virtual const char* encoding() const; + + + //- Write leading size for binary output + virtual void writeSize(const uint64_t nBytes); + + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- End the encoding sequence (padding the final characters with '=') + virtual void flush(); + + //- The encoded length for base64 encoded output. + virtual std::size_t encodedLength(std::size_t n) const; + +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index 7271dd22f5..2bc607a78a 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,6 +52,12 @@ Foam::foamVtkFormatter::~foamVtkFormatter() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +std::size_t Foam::foamVtkFormatter::encodedLength(std::size_t n) const +{ + return n; +} + + void Foam::foamVtkFormatter::indent() { label n = xmlTags_.size() * 2; @@ -149,7 +155,6 @@ Foam::foamVtkFormatter::tag(const word& tag) } - Foam::foamVtkFormatter& Foam::foamVtkFormatter::endTag(const word& tag) { @@ -181,7 +186,6 @@ Foam::foamVtkFormatter::endTag(const word& tag) } - Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr ( diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 65519b1955..5ab0776d60 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,8 +74,8 @@ class foamVtkFormatter template foamVtkFormatter& xmlAttribute ( - const word&, - const Type&, + const word& k, + const Type& v, const char quote ); @@ -120,14 +120,20 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t) = 0; + virtual void writeSize(const uint64_t nBytes) = 0; - virtual void write(const uint8_t) = 0; - virtual void write(const label) = 0; - virtual void write(const float) = 0; - virtual void write(const double) = 0; + virtual void write(const uint8_t val) = 0; + virtual void write(const label val) = 0; + virtual void write(const float val) = 0; + virtual void write(const double val) = 0; + + //- Flush encoding, write newline etc. virtual void flush() = 0; + //- The encoded length for binary output. + // The default is pass-through. + virtual std::size_t encodedLength(std::size_t n) const; + // Member Functions @@ -138,7 +144,7 @@ public: foamVtkFormatter& xmlHeader(); //- Write XML comment (at the current indentation level) - foamVtkFormatter& comment(const std::string&); + foamVtkFormatter& comment(const std::string& text); //- Open XML tag @@ -177,40 +183,40 @@ public: //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const std::string&, + const word& k, + const std::string& v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int32_t, + const word& k, + const int32_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int64_t, + const word& k, + const int64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const uint64_t, + const word& k, + const uint64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const scalar, + const word& k, + const scalar v, const char quote = '\'' ); @@ -219,19 +225,19 @@ public: // Member Operators //- Write XML attribute - foamVtkFormatter& operator()(const word&, const std::string&); + foamVtkFormatter& operator()(const word& k, const std::string& v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int32_t); + foamVtkFormatter& operator()(const word& k, const int32_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int64_t); + foamVtkFormatter& operator()(const word& k, const int64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const uint64_t); + foamVtkFormatter& operator()(const word& k, const uint64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const scalar); + foamVtkFormatter& operator()(const word& k, const scalar v); }; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C index 89525ab0ba..a3e87264f8 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,8 +71,8 @@ const char* Foam::foamVtkLegacyFormatter::encoding() const } -void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t) -{} +void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t ignored) +{/*nop*/} void Foam::foamVtkLegacyFormatter::write(const uint8_t val) diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H index fe2395add4..6ec5ba7e8d 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,11 +25,10 @@ Class foamVtkLegacyFormatter Description - Binary output for the VTK legacy format, always written as big-endian. + Binary output for the VTK legacy format, always written as big-endian + and with 32-bit integers. - The legacy files are always written as big endian. - Since integers in the legacy format are limited to 32-bit, - this format should not be used for OpenFOAM with 64-bit label sizes. + This format should never be used for OpenFOAM with 64-bit label sizes. SourceFiles foamVtkLegacyFormatter.C @@ -81,7 +80,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkLegacyFormatter(std::ostream&); + foamVtkLegacyFormatter(std::ostream& os); //- Destructor @@ -90,22 +89,25 @@ public: // Member Functions - //- Name for the Legacy output type ("BINARY") + //- Name for the legacy binary output type ("BINARY") virtual const char* name() const; //- Name for the XML append encoding (unused) - // Currently simply "BINARY", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - a no-op for legacy binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- Write a newline to the output virtual void flush(); + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.C b/src/fileFormats/vtk/format/foamVtkOutputOptions.C index 39f11a432e..c88d334594 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.C +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,10 +45,8 @@ Foam::foamVtkOutputOptions::foamVtkOutputOptions() // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -Foam::autoPtr Foam::foamVtkOutputOptions::newFormatter -( - std::ostream& os -) const +Foam::autoPtr +Foam::foamVtkOutputOptions::newFormatter(std::ostream& os) const { switch (type_) { @@ -87,9 +85,9 @@ Foam::autoPtr Foam::foamVtkOutputOptions::newFormatter // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -void Foam::foamVtkOutputOptions::ascii(bool b) +void Foam::foamVtkOutputOptions::ascii(bool on) { - if (b) + if (on) { // Force ASCII: @@ -132,9 +130,9 @@ void Foam::foamVtkOutputOptions::ascii(bool b) } -void Foam::foamVtkOutputOptions::append(bool b) +void Foam::foamVtkOutputOptions::append(bool on) { - if (b) + if (on) { if (!(type_ & APPEND)) { @@ -153,9 +151,9 @@ void Foam::foamVtkOutputOptions::append(bool b) } -void Foam::foamVtkOutputOptions::legacy(bool b) +void Foam::foamVtkOutputOptions::legacy(bool on) { - if (b) + if (on) { if (type_ & APPEND) { @@ -180,9 +178,9 @@ void Foam::foamVtkOutputOptions::legacy(bool b) } -void Foam::foamVtkOutputOptions::precision(unsigned val) const +void Foam::foamVtkOutputOptions::precision(unsigned prec) const { - precision_ = val; + precision_ = prec; } diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.H b/src/fileFormats/vtk/format/foamVtkOutputOptions.H index a5f59de514..7e0e89b24b 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.H +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -88,7 +88,7 @@ public: // Selectors //- Return new data formatter based on the writer options - autoPtr newFormatter(std::ostream&) const; + autoPtr newFormatter(std::ostream& os) const; // Member Functions @@ -117,16 +117,16 @@ public: // In append mode, this switches between base64 and raw binary. // In XML mode, this switches between ASCII and base64. // In legacy mode, this switches between ASCII and binary. - void ascii(bool); + void ascii(bool on); //- Toggle append mode on/off. - void append(bool); + void append(bool on); //- Toggle legacy mode on/off. - void legacy(bool); + void legacy(bool on); //- Set the write precision to be used for new ASCII formatters - void precision(unsigned val) const; + void precision(unsigned prec) const; // Other diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.C b/src/fileFormats/vtk/type/foamVtkPTraits.C index 91bf1f3a33..feb5e909c2 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.C +++ b/src/fileFormats/vtk/type/foamVtkPTraits.C @@ -59,11 +59,11 @@ Foam::foamVtkPTraits::typeName = "Float64"; #ifdef WM_LITTLE_ENDIAN template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "LittleEndian"; +Foam::foamVtkPTraits::typeName = "LittleEndian"; #else template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "BigEndian"; +Foam::foamVtkPTraits::typeName = "BigEndian"; #endif diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.H b/src/fileFormats/vtk/type/foamVtkPTraits.H index ea95c0820d..ff77c03b8d 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.H +++ b/src/fileFormats/vtk/type/foamVtkPTraits.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,28 +58,28 @@ public: template<> -const char* const foamVtkPTraits::typeName; // = UInt8 +const char* const foamVtkPTraits::typeName; // UInt8 template<> -const char* const foamVtkPTraits::typeName; // = Int32 +const char* const foamVtkPTraits::typeName; // Int32 template<> -const char* const foamVtkPTraits::typeName; // = UInt32 +const char* const foamVtkPTraits::typeName; // UInt32 template<> -const char* const foamVtkPTraits::typeName; // = Int64 +const char* const foamVtkPTraits::typeName; // Int64 template<> -const char* const foamVtkPTraits::typeName; // = UInt64 +const char* const foamVtkPTraits::typeName; // UInt64 template<> -const char* const foamVtkPTraits::typeName; // = Float32 +const char* const foamVtkPTraits::typeName; // Float32 template<> -const char* const foamVtkPTraits::typeName; // = Float64 +const char* const foamVtkPTraits::typeName; // Float64 template<> -const char* const foamVtkPTraits<::Foam::endian>::typeName; +const char* const foamVtkPTraits::typeName; // (Big|Little)Endian // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.C b/src/functionObjects/solvers/scalarTransport/scalarTransport.C index 84b68341d8..641241b91e 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.C +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.C @@ -201,7 +201,7 @@ Foam::functionObjects::scalarTransport::scalarTransport resetOnStartUp_(false), schemesField_("unknown-schemesField"), fvOptions_(mesh_), - bounded01_(dict.lookupOrDefault("bounded01", true)) + bounded01_(dict.lookupOrDefault("bounded01", true)) { read(dict); @@ -235,12 +235,7 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) dict.readIfPresent("bounded01", bounded01_); schemesField_ = dict.lookupOrDefault("schemesField", fieldName_); - - constantD_ = false; - if (dict.readIfPresent("D", D_)) - { - constantD_ = true; - } + constantD_ = dict.readIfPresent("D", D_); dict.readIfPresent("nCorr", nCorr_); dict.readIfPresent("resetOnStartUp", resetOnStartUp_); @@ -256,11 +251,11 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) bool Foam::functionObjects::scalarTransport::execute() { - Log << type() << " write:" << endl; - volScalarField& s = transportedField(); - const surfaceScalarField& phi = + Log << type() << " execute: " << s.name() << endl; + + const surfaceScalarField& phi = mesh_.lookupObject(phiName_); // Calculate the diffusivity diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.H b/src/functionObjects/solvers/scalarTransport/scalarTransport.H index e2570fc7f9..bc743e7eea 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.H +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.H @@ -111,17 +111,18 @@ Usage \table Property | Description | Required | Default value type | Type name: scalarTransport | yes | - phi | Name of flux field | yes | + field | Name of the scalar field | no | s + phi | Name of flux field | no | phi rho | Name of density field | no | rho - phase | Name of the phase name | no | none + phase | Name of the phase | no | none nut | Name of the turbulence viscosity | no | none D | Diffusion coefficient | no | auto generated nCorr | Number of correctors | no | 0 resetOnStartUp | Reset scalar to zero on start-up | no | no - schemesField | Name of field to specify schemes | no | fieldName + schemesField | Name of field to specify schemes | no | field name fvOptions | List of scalar sources | no | - bounded01 | Bounds scalar between 0-1 for multiphase | no |true - phasePhiCompressed |Compressed flux for VOF | no | alphaPhiUn + bounded01 | Bounds scalar between 0-1 for multiphase | no | true + phasePhiCompressed | Compressed flux for VOF | no | alphaPhiUn \endtable See also @@ -156,10 +157,10 @@ class scalarTransport { // Private data - //- Name of field to process + //- Name of the transport field. word fieldName_; - //- Name of flux field + //- Name of flux field (optional) word phiName_; //- Name of density field (optional) @@ -168,10 +169,10 @@ class scalarTransport //- Name of turbulent viscosity field (optional) word nutName_; - //- Name of phase field + //- Name of phase field (optional) word phaseName_; - //- Name of phase field compressed flux + //- Name of phase field compressed flux (optional) word phasePhiCompressedName_; //- Diffusion coefficient (optional) diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C index f976ceb902..b522df0e56 100644 --- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C +++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -264,15 +264,13 @@ void Foam::faceShading::calculate() { includeAllFacesPerPatch[patchI].insert ( - faceI //pp.start() + faceI ); } } } } - labelList triSurfaceToAgglom(5*nFaces); - triSurface localSurface = triangulate ( includePatches, @@ -294,9 +292,10 @@ void Foam::faceShading::calculate() dict ); - surfacesMesh.searchableSurface::write(); - - triSurfaceToAgglom.resize(surfacesMesh.size()); + if (debug) + { + surfacesMesh.searchableSurface::write(); + } scalar maxBounding = 5.0*mag(mesh_.bounds().max() - mesh_.bounds().min()); @@ -324,7 +323,7 @@ void Foam::faceShading::calculate() const vector d(direction_*maxBounding); - start.append(fc - SMALL*d); + start.append(fc - 0.001*d); startIndex.append(myFaceId); @@ -355,7 +354,7 @@ void Foam::faceShading::calculate() ( mesh_.time().path()/"allVisibleFaces.obj", end, - Cfs + start ); }