Skip to content

Creating meshes from CT scan images

mlesueur edited this page Aug 22, 2016 · 27 revisions

MOOSE already possesses the functionality to read a stack of CT scan images and create the corresponding mesh through its ImageReader. But the following paragraph explains why MOOSE's module is limited.

#MOOSE ImageSubdomain Using the function ImageSubdomain, MOOSE creates a mesh of the stack of CT-scan Images with 2 blocks, the pore space and the grains.

Two parameters can be chosen by the user:

  • Type of elements meshed
  • Level of refinement (different options available)

HOWEVER one important parameter can not be changed, level of coarsening. The mesh created can not have elements coarser than the resolution of the image.

Mesh coarsening is an important aspect in simulation with CT-scan images. We want to refine the mesh at the grain's boundary because this is where the simulation is complex. But we want to coarsen the region away from these boundaries in order to reduce simulation time.

This is why I would recommend to use REDBACK Image Reader in order to get the full panel of functionalities.

#REDBACK Image Reader ##Installation The first step is to [install VTK](Installing VTK). Then you have to run REDBACK's tests to make sure that those for ImageSubdomain are not skipped and do not fail.

##Usage

###Process input files The process to create a mesh with adapative refinement from a CT-scan image is in 4steps. These are all the input files you will need to run the process:

  • your stack of images (only 1 if 2D). See [here](Creating png images from raw data) some methods of creating these images from raw data.
  • mesh_generation_step1.i
  • mesh_generation_step2.i
  • remove_duplicates.py
  • mesh_generation_step3.i

A sample of all these files can be found in the folder tests of REDBACK's directory under the folder image_subdomains.

User parameters

In the first file, mesh_generation_step1.i, is all the parameters that the user has to change in order to adapt to his stack of images.

  • dim: The process can run 2D or 3D images.
  • elem_type
  • nx/y/z, x/y/zmax: Size of your mesh, the x/y/z ratio must be adapted to your stack of images but you have to put the smallest ratio possible (if your sample is cubic, nx=ny=nz=1).
  • uniform_refine: a uniform refinement of x means MOOSE builds a mesh of 2^x pixels size. the second step, adaptivity only coarsens the mesh, so you should take the highest refinement in this step.
  • Adaptivity: adaptative coarsening, a few parameters are modifiable in order to best adapt to your model.
  • image_func: this is where you indicate the localisation of your stack of files and their names. For 2 files in the folder stack named test_00.png and test_01.png, the code should be:

file_base = stack/test_0

file_range = '0 1'

In the second file mesh_generation_step2.i the image_func paragraph should be modified like explained above.

In the third file remove_duplicates.py nb_qp should be equal to the number of nodes that your mesh elements have (8 for first order hexagons).

If you are taking the files from the folder tests/image_subdomains you will have to change the path of input files in all the files because they are all pointing to gold/.... Just remove gold/ so that the files will be taken from your working directory.

Manual run

After that your files have been edited, you follow these steps to obtain your mesh from your stack of images. The python file has to be run from your working directory.

  • Run mesh_generation_step1.i. This generates the file 1block_mesh.e. The mesh is created with the level of refinement we want, but the grains and pore space are not separated yet.

  • Run mesh_generation_step2.i. This generates the file idfile.txt containing the list of element ids of the grains subdomain. This file usually may include duplicate elements.

  • Run python remove_duplicates.py. This generates the file idfile_unique.txt containing the list of unique element ids of the grains subdomain.

  • Run mesh_generation_step3.i. This generates the file 2blocks_mesh.e containing the refined mesh with the block of pore space and the block of grains.

Automatic script

All these steps can be run at once using the script steps.sh (located in REDBACK's folder tests/image_subdomains). In you working directory, type in the command line of your terminal

bash steps.sh

The end of each step is notified in your terminal but all the printed output of the runs are exported in result.txt.

I recommand to use this script only after making sure that the manual run is working. This script was not meant for debugging.