CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

surfaceScalarField into VolumeScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree16Likes
  • 1 Post By wyldckat
  • 15 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 25, 2010, 04:45
Default surfaceScalarField into VolumeScalarField
  #1
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,266
Blog Entries: 1
Rep Power: 24
nimasam is on a distinguished road
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 ?
nimasam is offline   Reply With Quote

Old   July 25, 2010, 11:12
Default
  #2
New Member
 
xiang chai
Join Date: Aug 2009
Posts: 13
Rep Power: 16
chai is on a distinguished road
Hi,
I think fvc::reconstruct(mvCoef) can do it for you.

chai
chai is offline   Reply With Quote

Old   November 12, 2011, 07:44
Default
  #3
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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
Arnoldinho is offline   Reply With Quote

Old   November 12, 2011, 15:46
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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?
Bernhard is offline   Reply With Quote

Old   November 15, 2011, 02:42
Default
  #5
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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
Arnoldinho is offline   Reply With Quote

Old   November 17, 2014, 10:22
Default
  #6
Member
 
Vignesh
Join Date: Oct 2012
Location: Darmstadt, Germany
Posts: 66
Rep Power: 13
vigneshTG is on a distinguished road
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?
__________________
Thanks and Regards

Vignesh
vigneshTG is offline   Reply With Quote

Old   November 17, 2014, 15:11
Default
  #7
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
Aaron_L likes this.
__________________
wyldckat is offline   Reply With Quote

Old   November 18, 2014, 01:45
Default
  #8
Member
 
Vignesh
Join Date: Oct 2012
Location: Darmstadt, Germany
Posts: 66
Rep Power: 13
vigneshTG is on a distinguished road
Dear Bruno,

Thank you very much for the reply and also for the neat explanation about the reconstruct option.
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 ?
__________________
Thanks and Regards

Vignesh
vigneshTG is offline   Reply With Quote

Old   November 23, 2014, 15:12
Default
  #9
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
wyldckat is offline   Reply With Quote

Old   November 24, 2014, 02:40
Default
  #10
Member
 
Vignesh
Join Date: Oct 2012
Location: Darmstadt, Germany
Posts: 66
Rep Power: 13
vigneshTG is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
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
__________________
Thanks and Regards

Vignesh
vigneshTG is offline   Reply With Quote

Old   January 3, 2015, 05:25
Default
  #11
Senior Member
 
T. Chourushi
Join Date: Jul 2009
Posts: 321
Blog Entries: 1
Rep Power: 17
Tushar@cfd is on a distinguished road
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?
Tushar@cfd is offline   Reply With Quote

Old   January 3, 2015, 11:35
Default
  #12
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

@vigneshTG: I've finally managed to look into this:
Quote:
Originally Posted by vigneshTG View Post
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 View Post
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
Attached Images
File Type: jpg Objective.jpg (15.9 KB, 291 views)
File Type: jpg reconstruct.jpg (17.7 KB, 230 views)

Last edited by wyldckat; January 3, 2015 at 14:14. Reason: attached the missing images
wyldckat is offline   Reply With Quote

Old   May 31, 2018, 05:04
Smile
  #13
Senior Member
 
Elham
Join Date: Oct 2009
Posts: 184
Rep Power: 16
Elham is on a distinguished road
Dear Bruno,

I had a look at https://openfoamwiki.net/index.php/C...rpolate-fields. It seems that it is for postprocessing. Can I use it for the runtime? I mean as a function in the code?

Cheers,

Elham

Last edited by Elham; June 1, 2018 at 10:54.
Elham is offline   Reply With Quote

Reply

Tags
surfacescalarfield, volscalarfield


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MSHArequest for surfaceScalarField phi from objectRegistry msha OpenFOAM Running, Solving & CFD 11 March 21, 2014 03:35
[OpenFOAM] Visualisation of a surfaceScalarField with paraview sinusmontis ParaView 3 July 9, 2010 04:09
[OpenFOAM] surfaceScalarField in paraFoam danielr ParaView 1 October 5, 2009 02:08
sampling a surfaceScalarField feijooos OpenFOAM Post-Processing 0 July 22, 2009 13:05
SurfaceScalarField ghf in interFoam how does it look like mcchouffe OpenFOAM Running, Solving & CFD 11 July 3, 2007 10:33


All times are GMT -4. The time now is 21:08.