tbenthompson / okada_wrapper

MATLAB and Python wrappers of the Okada Green's functions.
MIT License
67 stars 33 forks source link

Note: please consider using cutde instead of okada_wrapper. Triangular dislocations are strictly more powerful than rectangles. In addition, cutde supports many features not supported by okada_wrapper, including built-in tools to build large matrices or construct hierarchical matrix approximations. If you need a rectangular dislocation, one can easily be composed from two triangles.

Okada wrapper (MATLAB, Python)

Okada dislocations in Python and MATLAB!

These files are MATLAB and Python wrappers for the Okada DC3D0 point source and the DC3D rectangular dislocation surface fortran subroutines. The Matlab wrappers are written using the MEX functions. The original subroutine was written by Y. Okada as part of the paper:

Okada, Y., 1992, Internal deformation due to shear and tensile faults in a half-space, Bull. Seism. Soc. Am., 82, 1018-1040.

The inputs and outputs here are slightly different from the okada implementation, though not in any substantial way. Look at the original documentation webpage here for more details

A different MATLAB mex wrapper for the Okada dislocation sources is available on Paul Segall's website.

Common issues:

If you're having problems installing on a recent version of OSX, see here for some help: https://github.com/tbenthompson/okada_wrapper/issues/3

MATLAB

Download the code::

git clone https://github.com/tbenthompson/okada_wrapper.git

Make sure that MATLAB has a properly configured compiler. This page on MATLAB's site has details. It seem like GCC is automatically found if it is installed.

Open matlab and run::

mex 'DC3D0wrapper.F'
mex 'DC3Dwrapper.F'
DC3D0wrapper

Then, DC3D0wrapper can be treated like any other MATLAB function::

[success, u, grad_u] = DC3D0wrapper(0.6, [1.0, 1.0, -1.0],3.0,...
                                    90, [1.0, 0.0, 0.0, 0.0]);

Five arguments are required:

Three outputs are provided:

DC3Dwrapper

DC3Dwrapper can also be used for rectangular dislocation sources

[success, u, grad_u] = DC3Dwrapper(0.6, [1.0, 1.0, -1.0], 3.0,...
                                    90, [-0.7, 0.7], [-0.7, 0.7],...
                                    [1.0, 0.0, 0.0]);

Seven arguments are required:

The outputs are identical to DC3D0wrapper

Python

NEW: You can install okada_wrapper directly from the PyPI by running::

pip install okada_wrapper

For the old, manual installation method, download the code::

git clone https://github.com/tbenthompson/okada_wrapper.git

Make sure that a Fortran compiler is installed. The wrappers are tested using gcc/gfortran, but should hopefully work with other fortran compilers.

Then, run the install script::

pip install ./okada_wrapper

The syntax is almost identical to the MATLAB version::

from okada_wrapper import dc3d0wrapper, dc3dwrapper
success, u, grad_u = dc3d0wrapper(0.6, [1.0, 1.0, -1.0], 3.0,
                                  1.0, [1.0, 0.0, 0.0, 0.0])
success, u, grad_u = dc3dwrapper(0.6, [1.0, 1.0, -1.0],
                                 3.0, 90, [-0.7, 0.7], [-0.7, 0.7],
                                 [1.0, 0.0, 0.0])                                      

The arguments and outputs are identical to the MATLAB version.

Tests

To run the tests, from the root directory in MATLAB type::

test_okada.m

or, for python::

python test_okada.py

Okada plot