Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ogs/tools/ogstools
  • felikskiszkurno/ogstools
  • bilke/ogstools
  • dominik-kern/ogstools
  • heinzej/ogstools
  • TobiasMeisel/ogstools
  • FZill/ogstools
  • Max_Jaeschke/ogstools
  • baxmittens/ogstools
  • ChaofanChen/ogstools
  • Scinopode/ogstools
  • HBShaoUFZ/ogstools
  • suresh199824/ogstools
13 results
Show changes
Commits on Source (905)
Showing
with 722 additions and 116 deletions
FROM mcr.microsoft.com/devcontainers/python:3.9-bookworm
FROM mcr.microsoft.com/devcontainers/python:3.10-bookworm
# FEFLOW, instructions from https://download.feflow.com/download/FEFLOW/linux/
ENV \
# Adapt when changing base image:
DIST_DIR=ub2204x64
RUN apt-get update \
&& apt-get install -yq --no-install-recommends gpg curl ca-certificates \
&& curl -fsSL https://download.feflow.com/download/FEFLOW/linux/dhi-feflow-key.asc | gpg --dearmor | sudo tee /usr/share/keyrings/feflow.gpg > /dev/null \
&& apt-get install -yq --no-install-recommends gpg curl ca-certificates
# Error: The following packages have unmet dependencies:
# feflow-console81 : Depends: aspnetcore-runtime-6.0 but it is not installable
# Add dot net repos for debian 12 (bookworm base image)
RUN curl -fsSL https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -o packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb && rm packages-microsoft-prod.deb
RUN curl -fsSL https://download.feflow.com/download/FEFLOW/linux/dhi-feflow-key.asc | gpg --dearmor | sudo tee /usr/share/keyrings/feflow.gpg > /dev/null \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/feflow.gpg] https://download.feflow.com/download/FEFLOW/linux/apt-repo/$DIST_DIR stable main" | sudo tee /etc/apt/sources.list.d/feflow.stable.list \
&& apt-get update \
&& apt list | grep feflow \
&& apt-get install -yq --no-install-recommends feflow-ifm-devel feflow-python80 \
&& yes | apt-get -y install -yq --no-install-recommends feflow100-ifm-devel feflow100-python \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
ENV \
PYTHONPATH=/opt/feflow/8.0/python \
LD_LIBRARY_PATH=/opt/feflow/8.0/lib64:/opt/feflow/common/qt/lib64:/opt/feflow/common/lib64 \
FEFLOW80_ROOT=/opt/feflow/8.0
PYTHONPATH=/opt/feflow/10.0/python \
LD_LIBRARY_PATH=/opt/feflow/10.0/lib64:/opt/feflow/10.0/qt/lib64 \
FEFLOW100_ROOT=/opt/feflow/10.0
......@@ -2,9 +2,11 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "ogstools with FEFLOW",
"build": {
"dockerfile": "Dockerfile"
},
// Swap "build" and "image" for locally building the container
// "build": {
// "dockerfile": "Dockerfile"
// },
"image": "registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.10",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/git-lfs:1": {}
......@@ -16,7 +18,8 @@
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.black-formatter"
"ms-python.black-formatter",
"ms-toolsai.jupyter"
],
"settings": {
"python.defaultInterpreterPath": ".venv-devcontainer/bin/python",
......
......@@ -162,6 +162,13 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/S
/docs/auto_examples/
/docs/auto_user-guide/
# ignore jupyter notebooks in main folder (useful for testing, annoying for git)
/**.ipynb
# Ignore file created by running webpage preview locally
docs/sg_execution_times.rst
stages:
- test
- maintenance
- prepare
- deploy
variables:
POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
DOCKER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.9
DOCKER_USER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/main-3.9
DOCKER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.10-feflow-10.0
DOCKER_USER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/main-3.10-feflow-10.0
ARTIFACTS_PAGES_URL: https://$CI_PROJECT_ROOT_NAMESPACE.$CI_PAGES_DOMAIN/-/$SUBGROUP_SLUG$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
changes:
- Dockerfile
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE/devcontainer-3.9:$CI_COMMIT_REF_SLUG
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_TAG
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "ogs/tools/ogstools"'
......@@ -24,43 +22,221 @@ cache:
paths:
- .cache
.setup-headless: &setup-headless
- make setup
- make setup_headless
.pip-setup-extra-headless: &pip-setup-extra-headless
- pip install --extra-index-url https://wheels.vtk.org --upgrade --force-reinstall vtk-osmesa
- pip install -i https://gmsh.info/python-packages-dev-nox --upgrade --force-reinstall gmsh
.pip-setup-activate: &pip-setup-activate
- python -m venv .venv --upgrade-deps
- source .venv/bin/activate
.conda-setup-activate: &conda-setup-activate
- conda --version
- export CONDA_ENV_NAME=ogstools_conda_${PYTHON_VERSION}
- conda create -y -n $CONDA_ENV_NAME python=${PYTHON_VERSION} font-ttf-dejavu-sans-mono -c conda-forge
- conda activate $CONDA_ENV_NAME
.pip-install-ogs-latest: &pip-install-ogs-latest
# - pip uninstall ogs -y
- pip install ogs --index-url https://gitlab.opengeosys.org/api/v4/projects/120/packages/pypi/simple --pre
.regression-rules: &regression-rules
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
.maintenance-rules: &maintenance-rules
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
allow_failure: true
- if: $CI_PIPELINE_SOURCE == "schedule"
pre-commit:
tags: [shell, envinf]
rules:
- if: $CI_MERGE_REQUEST_IID
needs: []
script:
- git fetch origin ${CI_MERGE_REQUEST_DIFF_BASE_SHA}
- pre-commit run --from-ref ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --to-ref HEAD
build:
script:
- pip install build
- pyproject-build
tests (arch):
tests (arch - conda) [R]:
stage: test
tags: [shell, envinf]
needs: []
before_script:
- *conda-setup-activate
- pip install -e ".[ogs,pinned,test]"
- *pip-setup-extra-headless
script:
- pytest
- rm -rf "$(python -c 'import matplotlib as mpl; print(mpl.get_cachedir())')"
parallel:
matrix:
- PYTHON_VERSION: "3.10"
- PYTHON_VERSION: "3.11"
- PYTHON_VERSION: "3.12"
- PYTHON_VERSION: "3.13"
tests (arch - conda - ogs wheel release) [M]:
stage: maintenance
tags: [shell, envinf]
rules:
- *maintenance-rules
needs: []
before_script:
- *conda-setup-activate
- pip install -e ".[ogs,test]"
- *pip-setup-extra-headless
script:
- pytest
- rm -rf "$(python -c 'import matplotlib as mpl; print(mpl.get_cachedir())')"
parallel:
matrix:
- PYTHON_VERSION: "3.10"
- PYTHON_VERSION: "3.11"
- PYTHON_VERSION: "3.12"
- PYTHON_VERSION: "3.13"
tests (arch - pip - ogs latest) [M]:
stage: maintenance
tags: [shell, envinf]
rules:
- *maintenance-rules
needs: []
before_script:
- *pip-setup-activate
- *pip-install-ogs-latest
- pip install -e .[test]
- *pip-setup-extra-headless
script:
- pytest
tests (arch - pip - no OGS) [M]:
stage: maintenance
rules:
- *maintenance-rules
tags: [shell, envinf]
needs: []
before_script:
- *pip-setup-activate
- pip install -e .[test]
- *pip-setup-extra-headless
script:
- pre-commit run --all-files
- *setup-headless
- make test
- python -c "import ogstools as ot; ot.status(verbose=True)"
- pytest -m "not (tools or system)"
tests:
# tests (arch - pip - with OGS_IN_PATH) [M]:
# Actually a test with OGS in path was planned (just another export -> export PATH=$PWD/.venv_only_ogs/bin:$PATH )
# It will not work easily -> https://stackoverflow.com/questions/46242623/modify-path-for-gitlab-runner
# So we will skip this test for now, and remove the option to have OGS in path in the future, anyway
tests (arch - pip - with OGS_BIN_PATH) [M]:
stage: maintenance
tags: [shell, envinf]
rules:
- *maintenance-rules
needs: []
before_script:
- python -m venv .venv_only_ogs --upgrade-deps
- source .venv_only_ogs/bin/activate
- pip install ogs
- export OGS_BIN_PATH=$PWD/.venv_only_ogs/bin
- deactivate
- *pip-setup-activate
- pip install -e .[test]
- *pip-setup-extra-headless
script:
- python -c "import ogstools as ot; ot.status(verbose=True)"
- pytest -m "tools"
- pytest -m "system"
tests (arch - conda - ogs custom latest) [M]:
stage: maintenance
tags: [shell, envinf]
rules:
- *maintenance-rules
needs: []
before_script:
- *conda-setup-activate
- *pip-install-ogs-latest
- pip install -e .[test]
- *pip-setup-extra-headless
script:
- pytest
- rm -rf "$(python -c 'import matplotlib as mpl; print(mpl.get_cachedir())')"
parallel:
matrix:
- PYTHON_VERSION: "3.11"
- PYTHON_VERSION: "3.12"
- PYTHON_VERSION: "3.13"
tests (arch - pip - no OGS) [R]:
stage: test
tags: [shell, envinf]
needs: []
before_script:
- *pip-setup-activate
- pip install -e .[pinned,test]
- *pip-setup-extra-headless
script:
- python -c "import ogstools as ot; ot.status(verbose=True)"
- pytest -m "not (tools or system)"
tests coverage (arch - container) [R]:
stage: test
script:
- make setup_devcontainer
- source .venv-devcontainer/bin/activate
- make coverage
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
paths:
- htmlcov
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
environment:
name: code coverage $CI_MERGE_REQUEST_IID
url: ${ARTIFACTS_PAGES_URL}/htmlcov/index.html
tests win:
tests (win - pip) [R]:
stage: test
tags: [windows]
rules:
- *regression-rules
needs: []
variables:
MPLBACKEND: Agg # non-interactive backend for matplotlib
before_script:
- python -m venv .venv
- .venv\Scripts\Activate.ps1
- pip install -e ".[dev,test,docs]"
- pip install -e ".[ogs,pinned,test]"
script:
- pytest
tests (mac - pip) [R]:
stage: test
tags: [mac, arm64]
rules:
- *regression-rules
needs: []
before_script:
- python() { python3.10 "$@"; } # alias don't work in non-interactive shells
- *pip-setup-activate
- pip install -e ".[ogs,pinned,test]"
script:
- pytest
......@@ -69,10 +245,11 @@ tests win:
.docs-script: &docs-script
- make setup_devcontainer
- source .venv-devcontainer/bin/activate
- make docs SPHINXOPTS="-W --keep-going -n -j 1"
- make docs SPHINXOPTS="-W --keep-going -n -j 4"
- mv docs/_build/html public
docs preview:
docs preview [R]:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
......@@ -82,14 +259,72 @@ docs preview:
- public
environment:
name: docs preview $CI_MERGE_REQUEST_IID $CI_PROJECT_ROOT_NAMESPACE
url: "https://$CI_PROJECT_ROOT_NAMESPACE.$CI_PAGES_DOMAIN/-/$SUBGROUP_SLUG$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
url: "${ARTIFACTS_PAGES_URL}/public/index.html"
docs preview [M]:
stage: maintenance
needs: []
tags: [shell, envinf]
rules:
- *maintenance-rules
before_script:
- *pip-setup-activate
- *pip-install-ogs-latest
- pip install -e .[ogs,docs]
- *pip-setup-extra-headless
script:
- make docs SPHINXOPTS="--keep-going -n -j 4" | tee sphinx_output.log
- echo "Counting warnings in Sphinx output..."
# Count lines with "WARNING" in the Sphinx log
- warning_count=$(grep -c "WARNING" sphinx_output.log || true)
- echo "Found $warning_count warnings in Sphinx documentation."
# Set the warning threshold
- warning_threshold=7
# Check if warnings exceed the threshold
- if [ "$warning_count" -lt "$warning_threshold" ]; then
echo "Warnings ($warning_count) are below the threshold ($warning_threshold). Pipeline is green.";
exit 0;
else
echo "Warnings ($warning_count) exceeded the threshold ($warning_threshold). Pipeline failed.";
exit 1;
fi
- mv docs/_bpublicuild/html
artifacts:
paths:
- public
environment:
name: docs preview $CI_COMMIT_REF_SLUG
url: "${ARTIFACTS_PAGES_URL}/public/index.html"
setup maintainer [M]:
stage: maintenance
needs: []
tags: [shell, envinf]
rules:
- *maintenance-rules
before_script:
- *pip-setup-activate
- *pip-install-ogs-latest
script:
- pip install -e .[dev,test,docs,feflow,ogs]
- *pip-setup-extra-headless
setup developer [R]:
stage: test
tags: [shell, envinf]
rules:
- *regression-rules
before_script:
- *pip-setup-activate
- *pip-install-ogs-latest
script:
- pip install -e .[ogs,pinned,dev,test,docs,feflow]
- *pip-setup-extra-headless
pages:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
image: registry.opengeosys.org/ogs/tools/feflow-python-docker:8.0.1
script:
- *docs-script
artifacts:
......@@ -97,9 +332,43 @@ pages:
- public
environment: production
pages-tag:
stage: prepare
rules:
- if: $CI_COMMIT_TAG
script:
- *docs-script
artifacts:
paths:
- public
deploy-pages-tag:
stage: deploy
rules:
- if: $CI_COMMIT_TAG
needs: [pages-tag]
variables:
GIT_STRATEGY: none
script:
- rm -rf ogstools-docs
- git config --global user.name "GitLab CI"
- git config --global user.email "gitlab-ci-no-reply@opengeosys.org"
- git clone https://${CI_SERVER_HOST}/ogs/tools/ogstools-docs.git
- cd ogstools-docs
- mv ../public $CI_COMMIT_TAG
- git add $CI_COMMIT_TAG
- >
jq "map(if has(\"preferred\") then del(.preferred) else . end) + [{\"version\": \"$CI_COMMIT_TAG\",\"url\": \"https://ogstools.opengeosys.org/$CI_COMMIT_TAG/\",\"preferred\": true}]" _static/versions.json > versions.tmp
- mv versions.tmp _static/versions.json
- git add _static/versions.json
- rm stable && ln -s $CI_COMMIT_TAG stable && git add stable
- git commit -m "Release $CI_COMMIT_TAG"
- git push "https://${CI_COMMITTER_USER_AND_TOKEN}@${CI_SERVER_HOST}/ogs/tools/ogstools-docs.git" HEAD:main
publish:
rules:
- if: $CI_COMMIT_TAG
when: manual
variables:
TWINE_REPOSITORY: pypi
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
......@@ -114,11 +383,12 @@ devcontainer image:
- envinf
- shell
rules:
- changes:
- .devcontainer/*
- when: manual
allow_failure: true
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- devcontainer build --workspace-folder . --push true --image-name ${DOCKER_IMAGE}
# --push true will be done manually on a developers machine
- devcontainer build --workspace-folder . --image-name ${DOCKER_IMAGE}
user container image:
stage: .pre
......@@ -128,10 +398,44 @@ user container image:
- shell
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
allow_failure: true
- if: $CI_COMMIT_TAG
variables:
DOCKER_USER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/main-3.9:$CI_COMMIT_TAG
DOCKER_USER_IMAGE: registry.opengeosys.org/ogs/tools/ogstools/main-3.10:$CI_COMMIT_TAG
allow_failure: true
- if: $CI_MERGE_REQUEST_IID
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $DOCKER_USER_IMAGE .
- docker push $DOCKER_USER_IMAGE
code_quality_ruff [R]:
image: python:3.10-slim
needs: []
script:
# Use same ruff as in .pre-commit-config.yaml
- pip install ruff==0.0.277
- ruff . --format gitlab > ruff-code-quality-report.json || true
artifacts:
reports:
codequality: ruff-code-quality-report.json
code_quality_mypy [R]:
image: python:3.10-slim
needs: []
script:
# Use same mypy as in .pre-commit-config.yaml
- pip install mypy==1.4.1 mypy-to-codeclimate
- mypy ogstools > mypy-output.txt || true
- mypy-to-codeclimate mypy-output.txt mypy-code-quality-report.json || true
artifacts:
reports:
codequality: mypy-code-quality-report.json
ogs/tools/feflow-converter-tests:
stage: test
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
trigger: ogs/tools/feflow-converter-tests
Florian Zill <florian.zill@ufz.de>
Tobias Meisel <tobias.meisel@ufz.de> <tobias.meisel@web.de>
Jörg Buchwald <joerg.buchwald@ufz.de>
......@@ -11,15 +11,30 @@ repos:
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
exclude: ^ogstools/examples/
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace
exclude: ^ogstools/examples/
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.4.0
hooks:
- id: black
args: [--config=./pyproject.toml]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
name: pyupgrade
description: Automatically upgrade syntax for newer versions.
entry: pyupgrade
language: python
types: [python]
# for backward compatibility
files: ''
minimum_pre_commit_version: 0.15.0
args: [--py310-plus]
# black-formats code blocks in documentation files
- repo: https://github.com/asottile/blacken-docs
rev: 1.14.0
......@@ -28,7 +43,7 @@ repos:
additional_dependencies:
- black==23.3.0 # keep in sync with black hook
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.277"
rev: "v0.4.5"
hooks:
- id: ruff
args: ["--show-fixes", "--fix"]
......@@ -47,6 +62,7 @@ repos:
hooks:
- id: mypy
files: ogstools
exclude: ".*/examples/.*"
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
hooks:
......@@ -67,4 +83,4 @@ repos:
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
- id: mdformat
# Update with `git shortlog -sne`
cff-version: 1.2.0
title: OGSTools
message: >-
If you use this software, please cite it using these
metadata.
type: software
authors:
- given-names: Florian
family-names: Zill
orcid: "https://orcid.org/0000-0002-5177-401X"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
- given-names: Lars
family-names: Bilke
orcid: "https://orcid.org/0000-0001-8986-2413"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
- given-names: Tobias
family-names: Meisel
orcid: "https://orcid.org/0009-0009-8790-8903"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
- given-names: Julian
family-names: Heinze
oricd: "https://orcid.org/0009-0004-3449-8852"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
- given-names: Feliks K.
family-names: Kiszkurno
orcid: "https://orcid.org/0000-0003-3304-4838"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
- given-names: Dominik
family-names: Kern
orcid: "https://orcid.org/0000-0002-1958-2982"
affiliation: TU Bergakademie Freiberg
- given-names: Max
family-names: Jäschke
affiliation: Leipzig University of Applied Sciences -- HTWK
- given-names: Christoph
family-names: Lehmann
orcid: "https://orcid.org/0000-0001-7936-9852"
affiliation: Helmholtz Centre for Environmental Research -- UFZ
identifiers:
- type: doi
value: 10.5281/zenodo.10913063
description: Zenodo DOI for 0.3.0
- type: doi
value: 10.5281/zenodo.10913044
description: Zenodo DOI for 0.2.0
- type: doi
value: 10.5281/zenodo.10912983
description: Zenodo DOI for 0.1.0
- type: doi
value: 10.5281/zenodo.10912874
description: Zenodo DOI for 0.0.3
repository-code: "https://gitlab.opengeosys.org/ogs/tools/ogstools"
url: "https://ogstools.opengeosys.org"
license: BSD-3-Clause
FROM registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.9
FROM registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.10
RUN --mount=target=/ogstools,type=bind,source=.,readwrite \
pip install /ogstools[feflow] \
&& pip uninstall vtk -y
pip install /ogstools[feflow,dev,docs,test,pinned] \
&& pip uninstall vtk gmsh -y
RUN pip install --extra-index-url https://wheels.vtk.org vtk-osmesa \
&& pip install -i https://gmsh.info/python-packages-dev-nox gmsh
......
from setuptools import setup, find_packages
setup(
name="vtu2ascii",
version=0.01,
maintainer="Jörg Buchwald",
maintainer_email="joerg_buchwald@ufz.de",
author="Jörg Buchwald",
author_email="joerg.buchwald@ufz.de",
url="https://github.com/joergbuchwald/",
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
include_package_data=True,
install_requires=[],
py_modules=["vtu2ascii"],
)
import sys
import vtk
class VTU2ascii(object):
"""Converts VTU files into human readable ascii
"""
def __init__(self, ifile, ofile):
self.ifile = ifile
self.ofile = ofile
def readData(self):
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(self.ifile)
reader.Update()
self.data = reader.GetOutput()
def writeData(self,datamode="ascii"):
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(self.ofile)
writer.SetInputData(self.data)
if datamode == "binary":
writer.SetDataModeToBinary()
elif datamode == "appended":
writer.SetDataModeToAppended()
else:
writer.SetDataModeToAscii()
writer.Write()
if __name__ == '__main__':
converter = VTU2ascii(sys.argv[1], sys.argv[2])
converter.readData()
converter.writeData()
Copyright (c) 2022, OpenGeoSys Community (<https://www.opengeosys.org>)
Copyright (c) 2025, OpenGeoSys Community (<https://www.opengeosys.org>)
All rights reserved.
Redistribution and use in source and binary forms, with or without
......
help: ## Show this help
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST) | column -t -s :
.PHONY : setup setup_headless test coverage check clean docs cleandocs preview
.PHONY : setup pip_setup_headless test coverage check clean docs cleandocs preview
setup: ## Setup a virtual environment and install all development dependencies
python -m venv .venv --upgrade-deps
.venv/bin/pip install -e .[dev,test,docs]
.venv/bin/pip install -e .[pinned,dev,test,docs]
.venv/bin/pre-commit install
@echo
@echo ATTENTION: You need to activate the virtual environment in every shell with:
@echo source .venv/bin/activate
setup_headless: ## Install vtk-osmesa and gmsh without X11 dependencies
# Variables
REPO_URL := https://gitlab.opengeosys.org/ogs/ogs.git
TARGET_DIR := .ogs
COMMIT_HASH ?= master
# Clone the repository and checkout the specific commit
clone:
@if [ ! -d "$(TARGET_DIR)" ]; then \
echo "Cloning repository..."; \
git clone "$(REPO_URL)" "$(TARGET_DIR)"; \
else \
echo "Repository already cloned."; \
fi; \
if [ -n "$(COMMIT_HASH)" ]; then \
echo "Checking out specific commit: $(COMMIT_HASH)"; \
cd "$(TARGET_DIR)" && git fetch origin && git checkout "$(COMMIT_HASH)"; \
else \
echo "Pulling latest changes from master..."; \
cd "$(TARGET_DIR)" && git pull origin master; \
fi
# All latest versions (including latest OGS). Should be installed into a fresh virtual environment
# Hint for custom ogs: .venv/bin/pip install -v ./.ogs --config-settings=cmake.define.OGS_BUILD_PROCESSES="HeatConduction;ThermoRichardsMechanics;SmallDeformation;SteadyStateDiffusion"
pip_setup_latest:
python -m venv .venv --upgrade-deps
.venv/bin/pip install -e .[dev,test,docs]
.venv/bin/pip uninstall ogs -y
.venv/bin/pip install ogs --index-url https://gitlab.opengeosys.org/api/v4/projects/120/packages/pypi/simple --pre
@echo
@echo "ATTENTION: You need to activate the virtual environment in every shell with:"
@echo "source .venv/bin/activate"
# Assumes ogstools is already installed
pip_setup_headless: ## Install vtk-osmesa and gmsh without X11 dependencies
.venv/bin/pip uninstall gmsh vtk -y
.venv/bin/pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
.venv/bin/pip install -i https://gmsh.info/python-packages-dev-nox gmsh
setup_devcontainer: ## Internal usage
setup_devcontainer: ## Internal usage [CI]
rm -rf .venv-devcontainer
python -m venv .venv-devcontainer --upgrade-deps
.venv-devcontainer/bin/pip install -e .[dev,test,docs,feflow]
.venv-devcontainer/bin/pip install -e .[ogs,dev,test,docs,feflow,pinned]
.venv-devcontainer/bin/pip uninstall gmsh vtk -y
.venv-devcontainer/bin/pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
.venv-devcontainer/bin/pip install -i https://gmsh.info/python-packages-dev-nox gmsh
......@@ -45,8 +79,36 @@ docs: ## Builds the documentation
cleandocs: ## Cleans up temporary documentation files
rm -r docs/_build
rm -r docs/auto_examples
rm -r docs/auto_user-guide
rm -r docs/reference/*.rst
preview: ## Runs an auto-updating web server for the documentation
make docs
python docs/server.py
.PHONY: requirement
requirement:
## conda init zsh
## conda create --prefix /tmp/ogstools-test-env-py312 python=3.12
## conda activate /tmp/ogstools-test-env-py312
@version_output=$$(python --version 2>&1); \
version=$$(echo "$$version_output" | awk '{print $$2}' | awk -F'.' '{print $$1 "_" $$2}'); \
venv_dir=".venv_py$$version"; \
if [ -d "$$venv_dir" ]; then \
read -p "Virtual environment '$$venv_dir' already exists. Do you want to continue and recreate it? (y/N): " confirm; \
if [ "$$confirm" != "y" ] && [ "$$confirm" != "Y" ]; then \
echo "Aborting."; \
exit 1; \
fi; \
echo "Continuing to recreate virtual environment."; \
rm -r "$$venv_dir"; \
fi; \
echo "Creating virtual environment in $$venv_dir"; \
python -m venv $$venv_dir; \
echo "Activating virtual environment and installing packages"; \
. $$venv_dir/bin/activate && pip install . && pip freeze -l > requirements/requirements_py$$version.txt && \
echo "Activating virtual environment and installing packages"; \
. $$venv_dir/bin/activate && pip install .[dev,tests,doc] && pip freeze -l > requirements/requirements_allextras_py$$version.txt && \
echo "Deleting virtual environment"; \
rm -r $$venv_dir
![OGS workflow overview](https://ogs.ogs.xyz/tools/ogstools/_static/ogstools.png "Supporting complex workflows - from preprocessing to simulation to postprocessing")
![OGSTools](https://ogstools.opengeosys.org/stable/_static/ogstools.png "Supporting complex workflows - from preprocessing to simulation to postprocessing")
is a:
......@@ -9,9 +9,9 @@ is a:
# Overview
- **Website:** <https://www.opengeosys.org>
- **Documentation:** <https://ogs.ogs.xyz/tools/ogstools>
- **Documentation:** <https://ogstools.opengeosys.org>
- **Source code:** <https://gitlab.opengeosys.org/ogs/tools/ogstools>
- **Contributing:** <https://ogs.ogs.xyz/tools/ogstools/development/index.html>
- **Contributing:** <https://ogstools.opengeosys.org/stable/development/index.html>
- **Bug reports:** <https://discourse.opengeosys.org>
# Installation
......@@ -22,21 +22,21 @@ Install the latest version of ogstools:
pip install ogstools
```
For further details see the [User Guide](https://ogs.ogs.xyz/tools/ogstools/user-guide/index.html).
For further details see the [User Guide](https://ogstools.opengeosys.org/stable/user-guide/index.html).
# Getting started
For first steps, please take a look at our [examples](https://ogs.ogs.xyz/tools/ogstools/auto_examples/index.html).
For first steps, please take a look at our [examples](https://ogstools.opengeosys.org/stable/auto_examples/index.html).
# Contribution
Please report bugs on [Discourse](https://discourse.opengeosys.org) or fork the repository on our [GitLab](https://gitlab.opengeosys.org/ogs/tools/ogstools) and create a merge request. We also welcome contributions in the form of merge requests and are here to assist in ensuring that the code passes all quality checks. We recommend starting with the [Developer Guide](https://ogs.ogs.xyz/tools/ogstools/development/index.html) as your initial point of reference.
Please report bugs on [Discourse](https://discourse.opengeosys.org) or fork the repository on our [GitLab](https://gitlab.opengeosys.org/ogs/tools/ogstools) and create a merge request. We also welcome contributions in the form of merge requests and are here to assist in ensuring that the code passes all quality checks. We recommend starting with the [latest version of the Developer Guide](https://ogs.ogs.xyz/tools/ogstools/development/index.html) as your initial point of reference.
You may also contribute by [donating](https://gitlab.opengeosys.org/ogs/tools/ogstools/-/blob/release-notes/donation.md) your existing code snippets.
You may also contribute by [donating](https://gitlab.opengeosys.org/ogs/tools/ogstools/-/blob/main/donation.md) your existing code snippets.
# Motivation
To gain a deeper insight into the rationale behind the development of this Python library, find a comprehensive motivation section available [here](docs/user-guide/introduction/motivation.md).
To gain a deeper insight into the rationale behind the development of this Python library, find a comprehensive motivation section available [here](https://gitlab.opengeosys.org/ogs/tools/ogstools/-/blob/main/docs/user-guide/introduction/motivation.md).
# Related projects
......
......@@ -7,10 +7,13 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os
import warnings
from datetime import datetime
import pyvista
from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper
from sphinx.deprecation import RemovedInSphinx90Warning
from sphinx_gallery.sorting import ExplicitOrder, FileNameSortKey
import ogstools
......@@ -36,6 +39,7 @@ extensions = [
"sphinx_gallery.gen_gallery",
]
templates_path = ["_templates"]
exclude_patterns = [
"_build",
......@@ -45,6 +49,7 @@ exclude_patterns = [
"reference/ogstools.rst",
"examples/**/README.rst",
"examples/README.rst",
"user-guide/README.rst",
]
myst_enable_extensions = ["dollarmath", "colon_fence", "amsmath"]
......@@ -104,6 +109,7 @@ apidoc_module_dir = "../ogstools"
apidoc_output_dir = "reference"
apidoc_excluded_paths = [
"../**/examples/**",
"../**/user-guide/**",
"./**/tests/**",
"../**/**/templates/**",
]
......@@ -116,8 +122,9 @@ autodoc_class_signature = "separated"
autodoc_member_order = "bysource"
autodoc_preserve_defaults = True
autodoc_typehints = "description"
autodoc_typehints_description_target = "documented_params"
autodoc_default_options = {"special-members": "__call__"}
autodoc_default_options = {"special-members": "__call__, __getitem__"}
### sphinx-gallery setup ###
# necessary when building the sphinx gallery
......@@ -127,13 +134,33 @@ pyvista.OFF_SCREEN = True
# Disable progress bars in sphinx
os.environ["TQDM_DISABLE"] = "1"
def reset_plot_setup(*_):
"Reset the ogstools plot setup to its default values"
ogstools.plot.setup.reset()
sphinx_gallery_conf = {
"examples_dirs": ["examples"],
"gallery_dirs": ["auto_examples"],
"examples_dirs": ["examples", "user-guide"],
"gallery_dirs": ["auto_examples", "auto_user-guide"],
"show_signature": False,
"download_all_examples": False,
"image_scrapers": ("matplotlib", DynamicScraper()),
"matplotlib_animations": True,
"reset_modules": ("matplotlib", reset_plot_setup),
"subsection_order": ExplicitOrder(
[
"examples/howto_quickstart",
"examples/howto_preprocessing",
"examples/howto_prjfile",
"examples/howto_simulation",
"examples/howto_postprocessing",
"examples/howto_plot",
"examples/howto_conversions",
]
),
"within_subsection_order": FileNameSortKey,
}
# feflowlib is optional
......@@ -145,7 +172,13 @@ except ImportError:
["reference/ogstools.feflowlib.*", "user-guide/feflowlib*"]
)
apidoc_excluded_paths.append("../**/feflowlib/**")
sphinx_gallery_conf["ignore_pattern"] = r".*feflowlib/.*"
apidoc_excluded_paths.append("../docs/releases/ogstools-*.md")
sphinx_gallery_conf["ignore_pattern"] = r".*_feflowlib_*"
suppress_warnings = ["config.cache"]
warnings.filterwarnings("ignore", category=RemovedInSphinx90Warning)
# Suppress sphinx warning for multiple documents generated by sphinx-gallery
......
# Development setup
# Cloning the Source Repository
You can clone the source repository from https://gitlab.opengeosys.org/ogs/tools/ogstools and install the latest version by running:
`git clone git@gitlab.opengeosys.org:ogs/tools/ogstools.git` or
`git clone https://gitlab.opengeosys.org/ogs/tools/ogstools.git`
# Development environment
Change into the directory with the cloned ogstools sources. (`.` assumes that your working directory contains the ogstools sources, the directory where you find the `pyproject.toml`).
```bash
cd ogstools
```
Create a virtual environment, activate it and install required packages:
```bash
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,test,docs]"
pip install -e ".[pinned,dev,test,docs]"
# enable basic style checks once
pre-commit install
......@@ -118,6 +133,17 @@ If you want to link to a gallery page from another page use the following syntax
{ref}`meshlib example <sphx_glr_auto_examples_howto_meshlib_plot_meshlib_pyvista_input.py>`
```
### Guidelines for examples
In order to maintain consistency in style and structure between different
examples, please follow those recommendations when creating a new one:
- All imports and global settings must be done in first python block.
- No heading for import and settings cell.
- Examples that cover multiple steps and/or datasets must contain section.
- Sections have to be give a title, indicated by highest level heading.
- Section titles cannot start with ordinal number or letter (no 1./I./A. Example section title)
### Further information
For syntax references and extension usage see the following links:
......@@ -185,7 +211,7 @@ Now you are inside the container. For example, you can open a new terminal (`Ter
If you are familiar with [Docker](https://www.docker.com), you can also start the container manually, e.g. with:
```bash
docker run --rm -it -v $PWD:$PWD -w $PWD registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.9 /bin/bash
docker run --rm -it -v $PWD:$PWD -w $PWD registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.10 /bin/bash
# Inside the container:
make setup_devcontainer
pytest
......@@ -198,7 +224,7 @@ ______________________________________________________________________
To prevent these issues we recommend running via [Apptainer](https://apptainer.org):
```bash
apptainer shell docker://registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.9
apptainer shell docker://registry.opengeosys.org/ogs/tools/ogstools/devcontainer-3.10
# Inside the container:
make setup_devcontainer
pytest
......
Examples
========
.. toctree::
:maxdepth: 1
On this page you will find practical examples of using various features of
how ogstools can be used. Different stages of the simulation workflow are
covered.
../examples/howto_mesh_terrain/index
.. toctree::
:maxdepth: 3
.. contents:: Contents
:local:
:depth: 2
:depth: 3
Conversion tools
================
This section covers tools designed to help with converting already existing
simulations setup with alternative software to open formats compatible with OGS.
"""
Feflowlib: How to get started with the FEFLOW converter.
========================================================
.. sectionauthor:: Julian Heinze (Helmholtz Centre for Environmental Research GmbH - UFZ)
This example shows how a FEFLOW model can be converted and simulated in OGS.
"""
# %%
# 0. Necessary imports.
import tempfile
from pathlib import Path
from ogstools import FeflowModel
from ogstools.examples import (
feflow_model_2D_CT_t_560,
feflow_model_2D_HT,
feflow_model_box_Robin,
)
# %%
# 1. Convert the models.
temp_dir = Path(tempfile.mkdtemp("feflow_test_simulation"))
feflow_model_H = FeflowModel(
feflow_model_box_Robin, temp_dir / "3D_H_model.vtu"
)
feflow_model_HC = FeflowModel(
feflow_model_2D_CT_t_560, temp_dir / "2D_HC_model.vtu"
)
feflow_model_HT = FeflowModel(feflow_model_2D_HT, temp_dir / "2D_HT_model.vtu")
# %%
# 2. Define simulation times.
# Simulate the steady state diffusion process in OGS for the H-model.
feflow_model_H.setup_prj(steady=True)
feflow_model_HC.setup_prj(
end_time=int(4.8384e07),
time_stepping=list(
zip([10] * 8, [8.64 * 10**i for i in range(8)], strict=False)
),
)
feflow_model_HT.setup_prj(end_time=1e11, time_stepping=[(1, 1e10)])
# %%
# 3. Run the simulations.
feflow_model_H.run()
feflow_model_HC.run()
feflow_model_HT.run()
"""
Feflowlib: How to modify boundary conditions after conversion of a FEFLOW model.
================================================================================
.. sectionauthor:: Julian Heinze (Helmholtz Centre for Environmental Research GmbH - UFZ)
This example shows how boundary conditions can be modified after converting a FEFLOW model.
First we will change the values of the boundary conditions and later we will show how to define a new boundary mesh.
"""
# %%
# 0. Necessary imports
import tempfile
from pathlib import Path
import numpy as np
import pyvista as pv
import ogstools as ot
from ogstools.examples import feflow_model_2D_HT
from ogstools.feflowlib import assign_bulk_ids
# %%
# 1. Load a FEFLOW model (.fem) as a FeflowModel object to further work it.
# During the initialisation, the FEFLOW file is converted.
temp_dir = Path(tempfile.mkdtemp("converted_models"))
feflow_model = ot.FeflowModel(feflow_model_2D_HT, temp_dir / "HT_model")
mesh = feflow_model.mesh
# Print information about the mesh.
print(mesh)
# %%
# 2. Plot the temperature simulated in FEFLOW on the mesh.
fig = ot.plot.contourf(mesh, "P_TEMP", show_edges=True)
# %%
# 3. As the FEFLOW data now are a pyvista.UnstructuredGrid, all pyvista functionalities can be applied to it.
# Further information can be found at https://docs.pyvista.org/version/stable/user-guide/simple.html.
# For example it can be saved as a VTK Unstructured Grid File (\*.vtu).
# This allows to use the FEFLOW model for ``OGS`` simulation or to observe it in ``Paraview```.
pv.save_meshio(temp_dir / "HT_mesh.vtu", mesh)
# %%
# 4. Run the FEFLOW model in OGS.
feflow_model.setup_prj(end_time=1e11, time_stepping=[(1, 1e10)])
feflow_model.run()
ms = ot.MeshSeries(temp_dir / "HT_model.pvd")
# %%
# 5. Plot the temperature simulated in OGS.
ogs_sim_res = ms.mesh(ms.timesteps[-1])
ot.plot.contourf(ogs_sim_res, ot.variables.temperature)
# %%
# 6. The boundary meshes are manipulated to alter the model.
# The original boundary conditions are shown in this example: :ref:`sphx_glr_auto_examples_howto_conversions_plot_F_feflowlib_HT_simulation.py`
# 6.1 The Dirichlet boundary conditions for the hydraulic head are set to 0. Therefore, no water flows from the left to the right edge.
bc_flow = feflow_model.subdomains["P_BC_FLOW"]["P_BC_FLOW"]
feflow_model.subdomains["P_BC_FLOW"]["P_BC_FLOW"][bc_flow == 10] = 0
# %%
# 6.2 Overwrite the new boundary conditions and run the model.
feflow_model.run(overwrite=True)
# %%
# 6.3 The corresponding simulation results look like.
ms = ot.MeshSeries(temp_dir / "HT_model.pvd")
# Read the last timestep:
ogs_sim_res = ms.mesh(ms.timesteps[-1])
ot.plot.contourf(ogs_sim_res, ot.variables.temperature)
# %%
# 6.4 Create a new boundary mesh and overwrite the existing subdomains with this boundary mesh.
assign_bulk_ids(mesh)
# Get the points of the bulk mesh to build a new boundary mesh.
wanted_pts = [1492, 1482, 1481, 1491, 1479, 1480, 1839, 1840]
new_bc = mesh.extract_points(
[pt in wanted_pts for pt in mesh["bulk_node_ids"]],
adjacent_cells=False,
include_cells=False,
)
new_bc["bulk_node_ids"] = np.array(wanted_pts, dtype=np.uint64)
# Define the temperature values of these points.
new_bc["P_BC_HEAT"] = np.array([300] * len(wanted_pts), dtype=np.float64)
feflow_model.subdomains["P_BC_HEAT"] = new_bc
# %%
# 7. Run the new model and plot the simulation results.
feflow_model.run(overwrite=True)
ms = ot.MeshSeries(temp_dir / "HT_model.pvd")
ogs_sim_res = ms.mesh(ms.timesteps[-1])
ot.plot.contourf(ogs_sim_res, ot.variables.temperature)