From 1f6733d91d218e51e8998cf378af6c366d3dbd0d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 30 Jan 2009 00:07:53 +0100 Subject: [PATCH 01/20] PackedList - activated lazy evaluation - moving back to original flat addressing in iterators means there is no performance issue with using lazy evaluation - set() method now has ~0 for a default value. We can thus simply write 'set(i) to trun on all of the bits. This means we can use it just like labelHashSet::set(i) - added flip() method for inverting bits. I don't know where we might need it, but the STL has it so we might as well too. --- applications/test/PackedList/PackedListTest.C | 57 +++- .../containers/Lists/PackedList/PackedList.C | 51 +-- .../containers/Lists/PackedList/PackedList.H | 93 +++--- .../containers/Lists/PackedList/PackedListI.H | 301 +++++++----------- 4 files changed, 229 insertions(+), 273 deletions(-) diff --git a/applications/test/PackedList/PackedListTest.C b/applications/test/PackedList/PackedListTest.C index f1f58f3abc..a8488eb183 100644 --- a/applications/test/PackedList/PackedListTest.C +++ b/applications/test/PackedList/PackedListTest.C @@ -52,13 +52,25 @@ int main(int argc, char *argv[]) list1 = -1; list1.print(Info); + Info<< "\ntest zero\n"; + list1 = 0; + list1.print(Info); + + Info<< "\ntest set() with default argument (max_value)\n"; + list1.set(3); + list1.print(Info); + Info<< "\ntest assign between references\n"; list1[2] = 3; list1[4] = list1[2]; list1.print(Info); Info<< "\ntest assign between references, with chaining\n"; - list1[4] = list1[2] = 1; + list1[0] = list1[4] = 1; + list1.print(Info); + + Info<< "\ntest assign between references, with chaining and auto-vivify\n"; + list1[1] = list1[8] = list1[10] = list1[14] = 2; list1.print(Info); { @@ -91,6 +103,14 @@ int main(int argc, char *argv[]) list1.resize(8, list1.max_value()); list1.print(Info); + Info<< "\ntest flip() function\n"; + list1.flip(); + list1.print(Info); + + Info<< "\nre-flip()\n"; + list1.flip(); + list1.print(Info); + Info<< "\ntest set() function\n"; list1.set(1, 5); list1.print(Info); @@ -188,15 +208,23 @@ int main(int argc, char *argv[]) { Info<< "\ntest assignment of iterator\n"; list1.print(Info); - PackedList<3>::iterator cit = list1[25]; - cit.print(Info); + Info<< "cend()\n"; list1.end().print(Info); + PackedList<3>::iterator cit = list1[100]; + Info<< "out-of-range: "; + cit.print(Info); + cit = list1[15]; + Info<< "in-range: "; + cit.print(Info); + Info<< "out-of-range: "; + cit = list1[1000]; + cit.print(Info); } for ( - PackedList<3>::iterator cit = list1[5]; + PackedList<3>::iterator cit = list1[30]; cit != list1.end(); ++cit ) @@ -204,14 +232,19 @@ int main(int argc, char *argv[]) cit.print(Info); } -// Info<< "\ntest operator[] auto-vivify\n"; -// const unsigned int val = list1[45]; -// -// Info<< "list[45]:" << val << "\n"; -// list1[45] = list1.max_value(); -// Info<< "list[45]:" << list1[45] << "\n"; -// list1[49] = list1.max_value(); -// list1.print(Info); + Info<< "\ntest operator[] auto-vivify\n"; + Info<< "size:" << list1.size() << "\n"; + + const unsigned int val = list1[45]; + + Info<< "list[45]:" << val << "\n"; + Info<< "size after read:" << list1.size() << "\n"; + + list1[45] = list1.max_value(); + Info<< "size after write:" << list1.size() << "\n"; + Info<< "list[45]:" << list1[45] << "\n"; + list1[49] = list1[100]; + list1.print(Info); Info<< "\ntest copy constructor + append\n"; diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index 8667ad47ba..87ced9504f 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -83,25 +83,25 @@ unsigned int Foam::PackedList::count() const if (size_) { - // mask value for complete chunks + // mask value for complete segments unsigned int mask = maskLower(packing()); - unsigned int endIdx = size_ / packing(); - unsigned int endOff = size_ % packing(); + const unsigned int endSeg = size_ / packing(); + const unsigned int endOff = size_ % packing(); - // count bits in complete elements - for (unsigned i = 0; i < endIdx; ++i) + // count bits in complete segments + for (unsigned i = 0; i < endSeg; ++i) { register unsigned int bits = StorageList::operator[](i) & mask; COUNT_PACKEDBITS(c, bits); } - // count bits in partial chunk + // count bits in partial segment if (endOff) { mask = maskLower(endOff); - register unsigned int bits = StorageList::operator[](endIdx) & mask; + register unsigned int bits = StorageList::operator[](endSeg) & mask; COUNT_PACKEDBITS(c, bits); } } @@ -118,7 +118,7 @@ bool Foam::PackedList::trim() return false; } - // mask value for complete chunks + // mask value for complete segments unsigned int mask = maskLower(packing()); label currElem = packedLength(size_) - 1; @@ -130,7 +130,7 @@ bool Foam::PackedList::trim() StorageList::operator[](currElem) &= maskLower(endOff); } - // test entire chunk + // test entire segment while (currElem > 0 && !(StorageList::operator[](currElem) &= mask)) { currElem--; @@ -162,10 +162,22 @@ bool Foam::PackedList::trim() } +template +void Foam::PackedList::flip() +{ + label packLen = packedLength(size_); + + for (label i=0; i < packLen; i++) + { + StorageList::operator[](i) = ~StorageList::operator[](i); + } +} + + template Foam::labelList Foam::PackedList::values() const { - labelList elems(size()); + labelList elems(size_); forAll(*this, i) { @@ -178,10 +190,11 @@ Foam::labelList Foam::PackedList::values() const template Foam::Ostream& Foam::PackedList::iteratorBase::print(Ostream& os) const { - os << "iterator<" << label(nBits) << "> [" - << (index_ * packing() + offset_) << "]" - << " index:" << index_ << " offset:" << offset_ - << " value:" << unsigned(*this) + os << "iterator<" << label(nBits) << "> [" + << this->index_ << "]" + << " segment:" << label(this->index_ / packing()) + << " offset:" << label(this->index_ % packing()) + << " value:" << this->get() << nl; return os; @@ -194,7 +207,7 @@ Foam::Ostream& Foam::PackedList::print(Ostream& os) const os << "PackedList<" << label(nBits) << ">" << " max_value:" << max_value() << " packing:" << packing() << nl - << "values: " << size() << "/" << capacity() << "( "; + << "values: " << size_ << "/" << capacity() << "( "; forAll(*this, i) { os << get(i) << ' '; @@ -205,17 +218,17 @@ Foam::Ostream& Foam::PackedList::print(Ostream& os) const os << ")\n" << "storage: " << packLen << "/" << StorageList::size() << "( "; - // mask value for complete chunks + // mask value for complete segments unsigned int mask = maskLower(packing()); for (label i=0; i < packLen; i++) { const StorageType& rawBits = StorageList::operator[](i); - // the final storage may not be full, modify mask accordingly + // the final segment may not be full, modify mask accordingly if (i+1 == packLen) { - unsigned endOff = size_ % packing(); + unsigned int endOff = size_ % packing(); if (endOff) { @@ -229,7 +242,7 @@ Foam::Ostream& Foam::PackedList::print(Ostream& os) const for (unsigned int testBit = (1 << max_bits()); testBit; testBit >>= 1) { - if (testBit & mask) + if (mask & testBit) { if (rawBits & testBit) { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index b65a658e3a..a9cd59da86 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -44,9 +44,9 @@ Note Using the iteratorBase as a proxy allows assignment of values between list elements. Thus the following bit of code works as expected: @code - blist[1] = blist[5]; // value assignment, not iterator position - blist[2] = blist[5] = 4; // propagates value - blist[1] = blist[5] = blist[6]; // propagates value + list[1] = list[5]; // value assignment, not iterator position + list[2] = list[5] = 4; // propagates value + list[1] = list[5] = list[6]; // propagates value @endcode Using get() or the '[]' operator are similarly fast. Looping and reading @@ -58,11 +58,21 @@ Note useful for branching on changed values. @code - blist[5] = 4; - changed = blist.set(5, 8); + list[5] = 4; + changed = list.set(5, 8); if (changed) ... @endcode + The lazy evaluation used means that reading an out-of-range element + returns zero, but does not affect the list size. Even in a non-const + context, only the assigment causes the element to be created. + For example, + @code + list.resize(4); + Info<< list[10] << "\n"; // print zero, but doesn't adjust list + list[8] = 1; + @endcode + SeeAlso Foam::DynamicList @@ -120,9 +130,6 @@ class PackedList //- Calculate the list length when packed inline static label packedLength(const label); - //- Check index I is within valid range [ 0 .. max_value() ] - inline void checkIndex(const label) const; - public: // Public data @@ -172,22 +179,23 @@ public: // Access - //- The number of elements that can be stored before resizing + //- The number of elements that can be stored before reallocating inline label capacity() const; //- Number of entries. inline label size() const; - //- Return true if the list is empty (i.e., if size() == 0). + //- Return true if the list is empty (i.e., size() == 0). inline bool empty() const; //- Get value at index I. - // Does not auto-vivify entries. + // Never auto-vivify entries. inline unsigned int get(const label) const; //- Set value at index I. Return true if value changed. - // Does not auto-vivify entries. - inline bool set(const label, const unsigned int val); + // Does auto-vivify for non-existent entries. + // Default value set is the max_value. + inline bool set(const label, const unsigned int val = ~0u); //- Return the underlying packed storage inline List& storage(); @@ -200,9 +208,6 @@ public: // http://en.wikipedia.org/wiki/Hamming_weight unsigned int count() const; - //- Trim any trailing zero elements - bool trim(); - //- Return the values as a labelList labelList values() const; @@ -211,6 +216,12 @@ public: // Edit + //- Trim any trailing zero elements + bool trim(); + + //- Invert the bits in the addressable region. + void flip(); + //- Alter the size of the underlying storage. // The addressed size will be truncated if needed to fit, but will // remain otherwise untouched. @@ -255,12 +266,12 @@ public: inline unsigned int remove(); //- Get value at index I - // Does not auto-vivify entries. + // Never auto-vivify entries. inline unsigned int operator[](const label) const; //- Set value at index I. // Returns iterator to perform the actual operation. - // Does not auto-vivify entries. + // Does not auto-vivify entries, but will when assigned to. inline iteratorBase operator[](const label); //- Assignment of all entries to the given value. Takes linear time. @@ -294,52 +305,27 @@ public: // This also lets us use the default bitwise copy/assignment PackedList* list_; - //- Element index within storage - unsigned index_; - - //- Offset within storage element - unsigned offset_; + //- Element index + label index_; // Protected Member Functions - //- Get value as unsigned + //- Get value as unsigned, no range-checking inline unsigned int get() const; - //- Set value, returning true if changed + //- Set value, returning true if changed, no range-checking inline bool set(unsigned int); - //- Increment to new position - inline void incr(); - - //- Decrement to new position - inline void decr(); - - //- Move to new position, but not beyond end() - inline void seek(const iteratorBase&); - - // Constructors //- Construct null inline iteratorBase(); - //- Copy construct - inline iteratorBase(const iteratorBase&); - //- Construct from base list and position index inline iteratorBase(const PackedList*, const label); public: - // Member Functions - - //- Return true if the element is within addressable range - inline bool valid() const; - - //- Move iterator to end() if it would otherwise be out-of-range - // Returns true if the element was already ok - inline bool validate(); - // Member Operators //- Compare positions @@ -350,10 +336,12 @@ public: // This allows packed[0] = packed[3] for assigning values inline unsigned int operator=(const iteratorBase&); - //- Assign value + //- Assign value. + // A non-existent entry will be auto-vivified. inline unsigned int operator=(const unsigned int val); //- Conversion operator + // Never auto-vivify entries. inline operator unsigned int () const; //- Print value and information @@ -378,6 +366,8 @@ public: inline iterator(); //- Construct from iterator base, eg iter(packedlist[i]) + // but also "iterator iter = packedlist[i];" + // An out-of-range iterator is assigned end() inline iterator(const iteratorBase&); //- Construct from base list and position index @@ -386,6 +376,7 @@ public: // Member Operators //- Assign from iteratorBase, eg iter = packedlist[i] + // An out-of-range iterator is assigned end() inline iterator& operator=(const iteratorBase&); //- Return value @@ -427,7 +418,9 @@ public: //- Construct null inline const_iterator(); - //- Construct from iterator base + //- Construct from iterator base, eg iter(packedlist[i]) + // but also "const_iterator iter = packedlist[i];" + // An out-of-range iterator is assigned end() inline const_iterator(const iteratorBase&); //- Construct from base list and position index @@ -439,7 +432,7 @@ public: // Member operators //- Assign from iteratorBase or derived - // eg, iter = packedlist[i] or iter = [non-const]list.begin() + // eg, iter = packedlist[i] or even iter = list.begin() inline const_iterator& operator=(const iteratorBase&); //- Return referenced value directly diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 07e6d06208..929688ef24 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -65,24 +65,6 @@ inline Foam::label Foam::PackedList::packedLength(const label nElem) } -template -inline void Foam::PackedList::checkIndex(const label i) const -{ - if (!size_) - { - FatalErrorIn("PackedList::checkIndex(const label)") - << "attempt to access element from zero-sized list" - << abort(FatalError); - } - else if (i < 0 || i >= size_) - { - FatalErrorIn("PackedList::checkIndex(const label)") - << "index " << i << " out of range 0 ... " << size_-1 - << abort(FatalError); - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -105,7 +87,7 @@ template inline Foam::PackedList::PackedList(const PackedList& lst) : StorageList(lst), - size_(lst.size()) + size_(lst.size_) {} @@ -132,20 +114,7 @@ template inline Foam::PackedList::iteratorBase::iteratorBase() : list_(0), - index_(0), - offset_(0) -{} - - -template -inline Foam::PackedList::iteratorBase::iteratorBase -( - const iteratorBase& iter -) -: - list_(iter.list_), - index_(iter.index_), - offset_(iter.offset_) + index_(0) {} @@ -157,8 +126,7 @@ inline Foam::PackedList::iteratorBase::iteratorBase ) : list_(const_cast*>(lst)), - index_(i / packing()), - offset_(i % packing()) + index_(i) {} @@ -166,8 +134,11 @@ template inline unsigned int Foam::PackedList::iteratorBase::get() const { - const unsigned int& stored = list_->StorageList::operator[](index_); - return (stored >> (nBits * offset_)) & max_value(); + const unsigned int seg = index_ / packing(); + const unsigned int off = index_ % packing(); + + const unsigned int& stored = list_->StorageList::operator[](seg); + return (stored >> (nBits * off)) & max_value(); } @@ -175,114 +146,37 @@ template inline bool Foam::PackedList::iteratorBase::set(const unsigned int val) { - unsigned int& stored = list_->StorageList::operator[](index_); + const unsigned int seg = index_ / packing(); + const unsigned int off = index_ % packing(); + + unsigned int& stored = list_->StorageList::operator[](seg); const unsigned int prev = stored; - const unsigned int startBit = nBits * offset_; + const unsigned int startBit = nBits * off; const unsigned int maskNew = max_value() << startBit; if (val & ~max_value()) { -# ifdef DEBUGList - FatalErrorIn("PackedList::iteratorBase::set(const unsigned int)") - << "value " << label(val) -w << " out-of-range 0 ... " << label(max_value()) - << " representable by " << nBits << " bits" - << abort(FatalError); -# endif - - // treat overflow as max_value + // overflow is max_value, fill everything stored |= maskNew; } else { - stored = (stored & ~maskNew) | (maskNew & (val << startBit)); + stored &= ~maskNew; + stored |= maskNew & (val << startBit); } return prev != stored; } - -template -inline void -Foam::PackedList::iteratorBase::incr() -{ - offset_++; - if (offset_ >= packing()) - { - offset_ = 0; - index_++; - } -} - - -template -inline void -Foam::PackedList::iteratorBase::decr() -{ - if (!offset_) - { - offset_ = packing(); - index_--; - } - offset_--; -} - - -template -inline void -Foam::PackedList::iteratorBase::seek -( - const iteratorBase& iter -) -{ - list_ = iter.list_; - index_ = iter.index_; - offset_ = iter.offset_; - - this->validate(); -} - - -template -inline bool -Foam::PackedList::iteratorBase::valid() const -{ - label elemI = offset_ + index_ * packing(); - return (elemI < list_->size_); -} - - -template -inline bool -Foam::PackedList::iteratorBase::validate() -{ - // avoid going past end() - unsigned endIdx = list_->size_ / packing(); - unsigned endOff = list_->size_ % packing(); - - if (index_ > endIdx || (index_ == endIdx && offset_ > endOff)) - { - index_ = endIdx; - offset_ = endOff; - - return false; - } - else - { - return true; - } -} - - template inline bool Foam::PackedList::iteratorBase::operator== ( const iteratorBase& iter ) const { - return this->index_ == iter.index_ && this->offset_ == iter.offset_; + return this->index_ == iter.index_; } @@ -292,7 +186,7 @@ inline bool Foam::PackedList::iteratorBase::operator!= const iteratorBase& iter ) const { - return this->index_ != iter.index_ || this->offset_ != iter.offset_; + return this->index_ != iter.index_; } @@ -310,14 +204,11 @@ template inline unsigned int Foam::PackedList::iteratorBase::operator=(const unsigned int val) { -# ifdef DEBUGList - // lazy evaluation would be nice to keep, but really slows things down - label minsize = 1 + offset_ + index_ * packing(); - if (minsize > list_->size_) + // lazy evaluation - increase size on assigment + if (index_ >= list_->size_) { - list_->resize(minsize); + list_->resize(index_ + 1); } -#endif this->set(val); return val; @@ -328,14 +219,11 @@ template inline Foam::PackedList::iteratorBase::operator unsigned int () const { -# ifdef DEBUGList - // lazy evaluation would be nice to keep, but really slows things down - label minsize = 1 + offset_ + index_ * packing(); - if (minsize > list_->size_) + // lazy evaluation - return 0 for out-of-range + if (index_ >= list_->size_) { return 0; } -#endif return this->get(); } @@ -365,7 +253,12 @@ inline Foam::PackedList::iterator::iterator : iteratorBase(iter) { - this->validate(); + // avoid going past end() + // eg, iter = iterator(list, Inf) + if (this->index_ > this->list_->size_) + { + this->index_ = this->list_->size_; + } } @@ -377,7 +270,12 @@ inline Foam::PackedList::const_iterator::const_iterator : iteratorBase(iter) { - this->validate(); + // avoid going past end() + // eg, iter = iterator(list, Inf) + if (this->index_ > this->list_->size_) + { + this->index_ = this->list_->size_; + } } @@ -417,7 +315,16 @@ template inline typename Foam::PackedList::iterator& Foam::PackedList::iterator::operator=(const iteratorBase& iter) { - this->seek(iter); + this->list_ = iter.list_; + this->index_ = iter.index_; + + // avoid going past end() + // eg, iter = iterator(list, Inf) + if (this->index_ > this->list_->size_) + { + this->index_ = this->list_->size_; + } + return *this; } @@ -426,7 +333,16 @@ template inline typename Foam::PackedList::const_iterator& Foam::PackedList::const_iterator::operator=(const iteratorBase& iter) { - this->seek(iter); + this->list_ = iter.list_; + this->index_ = iter.index_; + + // avoid going past end() + // eg, iter = iterator(list, Inf) + if (this->index_ > this->list_->size_) + { + this->index_ = this->list_->size_; + } + return *this; } @@ -435,7 +351,7 @@ template inline typename Foam::PackedList::iterator& Foam::PackedList::iterator::operator++() { - this->incr(); + ++this->index_; return *this; } @@ -444,7 +360,7 @@ template inline typename Foam::PackedList::const_iterator& Foam::PackedList::const_iterator::operator++() { - this->incr(); + ++this->index_; return *this; } @@ -454,7 +370,7 @@ inline typename Foam::PackedList::iterator Foam::PackedList::iterator::operator++(int) { iterator old = *this; - this->incr(); + ++this->index_; return old; } @@ -464,7 +380,7 @@ inline typename Foam::PackedList::const_iterator Foam::PackedList::const_iterator::operator++(int) { const_iterator old = *this; - this->incr(); + ++this->index_; return old; } @@ -473,7 +389,7 @@ template inline typename Foam::PackedList::iterator& Foam::PackedList::iterator::operator--() { - this->decr(); + --this->index_; return *this; } @@ -482,7 +398,7 @@ template inline typename Foam::PackedList::const_iterator& Foam::PackedList::const_iterator::operator--() { - this->decr(); + --this->index_; return *this; } @@ -492,7 +408,7 @@ inline typename Foam::PackedList::iterator Foam::PackedList::iterator::operator--(int) { iterator old = *this; - this->decr(); + --this->index_; return old; } @@ -502,7 +418,7 @@ inline typename Foam::PackedList::const_iterator Foam::PackedList::const_iterator::operator--(int) { const_iterator old = *this; - this->decr(); + --this->index_; return old; } @@ -567,7 +483,7 @@ template inline typename Foam::PackedList::iterator Foam::PackedList::end() { - return iterator(this, this->size()); + return iterator(this, size_); } @@ -575,7 +491,7 @@ template inline typename Foam::PackedList::const_iterator Foam::PackedList::end() const { - return const_iterator(this, this->size()); + return const_iterator(this, size_); } @@ -583,7 +499,7 @@ template inline typename Foam::PackedList::const_iterator Foam::PackedList::cend() const { - return const_iterator(this, this->size()); + return const_iterator(this, size_); } @@ -617,20 +533,12 @@ inline void Foam::PackedList::resize // fill new elements or newly exposed elements if (size_) { - // fill value for complete chunks + // fill value for complete segments unsigned int fill = val; if (fill & ~max_value()) { -# ifdef DEBUGList - FatalErrorIn("PackedList::resize(label, const unsigned int)") - << "value " << label(val) - << " out-of-range 0 ... " << label(max_value()) - << " representable by " << nBits << " bits" - << abort(FatalError); -# endif - - // treat overflow as max_value, fill everything + // overflow is max_value, fill everything fill = ~0; } else @@ -641,26 +549,26 @@ inline void Foam::PackedList::resize } } - unsigned begIdx = size_ / packing(); - unsigned begOff = size_ % packing(); - unsigned endIdx = nElem / packing(); + unsigned int seg = size_ / packing(); + unsigned int off = size_ % packing(); - // partial chunk, preserve existing value - if (begOff) + // partial segment, preserve existing value + if (off) { - unsigned int maskOld = maskLower(begOff); + unsigned int maskOld = maskLower(off); - StorageList::operator[](begIdx) &= maskOld; - StorageList::operator[](begIdx) |= ~maskOld & fill; + StorageList::operator[](seg) &= maskOld; + StorageList::operator[](seg) |= ~maskOld & fill; - // continue with the next chunk - begIdx++; + // continue with the next segment + seg++; } + unsigned int endSeg = nElem / packing(); // fill in complete elements - while (begIdx < endIdx) + while (seg < endSeg) { - StorageList::operator[](begIdx++) = fill; + StorageList::operator[](seg++) = fill; } } else @@ -786,17 +694,31 @@ Foam::PackedList::xfer() template inline unsigned int Foam::PackedList::get(const label i) const { -# ifdef DEBUGList - checkIndex(i); +# ifdef FULLDEBUG + if (i < 0) + { + FatalErrorIn("PackedList::get(const label)") + << "negative index " << i << " max=" << size_-1 + << abort(FatalError); + } # endif - return iteratorBase(this, i).get(); + // lazy evaluation - return 0 for out-of-range + if (i < size_) + { + return iteratorBase(this, i).get(); + } + else + { + return 0; + } } template inline unsigned int Foam::PackedList::operator[](const label i) const { + // lazy evaluation - return 0 for out-of-range if (i < size_) { return iteratorBase(this, i).get(); @@ -815,18 +737,21 @@ inline bool Foam::PackedList::set const unsigned int val ) { -# ifdef DEBUGList - checkIndex(i); - - if (val & ~max_value()) +# ifdef FULLDEBUG + if (i < 0) { - FatalErrorIn("PackedList::set(const label, const unsigned int)") - << "value " << label(val) - << " out-of-range 0 ... " << label(max_value()) - << " representable by " << nBits << " bits" + FatalErrorIn("PackedList::set(const label)") + << "negative index " << i << " max=" << size_-1 << abort(FatalError); } -# endif +#endif + + // lazy evaluation - increase size on assigment + if (i >= size_) + { + resize(i + 1); + } + return iteratorBase(this, i).set(val); } @@ -879,14 +804,6 @@ inline void Foam::PackedList::operator=(const unsigned int val) if (fill & ~max_value()) { -# ifdef DEBUGList - FatalErrorIn("PackedList::operator=(const unsigned int)") - << "value " << label(val) - << " out-of-range 0 ... " << label(max_value()) - << " representable by " << nBits << " bits" - << abort(FatalError); -# endif - // treat overflow as max_value fill = ~0; } From fe6a83a3a8c84f4078ff3d0e7a8be803d73440d3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 30 Jan 2009 09:06:47 +0100 Subject: [PATCH 02/20] moved fileName::IOobjectComponents -> IOobject::fileNameComponents --- applications/test/fileName/fileNameTest.C | 14 +-- src/OpenFOAM/db/IOobject/IOobject.C | 89 ++++++++++++++++++- src/OpenFOAM/db/IOobject/IOobject.H | 16 +++- .../primitives/strings/fileName/fileName.C | 88 ------------------ .../primitives/strings/fileName/fileName.H | 9 -- 5 files changed, 111 insertions(+), 105 deletions(-) diff --git a/applications/test/fileName/fileNameTest.C b/applications/test/fileName/fileNameTest.C index f5a4a93542..c4791f6f38 100644 --- a/applications/test/fileName/fileNameTest.C +++ b/applications/test/fileName/fileNameTest.C @@ -32,6 +32,7 @@ Description #include "fileName.H" #include "SubList.H" +#include "IOobject.H" #include "IOstreams.H" #include "OSspecific.H" @@ -61,7 +62,8 @@ int main() << endl; // try with different combination - for (label start = 0; start < wrdList.size(); ++start) + // The final one should emit warnings + for (label start = 0; start <= wrdList.size(); ++start) { fileName instance, local; word name; @@ -69,26 +71,28 @@ int main() fileName path(SubList(wrdList, wrdList.size()-start, start)); fileName path2 = "." / path; - path.IOobjectComponents + IOobject::fileNameComponents ( + path, instance, local, name ); - Info<< "IOobjectComponents for " << path << nl + Info<< "IOobject::fileNameComponents for " << path << nl << " instance = " << instance << nl << " local = " << local << nl << " name = " << name << endl; - path2.IOobjectComponents + IOobject::fileNameComponents ( + path2, instance, local, name ); - Info<< "IOobjectComponents for " << path2 << nl + Info<< "IOobject::fileNameComponents for " << path2 << nl << " instance = " << instance << nl << " local = " << local << nl << " name = " << name << endl; diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index fc1c023874..1883f773b9 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -35,6 +35,85 @@ namespace Foam defineTypeNameAndDebug(IOobject, 0); } +// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // + +// Return components following the IOobject requirements +// +// behaviour +// input IOobject(instance, local, name) +// ----- ------ +// "foo" ("", "", "foo") +// "foo/bar" ("foo", "", "bar") +// "/XXX" ERROR - no absolute path +// "foo/bar/" ERROR - no name +// "foo/xxx/bar" ("foo", "xxx", "bar") +// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar") +bool Foam::IOobject::IOobject::fileNameComponents +( + const fileName& path, + fileName& instance, + fileName& local, + word& name +) +{ + instance.clear(); + local.clear(); + name.clear(); + + // called with directory + if (::Foam::dir(path)) + { + WarningIn("IOobject::fileNameComponents(const fileName&, ...)") + << " called with directory: " << path << "\n"; + return false; + } + + string::size_type first = path.find('/'); + + if (first == 0) + { + // called with absolute path + WarningIn("IOobject::fileNameComponents(const fileName&, ...)") + << "called with absolute path: " << path << "\n"; + return false; + } + + if (first == string::npos) + { + // no '/' found - no instance or local + + // check afterwards + name.string::operator=(path); + } + else + { + instance = path.substr(0, first); + + string::size_type last = path.rfind('/'); + if (last > first) + { + // with local + local = path.substr(first+1, last-first-1); + } + + // check afterwards + name.string::operator=(path.substr(last+1)); + } + + + // check for valid (and stripped) name, regardless of the debug level + if (name.empty() || string::stripInvalid(name)) + { + WarningIn("IOobject::fileNameComponents(const fileName&, ...)") + << "has invalid word for name: \"" << name + << "\"\nwhile processing path: " << path << "\n"; + return false; + } + + return true; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::IOobject::IOobject @@ -118,7 +197,15 @@ Foam::IOobject::IOobject registerObject_(registerObject), objState_(GOOD) { - path.IOobjectComponents(instance_, local_, name_); + if (!fileNameComponents(path, instance_, local_, name_)) + { + FatalErrorIn + ( + "IOobject::IOobject" "(const fileName&, const objectRegistry&, ...)" + ) + << " invalid path specification\n" + << exit(FatalError); + } if (objectRegistry::debug) { diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 6ee171423a..5559a2295a 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -149,7 +149,6 @@ private: //- IOobject state objectState objState_; - protected: // Protected member functions @@ -168,6 +167,18 @@ public: TypeName("IOobject"); + // Static Member Functions + + //- Split path into instance, local, name components + static bool fileNameComponents + ( + const fileName& path, + fileName& instance, + fileName& local, + word& name + ); + + // Constructors //- Construct from name, instance, registry, io options @@ -194,6 +205,7 @@ public: ); //- Construct from path, registry, io options + // Uses fileNameComponents() to split path into components. IOobject ( const fileName& path, @@ -215,7 +227,7 @@ public: virtual ~IOobject(); - // Member functions + // Member Functions // General access diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 3f41e9e692..50d8a29947 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -212,94 +212,6 @@ Foam::word Foam::fileName::component } - -// Return components following the IOobject requirements -// -// behaviour -// input IOobject(instance, local, name) -// ----- ------ -// "foo" ("", "", "foo") -// "foo/bar" ("foo", "", "bar") -// "/XXX" ERROR - no absolute path -// "foo/bar/" ERROR - no name -// "foo/xxx/bar" ("foo", "xxx", "bar") -// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar") -bool Foam::fileName::IOobjectComponents -( - fileName& instance, - fileName& local, - word& name -) -const -{ - instance.clear(); - local.clear(); - name.clear(); - - // called with directory - if (::Foam::dir(*this)) - { - std::cerr - << "fileName::IOobjectComponents() called with directory: " - << this->c_str() << std::endl; - std::abort(); - - return false; - } - - size_type first = find('/'); - - if (first == 0) - { - // called with absolute path - std::cerr - << "fileName::IOobjectComponents() called with absolute path: " - << this->c_str() << std::endl; - std::abort(); - - return false; - } - - if (first == npos) - { - // no '/' found - no instance or local - - // check afterwards - name.string::operator=(*this); - } - else - { - instance = substr(0, first); - - size_type last = rfind('/'); - if (last > first) - { - // with local - local = substr(first+1, last-first-1); - } - - // check afterwards - name.string::operator=(substr(last+1)); - } - - - // check for valid (and stripped) name, regardless of the debug level - if (name.empty() || string::stripInvalid(name)) - { - std::cerr - << "fileName::IOobjectComponents() has invalid word for name: " - << name.c_str() << "\nwhile processing " - << this->c_str() << std::endl; - std::abort(); - - return false; - } - - return true; -} - - - // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // void Foam::fileName::operator=(const fileName& str) diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 0eeb89312e..a8312df3f6 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -163,15 +163,6 @@ public: //- Return a single component of the path word component(const size_type, const char delimiter='/') const; - //- Return path as instance, local, name components for IOobject - bool IOobjectComponents - ( - fileName& instance, - fileName& local, - word& name - ) const; - - // Member operators // Assignment From e5c58292440bc8f5d3836dd99680a2f2b927fa63 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 2 Feb 2009 16:50:18 +0100 Subject: [PATCH 03/20] OSspecific: isDir(), isFile() instead of dir(), file() --- .../decomposePar/decomposePar.C | 4 +- .../reconstructPar/reconstructPar.C | 4 +- .../redistributeMeshPar/redistributeMeshPar.C | 4 +- .../foamToEnsight/foamToEnsight.C | 2 +- .../foamToEnsightParts/foamToEnsightParts.C | 4 +- .../foamToFieldview9/foamToFieldview9.C | 6 +-- .../dataConversion/foamToVTK/foamToVTK.C | 2 +- .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C | 4 +- .../graphics/PVFoamReader/vtkFoam/vtkFoam.C | 8 ++-- .../ensightFoamReader/USERD_set_filenames.H | 6 +-- .../fieldview9Reader/fieldview9Reader.C | 6 +-- .../postProcessing/velocityField/Mach/Mach.C | 2 +- src/OSspecific/Unix/Unix.C | 40 +++++++++---------- src/OpenFOAM/db/IOobject/IOobject.C | 10 ++--- src/OpenFOAM/db/IOobjectList/IOobjectList.C | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C | 4 +- src/OpenFOAM/db/Time/findInstance.C | 6 +-- src/OpenFOAM/global/JobInfo/JobInfo.C | 4 +- src/OpenFOAM/global/argList/argList.C | 6 +-- src/OpenFOAM/include/OSspecific.H | 18 ++++----- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 2 +- .../primitives/strings/fileName/fileName.C | 4 +- src/finiteVolume/fvMesh/fvMesh.C | 4 +- .../searchableSurface/triSurfaceMesh.C | 2 +- .../surfaceFormats/stl/STLsurfaceFormatCore.C | 1 + .../surfaceFormats/stl/STLsurfaceFormatCore.H | 1 - .../surfaceFormats/surfaceFormatsCore.C | 4 +- .../triSurface/interfaces/STL/readSTLBINARY.C | 2 +- src/triSurface/triSurface/triSurface.C | 2 +- 30 files changed, 85 insertions(+), 85 deletions(-) diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index b6eaf39258..a7328cb487 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) // determine the existing processor count directly label nProcs = 0; - while (dir(runTime.path()/(word("processor") + name(nProcs)))) + while (isDir(runTime.path()/(word("processor") + name(nProcs)))) { ++nProcs; } @@ -480,7 +480,7 @@ int main(int argc, char *argv[]) // Any uniform data to copy/link? fileName uniformDir("uniform"); - if (dir(runTime.timePath()/uniformDir)) + if (isDir(runTime.timePath()/uniformDir)) { Info<< "Detected additional non-decomposed files in " << runTime.timePath()/uniformDir diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index ac08b17645..20def06b9c 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) // determine the processor count directly label nProcs = 0; - while (dir(args.path()/(word("processor") + name(nProcs)))) + while (isDir(args.path()/(word("processor") + name(nProcs)))) { ++nProcs; } @@ -383,7 +383,7 @@ int main(int argc, char *argv[]) // the master processor. fileName uniformDir0 = databases[0].timePath()/"uniform"; - if (dir(uniformDir0)) + if (isDir(uniformDir0)) { cp(uniformDir0, runTime.timePath()); } diff --git a/applications/utilities/parallelProcessing/redistributeMeshPar/redistributeMeshPar.C b/applications/utilities/parallelProcessing/redistributeMeshPar/redistributeMeshPar.C index 379dd70b91..c46a41b273 100644 --- a/applications/utilities/parallelProcessing/redistributeMeshPar/redistributeMeshPar.C +++ b/applications/utilities/parallelProcessing/redistributeMeshPar/redistributeMeshPar.C @@ -503,7 +503,7 @@ int main(int argc, char *argv[]) # include "setRootCase.H" // Create processor directory if non-existing - if (!Pstream::master() && !dir(args.path())) + if (!Pstream::master() && !isDir(args.path())) { Pout<< "Creating case directory " << args.path() << endl; mkDir(args.path()); @@ -525,7 +525,7 @@ int main(int argc, char *argv[]) const fileName meshDir = runTime.path()/masterInstDir/polyMesh::meshSubDir; boolList haveMesh(Pstream::nProcs(), false); - haveMesh[Pstream::myProcNo()] = dir(meshDir); + haveMesh[Pstream::myProcNo()] = isDir(meshDir); Pstream::gatherList(haveMesh); Pstream::scatterList(haveMesh); Info<< "Per processor mesh availability : " << haveMesh << endl; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 8fc7636f2a..bb7c1880f0 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) if (Pstream::master()) { - if (dir(postProcPath)) + if (isDir(postProcPath)) { rmDir(postProcPath); } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C index 1d31a4e31c..329dda87f9 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) // Ensight and Ensight/data directories must exist // do not remove old data - we might wish to convert new results // or a particular time interval - if (dir(ensightDir)) + if (isDir(ensightDir)) { Info<<"Warning: reusing existing directory" << nl << " " << ensightDir << endl; @@ -324,7 +324,7 @@ int main(int argc, char *argv[]) { const word& cloudName = cloudIter.key(); - if (!dir(runTime.timePath()/regionPrefix/"lagrangian"/cloudName)) + if (!isDir(runTime.timePath()/regionPrefix/"lagrangian"/cloudName)) { continue; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C index 81ac4facac..7fc54a8cf2 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C +++ b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C @@ -260,7 +260,7 @@ int main(int argc, char *argv[]) // make a directory called FieldView in the case fileName fvPath(runTime.path()/"Fieldview"); - if (dir(fvPath)) + if (isDir(fvPath)) { rmDir(fvPath); } @@ -346,7 +346,7 @@ int main(int argc, char *argv[]) // Output the magic number. writeInt(fvFile, FV_MAGIC); - + // Output file header and version number. writeStr80(fvFile, "FIELDVIEW"); @@ -417,7 +417,7 @@ int main(int argc, char *argv[]) { if (volFieldPtrs[fieldI] == NULL) { - Info<< " dummy field for " + Info<< " dummy field for " << volFieldNames[fieldI].c_str() << endl; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index 45c5f37996..e03c76c057 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -333,7 +333,7 @@ int main(int argc, char *argv[]) regionPrefix = regionName; } - if (dir(fvPath)) + if (isDir(fvPath)) { if ( diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C index 779cddac39..7a8fd89e9e 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C @@ -228,7 +228,7 @@ Foam::vtkPV3Foam::vtkPV3Foam // avoid argList and get rootPath/caseName directly from the file fileName fullCasePath(fileName(FileName).path()); - if (!dir(fullCasePath)) + if (!isDir(fullCasePath)) { return; } @@ -518,7 +518,7 @@ double* Foam::vtkPV3Foam::findTimes(int& nTimeSteps) if ( - file(runTime.path()/timeName/meshDir_/"points") + isFile(runTime.path()/timeName/meshDir_/"points") && IOobject("points", timeName, meshDir_, runTime).headerOk() ) { diff --git a/applications/utilities/postProcessing/graphics/PVFoamReader/vtkFoam/vtkFoam.C b/applications/utilities/postProcessing/graphics/PVFoamReader/vtkFoam/vtkFoam.C index 6d6eef9b5f..6a1830b5d1 100644 --- a/applications/utilities/postProcessing/graphics/PVFoamReader/vtkFoam/vtkFoam.C +++ b/applications/utilities/postProcessing/graphics/PVFoamReader/vtkFoam/vtkFoam.C @@ -194,7 +194,7 @@ void Foam::vtkFoam::updateSelectedRegions() // Read the selected patches and add to the region list for (int i=0; iGetRegionSelection()->GetArraySetting(i); } } @@ -282,7 +282,7 @@ void Foam::vtkFoam::convertMesh() else { // A patch already existent in the list and which - // continues to exist found + // continues to exist found regioni++; } } @@ -391,7 +391,7 @@ Foam::vtkFoam::vtkFoam(const char* const FileName, vtkFoamReader* reader) { fileName fullCasePath(fileName(FileName).path()); - if (!dir(fullCasePath)) + if (!isDir(fullCasePath)) { return; } @@ -572,7 +572,7 @@ void Foam::vtkFoam::Update() { Info<< "Reading Mesh" << endl; } - meshPtr_ = + meshPtr_ = new fvMesh ( IOobject diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H index f01839a930..90f2d3f415 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H @@ -47,7 +47,7 @@ int USERD_set_filenames } caseDir = tmp; - if (!dir(rootDir/caseDir)) + if (!isDir(rootDir/caseDir)) { Info<< rootDir/caseDir << " is not a valid directory." << endl; @@ -144,7 +144,7 @@ int USERD_set_filenames } isTensor[n] = isitTensor; } - + bool lagrangianNamesFound = false; label n = 0; while (!lagrangianNamesFound && n < Num_time_steps) @@ -176,7 +176,7 @@ int USERD_set_filenames Info << "[Found lagrangian]" << endl; delete sprayPtr; - + sprayPtr = new Cloud(*meshPtr); IOobjectList objects(*meshPtr, runTime.timeName(), "lagrangian"); diff --git a/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C b/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C index 10b29fc8b3..11fd038f16 100644 --- a/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C +++ b/applications/utilities/postProcessing/graphics/fieldview9Reader/fieldview9Reader.C @@ -132,8 +132,8 @@ static void errorMsg(const string& msg) // Simple check if directory is valid case directory. static bool validCase(const fileName& rootAndCase) { - //if (dir(rootAndCase/"system") && dir(rootAndCase/"constant")) - if (dir(rootAndCase/"constant")) + //if (isDir(rootAndCase/"system") && isDir(rootAndCase/"constant")) + if (isDir(rootAndCase/"constant")) { return true; } @@ -528,7 +528,7 @@ void user_query_file_function return; } - + } fileName rootDir(rootAndCase.path()); diff --git a/applications/utilities/postProcessing/velocityField/Mach/Mach.C b/applications/utilities/postProcessing/velocityField/Mach/Mach.C index 917a53668f..02c69df34a 100644 --- a/applications/utilities/postProcessing/velocityField/Mach/Mach.C +++ b/applications/utilities/postProcessing/velocityField/Mach/Mach.C @@ -63,7 +63,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh) volVectorField U(Uheader, mesh); - if (file(runTime.constantPath()/"thermophysicalProperties")) + if (isFile(runTime.constantPath()/"thermophysicalProperties")) { // thermophysical Mach autoPtr thermo diff --git a/src/OSspecific/Unix/Unix.C b/src/OSspecific/Unix/Unix.C index c3479810d4..ee6fa81888 100644 --- a/src/OSspecific/Unix/Unix.C +++ b/src/OSspecific/Unix/Unix.C @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description - UNIX versions of the functions declared in OSspecific.H. + UNIX versions of the functions declared in OSspecific.H \*---------------------------------------------------------------------------*/ @@ -218,7 +218,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) // Search user files: // ~~~~~~~~~~~~~~~~~~ fileName searchDir = home()/".OpenFOAM"; - if (dir(searchDir)) + if (isDir(searchDir)) { // Check for user file in ~/.OpenFOAM/VERSION fileName fullName = searchDir/FOAMversion/name; @@ -239,7 +239,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) // Search site files: // ~~~~~~~~~~~~~~~~~~ searchDir = getEnv("WM_PROJECT_INST_DIR"); - if (dir(searchDir)) + if (isDir(searchDir)) { // Check for site file in $WM_PROJECT_INST_DIR/site/VERSION fileName fullName = searchDir/"site"/FOAMversion/name; @@ -259,7 +259,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) // Search installation files: // ~~~~~~~~~~~~~~~~~~~~~~~~~~ searchDir = getEnv("WM_PROJECT_DIR"); - if (dir(searchDir)) + if (isDir(searchDir)) { // Check for shipped OpenFOAM file in $WM_PROJECT_DIR/etc fileName fullName = searchDir/"etc"/name; @@ -476,24 +476,24 @@ Foam::fileName::Type Foam::type(const fileName& name) // Does the name exist in the filing system? bool Foam::exists(const fileName& name) { - return mode(name) || file(name); -} - - -// Does the file exist -bool Foam::file(const fileName& name) -{ - return S_ISREG(mode(name)) || S_ISREG(mode(name + ".gz")); + return mode(name) || isFile(name); } // Does the directory exist -bool Foam::dir(const fileName& name) +bool Foam::isDir(const fileName& name) { return S_ISDIR(mode(name)); } +// Does the file exist +bool Foam::isFile(const fileName& name) +{ + return S_ISREG(mode(name)) || S_ISREG(mode(name + ".gz")); +} + + // Return size of file off_t Foam::fileSize(const fileName& name) { @@ -641,7 +641,7 @@ bool Foam::cp(const fileName& src, const fileName& dest) } // Make sure the destination directory exists. - if (!dir(destFile.path()) && !mkDir(destFile.path())) + if (!isDir(destFile.path()) && !mkDir(destFile.path())) { return false; } @@ -681,7 +681,7 @@ bool Foam::cp(const fileName& src, const fileName& dest) } // Make sure the destination directory exists. - if (!dir(destFile) && !mkDir(destFile)) + if (!isDir(destFile) && !mkDir(destFile)) { return false; } @@ -806,7 +806,7 @@ bool Foam::rmDir(const fileName& directory) { if (Unix::debug) { - Info<< "rmdir(const fileName&) : " + Info<< "rmDir(const fileName&) : " << "removing directory " << directory << endl; } @@ -817,7 +817,7 @@ bool Foam::rmDir(const fileName& directory) // Attempt to open directory and set the structure pointer if ((source = opendir(directory.c_str())) == NULL) { - WarningIn("rmdir(const fileName&)") + WarningIn("rmDir(const fileName&)") << "cannot open directory " << directory << endl; return false; @@ -837,7 +837,7 @@ bool Foam::rmDir(const fileName& directory) { if (!rmDir(path)) { - WarningIn("rmdir(const fileName&)") + WarningIn("rmDir(const fileName&)") << "failed to remove directory " << fName << " while removing directory " << directory << endl; @@ -851,7 +851,7 @@ bool Foam::rmDir(const fileName& directory) { if (!rm(path)) { - WarningIn("rmdir(const fileName&)") + WarningIn("rmDir(const fileName&)") << "failed to remove file " << fName << " while removing directory " << directory << endl; @@ -867,7 +867,7 @@ bool Foam::rmDir(const fileName& directory) if (!rm(directory)) { - WarningIn("rmdir(const fileName&)") + WarningIn("rmDir(const fileName&)") << "failed to remove directory " << directory << endl; closedir(source); diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 1883f773b9..dc80008633 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -61,7 +61,7 @@ bool Foam::IOobject::IOobject::fileNameComponents name.clear(); // called with directory - if (::Foam::dir(path)) + if (::Foam::isDir(path)) { WarningIn("IOobject::fileNameComponents(const fileName&, ...)") << " called with directory: " << path << "\n"; @@ -269,7 +269,7 @@ Foam::fileName Foam::IOobject::filePath() const fileName path = this->path(); fileName objectPath = path/name(); - if (file(objectPath)) + if (isFile(objectPath)) { return objectPath; } @@ -288,13 +288,13 @@ Foam::fileName Foam::IOobject::filePath() const rootPath()/caseName() /".."/instance()/db_.dbDir()/local()/name(); - if (file(parentObjectPath)) + if (isFile(parentObjectPath)) { return parentObjectPath; } } - if (!dir(path)) + if (!isDir(path)) { word newInstancePath = time().findInstancePath(instant(instance())); @@ -306,7 +306,7 @@ Foam::fileName Foam::IOobject::filePath() const /newInstancePath/db_.dbDir()/local()/name() ); - if (file(fName)) + if (isFile(fName)) { return fName; } diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index 9f923d8fce..a55f68a425 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -48,7 +48,7 @@ Foam::IOobjectList::IOobjectList { word newInstance = instance; - if (!dir(db.path(instance))) + if (!isDir(db.path(instance))) { newInstance = db.time().findInstancePath(instant(instance)); @@ -59,7 +59,7 @@ Foam::IOobjectList::IOobjectList } // Create list file names in directory - fileNameList ObjectNames = + fileNameList ObjectNames = readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE); forAll(ObjectNames, i) diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index b4be5d37fe..efeb792267 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -54,7 +54,7 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) ifPtr_ = new ifstream(pathname.c_str()); // If the file is compressed, decompress it before reading. - if (!ifPtr_->good() && file(pathname + ".gz")) + if (!ifPtr_->good() && isFile(pathname + ".gz")) { if (IFstream::debug) { @@ -159,7 +159,7 @@ Foam::IFstream& Foam::IFstream::operator()() const { if (!good()) { - if (!file(pathname_) && !file(pathname_ + ".gz")) + if (!isFile(pathname_) && !isFile(pathname_ + ".gz")) { FatalIOErrorIn("IFstream::operator()", *this) << "file " << pathname_ << " does not exist" diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index bc6c2a03cc..2b5849d2e7 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -57,7 +57,7 @@ Foam::OFstreamAllocator::OFstreamAllocator if (compression == IOstream::COMPRESSED) { - if (file(pathname)) + if (isFile(pathname)) { rm(pathname); } @@ -66,7 +66,7 @@ Foam::OFstreamAllocator::OFstreamAllocator } else { - if (file(pathname + ".gz")) + if (isFile(pathname + ".gz")) { rm(pathname + ".gz"); } diff --git a/src/OpenFOAM/db/Time/findInstance.C b/src/OpenFOAM/db/Time/findInstance.C index 348ad4ebe5..d3d475cec3 100644 --- a/src/OpenFOAM/db/Time/findInstance.C +++ b/src/OpenFOAM/db/Time/findInstance.C @@ -43,7 +43,7 @@ Foam::word Foam::Time::findInstance // Is the mesh data in the current time directory ? if ( - file(path()/timeName()/dir/name) + isFile(path()/timeName()/dir/name) && IOobject(name, timeName(), dir, *this).headerOk() ) { @@ -81,7 +81,7 @@ Foam::word Foam::Time::findInstance { if ( - file(path()/ts[j].name()/dir/name) + isFile(path()/ts[j].name()/dir/name) && IOobject(name, ts[j].name(), dir, *this).headerOk() ) { @@ -109,7 +109,7 @@ Foam::word Foam::Time::findInstance if ( - file(path()/constant()/dir/name) + isFile(path()/constant()/dir/name) && IOobject(name, constant(), dir, *this).headerOk() ) { diff --git a/src/OpenFOAM/global/JobInfo/JobInfo.C b/src/OpenFOAM/global/JobInfo/JobInfo.C index f1e8021603..e07b6ab271 100644 --- a/src/OpenFOAM/global/JobInfo/JobInfo.C +++ b/src/OpenFOAM/global/JobInfo/JobInfo.C @@ -65,14 +65,14 @@ Foam::JobInfo::JobInfo() << Foam::exit(FatalError); } - if (!dir(runningDir) && !mkDir(runningDir)) + if (!isDir(runningDir) && !mkDir(runningDir)) { FatalErrorIn("JobInfo::JobInfo()") << "Cannot make JobInfo directory " << runningDir << Foam::exit(FatalError); } - if (!dir(finishedDir) && !mkDir(finishedDir)) + if (!isDir(finishedDir) && !mkDir(finishedDir)) { FatalErrorIn("JobInfo::JobInfo()") << "Cannot make JobInfo directory " << finishedDir diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index a237c0256c..4384a7ea41 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -409,7 +409,7 @@ Foam::argList::argList label nProcDirs = 0; while ( - dir + isDir ( rootPath_/globalCase_/"processor" + name(++nProcDirs) @@ -697,7 +697,7 @@ bool Foam::argList::check(bool checkArgs, bool checkOpts) const bool Foam::argList::checkRootCase() const { - if (!dir(rootPath())) + if (!isDir(rootPath())) { FatalError << executable_ @@ -707,7 +707,7 @@ bool Foam::argList::checkRootCase() const return false; } - if (!dir(path()) && Pstream::master()) + if (!isDir(path()) && Pstream::master()) { // Allow slaves on non-existing processor directories, created later FatalError diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 4594f6eff8..1b434670b8 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -63,7 +63,7 @@ bool env(const word&); //- Return environment variable of given name // Return string() if the environment is undefined -string getEnv(const word& name); +string getEnv(const word&); //- Set an environment variable bool setEnv(const word& name, const string& value, const bool overwrite); @@ -103,7 +103,7 @@ bool chDir(const fileName& dir); // // @return the full path name or fileName() if the name cannot be found // Optionally abort if the file cannot be found -fileName findEtcFile(const fileName& name, bool mandatory=false); +fileName findEtcFile(const fileName&, bool mandatory=false); //- Make a directory and return an error if it could not be created // and does not already exist @@ -119,13 +119,13 @@ mode_t mode(const fileName&); fileName::Type type(const fileName&); //- Does the name exist in the file system? -bool exists(const fileName& name); +bool exists(const fileName&); -//- Does the file exist? -bool file(const fileName&); +//- Does the name exist as a FILE in the file system? +bool isFile(const fileName&); -//- Does the directory exist? -bool dir(const fileName&); +//- Does the name exist as a DIRECTORY in the file system? +bool isDir(const fileName&); //- Return size of file off_t fileSize(const fileName&); @@ -165,10 +165,10 @@ void fdClose(const int); //- Check if machine is up by pinging given port bool ping(const word&, const label port, const label timeOut); -//- Check if machine is up by ping port 22 = ssh and 222 = rsh +//- Check if machine is up by pinging port 22 (ssh) and 222 (rsh) bool ping(const word&, const label timeOut=10); -//- Executes a command specified in command +//- Execute the specified command int system(const string& command); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index c3a789e54d..0428b252d7 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -1103,7 +1103,7 @@ void Foam::polyMesh::removeFiles(const fileName& instanceDir) const rm(meshFilesPath/"parallelData"); // remove subdirectories - if (dir(meshFilesPath/"sets")) + if (isDir(meshFilesPath/"sets")) { rmDir(meshFilesPath/"sets"); } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 50d8a29947..4e6c2c6423 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -63,13 +63,13 @@ bool Foam::fileName::exists() const bool Foam::fileName::isDir() const { - return ::Foam::dir(*this); + return ::Foam::isDir(*this); } bool Foam::fileName::isFile() const { - return ::Foam::file(*this); + return ::Foam::isFile(*this); } diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index d9c775a68b..aebecfefe9 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -162,7 +162,7 @@ Foam::fvMesh::fvMesh(const IOobject& io) // Check the existance of the cell volumes and read if present // and set the storage of V00 - if (file(time().timePath()/"V0")) + if (isFile(time().timePath()/"V0")) { V0Ptr_ = new DimensionedField ( @@ -182,7 +182,7 @@ Foam::fvMesh::fvMesh(const IOobject& io) // Check the existance of the mesh fluxes, read if present and set the // mesh to be moving - if (file(time().timePath()/"meshPhi")) + if (isFile(time().timePath()/"meshPhi")) { phiPtr_ = new surfaceScalarField ( diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index ad8ffc5927..b5e3e0f572 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -562,7 +562,7 @@ bool Foam::triSurfaceMesh::writeObject triSurface::write(fullPath); - if (!file(fullPath)) + if (!isFile(fullPath)) { return false; } diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C index afe81aebac..af262c6c1d 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C @@ -25,6 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "STLsurfaceFormatCore.H" +#include "gzstream.h" #include "OSspecific.H" #include "Map.H" diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H index 56607fa0a0..3bf0d7ba27 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H @@ -39,7 +39,6 @@ SourceFiles #include "STLtriangle.H" #include "triFace.H" -#include "gzstream.h" #include "IFstream.H" #include "Ostream.H" #include "OFstream.H" diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C index 3552d4f404..277ba8d4c4 100644 --- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C +++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C @@ -91,7 +91,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshInstance { for (label i = instanceI; i >= 0; --i) { - if (file(d.path()/ts[i].name()/subdirName/foamName)) + if (isFile(d.path()/ts[i].name()/subdirName/foamName)) { return ts[i].name(); } @@ -134,7 +134,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshName { fileName testName(d.path()/ts[i].name()/subdirName/foamName); - if (file(testName)) + if (isFile(testName)) { return testName; } diff --git a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C b/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C index 4c7c9e859a..1bdc059a80 100644 --- a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C +++ b/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C @@ -48,7 +48,7 @@ bool triSurface::readSTLBINARY(const fileName& STLfileName) new ifstream(STLfileName.c_str(), std::ios::binary) ); // If the file is compressed, decompress it before reading. - if (!STLfilePtr->good() && file(STLfileName + ".gz")) + if (!STLfilePtr->good() && isFile(STLfileName + ".gz")) { compressed = true; STLfilePtr.reset(new igzstream((STLfileName + ".gz").c_str())); diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index e589ec6158..2eee0bb858 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -67,7 +67,7 @@ Foam::fileName Foam::triSurface::triSurfInstance(const Time& d) { for (label j=i; j>=0; j--) { - if (file(d.path()/ts[j].name()/typeName/foamName)) + if (isFile(d.path()/ts[j].name()/typeName/foamName)) { if (debug) { From 05440dd4a07190f0b382ddf92c207e235fc1aa00 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 2 Feb 2009 16:57:50 +0100 Subject: [PATCH 04/20] updated surfaceCoordinateSystemTransform --- .../surfaceCoordinateSystemTransform.C | 104 ++++++++++-------- 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C b/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C index cabebafc56..f0578f4ab2 100644 --- a/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C +++ b/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C @@ -34,17 +34,23 @@ Usage - surfaceMeshCoordinateSystemTransform inputFile outputFile [OPTION] @param -clean \n - Perform some surface checking/cleanup on the input surface + Perform some surface checking/cleanup on the input surface. - @param -scale \ \n - Specify a scaling factor for writing the files + @param -scaleIn \ \n + Specify a scaling factor when reading files. - @param -triSurface \n - Use triSurface library for input/output + @param -scaleOut \ \n + Specify a scaling factor when writing files. @param -dict \ \n Specify an alternative dictionary for coordinateSystems. + @param -from \ \n + Specify a coordinate System when reading files. + + @param -to \ \n + Specify a coordinate System when writing files. + Note The filename extensions are used to determine the file format type. @@ -55,7 +61,6 @@ Note #include "Time.H" #include "MeshedSurfaces.H" -#include "UnsortedMeshedSurfaces.H" #include "coordinateSystems.H" using namespace Foam; @@ -68,18 +73,40 @@ int main(int argc, char *argv[]) argList::noParallel(); argList::validArgs.append("inputFile"); argList::validArgs.append("outputFile"); - argList::validOptions.insert("scale", "scale"); - argList::validOptions.insert("unsorted", ""); + argList::validOptions.insert("clean", "scale"); + argList::validOptions.insert("scaleIn", "scale"); + argList::validOptions.insert("scaleOut", "scale"); + argList::validOptions.insert("dict", "coordinateSystemsDict"); argList::validOptions.insert("from", "sourceCoordinateSystem"); - argList::validOptions.insert("to", "targetCoordinateSystem"); - argList::validOptions.insert("dict", "dictionary"); + argList::validOptions.insert("to", "targetCoordinateSystem"); argList args(argc, argv); Time runTime(args.rootPath(), args.caseName()); const stringList& params = args.additionalArgs(); - const word dictName("coordinateSystems"); + fileName importName(params[0]); + fileName exportName(params[1]); + // disable inplace editing + if (importName == exportName) + { + FatalErrorIn(args.executable()) + << "Output file " << exportName << " would overwrite input file." + << exit(FatalError); + } + + // check that reading/writing is supported + if + ( + !MeshedSurface::canRead(importName, true) + || !MeshedSurface::canWriteType(exportName.ext(), true) + ) + { + return 1; + } + + + // get the coordinate transformations autoPtr fromCsys; autoPtr toCsys; @@ -95,7 +122,7 @@ int main(int argc, char *argv[]) ( new IOobject ( - ( dictPath.isDir() ? dictPath/dictName : dictPath ), + ( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ), runTime, IOobject::MUST_READ, IOobject::NO_WRITE, @@ -109,7 +136,7 @@ int main(int argc, char *argv[]) ( new IOobject ( - dictName, + coordinateSystems::typeName, runTime.constant(), runTime, IOobject::MUST_READ, @@ -167,34 +194,20 @@ int main(int argc, char *argv[]) if (fromCsys.valid() && toCsys.valid()) { FatalErrorIn(args.executable()) - << "Only allowed -from or -to option at the moment." + << "Only allowed '-from' or '-to' option at the moment." << exit(FatalError); } } - scalar scaleFactor = 0; - if (args.options().found("scale")) + scalar scaleIn = 0; + scalar scaleOut = 0; + if (args.options().found("scaleIn")) { - IStringStream(args.options()["scale"])() >> scaleFactor; + IStringStream(args.options()["scaleIn"])() >> scaleIn; } - - fileName importName(params[0]); - fileName exportName(params[1]); - - if (importName == exportName) + if (args.options().found("scaleOut")) { - FatalErrorIn(args.executable()) - << "Output file " << exportName << " would overwrite input file." - << exit(FatalError); - } - - if - ( - !meshedSurface::canRead(importName, true) - || !meshedSurface::canWriteType(exportName.ext(), true) - ) - { - return 1; + IStringStream(args.options()["scaleOut"])() >> scaleOut; } @@ -206,28 +219,33 @@ int main(int argc, char *argv[]) surf.cleanup(true); } + if (scaleIn > 0) + { + Info<< " -scaleIn " << scaleIn << endl; + surf.scalePoints(scaleIn); + } + if (fromCsys.valid()) { + Info<< " -from " << fromCsys().name() << endl; tmp tpf = fromCsys().localPosition(surf.points()); surf.movePoints(tpf()); } if (toCsys.valid()) { + Info<< " -to " << toCsys().name() << endl; tmp tpf = toCsys().globalPosition(surf.points()); surf.movePoints(tpf()); } + if (scaleOut > 0) + { + Info<< " -scaleOut " << scaleOut << endl; + surf.scalePoints(scaleOut); + } + Info<< "writing " << exportName; - if (scaleFactor <= 0) - { - Info<< " without scaling" << endl; - } - else - { - Info<< " with scaling " << scaleFactor << endl; - surf.scalePoints(scaleFactor); - } surf.write(exportName); } From a43df3bddd79edfcd0061ed4e8bfac1f3daa2ba7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 4 Feb 2009 16:17:14 +0100 Subject: [PATCH 05/20] added surfMesh, reworked MeshedSurface - renamed surface regions (formerly patches or groups) to surfZone. - added surfMesh, but without any of the patch information needed to make it useful for finiteArea. - promoted coordinateSystem transformation to surfaceMeshConvert and moved old to surfaceMeshConvertTesting. --- .../Make/files | 3 - .../Make/options | 5 - .../surfaceCoordinateSystemTransform.C | 257 ---------- .../surface/surfaceMeshConvert/Make/options | 4 +- .../coordinateSystems | 0 .../surfaceMeshConvert/surfaceMeshConvert.C | 303 ++++++------ .../surfaceMeshConvertTesting/Make/files | 3 + .../surfaceMeshConvertTesting/Make/options | 5 + .../surfaceMeshConvertTesting.C | 323 +++++++++++++ .../BasicMeshedSurface/BasicMeshedSurface.H | 2 +- src/surfMesh/Make/files | 12 +- src/surfMesh/MeshedSurface/MeshedSurface.C | 291 ++++++------ src/surfMesh/MeshedSurface/MeshedSurface.H | 66 +-- src/surfMesh/MeshedSurface/MeshedSurfaceIO.C | 24 +- src/surfMesh/SurfGeoMesh/SurfGeoMesh.H | 105 +++++ .../UnsortedMeshedSurface.C | 183 +++---- .../UnsortedMeshedSurface.H | 89 ++-- .../UnsortedMeshedSurfaceIO.C | 18 +- src/surfMesh/surfFields/surfFields.C | 82 ++++ src/surfMesh/surfFields/surfFields.H | 73 +++ src/surfMesh/surfFields/surfFieldsFwd.H | 59 +++ src/surfMesh/surfFields/surfGeoMesh.H | 90 ++++ src/surfMesh/surfMesh/surfMesh.C | 446 ++++++++++++++++++ src/surfMesh/surfMesh/surfMesh.H | 334 +++++++++++++ src/surfMesh/surfMesh/surfMeshClear.C | 84 ++++ src/surfMesh/surfMesh/surfMeshIO.C | 215 +++++++++ .../surfZone/surfZone.C} | 68 +-- .../surfZone/surfZone.H} | 69 +-- .../surfZone/surfZoneIOList.C} | 48 +- .../surfZone/surfZoneIOList.H} | 32 +- .../surfZone/surfZoneList.H} | 12 +- .../surfZoneIdentifier/surfZoneIdentifier.C} | 38 +- .../surfZoneIdentifier/surfZoneIdentifier.H} | 64 ++- .../surfZoneIdentifierList.H} | 10 +- .../surfaceFormats/ac3d/AC3DsurfaceFormat.C | 86 ++-- .../surfaceFormats/ac3d/AC3DsurfaceFormat.H | 8 +- .../ac3d/AC3DsurfaceFormatCore.C | 14 +- .../ac3d/AC3DsurfaceFormatCore.H | 2 +- .../surfaceFormats/ftr/FTRsurfaceFormat.C | 20 +- .../surfaceFormats/gts/GTSsurfaceFormat.C | 66 +-- .../surfaceFormats/gts/GTSsurfaceFormat.H | 2 +- .../surfaceFormats/nas/NASsurfaceFormat.C | 60 +-- .../surfaceFormats/nas/NASsurfaceFormat.H | 2 +- .../surfaceFormats/obj/OBJsurfaceFormat.C | 58 +-- .../surfaceFormats/obj/OBJsurfaceFormat.H | 4 +- .../surfaceFormats/obj/OBJsurfaceFormatCore.C | 12 +- .../surfaceFormats/obj/OBJsurfaceFormatCore.H | 2 +- .../surfaceFormats/off/OFFsurfaceFormat.C | 38 +- .../surfaceFormats/off/OFFsurfaceFormat.H | 6 +- .../surfaceFormats/off/OFFsurfaceFormatCore.C | 12 +- .../surfaceFormats/off/OFFsurfaceFormatCore.H | 2 +- .../surfaceFormats/smesh/SMESHsurfaceFormat.C | 16 +- .../surfaceFormats/smesh/SMESHsurfaceFormat.H | 4 +- .../smesh/SMESHsurfaceFormatCore.C | 2 +- .../starcd/STARCDsurfaceFormat.C | 54 +-- .../starcd/STARCDsurfaceFormat.H | 2 +- .../starcd/STARCDsurfaceFormatCore.C | 10 +- .../starcd/STARCDsurfaceFormatCore.H | 2 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 66 +-- .../surfaceFormats/stl/STLsurfaceFormat.H | 8 +- .../stl/STLsurfaceFormatASCII.L | 15 +- .../surfaceFormats/stl/STLsurfaceFormatCore.C | 38 +- .../surfaceFormats/stl/STLsurfaceFormatCore.H | 12 +- src/surfMesh/surfaceFormats/stl/STLtriangle.H | 11 +- .../surfaceFormats/stl/STLtriangleI.H | 14 +- .../surfaceFormats/surfaceFormatsCore.C | 64 +-- .../surfaceFormats/surfaceFormatsCore.H | 14 +- .../surfaceFormats/tri/TRIsurfaceFormat.C | 42 +- .../surfaceFormats/tri/TRIsurfaceFormat.H | 8 +- .../surfaceFormats/tri/TRIsurfaceFormatCore.C | 46 +- .../surfaceFormats/tri/TRIsurfaceFormatCore.H | 14 +- .../surfaceFormats/vtk/VTKsurfaceFormat.C | 10 +- .../surfaceFormats/vtk/VTKsurfaceFormat.H | 2 +- .../surfaceFormats/vtk/VTKsurfaceFormatCore.C | 29 +- .../surfaceFormats/vtk/VTKsurfaceFormatCore.H | 8 +- .../surfaceRegistry/surfaceRegistry.C | 62 +++ .../surfaceRegistry/surfaceRegistry.H | 91 ++++ 77 files changed, 3097 insertions(+), 1358 deletions(-) delete mode 100644 applications/utilities/surface/surfaceCoordinateSystemTransform/Make/files delete mode 100644 applications/utilities/surface/surfaceCoordinateSystemTransform/Make/options delete mode 100644 applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C rename applications/utilities/surface/{surfaceCoordinateSystemTransform => surfaceMeshConvert}/coordinateSystems (100%) create mode 100644 applications/utilities/surface/surfaceMeshConvertTesting/Make/files create mode 100644 applications/utilities/surface/surfaceMeshConvertTesting/Make/options create mode 100644 applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C create mode 100644 src/surfMesh/SurfGeoMesh/SurfGeoMesh.H create mode 100644 src/surfMesh/surfFields/surfFields.C create mode 100644 src/surfMesh/surfFields/surfFields.H create mode 100644 src/surfMesh/surfFields/surfFieldsFwd.H create mode 100644 src/surfMesh/surfFields/surfGeoMesh.H create mode 100644 src/surfMesh/surfMesh/surfMesh.C create mode 100644 src/surfMesh/surfMesh/surfMesh.H create mode 100644 src/surfMesh/surfMesh/surfMeshClear.C create mode 100644 src/surfMesh/surfMesh/surfMeshIO.C rename src/surfMesh/{surfRegion/surfRegion/surfRegion.C => surfZone/surfZone/surfZone.C} (65%) rename src/surfMesh/{surfRegion/surfRegion/surfRegion.H => surfZone/surfZone/surfZone.H} (69%) rename src/surfMesh/{surfRegion/surfRegion/surfRegionIOList.C => surfZone/surfZone/surfZoneIOList.C} (75%) rename src/surfMesh/{surfRegion/surfRegion/surfRegionIOList.H => surfZone/surfZone/surfZoneIOList.H} (79%) rename src/surfMesh/{surfRegion/surfRegion/surfRegionList.H => surfZone/surfZone/surfZoneList.H} (90%) rename src/surfMesh/{surfRegion/surfRegionIdentifier/surfRegionIdentifier.C => surfZone/surfZoneIdentifier/surfZoneIdentifier.C} (75%) rename src/surfMesh/{surfRegion/surfRegionIdentifier/surfRegionIdentifier.H => surfZone/surfZoneIdentifier/surfZoneIdentifier.H} (67%) rename src/surfMesh/{surfRegion/surfRegionIdentifier/surfRegionIdentifierList.H => surfZone/surfZoneIdentifier/surfZoneIdentifierList.H} (89%) create mode 100644 src/surfMesh/surfaceRegistry/surfaceRegistry.C create mode 100644 src/surfMesh/surfaceRegistry/surfaceRegistry.H diff --git a/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/files b/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/files deleted file mode 100644 index b937625a71..0000000000 --- a/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -surfaceCoordinateSystemTransform.C - -EXE = $(FOAM_APPBIN)/surfaceCoordinateSystemTransform diff --git a/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/options b/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/options deleted file mode 100644 index 42b30c8652..0000000000 --- a/applications/utilities/surface/surfaceCoordinateSystemTransform/Make/options +++ /dev/null @@ -1,5 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/surfMesh/lnInclude - -EXE_LIBS = -lmeshTools -lsurfMesh diff --git a/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C b/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C deleted file mode 100644 index f0578f4ab2..0000000000 --- a/applications/utilities/surface/surfaceCoordinateSystemTransform/surfaceCoordinateSystemTransform.C +++ /dev/null @@ -1,257 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Application - surfaceMeshCoordinateSystemTransform - -Description - - Transform (scale/rotate/translate) a surface based on - a coordinateSystem. - -Usage - - surfaceMeshCoordinateSystemTransform inputFile outputFile [OPTION] - - @param -clean \n - Perform some surface checking/cleanup on the input surface. - - @param -scaleIn \ \n - Specify a scaling factor when reading files. - - @param -scaleOut \ \n - Specify a scaling factor when writing files. - - @param -dict \ \n - Specify an alternative dictionary for coordinateSystems. - - @param -from \ \n - Specify a coordinate System when reading files. - - @param -to \ \n - Specify a coordinate System when writing files. - -Note - The filename extensions are used to determine the file format type. - -\*---------------------------------------------------------------------------*/ - -#include "argList.H" -#include "timeSelector.H" -#include "Time.H" - -#include "MeshedSurfaces.H" -#include "coordinateSystems.H" - -using namespace Foam; - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Main program: - -int main(int argc, char *argv[]) -{ - argList::noParallel(); - argList::validArgs.append("inputFile"); - argList::validArgs.append("outputFile"); - argList::validOptions.insert("clean", "scale"); - argList::validOptions.insert("scaleIn", "scale"); - argList::validOptions.insert("scaleOut", "scale"); - argList::validOptions.insert("dict", "coordinateSystemsDict"); - argList::validOptions.insert("from", "sourceCoordinateSystem"); - argList::validOptions.insert("to", "targetCoordinateSystem"); - - argList args(argc, argv); - Time runTime(args.rootPath(), args.caseName()); - const stringList& params = args.additionalArgs(); - - fileName importName(params[0]); - fileName exportName(params[1]); - - // disable inplace editing - if (importName == exportName) - { - FatalErrorIn(args.executable()) - << "Output file " << exportName << " would overwrite input file." - << exit(FatalError); - } - - // check that reading/writing is supported - if - ( - !MeshedSurface::canRead(importName, true) - || !MeshedSurface::canWriteType(exportName.ext(), true) - ) - { - return 1; - } - - - // get the coordinate transformations - autoPtr fromCsys; - autoPtr toCsys; - - if (args.options().found("from") || args.options().found("to")) - { - autoPtr csDictIoPtr; - - if (args.options().found("dict")) - { - fileName dictPath(args.options()["dict"]); - - csDictIoPtr.set - ( - new IOobject - ( - ( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } - else - { - csDictIoPtr.set - ( - new IOobject - ( - coordinateSystems::typeName, - runTime.constant(), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } - - - if (!csDictIoPtr->headerOk()) - { - FatalErrorIn(args.executable()) - << "Cannot open coordinateSystems file\n " - << csDictIoPtr->objectPath() << nl - << exit(FatalError); - } - - coordinateSystems csLst(csDictIoPtr()); - - if (args.options().found("from")) - { - const word csName(args.options()["from"]); - - label csId = csLst.find(csName); - if (csId < 0) - { - FatalErrorIn(args.executable()) - << "Cannot find -from " << csName << nl - << "available coordinateSystems: " << csLst.toc() << nl - << exit(FatalError); - } - - fromCsys.reset(new coordinateSystem(csLst[csId])); - } - - if (args.options().found("to")) - { - const word csName(args.options()["to"]); - - label csId = csLst.find(csName); - if (csId < 0) - { - FatalErrorIn(args.executable()) - << "Cannot find -to " << csName << nl - << "available coordinateSystems: " << csLst.toc() << nl - << exit(FatalError); - } - - toCsys.reset(new coordinateSystem(csLst[csId])); - } - - - // maybe fix this later - if (fromCsys.valid() && toCsys.valid()) - { - FatalErrorIn(args.executable()) - << "Only allowed '-from' or '-to' option at the moment." - << exit(FatalError); - } - } - - scalar scaleIn = 0; - scalar scaleOut = 0; - if (args.options().found("scaleIn")) - { - IStringStream(args.options()["scaleIn"])() >> scaleIn; - } - if (args.options().found("scaleOut")) - { - IStringStream(args.options()["scaleOut"])() >> scaleOut; - } - - - { - MeshedSurface surf(importName); - - if (args.options().found("clean")) - { - surf.cleanup(true); - } - - if (scaleIn > 0) - { - Info<< " -scaleIn " << scaleIn << endl; - surf.scalePoints(scaleIn); - } - - if (fromCsys.valid()) - { - Info<< " -from " << fromCsys().name() << endl; - tmp tpf = fromCsys().localPosition(surf.points()); - surf.movePoints(tpf()); - } - - if (toCsys.valid()) - { - Info<< " -to " << toCsys().name() << endl; - tmp tpf = toCsys().globalPosition(surf.points()); - surf.movePoints(tpf()); - } - - if (scaleOut > 0) - { - Info<< " -scaleOut " << scaleOut << endl; - surf.scalePoints(scaleOut); - } - - Info<< "writing " << exportName; - surf.write(exportName); - } - - Info<< "\nEnd\n" << endl; - - return 0; -} - -// ************************************************************************* // diff --git a/applications/utilities/surface/surfaceMeshConvert/Make/options b/applications/utilities/surface/surfaceMeshConvert/Make/options index 5293dabe4c..42b30c8652 100644 --- a/applications/utilities/surface/surfaceMeshConvert/Make/options +++ b/applications/utilities/surface/surfaceMeshConvert/Make/options @@ -1,5 +1,5 @@ EXE_INC = \ - -I$(LIB_SRC)/triSurface/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude -EXE_LIBS = -lsurfMesh +EXE_LIBS = -lmeshTools -lsurfMesh diff --git a/applications/utilities/surface/surfaceCoordinateSystemTransform/coordinateSystems b/applications/utilities/surface/surfaceMeshConvert/coordinateSystems similarity index 100% rename from applications/utilities/surface/surfaceCoordinateSystemTransform/coordinateSystems rename to applications/utilities/surface/surfaceMeshConvert/coordinateSystems diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index 9b5c2cb8f7..c22534ecf5 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -26,25 +26,30 @@ Application surfaceMeshConvert Description - Converts from one surface mesh format to another + + Convert between surface formats with optional scaling or + transformations (rotate/translate) on a coordinateSystem. Usage - surfaceMeshConvert inputFile outputFile [OPTION] @param -clean \n - Perform some surface checking/cleanup on the input surface + Perform some surface checking/cleanup on the input surface. - @param -orient \n - Check face orientation on the input surface + @param -scaleIn \ \n + Specify a scaling factor when reading files. - @param -scale \ \n - Specify a scaling factor for writing the files + @param -scaleOut \ \n + Specify a scaling factor when writing files. - @param -triSurface \n - Use triSurface library for input/output + @param -dict \ \n + Specify an alternative dictionary for constant/coordinateSystems. - @param -keyed \n - Use keyedSurface for input/output + @param -from \ \n + Specify a coordinate System when reading files. + + @param -to \ \n + Specify a coordinate System when writing files. Note The filename extensions are used to determine the file format type. @@ -54,12 +59,9 @@ Note #include "argList.H" #include "timeSelector.H" #include "Time.H" -#include "polyMesh.H" -#include "triSurface.H" -#include "PackedBoolList.H" #include "MeshedSurfaces.H" -#include "UnsortedMeshedSurfaces.H" +#include "coordinateSystems.H" using namespace Foam; @@ -71,24 +73,21 @@ int main(int argc, char *argv[]) argList::noParallel(); argList::validArgs.append("inputFile"); argList::validArgs.append("outputFile"); - argList::validOptions.insert("clean", ""); - argList::validOptions.insert("orient", ""); - argList::validOptions.insert("scale", "scale"); - argList::validOptions.insert("triSurface", ""); - argList::validOptions.insert("unsorted", ""); - argList::validOptions.insert("triFace", ""); -# include "setRootCase.H" - const stringList& params = args.additionalArgs(); + argList::validOptions.insert("clean", "scale"); + argList::validOptions.insert("scaleIn", "scale"); + argList::validOptions.insert("scaleOut", "scale"); + argList::validOptions.insert("dict", "coordinateSystemsDict"); + argList::validOptions.insert("from", "sourceCoordinateSystem"); + argList::validOptions.insert("to", "targetCoordinateSystem"); - scalar scaleFactor = 0; - if (args.options().found("scale")) - { - IStringStream(args.options()["scale"])() >> scaleFactor; - } + argList args(argc, argv); + Time runTime(args.rootPath(), args.caseName()); + const stringList& params = args.additionalArgs(); fileName importName(params[0]); fileName exportName(params[1]); + // disable inplace editing if (importName == exportName) { FatalErrorIn(args.executable()) @@ -96,165 +95,157 @@ int main(int argc, char *argv[]) << exit(FatalError); } + // check that reading/writing is supported if ( - !meshedSurface::canRead(importName, true) - || !meshedSurface::canWriteType(exportName.ext(), true) + !MeshedSurface::canRead(importName, true) + || !MeshedSurface::canWriteType(exportName.ext(), true) ) { return 1; } - if (args.options().found("triSurface")) + + // get the coordinate transformations + autoPtr fromCsys; + autoPtr toCsys; + + if (args.options().found("from") || args.options().found("to")) { - triSurface surf(importName); + autoPtr csDictIoPtr; - Info<< "Read surface:" << endl; - surf.writeStats(Info); - Info<< endl; - - if (args.options().found("orient")) + if (args.options().found("dict")) { - Info<< "Checking surface orientation" << endl; - PatchTools::checkOrientation(surf, true); - Info<< endl; - } + fileName dictPath(args.options()["dict"]); - if (args.options().found("clean")) - { - Info<< "Cleaning up surface" << endl; - surf.cleanup(true); - surf.writeStats(Info); - Info<< endl; - } - - Info<< "writing " << exportName; - if (scaleFactor <= 0) - { - Info<< " without scaling" << endl; + csDictIoPtr.set + ( + new IOobject + ( + ( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ); } else { - Info<< " with scaling " << scaleFactor << endl; - surf.scalePoints(scaleFactor); - surf.writeStats(Info); - Info<< endl; + csDictIoPtr.set + ( + new IOobject + ( + coordinateSystems::typeName, + runTime.constant(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ); } - // write sorted by region - surf.write(exportName, true); + + if (!csDictIoPtr->headerOk()) + { + FatalErrorIn(args.executable()) + << "Cannot open coordinateSystems file\n " + << csDictIoPtr->objectPath() << nl + << exit(FatalError); + } + + coordinateSystems csLst(csDictIoPtr()); + + if (args.options().found("from")) + { + const word csName(args.options()["from"]); + + label csId = csLst.find(csName); + if (csId < 0) + { + FatalErrorIn(args.executable()) + << "Cannot find -from " << csName << nl + << "available coordinateSystems: " << csLst.toc() << nl + << exit(FatalError); + } + + fromCsys.reset(new coordinateSystem(csLst[csId])); + } + + if (args.options().found("to")) + { + const word csName(args.options()["to"]); + + label csId = csLst.find(csName); + if (csId < 0) + { + FatalErrorIn(args.executable()) + << "Cannot find -to " << csName << nl + << "available coordinateSystems: " << csLst.toc() << nl + << exit(FatalError); + } + + toCsys.reset(new coordinateSystem(csLst[csId])); + } + + + // maybe fix this later + if (fromCsys.valid() && toCsys.valid()) + { + FatalErrorIn(args.executable()) + << "Only allowed '-from' or '-to' option at the moment." + << exit(FatalError); + } } - else if (args.options().found("unsorted")) + + scalar scaleIn = 0; + scalar scaleOut = 0; + if (args.options().found("scaleIn")) { - UnsortedMeshedSurface surf(importName); - - Info<< "Read surface:" << endl; - surf.writeStats(Info); - Info<< endl; - - if (args.options().found("orient")) - { - Info<< "Checking surface orientation" << endl; - PatchTools::checkOrientation(surf, true); - Info<< endl; - } - - if (args.options().found("clean")) - { - Info<< "Cleaning up surface" << endl; - surf.cleanup(true); - surf.writeStats(Info); - Info<< endl; - } - - Info<< "writing " << exportName; - if (scaleFactor <= 0) - { - Info<< " without scaling" << endl; - } - else - { - Info<< " with scaling " << scaleFactor << endl; - surf.scalePoints(scaleFactor); - surf.writeStats(Info); - Info<< endl; - } - surf.write(exportName); + IStringStream(args.options()["scaleIn"])() >> scaleIn; } -#if 1 - else if (args.options().found("triFace")) + if (args.options().found("scaleOut")) { - MeshedSurface surf(importName); - - Info<< "Read surface:" << endl; - surf.writeStats(Info); - Info<< endl; - - if (args.options().found("orient")) - { - Info<< "Checking surface orientation" << endl; - PatchTools::checkOrientation(surf, true); - Info<< endl; - } - - if (args.options().found("clean")) - { - Info<< "Cleaning up surface" << endl; - surf.cleanup(true); - surf.writeStats(Info); - Info<< endl; - } - - Info<< "writing " << exportName; - if (scaleFactor <= 0) - { - Info<< " without scaling" << endl; - } - else - { - Info<< " with scaling " << scaleFactor << endl; - surf.scalePoints(scaleFactor); - surf.writeStats(Info); - Info<< endl; - } - surf.write(exportName); + IStringStream(args.options()["scaleOut"])() >> scaleOut; } -#endif - else + + { MeshedSurface surf(importName); - Info<< "Read surface:" << endl; - surf.writeStats(Info); - Info<< endl; - - if (args.options().found("orient")) - { - Info<< "Checking surface orientation" << endl; - PatchTools::checkOrientation(surf, true); - Info<< endl; - } - if (args.options().found("clean")) { - Info<< "Cleaning up surface" << endl; surf.cleanup(true); - surf.writeStats(Info); - Info<< endl; + } + + if (scaleIn > 0) + { + Info<< " -scaleIn " << scaleIn << endl; + surf.scalePoints(scaleIn); + } + + if (fromCsys.valid()) + { + Info<< " -from " << fromCsys().name() << endl; + tmp tpf = fromCsys().localPosition(surf.points()); + surf.movePoints(tpf()); + } + + if (toCsys.valid()) + { + Info<< " -to " << toCsys().name() << endl; + tmp tpf = toCsys().globalPosition(surf.points()); + surf.movePoints(tpf()); + } + + if (scaleOut > 0) + { + Info<< " -scaleOut " << scaleOut << endl; + surf.scalePoints(scaleOut); } Info<< "writing " << exportName; - if (scaleFactor <= 0) - { - Info<< " without scaling" << endl; - } - else - { - Info<< " with scaling " << scaleFactor << endl; - surf.scalePoints(scaleFactor); - surf.writeStats(Info); - Info<< endl; - } surf.write(exportName); } diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/Make/files b/applications/utilities/surface/surfaceMeshConvertTesting/Make/files new file mode 100644 index 0000000000..6fd163a054 --- /dev/null +++ b/applications/utilities/surface/surfaceMeshConvertTesting/Make/files @@ -0,0 +1,3 @@ +surfaceMeshConvertTesting.C + +EXE = $(FOAM_APPBIN)/surfaceMeshConvertTesting diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/Make/options b/applications/utilities/surface/surfaceMeshConvertTesting/Make/options new file mode 100644 index 0000000000..5293dabe4c --- /dev/null +++ b/applications/utilities/surface/surfaceMeshConvertTesting/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/triSurface/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude + +EXE_LIBS = -lsurfMesh diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C new file mode 100644 index 0000000000..c7cc9b862f --- /dev/null +++ b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C @@ -0,0 +1,323 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Application + surfaceMeshConvertTesting + +Description + Converts from one surface mesh format to another, but primarily + used for testing functionality. + +Usage + - surfaceMeshConvertTesting inputFile outputFile [OPTION] + + @param -clean \n + Perform some surface checking/cleanup on the input surface + + @param -orient \n + Check face orientation on the input surface + + @param -scale \ \n + Specify a scaling factor for writing the files + + @param -triSurface \n + Use triSurface library for input/output + + @param -keyed \n + Use keyedSurface for input/output + +Note + The filename extensions are used to determine the file format type. + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "timeSelector.H" +#include "Time.H" +#include "polyMesh.H" +#include "triSurface.H" +#include "surfMesh.H" +#include "surfFields.H" +#include "PackedBoolList.H" + +#include "MeshedSurfaces.H" +#include "UnsortedMeshedSurfaces.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::noParallel(); + argList::validArgs.append("inputFile"); + argList::validArgs.append("outputFile"); + argList::validOptions.insert("clean", ""); + argList::validOptions.insert("orient", ""); + argList::validOptions.insert("surfMesh", ""); + argList::validOptions.insert("scale", "scale"); + argList::validOptions.insert("triSurface", ""); + argList::validOptions.insert("unsorted", ""); + argList::validOptions.insert("triFace", ""); +# include "setRootCase.H" + const stringList& params = args.additionalArgs(); + + scalar scaleFactor = 0; + if (args.options().found("scale")) + { + IStringStream(args.options()["scale"])() >> scaleFactor; + } + + fileName importName(params[0]); + fileName exportName(params[1]); + + if (importName == exportName) + { + FatalErrorIn(args.executable()) + << "Output file " << exportName << " would overwrite input file." + << exit(FatalError); + } + + if + ( + !meshedSurface::canRead(importName, true) + || !meshedSurface::canWriteType(exportName.ext(), true) + ) + { + return 1; + } + + if (args.options().found("triSurface")) + { + triSurface surf(importName); + + Info<< "Read surface:" << endl; + surf.writeStats(Info); + Info<< endl; + + if (args.options().found("orient")) + { + Info<< "Checking surface orientation" << endl; + PatchTools::checkOrientation(surf, true); + Info<< endl; + } + + if (args.options().found("clean")) + { + Info<< "Cleaning up surface" << endl; + surf.cleanup(true); + surf.writeStats(Info); + Info<< endl; + } + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + surf.scalePoints(scaleFactor); + surf.writeStats(Info); + Info<< endl; + } + + // write sorted by region + surf.write(exportName, true); + } + else if (args.options().found("unsorted")) + { + UnsortedMeshedSurface surf(importName); + + Info<< "Read surface:" << endl; + surf.writeStats(Info); + Info<< endl; + + if (args.options().found("orient")) + { + Info<< "Checking surface orientation" << endl; + PatchTools::checkOrientation(surf, true); + Info<< endl; + } + + if (args.options().found("clean")) + { + Info<< "Cleaning up surface" << endl; + surf.cleanup(true); + surf.writeStats(Info); + Info<< endl; + } + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + surf.scalePoints(scaleFactor); + surf.writeStats(Info); + Info<< endl; + } + surf.write(exportName); + } +#if 1 + else if (args.options().found("triFace")) + { + MeshedSurface surf(importName); + + Info<< "Read surface:" << endl; + surf.writeStats(Info); + Info<< endl; + + if (args.options().found("orient")) + { + Info<< "Checking surface orientation" << endl; + PatchTools::checkOrientation(surf, true); + Info<< endl; + } + + if (args.options().found("clean")) + { + Info<< "Cleaning up surface" << endl; + surf.cleanup(true); + surf.writeStats(Info); + Info<< endl; + } + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + surf.scalePoints(scaleFactor); + surf.writeStats(Info); + Info<< endl; + } + surf.write(exportName); + } +#endif + else + { + MeshedSurface surf(importName); + + Info<< "Read surface:" << endl; + surf.writeStats(Info); + Info<< endl; + + if (args.options().found("orient")) + { + Info<< "Checking surface orientation" << endl; + PatchTools::checkOrientation(surf, true); + Info<< endl; + } + + if (args.options().found("clean")) + { + Info<< "Cleaning up surface" << endl; + surf.cleanup(true); + surf.writeStats(Info); + Info<< endl; + } + + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + surf.scalePoints(scaleFactor); + surf.writeStats(Info); + Info<< endl; + } + surf.write(exportName); + + if (args.options().found("surfMesh")) + { + Foam::Time runTime + ( + args.rootPath(), + args.caseName() + ); + + surfMesh surfOut + ( + IOobject + ( + "mySurf", + runTime.instance(), + runTime + ), + surf.xfer() + ); + + Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl; + surfOut.write(); + + surfLabelField zoneIds + ( + IOobject + ( + "zoneIds", + surfOut.instance(), + surfOut, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + surfOut, + dimless + ); + + const surfZoneList& zones = surfOut.surfZones(); + forAll(zones, zoneI) + { + SubList