ENH: add comparison operators to exprValue, integrate exprValueFieldTag

- exprValueFieldTag is an extended version of exprValue,
  with additional Field/List uniformity handling

- the exprValueFieldTag reduce() method provides a more efficient
  method than using a regular combine operator. Since fields are
  usually non-uniform, will mostly only need the bitwise reduce and
  not a more expensive gather/combine.

ENH: output of exprValue (scalar type) now includes '.'

- prevents scalar/label ambiguity for values like '100.0', which would
  otherwise be written as '100' and thus interpreted as a label value
  when re-reading.
This commit is contained in:
Mark Olesen
2024-05-17 14:10:28 +02:00
parent baa8dccb0a
commit d859f7b00f
11 changed files with 758 additions and 289 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
Copyright (C) 2023-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,6 @@ Description
#include "vectorField.H"
#include "DynamicList.H"
#include "Random.H"
#include "exprValue.H"
#include "exprValueFieldTag.H"
using namespace Foam;
@ -61,27 +60,81 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
DynamicList<fieldTag> allTags;
{
scalarField fld1(20);
scalarField fld2a(20, Zero);
scalarField fld2b(10, 3.10);
scalarField fld3;
forAll(fld1, i)
for (auto& val : fld1)
{
fld1[i] = rnd.position<scalar>(0, 20);
val = rnd.position<scalar>(0, 20);
}
if (!UPstream::master())
{
fld2b.resize(5);
fld2b *= 2;
}
fieldTag tag1(fld1.begin(), fld1.end());
fieldTag tag2a(fld2a.begin(), fld2a.end());
fieldTag tag2b(fld2b.begin(), fld2b.end());
fieldTag tag3(fld3.begin(), fld3.end());
fieldTag tag4(fld3.begin(), fld3.end());
printInfo(tag1) << nl;
printInfo(tag2a) << nl;
printInfo(tag2b) << nl;
printInfo(tag3) << nl;
{
Pout<< "Test reduce" << nl;
fieldTag work(fld2b.begin(), fld2b.end());
Pout<< "Before" << nl;
printInfo(work) << nl;
work.reduce();
Pout<< "After" << nl;
printInfo(work) << nl;
Pout<< "====" << nl;
}
allTags.clear();
allTags.push_back(tag1);
allTags.push_back(tag2a);
allTags.push_back(tag2b);
allTags.push_back(tag3);
allTags.push_back(tag4);
allTags.push_back(fieldTag::make_empty<tensor>());
// Add some other types
{
vectorField vfld2a(20, vector::uniform(1.23));
allTags.emplace_back
(
vfld2a.begin(),
vfld2a.end()
);
allTags.emplace_back(vector(1.01, 2.02, 3.03));
allTags.emplace_back(12.4);
allTags.emplace_back().set_value(vector::uniform(2.0));
allTags.back().set_empty();
}
Info<< "all tags: " << allTags << nl;
Foam::sort(allTags);
Info<< "sorted: " << allTags << nl;
fieldTag result;
result = fieldTag::combineOp{}(tag1, tag2a);