Compare commits

..

5 Commits

Author SHA1 Message Date
07eded03a7 ENH: error handling for empty surfaces in surfaceFieldValue (#2966)
- for workflows with appearing/disappearing patches (for example)
  can specify that empty surfaces should be ignored or warned about
  instead of raising a FatalError.

  Note that this handling is additional to the regular top-level
  "errors" specification. So specifying 'strict' will only actually
  result in a FatalError if the "errors" does not trap errors.

- "ignore" : any empty surfaces are simply ignored and no
  file output (besides the header).

- "warn" : empty surfaces are warned about a few times (10)
  and the file output contains a NaN entry

- "strict" : corresponds to the default behaviour.
  Throws a FatalError if the surface is empty.
  This error may still be caught by the top-level "errors" handling.
2023-08-30 16:31:56 +02:00
45133bfaa8 ENH: relocate functionObjectList errorHandling types to error (#2966)
- was previously private within functionObjectList, now exposed from
  error as 'handlerTypes' and 'handlerNames' enumeration.
2023-08-30 15:48:16 +02:00
49151becf3 ENH: improve robustness of raw reading, file size checks
- use ignore instead of seekg/tellg to swallow input (robuster)

- check for bad gcount() values

- wrap Foam::fileSize() compressed/uncompressed handling into IFstream.

- improve handling of compressed files in masterUncollatedFileOperation.
  Previously read into a string via stream iterators.
  Now read chunk-wise into a List of char for fewer reallocations.
2023-08-30 15:40:26 +02:00
8b0a049de3 ENH: update and enhancement of memory-streams
- soft renames (ie, old names still available via typedefs) for more
  reasonable names and more coverage with std stream variants.

  The old names could be a bit cryptic.
  For example, uiliststream (== an unallocated/external list storage),
  which is written as std::ispanstream for C++23.

  Could similarly argue that IListStream is better named as
  ICharStream, since it is an input stream of characters and the
  internal storage mechanism (List or something else) is mostly
  irrelevant.

  Extending the coverage to include all std stream variants, and
  simply rewrap them for OpenFOAM IOstream types. This simplifies the
  inheritance patterns and allows reuse of icharstream/ocharstream as
  a drop-in replace for istringstream/ostringstream in other wrappers.

  Classes:
    * icharstream / ICharStream   [old: none / IListStream]
    * ocharstream / OCharStream   [old: none / OListStream]
    * ispanstream / ISpanStream   [old: uiliststream / UIListStream]
    * ospanstream / OSpanStream   [old: none / UOListStream]

  Possible new uses : read file contents into a buffer, broadcast
  buffer contents to other ranks and then transfer into an icharstream
  to be read from. This avoid the multiple intermediate copies that
  would be associated when using an istringstream.

- Use size doubling instead of block-wise incremental for ocharstream
  (OCharStream). This corresponds to the sizing behaviour as per
  std::stringstream (according to gcc-11 includes)

STYLE: drop Foam_IOstream_extras constructors for memory streams

- transitional/legacy constructors but not used in any code
2023-08-30 15:40:26 +02:00
ca24f154fc ENH: support List sub-slice searching, use std::find() 2023-08-30 15:40:26 +02:00
50 changed files with 737 additions and 1004 deletions

View File

@ -1,2 +1,2 @@
api=2307
api=2306
patch=0

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,7 +37,6 @@ Description
#include "scalarField.H"
#include "SubField.H"
#include "labelRange.H"
#include "ListOps.H"
#include <numeric>
using namespace Foam;
@ -58,26 +57,26 @@ int main(int argc, char *argv[])
argList::noFunctionObjects();
{
List<label> ident(25);
List<scalar> ident(25);
std::iota(ident.begin(), ident.end(), 0);
print(ident);
SubList<label>(ident, 10) = -10;
SubList<scalar>(ident, 10) = -10;
print(ident);
SubField<label>(ident, 10) = 10;
SubField<scalar>(ident, 10) = 10;
print(ident);
SubField<label>(ident, 10) += 10;
SubField<scalar>(ident, 10) += 10;
print(ident);
SubField<label>{ident, 10, 10} *= 5;
SubField<scalar>{ident, 10, 10} *= 5;
print(ident);
// NOTE: Need {} instead of ()
// SubList<label>(ident) = 100;
// SubList<scalar>(ident) = 100;
// GCC
// error: conflicting declaration 'Foam::SubList<double> ident'
@ -86,30 +85,7 @@ int main(int argc, char *argv[])
// warning: parentheses were disambiguated as redundant parentheses
// around declaration of variable named 'ident' [-Wvexing-parse]
SubList<label>{ident} = 100;
print(ident);
SubList<label> sub(ident);
sub = 1;
print(sub);
sub.reset(ident, labelRange(4, 5)) = 5;
print(sub);
print(ident);
sub.reset(ident, labelRange(14, 5)) = 15;
print(sub);
print(ident);
// Cryptic, probably not a great idea to write this
sub.reset(ident, {20, 3}) = -1;
print(sub);
print(ident);
// This is also possible since we hold a concrete pointer/size
// and not an intermediate
ListOps::identity(sub.reset(ident, 8, 8));
print(sub);
SubList<scalar>{ident} = 100;
print(ident);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022-2023 OpenCFD Ltd.
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,16 +75,6 @@ void testBroadcast(List<T>& values)
}
template<class T>
void testBroadcast(std::vector<T>& values)
{
Info<< nl << "is_contiguous:" << is_contiguous<T>::value << endl;
Pout<< "pre-broadcast: " << flatOutput(values) << endl;
Pstream::broadcast(values);
Pout<< "post-broadcast: " << flatOutput(values) << endl;
}
void testBroadcast(bitSet& values)
{
Pout<< "pre-broadcast: "
@ -145,20 +135,6 @@ int main(int argc, char *argv[])
testBroadcast(values);
}
{
std::vector<word> values;
if (Pstream::master())
{
values.resize(UPstream::nProcs());
for (decltype(values.size()) i=0; i < values.size(); ++i)
{
values[i] = "vector_" + Foam::name(i);
}
}
testBroadcast(values);
}
{
vector values(vector::uniform(-1));
if (Pstream::master())

View File

@ -51,30 +51,13 @@ int main(int argc, char *argv[])
hmm.source()[1] = vector(1.0, 4.0, 3.0);
hmm.source()[2] = vector(0.0, 5.0, 2.0);
Info<< hmm << nl;
Info<< hmm.solve() << nl;
Info<< hmm << nl;
Info<< hmm.LUsolve() << nl;
Info<< hmm << nl;
Info<< hmm << endl;
Info<< hmm.solve() << endl;
Info<< hmm << endl;
Info<< hmm.LUsolve() << endl;
Info<< hmm << endl;
{
scalarSquareMatrix mat0;
Info<< "empty: " << mat0 << endl;
mat0.resize_nocopy(1);
mat0 = Identity<scalar>();
Info<< "ident (1x1): " << mat0 << endl;
mat0.resize_nocopy(3);
mat0 = Identity<scalar>();
Info<< "ident (3x3): " << mat0 << endl;
mat0.resize_nocopy(5);
mat0 = Identity<scalar>();
Info<< "ident (5x5): " << mat0 << endl;
}
Info<< "\nEnd\n" << endl;
Info<< "End\n" << endl;
return 0;
}

View File

@ -429,7 +429,7 @@ unset cmd
case "$WM_MPLIB" in
*OPENMPI*)
cmd="mpirun --oversubscribe -app $PWD/mpirun.schema </dev/null"
cmd="mpirun -app $PWD/mpirun.schema </dev/null"
;;
MPICH)
cmd="mpiexec"

View File

