Integrate scalar field

Hi everyone,
I am investigating if it is possible to integrate a scalar field stored in a rectangular grid over a volume defined with a CAD file. This cad file can be easily imported in ParaView as .stl but I wonder if I could use it to clip a region of the rectangular grid and later integrate over the resulting region. I am not sure if this could be done with some programmable filter/vtk programming or if it could be done at all. Any suggestion would be greatly appreciated!


What do you mean by

integrate over a rectangular grid


I have a data set which describe a scalar field of a variable(let’s say temperature). This data set is organized as a rectilinear grid (see here: ). I am trying to understand if the volume, over which integrate this variable, could be defined by importing a CAD file. Hope this clarifes a bit

Still not sure what you mean.

What do you mean by :

the volume, over which integrate this variable


I have a spatial distribution of a variable that looks like this:

with the filter integrate variable ( I can easily integrate the variable over the whole volume of the grid shown in the picture and get the total value.

What I’d like to do is to import a stl to clip a subsect of this volume and then integrate the variable only over this smaller region.

Sadly, ParaView does not have a way to clip a volume with a .stl yet. This is not a trivial task.

I suspected so, thanks anyway!

Marco, I think I have a workflow that will work for you. I’ll reply later when I’m at a computer.

@MarcDP Here’s what to do:

  1. make sure your CAD volume and your simulation volume have the same origin (or use a transform filter later)
  2. export your volume as STL or .step
  3. import into gmsh and mesh at a scale that is appropriate for the level of your simulation data
  4. open the mesh in Paraview with your simulation domain all processed
  5. resampleWithDataset to translate the simulation results to your empty mesh
  6. IntegrateVariables on the resampled data.

Let me know if you need a worked example.

Thanks Mordecai, It is indeed a workable solution. Unfortunately I have to repeat this process for a large number of solids in an ordered manner. In fact I need to take the result of these integrations and pipeline it into another script and I am not sure I can mesh all of them in a scripted manner from the original CADs. I will investigate, thanks for now


If you have all the solids as step or at least, it’s very easy to mesh them with a basic tet mesh via command line with gmsh.

gmsh can export in vtk format?

Not needed, paraview can read in several mesh types. In my workflow that I discovered/developed this approach, I used gmshtofoam and opened the .foam in paraview.

Gmshtofoam is a command line till that is party of openfoam tools. You should be able to use it as a standalone tool if you need it without getting into the madness that is openFOAM. Are you working in Linux?

@momentumv @MarcDP : There is a GMSH reader plugin in ParaView since 5.6.
It is not available in the release (yet), but if you build ParaView from sources, you can enable it.

@mwestphal that’s a handy info, thanks

@momentumv almost I’m using WSL …I think It would be interesting to do it in a single script, first with the gmsh api which should be able to export the mesh in vtk according to the manual and then finish the job with the paraview python module

Should be not to hard to get it all set up in one python script that builds the need gmsh system calls.