CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Make a function available to a volSymmTensorField (https://www.cfd-online.com/Forums/openfoam-programming-development/232018-make-function-available-volsymmtensorfield.html)

Shibi November 26, 2020 14:30

Make a function available to a volSymmTensorField
 
Hello to all,


I'm new to programming in OpenFoam and would like to know the following:


I defined a custom function in OpenFoam that takes as input two tensors and returns a symmetric tensor.

Code:

inline SymmTensor<scalar> test(const Tensor<scalar>& a, const Tensor<scalar>& b)
{

    SymmTensor<scalar> tmp(symm(a+b));
    return tmp;
}




I would like to be able to initialize a volSymmTensorField with this function, taking as input two volTensorFields .e.g,


Code:

volTensorField a
(
    IOobject
    (
        "a",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    Tensor<scalar>::I
);

volTensorField b
(
    IOobject
    (
        "b",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    Tensor<scalar>::I
);

volSymmTensorField test
    (
    IOobject
    (
        "test",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    test(a,b)
    );





Is this possible?


What steps do I need to take to make this work?


Best Regards!

Is






olesen November 27, 2020 11:20

Sure it is possible, but is a bit of work. Starting from the bottom and working our way up.
- define function operating on two tensors
- define function for plain lists/fields - see FieldFunctions.H
- define function for a field of fields - see FieldFieldFunctions.H
- define function for dimensioned (internal) fields - see DimensionedFieldFunctions.H
- finally define function for volume fields, handling internal and boundary (FieldFields) - see GeometricFieldFunctions.H


A bit of work, but certainly a really good way to learn.


All times are GMT -4. The time now is 02:54.