# Grain boundaries

**URL:** https://discourse.paraview.org/t/grain-boundaries/4984
**Category:** ParaView Support
**Created:** [July 29, 2020, 1:23pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984 "2020-07-29T13:23:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![f.gallardo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/fbc32d/32.png) [@f.gallardo](https://discourse.paraview.org/u/f.gallardo)
#### Post date: [July 29, 2020, 1:23pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/1 "2020-07-29T13:23:56Z")

</div>

![explanationforParaviewForum](https://discourse.paraview.org/uploads/default/original/2X/8/8481e599914bbc595cfc8919dfc19d14e8dec6db.png)

Hello,

I have cell data which correspond to grains. I would like to outline the edges that share 2 different grain IDs, a.k.a. grain boundaries.

I did an example (see picture) with 1 grain. I did:

> threshold of 1 grain + feature edge view representation

I am not willing to do this by brute force (going 1 by 1). I am wondering if there is a simple solution to do this.

Many thanks,  
Fran

---

<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 4, 2020, 2:45pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/2 "2020-08-04T14:45:23Z")

</div>

This is very nice looking ! Thanks for sharing.

As for your question, I’m afraid there is no better way to do that currently.

An alternative could be to use the “DigitalRockPhysics” plugin and its “ExplodeMaterialClusters” filters.  
See here for more info, it should work in 2D too.  
[https://gitlab.kitware.com/paraview/paraview/-/merge\_requests/2184](https://gitlab.kitware.com/paraview/paraview/-/merge_requests/2184)

---

<div class="post-metadata">

### Author: ![SC\_REN](https://discourse.paraview.org/user_avatar/discourse.paraview.org/sc_ren/32/5794_2.png) [@SC\_REN](https://discourse.paraview.org/u/SC_REN)
#### Post date: [January 28, 2021, 2:53pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/3 "2021-01-28T14:53:48Z")

</div>

Hi, I had the same problem. I hope you find a solution.

Finally, I used python shell to loop on the thereshold-FeatureEdge procedure to extract the grain boundaries.

BR,  
SC

---

<div class="post-metadata">

### Author: ![f.gallardo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/fbc32d/32.png) [@f.gallardo](https://discourse.paraview.org/u/f.gallardo)
#### Post date: [January 28, 2021, 3:13pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/4 "2021-01-28T15:13:49Z")

</div>

Hello,

what we did was:

1. calculate the points where the boundaries are.
2. Construct ‘quad’ elements in VTK using the previous points.
3. Visualize them as feature edges

We also upgrade it to 3D. Also vectorize it, avoiding loops and making it a bit more efficient.

If needed, let me know and i can send the code.

Cheers,  
Fran

 ![AusteniteIPF](https://discourse.paraview.org/uploads/default/original/2X/e/e25b0948433515baf8a4ca0786c6201cd88fd3ad.png)

---

<div class="post-metadata">

### Author: ![F.Niessen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/f.niessen/32/6606_2.png) [@F.Niessen](https://discourse.paraview.org/u/F.Niessen)
#### Post date: [May 6, 2021, 2:26pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/5 "2021-05-06T14:26:07Z")

</div>

Dear Fran,

I would be interested in the code, I am trying to visualize a similar structure. That would be very appreciated.

Best wishes  
Frank

---

<div class="post-metadata">

### Author: ![f.gallardo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/fbc32d/32.png) [@f.gallardo](https://discourse.paraview.org/u/f.gallardo)
#### Post date: [May 6, 2021, 2:58pm UTC](https://discourse.paraview.org/t/grain-boundaries/4984/7 "2021-05-06T14:58:15Z")

</div>

[getGrainBoundaries\_DAMASK.py](https://discourse.paraview.org/uploads/short-url/ndZF8jwC4Y5gb7tsb0cGPAQFElJ.py) (1.8 KB)

Hello, here the code. It uses functions from modules of DAMASK ( [Files · v3.0.0-alpha3 · damask / DAMASK · GitLab (mpie.de)](https://magit1.mpie.de/damask/DAMASK/-/tree/v3.0.0-alpha3)).

Something like this would be the work flow.  
file = Grid.load(ref\_path/‘get\_grain\_boundaries\_8g12x15x20.vtr’)  
GB = file.get\_grain\_boundaries(periodic=True,direction=‘xyz’) GB.save(ref\_path/f’get\_grain\_boundaries\_8g12x15x20\_{direction}\_{periodic}.vtu’,parallel=False)

Cheers,

---

<div class="post-metadata">

### Author: ![N.S](https://discourse.paraview.org/user_avatar/discourse.paraview.org/n.s/32/9435_2.png) [@N.S](https://discourse.paraview.org/u/N.S)
#### Post date: [June 20, 2022, 5:07am UTC](https://discourse.paraview.org/t/grain-boundaries/4984/8 "2022-06-20T05:07:18Z")

</div>

Thanks for the very valuable code!

By the way, can Grid.load() read a vtr file, or if it’s a vti, I’m having trouble getting an error.

---

<div class="post-metadata">

### Author: ![f.gallardo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/f/fbc32d/32.png) [@f.gallardo](https://discourse.paraview.org/u/f.gallardo)
#### Post date: [June 20, 2022, 6:38am UTC](https://discourse.paraview.org/t/grain-boundaries/4984/9 "2022-06-20T06:38:18Z")

</div>

Currently, Grid.load reads both, vti and vtr.

---

<div class="post-metadata">

### Author: ![N.S](https://discourse.paraview.org/user_avatar/discourse.paraview.org/n.s/32/9435_2.png) [@N.S](https://discourse.paraview.org/u/N.S)
#### Post date: [June 20, 2022, 6:50am UTC](https://discourse.paraview.org/t/grain-boundaries/4984/10 "2022-06-20T06:50:28Z")

</div>

Thank you for your prompt reply.

I am having trouble with the following error.  
ValueError: File format VTI not available, choose one of dict\_keys([‘CCP4’, ‘MRC’, ‘DX’, ‘PLT’, ‘PKL’, ‘PICKLE’, ‘PYTHON’])

I thought Grid.load() was GriddataFomats, is that correct?
