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

@ -297,6 +297,20 @@ tmp<FieldField<Field, Type>> FieldField<Field, Type>::T() const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<template<class> class Field, class Type>
const Type& FieldField<Field, Type>::operator[](const labelPair& index) const
{
return this->operator[](index.first())[index.second()];
}
template<template<class> class Field, class Type>
Type& FieldField<Field, Type>::operator[](const labelPair& index)
{
return this->operator[](index.first())[index.second()];
}
template<template<class> class Field, class Type>
void FieldField<Field, Type>::operator=(const FieldField<Field, Type>& ff)
{
@ -356,6 +370,16 @@ void FieldField<Field, Type>::operator=(const Type& val)
}
template<template<class> class Field, class Type>
void FieldField<Field, Type>::operator=(const Foam::zero)
{
forAll(*this, i)
{
this->operator[](i) = Foam::zero{};
}
}
#define COMPUTED_ASSIGNMENT(TYPE, op) \
\
template<template<class> class Field, class Type> \

View File

@ -39,6 +39,7 @@ SourceFiles
#define Foam_FieldField_H
#include "tmp.H"
#include "Pair.H"
#include "PtrList.H"
#include "scalar.H"
#include "direction.H"
@ -79,7 +80,6 @@ class FieldField
public refCount,
public PtrList<Field<Type>>
{
public:
//- Component type
@ -153,7 +153,16 @@ public:
tmp<FieldField<Field, Type>> T() const;
// Member operators
// Member Operators
//- Const or non-const access to a field
using PtrList<Field<Type>>::operator[];
//- Const access to a single field element via (fieldi, elemi)
inline const Type& operator[](const labelPair& index) const;
//- Non-const access to a single field element via (fieldi, elemi)
inline Type& operator[](const labelPair& index);
//- Copy assignment
void operator=(const FieldField<Field, Type>&);
@ -167,6 +176,9 @@ public:
//- Assign uniform value
void operator=(const Type& val);
//- Assign uniform zero
void operator=(const Foam::zero);
void operator+=(const FieldField<Field, Type>&);
void operator+=(const tmp<FieldField<Field, Type>>&);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,10 +37,11 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef oneFieldField_H
#define oneFieldField_H
#ifndef Foam_oneFieldField_H
#define Foam_oneFieldField_H
#include "oneField.H"
#include "Pair.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -65,10 +66,17 @@ public:
// Member Operators
//- Return the field
oneField operator[](const label) const noexcept
{
return oneField{};
}
//- Return the field element
one operator[](const labelPair&) const noexcept
{
return one{};
}
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -37,10 +37,11 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef zeroFieldField_H
#define zeroFieldField_H
#ifndef Foam_zeroFieldField_H
#define Foam_zeroFieldField_H
#include "zeroField.H"
#include "Pair.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -65,10 +66,17 @@ public:
// Member Operators
//- Return the field
zeroField operator[](const label) const noexcept
{
return zeroField{};
}
//- Return the field element
zero operator[](const labelPair&) const noexcept
{
return zero{};
}
};

View File

@ -36,11 +36,11 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef oneField_H
#define oneField_H
#ifndef Foam_oneField_H
#define Foam_oneField_H
#include "one.H"
#include "scalar.H"
#include "scalarFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -36,11 +36,11 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef zeroField_H
#define zeroField_H
#ifndef Foam_zeroField_H
#define Foam_zeroField_H
#include "zero.H"
#include "scalar.H"
#include "scalarFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //