Mushy Layer
1.0
|
This is code to simulate flow in a reactive porous media, a "mushy layer", within a square box.
In this readme we first present some instructions on downloading and installing the code, then describe how to recreate the test problems and figures found in the scientific paper (currently unpublished, email [james] for a copy) written about this method. The paper is a good reference for more information on the physics of this model. .par kinso n@ph ysics .ox. ac.uk
If you have any issues, please contact [james]. .par kinso n@ph ysics .ox. ac.uk
AMRFASMultigrid
functionality, required for solving nonlinear elliptic equations.Cloning the repository from GitHub is straightforward:
To fetch and merge any changes to the library, use git pull
.
To compile the code, you must first have a working Chombo installation (see the ChomboInstallationGuide.md file in the docs folder). Define the path to your chombo library folder in the GNUMakefile (/execSubcyle/GNUMakefile
) then you should be able to compile by
You should also add an environment variable MUSHY_LAYER_DIR
which points to /path/to/mushy-layer/
for some of the python scripts to work. E.g.
The executable in /execSubcycle/
requires inputs in order to run. These can either be supplied at the command line or, more sensibly, by specifying the location of a file which contains a list of inputs, e.g.
where inputs is a file in /execSubcycle/
.
For more details on how to setup your inputs file for the problem you're interested in, see /docs/RunningTheMushyLayerCode.md/
.
There are example problems, with input files, in the /examples/
directory.
For running in parallel (with 2 processors in this example), run the code like
Documentation can be generated using Doyxgen if it is installed. A default configuration file can be found in the /docs/
directory, which can be run via:
You can also find a reasonably up to date version of the documentation online at [https://jrgparkinson.github.io/mushy-layer/doc/html/index.html], if you do not want to compile it yourself. The Classes section is particularly useful.
This repository contains various other pieces of code for running simulations.
/setupNewRun/
takes a checkpoint file and creates a new file with the same data on a domain with a different width, which is useful for computing optimal states. /postProcess/
loads checkpoint files and computes various diagnostics that were not run during the simulations. /VisitPatch/
describes a small patch for the VISIT software to allow you to open checkpoint files as well as plot files. /params/
contains input files for different types of simulations. They may not all work, sorry. /grids/
contains gridfiles which can be loaded via main.gridfile=/path/to/gridfile
in an inputs file, and sets a fixed variable mesh (i.e. not adaptive) for simulations. /mk/
contains some custom Makefile options for compiling on some of the machines in AOPP at the University of Oxford.
The code in /setupNewRun/
and /postProcess/
needs to be compiled like the code in /execSubcycle/
. First update the GNUMakefile
files in each subdirectory, then run make all
as before.
The source code is spread across a number of directories, which are briefly summarised here.
/BCutil/
contains code for implementing boundary conditions. /util/
contains code for various non-mushy layer specific operations, e.g. computing gradients, divergences etc. /src/
contains mushy layer code /srcSubcycle/
contains mushy layer code for the subcycled algorithm /execSubcyle/
contains the driver code the subcycled application /srcNonSubcycle/
contains mushy layer code for the non-subcycled algorithm (currently broken) /execNonSubcycle/
contains the driver code for the non-subcycle application (currently broken)
We have written a paper describing the physics of this model. A draft can be found in the /docs/
directory. In this paper, we demonstrate the accuracy and convergence properties of our code. Everything you need to run these tests yourself should be found in the /tests/
directory, as described below.
/test/
contains python scripts for running various test problems, which demonstrate the accuracy and efficiency of the code. You can run all the problems via the script runMethodsPaperTests.py
. For more information, see the README located in the /test/
directory.
You must ensure that the /test/
directory is in your PYTHONPATH
, i.e. place the following in your ~/.bashrc or similar
The analysis is performed by matlab scripts located in /matlab/*
, which must be added to your matlab path to be executed:
Note that running all the tests will take some time unless you have lots of processors available (i.e. multiple days) and will take up a reasonable amount of disk space (~50GB).
Having run the test problems, some of the figures found in the paper will have been created automatically in the subdirectory for each tests problem (e.g. /path/to/test_output/FixedPorousHole-1proc/Fig6Error-xDarcy_velocity-L2.eps
). The python script located at mushy-layer/test/makeFigures.py
should then make the remaining figures for you, mainly by calling various matlab scripts.
In this section we briefly describe how the code works with the Chombo library so solve equations on a hierarchy of adaptive meshes. If you are planning on making changes to the code, or want to see which bits solve which equations, this might be a useful starting point. If you are going to look at the code regularly, you are highly recommended to use an Integrated Development Environment (IDE) - e.g. Eclipse. Brief setup instructions for Eclipse can be found below.
The mushy layer code starts in execSubcycle/mushyLayer.cpp
. The function mushyLayer(...)
calls various other methods from src/MushyLayerUtils.cpp
and srcSubcycle/MushyLayerSubcycleUtils.cpp
to a) Create the problem domain b) Create a 'Mushy Layer Factory' object which tells Chombo how to make a new Mushy Layer object for handling integration of the governing equations on one level of refinement c) Create an AMR
object which handles solving the equations over a hierarchy of levels.
The code then tells the AMR object to run until a certain time or number of steps. The AMR object is the heart of Chombo. It continually evolves the solution, periodically calling into functions from the Mushy Layer code to do things, e.g.
srcSubcycle/AMRLevelMushyLayerInit.cpp
.srcSubcycle/AMRLevelMushyLayer.cpp
in the advance(...)
function (which subsequently calls lots of other mushy layer functions).srcSubcycle/AMRLevelMushyLayer.cpp :: computeDt()
.srcSubcycle/AMRLevelMushyLayerRegrid.cpp :: regrid(..)
.srcSubcycle/AMRLevelMushyLayerSync.cpp :: postTimestep(..)
Within the advance(..)
method, the key pieces are:
computeAdvectionVelocities(..)
- computes face centered velocities for doing advection with.exitStatus = multiCompAdvectDiffuse(HC_old, HC_new, srcMultiComp, doFRUpdates, doAdvectiveSrc);
- updates enthalpy and salinity fields.computeCCvelocity(advectionSourceTerm, m_time-m_dt, m_dt, doFRupdates, doProjection, compute_uDelU);
- compute new cell centred velocity.For those new to this code/Chombo, here are some tips:
getCoarserLevel()
, getFinerLevel()
.m_time
is the new time ($t^{n+1} = t^n + t$).m_scalarNew
, m_vectorNew
, indexed by the field name, i.e. enthalpy on a level of refinement is m_scalarNew[ScalarVars::m_enthalpy]
fillScalars(..)
, e.g. fillScalars(*m_scalarNew[ScalarVars::m_enthalpy], m_time, ScalarVars::m_enthalpy);
Eclipse is an Integrated Development Environment (IDE). In short, it is a powerful code editor (syntax highlighting, advanced find/replace) which also understands the structure of a program. For codes like this one which are spread over multiple files in multiple folders, and use external libraries, it is invaluable. Useful features include:
In short, it's a bit like MATLAB (but for C++).
Setting up Eclipse with the Mushy Layer is not difficult, but also requires quite a few steps (should take 30 mins, but took me many hours to work them all out from scratch). The following steps should do the job. We assume that you are already able to compile and run the Mushy Layer code.
LD_LIBRARY_PATH = /usr/local/hdf5-1.8.21p-v18/lib:
The first should point to your hdf5 installation./path/to/mushy-layer
, and choose a sensible name (we went for 'MushyLayer'). Again choose the Linux GCC toolchain.${workspace_loc:/MushyLayer}/execSubcycle/
. When you use this build profile, you will create an executable using the default options in your Make.defs.local file.make DEBUG=TRUE OPT=FALSE
. When you use this build profile, you will force the compiler to use the DEBUG flags and not use the OPT flags. This creates and executable suitable for debugging with.mushyLayer2d.Linux.64.mpiCC.gfortran.DEBUG.MPI.ex
. For Build configuration, choose the debug configuration you just created. Now go to the Arguments tab and enter the name of the inputs file you'll want to use for your debugging (you'll probably find you change this a lot). Make sure the Working Directory at the bottom is set to ${workspace_loc:MushyLayer}/execSubcycle
. Now go to the Environment tab and set CH_TIMER=1
- this makes sure chombo produces timing output from simulations, which can be useful. VISITHOME=/path/to/visit2.12.0/src
- this allows Eclipse to find your installation of Visit (if you've installed Visit) so it can be used for debugging. (your visit installation is likely in a different place) LD_LIBRARY_PATH=/usr/local/hdf5-1.8.21p-v18/lib:
- make sure Eclipse can find HDF5. (your hdf5 installation is likely in a different place) Finally, go to the Debugger tab and uncheck 'Stop on startup at: main' as otherwise this will drive you crazy.You should now be all set up for debugging. Here is an example. Open up srcSubcycle/AMRLevelMushyLayer.cpp
, find the advance(...)
method (the outline panel on the right hand side is useful for this) and find the code
Insert a breakpoint on the if...
line (Run->Toggle breakpoint) and then go Run->Debug. The code should run until this line then stop. Let's have a look at the source term for the advection velocity solve. In the console at the bottom of the window, enter call viewLevel(&advectionSourceTerm)
and an instance of Visit should open showing you the source term field on this level of refinement. Now step through the lines (F6) until you get past this if/else
clause, by which point you will have calculated the advection velocity. We can look at this by entering call viewFluxLevel(&m_advVel)
Other useful options available for viewing data include
viewFAB(&fab)
for FArrayBoxes (LevelData's are composed of FArrayBoxes). If you have a FluxBox fluxbox
instead, you can look at each component in turn with viewFAB(&fluxbox[0])
, viewFAB(&fluxbox[1])
etc.p m_time
return the value of any variable (you can also hover over a variable in the editor window).There are probably more, and these are documented in the ChomboDesign.pdf document.