|
|
<!-- --- title: Developer Upgrade Guide (OpenFOAM-v1806) -->
|
|
|
|
|
|
[Back to Upgrade Guides](/guides/upgrade/upgrade)
|
|
|
|
|
|
## User Input / Interaction
|
|
|
|
|
|
### Environment
|
|
|
|
|
|
Since OpenFOAM-v1612, `FOAM_INST_DIR` and `foamInstDir` no longer have any
|
|
|
special meanings when sourcing the `bashrc` or `cshrc` files.
|
|
|
|
|
|
The outdated use of `foamInstDir` and `FOAM_INST_DIR` has been largely removed.
|
|
|
If you have environments that used these values, they may require
|
|
|
adjustment.
|
|
|
|
|
|
|
|
|
### Dictionary input compatibility
|
|
|
|
|
|
Removed deprecated support for `compressed/uncompressed` as selector
|
|
|
names for the `writeCompression` type.
|
|
|
|
|
|
These were deprecated DEC-2009 and now finally removed.
|
|
|
|
|
|
If these are encountered, a warning will be emitted
|
|
|
|
|
|
Unknown compression specifier 'compressed', assuming no compression
|
|
|
|
|
|
Update your dictionaries to use a normal switch value:
|
|
|
|
|
|
writeCompression on;
|
|
|
writeCompression off;
|
|
|
|
|
|
|
|
|
## Source code incompatibilities
|
|
|
|
|
|
Numerous internal changes have been to several low-level containers
|
|
|
for improved memory usage and to provide better guards against memory
|
|
|
leaks. Some of the changes may affect the compilation of existing user
|
|
|
code.
|
|
|
|
|
|
### Compiler define for the API level
|
|
|
|
|
|
The compiler define for the API level is simplified:
|
|
|
|
|
|
##if OPENFOAM < 1806
|
|
|
... old code
|
|
|
##endif
|
|
|
|
|
|
The older `OPENFOAM_PLUS` define is provided (in stdFoam.H)
|
|
|
for existing code.
|
|
|
|
|
|
|
|
|
### List
|
|
|
|
|
|
The `List` constructor from two arbitrary iterators has been removed
|
|
|
since it was fragile and interfered with constructor resolution.
|
|
|
The new `ListOps::create` factory methods provide robuster and
|
|
|
more flexible solutions.
|
|
|
|
|
|
|
|
|
### HashTable
|
|
|
|
|
|
Removed const access version of `HashTable::operator()(key, default) const`
|
|
|
since there is a non-const version with an identical signature,
|
|
|
which in some cases could lead to the wrong version being called.
|
|
|
|
|
|
Read accessed are now handled more explicitly via the
|
|
|
`HashTable::lookup(key, default)` method.
|
|
|
|
|
|
This helps avoids unintentional insertions.
|
|
|
|
|
|
|
|
|
### String construction
|
|
|
|
|
|
Previously it was possible to implicitly create a string from a single
|
|
|
character, which could lead to very curious situations.
|
|
|
|
|
|
Both of these would have previously worked:
|
|
|
|
|
|
str.replace('(', '_'); // Sure
|
|
|
str.replace('(', true); // Compiled, but a bad idea
|
|
|
|
|
|
This constructor is now marked as being explicit, to avoid dubious
|
|
|
automatic conversions. This means that some existing code will not
|
|
|
compile.
|
|
|
|
|
|
For example, the following
|
|
|
|
|
|
str.replace('(', '_'); // Sure
|
|
|
|
|
|
should be changed to this
|
|
|
|
|
|
str.replace("(", "_");
|
|
|
|
|
|
|
|
|
### regExp
|
|
|
|
|
|
The API for matching with groups has changed.
|
|
|
|
|
|
Element 0 now contains the entire match instead of group 1 and
|
|
|
element 1 contains the match for group 1.
|
|
|
|
|
|
Additionally, the matches are no longer stored as copies in a `List`
|
|
|
container, but stored by iterator pairs for the matched ranges.
|
|
|
|
|
|
The aligns the behaviour with the C++11 regex conventions in
|
|
|
anticipation of a future change to C++11 regex. This is currently not
|
|
|
possible due to incomplete coverage with various compilers.
|
|
|
|
|
|
|
|
|
The `regExp::results_type` now behaves similarly to the C++11 `std::smatch`
|
|
|
type.
|
|
|
|
|
|
Old:
|
|
|
|
|
|
List<std::string> mat;
|
|
|
if (re.match(text, mat)) Info<< "group 1: " << mat[0] << nl;
|
|
|
|
|
|
New:
|
|
|
|
|
|
regExp::results_type mat;
|
|
|
if (re.match(text, mat)) Info<< "group 1: " << mat.str(1) << nl;
|
|
|
|
|
|
|
|
|
### Foam::name
|
|
|
|
|
|
|
|
|
The two-parameter form introduced in a previous version has been
|
|
|
replaced by `word::printf()` to avoid ambiguity and clarify the expected
|
|
|
output and behaviour.
|
|
|
|
|
|
For example,
|
|
|
|
|
|
word::prinf("index_%05d", idx);
|
|
|
|
|
|
|
|
|
### HashTable, HashSet, string::hash
|
|
|
|
|
|
The `string::hash` function, which is used by `HashTable` and `HashSet` now
|
|
|
operates on `std::string` directly, to further eliminate inadvertent
|
|
|
automatic conversions.
|
|
|
|
|
|
This means that the following type of code will no longer compile:
|
|
|
|
|
|
HashSet<label> set;
|
|
|
HashTable<scalar, label> table;
|
|
|
|
|
|
since there is correct way to use a string hash function on a label.
|
|
|
This did compile in previous versions (through the automatic
|
|
|
conversions), but would have been incorrect and resulted in very slow
|
|
|
hash tables.
|
|
|
|
|
|
The easy correction is to use a container with the suitable
|
|
|
hasher, e.g.,
|
|
|
|
|
|
labelHashSet set;
|
|
|
Map<scalar> table;
|
|
|
|
|
|
|
|
|
### HashPtrTable, PtrMap
|
|
|
|
|
|
Using an `insert()` with raw pointers is now disallowed, since a failed
|
|
|
insertion , i.e. where the entry already existed, would result in an unmanaged
|
|
|
pointer and a potential memory leak.
|
|
|
|
|
|
Change your code to `insert()` using an `autoPtr` or else using the `set()`
|
|
|
method with an `autoPtr` or a raw pointer.
|
|
|
|
|
|
|
|
|
### IOobjectList
|
|
|
|
|
|
Similar to potential memory leakage with `HashPtrTable`.
|
|
|
|
|
|
* IOobjectList::add() now takes an `autoPtr` instead of an object reference.
|
|
|
* IobjectList::remove() now returns an `autoPtr` instead of a raw pointer.
|
|
|
|
|
|
|
|
|
### stringListOps
|
|
|
|
|
|
Removed direct use of C-string or string, which was previously
|
|
|
implicitly converted to a `regExp`:
|
|
|
|
|
|
findStrings()
|
|
|
subsetStrings()
|
|
|
subsetStrings()
|
|
|
inplaceSubsetStrings()
|
|
|
|
|
|
For most cases, this conversion would be largely unintentional
|
|
|
and also less efficient. If the regex is desirable, the caller
|
|
|
should invoke it explicitly.
|
|
|
|
|
|
For example,
|
|
|
|
|
|
findStrings(regExp(str), listOfStrings);
|
|
|
|
|
|
Or use one of the more standard `keyType`, `wordRe`, `wordRes` variants
|
|
|
instead.
|
|
|
|
|
|
If string is to be used as a plain (non-regex) matcher, the
|
|
|
`ListOps` function should be used:
|
|
|
|
|
|
findIndices(listOfStrings, str);
|
|
|
|
|
|
|
|
|
### ListOps namespace change
|
|
|
|
|
|
Relocated some functions into the `ListOps` namespace for better code
|
|
|
isolation and documentation of purpose.
|
|
|
|
|
|
| old | new |
|
|
|
|--------------------|-------------------- |
|
|
|
| ListAppendEqOp | ListOps::appendEqOp |
|
|
|
| ListUniqueEqOp | ListOps::UniqueEqOp |
|
|
|
| setValues | ListOps::setValue |
|
|
|
| createWithValues | ListOps::createWithValue |
|
|
|
|
|
|
The updated functions also have many more alternative selectors
|
|
|
possible and parameter options than previously.
|
|
|
|
|
|
|
|
|
### ListOps functions removed
|
|
|
|
|
|
Removed deprecated and unused `ListOps` functions which were deprecated MAR-2017.
|
|
|
|
|
|
subset(const UList<T>& select, const T& value, const ListType&);
|
|
|
inplaceSubset(const UList<T>& select, const T& value, ListType&);
|
|
|
|
|
|
The `subsetList`/`inplaceSubsetList` variants with a unary predicate
|
|
|
provide more flexible and robuster solutions.
|
|
|
|
|
|
|
|
|
Removed the deprecated (deprecated MAR-2017) `initList` methods
|
|
|
|
|
|
initList(const T[mRows]);
|
|
|
initListList(const T[mRows][nColumns]);
|
|
|
|
|
|
These have be replaced by `List` constructors and
|
|
|
`std::initializer_list`
|
|
|
|
|
|
|
|
|
### Remove usage of Xfer class
|
|
|
|
|
|
The `Xfer` class was a remnant from C++98 code and has now been been
|
|
|
removed from the code in favour of using C++11 movable references.
|
|
|
This change largely affects internal library use.
|
|
|
|
|
|
A visible change for advanced users is the `polyMesh` constructor, which
|
|
|
now takes movable references, and the `polyMesh::resetPrmimitives` method,
|
|
|
which now takes `autoPtr` instead.
|
|
|
|
|
|
|
|
|
### autoPtr
|
|
|
|
|
|
Was significantly revised and improved. In the course of doing so,
|
|
|
the method names for direct, unchecked pointer access were changed:
|
|
|
|
|
|
- renamed rawPtr() to get()
|
|
|
- renamed rawRef() to ref()
|
|
|
|
|
|
The method name `get()` was chosen for consistency with `std::unique_ptr`
|
|
|
naming. The method name `ref()` was chosen for similarity with the
|
|
|
`tmp`.
|
|
|
|
|
|
|
|
|
### PackedList, PackedBoolList
|
|
|
|
|
|
`PackedBoolList` has been removed and replaced by the new `bitSet` class
|
|
|
that offers more functionality. In most cases `bitSet` can be treated as
|
|
|
a drop-in replacement.
|
|
|
|
|
|
Compilation of existing code will generally be unaffected and the
|
|
|
`PackedBoolList` name is still available as a compatiblity typedef and
|
|
|
header. However, there are some differences of behaviour.
|
|
|
|
|
|
|
|
|
##### Access to non-existent entries
|
|
|
|
|
|
In previous versions of `PackedList` and `PackedBoolList`, the array-like
|
|
|
access was treated indirectly. So that code with `list[i]` created a
|
|
|
somewhat large intermediate proxy object.
|
|
|
This means that it could be used to query non-existent elements or,
|
|
|
when assigned to, it could resize the list and set the value.
|
|
|
In some cases this automatic behaviour was convenient, in other cases
|
|
|
it could be used inadvertently and cause subtle bugs.
|
|
|
|
|
|
|
|
|
Old code:
|
|
|
|
|
|
PackedBoolList items(10);
|
|
|
|
|
|
items[20] = true; // OK. auto vivifies a new element
|
|
|
items.get(30); // OK. lazy evaluation (out-of-bounds) = false
|
|
|
items.set(40); // OK. auto vivifies a new element
|
|
|
if (items[50]) ... // OK. lazy evaluation (out-of-bounds) = false
|
|
|
|
|
|
|
|
|
New code:
|
|
|
|
|
|
bitSet items(10);
|
|
|
|
|
|
items[20] = true; // Error. Out of bounds.
|
|
|
items.get(30); // OK. lazy evaluation (out-of-bounds) = false
|
|
|
items.set(40); // OK. auto vivifies a new element
|
|
|
if (items[50]) ... // Error. Out of bounds.
|
|
|
if (items.test(50))... // OK. lazy evaluation (out-of-bounds) = false
|
|
|
|
|
|
|
|
|
For read-only (const) access, the behaviour is similar to previously.
|
|
|
|
|
|
bitSet items(10);
|
|
|
|
|
|
items.get(30); // OK. lazy evaluation (out-of-bounds) = false
|
|
|
if (items[50]) ... // OK. lazy evaluation (out-of-bounds) = false
|
|
|
if (items.test(50))... // OK. lazy evaluation (out-of-bounds) = false
|
|
|
|
|
|
|
|
|
##### Iterators
|
|
|
|
|
|
Iterators for the `PackedList` class have been removed for performance
|
|
|
reasons. The usual `forAll` macro can still be used.
|
|
|
|
|
|
The `PackedBoolList` iterators have changed behaviour in `bitSet`.
|
|
|
The regular iterator has been full removed (can use
|
|
|
`forAll` macro as an alternative).
|
|
|
|
|
|
The `bitSet const_iterator` has changed behaviour. It now only iterates
|
|
|
over values that are true, skipping intermediate values.
|
|
|
Dereferencing the iterator returns the location.
|
|
|
|
|
|
Old code:
|
|
|
|
|
|
PackedBoolList selected(...);
|
|
|
|
|
|
forAllConstIters(selected, iter)
|
|
|
{
|
|
|
if (*iter)
|
|
|
{
|
|
|
// Value is true, but where am I?
|
|
|
}
|
|
|
}
|
|
|
|
|
|
forAll(selected, celli)
|
|
|
{
|
|
|
if (selected[celli])
|
|
|
{
|
|
|
sumVol += mesh_.cellVolumes()[celli];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
New code:
|
|
|
|
|
|
bitSet selected(...);
|
|
|
|
|
|
for (const label celli : selected)
|
|
|
{
|
|
|
sumVol += mesh_.cellVolumes()[celli];
|
|
|
}
|
|
|
|
|
|
|
|
|
This change increases usability and improves performance since the
|
|
|
iterator internally skips empty elements block-wise with many fewer
|
|
|
looping operations.
|
|
|
|
|
|
|
|
|
### Applications
|
|
|
|
|
|
`foamToTecplot360` has again been removed. It was previously broken,
|
|
|
but updated for OpenFOAM-v1612.
|
|
|
However, the cryptic API-versioned calls, limited availability of
|
|
|
the SDK and lack of adequate testing made proper maintenance very
|
|
|
difficult. |