-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New capability to visualize stratigraphy in Paraview
- Loading branch information
1 parent
62cafea
commit c81dc07
Showing
1 changed file
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Badlands vtk stratigraphic mesh creation\n", | ||
"\n", | ||
"If the stratigraphic structure is turned on in the XmL input file, **Badlands** produces sedimentary layers Hdf5 files. The stratigraphic layers are defined on a regularly spaced grid and a layer is recorded at each layer time interval given by the user.\n", | ||
"\n", | ||
"Here we build a vtk **structured grid** based on the stratal layers that could be visualise directly in **Paraview/Visit**." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"# Import badlands grid generation toolbox\n", | ||
"import pybadlands_companion.stratalMesh as mesh\n", | ||
"\n", | ||
"# display plots in SVG format\n", | ||
"%config InlineBackend.figure_format = 'svg' " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Loading stratigraphic file\n", | ||
"\n", | ||
"First we need to load one of the stratigraphic file. The files are located in the **h5/** folder in the simulation main output folder and are named using the following convention:\n", | ||
"- `sed.time`T`.p`X`.hdf5`\n", | ||
"\n", | ||
"with T the display time index and X the number of the partition (used in the parallel version). In cases where you ran your simulation in parallel you will also need to give the number of CPUs used (_cpus_).\n", | ||
"\n", | ||
"To load a file you will need to give the folder name and the number of processors used in your simulation.\n", | ||
"\n", | ||
"For more information regarding the function uncomment the following line." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"folder = '/workspace/volume/outbdls'\n", | ||
"vtkMesh = mesh.stratalMesh(folder+'/h5')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Then we need to load a particular output time interval (this is the T parameter in the hdf5 file name convention).\n", | ||
"\n", | ||
"**Note**\n", | ||
"\n", | ||
"This number is not always the number of sedimentary layers for this particular time step as you could have chosen in the input file to have more than 1 sedimentary layer recorded by output interval!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"vtkMesh.loadStratigraphy(timestep=30) #last timestep -1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Building the vtk unstructured grid\n", | ||
"\n", | ||
"We then build the stratigraphic mesh for the considered time interval. \n", | ||
"\n", | ||
"You need to specify the folder where you want your output to be stored.\n", | ||
"\n", | ||
"The mesh file names will have the following convention:\n", | ||
"\n", | ||
"- `stratalMesh.time`T`.vts`\n", | ||
"\n", | ||
"with T the display time index." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"vtkMesh.buildMesh(outfolder='/workspace/volume/outbdls')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"folder = '/workspace/volume/outbdls'\n", | ||
"vtkMesh = mesh.stratalMesh(folder+'/h5')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Number of visualisation steps created: 313\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import glob,re\n", | ||
"folder2 = '/workspace/volume/outbdls'\n", | ||
"stepCounter = len(glob.glob1(folder2+\"/xmf/\",\"tin.time*\"))-1\n", | ||
"print \"Number of visualisation steps created: \",stepCounter" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pvd_file = folder+'/stratiView.pvd'\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"f= open(str(pvd_file),'w')\n", | ||
"\n", | ||
"f.write('<?xml version=\"1.0\"?>\\n')\n", | ||
"f.write('<VTKFile type=\"Collection\" version=\"0.1\"\\n')\n", | ||
"f.write(' byte_order=\"LittleEndian\"\\n')\n", | ||
"f.write(' compressor=\"vtkZLibDataCompressor\">\\n')\n", | ||
"f.write(' <Collection>\\n')\n", | ||
"\n", | ||
"kk = 0\n", | ||
"for k in range(1,stepCounter+1,1):#change timestep 10/50/,...\n", | ||
" vtkMesh.loadStratigraphy(timestep=k)\n", | ||
" vtkMesh.buildMesh(outfolder=folder+'/h5')\n", | ||
" # Get the sea level history and depositional time for each stratigraphic layer\n", | ||
" with open(folder+'/xmf/tin.time'+str(k)+'.xmf') as fp:\n", | ||
" line = fp.readline()\n", | ||
" while line:\n", | ||
" if 'Time' in line:\n", | ||
" val = [float(s) for s in re.findall(r'-?\\d+\\.?\\d*', line)]\n", | ||
" time = val[0]\n", | ||
" line = fp.readline()\n", | ||
" print 'Rendering for time step '+str(k)+': '+str(time)+' years'\n", | ||
" f.write(' <DataSet timestep=\"%s\" group=\"\" part=\"%d\" file=\"xmf/strat.time%d.vtm\"/>\\n'%(time,kk,kk))\n", | ||
" # Create the VTM\n", | ||
" vtm_file = folder+'/xmf/strat.time'+str(kk)+'.vtm'\n", | ||
" fvtm= open(str(vtm_file),'w')\n", | ||
" fvtm.write('<?xml version=\"1.0\"?>\\n')\n", | ||
" fvtm.write('<VTKFile type=\"vtkMultiBlockDataSet\" version=\"1.0\">\\n')\n", | ||
" fvtm.write(' <vtkMultiBlockDataSet>\\n')\n", | ||
" fvtm.write(' <DataSet index=\"0\" name=\"\" file=\"../h5/stratalMesh.time%d.vts\"/> \\n'%k)\n", | ||
" fvtm.write(' </vtkMultiBlockDataSet>\\n')\n", | ||
" fvtm.write('</VTKFile>\\n')\n", | ||
" fvtm.close()\n", | ||
" kk += 1\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"f.write(' </Collection>\\n')\n", | ||
"f.write('</VTKFile>\\n')\n", | ||
"f.close()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |