Skip to content

Update TensorMesh-OMF interface

Compare
Choose a tag to compare
@lheagy lheagy released this 03 Jul 18:36

Overview

This release adds full support for going back and forth between OMF and discretize.TensorMesh. The OMF support implemented in a previous release only went one way (disscretize ➡️ OMF) and had a bug that messed up the spatial reference of the OMF mesh. This release makes it seamless to go back and forth (discretize ↔️ OMF). Give it a try with the new to_omf(models) method and load your TensorMeshs into other software that supports OMF (e.g. Leapfrog)!

Notes

  • At the moment, only TensorMeshs are supported by OMF
  • OMFv2 should bring more support for Curvilinear and Tree meshes. When that's released we can fill in the methods that currently raises a NotImplementedError
  • These changes makes updates to the TensorMesh-OMF interface to make going to/from OMF/discretize more fluid.

Example

import discretize
import omf
import numpy as np

# Make a TensorMesh
h = np.ones(16)
mesh = discretize.TensorMesh([h, 2*h, 3*h])
vec = np.arange(mesh.nC)
models = {'arange': vec}

# Make an OMF Element
omf_element = mesh.to_omf(models)

# Use OMF to save that element to an OMF project
proj = omf.Project(
    name='My project',
    description='The most awesome project I have ever worked '\
                'on and this is a lengthy description of how '\
                'awesome it is.',
)

# Add the volume element
proj.elements = [omf_element,]

# Verify all is good
assert proj.validate()

# Write it out
omf.OMFWriter(proj, 'myproject.omf')

And now you can use the .omf project file with your tensor mesh or many tensor meshes in your favorite software that supports OMF (e.g. Leapfrog).

Or you could verify this all worked with omfvista:

import omfvista
foo = omfvista.load_project('myproject.omf')
foo.plot()