@ -304,21 +304,16 @@ runApplication()
#
runParallel()
{
local appName appRun optValue logFile logMode
local mpiopts nProcs
local appName appRun optValue logFile logMode nProcs
# Any additional parsed arguments (eg, decomposeParDict)
local appArgs="-parallel"
local mpirun="mpirun"
case "$FOAM_MPI" in
(msmpi*)
if [ "$FOAM_MPI" = msmpi ]
then
mpirun="mpiexec"
;;
(*openmpi*)
mpiopts="--oversubscribe"
;;
esac
fi
# Parse options until executable is encountered
while [ "$#" -gt 0 ] && [ -z "$appRun" ]
@ -383,11 +378,11 @@ runParallel()
if [ "$logMode" = append ]
then
(
"$mpirun" $mpiopts -n "${nProcs:?}" $appRun $appArgs "$@" </dev/null >> $logFile 2>&1
$mpirun -n $nProcs $appRun $appArgs "$@" </dev/null >> $logFile 2>&1
)
else
(
"$mpirun" $mpiopts -n "${nProcs:?}" $appRun $appArgs "$@" </dev/null > $logFile 2>&1
$mpirun -n $nProcs $appRun $appArgs "$@" </dev/null > $logFile 2>&1
)
fi
fi

View File

@ -225,8 +225,6 @@ castellatedMeshControls
//cellZone sphere;
//cellZoneInside inside; // outside/insidePoint
//insidePoint (1 1 1); // if (cellZoneInside == insidePoint)
// or alternative multiple insidePoints:
//insidePoints ((1 1 1)); // if (cellZoneInside == insidePoint)
//- Optional specification of what to do with faceZone faces:
// internal : keep them as internal faces (default)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2023 OpenCFD Ltd.
Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -102,51 +102,48 @@ bool Foam::PackedList<Width>::uniform() const
return true;
}
// The value of the first element for testing
const unsigned int val = get(0);
const label nblocks = num_blocks(size());
bool identical = true;
if (!val)
{
// No bits set: just check there are no non-zero blocks
// - like bitSet::none()
identical = (-1 == first_block());
}
else if (val == PackedList<Width>::max_value)
{
// All bits set: just check there are no zero blocks
// - like bitSet::all()
identical = (-1 == first_not_block());
}
else
{
const label nblocks = num_blocks(size());
// Zero value: can just check block content directly
if (nblocks > 1)
for (label blocki = 0; identical && blocki < nblocks; ++blocki)
{
// Fill value for complete blocks
const unsigned int blockval = repeated_value(val);
// Check each complete block (nblocks-1)
for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki)
{
identical = (blocks_[blocki] == blockval);
}
identical = !blocks_[blocki];
}
// Partial block: check manually
for
(
label elemi = elem_per_block*(nblocks-1);
identical && elemi < size();
++elemi
)
return identical;
}
else if (nblocks > 1)
{
// Fill value for complete blocks
const unsigned int blockval = repeated_value(val);
// Check each complete block (nblocks-1)
for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki)
{
identical = (val == get(elemi));
identical = (blocks_[blocki] == blockval);
}
}
// Partial block: check manually
for
(
label elemi = elem_per_block*(nblocks-1);
identical && elemi < size();
++elemi
)
{
identical = (val == get(elemi));
}
return identical;
}
@ -197,20 +194,16 @@ Foam::PackedList<Width>::unpack() const
"Width of IntType is too small to hold result"
);
List<IntType> output(size());
if (empty())
{
return output;
return List<IntType>(0);
}
else if (uniform())
{
output = static_cast<IntType>(get(0));
return output;
return List<IntType>(size(), static_cast<IntType>(get(0)));
}
// NON-UNIFORM and len > 0
List<IntType> output(size());
label outi = 0;
// Process n-1 complete blocks
@ -222,7 +215,7 @@ Foam::PackedList<Width>::unpack() const
for (unsigned nget = elem_per_block; nget; --nget, ++outi)
{
output[outi] = IntType(blockval & PackedList<Width>::max_value);
output[outi] = IntType(blockval & max_value);
blockval >>= Width;
}
}

View File

@ -221,14 +221,6 @@ protected:
//- Copy assignment
inline void copyAssign(const PackedList<Width>& rhs);
//- Find the first block with a '1' bit
// \return block number or -1 for an list or if all bits are OFF.
inline label first_block() const;
//- Find the first block with a '0' bit
// \return block number or -1 for an list or if all bits are ON.
inline label first_not_block() const;
public:
@ -300,7 +292,7 @@ public:
//- Number of elements that can be stored without reallocating
inline label capacity() const noexcept;
//- True if all entries have identical values (and list is non-empty)
//- True if all entries have identical values, and list is non-empty
bool uniform() const;
//- Test for equality of sizes and the bits set

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -147,73 +147,6 @@ inline void Foam::PackedList<Width>::copyAssign(const PackedList<Width>& rhs)
}
template<unsigned Width>
inline Foam::label Foam::PackedList<Width>::first_block() const
{
if (size())
{
const label nblocks = num_blocks(size());
for (label blocki=0; blocki < nblocks; ++blocki)
{
if (blocks_[blocki])
{
return blocki;
}
}
}
return -1;
}
template<unsigned Width>
inline Foam::label Foam::PackedList<Width>::first_not_block() const
{
if (!size())
{
return -1;
}
// Check on complement (changes 0 <-> 1).
// If any 1's now appear, there was a 0 bit before
const label nblocks = num_blocks(size());
// Extra bits in the final block?
const unsigned int off = size() % elem_per_block;
if (!off)
{
for (label blocki=0; blocki < nblocks; ++blocki)
{
if (~(blocks_[blocki]))
{
return blocki;
}
}
}
else
{
for (label blocki=0; blocki < nblocks-1; ++blocki)
{
if (~(blocks_[blocki]))
{
return blocki;
}
}
// The final block needs masking
if (~(blocks_[nblocks-1]) & mask_lower(off))
{
return nblocks-1;
}
}
return -1;
}
// * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
namespace Foam

View File

@ -18,8 +18,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef FoamCompat_PackedBoolList_H
#define FoamCompat_PackedBoolList_H
#ifndef PackedBoolList_H
#define PackedBoolList_H
#include "bitSet.H"

View File

