CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   surfaceScalarField into VolumeScalarField (http://www.cfd-online.com/Forums/openfoam-programming-development/78541-surfacescalarfield-into-volumescalarfield.html)

nimasam July 25, 2010 04:45

surfaceScalarField into VolumeScalarField
 
hi dear foamers
i have an surface Scalar Field i want to change it into a volume Scalar Field whats ur suggestions ?
my code is like below
....

volVectorField mFlux=K*fvc::grad(T)/L;
surfaceVectorField mFluxf=fvc::interpolate(mFlux);

const surfaceVectorField& sf=mesh.Sf();
surfaceScalarField mvCoef=(mFluxf & sf);

volScalarField mvCoefV= ??? mvCoef
....
what should i substitute instead of "???" in above code ? :(

chai July 25, 2010 11:12

Hi,
I think fvc::reconstruct(mvCoef) can do it for you.

chai

Arnoldinho November 12, 2011 08:44

Hi nimasam,

your post is rather old, but I'm facing the same problem right now. I have to convert a surfaceScalarField into a volScalarField to directly save and visualize the Courant number in the cells. Did you find an easy way to interpolate the values?

I'm not sure what fvc::reconstruct() is doing, and it also did not compile in the way I used it.

A workaround is saving the surfaceScalarField directly and visualize it in ParaView using foamToVTK -surfaceFields. But thats just a workaround...

Arne

Bernhard November 12, 2011 16:46

Can you post your errors+relevant code? fvc::reconstruct is more or less the opposite of fvc::interpolate.

Did you check out the Co utility?

Arnoldinho November 15, 2011 03:42

Thanks Bernhard,

I did not know the Co utility until now. Just implemented the same functionality within the solver, in if(runTime.outputTime()), and all is fine.

Arne

vigneshTG November 17, 2014 11:22

Dear All,

fvc::reconstruct operates only on Vector and Tensor fields.


What about scalar fields ? Which command should we use to convert a surface field to volumetric field?

wyldckat November 17, 2014 16:11

Greetings Vignesh,

Some years ago I wrote a couple of neat utilities that help test the field reconstruct and interpolate features in OpenFOAM: https://github.com/wyldckat/reconstr...rpolate-fields
Including a wiki page with some helpful tips on this topic: https://github.com/wyldckat/reconstr...te-fields/wiki

Regarding your question, I wrote back then: https://github.com/wyldckat/reconstr...ctSurfaceField
Quote:

reconstructSurfaceField can reconstruct surface fields back to volume fields. More specifically, it will interpolate the fields that exist in the face centres onto the cell centres.

But
this operation is not the opposite done by interpolateVolumeField, because fvc::reconstruct was designed for reconstructing the field from the operation of fvc::interpolate(volVectorField) & Mesh.Sf(). In other words, the reconstruction operation will created a vector from the 3 main directions of face scalar values or a tensor from the same 3 main directions of face vector values.

Which means that this operation is only done to the following fields:
  • Reconstruct volVectorField from surfaceScalarField.
  • Reconstruct volTensorField from surfaceVectorField.

This to say that it really depends on whether you know what exactly you're trying to reconstruct.

Best regards,
Bruno

vigneshTG November 18, 2014 02:45

Dear Bruno,

Thank you very much for the reply and also for the neat explanation about the reconstruct option. :D
Actually i am trying to reconstruct from a scalar surface field. It is not the outcome of the operation fvc::interpolate(volVectorField) & Mesh.Sf()

I am sorry to ask again ..... Is there any way to reconstruct a scalarfield ?

wyldckat November 23, 2014 16:12

Hi Vignesh,

Can you provide more specific details? Because the answer seems simply to be:
Code:

fvc::reconstruct(surfScaField)
and it will give you a reconstructed scalar field.

Best regards,
Bruno

vigneshTG November 24, 2014 03:40

Quote:

Originally Posted by wyldckat (Post 520662)
Hi Vignesh,

Can you provide more specific details? Because the answer seems simply to be:
Code:

fvc::reconstruct(surfScaField)
and it will give you a reconstructed scalar field.

Best regards,
Bruno

Hi Bruno,

I was trying to smooth the volume fraction using the relation given below

\alpha_{s,i+1} = C \langle \langle \alpha_{s,i} \rangle_{c \to f} \rangle_{f \to c} + (1 - \alpha_{s,i})C

where \alpha is the volume fraction and the symbol c \to f implies interpolate from cell center to face and the other one is the reverse (interpolate back to center from face). Interpolating back to cell centers is the point where i got stuck. I tried using fvc::reconstruct(alphaF) but i got errors indicating you cannot do this operation.

I found this smoothing function for volume fraction in this Paper
Thanks for your help

Tushar@cfd January 3, 2015 06:25

Dear All,

I need to calculate "volScalarField" from "surfaceScalarField", if I apply "reconstruct" on surfaceScalarField it gives me "volVectorField".

Any Idea how I would achieve this?

wyldckat January 3, 2015 12:35

2 Attachment(s)
Greetings to all!

@vigneshTG: I've finally managed to look into this:
Quote:

Originally Posted by vigneshTG (Post 520738)
I was trying to smooth the volume fraction using the relation given below

\alpha_{s,i+1} = C \langle \langle \alpha_{s,i} \rangle_{c \to f} \rangle_{f \to c} + (1 - \alpha_{s,i})C

where \alpha is the volume fraction and the symbol c \to f implies interpolate from cell center to face and the other one is the reverse (interpolate back to center from face). Interpolating back to cell centers is the point where i got stuck. I tried using fvc::reconstruct(alphaF) but i got errors indicating you cannot do this operation.

I found this smoothing function for volume fraction in this Paper

OK, now with this we have a better idea of what's going on. This is one of those situations where having an example calculation can help figure out what should be done.
Curiously, I found about the following methods, which are all used in this file: applications/solvers/multiphase/interFoam/LTSInterFoam/setrDeltaT.H
  • fvc::smooth
  • fvc::spread
  • fvc::sweep
The description is given here: https://github.com/OpenFOAM/OpenFOAM...th/fvcSmooth.H
Quote:

Code:

Description
    Provides functions smooth spread and sweep which use the FaceCellWave
    algorithm to smooth and redistribute the first field argument.

    smooth: smooths the field by ensuring the values in neighbouring cells are
            at least coeff* the cell value.

    spread: redistributes the field by spreading the maximum value within the
            region defined by the value (being between alphaMax and alphaMin)
            and gradient of alpha (where the difference between the values in
            neighbouring cells is larger than alphaDiff).

    sweep: redistributes the field by sweeping the maximum value where the
          gradient of alpha is large (where the difference between the values
          in neighbouring cells is larger than alphaDiff) away from that
          starting point of the sweep.


But neither one seems to be what you're looking for...

The other thing that comes to mind is rhoCentralFoam, so you might want to look at it for ideas as well...

Anyway, the schematic I came up is in the attached files:
  1. Objective.jpg - This image shows the calculation you're looking for.
  2. reconstruct.jpg - This image shows what is done by "reconstruct". The calculations shown near the bottom right are attempts at getting the same kind of calculation, but that doesn't work.
If you noticed, what you're actually looking for is a way to average values out.
So I went looking for the code that "fvc::reconstruct" has got inside it, and found it here: src/finiteVolume/finiteVolume/fvc/fvcReconstruct.C
Quote:

Code:

reconstruct
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
)
{
    typedef typename outerProduct<vector, Type>::type GradType;

    const fvMesh& mesh = ssf.mesh();

    surfaceVectorField SfHat(mesh.Sf()/mesh.magSf());

    tmp<GeometricField<GradType, fvPatchField, volMesh> > treconField
    (
        new GeometricField<GradType, fvPatchField, volMesh>
        (
            IOobject
            (
                "volIntegrate("+ssf.name()+')',
                ssf.instance(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            inv(surfaceSum(SfHat*mesh.Sf()))&surfaceSum(SfHat*ssf),
            zeroGradientFvPatchField<GradType>::typeName
        )
    );

    treconField().correctBoundaryConditions();

    return treconField;
}


So, this might all look like some alien language, but it's very simple:
  • "SfHat" - surface field that has the normals of all faces on the mesh.
  • "mesh.Sf()" - is a surface field that has mixed in the area of the face over each major direction of the normal, including said normal of the face.
  • "surfaceSum" - similar to "fvc::reconstruct", but I had a look at "fvc::surfaceSum" and what it does is add the values of all faces into the cell they belong to. This gets you half way to where you want to get to.
This to say that what you're looking for is actually "fvc::average", not "fvc::reconstruct".

In addition, there is one other interesting method named "fvc::reconstructMag", but this will unlikely give you the desired results.


In addition, I very strongly advise you to test these functions with some basic calculations, where you have a simple mesh with simple values inside each cell of the mesh, so that you can then you verify if the calculations are done exactly the way you want them to be.

--------------
@Tushar@cfd:
Quote:

Originally Posted by Tushar@cfd (Post 525968)
I need to calculate "volScalarField" from "surfaceScalarField", if I apply "reconstruct" on surfaceScalarField it gives me "volVectorField".

Any Idea how I would achieve this?

There are several ways to solve a problem, but some solutions are not acceptable and others are simply undesirable. From your description, I only see reasons why no solution will be what you want, because you're not looking at this properly.
Which makes me need to ask you: did you even read the past few 4-5 posts above?

And I hope you can look at the explanation I gave above to vigneshTG and that you understand that it isn't as simple as just converting a surface scalar field to a volume scalar field, since otherwise you might be simply be generating garbage values out of a perfectly nice surface field ;)

Best regards,
Bruno


All times are GMT -4. The time now is 19:01.