Commit Graph

1459 Commits

Author SHA1 Message Date
Mark Olesen
b1f9fe9d79 STYLE: adjust ITstream naming for empty_stream() 2023-11-18 15:24:15 +01:00
Mark Olesen
636a654f4a ENH: add standard _byte access for exprValue
- allows UPstream::broadcast and direct read/write

- add operator== for exprValue
2023-11-18 15:24:01 +01:00
Mark Olesen
a81d757721 COMP: add missing include for SortList
- extend test to include partition + sort
2023-11-14 22:54:44 +01:00
Mark Olesen
3524a6f4df FIX: getLine() line counting (adjustment to 459aaad0f9)
ENH: return ITstream::emptyStream() in a 'bad' state

- to indicate that it is invalid for reading
2023-11-14 22:54:44 +01:00
Mark Olesen
269be2f4ea ENH: provide Time::NewGlobalTime factory methods (#3007)
- avoids clutter of argList::envGlobalPath() ...

ENH: allow temporary overwriting of output writeFormat

- allows switching for particular output routines

COMP: explicitly use TimePaths methods with Time

- this simplifies any overloading done at a later stage
2023-11-07 10:33:47 +01:00
Mark Olesen
07dcdefa02 ENH: support creation of boundaries/zones from list of entries
- this makes it easier to split creation into a two-stage process
  as required

- extend handling for polyBoundaryMeshEntries, faBoundaryMeshEntries
  with more functionality. Ensure that these are never registered.

ENH: addition writeEntry methods for polyBoundaryMesh

- simplifies streaming and collating into other files

ENH: polyMesh rereading - update owner/neighbour header information

- this avoids accidentally reading the "cells" file if the mesh has
  been created with NO_READ and then updated

STYLE: less vertical space when outputting empty PtrList
2023-11-07 10:33:47 +01:00
Mark Olesen
98246a438e ENH: simplify calling of decomposition, support CompactListList
- combined most of the unweighted and weighted decomposition routines
  such that an empty weight field is treated as uniform weighting.
  This allows default parameters and cuts down on the number of
  decompose methods.

- for topology-driven decomposition, it is now possible to pass in the
  owner/neighbour connectivity as a CompactListList directly instead
  of first creating a labelListList (which was internally repacked into
  a CompactListList in many cases).
  However, multiLevelDecomp still uses unpacking (to avoid a larger
  reworking of code).

- support direct creation of some methods (eg, random, scotch etc)
  without a dictionary

- fix incorrect neighbour face weighting (fixes #3019)

ENH: relocate calcCellCells from decompositionMethod to globalMeshData

- makes it more universally available
2023-11-07 10:33:47 +01:00
Mark Olesen
507805c330 ENH: partly align globalIndex and CompactListList methods
- CompactListList::size() corresponds to the number of sub-lists
  whereas globalIndex::size() corresponds to the totalSize().
  This difference can lead to potential coding errors when switching
  between pure addressing (eg globalIndex) and addressing with content
  (eg, CompactListList).

  Within the source tree, there are no longer any occurances of
  globalIndex::size() but it is nonetheless unsafe to change its
  meaning now. Instead provide a commonly named length() method that
  corresponds to the natural length: ie, the number of offsets minus 1
  (with guards).

- add CompactListList::writeMatrix for writing the compact contents
  in an unpacked form (eg, for debugging) without actually needing to
  unpack into storage.

- provide globalIndex::whichProcID() two-parameter version
  with myProcNo as the first argument.
  Symmetric with isLocal etc, useful when using a communicator
  that is not worldComm.
2023-11-07 10:33:47 +01:00
Mark Olesen
08a9b03891 ENH: polyBoundaryMesh additional faces() and faceOwner() slice methods
- return a subList view of the mesh faces, owners
2023-11-07 10:33:47 +01:00
Mark Olesen
546b204793 COMP: split endian.H into foamEndianFwd.H and foamEndian.H
- usually only need big/little defines (which are now in the Fwd)
  and rarely need byte-swapping.

  Provide endian.H compatibility include, but foamEndianFwd.H or
  foamEndian.H to avoid potential name clashes.
2023-11-07 10:33:47 +01:00
Mark Olesen
98ccb7df6b ENH: extend VectorSpace traits to include pTraits_cmptType
- The pTraits_cmptType returns the data type of 'cmptType' (for
  arithmetic and VectorSpace types) or is simply a pass-through.

  This can be combined with the pTraits_nComponents for casting.
  For example,

  function
  (
      reinterpret_cast<pTraits_cmptType<Type>::type*>(buf.data()),
      (buf.size()/pTraits_nComponents<Type>::value)
  );

ENH: extend Foam::identityOp so support array indexing (pass-through)
2023-11-07 10:33:47 +01:00
Mark Olesen
dc7d0ffeaa ENH: add face/triFace find(edge) method (#3004)
- returns the edge index within the face, -1 if not found
2023-10-27 13:48:18 +02:00
Mark Olesen
b34793c392 ENH: additional globalIndex methods and helpers
- single() method : simply tests if the globalIndex has nProcs == 1,
  which is typically from a gatherNone invocation.
  For example,

     globalIndex gi;
     if (...) gi.reset(localSize);
     else     gi.reset(globalIndex::gatherNone{}, localSize);

     // later...
     const label begin = (gi.single() ? 0 : gi.localStart());
     const label count = (gi.single() ? gi.totalSize() : gi.localSize());

- add front() and back() methods to return the begin/end ranges,
  and begin_value(), end_value() - as per labelRange.

- make more methods noexcept

- calcOffset(), calcRange() helper functions to determine
  the processor-local of a numbering range without the overhead of
  creating a list of offsets.

  For example,

     label myOffset = globalIndex::calcOffset(mesh.nCells());
     labelRange mySlice = globalIndex::calcRange(mesh.nCells());

- add globalIndex localEnd() as per CompactListList method

STYLE: align looping constructs in CompactListList with List

- make more methods noexcept
2023-10-26 14:03:39 +02:00
Mark Olesen
d9f0587416 ENH: promote ListOps::identity to Foam::identity
- becoming more frequently used and there is no ambiguity in calling
  parameters either - identity(label) vs identity(labelUList&).

  Provide both int32 and int64 versions.
2023-10-26 11:24:57 +02:00
Mark Olesen
1faa143a7c ENH: expose fieldNames() selection for sampledSets/sampledSurfaces
- consistent with probes. Allows reporting/querying
2023-10-26 09:19:18 +02:00
Mark Olesen
0343ab00f3 DOC: add application/test/README.md
- extraction of Description from the respective tests.
  Relatively incomplete

  Uses the `application/tests/get-descriptions` extractor
2023-10-24 10:57:49 +02:00
Mark Olesen
870c6a6924 TEST: add standalone test application: Test-surface-sampling 2023-10-24 10:57:22 +02:00
Mark Olesen
1476de89ee ENH: add unary functor for Foam::zero
- acts somewhat like an identity op that 'swallows' its parameter
  and maps back to zero.
2023-10-23 15:28:34 +02:00
Mark Olesen
fb26fcedfc STYLE: use getOrDefault instead of lookupOrDefault
- now mark methods with strict deprecation, to make it easier to find
  their use but without adding extra compilation noise for others

ENH: minor update for Enum methods and iterator

- add warnOnly (failsafe) option for readEntry and getOrDefault

- add good() method to Enum iterator (simliar to HashTable)

- replace unused/fragile Enum find() methods with iterator return
  that can be used more generally
2023-10-16 14:19:19 +02:00
Mark Olesen
3562565995 ENH: minor updates for globalIndex
- explicit use of UPstream::worldComm in globalIndex methods
  for more clarity

- adjust method declaration ordering:
  de-emphasize the processor-local convenience methods

- consistent use of leading tag dispatch,
  remove unused enum-based dispatch tag

- add begin()/cbegin() with offset (as per List containers)

BUG: missing use of communicator in globalIndex gatherNonLocal

- does not affect any existing code (which all use worldComm anyhow)
2023-10-13 14:44:18 +02:00
Mark Olesen
0fb2c8eb1c STYLE: update applications/tests to use SpanStream/CharStream 2023-10-11 18:11:37 +00:00
Mark Olesen
3693d61e6c ENH: refine SpanStream and CharStream methods
- support std::string_view (c++17) or span view (older c++) of stream
  buffer contents. This simplifies formatting + reparsing.

  Example,

      OCharStream os;
      os << ...;

      ISpanStream is(os.view());
      is >> ...;

- additional release() method for ICharStream, OCharStream
  that returns the contents as a DynamicList<char> and resets the stream.

- provide a str() method for API compatibility with older
  std::ostringstream etc.
2023-10-11 18:11:37 +00:00
Mark Olesen
b76595df42 ENH: improve stream output of std::string etc.
- change write(const string&) to write(const std::string&).
  This allows output of std::string without an intermediate copy.

- additional writeQuoted method to handle range of char data:

     writeQuoted(const char* str, std::streamsize len, bool)

  This helps with supporting string_view and span<char>

- add operator<< for stdFoam::span<char> and std::string_view (c++17)

- avoid duplicate code in OBJstream

STYLE: add override keyword for IO stream methods
2023-10-11 18:11:37 +00:00
Mark Olesen
96c9bf8615 ENH: add List::resize_unsafe(label)
- changes the addressed list size without affecting list allocation.
  Can be useful for the following type of coding pattern:

  - pre-allocate a List with some max content length
  - populate with some content (likely not the entire pre-allocated size)
  - truncate the list to the length of valid content
  - process the List
  - discard the List

  Since the List is being discarded, using resize_unsafe() instead of
  resize() avoids an additional allocation with the new size and
  copying/moving of the elements.

  This programming pattern can also be used when the List is being
  returned from a subroutine, and carrying about a bit of unused memory
  is less important than avoiding reallocation + copy/move.

  If used improperly, it can obviously result in addressing into
  unmanaged memory regions (ie, 'unsafe').
2023-10-11 18:11:37 +00:00
Mark Olesen
ce1260cf70 ENH: improve DynamicList shrink and swapping
- shrink_to_fit()
  corresponds to std::vector naming.
  For DynamicList it is a *binding* request.

- shrink_unsafe()
  simply adjusts the capacity() to match the
  current size() without forcing a re-allocation.

  Useful when collapsing to a non-dynamic list to avoid reallocation
  and copying contents. The memory cleanup will still occur properly
  at a later stage.

- DynamicList::swap(List&)
  simple recovery of content into a non-dynamic List that also
  ensures that the capacity is correctly updated.

STYLE: promote List::capacity() to public visibility (like std::vector)

STYLE: remove unused expandStorage() method

- simply a wrapper for resize(capacity())
2023-10-11 18:11:37 +00:00
Mark Olesen
1d43e45fdd ENH: add test application for fileHander writing
COMP: update applications/test
2023-10-11 18:11:37 +00:00
Mark Olesen
1af40e7dfe STYLE: remove unused (transitional) methods from CircularBuffer
- old methods (and class) were not widely used
2023-10-11 18:11:37 +00:00
Mark Olesen
0250a1b0bb ENH: support List sub-slice searching, use std::find()
- support UList shallowCopy with pointer/size
  (eg, for slicing into or from span)

ENH: add SubList::reset() functionality

- allows modification of a SubList after construction.
  Previously a SubList had an immutable location after construction
  and there was no way to shift or change its location.

BUG: missed special handling for DynamicList<char>::readList (fixes #2974)

- equivalent to List<char>::readList, in which the stream is
  temporarily toggled from ASCII to BINARY when reading in a List of
  char data.
  This specialization was missed when DynamicList<T>::readList() was
  fully implemented.
2023-09-05 10:15:17 +02:00
Mark Olesen
aa1b6d9cbd ENH: add ListPolicy uniformity enumeration and algorithm
- defines values for EMPTY, UNIFORM, NONUNIFORM and MIXED
  that allow bitwise OR reduction and provide an algorithm
  for calculating uniformity

ENH: consolidate more efficient uniformity checks in PackedList

ENH: improve linebreak handling when outputting small matrices
2023-09-04 14:40:33 +02:00
Mark Olesen
459aaad0f9 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-09-01 14:44:49 +00:00
Mark Olesen
a341d09afc 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-09-01 14:44:49 +00:00
Mark Olesen
750d9084d4 ENH: improve addressing into labelRanges (#2933)
- totalSize() returns retrieve the linear (total) size
  (naming as per globalIndex)
- operator[] retrieves the referenced value (linear indexing)
- labels() returns a flattened labelList (as per labelRange itself)
2023-08-30 13:39:16 +00:00
Mark Olesen
9d291ab4cc ENH: add Pstream::broadcastList()
- broadcasts list contiguous content as a two-step process:
    1. broadcast the size, and resize for receiver list
    2. broadcast contiguous contents (if non-empty)

  This avoids serialization/de-serialization memory overhead but at
  the expense of an additional broadcast call.
  The trade-off of the extra broadcast of the size will be less
  important than avoiding a memory peak for large contiguous mesh data.

REVERT: unstable MPI_Mprobe/MPI_Mrecv on intelmpi + PMI-2 (#2796)

- partial revert of commit c6f528588b, for NBX implementation.
  Not yet flagged as causing errors here, but eliminated for
  consistency.
2023-08-29 11:24:16 +02:00
Mark Olesen
778796853d CONFIG: enable use of stricter deprecation warnings
- selected with '+strict' in WM_COMPILE_CONTROL or 'wmake -strict', it
  enables the FOAM_DEPRECATED_STRICT() macro, which can be used to
  mark methods that are implicitly deprecated, but are not yet marked
  as full deprecated (eg, API modification is too recent, generates
  too many warnings).  Can be considered a developer option.
2023-08-21 08:39:36 +02:00
Mark Olesen
97668eab26 STYLE: update noexcept and default construct for signals
- eliminate ClassName in favour of simple debug

- include Apple-specific FPE handling after local definition
  to allow for more redefinitions

COMP: remove stray <csignal> includes
2023-08-18 15:42:18 +02:00
Mark Olesen
03ca52b036 ENH: PtrList, PtrDynList, HashPtrTable try_emplace() method
- naming like std::map::try_emplace(), it behaves like emplace_set()
  if there is no element at the given location otherwise a no-op

ENH: reuse existing HashPtrTable 'slot' when setting pointers

- avoids extra HashTable operations
2023-08-18 13:55:32 +02:00
Mark Olesen
268de43afc ENH: provision for delayed reading of compound tokens (#2953)
- the construction of compound tokens is now split into two stages:
    - default construct
    - read contents
  This permits a larger variety of handling.

- the new token::readCompoundToken(..) method allows for simpler
  more failsafe invocations.

- forward resize(), read() methods for compound tokens to support
  separate read and population.
  Top-level refCompoundToken() method for modify access.

ENH: split off a private readCompoundToken() method within ISstream

- this allows overloading and alternative tokenisation handling for
  derived classes
2023-08-16 16:22:17 +02:00
Mark Olesen
43f8b477b7 ENH: additional ITstream access/manipulate methods
- simplifies iteration of ITstream using nRemainingTokens() and skip()
  methods or directly as a list of tokens.

  The currentToken() method returns const or non-const access to
  the token at the current tokenIndex.

  The peekToken(label) method provides failsafe read access to tokens
  at given locations.

ENH: add primitiveEntry construct with moving a single token
2023-08-16 16:22:17 +02:00
Mark Olesen
2422e6f061 ENH: use std algorithms for copy/move/compare within List containers
ENH: add List resize_fill variant. Fuses resize_nocopy + uniform fill

COMP: avoid cast ambiguity when assigning Foam::zero to UList<char>
2023-08-16 12:28:12 +02:00
Mark Olesen
eeb9d144e3 STYLE: qualify Swap with Foam:: prefix (visibility)
- drop unnecessary Foam::Swap specializations when MoveConstructible
  and MoveAssignable already apply. The explicit redirect to swap
  member functions was needed before proper move semantics where
  added.

  Removed specializations: autoPtr, refPtr, tmp, UList.
  Retained specialization: DynamicList, FixedList.

     Special handling for DynamicList is only to accommodate dissimilar
     sizing template parameters (which probably doesn't occur in
     practice).
     Special handling for FixedList to apply element-wise swapping.

- use std::swap for primitives. No need to mask with Foam::Swap wrapper
2023-08-16 12:28:09 +02:00
Mark Olesen
fabd3f4e0c ENH: eliminate reliance on SLList during reading
- fully implement DynamicList::readList() instead of simply
  redirecting to List::readList(). This also benefits DynamicField.
  Leverage DynamicList reading to simplify and improve CircularBuffer
  reading.

- bracket lists are now read chunk-wise instead of using a
  singly-linked list. For integral and vector-space types
  (eg, scalar, vector, etc) this avoids intermediate allocations
  for each element.

ENH: add CircularBuffer emplace_front/emplace_back

STYLE: isolate to-be-deprecated construct/assign forms

- still have construct/assign FixedList from a C-array.
  This is not really needed, can use std::initializer_list

- still have construct/assign List from SLList.
  Prefer to avoid these in the future.

DEFEATURE: remove construct/assign FixedList from SLList

- never used

DEFEATURE: remove move construct/assign List from SLList

- now unused. Retain copy construct/assign from SLList for transition
  purposes.
2023-08-16 12:27:04 +02:00
Mark Olesen
97a42df7ba ENH: add VectorSpace trait tests and evaluations
- is_vectorspace :
  test existence and non-zero value of the Type 'rank' static variable

- pTraits_rank :
  value of 'rank' static variable (if it exists), 0 otherwise

- pTraits_nComponents :
  value of 'nComponents' static variable (if it exists), 1 otherwise

- pTraits_has_zero :
  test for pTraits<T>::zero member, which probably means that it also
  has one, min, max members as well

Note that these traits are usable with any classes. For example,

  - is_vectorspace<std::string>::value  ==> false
  - pTraits_nComponents<std::string>::value  ==> 1
  - pTraits<std::string>::nComponents  ==> fails to compile

  Thus also allows testing pTraits_rank<...>::value with items
  for which pTraits<...>::rank fails to compile.

  Eg, cyclicAMIPolyPatch::interpolate called by FaceCellWave with a
  wallPoint.

     pTraits<wallPoint>::rank ==> fails to compile
     is_vectorspace<wallPoint>::value ==> false

GIT: relocate ListLoopM.H to src/OpenFOAM/fields/Fields (future isolation)
2023-08-10 10:38:39 +02:00
Mark Olesen
129b738136 ENH: define IOobjectList::csorted(), deprecate some sorted() const methods
- prefer csorted() method for const access since it ensures that the
  return values are also const pointers (for example) even if
  the object itself can be accessed as a non-const.

- the csorted() method already existed for HashTable and
  objectRegistry, but now added to IOobjectList for method name
  consistency (even although the IOobjectList only has a const-access
  version)

ENH: objectRegistry with templated strict lookup

- for lookupClass and csorted/sorted. Allows isType restriction as a
  compile-time specification.
2023-07-31 20:11:32 +02:00
Mark Olesen
945e3e41b1 ENH: more consistent use of good() or direct testing instead valid() 2023-07-27 16:52:03 +02:00
Mark Olesen
63258d0b33 ENH: refine PtrList emplace method, add emplace for autoPtr/refPtr...
* resize_null() methods for PtrList variants
  - for cases where an existing PtrList needs a specific size and
    but not retain any existing entries.

    Eg,
        ptrs.resize_null(100);

    vs.   ptrs.free();     ptr.resize(100);
    or    ptr.resize(100); ptrs.free();

* remove stored pointer before emplacing PtrList elements
  - may reduce memory peaks

* STYLE: static_cast of (nullptr) instead of reinterpret_cast of (0)

* COMP: implement emplace_set() for PtrDynList
  - previously missing, which meant it would have leaked through to the
    underlying PtrList definition

* emplace methods for autoPtr, refPtr, tmp
  - applies reset() with forwarding arguments.
    For example,

        tmp<GeoField> tfld = ...;

    later...

        tfld.emplace(io, mesh);

    vs.
        tfld.reset(new GeoField(io, mesh));
    or
        tfld.reset(tmp<GeoField>::New(io, mesh));

    The emplace() obviously has reduced typing, but also allows the
    existing stored pointer to be deleted *before* creating its
    replacement (reduces memory peaks).
2023-07-27 16:52:03 +02:00
Mark Olesen
32903d337e ENH: add slice/range support to UPstream::waitSomeRequests()
- this simplifies polling receives and allows separation from
  the sends

ENH: add UPstream::removeRequests(pos, len)

- cancel/free of outstanding requests and remove segment from the
  internal list of outstanding requests
2023-07-27 16:52:03 +02:00
Mark Olesen
65cddb6120 ENH: specialise bitOr<unsigned char> reduction
STYLE: remove extraneous parRun check before Pstream::combineReduce

- already handled by Pstream::combineReduce itself

STYLE: remove deprecated globalMeshData::ListPlusEqOp

- deprecated/superseded by ListOps::appendEqOp (2020-09)

STYLE: qualify stream format with IOstreamOption (easier to find)
2023-07-19 14:06:23 +02:00
Mark Olesen
8ee4b52560 ENH: provide MPI native bitOrOp reduce with single/multiple values
- can be used, for example, to track global states:

      // Encode as 0:empty, 1:uniform, 2:nonuniform, 3:mixed
      PackedList<2> uniformity(fields.size());

      forAll(fields, i)
      {
          uniformity.set(i, fields[i].whichUniformity());
      }

      reduce
      (
          uniformity.data(),
          uniformity.size_data(),
          bitOrOp<unsigned>()
      );
2023-07-05 15:14:26 +02:00
Mark Olesen
5635e14f81 ENH: add low-level polymorphic/boxed exprValue
- primarily for handling expression results,
  but can also be used as a universal value holder.

  Has some characteristics suitable for type-less IO:
  eg, is_integral(), nComponents()

ENH: add is_pointer() check for expression scanToken
2023-07-04 17:25:26 +02:00
Andrew Heather
763bf4674d RELEASE: Updated headers to v2306 2023-06-28 16:35:48 +01:00