Skip to content

Run LaMEM from existing *.dat files ​

Legacy workflow

This page describes the "classical" way of using LaMEM: running a simulation from a parameter (*.dat) file that was written by hand or taken from the LaMEM repository. For new models we recommend creating, running and analysing them directly from Julia, see Create & run LaMEM models from julia. The workflow below remains useful if you already have *.dat files.

Go to the package manager & install it with:

julia
julia>]
pkg>add LaMEM

It will automatically download a binary version of LaMEM which runs in parallel (along with the correct PETSc version). This will work on linux, mac and windows.

Starting a simulation ​

If you have a LaMEM (*.dat) input file, you can run in parallel (here on 4 cores) with:

julia
julia> ParamFile="input_files/FallingBlock_Multigrid.dat";
julia> run_lamem(ParamFile, 4,"-time_end 1")
-------------------------------------------------------------------------- 
                   Lithosphere and Mantle Evolution Model                   
     Compiled: Date: Sep 10 2022 - Time: 06:21:30           
-------------------------------------------------------------------------- 
        STAGGERED-GRID FINITE DIFFERENCE CANONICAL IMPLEMENTATION           
-------------------------------------------------------------------------- 
Parsing input file : input_files/FallingBlock_Multigrid.dat 
   Adding PETSc option: -snes_type ksponly
   Adding PETSc option: -js_ksp_monitor
   Adding PETSc option: -crs_pc_type bjacobi
Finished parsing input file : input_files/FallingBlock_Multigrid.dat 
--------------------------------------------------------------------------
Time stepping parameters:
   Simulation end time          : 1. [ ] 
   Maximum number of steps      : 10 
   Time step                    : 10. [ ] 
   Minimum time step            : 1e-05 [ ] 
   Maximum time step            : 100. [ ] 
   Time step increase factor    : 0.1 
   CFL criterion                : 0.5 
   CFLMAX (fixed time steps)    : 0.5 
   Output time step             : 0.2 [ ] 
   Output every [n] steps       : 1 
   Output [n] initial steps     : 1 
--------------------------------------------------------------------------

The last parameter are optional PETSc command-line options. By default it runs on one processor.

Saving the output to a logfile ​

The LaMEM output is shown in the REPL, but not saved to disk. If you run LaMEM through a queueing system such as slurm you usually get a logfile automatically, but on a local machine you do not. Use the logfile keyword to save the output to a file in addition to showing it in the REPL:

julia
julia> run_lamem(ParamFile, 4, "-time_end 1", logfile="test")

This writes test.log. A name that already has an extension is used as given, so logfile="test.out" writes test.out.

This also works when you run a julia-defined Model, in which case a relative name ends up in the output directory of the model, next to the other output of the run:

julia
julia> run_lamem(model, 1, logfile="test")    # writes <out_dir>/test.log

If you restart a simulation from LaMEM's restart database (with -mode restart), the output of the restarted run is added to an existing logfile, under a line that marks where the restart begins, so the log of a simulation that was restarted a few times stays in one file:

julia
julia> run_lamem(ParamFile, 4, logfile="test")                  # writes test.log
julia> run_lamem(ParamFile, 4, "-mode restart", logfile="test") # appends to test.log

A normal (non-restart) run instead starts a fresh logfile. Use the append keyword if you want to decide this yourself, e.g. append=true to always add to an existing file, or append=false to always overwrite it.

Such a logfile can afterwards be analysed with read_LaMEM_logfile, provided the simulation was run with the -log_view option of PETSc.

Please note that you will have to be in the correct directory or indicate where that directory is. If you are in a different directory, the easiest way to change to the correct one is by using the changefolder function (on Windows and Mac):

julia
julia> changefolder()

Alternatively, you can use the build-in terminal/shell in julia, which you can access with:

julia
julia>;
shell>cd ~/LaMEM/input_models/BuildInSetups/

use the Backspace key to return to the julia REPL.

Once you have performed a simulation, you can look at the results by opening the *.pvd files with Paraview. In this example, that would be FB_multigrid.pvd and FB_multigrid_phase.pvd.