Contrib/reconstruct-interpolate-fields

From OpenFOAMWiki

This page is a verbatim copy of the wiki page resident in the project reconstruct-interpolate-fields at wyldckat@github. Feel free to improve this page or even collaborate directly with that small project, either with code or wiki edits. - Wyldckat 01:24, 15 July 2012 (CEST)



1 Introduction

This small project, designed for being used with OpenFOAM, is both a small educational kit about fvc::interpolate and fvc::reconstruct, as well as a convenient kit of utilities for using those two methods for field interpolations on face to/from cell centres.

So far, the two utilities available are meant only for using at the post-processing stage and it's advisable to use them on fields that were written in binary form. Said binary form is explained in OpenFOAM's User Guide, in the section about controlDict.

If you have trouble/problems using this toolkit, you can use either one of the following forums:

2 Installation

How to get and build:

git clone git://github.com/wyldckat/reconstruct-interpolate-fields.git
cd reconstruct-interpolate-fields
wmake all

If you don't have Git installed, you can use the ZIP option shown in the project page: reconstruct-interpolate-fields at wyldckat@github

3 How to use

3.1 interpolateVolumeField

interpolateVolumeField can interpolate volume fields to surface fields. More specifically, it will interpolate the fields that exist in the cell centres onto the face centres. This operation is only done for the following field interpolations:

  • Interpolate volScalarField to surfaceScalarField.
  • Interpolate volVectorField to surfaceVectorField.

Note: It can be extended for the operation of volTensorField to surfaceTensorField, as well as accepting a list of fields for interpolation. This is left as an exercise to the reader, so feel free to fork this project. And you can do a pull request when you feel like to share your modifications with this project. For more about about forking and pull requests read the GitHub Help.

As for using this utility, you can run in the following ways:

  • Interpolate one scalar field for all time instances:
    interpolateVolumeField -scalar p pInterpolated
  • Interpolate one vector field for all time instances:
    interpolateVolumeField -vector U Uinterpolated
  • Interpolate one scalar field for the latest time only:
    interpolateVolumeField -scalar p pInterpolated -latestTime
  • Interpolate one vector field for the latest time only:
    interpolateVolumeField -vector U Uinterpolated -latestTime

For more options, run:

interpolateVolumeField -help

3.2 reconstructSurfaceField

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.

Note: It might be possible to interpolate surface fields to volume fields, but this was not studied for this project. This is left as an exercise to the reader, so feel free to fork this project. And you can do a pull request when you feel like to share your modifications with this project. For more about about forking and pull requests read the GitHub Help.

As for using this utility, you can run in the following ways:

  • Reconstruct one surface scalar to volume vector field for all time instances:
    reconstructSurfaceField -scalar phi phiCells
  • Reconstruct one surface vector to volume tensor field for all time instances:
    reconstructSurfaceField -vector phiUp phiUpCells
  • Reconstruct one surface scalar to volume vector field for the latest time only:
    reconstructSurfaceField -scalar phi phiCells -latestTime
  • Reconstruct one surface vector to volume tensor field for the latest time only:
    reconstructSurfaceField -vector phiUp phiUpCells -latestTime

For more options, run:

reconstructSurfaceField -help

4 Viewing and exporting results

For viewing and exporting surface fields to another format:

  1. Export to VTK:
    foamToVTK -surfaceFields
    Note: This will export all surface fields to VTK, so no need to select which ones to export.
  2. Open in ParaView one or more files VTK/surfaceFields/surfaceFields_*.vtk.
  3. Then on ParaView, with one of the surfaceFields_*.vtk selected:
    • To view, apply the Glyph filter. Use Sphere glyph on scalars and Arrow on vectors.
    • To export: choose on the menu File -> Save Data then save as CSV. It will ask the mode of export, for which you can choose the default option.


For viewing volume fields, they will appear on the list of fields to import on ParaView, in the Object Inspector widget, or simply be exported as any other volume field.