Skip to content

molivag/MeshTran

Repository files navigation

MeshTran

Mesh transformation utilities for FEMTIC-based magnetotelluric inverse modeling.

MeshTran is an open-source preprocessing toolkit designed to prepare spatial data and computational domains for the Finite Element Magnetotelluric Inversion Code, FEMTIC (Y. Usui, 2015). The objective of this project is not to replace FEMTIC utilities, but to provide a structured preprocessing layer that simplifies coordinate transformations, domain definition, and mesh preparation steps commonly required before running large-scale MT inversions.

The toolkit focuses on reproducible preparation of FEMTIC input files from observational data and geospatial datasets. In particular, MeshTran aims to reduce the complexity of preparing the FEMTIC preprocessing input data by allowing most mesh preparation steps to be controlled from a single configuration file.

MeshTran is also designed as a component of the broader MTIF (Magnetotelluric Inversion Framework) ecosystem, where it acts as the geometry and preprocessing layer prior to running the inversion workflow.


Features

Current utilities support the following preprocessing tasks:

  • Reading MT station information from EDI files
  • Coordinate transformation (latitude/longitude → UTM → mesh coordinates)
  • Domain centering and coordinate normalization
  • DEM and bathymetry integration
  • Automated generation of FEMTIC input files
  • Preparation of geometry and inputs for makeTetraMesh and TetGen
  • Simplified configuration of FEMTIC meshing parameters
  • Basic validation utilities for domain consistency

A key goal of MeshTran is to simplify FEMTIC mesh configuration. Instead of manually editing multiple preprocessing files, users can define the required parameters in a single configuration input, from which MeshTran generates the corresponding FEMTIC input files.


Workflow Overview

The typical preprocessing pipeline implemented in MeshTran follows these steps:

  1. Reading configuration file
  2. Read DEM and EDI files, extracting latitude, longitude, and elevation
    • 1.1 For the stydy cases involves sea, extracting coast line
    • 1.2 Performing the ray casting algorithm to land-sea classification
  3. Convert geographic coordinates from DEM and EDI files to kilometers UTM coordinates
  4. Transform coordinates into the local mesh reference system
  5. Read from EDI files, impedance tensor data and choose the error floor or assigned error must be applied to the data
  6. Write observe data file.
  7. Validate domain coverage with DEM and asign padding constraints to land only cases.
  8. Define the computational analysis domain in local mesh coordinates
  9. Writing topography, bathymetry and coast line files.
  10. Writing files for surface refinement at site zones and two-dimensional surface mesh
  11. Generating volumetric refinement file below site zones and file for volumetric iterative refinement.
  12. Writing files for model parameter mesh getting resistivity_attr file.
  13. Running a wrapper of makeTetraMesh
  14. Run wrapped TetGen to get volumetric mesh in *.ele,*.edge,*.node,*.face and .neigh files.
  15. Running iterative refinement
  16. Running wrapped TetGen2Femtic
  17. Generating input files ready for FEMTIC inversion

Input files generated by MeshTran

Observe data.

  • observe.dat

Geometry.

  • control.dat         →   (surface mesh)
  • topography.dat
  • bathymetry.dat
  • coastline.dat
  • observing_site.dat
  • analysis_domain.dat

Mesh refinement.

  • makeMtr.param
  • obs_site.dat

TetGen and convertion to FEMTIC

  • output.X.node
  • output.X.ele
  • output.X.face
  • output.X.neigh
  • resistivity_attr.dat

FEMTIC inputs

  • resistivity_block_iter0.dat
  • mesh.dat
  • output.*.femtic.vtk

The control.dat file (not generated by MeshTran), which defines the inversion parameters, should be created manually according to the desired configuration.


Repository Structure

The repository is organized as follows:

MeshTran/
├─ Makefile
├── readme.md
├── computing
├── meshTran (executable must be compiled)
├── mod
├── set_meshtran.io
│ 
├── preprocessing
│   ├── buildMesh
│   ├── DEM
│   ├── edi_files
│   └── geometry
│ 
└── src
    ├── mesh_config.f90
    ├── mesh_entities.f90
    └── meshTranFemtic.f90

The structure may evolve as the project matures.

Usage

A minimal preprocessing workflow using MeshTran follows these steps:

  1. Put the DEM.xyz and EDI files in preprocessing/ folder

  2. Provide a configuration file (*.io) setting the dataset and meshing parameters.

  3. Compile MeshTran by running:

    make
  4. Run the MeshTran preprocessing workflow by:

    ./meshTran
  5. Generate FEMTIC input files in computing/ after meshtran execution.

By these simple steps it processes station data, prepares the computational domain, and generates the required FEMTIC preprocessing files.


Example of set_meshtran.io input file.

See the MeshTran Wiki for a detailed example configuration file and guides on mesh quality, coastline extraction, and advanced workflow configuration.


Integration with MTIF

MeshTran is designed to function as a preprocessing component within the MTIF (Magnetotelluric Inversion Framework).

Within MTIF, configuration is typically handled using structured configuration files (e.g. TOML), which are more expressive and easier to maintain than the traditional FEMTIC plaintext input files. MeshTran acts as the intermediate layer that translates these higher-level configuration parameters into the FEMTIC input format required by the meshing and inversion pipeline.


Dependencies

MeshTran is a Linux tool. At build time it only links against the Intel toolchain below; all geometry/topography processing is delegated to external CLI tools invoked as subprocesses via Fortran's execute_command_line, which must be available on $PATH.

Build-time

  • Intel OneAPI HPC Toolkit 2024.0
  • Intel ifort 2021.11.1 20231117 (included in the OneAPI described above)
  • Intel MKL 2024.0

Runtime — external CLI tools (invoked via execute_command_line)

Tool Version Tested Used For
gdal_contour GDAL 3.9.3 (2024-10-07) Coastline contour extraction from DEM (GeoJSON)
jq 1.7.1 Parse coastline GeoJSON into coordinate CSV
ogr2ogr GDAL 3.9.3 (2024-10-07) Convert line geometry to Shapefile
ogrinfo GDAL 3.9.3 (2024-10-07) Inspect Shapefile attributes and IDs
gnuplot 6.0 patchlevel 1 Diagnostic visualization of DEM and coastline
TetGen 1.5 (2013-11-04) Tetrahedral mesh generation

Required external binaries (built/installed separately by the user)

  • tetGen2Femtic v1.0
  • makeTetraMesh v1.3
  • makeMtr v1.0

The TetGen execution parameters can be modified and MeshTran must be recompiled if different meshing behavior is desired.


Project Status

This project is currently under active development. And it already covers the necessary preprocessing steps required to generate the input files needed to run land-only and land-sea magnetotelluric inversion models with FEMTIC.

Interfaces and utilities may evolve as the preprocessing workflow matures. The code is primarily developed to support FEMTIC-based magnetotelluric inversion model research.


Portability

Due to the nature of its underlying system calls, MeshTran is a tool focused primarily on Linux and macOS (Unix-like systems). For Windows users, a Docker container is planned to be implemented in the future.


Citation

If you use MeshTran, please cite the software using the GitHub "Cite this repository" button or the DOI assigned by Zenodo.

About

Open-source preprocessing tool for mesh and model preparation for FEMTIC-based magnetotelluric inversion.

Topics

Resources

License

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors