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/)
-   -   Interpolation from several volscalarfield named Y[i] (https://www.cfd-online.com/Forums/openfoam-programming-development/223799-interpolation-several-volscalarfield-named-y-i.html)

farzadmech January 27, 2020 07:25

Interpolation from several volscalarfield named Y[i]
 
Dear friends
I have defined several volScalarField as below;
Code:

label N = 2;
    PtrList<volScalarField> Y(N);

and now I want to interpolate them. As am example, we interpolate velocity U as below;
Code:

UInterp_
    (
        interpolation<vector>::New
        (
            cloud.solution().interpolationSchemes(),
            cloud.U()
        )
    ),

How should I interpolate using PtrList?


Thanks,
Farzad

Daniel_Khazaei January 27, 2020 08:58

I think you can try and make a PtrList of your interpolators which can be recalled for each element by [] operator.

farzadmech January 27, 2020 09:46

Thank you for your response dear Daniel. So what are you saying is this(could you please confirm that);

Code:

YiInterp_[1]
    (
        interpolation<scalar>::New              //scalarField
        (
            cloud.solution().interpolationSchemes(),
            cloud.Yi()
        )
    ),

And;

Code:

YiInterp_[2]
    (
        interpolation<scalar>::New              //scalarField
        (
            cloud.solution().interpolationSchemes(),
            cloud.Yi()
        )
    ),

So what should I do with Yi()?

Quote:

Originally Posted by Daniel_Khazaei (Post 755723)
I think you can try and make a PtrList of your interpolators which can be recalled for each element by [] operator.


Daniel_Khazaei January 27, 2020 10:32

Well I'm writing this on the fly without knowing what your trying to do exactly, it seems that you are trying to implement this at constructor level:

1- You can create a PtrList without knowing its size and elements by using the null constructor provided by class PtrList.

step #1

Initialize your list with null constructor at initializer list level as follow:

Code:

YiInterp_()
if you already know the size:
Code:

YiInterp_(list_size_here)
step #2

Now inside the constructor body just loop over the element, but if you have used the null constructor you need to set a size before starting to access elements:

Code:

YiInterp_.setSize(list_size_here); // skip this if you have set the size before
forAll(YiInterp_, i)
{
    YiInterp_.set
    (
        i,
        interpolation<scalar>::New
        (
            cloud.solution().interpolationSchemes(),
            cloud.Yi()[i]
        )
    );
}

NOTE: here I assumed that Yi is a PtrList itself, otherwise I don't see any point to create a list of interpolators.

farzadmech January 27, 2020 11:37

Thanks Daniel. I will try the way you suggested and let you know.


Farzad

Daniel_Khazaei January 27, 2020 12:05

Quote:

Originally Posted by farzadmech (Post 755739)
Thanks Daniel. I will try the way you suggested and let you know.
Farzad

I have just updated my previous post with the correct syntax.


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