ENH: support tuple (pair) indexing into FieldField

- can use a (patchi, elemi) pair to access an element of a FieldField
This commit is contained in:
Mark Olesen
2022-09-12 12:50:10 +02:00
parent a0282c7e41
commit 052d8b13e3
16 changed files with 277 additions and 97 deletions

View File

@ -34,21 +34,29 @@ Application
using namespace Foam;
vectorField randomVectorField(label size)
template<class Type>
tmp<Field<Type>> randomField(Random& rnd, label dim)
{
Random rnd;
auto tfld = tmp<Field<Type>>::New(dim);
auto& fld = tfld.ref();
vectorField vf(size);
forAll(vf, i)
for (Type& val : fld)
{
for (direction cmpt=0; cmpt < vector::nComponents; ++cmpt)
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
{
vf[i][cmpt] = rnd.position<label>(0, 100);
setComponent(val, cmpt) = rnd.position<label>(0, 100);
}
}
return vf;
return tfld;
}
template<class Type>
tmp<Field<Type>> randomField(label dim)
{
Random rnd;
return randomField<Type>(rnd, dim);
}
@ -251,7 +259,7 @@ int main(int argc, char *argv[])
{
Info<< nl << "vectorField" << nl;
vectorField vf1(randomVectorField(4));
vectorField vf1(randomField<vector>(4));
FixedList<scalarField, 3> cmpts(scalarField(vf1.size()));
Info<< nl