Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchengtkc committed Oct 27, 2023
1 parent 427e2e3 commit 59af220
Show file tree
Hide file tree
Showing 81 changed files with 14,295 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM mcr.microsoft.com/devcontainers/base:bullseye
# FROM mcr.microsoft.com/devcontainers/base:jammy

ARG DEBIAN_FRONTEND=noninteractive
ARG USER=vscode

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev

# Python and poetry installation
USER $USER
ARG HOME="/home/$USER"
ARG PYTHON_VERSION=3.11
# ARG PYTHON_VERSION=3.10

ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${HOME}/.local/bin:$PATH"

RUN echo "done 0" \
&& curl https://pyenv.run | bash \
&& echo "done 1" \
&& pyenv install ${PYTHON_VERSION} \
&& echo "done 2" \
&& pyenv global ${PYTHON_VERSION} \
&& echo "done 3" \
&& curl -sSL https://install.python-poetry.org | python3 - \
&& poetry config virtualenvs.in-project true
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "poetry3-poetry-pyenv",
"build": {
"dockerfile": "Dockerfile"
},

// 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features.
// "features": {},

// 👇 Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// 👇 Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "poetry install --with dev --no-interaction",

// 👇 Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions":["ms-python.python", "njpwerner.autodocstring"]
}
}

// 👇 Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
36 changes: 36 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: docs

on:
workflow_dispatch:
push:
branches: [ main ]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2


- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3
poetry install --with dev --no-interaction
- name: Build
run: |
cd docs
sudo apt-get install pandoc
poetry run make html
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html
destination_dir: ./
48 changes: 48 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Tests

on:
workflow_dispatch:
push:
branches: [ main, dev ]
pull_request:
branches: [ main , dev ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10','3.11']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3
poetry install --with dev --no-interaction
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=examples
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=examples
- name: Test with pytest
run: |
poetry run pytest --cov-report=term-missing --cov=temperer tests/ | tee pytest-coverage.txt
- name: Comment coverage
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
uses: coroo/[email protected]
with:
pytest-coverage: pytest-coverage.txt
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

#others
*.spyproject
INPUTS/
RESULTS/
.ipynb_checkpoints
dask-worker-space/
*.mat
*.vscode
*.DS_Store
venv/
others/
__pycache__/
*.egg-info/
.eggs/

.testmondata
.pytest_cache
.coverage

nodes-mapA/
out-mapA/
out-mapA-2
temp/

exec/
exec2/
exec3/
exec4/
exec5/
exec6/
exec7/
exec8/
exec9/
exec10/
exec11/
exec12/
exec13/

docs/_build
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
# pysubsheat
# SubsHeat
## Forward modeling of thermal evolution in geological time

![Build Status](https://github.com/equinor/SubsHeat/actions/workflows/python-test.yml/badge.svg?branch=main)
![Build Status](https://github.com/equinor/SubsHeat/actions/workflows/docs.yml/badge.svg?branch=main)

[Documentation](https://curly-adventure-5mpe5wj.pages.github.io/)

SubsHeat is a python package used for modeling thermal evolution based on McKenzie's type basin extension. It can be use for:

- Finding beta factor
- Calculating subsidence and thermal history
- Basement heat flow through time

## Features

- Build model from either:
- Python objects
- [XTGeo](https://github.com/equinor/xtgeo/) supported surface formats
- [PetroMod](https://www.software.slb.com/products/petromod) models using [petromodder](https://github.com/equinor/petromodder)
- Multi-rift phase support
- Numba accelerated
- Dask support

## SubsHeat3D
3D simulations in SubsHeat are under active development. Currently, yhey are based on a uniform reactangular grid of 1D nodes (defined in a NodeGrid data structure). The sediment inputs, horizons are present day, are provided as .gri files, which are read into a SedimentStack class.

### Pre-requisite: grid of 1D node simulation
The complete 1D SubsHeat simulation is run for some of the 1D nodes. For other 1D nodes the subsidence, beta factor, and crustal thickness are interpolated. The 1D simulations can be run using the script [parallel-1Dsed.py](subsheat3D/parallel-1Dsed.py). Results for each node are pickled to a separate file (this is to be improved!).

### 3D heat equation simulation using dolfinx
The 3D simulation performs a series of heat equation solves, regularly updating the mesh positions from the 1D nodes. The equations are solved using the PETSc solver from the dolfinx package (part of the FeNiCs project). The compute mesh is built by defining hexahedra for every rectangle of 1D nodes and for every layer (i.e. each sediment, the crust, the lithosphere, and the aesthenosphere), which are then subdivided into tetrahedra.

The dolfinx model building and solving is managed by the class [UniformNodeGridFixedSizeMeshModel](subsheat3D/fixed_mesh_model.py). The use of this class is demonstrated in [subsheat3D_mapA_example.py](tests/subsheat3D_mapA_example.py). Note that the NodeGrid class definition in this script should match the definition used in [parallel-1Dsed.py](subsheat3D/parallel-1Dsed.py) to compute the 1D solutions. This script writes the results (mesh positions and function values) at every 1M years in xdmf format for visualization in ParaView.

### RESQML output
The test script [subsheat3D_mapA_example.py](tests/subsheat3D_mapA_example.py) further demonstrates writing the unstructured grid (with properties) in RESQML format, as a pair of .epc and .h5 files. The RESQML I/O functions are in a separate file, [resqpy_helpers.py](subsheat3D/resqpy_helpers.py), and require a modified version of the resqpy library. To visualise RESQML data in ParaView, a 3rd-party plug-in can be installed, see [fespp](https://github.com/F2I-Consulting/fespp).

### SubsHeat3D dependencies
The dolfinx package is Linux-only(?) and has to be compiled from source or installed using apt-get. The resqpy dependency can be installed with pip, but, for now, some writing of properties on unstructured grids requires a change in resqpy that is not yet merged. The other dependencies xtgeo and meshio can be installed using pip (requirements file is to be added).


## Installation

SubsHeat support Python >=3.7, <3.10.

Install from source by cloning this repo

```
git clone https://github.com/equinor/SubsHeat.git
pip install -e .
```
or install from Azure private feed. Contact us for access

```
pip install --extra-index-url \
https://x:<token>@pkgs.dev.azure.com/Equinor/DIPVP/_packaging/ET_PSM/pypi/simple \
subsheat
```

## Development

Easiest is to use codespace:
https://docs.github.com/en/codespaces/getting-started/quickstart

Or use our devcontainer:
https://code.visualstudio.com/docs/remote/containers

## Run tests

`poetry run pytest --cov-report=term-missing --cov=subsheat tests/ | tee pytest-coverage.txt`

## License

20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
36 changes: 36 additions & 0 deletions docs/apireference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
==================================
API Reference
==================================


Model
---------------
.. automodule:: temperer.model
:members:

Model builder
---------------
.. automodule:: temperer.build
:members:
.. autoclass:: temperer.build.Builder
:members:

Parameters
---------------
.. automodule:: temperer.parameters
:members:

Forward model
---------------
.. automodule:: temperer.forward_modelling
:members:

Simulator
---------------
.. automodule:: temperer.simulator
:members:

Results
---------------
.. automodule:: temperer.postprocessing
:members:
Loading

0 comments on commit 59af220

Please sign in to comment.