@ -65,6 +65,13 @@ class bitSet
:
public PackedList<1>
{
// Private Member Functions
//- Find the first block with a '0' bit
// \return block number or -1 if the set is empty or all bits are on.
inline label first_not_block() const;
protected:
// Logic/Set Operations
@ -131,7 +138,7 @@ public:
// Constructors
//- Default construct an empty, zero-sized bitSet
inline constexpr bitSet() noexcept;
inline bitSet() noexcept;
//- Construct from Istream
explicit bitSet(Istream& is);
@ -239,6 +246,9 @@ public:
// \note Method name compatibility with boost::dynamic_bitset
inline bool none() const;
//- True if all entries have identical values, and the set is non-empty
inline bool uniform() const;
//- Count number of bits set.
// \param on can be set to false to count the number of unset bits
// instead.

View File

@ -25,9 +25,56 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline Foam::label Foam::bitSet::first_not_block() const
{
if (empty())
{
return -1;
}
// Use complement to change 0 <-> 1 and check if any 1's now appear
const label nblocks = num_blocks(size());
// Extra bits in the final block?
const unsigned int off = size() % elem_per_block;
if (!off)
{
for (label blocki=0; blocki < nblocks; ++blocki)
{
if (~(blocks_[blocki]))
{
return blocki;
}
}
}
else
{
for (label blocki=0; blocki < nblocks-1; ++blocki)
{
if (~(blocks_[blocki]))
{
return blocki;
}
}
// The final block needs masking
if (~(blocks_[nblocks-1]) & mask_lower(off))
{
return nblocks-1;
}
}
return -1;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline constexpr Foam::bitSet::bitSet() noexcept
inline Foam::bitSet::bitSet() noexcept
:
PackedList<1>()
{}
@ -266,14 +313,14 @@ inline Foam::bitSet::const_iterator Foam::bitSet::cend() const noexcept
inline Foam::label Foam::bitSet::find_first() const
{
const label blocki = first_block();
// Process block-wise, detecting any '1' bits
if (blocki >= 0)
const label nblocks = num_blocks(size());
for (label blocki = 0; blocki < nblocks; ++blocki)
{
label pos = (blocki * elem_per_block);
// Detect first '1' bit within the block
for
(
unsigned int blockval = blocks_[blocki];
@ -301,7 +348,7 @@ inline Foam::label Foam::bitSet::find_first_not() const
{
label pos = (blocki * elem_per_block);
// Detect first '0' bit within the block (check the complement)
// Detect first '0' bit by checking the complement.
// No special masking for the final block, that was already checked
// in the first_not_block() call.
@ -414,19 +461,39 @@ inline const Foam::bitSet& Foam::bitSet::null()
inline bool Foam::bitSet::all() const
{
if (empty()) return true; // SIC. boost convention
return (-1 == first_not_block());
return -1 == first_not_block();
}
inline bool Foam::bitSet::any() const
{
return (-1 != first_block());
if (size())
{
const label nblocks = num_blocks(size());
for (label blocki=0; blocki < nblocks; ++blocki)
{
if (blocks_[blocki])
{
return true;
}
}
}
return false;
}
inline bool Foam::bitSet::none() const
{
return (-1 == first_block());
return !any();
}
inline bool Foam::bitSet::uniform() const
{
return (size() == 1 || (size() > 1 && (test(0) ? all() : none())));
}

View File

@ -108,8 +108,6 @@ const Foam::SubList<T> Foam::CircularBuffer<T>::array_two() const
template<class T>
Foam::label Foam::CircularBuffer<T>::find(const T& val, label pos) const
{
if (pos < 0) return -1; // no-op
label i = -1;
const auto list1 = this->array_one();

View File

@ -282,21 +282,18 @@ public:
// Search
//- True if the value is contained in the list.
inline bool contains(const T& val) const;
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (no-op if -ve)
// \return true if found.
inline bool contains(const T& val, label pos) const;
//- Find index of the first occurrence of the value.
// Any occurrences before the start pos are ignored.
// Linear search.
// \return position in list or -1 if not found.
label find(const T& val, label pos = 0) const;
//- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored.
// \return true if found.
inline bool contains(const T& val, label pos = 0) const;
// Stack-like Operations

View File

@ -255,13 +255,6 @@ inline void Foam::CircularBuffer<T>::reserve_nocopy(const label len)
}
template<class T>
bool Foam::CircularBuffer<T>::contains(const T& val) const
{
return (this->array_one().contains(val) || this->array_two().contains(val));
}
template<class T>
inline bool Foam::CircularBuffer<T>::contains(const T& val, label pos) const
{

View File

@ -499,12 +499,8 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{
if (size_)
{
iterator iter(find(key));
if (iter.good()) return iterator_erase(iter);
}
return false;
iterator iter(find(key));
return iterator_erase(iter);
}

View File

@ -31,21 +31,13 @@ template<class T, class Addr>
Foam::label Foam::IndirectListBase<T, Addr>::find
(
const T& val,
label pos,
label len
label pos
) const
{
if (pos >= 0 && pos < addr_.size())
const label len = addr_.size();
if (pos >= 0 && len)
{
// Change sub-length to (one-past) end position
// len == -1 (like std::string::npos) - search until end
if (len > 0) len += pos;
if (len < 0 || len > addr_.size())
{
len = addr_.size();
}
const T* const vals = values_.begin();
while (pos < len)
@ -70,7 +62,7 @@ Foam::label Foam::IndirectListBase<T, Addr>::rfind
label pos
) const
{
// pos == -1 (like std::string::npos) - search from end
// pos == -1 has same meaning as std::string::npos - search from end
if (pos < 0 || pos >= addr_.size())
{

View File

@ -179,19 +179,11 @@ public:
// Search
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (default: 0, no-op if -ve)
// \param len The length of the search region (-ve until the end)
// \return true if found.
inline bool contains(const T& val, label pos = 0, label len = -1) const;
//- Find index of the first occurrence of the value.
// \param val The value to search for
// \param pos The first position to examine (default: 0, no-op if -ve)
// \param len The length of the search region (-ve until the end)
// \return position in list or -1 if not found.
label find(const T& val, label pos = 0, label len = -1) const;
// Any occurrences before the start pos are ignored.
// Linear search.
// \return -1 if not found.
label find(const T& val, label pos = 0) const;
//- Find index of the last occurrence of the value.
// Any occurrences after the end pos are ignored.
@ -199,6 +191,12 @@ public:
// \return -1 if not found.
label rfind(const T& val, label pos = -1) const;
//- Is the value contained in the list?
// Linear search from start pos until the end of the list.
// Any occurrences before the start pos are ignored.
// \return true if found.
inline bool contains(const T& val, label pos = 0) const;
// Member Operators

View File

@ -102,11 +102,10 @@ template<class T, class Addr>
inline bool Foam::IndirectListBase<T, Addr>::contains
(
const T& val,
label pos,
label len
label pos
) const
{
return (this->find(val, pos, len) >= 0);
return (this->find(val, pos) >= 0);
}

View File

@ -222,27 +222,6 @@ Foam::Istream& Foam::DynamicList<T, SizeMin>::readList(Istream& is)
);
}
}
else if (std::is_same<char, T>::value)
{
// Special treatment for char data (always binary and contiguous)
// (see List<char>::readList)
if (len)
{
const auto oldFmt = is.format(IOstreamOption::BINARY);
// read(...) includes surrounding start/end delimiters
is.read(list.data_bytes(), list.size_bytes());
is.format(oldFmt);
is.fatalCheck
(
"DynamicList<char>::readList(Istream&) : "
"reading binary block"
);
}
}
else
{
// Begin of contents marker

View File

@ -45,14 +45,6 @@ std::streamsize Foam::FixedList<T, N>::byteSize()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, unsigned N>
Foam::label Foam::FixedList<T, N>::find(const T& val) const
{
const auto iter = std::find(this->cbegin(), this->cend(), val);
return (iter != this->cend() ? label(iter - this->cbegin()) : label(-1));
}
template<class T, unsigned N>
Foam::label Foam::FixedList<T, N>::find
(
@ -63,8 +55,8 @@ Foam::label Foam::FixedList<T, N>::find
{
if (pos >= 0 && pos < label(N))
{
// Change sub-length to (one-past) end position
// len == -1 (like std::string::npos) - search until end
// Change length to end iterator position
// len == -1 has same meaning as std::string::npos - search until end
if (len > 0) len += pos;
if (len < 0 || len > label(N))
@ -72,16 +64,13 @@ Foam::label Foam::FixedList<T, N>::find
len = label(N);
}
const auto iter = std::find
(
(this->cbegin() + pos),
(this->cbegin() + len),
val
);
auto iter = (this->cbegin() + pos);
const auto lastIter = (this->cbegin() + len);
if (iter != (this->cbegin() + len))
iter = std::find(iter, lastIter, val);
if (iter != lastIter)
{
return label(iter - this->cbegin());
return label(iter - this->begin());
}
}
@ -92,8 +81,7 @@ Foam::label Foam::FixedList<T, N>::find
template<class T, unsigned N>
Foam::label Foam::FixedList<T, N>::rfind(const T& val, label pos) const
{
// pos == -1 (like std::string::npos) - search from end
// pos == -1 has same meaning as std::string::npos - search from end
if (pos < 0 || pos >= label(N))
{
pos = label(N)-1;

View File

@ -275,27 +275,12 @@ public:
// Search
//- True if the value is contained in the list.
inline bool contains(const T& val) const;
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (no-op if -ve)
// \param len The length of the search region (-ve until the end)
// \return true if found.
inline bool contains(const T& val, label pos, label len = -1) const;
//- Find index of the first occurrence of the value.
// \param val The value to search for
// \return position in list or -1 if not found.
label find(const T& val) const;
//- Find index of the first occurrence of the value.
// \param val The value to search for
// \param pos The first position to examine (no-op if -ve)
// \param pos The first position to examine (default: 0, -ve no-op)
// \param len The length of the search region (-ve until the end)
// \return position in list or -1 if not found.
label find(const T& val, label pos, label len = -1) const;
label find(const T& val, label pos = 0, label len = -1) const;
//- Find index of the last occurrence of the value.
// Any occurrences after the end pos are ignored.
@ -303,6 +288,13 @@ public:
// \return position in list or -1 if not found.
label rfind(const T& val, label pos = -1) const;
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (default: 0, -ve no-op)
// \param len The length of the search region (-ve until the end)
// \return true if found.
inline bool contains(const T& val, label pos = 0, label len = -1) const;
// Edit

View File

@ -306,14 +306,6 @@ inline bool Foam::FixedList<T, N>::uniform() const
}
template<class T, unsigned N>
inline bool Foam::FixedList<T, N>::contains(const T& val) const
{
const auto iter = std::find(this->cbegin(), this->cend(), val);
return (iter != this->cend());
}
template<class T, unsigned N>
inline bool Foam::FixedList<T, N>::contains
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,10 +89,7 @@ public:
// Constructors
//- Construct from UList, the entire size
inline explicit SubList(const UList<T>& list) noexcept;
//- Construct from std::vector, the entire size
inline explicit SubList(const std::vector<T>& list) noexcept;
inline explicit SubList(const UList<T>& list);
//- Construct from FixedList, the entire size
template<unsigned N>
@ -131,47 +128,6 @@ public:
);
// Member Functions
//- Reset to zero-sized and nullptr
inline UList<T>& reset(std::nullptr_t) noexcept;
//- Reset to use entire UList
inline UList<T>& reset(const UList<T>& list) noexcept;
//- Reset to use UList with sub-list size, start at 0
inline UList<T>& reset
(
const UList<T>& list,
const label subSize
);
//- Reset to use UList with sub-list size and start index
inline UList<T>& reset
(
const UList<T>& list,
const label subSize,
const label startIndex
);
//- Reset to use UList with a (start,size) range.
// The range is subsetted with the list size itself to ensure that the
// result always addresses a valid section of the list.
inline UList<T>& reset
(
const UList<T>& list,
const labelRange& range
);
//- Reset to use UList with a (start,size) range, but bypassing
//- run-time range checking.
inline UList<T>& reset
(
const labelRange& range,
const UList<T>& list
);
// Member Operators
//- Allow cast to a const List\<T\>&

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,37 +28,18 @@ License
#include "FixedList.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
inline const Foam::SubList<T>& Foam::SubList<T>::null()
{
return NullObjectRef<SubList<T>>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::SubList<T>::SubList
(
const UList<T>& list
) noexcept
)
:
UList<T>(const_cast<T*>(list.cdata()), list.size())
{}
template<class T>
inline Foam::SubList<T>::SubList
(
const std::vector<T>& list
) noexcept
:
UList<T>(const_cast<T*>(list.data()), label(list.size()))
{}
template<class T>
template<unsigned N>
inline Foam::SubList<T>::SubList
@ -132,102 +113,9 @@ inline Foam::SubList<T>::SubList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept
inline const Foam::SubList<T>& Foam::SubList<T>::null()
{
UList<T>::shallowCopy(nullptr, 0);
return *this;
}
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset
(
const UList<T>& list
) noexcept
{
UList<T>::shallowCopy(list);
return *this;
}
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset
(
const UList<T>& list,
const label subSize
)
{
#ifdef FULLDEBUG
list.checkSize(subSize);
#endif
UList<T>::shallowCopy(const_cast<T*>(list.cdata()), subSize);
return *this;
}
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset
(
const UList<T>& list,
const label subSize,
const label startIndex
)
{
#ifdef FULLDEBUG
list.checkRange(startIndex, subSize);
#endif
UList<T>::shallowCopy
(
const_cast<T*>(list.cdata() + startIndex),
subSize
);
return *this;
}
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset
(
const UList<T>& list,
const labelRange& range
)
{
#ifdef FULLDEBUG
// subset0() always produces valid ranges but want to check
// that the input itself was valid
list.checkRange(range.start(), range.size());
#endif
labelRange clamped(range.subset0(list.size()));
UList<T>::shallowCopy
(
const_cast<T*>(list.cdata() + clamped.start()),
clamped.size()
);
return *this;
}
template<class T>
inline Foam::UList<T>& Foam::SubList<T>::reset
(
const labelRange& range,
const UList<T>& list
)
{
#ifdef FULLDEBUG
list.checkRange(range.start(), range.size());
#endif
UList<T>::shallowCopy
(
const_cast<T*>(list.cdata() + range.start()),
range.size()
);
return *this;
return NullObjectRef<SubList<T>>();
}

View File

@ -176,21 +176,13 @@ std::streamsize Foam::UList<T>::byteSize() const
}
template<class T>
Foam::label Foam::UList<T>::find(const T& val) const
{
const auto iter = std::find(this->cbegin(), this->cend(), val);
return (iter != this->cend() ? label(iter - this->cbegin()) : label(-1));
}
template<class T>
Foam::label Foam::UList<T>::find(const T& val, label pos, label len) const
{
if (pos >= 0 && pos < this->size())
{
// Change sub-length to (one-past) end position
// len == -1 (like std::string::npos) - search until end
// Change length to end iterator position
// len == -1 has same meaning as std::string::npos - search until end
if (len > 0) len += pos;
if (len < 0 || len > this->size())
@ -198,16 +190,13 @@ Foam::label Foam::UList<T>::find(const T& val, label pos, label len) const
len = this->size();
}
const auto iter = std::find
(
(this->cbegin() + pos),
(this->cbegin() + len),
val
);
auto iter = (this->cbegin() + pos);
const auto lastIter = (this->cbegin() + len);
if (iter != (this->cbegin() + len))
iter = std::find(iter, lastIter, val);
if (iter != lastIter)
{
return label(iter - this->cbegin());
return label(iter - this->begin());
}
}
@ -218,8 +207,7 @@ Foam::label Foam::UList<T>::find(const T& val, label pos, label len) const
template<class T>
Foam::label Foam::UList<T>::rfind(const T& val, label pos) const
{
// pos == -1 (like std::string::npos) - search from end
// pos == -1 has same meaning as std::string::npos - search from end
if (pos < 0 || pos >= this->size())
{
pos = this->size()-1;

View File

@ -318,27 +318,12 @@ public:
// Search
//- True if the value is contained in the list.
inline bool contains(const T& val) const;
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (no-op if -ve)
// \param len The length of the search region (-ve until the end)
// \return true if found.
inline bool contains(const T& val, label pos, label len = -1) const;
//- Find index of the first occurrence of the value.
// \param val The value to search for
// \return position in list or -1 if not found.
label find(const T& val) const;
//- Find index of the first occurrence of the value.
// \param val The value to search for
// \param pos The first position to examine (no-op if -ve)
// \param pos Initial position to examine (default: 0, -ve no-op)
// \param len The length of the search region (-ve until the end)
// \return position in list or -1 if not found.
label find(const T& val, label pos, label len = -1) const;
label find(const T& val, label pos = 0, label len = -1) const;
//- Find index of the last occurrence of the value.
// Any occurrences after the end pos are ignored.
@ -346,6 +331,13 @@ public:
// \return position in list or -1 if not found.
label rfind(const T& val, label pos = -1) const;
//- Is the value contained in the list?
// \param val The value to search for
// \param pos The first position to examine (default: 0, -ve no-op)
// \param len The length of the search region (-ve until the end)
// \return true if found.
inline bool contains(const T& val, label pos = 0, label len = -1) const;
// Edit
@ -364,9 +356,6 @@ public:
// Copy
//- Copy the pointer and size
inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
//- Copy the pointer and size held by the given UList
inline void shallowCopy(const UList<T>& list) noexcept;
@ -676,11 +665,7 @@ Ostream& operator<<(Ostream& os, const UList<T>& list)
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
}
//- Read std::vector contents from Istream
template<class T>
Istream& operator>>(Istream& is, std::vector<T>& list);
//- Write std::vector to Ostream (via UList)
//- Write std::vector to Ostream. ASCII only, no line-breaks
template<class T>
Ostream& operator<<(Ostream& os, const std::vector<T>& list);

View File

@ -303,14 +303,6 @@ inline std::streamsize Foam::UList<T>::size_bytes() const noexcept
}
template<class T>
inline bool Foam::UList<T>::contains(const T& val) const
{
const auto iter = std::find(this->begin(), this->end(), val);
return (iter != this->end());
}
template<class T>
inline bool Foam::UList<T>::contains(const T& val, label pos, label len) const
{
@ -318,18 +310,6 @@ inline bool Foam::UList<T>::contains(const T& val, label pos, label len) const
}
template<class T>
inline void Foam::UList<T>::shallowCopy
(
T* __restrict__ ptr,
const label len
) noexcept
{
size_ = len;
v_ = ptr;
}
template<class T>
inline void Foam::UList<T>::shallowCopy(const UList<T>& list) noexcept
{

View File

@ -187,7 +187,10 @@ Foam::Istream& Foam::UList<T>::readList(Istream& is)
<< exit(FatalIOError);
}
std::move(elems.begin(), elems.end(), list.begin());
for (label i = 0; i < len; ++i)
{
list[i] = std::move(elems[i]);
}
}
else if (tok.isLabel())
{

View File

@ -26,183 +26,35 @@ License
\*---------------------------------------------------------------------------*/
#include "UList.H"
#include "Istream.H"
#include "Ostream.H"
#include "contiguous.H"
#include "token.H"
#include <vector>
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, std::vector<T>& list)
{
is.fatalCheck(FUNCTION_NAME);
token tok(is);
is.fatalCheck("Istream >> std::vector<T> : reading first token");
if (tok.isCompound())
{
// No compound handling ...
list.clear(); // Clear old contents
FatalIOErrorInFunction(is)
<< "Support for compoundToken - not implemented" << nl
<< exit(FatalIOError);
}
else if (tok.isLabel())
{
// Label: could be int(..), int{...} or just a plain '0'
const label len = tok.labelToken();
// Resize to length required
list.resize(len);
if (is.format() == IOstreamOption::BINARY && is_contiguous<T>::value)
{
// Binary and contiguous
if (len)
{
Detail::readContiguous<T>
(
is,
reinterpret_cast<char*>(list.data()), // data_bytes()
std::streamsize(list.size())*sizeof(T) // size_bytes()
);
is.fatalCheck
(
"Istream >> std::vector<T> : "
"reading binary block"
);
}
}
else if (std::is_same<char, T>::value)
{
// Special treatment for char data (binary I/O only)
const auto oldFmt = is.format(IOstreamOption::BINARY);
if (len)
{
// read(...) includes surrounding start/end delimiters
is.read
(
reinterpret_cast<char*>(list.data()), // data_bytes()
std::streamsize(list.size())*sizeof(T) // size_bytes()
);
is.fatalCheck
(
"Istream >> std::vector<char> : "
"reading binary block"
);
}
is.format(oldFmt);
}
else
{
// Begin of contents marker
const char delimiter = is.readBeginList("List");
if (len)
{
if (delimiter == token::BEGIN_LIST)
{
auto iter = list.begin();
const auto last = list.end();
// Contents
for (/*nil*/; (iter != last); (void)++iter)
{
is >> *iter;
is.fatalCheck
(
"Istream >> std::vector<char> : "
"reading entry"
);
}
}
else
{
// Uniform content (delimiter == token::BEGIN_BLOCK)
T elem;
is >> elem;
is.fatalCheck
(
"Istream >> std::vector<char> : "
"reading the single entry"
);
// Fill with the value
list.assign(list.size(), elem);
}
}
// End of contents marker
is.readEndList("List");
}
}
else if (tok.isPunctuation(token::BEGIN_LIST))
{
// "(...)" : read as bracketed list
// Slightly sub-optimal since it has intermediate resizing,
// however don't expect this as input very often.
list.clear(); // Clear addressing, leave storage intact (probably)
is >> tok;
is.fatalCheck(FUNCTION_NAME);
while (!tok.isPunctuation(token::END_LIST))
{
is.putBack(tok);
// C++17
// is >> list.emplace_back();
// C++11
list.emplace_back();
is >> list.back();
is.fatalCheck
(
"Istream >> std::vector<char> : "
"reading entry"
);
is >> tok;
is.fatalCheck(FUNCTION_NAME);
}
}
else
{
list.clear(); // Clear old contents
FatalIOErrorInFunction(is)
<< "incorrect first token, expected <int> or '(', found "
<< tok.info() << nl
<< exit(FatalIOError);
}
return is;
}
template<class T>
Foam::Ostream& Foam::operator<<(Ostream& os, const std::vector<T>& list)
{
// Use UList for output
UList<T> proxy(const_cast<T*>(list.data()), label(list.size()));
os << proxy;
auto iter = list.cbegin();
const auto last = list.cend();
// Write ascii list contents, no line breaks
os << label(list.size()) << token::BEGIN_LIST;
if (iter != last)
{
os << *iter;
while (++iter != last)
{
os << token::SPACE << *iter;
}
}
os << token::END_LIST;
os.check(FUNCTION_NAME);
return os;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,41 +88,6 @@ template<> struct no_linebreak<word> : std::true_type {};
template<> struct no_linebreak<wordRe> : std::true_type {};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Classification of list/container uniformity.
//- The values can be used with bit-wise \c or reduction
enum uniformity : unsigned char
{
EMPTY = 0, //!< An empty container
UNIFORM = 0x1, //!< Container (non-empty) with identical values
NONUNIFORM = 0x2, //!< Container (non-empty) with different values
MIXED = 0x3 //!< Mixed uniform/non-uniform (eg, after reduction)
};
//- Algorithm to determine list/container uniformity
template<class InputIt>
enum uniformity check_uniformity(InputIt first, InputIt last)
{
if (first == last) return uniformity::EMPTY;
// Like std::all_of() with checking against element 0,
// but without using a lambda with auto type (pre C++14) etc.
const auto& elem0 = *first;
for ((void)++first; (first != last); (void)++first)
{
if (elem0 != *first)
{
return uniformity::NONUNIFORM;
}
}
return uniformity::UNIFORM;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace ListPolicy

View File

@ -399,7 +399,7 @@ Foam::functionObjectList::functionObjectList
errorHandling_(),
digests_(),
indices_(),
warnings_(0),
warnings_(),
time_(runTime),
parentDict_(parentDict),
propsDictPtr_(nullptr),
@ -664,7 +664,7 @@ bool Foam::functionObjectList::execute()
if
(
(errorHandling == error::handlerTypes::WARN)
(errorHandling != error::handlerTypes::IGNORE)
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
)
{
@ -706,11 +706,10 @@ bool Foam::functionObjectList::execute()
{
// Treat IOerror and error identically
unsigned nWarnings;
hadError = true;
if
(
(errorHandling == error::handlerTypes::WARN)
(errorHandling != error::handlerTypes::IGNORE)
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
)
{
@ -732,17 +731,6 @@ bool Foam::functionObjectList::execute()
// Restore previous state
FatalError.throwing(oldThrowingError);
FatalIOError.throwing(oldThrowingIOerr);
// Reset the warning counter (if any)
// if no errors were encountered
if
(
(errorHandling == error::handlerTypes::WARN)
&& !hadError && !warnings_.empty()
)
{
warnings_.erase(objName);
}
}
else
{
@ -869,35 +857,32 @@ bool Foam::functionObjectList::end()
catch (const Foam::error& err)
{
// Treat IOerror and error identically
// If it somehow failed, emit a warning (unless IGNORE).
// Unlike execute(), do not suppress further warning messages
// (we want to know about rare issues)
// but do reset the warnings counter for the next cycle.
unsigned nWarnings;
if (errorHandling != error::handlerTypes::IGNORE)
if
(
(errorHandling != error::handlerTypes::IGNORE)
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
)
{
// Trickery to get original message
err.write(Warning, false);
Info<< nl
<< "--> end() function object '"
<< objName << "'"
<< nl << endl;
<< objName << "'";
if (nWarnings == maxWarnings)
{
Info<< nl << "... silencing further warnings";
}
Info<< nl << endl;
}
}
// Restore previous state
FatalError.throwing(oldThrowingError);
FatalIOError.throwing(oldThrowingIOerr);
// Reset the corresponding warning counter (if any)
if
(
(errorHandling == error::handlerTypes::WARN)
&& !warnings_.empty()
)
{
warnings_.erase(objName);
}
}
}

View File

@ -0,0 +1,154 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::SubDimensionedField
Description
SubDimensionedField is a DimensionedField obtained as a section of another
DimensionedField.
Thus it is itself unallocated so that no storage is allocated or
deallocated during its use. To achieve this behaviour,
SubDimensionedField is derived from SubField rather than Field.
SourceFiles
SubDimensionedFieldI.H
\*---------------------------------------------------------------------------*/
#ifndef SubDimensionedField_H
#define SubDimensionedField_H
#include "Field.H"
#include "SubField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class SubDimensionedField Declaration
\*---------------------------------------------------------------------------*/
template<class Type, class GeoMesh>
class SubDimensionedField
:
public regIOobject,
public SubField<Type>
{
public:
// Public typedefs
typedef typename GeoMesh::Mesh Mesh;
typedef typename Field<Type>::cmptType cmptType;
// Constructors
//- Construct from a SubField
inline SubDimensionedField(const SubField<Type>& sfield);
//- Construct from a UList and size
inline SubDimensionedField
(
const UList<Type>& list,
const label subSize
);
//- Construct from a UList start and end indices
inline SubDimensionedField
(
const UList<Type>& list,
const label subSize,
const label startIndex
);
//- Construct from UList and a (start,size) range.
// The range is subsetted with the list size itself to ensure that the
// result always addresses a valid section of the list.
inline SubDimensionedField
(
const UList<Type>& list,
const labelRange& range
);
//- Construct from UList and a (start,size) range, but bypassing
//- run-time range checking.
inline SubDimensionedField
(
const labelRange& range,
const UList<Type>& list
);
//- Construct as copy
inline SubDimensionedField
(
const SubDimensionedField<cmptType, GeoMesh>& sfield
);
// Member functions
//- Return a null SubDimensionedField
static inline const SubDimensionedField<Type, GeoMesh>& null();
//- Return a component field of the field
inline tmp<DimensionedField<cmptType, GeoMesh>> component
(
const direction d
) const;
//- Return the field transpose (only defined for second rank tensors)
tmp<DimensionedField<Type, GeoMesh>> T() const;
// Member operators
//- Assignment
inline void operator=(const SubDimensionedField<Type, GeoMesh>& rhs);
//- Allow cast to a const DimensionedField<Type, GeoMesh>&
inline operator const DimensionedField<Type, GeoMesh>&() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "SubDimensionedFieldI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,156 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const SubField<Type>& sfield
)
:
SubField<Type>(sfield)
{}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const UList<Type>& list,
const label subSize
)
:
SubField<Type>(list, subSize)
{}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const UList<Type>& list,
const label subSize,
const label startIndex
)
:
SubField<Type>(list, subSize, startIndex)
{}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const UList<Type>& list,
const labelRange& range
)
:
SubField<Type>(list, range)
{}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const labelRange& range,
const UList<Type>& list
)
:
SubField<Type>(range, list)
{}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
(
const SubDimensionedField<Type, GeoMesh>& sfield
)
:
refCount(),
SubField<Type>(sfield)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
inline const Foam::SubDimensionedField<Type, GeoMesh>&
Foam::SubDimensionedField<Type, GeoMesh>::null()
{
return NullObjectRef<SubDimensionedField<Type, GeoMesh>>();
}
template<class Type, class GeoMesh>
inline
Foam::tmp
<
Foam::Field<typename Foam::SubDimensionedField<Type, GeoMesh>::cmptType>
>
Foam::SubDimensionedField<Type, GeoMesh>::component
(
const direction d
) const
{
return
(
reinterpret_cast<const DimensionedField<Type, GeoMesh>&>(*this)
).component(d);
}
template<class Type, class GeoMesh>
inline Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::SubDimensionedField<Type, GeoMesh>::T() const
{
return
(
reinterpret_cast<const DimensionedField<Type, GeoMesh>&>(*this)
).T();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
inline void Foam::SubDimensionedField<Type, GeoMesh>::operator=
(
const SubDimensionedField<Type, GeoMesh>& rhs
)
{
dimensions() = rhs.dimensions();
SubField<Type>::operator=(rhs);
}
template<class Type, class GeoMesh>
inline Foam::SubDimensionedField<Type, GeoMesh>::operator
const Foam::DimensionedField<Type, GeoMesh>&() const
{
return *(reinterpret_cast<const DimensionedField<Type, GeoMesh>*>(this));
}
// ************************************************************************* //

View File

@ -172,7 +172,7 @@ public:
#include "SubFieldI.H"
// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::SubField<Type>

View File

@ -146,9 +146,9 @@ Foam::Ostream& Foam::Matrix<Form, Type>::writeMatrix
) const
{
const Matrix<Form, Type>& mat = *this;
const label len = mat.size(); // Total size (rows * cols)
auto iter = mat.cbegin(); // element-wise iterator
// The total size
const label len = mat.size();
// Rows, columns size
os << mat.nRows() << token::SPACE << mat.nCols();
@ -163,101 +163,73 @@ Foam::Ostream& Foam::Matrix<Form, Type>::writeMatrix
os.write(mat.cdata_bytes(), mat.size_bytes());
}
}
else if (len > 1 && is_contiguous<Type>::value && mat.uniform())
{
// Two or more entries, and all entries have identical values.
os << token::BEGIN_BLOCK << *iter << token::END_BLOCK;
}
else if
(
(len <= 1 || !shortLen)
|| (len <= shortLen && is_contiguous<Type>::value)
)
{
// Single-line output (entire matrix)
// Begin matrix
os << token::BEGIN_LIST;
// Loop over rows
for (label i = 0; i < mat.nRows(); ++i)
{
// Begin row
os << token::BEGIN_LIST;
// Write row
for (label j = 0; j < mat.nCols(); ++j)
{
if (j) os << token::SPACE;
os << *iter;
++iter;
}
// End row
os << token::END_LIST;
}
// End matrix
os << token::END_LIST;
}
else if
(
(mat.nCols() <= 1 || !shortLen)
|| (mat.nCols() <= shortLen && is_contiguous<Type>::value)
)
{
// Multi-line matrix, single-line rows
// Begin matrix
os << nl << token::BEGIN_LIST;
// Loop over rows
for (label i = 0; i < mat.nRows(); ++i)
{
// Begin row
os << nl << token::BEGIN_LIST;
// Write row
for (label j = 0; j < mat.nCols(); ++j)
{
if (j) os << token::SPACE;
os << *iter;
++iter;
}
// End row
os << token::END_LIST;
}
// End matrix
os << nl << token::END_LIST << nl;
}
else
{
// Multi-line output
// Begin matrix
os << nl << token::BEGIN_LIST;
// Loop over rows
for (label i=0; i < mat.nRows(); ++i)
if (len)
{
// Begin row
os << nl << token::BEGIN_LIST;
const Type* v = mat.cdata();
// Write row
for (label j = 0; j < mat.nCols(); ++j)
// Can the contents be considered 'uniform' (ie, identical)
if (len > 1 && is_contiguous<Type>::value && mat.uniform())
{
os << nl << *iter;
++iter;
// Two or more entries, and all entries have identical values.
os << token::BEGIN_BLOCK << v[0] << token::END_BLOCK;
}
else if (len < shortLen && is_contiguous<Type>::value)
{
// Write start contents delimiter
os << token::BEGIN_LIST;
// End row
os << nl << token::END_LIST;
label idx = 0;
// Loop over rows
for (label i = 0; i < mat.nRows(); ++i)
{
os << token::BEGIN_LIST;
// Write row
for (label j = 0; j < mat.nCols(); ++j)
{
if (j) os << token::SPACE;
os << v[idx++];
}
os << token::END_LIST;
}
// Write end of contents delimiter
os << token::END_LIST;
}
else
{
// Write start contents delimiter
os << nl << token::BEGIN_LIST;
label idx = 0;
// Loop over rows
for (label i=0; i < mat.nRows(); ++i)
{
os << nl << token::BEGIN_LIST;
// Write row
for (label j = 0; j < mat.nCols(); ++j)
{
os << nl << v[idx++];
}
os << nl << token::END_LIST;
}
// Write end of contents delimiter
os << nl << token::END_LIST << nl;
}
}
else
{
// Empty matrix
os << token::BEGIN_LIST << token::END_LIST << nl;
}
// End matrix
os << nl << token::END_LIST << nl;
}
os.check(FUNCTION_NAME);

View File

@ -150,9 +150,6 @@ public:
//- Resize the matrix preserving the elements
inline void resize(const label m);
//- Resize the matrix \em without preserving existing content
inline void resize_nocopy(const label n);
//- Resize the matrix preserving the elements (compatibility)
inline void resize(const label m, const label n);

View File

@ -218,13 +218,6 @@ inline void Foam::SquareMatrix<Type>::resize(const label m)
}
template<class Type>
inline void Foam::SquareMatrix<Type>::resize_nocopy(const label m)
{
Matrix<SquareMatrix<Type>, Type>::resize_nocopy(m, m);
}
template<class Type>
inline void Foam::SquareMatrix<Type>::resize(const label m, const label n)
{

View File

@ -157,7 +157,7 @@ Foam::cyclicAMIFvPatchField<Type>::cyclicAMIFvPatchField
cyclicAMIPatch_(ptf.cyclicAMIPatch_),
sendRequests_(0),
recvRequests_(0),
patchNeighbourFieldPtr_(ptf.patchNeighbourFieldPtr_)
patchNeighbourFieldPtr_(ptf.patchNeighbourFieldPtr_.clone())
{
if (debug && !ptf.all_ready())
{
@ -180,7 +180,7 @@ Foam::cyclicAMIFvPatchField<Type>::cyclicAMIFvPatchField
cyclicAMIPatch_(ptf.cyclicAMIPatch_),
sendRequests_(0),
recvRequests_(0),
patchNeighbourFieldPtr_(nullptr)
patchNeighbourFieldPtr_(ptf.patchNeighbourFieldPtr_.clone())
{
if (debug && !ptf.all_ready())
{
@ -655,7 +655,7 @@ void Foam::cyclicAMIFvPatchField<Type>::updateInterfaceMatrix
const labelUList& nbrFaceCells =
lduAddr.patchAddr(cyclicAMIPatch_.neighbPatchID());
pnf = Field<Type>(psiInternal, nbrFaceCells);
Field<Type> pnf(psiInternal, nbrFaceCells);
// Transform according to the transformation tensors
transformCoupleField(pnf);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,11 +61,10 @@ bool Foam::functionObjects::Lambda2::calc()
)
);
// (JH:p. 76-78)
return store
(
resultName_,
eigenValues(SSplusWW)().component(vector::Y)
-eigenValues(SSplusWW)().component(vector::Y)
);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2020-2023 OpenCFD Ltd.
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,39 +37,30 @@ Description
Operands:
\table
Operand | Type | Location
input | volVectorField | \<case\>/\<time\>/\<inpField\>
input | volVectorField | $FOAM_CASE/\<time\>/\<inpField\>
output file | - | -
output field | volScalarField | \<case\>/\<time\>/\<outField\>
output field | volScalarField | $FOAM_CASE/\<time\>/\<outField\>
\endtable
References:
\verbatim
Governing equation (tag:JH):
Jeong, J., & Hussain, F. (1995).
On the identification of a vortex.
Journal of Fluid Mechanics, 285, 69-94.
DOI:10.1017/S0022112095000462
\endverbatim
Usage
Minimal example by using \c system/controlDict.functions:
\verbatim
Lambda21
{
// Mandatory entries
// Mandatory entries (unmodifiable)
type Lambda2;
libs (fieldFunctionObjects);
// Inherited entries
// Optional (inherited) entries
...
}
\endverbatim
where the entries mean:
\table
Property | Description | Type | Reqd | Deflt
type | Type name: Lambda2 | word | yes | -
libs | Library name: fieldFunctionObjects | word | yes | -
Property | Description | Type | Req'd | Dflt
type | Type name: Lambda2 | word | yes | -
libs | Library name: fieldFunctionObjects | word | yes | -
\endtable
The inherited entries are elaborated in:
@ -81,6 +72,12 @@ Usage
postProcess -func Lambda2
\endverbatim
See also
- Foam::functionObject
- Foam::functionObjects::fvMeshFunctionObject
- Foam::functionObjects::fieldExpression
- ExtendedCodeGuide::functionObjects::field::Lambda2
SourceFiles
Lambda2.C

View File

@ -3344,33 +3344,24 @@ void Foam::meshRefinement::zonify
<< nl << endl;
// Collect per surface the -insidePoint -cellZone
// Usually only a single inside point per surface so no clever
// counting - just use DynamicField
DynamicField<point> insidePoints(locationSurfaces.size());
DynamicList<label> insidePointCellZoneIDs(locationSurfaces.size());
pointField insidePoints(locationSurfaces.size());
labelList insidePointCellZoneIDs(locationSurfaces.size(), -1);
forAll(locationSurfaces, i)
{
const label surfI = locationSurfaces[i];
const auto& surfInsidePoints = surfZones[surfI].zoneInsidePoints();
label surfI = locationSurfaces[i];
insidePoints[i] = surfZones[surfI].zoneInsidePoint();
const word& name = surfZones[surfI].cellZoneName();
label zoneID = -1;
if (name != "none")
{
zoneID = mesh_.cellZones().findZoneID(name);
label zoneID = mesh_.cellZones().findZoneID(name);
if (zoneID == -1)
{
FatalErrorInFunction
<< "Specified non-existing cellZone " << name
<< " for surface " << surfaces_.names()[surfI]
<< "problem"
<< abort(FatalError);
}
}
for (const auto& pt : surfInsidePoints)
{
insidePoints.append(pt);
insidePointCellZoneIDs.append(zoneID);
insidePointCellZoneIDs[i] = zoneID;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -83,7 +83,7 @@ Foam::surfaceZonesInfo::surfaceZonesInfo
faceZoneNames_(),
cellZoneName_(),
zoneInside_(NONE),
zoneInsidePoints_(),
zoneInsidePoint_(point::min),
faceType_(INTERNAL)
{
const label nRegions = surface.regions().size();
@ -156,31 +156,9 @@ Foam::surfaceZonesInfo::surfaceZonesInfo
zoneInside_ = areaSelectionAlgoNames[method];
if (zoneInside_ == INSIDEPOINT)
{
const bool foundPoints = surfacesDict.readIfPresent
(
"insidePoints",
zoneInsidePoints_,
keyType::LITERAL
);
if (foundPoints)
{
if (surfacesDict.found("insidePoint", keyType::LITERAL))
{
FatalIOErrorInFunction(surfacesDict)
<< "Cannot supply both 'insidePoint'"
<< " and 'insidePoints'" << exit(FatalIOError);
}
}
else
{
zoneInsidePoints_ = pointField
(
1,
surfacesDict.get<point>("insidePoint", keyType::LITERAL)
);
}
surfacesDict.readEntry("insidePoint", zoneInsidePoint_);
}
}
else
{
@ -238,14 +216,14 @@ Foam::surfaceZonesInfo::surfaceZonesInfo
const wordList& faceZoneNames,
const word& cellZoneName,
const areaSelectionAlgo& zoneInside,
const pointField& zoneInsidePoints,
const point& zoneInsidePoint,
const faceZoneType& faceType
)
:
faceZoneNames_(faceZoneNames),
cellZoneName_(cellZoneName),
zoneInside_(zoneInside),
zoneInsidePoints_(zoneInsidePoints),
zoneInsidePoint_(zoneInsidePoint),
faceType_(faceType)
{}
@ -255,7 +233,7 @@ Foam::surfaceZonesInfo::surfaceZonesInfo(const surfaceZonesInfo& surfZone)
faceZoneNames_(surfZone.faceZoneNames()),
cellZoneName_(surfZone.cellZoneName()),
zoneInside_(surfZone.zoneInside()),
zoneInsidePoints_(surfZone.zoneInsidePoints()),
zoneInsidePoint_(surfZone.zoneInsidePoint()),
faceType_(surfZone.faceType())
{}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2015,2023 OpenCFD Ltd.
Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,7 +38,7 @@ SourceFiles
#define surfaceZonesInfo_H
#include "Enum.H"
#include "pointField.H"
#include "point.H"
#include "word.H"
#include "PtrList.H"
#include "labelList.H"
@ -110,7 +110,7 @@ private:
areaSelectionAlgo zoneInside_;
//- If zoneInside=location gives the corresponding inside point
pointField zoneInsidePoints_;
point zoneInsidePoint_;
//- Per 'interface' surface :
// What to do with outside
@ -142,7 +142,7 @@ public:
const wordList& faceZoneNames,
const word& cellZoneNames,
const areaSelectionAlgo& zoneInside,
const pointField& zoneInsidePoints,
const point& zoneInsidePoints,
const faceZoneType& faceType
);
@ -179,16 +179,10 @@ public:
return zoneInside_;
}
//- Get specified inside location for surfaces with a cellZone
const point zoneInsidePoint() const
{
return zoneInsidePoints_[0];
}
//- Get specified inside locations for surfaces with a cellZone
const pointField& zoneInsidePoints() const
const point& zoneInsidePoint() const
{
return zoneInsidePoints_;
return zoneInsidePoint_;
}
//- How to handle face of surfaces with a faceZone

View File

@ -1389,7 +1389,6 @@ Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
(
face2i != facei
&& surfaceIndex[face2i] != -1
&& cutter.faceLevel(face2i) > cLevel
)
{
// Get outwards pointing normal

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -756,7 +756,7 @@ Foam::Ostream& Foam::operator<<
const labelUList& interpolationCells = e.interpolationCells();
const labelListList& cellStencil = e.cellStencil();
labelList nCells(cellCellStencil::count(5, cellTypes));
labelList nCells(cellCellStencil::count(4, cellTypes));
label nInvalidInterpolated = 0;
label nLocal = 0;
@ -808,7 +808,7 @@ Foam::Ostream& Foam::operator<<
reduce(nRemote, sumOp<label>());
reduce(nInvalidInterpolated, sumOp<label>());
os << "Overset analysis : nCells : "
Info<< "Overset analysis : nCells : "
<< returnReduce(cellTypes.size(), sumOp<label>()) << nl
<< incrIndent
<< indent << "calculated : " << nCells[cellCellStencil::CALCULATED]
@ -818,16 +818,9 @@ Foam::Ostream& Foam::operator<<
<< " mixed local/remote:" << nMixed
<< " remote:" << nRemote
<< " special:" << nInvalidInterpolated << ")" << nl
<< indent << "hole : " << nCells[cellCellStencil::HOLE] << nl;
if (nCells[cellCellStencil::SPECIAL] || nCells[cellCellStencil::POROUS])
{
os << indent << "special : " << nCells[cellCellStencil::SPECIAL]
<< nl
<< indent << "porous : " << nCells[cellCellStencil::POROUS]
<< nl;
}
os << decrIndent << endl;
<< indent << "hole : " << nCells[cellCellStencil::HOLE] << nl
<< indent << "special : " << nCells[cellCellStencil::SPECIAL] << nl
<< decrIndent << endl;
return os;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2023 OpenCFD Ltd.
Copyright (C) 2014-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1100,7 +1100,16 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
}
}
Info << this->info();
{
labelList nCells(count(3, cellTypes_));
Info<< "Overset analysis : nCells : "
<< returnReduce(cellTypes_.size(), sumOp<label>()) << nl
<< incrIndent
<< indent << "calculated : " << nCells[CALCULATED] << nl
<< indent << "interpolated : " << nCells[INTERPOLATED] << nl
<< indent << "hole : " << nCells[HOLE] << nl
<< decrIndent << endl;
}
return true;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1136,8 +1136,60 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
// Print some stats
Info<< this->info();
{
labelList nCells(count(3, cellTypes_));
label nLocal = 0;
label nMixed = 0;
label nRemote = 0;
forAll(interpolationCells_, i)
{
label celli = interpolationCells_[i];
const labelList& slots = cellStencil_[celli];
bool hasLocal = false;
bool hasRemote = false;
forAll(slots, sloti)
{
if (slots[sloti] >= mesh_.nCells())
{
hasRemote = true;
}
else
{
hasLocal = true;
}
}
if (hasRemote)
{
if (!hasLocal)
{
nRemote++;
}
else
{
nMixed++;
}
}
else if (hasLocal)
{
nLocal++;
}
}
Info<< "Overset analysis : nCells : "
<< returnReduce(cellTypes_.size(), sumOp<label>()) << nl
<< incrIndent
<< indent << "calculated : " << nCells[CALCULATED] << nl
<< indent << "interpolated : " << nCells[INTERPOLATED]
<< " (from local:" << returnReduce(nLocal, sumOp<label>())
<< " mixed local/remote:" << returnReduce(nMixed, sumOp<label>())
<< " remote:" << returnReduce(nRemote, sumOp<label>()) << ")" << nl
<< indent << "hole : " << nCells[HOLE] << nl
<< decrIndent << endl;
}
DebugInfo<< FUNCTION_NAME << " : Finished analysis" << endl;
// Tbd: detect if anything changed. Most likely it did!

View File

@ -1,5 +1,5 @@
#-------------------------------*- makefile -*---------------------------------
WM_VERSION = OPENFOAM=2307
WM_VERSION = OPENFOAM=2306
AR = ar
ARFLAGS = cr