Convert a MODFLOW model file to a VTK file
The R code "Convert a Modflow file to VTK" will be presented with a practical example. It is assumed that the user is familiar with the MODFLOW code. VTK is an opensource 3D visualization file format. Converting a MODFLOW model to VTK allows it to be visualized in 3D without the need for commercial softwares. VTK formats can be visualized with various free softwares, Paraview, VisIt, Vistrails, Mayavi..etc. Two inputs are required:
- A MODFLOW discretization file (*.DIS). The DIS file in modflow contains the spatial and temporary discretization of the 3D model. But only the spatial aspect is of interest here
- The model Offset, which is basically the coordinates of the lower left corner of the model. The default values are 0, in which case the model results will be in local coordinates.
The Code is available here.
1. Copy the code, paste it in a text file and save it with the extention *.r (optional), for instance mf2vtk.r
2. Start R and source the R code.
3. The following navigation window will be displayed. Navigate to your *.DIS file select it and click open.
4. The next two windows will pop up asking for the offset in the X and Y direction respectively. Enter your offset. If you don't have these values accept the default 0 values and click ok
5. The next windows allows you to navigate and save the result file. Save it with a *.vtk extension.
6. Now to visualize the results download and install www.paraview.org">http://www.paraview.org">Paraview or any of the VTK visualization tools and open the VTK file you created earlier. Two screenshots are shown below (full 3D and cross-section)
ps: the VTK contains a variable names layernum which represents the model layers, other properties can be added.