# Integrate scalar field

**URL:** https://discourse.paraview.org/t/integrate-scalar-field/2459
**Category:** ParaView Support
**Created:** [August 21, 2019, 7:00am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459 "2019-08-21T07:00:25Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 21, 2019, 7:00am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/1 "2019-08-21T07:00:25Z")

</div>

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!

Marco

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [August 21, 2019, 7:07am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/2 "2019-08-21T07:07:05Z")

</div>

What do you mean by

> integrate over a rectangular grid

?

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 21, 2019, 7:17am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/3 "2019-08-21T07:17:39Z")

</div>

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: [https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf](https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf) ). 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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [August 21, 2019, 8:03am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/4 "2019-08-21T08:03:03Z")

</div>

Still not sure what you mean.

What do you mean by :

> the volume, over which integrate this variable

?

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 21, 2019, 6:28pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/5 "2019-08-21T18:28:10Z")

</div>

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

 ![image](https://discourse.paraview.org/uploads/default/original/2X/6/63da47afcd41b87d10bb78fe617a11e06816c569.png)

with the filter integrate variable ([https://kitware.github.io/paraview-docs/latest/python/paraview.simple.IntegrateVariables.html](https://kitware.github.io/paraview-docs/latest/python/paraview.simple.IntegrateVariables.html)) 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.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [August 22, 2019, 7:31am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/6 "2019-08-22T07:31:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 22, 2019, 8:46am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/7 "2019-08-22T08:46:41Z")

</div>

I suspected so, thanks anyway!

---

<div class="post-metadata">

### Author: ![momentumv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/momentumv/32/1686_2.png) [@momentumv](https://discourse.paraview.org/u/momentumv)
#### Post date: [August 24, 2019, 2:53pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/8 "2019-08-24T14:53:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![momentumv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/momentumv/32/1686_2.png) [@momentumv](https://discourse.paraview.org/u/momentumv)
#### Post date: [August 24, 2019, 7:34pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/9 "2019-08-24T19:34:22Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 27, 2019, 1:02pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/10 "2019-08-27T13:02:26Z")

</div>

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

Marco

---

<div class="post-metadata">

### Author: ![momentumv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/momentumv/32/1686_2.png) [@momentumv](https://discourse.paraview.org/u/momentumv)
#### Post date: [August 27, 2019, 1:07pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/11 "2019-08-27T13:07:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 28, 2019, 1:18pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/12 "2019-08-28T13:18:43Z")

</div>

gmsh can export in vtk format?

---

<div class="post-metadata">

### Author: ![momentumv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/momentumv/32/1686_2.png) [@momentumv](https://discourse.paraview.org/u/momentumv)
#### Post date: [August 28, 2019, 2:31pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/13 "2019-08-28T14:31:10Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [August 29, 2019, 1:13am UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/14 "2019-08-29T01:13:23Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![MarcDP](https://discourse.paraview.org/user_avatar/discourse.paraview.org/marcdp/32/1931_2.png) [@MarcDP](https://discourse.paraview.org/u/MarcDP)
#### Post date: [August 30, 2019, 2:30pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/15 "2019-08-30T14:30:20Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![momentumv](https://discourse.paraview.org/user_avatar/discourse.paraview.org/momentumv/32/1686_2.png) [@momentumv](https://discourse.paraview.org/u/momentumv)
#### Post date: [September 1, 2019, 3:28pm UTC](https://discourse.paraview.org/t/integrate-scalar-field/2459/16 "2019-09-01T15:28:36Z")

</div>

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