Mentions légales du service

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
  • mgenet/dolfin_warp
  • cpatte/dolfin_dic
  • falvarez/dolfin_dic
  • eberbero/dolfin_dic
4 results
Show changes
Commits on Source (419)
Showing
with 1379 additions and 0 deletions
*.pyc
*.kdev4*
.spyproject
.DS_Store
build
dist
*.egg-info
.vscode
stages:
- test
- deploy
tests-on-ubuntu-20.04-with-apt: # MG20230608: This leads to seg fault while manipulating vtk objects inside cpp fenics expressions… # MG20241020: I think the mesh reader fails…
stage: test
when: manual
tags:
- ci.inria.fr
- large
image: ubuntu:20.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential git gnuplot python3-matplotlib python3-numpy python3-pandas python3-pip python-is-python3 # MG20220814: environment variables are needed to prevent tzdata installation hanging while waiting timezone info, cf. https://anonoz.github.io/tech/2020/04/24/docker-build-stuck-tzdata.html
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y software-properties-common; add-apt-repository -y ppa:fenics-packages/fenics; apt update; apt install -y fenics; export DISPLAY=0:0
# - apt update; apt install -y libopenblas-base; export OMP_NUM_THREADS="1" # MG20221201: This seems to fail in Ubuntu 20.04
- apt update; apt install -y libvtk7-dev python3-vtk7; export CPATH="/usr/include/vtk-7.1":$CPATH
- apt update; apt install -y libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxft-dev libxinerama1 gcc-multilib xvfb gmsh; pip install gmsh
- apt update; apt install -y python3-h5py; pip install meshio; pip install numpy==1.23.5 # MG20220814: meshio needs updated numpy apparently # MG20230103: apparently numpy >= 1.24 does not work anymore with the old version of pandas (and probably other stuff) present in Ubuntu 20.04 apt repo, cf. https://stackoverflow.com/a/74975994
- pip install git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
tests-on-ubuntu-22.04-with-apt: # MG20230608: This leads to seg fault while manipulating vtk objects inside cpp fenics expressions… # MG20241020: I think the image reader fails…
stage: test
when: manual
tags:
- ci.inria.fr
- large
image: ubuntu:22.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential git gnuplot python3-matplotlib python3-numpy python3-pandas python3-pip python-is-python3 # MG20220814: environment variables are needed to prevent tzdata installation hanging while waiting timezone info, cf. https://anonoz.github.io/tech/2020/04/24/docker-build-stuck-tzdata.html
- apt update; apt install -y software-properties-common; add-apt-repository -y ppa:fenics-packages/fenics; apt update; apt install -y fenics; export DISPLAY=0:0
- apt update; apt install -y libopenblas-base; export OMP_NUM_THREADS="1"
- apt update; apt install -y libvtk9-dev python3-vtk9; export CPATH="/usr/include/vtk-9.1":$CPATH
- apt update; apt install -y libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxft-dev libxinerama1 gcc-multilib xvfb gmsh; pip install gmsh
- apt update; apt install -y python3-h5py; pip install meshio; pip install numpy==1.24.4 # MG20220814: meshio needs updated numpy apparently # MG20230103: apparently numpy >= 1.25 does not work with FEniCS
- pip install git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
tests-on-ubuntu-24.04-with-apt: # MG 20241017: apt python version is 3.12, which seems incompatible with numpy 1.24…
stage: test
when: manual
tags:
- ci.inria.fr
- large
image: ubuntu:24.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential git gnuplot python3-matplotlib python3-numpy python3-pandas python3-pip python-is-python3 # MG20220814: environment variables are needed to prevent tzdata installation hanging while waiting timezone info, cf. https://anonoz.github.io/tech/2020/04/24/docker-build-stuck-tzdata.html
- apt update; apt install -y software-properties-common; add-apt-repository -y ppa:fenics-packages/fenics; apt update; apt install -y fenics; export DISPLAY=0:0
# - apt update; apt install -y libopenblas-base; export OMP_NUM_THREADS="1" # MG20241017: Not present in Ubuntu 24.04
- apt update; apt install -y libvtk9-dev python3-vtk9; export CPATH="/usr/include/vtk-9.1":$CPATH
- apt update; apt install -y libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxft-dev libxinerama1 gcc-multilib xvfb gmsh; pip install --break-system-packages gmsh
- apt update; apt install -y python3-h5py; pip install --break-system-packages meshio; pip install --break-system-packages numpy==1.24.4 # MG20220814: meshio needs latest numpy apparently # MG20230103: apparently numpy >= 1.25 does not work with FEniCS
- pip install --break-system-packages git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
tests-on-ubuntu-20.04:
stage: test
only:
- devel
- /^devel-.*/
tags:
- ci.inria.fr
- large
image: ubuntu:20.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential gcc-multilib git gnuplot libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama1 libxft-dev wget xvfb
# - apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y libopenblas-base; export OMP_NUM_THREADS="1" # MG20221201: This seems to fail in Ubuntu 20.04
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; bash Miniconda3-latest-Linux-x86_64.sh -b -p /root/miniconda; eval "$(/root/miniconda/bin/conda shell.bash hook)"; conda init
# - conda install conda-libmamba-solver; conda config --set solver libmamba # MG20241017: This is now the default solver, cf. https://conda.org/blog/2023-11-06-conda-23-10-0-release
- conda create -y -c conda-forge -n dolfin_warp expat=2.5 fenics=2019.1.0 matplotlib=3.5 meshio=5.3 mpi4py=3.1.3 numpy=1.23.5 pandas=1.3 pip python=3.10 scipy=1.8 vtk=9.1; conda activate dolfin_warp # MG20230608: need to install meshio via conda because pip install has h5py dependency issues # MG20230608: need to install vtk9 because vtk7 seems to require python2 # MG20241020: expat > 2.5 seems to break vtkXMLDataParser, cf. https://gitlab.kitware.com/vtk/vtk/-/issues/19258
- conda activate dolfin_warp; conda env config vars set CPATH=$CONDA_PREFIX/include/vtk-9.1; conda deactivate; conda activate dolfin_warp
- pip install git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
tests-on-ubuntu-22.04:
stage: test
only:
- devel
- /^devel-.*/
tags:
- ci.inria.fr
- large
image: ubuntu:22.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential gcc-multilib git gnuplot libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama1 libxft-dev wget xvfb
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y libopenblas-base; export OMP_NUM_THREADS="1"
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; bash Miniconda3-latest-Linux-x86_64.sh -b -p /root/miniconda; eval "$(/root/miniconda/bin/conda shell.bash hook)"; conda init
# - conda install conda-libmamba-solver; conda config --set solver libmamba # MG20241017: This is now the default solver, cf. https://conda.org/blog/2023-11-06-conda-23-10-0-release
- conda create -y -c conda-forge -n dolfin_warp expat=2.5 fenics=2019.1.0 matplotlib=3.5 meshio=5.3 mpi4py=3.1.3 numpy=1.23.5 pandas=1.3 pip python=3.10 scipy=1.8 vtk=9.1; conda activate dolfin_warp # MG20230608: need to install meshio via conda because pip install has h5py dependency issues
- conda activate dolfin_warp; conda env config vars set CPATH=$CONDA_PREFIX/include/vtk-9.1; conda deactivate; conda activate dolfin_warp
- pip install git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
tests-on-ubuntu-24.04:
stage: test
only:
- devel
- /^devel-.*/
tags:
- ci.inria.fr
- large
image: ubuntu:24.04
script:
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt upgrade -y
- apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y build-essential gcc-multilib git gnuplot libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama1 libxft-dev wget xvfb
# - apt update; DEBIAN_FRONTEND=noninteractive TZ=Europe/Paris apt install -y libopenblas-base; export OMP_NUM_THREADS="1" # MG20241017: Not present in Ubuntu 24.04
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; bash Miniconda3-latest-Linux-x86_64.sh -b -p /root/miniconda; eval "$(/root/miniconda/bin/conda shell.bash hook)"; conda init
# - conda install conda-libmamba-solver; conda config --set solver libmamba # MG20241017: This is now the default solver, cf. https://conda.org/blog/2023-11-06-conda-23-10-0-release
- conda create -y -c conda-forge -n dolfin_warp expat=2.5 fenics=2019.1.0 matplotlib=3.5 meshio=5.3 mpi4py=3.1.3 numpy=1.23.5 pandas=1.3 pip python=3.10 scipy=1.8 vtk=9.1; conda activate dolfin_warp # MG20230608: need to install meshio via conda because pip install has h5py dependency issues
- conda activate dolfin_warp; conda env config vars set CPATH=$CONDA_PREFIX/include/vtk-9.1; conda deactivate; conda activate dolfin_warp
- pip install git+https://gitlab.inria.fr/mgenet/myPythonLibrary.git git+https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git git+https://gitlab.inria.fr/mgenet/vtkpython_cbl.git git+https://gitlab.inria.fr/mgenet/dolfin_mech.git
- cd Tests; ln -s ../dolfin_warp; make
# docker:
# stage: deploy
# only:
# - master
# tags:
# - ci.inria.fr
# - small
# image: docker:19.03.11
# services:
# - docker:19.03.11-dind
# script:
# - echo Docker login
# - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# - echo Build dolfin_warp-2017.2.0-dev
# - docker build -t $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2017.2.0-dev -f Docker/dolfin_warp-2017.2.0-dev/Dockerfile .
# - docker push $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2017.2.0-dev
# - echo Build dolfin_warp-2017.2.0
# - docker build -t $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2017.2.0 -f Docker/dolfin_warp-2017.2.0/Dockerfile .
# - docker push $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2017.2.0
# - echo Build dolfin_warp-2019.1.0-dev
# - docker build -t $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2019.1.0-dev -f Docker/dolfin_warp-2019.1.0-dev/Dockerfile .
# - docker push $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2019.1.0-dev
# - echo Build dolfin_warp-2019.1.0
# - docker build -t $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2019.1.0 -f Docker/dolfin_warp-2019.1.0/Dockerfile .
# - docker push $CI_REGISTRY/mgenet/dolfin_warp/dolfin_warp-2019.1.0
# - echo Docker logout
# - docker logout $CI_REGISTRY
pypi:
stage: deploy
only:
- master
tags:
- ci.inria.fr
- small
image: python
variables:
TWINE_USERNAME: $PYPI_USER
TWINE_PASSWORD: $PYPI_PASS
script:
- pip install -U setuptools twine
- python setup.py sdist bdist_wheel
- twine upload dist/*
gitlab:
stage: deploy
only:
- master
tags:
- ci.inria.fr
- small
image: python
script:
- pip install -U setuptools twine
- python setup.py sdist bdist_wheel
- TWINE_USERNAME=gitlab-ci-token TWINE_PASSWORD=${CI_JOB_TOKEN} twine upload --verbose --skip-existing --repository-url https://gitlab.inria.fr/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/*
cff-version: 1.2.0
authors:
- family-names: Genet
given-names: Martin
orcid: 0000-0003-2204-201X
- family-names: Patte
given-names: Cécile
orcid: 0000-0001-8553-886X
- family-names: Berberoğlu
given-names: Ezgi
orcid: 0000-0002-4607-8845
- family-names: Álvarez-Barrientos
given-names: Felipe
orcid: 0000-0003-4468-7951
- family-names: Laville
given-names: Colin
- family-names: Peyraut
given-names: Alice
orcid: 0009-0000-9445-8060
- family-names: Daby-Seesaram
given-names: Alexandre
orcid: 0000-0002-2374-0971
title: "dolfin_warp"
url: https://gitlab.inria.fr/mgenet/dolfin_warp
doi: 10.5281/zenodo.8010275
# FEniCS base
# FROM ubuntu:latest
# FROM quay.io/fenicsproject/stable:2016.1.0
# FROM quay.io/fenicsproject/stable:2016.2.0
# FROM quay.io/fenicsproject/stable:2017.1.0
FROM quay.io/fenicsproject/stable:2017.2.0
# FROM quay.io/fenicsproject/stable:current
# FROM quay.io/fenicsproject/stable:latest
# USER root
# RUN apt-get update; apt-get -y upgrade; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# RUN apt-get update; apt-get install -y software-properties-common; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# RUN add-apt-repository -y ppa:fenics-packages/fenics-2016.1.0
# RUN add-apt-repository -y ppa:fenics-packages/fenics-2016.2.0
# RUN add-apt-repository -y ppa:fenics-packages/fenics-2017.1.0
# RUN add-apt-repository -y ppa:fenics-packages/fenics-2017.2.0
# RUN add-apt-repository -y ppa:fenics-packages/fenics
# RUN apt-get update; apt-get install -y fenics; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# basic stuff
RUN apt-get update; apt-get -y install rename; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# python stuff
RUN apt-get update; apt-get -y install python-future python-numpy python-scipy python-tk; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# vtk stuff
RUN apt-get update; apt-get -y install libvtk6-dev python-vtk6; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV CPATH="/usr/include/vtk-6.2":$CPATH
# gnuplot stuff
RUN apt-get update; apt-get -y install gnuplot git; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /home/fenics
RUN git clone https://github.com/aschn/gnuplot-colorbrewer.git
RUN echo "set loadpath \"/home/fenics/gnuplot-colorbrewer/diverging:/home/fenics/gnuplot-colorbrewer/qualitative:/home/fenics/gnuplot-colorbrewer/sequential\"" > .gnuplot
# environment setup
WORKDIR /home/fenics
RUN mkdir code
ENV PYTHONPATH=/home/fenics/code:$PYTHONPATH
ENV PYTHONPATH=/home/fenics/code/myPythonLibrary:$PYTHONPATH
ENV PYTHONPATH=/home/fenics/code/myVTKPythonLibrary:$PYTHONPATH
ENV PATH=/home/fenics/code/myPythonLibrary/myPythonLibrary:$PATH
ENV PATH=/home/fenics/code/myVTKPythonLibrary/myVTKPythonLibrary:$PATH
ENV PATH=/home/fenics/code/vtkpython_cbl:$PATH
#USER root
FROM registry.gitlab.inria.fr/mgenet/dolfin_warp/dolfin_warp-2017.2.0-dev
# RUN pip install myPythonLibrary
# RUN pip install myVTKPythonLibrary
RUN apt-get update; apt-get -y install git; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /home/fenics/code
RUN git clone https://gitlab.inria.fr/mgenet/myPythonLibrary.git
RUN git clone https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git
RUN git clone https://gitlab.inria.fr/mgenet/vtkpython_cbl.git
RUN git clone https://gitlab.inria.fr/mgenet/dolfin_mech.git
RUN git clone https://gitlab.inria.fr/mgenet/dolfin_warp.git
# FEniCS base
FROM quay.io/fenicsproject/stable:2019.1.0.r3
# basic stuff
RUN apt-get update; apt-get -y install rename; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# python3 stuff
RUN apt-get update; apt-get -y install python3-future python3-numpy python3-scipy python3-tk; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip install numpy==1.15
# vtk stuff
RUN apt-get update; apt-get -y install libvtk7-dev python3-vtk7; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV CPATH="/usr/include/vtk-7.1":$CPATH
# gnuplot stuff
RUN apt-get update; apt-get -y install gnuplot git; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /home/fenics
RUN git clone https://github.com/aschn/gnuplot-colorbrewer.git
RUN echo "set loadpath \"/home/fenics/gnuplot-colorbrewer/diverging:/home/fenics/gnuplot-colorbrewer/qualitative:/home/fenics/gnuplot-colorbrewer/sequential\"" > .gnuplot
# optimization stuff
RUN pip install git+https://github.com/dolfin-adjoint/pyadjoint.git@2019.1.0 cma nlopt sklearn
# environment setup
WORKDIR /home/fenics
RUN mkdir code
ENV PYTHONPATH=/home/fenics/code:$PYTHONPATH
ENV PYTHONPATH=/home/fenics/code/myPythonLibrary:$PYTHONPATH
ENV PYTHONPATH=/home/fenics/code/myVTKPythonLibrary:$PYTHONPATH
ENV PATH=/home/fenics/code/myPythonLibrary/myPythonLibrary:$PATH
ENV PATH=/home/fenics/code/myVTKPythonLibrary/myVTKPythonLibrary:$PATH
ENV PATH=/home/fenics/code/vtkpython_cbl:$PATH
FROM registry.gitlab.inria.fr/mgenet/dolfin_warp/dolfin_warp-2019.1.0-dev
# RUN pip install myPythonLibrary
# RUN pip install myVTKPythonLibrary
RUN apt-get update; apt-get -y install git; apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /home/fenics/code
RUN git clone https://gitlab.inria.fr/mgenet/myPythonLibrary.git
RUN git clone https://gitlab.inria.fr/mgenet/myVTKPythonLibrary.git
RUN git clone https://gitlab.inria.fr/mgenet/vtkpython_cbl.git
RUN git clone https://gitlab.inria.fr/mgenet/dolfin_mech.git
RUN git clone https://gitlab.inria.fr/mgenet/dolfin_warp.git
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# dolfin_warp
A set of FEniCS- and VTK-based python tools for Finite Element Digital Image Correlation/Image Registration/Motion Tracking, basically implementing the method described in [[Genet, Stoeck, von Deuster, Lee & Kozerke (2018). Equilibrated Warping: Finite Element Image Registration with Finite Strain Equilibrium Gap Regularization. Medical Image Analysis, 50, 1–22.](https://doi.org/10.1016/j.media.2018.07.007)] and [[Genet (2023). Finite strain formulation of the discrete equilibrium gap principle: application to mechanically consistent regularization for large motion tracking. Comptes Rendus Mécanique, 351, 429-458.](https://doi.org/10.5802/crmeca.228)].
The library has notably been used in:
* [[Genet, Stoeck, von Deuster, Lee & Kozerke (2018). Equilibrated Warping: Finite Element Image Registration with Finite Strain Equilibrium Gap Regularization. Medical Image Analysis, 50, 1–22.](https://doi.org/10.1016/j.media.2018.07.007)]
* [[Zou, Xi, Zhao, Koh, Gao, Su, Tan, Allen, Lee, Genet & Zhong (2018). Quantification of Biventricular Strains in Heart Failure With Preserved Ejection Fraction Patient Using Hyperelastic Warping Method. Frontiers in Physiology.](https://doi.org/10.3389/fphys.2018.01295)]
* [[Finsberg, Xi, Tan, Zhong, Genet, Sundnes, Lee & Wall (2018). Efficient estimation of personalized biventricular mechanical function employing gradient-based optimization. International Journal for Numerical Methods in Biomedical Engineering.](https://doi.org/10.1002/cnm.2982)]
* [[Berberoğlu, Stoeck, Moireau, Kozerke & Genet (2019). Validation of Finite Element Image Registration‐based Cardiac Strain Estimation from Magnetic Resonance Images. PAMM.](https://doi.org/10.1002/pamm.201900418)]
* [[Finsberg, Xi, Zhao, Tan, Genet, Sundnes, Lee, Zhong & Wall (2019). Computational quantification of patient-specific changes in ventricular dynamics associated with pulmonary hypertension. American Journal of Physiology-Heart and Circulatory Physiology.](https://doi.org/10.1152/ajpheart.00094.2019)]
* [[Lee & Genet (2019). Validation of Equilibrated Warping—Image Registration with Mechanical Regularization—On 3D Ultrasound Images. Functional Imaging and Modeling of the Heart (FIMH). Cham: Springer International Publishing.](https://doi.org/10.1007/978-3-030-21949-9_36)]
* [[Škardová, Rambausek, Chabiniok & Genet (2019). Mechanical and Imaging Models-Based Image Registration. VipIMAGE 2019. Cham: Springer International Publishing.](https://doi.org/10.1007/978-3-030-32040-9_9)]
* [[Zou, Leng, Xi, Zhao, Koh, Gao, Tan, Tan, Allen, Lee, Genet & Zhong (2020). Three-dimensional biventricular strains in pulmonary arterial hypertension patients using hyperelastic warping. Computer Methods and Programs in Biomedicine.](https://doi.org/10.1016/j.cmpb.2020.105345)]
* [[Gusseva, Hussain, Friesen, Moireau, Tandon, Patte, Genet, Hasbani, Greil, Chapelle & Chabiniok (2021). Biomechanical Modeling to Inform Pulmonary Valve Replacement in Tetralogy of Fallot Patients after Complete Repair. Canadian Journal of Cardiology.](https://doi.org/10.1016/j.cjca.2021.06.018)]
* [[Berberoğlu, Stoeck, Moireau, Kozerke & Genet (2021). In-silico study of accuracy and precision of left-ventricular strain quantification from 3D tagged MRI. PLOS ONE.](https://doi.org/10.1371/journal.pone.0258965)]
* [[Castellanos, Škardová, Bhattaru, Berberoğlu, Greil, Tandon, Dillenbeck, Burkhardt, Hussain, Genet & Chabiniok (2021). Left Ventricular Torsion Obtained Using Equilibrated Warping in Patients with Repaired Tetralogy of Fallot. Pediatric Cardiology.](https://doi.org/10.1007/s00246-021-02608-y)]
* [[Berberoğlu, Stoeck, Kozerke & Genet (2022). Quantification of left ventricular strain and torsion by joint analysis of 3D tagging and cine MR images. Medical Image Analysis.](https://doi.org/10.1016/j.media.2022.102598)]
* [[Patte, Brillet, Fetita, Gille, Bernaudin, Nunes, Chapelle & Genet (2022). Estimation of regional pulmonary compliance in idiopathic pulmonary fibrosis based on personalized lung poromechanical modeling. Journal of Biomechanical Engineering.](https://doi.org/10.1115/1.4054106)]
* [[Laville, Fetita, Gille, Brillet, Nunes, Bernaudin & Genet (2023). Comparison of optimization parametrizations for regional lung compliance estimation using personalized pulmonary poromechanical modeling. Biomechanics and Modeling in Mechanobiology.](https://doi.org/10.1007/s10237-023-01691-9)]
* [[Genet (2023). Finite strain formulation of the discrete equilibrium gap principle: application to mechanically consistent regularization for large motion tracking. Comptes Rendus Mécanique, 351, 429-458.](https://doi.org/10.5802/crmeca.228)]
(If you use it for your own work please let me know!)
### Tutorials
Interactive tutorials can be found at [https://mgenet.gitlabpages.inria.fr/dolfin_warp-tutorials](https://mgenet.gitlabpages.inria.fr/dolfin_warp-tutorials).
### Installation
A working installation of [FEniCS](https://fenicsproject.org) (version 2019.1.0; including the dolfin python interface) & [VTK](https://vtk.org) (also including python interface) is required to run `dolfin_warp`.
To setup a system, the simplest is to use [conda](https://conda.io): first install [miniconda](https://docs.conda.io/projects/miniconda/en/latest) (note that for Microsoft Windows machines you first need to install WSL, the [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install), and then install miniconda for linux inside the WSL; for Apple MacOS machines with Apple Silicon CPUs, you still need to install the MacOS Intel x86_64 version of miniconda), and then install the necessary packages:
```
conda create -y -c conda-forge -n dolfin_warp expat=2.5 fenics=2019.1.0 gnuplot=5.4 matplotlib=3.5 meshio=5.3 mpi4py=3.1.3 numpy=1.23.5 pandas=1.3 pip python=3.10 scipy=1.9 vtk=9.2
conda activate dolfin_warp
conda env config vars set CPATH=$CONDA_PREFIX/include/vtk-9.2
conda activate dolfin_warp
pip install dolfin_warp
```
test:
set -e; for i in test_*.py; do echo $$i; set -e; python $$i; done
#coding=utf8
################################################################################
import math
import os
import myVTKPythonLibrary as myvtk
import dolfin_mech as dmech
import dolfin_warp as dwarp
################################################################################
def generate_images_and_meshes_from_HeartSlice(
n_voxels : int ,
deformation_type : str ,
texture_type : str ,
noise_level : float ,
k_run : int = None,
run_model : bool = True,
generate_images : bool = True,
mesh_size : float = None):
images_folder = "generate_images"
if not os.path.exists(images_folder):
os.mkdir(images_folder)
working_basename = "heart"
working_basename += "-"+deformation_type
if (mesh_size is not None):
working_basename += "-h="+str(mesh_size)
if (mesh_size is None):
mesh_size = 1./n_voxels
mesh_params = {"X0":0.5, "Y0":0.5, "Ri":0.2, "Re":0.4, "l":mesh_size, "mesh_filebasename":images_folder+"/"+working_basename+"-mesh"}
if ("-coarse" in deformation_type):
mesh_params["l"] = 0.05
mesh_params["mesh_filebasename"] = images_folder+"/"+working_basename+"-mesh-coarse"
elif ("-fine" in deformation_type):
mesh_params["l"] = 0.01
mesh_params["mesh_filebasename"] = images_folder+"/"+working_basename+"-mesh-fine"
elif ("-ultrafine" in deformation_type):
mesh_params["l"] = 0.005
mesh_params["mesh_filebasename"] = images_folder+"/"+working_basename+"-mesh-ultrafine"
load_params = {"type":"disp", "dRi":-0.10, "dRe":-0.05, "dTi":-math.pi/4, "dTe":-math.pi/8}
if ("nocontract" in deformation_type):
load_params["dRi"] = 0.
load_params["dRe"] = 0.
if ("notwist" in deformation_type):
load_params["dTi"] = 0.
load_params["dTe"] = 0.
# print (run_model)
if (run_model):
dmech.run_HeartSlice_Hyperelasticity(
incomp = 0,
mesh_params = mesh_params,
mat_params = {"model":"CGNH", "parameters":{"E":1., "nu":0.3}},
step_params = {"dt_ini":1/20},
load_params = load_params,
res_basename = images_folder+"/"+working_basename,
write_vtus_with_preserved_connectivity = True,
verbose = 1)
if (generate_images):
ref_image = myvtk.createImageFromSizeAndRes(
dim = 2 ,
size = 1. ,
res = n_voxels,
up = 1 )
s = [0.1]*2
ref_image_model = lambda X:math.sqrt(abs(math.sin(math.pi*X[0]/s[0]))
* abs(math.sin(math.pi*X[1]/s[1])))
if (noise_level == 0):
noise_params = {"type":"no"}
else:
noise_params = {"type":"normal", "stdev":noise_level}
dwarp.compute_warped_images(
working_folder = images_folder,
working_basename = "heart-"+deformation_type,
working_ext = "vtu",
working_displacement_field_name = "U",
ref_image = ref_image,
ref_frame = 0,
ref_image_model = ref_image_model,
noise_params = noise_params,
suffix = texture_type+"-noise="+str(noise_level)+(k_run is not None)*("-run="+str(k_run).zfill(2)),
print_warped_mesh = 0,
verbose = 0)
########################################################################
if (__name__ == "__main__"):
import fire
fire.Fire(generate_images_and_meshes_from_HeartSlice)
# import argparse
# from distutils.util import strtobool
# parser = argparse.ArgumentParser()
# parser.add_argument("--n_dim" , type=int , choices=[2] )
# parser.add_argument("--n_voxels" , type=int )
# parser.add_argument("--deformation_type" , type=str )
# parser.add_argument("--texture_type" , type=str , choices=["tagging"])
# parser.add_argument("--noise_level" , type=float )
# parser.add_argument("--k_run" , type=int , default=None)
# parser.add_argument("--run_model" , type=lambda x: bool(strtobool(x)), default=True) # MG20220901: Watch out! All non empty strings evaluate to True!
# parser.add_argument("--generate_images" , type=lambda x: bool(strtobool(x)), default=True) # MG20220901: Watch out! All non empty strings evaluate to True!
# args = parser.parse_args()
# # print (args.run_model)
# generate_images_and_meshes_from_HeartSlice(
# n_dim = args.n_dim,
# n_voxels = args.n_voxels,
# deformation_type = args.deformation_type,
# texture_type = args.texture_type,
# noise_level = args.noise_level,
# k_run = args.k_run,
# run_model = args.run_model,
# generate_images = args.generate_images)
#coding=utf8
################################################################################
import dolfin
import math
import typing
import dolfin_mech as dmech
import dolfin_warp as dwarp
################################################################################
def generate_images_and_meshes_from_Struct(
n_dim : int ,
n_voxels : int ,
structure_type : str ,
deformation_type : str ,
texture_type : str ,
noise_level : float ,
k_run : typing.Optional[int] = None, # MG20220815: This can be written "int | None" starting with python 3.10
mesh_size : float = 0.1 ,
generate_images : bool = True,
compute_meshes : bool = True):
images = {
"n_dim":n_dim,
"L":[1.]*n_dim,
"n_voxels":[n_voxels]*n_dim,
"upsampling_factors":[1]*n_dim,
"T":1.,
"n_frames":21,
"data_type":"float"}
images["folder"] = "generate_images"
images["basename"] = structure_type
images["basename"] += "-"+deformation_type
images["basename"] += "-"+texture_type
images["basename"] += "-noise="+str(noise_level)
if (k_run is not None):
images["basename"] += "-run="+str(k_run).zfill(2)
images["ext"] = "vti"
if (structure_type == "square"):
if (deformation_type == "translation"):
Xmin = [0.1,0.2]
Xmax = [0.7,0.8]
elif (deformation_type in ("no", "rotation", "compression", "shear")):
Xmin = [0.2,0.2]
Xmax = [0.8,0.8]
else: assert (0)
structure = {"type":"box", "Xmin":Xmin, "Xmax":Xmax}
elif (structure_type == "disc"):
if (deformation_type == "translation"):
X0 = [0.4,0.5]
elif (deformation_type in ("no", "rotation", "compression", "shear")):
X0 = [0.5,0.5]
else: assert (0)
R = 0.35
structure = {"type":"disc", "X0":X0, "R":R}
elif (structure_type == "ring"):
if (deformation_type == "translation"):
X0 = [0.4,0.5]
elif (deformation_type in ("no", "rotation", "compression", "shear", "inflate", "twist")):
X0 = [0.5,0.5]
else: assert (0)
Ri = 0.15
Re = 0.35
structure = {"type":"heart", "X0":X0, "Ri":Ri, "Re":Re}
if (texture_type == "tagging"):
texture = {"type":"tagging", "s":0.1}
if (noise_level == 0):
noise = {"type":"no"}
else:
noise = {"type":"normal", "stdev":noise_level}
if (deformation_type == "no"):
deformation = {"type":"no"}
elif (deformation_type == "translation"):
deformation = {"type":"translation", "Dx":0.2, "Dy":0.}
elif (deformation_type == "rotation"):
deformation = {"type":"rotation", "Cx":0.5, "Cy":0.5, "Rz":45.} # 90 be require more time steps?
elif (deformation_type == "compression"):
deformation = {"type":"homogeneous", "X0":0.5, "Y0":0.5, "Exx":-0.20}
elif (deformation_type == "shear"):
deformation = {"type":"homogeneous", "X0":0.5, "Y0":0.5, "Fxy":+0.20}
elif (deformation_type == "inflate"):
deformation = {"type":"heart", "dRi":-0.10, "dRe":0., "dTi":0., "dTe":0.}
elif (deformation_type == "twist"):
deformation = {"type":"heart", "dRi":0., "dRe":0., "dTi":-math.pi/4, "dTe":0.}
evolution = {"type":"linear"}
if (generate_images):
dwarp.generate_images(
images = images,
structure = structure,
texture = texture,
noise = noise,
deformation = deformation,
evolution = evolution,
keep_temp_images = 0,
verbose = 1)
if (compute_meshes):
if (structure_type == "square"):
n_cells = int((0.8-0.2)/mesh_size)
if (n_dim == 2):
mesh = dolfin.RectangleMesh(
dolfin.Point(Xmin),
dolfin.Point(Xmax),
n_cells, n_cells,
"crossed")
elif (n_dim == 3):
mesh = dolfin.BoxMesh(
dolfin.Point(Xmin),
dolfin.Point(Xmax),
n_cells, n_cells, n_cells)
elif (structure_type == "disc"):
# import mshr
# geometry = mshr.Circle(dolfin.Point(X0[0], X0[1]), R)
# mesh = mshr.generate_mesh(geometry, r/mesh_size)
mesh, _, _, _, _, _, _, _ = dmech.run_Disc_Mesh(params={"X0":X0[0], "Y0":X0[1], "R":R, "l":mesh_size})
elif (structure_type == "ring"):
# import mshr
# geometry = mshr.Circle(dolfin.Point(X0[0], X0[1]), Re)\
# - mshr.Circle(dolfin.Point(X0[0], X0[1]), Ri)
# mesh = mshr.generate_mesh(geometry, (Re-Ri)/mesh_size)
mesh, _, _, _, _, _, _, _, _ = dmech.run_HeartSlice_Mesh(params={"X0":X0[0], "Y0":X0[1], "Ri":Ri, "Re":Re, "l":mesh_size})
working_folder = images["folder"]
working_basename = structure_type
working_basename += "-"+deformation_type
working_basename += "-h="+str(mesh_size)
dolfin.File(working_folder+"/"+working_basename+".xml") << mesh
dwarp.compute_warped_mesh(
working_folder = working_folder,
working_basename = working_basename,
images = images,
structure = structure,
deformation = deformation,
evolution = evolution,
mesh = mesh,
mesh_ext = "vtu",
verbose = 1)
########################################################################
if (__name__ == "__main__"):
import fire
fire.Fire(generate_images_and_meshes_from_Struct)
# import argparse
# from distutils.util import strtobool
# parser = argparse.ArgumentParser()
# parser.add_argument("--n_dim" , type=int , choices=[2,3] )
# parser.add_argument("--n_voxels" , type=int )
# parser.add_argument("--deformation_type", type=str , choices=["translation", "rotation", "compression", "shear"])
# parser.add_argument("--texture_type" , type=str , choices=["no", "tagging"] )
# parser.add_argument("--noise_level" , type=float )
# parser.add_argument("--k_run" , type=int , default=None)
# parser.add_argument("--generate_images" , type=lambda x: bool(strtobool(x)) , default=True) # MG20220901: Watch out! All non empty strings evaluate to True!
# parser.add_argument("--compute_meshes" , type=lambda x: bool(strtobool(x)) , default=True) # MG20220901: Watch out! All non empty strings evaluate to True!
# args = parser.parse_args()
# generate_images_and_meshes_from_Struct(
# n_dim = args.n_dim,
# n_voxels = args.n_voxels,
# deformation_type = args.deformation_type,
# texture_type = args.texture_type,
# noise_level = args.noise_level,
# k_run = args.k_run,
# generate_images = args.generate_images,
# compute_meshes = args.compute_meshes)
# noise_level regul_level mesh_size disp_err_avg disp_err_std disp_err_min disp_err_max
0.0 0.0 0.1 0.015962164014165964 0.0 0.015962164014165964 0.015962164014165964
0.0 0.0 0.05 0.042734835029093976 0.0 0.042734835029093976 0.042734835029093976
0.0 0.0 0.025 0.1028629303673039 0.0 0.1028629303673039 0.1028629303673039
0.0 0.0 0.0125 0.1667576966947951 0.0 0.1667576966947951 0.1667576966947951
0.0 0.0 0.00625 0.211275858626953 0.0 0.211275858626953 0.211275858626953
0.0 0.1 0.1 0.014836859253818181 0.0 0.014836859253818181 0.014836859253818181
0.0 0.1 0.05 0.01402212672105198 0.0 0.01402212672105198 0.01402212672105198
0.0 0.1 0.025 0.019056550311953465 0.0 0.019056550311953465 0.019056550311953465
0.0 0.1 0.0125 0.0193049708800561 0.0 0.0193049708800561 0.0193049708800561
0.0 0.1 0.00625 0.01983827666253226 0.0 0.01983827666253226 0.01983827666253226
0.1 0.0 0.1 0.03655036903642049 0.0006651313560001717 0.035317286778453305 0.037475925851265156
0.1 0.0 0.05 0.09149609522146633 0.0016940786152186704 0.08939129653320196 0.09472372495016612
0.1 0.0 0.025 0.1499321421902205 0.0023791258316908574 0.1469107367349529 0.15511113845791144
0.1 0.0 0.0125 0.18085919729808114 0.00220587689392177 0.17830436619716208 0.18620392137368155
0.1 0.0 0.00625 0.1983644210935879 0.007554064630692438 0.19381635948011608 0.22023635676331854
0.1 0.1 0.1 0.022274065397688468 0.0007105992957698582 0.021390867388747528 0.023763231828068734
0.1 0.1 0.05 0.028343001489011043 0.0002776335895695596 0.027958012795979686 0.028810336890601775
0.1 0.1 0.025 0.030821775392859057 0.0005336460825933512 0.029780833182624505 0.031631739673439054
0.1 0.1 0.0125 0.030854798067260332 0.0004183420112449717 0.030038878845465116 0.03144793566698627
0.1 0.1 0.00625 0.10029266911440327 0.11094975435011085 0.030188280471457718 0.40479315245531644
# noise_level regul_level mesh_size disp_err_avg disp_err_std disp_err_min disp_err_max
0.0 0.0 0.1 0.015962164014165964 0.0 0.015962164014165964 0.015962164014165964
0.0 0.0 0.05 0.055067415210899924 0.0 0.055067415210899924 0.055067415210899924
0.0 0.0 0.025 0.3896090323996506 0.0 0.3896090323996506 0.3896090323996506
0.0 0.0 0.0125 0.9301481213112067 0.0 0.9301481213112067 0.9301481213112067
0.0 0.0 0.00625 0.9820837244733407 0.0 0.9820837244733407 0.9820837244733407
0.0 0.1 0.1 0.014836859253818181 0.0 0.014836859253818181 0.014836859253818181
0.0 0.1 0.05 0.01428394299809057 0.0 0.01428394299809057 0.01428394299809057
0.0 0.1 0.025 0.9176460987052593 0.0 0.9176460987052593 0.9176460987052593
0.0 0.1 0.0125 0.966242962683782 0.0 0.966242962683782 0.966242962683782
0.0 0.1 0.00625 0.9857602375986628 0.0 0.9857602375986628 0.9857602375986628
0.1 0.0 0.1 0.03655036903642049 0.0006651313560001717 0.035317286778453305 0.037475925851265156
0.1 0.0 0.05 0.12524783161739536 0.005525325821283487 0.11413330547434246 0.13238173827965505
0.1 0.0 0.025 0.5921728364473541 0.13418284098136607 0.4653752849260762 0.8942222565567713
0.1 0.0 0.0125 0.6968344531057828 0.15720902669803632 0.5216937272222719 0.9381104154427546
0.1 0.0 0.00625 0.9475388011653388 0.3277005205271885 0.6733323444742123 1.8513643559295057
0.1 0.1 0.1 0.022274065397688468 0.0007105992957698582 0.021390867388747528 0.023763231828068734
0.1 0.1 0.05 0.31420585990807676 0.24513130582077655 0.030219799218450853 0.622625403307605
0.1 0.1 0.025 0.9379244797263316 0.011586789881604616 0.918279231114799 0.9540782994533524
0.1 0.1 0.0125 0.9746665532882666 0.0041583220091513245 0.9685277522579792 0.9807985968197472
0.1 0.1 0.00625 0.9908080349416327 0.0017877466144524989 0.9880099959877723 0.9940434445109201
#coding=utf8
########################################################################
import numpy
import os
import myPythonLibrary as mypy
import dolfin_warp as dwarp
########################################################################
def plot_disp_error_vs_mesh_size(
images_folder : str ,
sol_folder : str ,
structure_type : str ,
deformation_type : str ,
texture_type : str ,
regul_type : str ,
noise_level_lst : list ,
n_runs_for_noisy_images : int ,
regul_level_lst : list ,
mesh_size_lst : list ,
with_refine : bool = False,
error_for_nan : float = None ,
generate_datafile : bool = True ,
generate_datafile_with_limited_precision : bool = False,
generate_plotfile : bool = True ,
generate_plot : bool = True ):
print ("structure_type:" , structure_type )
print ("deformation_type:", deformation_type)
print ("texture_type:" , texture_type )
print ("regul_type:" , regul_type )
script_basename = "plot_disp_error_vs_mesh_size"
if not os.path.exists(script_basename):
os.mkdir(script_basename)
datafile_basename = script_basename
datafile_basename += "/"+structure_type
datafile_basename += "-"+deformation_type
datafile_basename += "-"+texture_type
datafile_basename += "-"+regul_type
if (with_refine):
datafile_basename += "-with_refine"
########################################################################
if (generate_datafile) or (generate_datafile_with_limited_precision):
if (generate_datafile): data_printer = mypy.DataPrinter(
names=["noise_level", "regul_level", "mesh_size", "disp_err_avg", "disp_err_std", "disp_err_min", "disp_err_max"],
filename=datafile_basename+".dat",
limited_precision=False)
if (generate_datafile_with_limited_precision): data_printer2 = mypy.DataPrinter(
names=["noise_level", "regul_level", "mesh_size", "disp_err_avg", "disp_err_std", "disp_err_min", "disp_err_max"],
filename=datafile_basename+"-limited_precision.dat",
limited_precision=True)
if (generate_datafile): data_printer3 = mypy.DataPrinter(
names=["noise_level", "regul_level", "mesh_size", "disp_err"],
filename=datafile_basename+"-all_points.dat",
limited_precision=False)
if (structure_type in ("square", "disc", "ring")):
ref_disp_array_name = "displacement"
elif (structure_type in ("heart")):
ref_disp_array_name = "U"
else: assert (0)
for noise_level in noise_level_lst:
for regul_level in regul_level_lst:
for k_mesh_size, mesh_size in enumerate(mesh_size_lst):
print ("noise_level:", noise_level)
print ("regul_level:", regul_level)
print ("mesh_size:" , mesh_size )
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
disp_err_lst = []
for k_run in range(1, n_runs+1):
print ("k_run:", k_run)
images_basename = structure_type
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
sol_basename = images_basename
if not (with_refine):
sol_basename += "-h="+str(mesh_size)
sol_basename += "-"+regul_type
sol_basename += "-regul="+str(regul_level)
if (with_refine):
sol_basename += "-refine="+str(k_mesh_size)
# import time
# t = time.time()
# disp_err_vtk = dwarp.compute_displacement_error_with_vtk(
# working_folder=sol_folder,
# working_basename=sol_basename,
# working_disp_array_name="displacement",
# ref_folder=images_folder,
# ref_basename=structure_type+"-"+deformation_type+"-h="+str(mesh_size),
# ref_disp_array_name=ref_disp_array_name,
# verbose=0)
# print ("t (vtk)", time.time() - t)
# print ("disp_err_vtk:", disp_err_vtk)
# t = time.time()
# disp_err_np = dwarp.compute_displacement_error_with_numpy(
# working_folder=sol_folder,
# working_basename=sol_basename,
# working_disp_array_name="displacement",
# ref_folder=images_folder,
# ref_basename=structure_type+"-"+deformation_type+"-h="+str(mesh_size),
# ref_disp_array_name=ref_disp_array_name,
# verbose=0)
# print ("t (np)", time.time() - t)
# print ("disp_err_np:", disp_err_np)
# assert (disp_err_np == disp_err_vtk)
# t = time.time()
# disp_err_fenics = dwarp.compute_displacement_error_with_fenics(
# working_folder=sol_folder,
# working_basename=sol_basename,
# working_disp_array_name="displacement",
# ref_folder=images_folder,
# ref_basename=structure_type+"-"+deformation_type,
# ref_disp_array_name=ref_disp_array_name,
# verbose=0)
# print ("t (fenics)", time.time() - t)
# print ("disp_err_fenics:", disp_err_fenics)
# disp_err = disp_err_fenics
try:
disp_err = dwarp.compute_displacement_error_with_fenics(
working_folder=sol_folder,
working_basename=sol_basename,
working_disp_array_name="displacement",
ref_folder=images_folder,
ref_basename=structure_type+"-"+deformation_type,
ref_disp_array_name=ref_disp_array_name,
verbose=0)
# disp_err = dwarp.compute_displacement_error(
# working_folder=sol_folder,
# working_basename=sol_basename,
# working_disp_array_name="displacement",
# ref_folder=images_folder,
# ref_basename=structure_type+"-"+deformation_type+"-h="+str(mesh_size),
# ref_disp_array_name=ref_disp_array_name,
# verbose=0)
except:
disp_err = error_for_nan
print ("disp_err:", disp_err)
disp_err_lst.append(disp_err)
if (error_for_nan is not None):
if numpy.isnan(disp_err) or (disp_err > error_for_nan):
disp_err = error_for_nan
if (generate_datafile): data_printer3.write_line([noise_level, regul_level, mesh_size, disp_err])
disp_err_avg = numpy.mean(disp_err_lst)
disp_err_std = numpy.std(disp_err_lst)
disp_err_min = numpy.min(disp_err_lst)
disp_err_max = numpy.max(disp_err_lst)
print ("disp_err_avg:", disp_err_avg)
print ("disp_err_std:", disp_err_std)
print ("disp_err_min:", disp_err_min)
print ("disp_err_max:", disp_err_max)
if (error_for_nan is not None):
if numpy.isnan(disp_err_avg) or (disp_err_avg > error_for_nan):
disp_err_avg = error_for_nan
disp_err_std = 0.
if (disp_err_min > error_for_nan):
disp_err_min = error_for_nan
disp_err_max = error_for_nan
if (generate_datafile ): data_printer.write_line([noise_level, regul_level, mesh_size, disp_err_avg, disp_err_std, disp_err_min, disp_err_max])
if (generate_datafile_with_limited_precision): data_printer2.write_line([noise_level, regul_level, mesh_size, disp_err_avg, disp_err_std, disp_err_min, disp_err_max])
if (generate_datafile ): data_printer.write_line(); data_printer.write_line()
if (generate_datafile_with_limited_precision): data_printer2.write_line(); data_printer2.write_line()
if (generate_datafile ): data_printer3.write_line(); data_printer3.write_line()
if (generate_datafile ): data_printer.close()
if (generate_datafile_with_limited_precision): data_printer2.close()
if (generate_datafile ): data_printer3.close()
########################################################################
if (generate_plotfile):
plotfile = open(datafile_basename+".plt", "w")
plotfile.write('''\
set terminal pdf enhanced size 5,3; outputfile_ext = "pdf"
load "Set1.plt"
set linestyle 1 pointtype 0
set linestyle 2 pointtype 0
set linestyle 3 pointtype 0
set linestyle 4 pointtype 0
set linestyle 5 pointtype 0
set linestyle 6 pointtype 0
set linestyle 7 pointtype 0
set linestyle 8 pointtype 0
set linestyle 9 pointtype 0
set linestyle 10 pointtype 0
set linestyle 11 pointtype 0
set linestyle 12 pointtype 0
set style fill transparent solid 0.1 noborder
datafile_basename = "'''+datafile_basename+'''"
datafile_name = datafile_basename.".dat"
poinfile_name = datafile_basename."-all_points.dat"
set output datafile_basename.".".outputfile_ext
set title "'''+structure_type+'''-'''+deformation_type+'''-'''+regul_type+'''"
set key outside right center box textcolor variable width -3
set grid
set xlabel "mesh size"
set xrange [0.1/2**4:0.1]
# set format x "%g"
set logscale x
set ylabel "normalized displacement error (%)"
set yrange [1e-1:1e+3]
set logscale y
plot ''')
for k_noise_level,noise_level in enumerate(noise_level_lst):
for k_regul_level,regul_level in enumerate(regul_level_lst):
if (noise_level == 0.0): lc = 1
elif (noise_level == 0.1): lc = 2
elif (noise_level == 0.2): lc = 3
elif (noise_level == 0.3): lc = 4
else: assert (0)
if (regul_level == 0.0 ): dt = 1
elif (regul_level == 0.1 ): dt = 2
elif (regul_level == 0.99): dt = 3
else: assert (0)
# index_for_plot = k_regul_level*len(noise_level_lst)+k_noise_level+1
index_for_data = k_noise_level*len(regul_level_lst)+k_regul_level
plotfile.write(((''' ''')*((k_noise_level>0)or(k_regul_level>0)))+'''datafile_name index '''+str(index_for_data)+''' using ($3):(100*$4) with lines linestyle '''+str(lc)+''' dashtype '''+str(dt)+''' linewidth 3 title "noise = '''+"{:1.1f}".format(noise_level)+''', regul = '''+"{:1.2f}".format(regul_level)+'''"'''+''',\\\n''')
if (noise_level == 0): continue
# plotfile.write( ''' ''' +'''datafile_name index '''+str(index_for_data)+''' using ($3):(100*$4):(100*$5) with errorbars linestyle '''+str(lc)+''' notitle''' +''',\\\n''')
# plotfile.write( ''' ''' +'''datafile_name index '''+str(index_for_data)+''' using ($3):(100*$4-100*$5):(100*$4+100*$5) with filledcurves linestyle '''+str(lc)+''' notitle''' +((''',\\
plotfile.write( ''' ''' +'''poinfile_name index '''+str(index_for_data)+''' using ($3):(100*$4) with points linestyle '''+str(lc)+''' notitle''' +((''',\\
''')*((k_noise_level<len(noise_level_lst)-1)or(k_regul_level<len(regul_level_lst)-1))))
plotfile.close()
########################################################################
if (generate_plot):
os.system("gnuplot "+datafile_basename+".plt")
os.system("convert -density 300 "+datafile_basename+".pdf"+" "+datafile_basename+".png")
########################################################################
if (__name__ == "__main__"):
import fire
fire.Fire(plot_disp_error_vs_mesh_size)
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.5816852389172984 0.0
0.0 0.8 0.19368023004774895 0.0
0.0 0.4 0.09145007253920429 0.0
0.0 0.2 0.05665768439651671 0.0
0.0 0.1 0.033945826072207176 0.0
0.0 0.05 0.02492552630823139 0.0
0.0 0.025 0.022309037733112866 0.0
0.0 0.0125 0.022298499424028593 0.0
0.0 0.001 0.023769174394975282 0.0
0.1 0.99 0.697464532051001 0.02185600436962613
0.1 0.8 0.1994415254313896 0.0011354080298153068
0.1 0.4 0.09762662605531053 0.0016378049258639095
0.1 0.2 0.06462602712232121 0.0017966491004197647
0.1 0.1 0.04759551156664602 0.001323131822203368
0.1 0.05 0.04630896601464008 0.0013500020318863804
0.1 0.025 0.04908141796337479 0.0013137626001367654
0.1 0.0125 0.05235282142634371 0.0013139148250238917
0.1 0.001 0.0587169249628267 0.0013645664091331115
0.2 0.99 0.6665357317447584 0.03114323063824824
0.2 0.8 0.21491632018018417 0.0027358772490789717
0.2 0.4 0.11304358729454123 0.0018577242902248243
0.2 0.2 0.08515073788249392 0.0026164119262251967
0.2 0.1 0.07916806062949974 0.003129854967537309
0.2 0.05 0.08622217610024792 0.0026927473833285166
0.2 0.025 0.09755895684795715 0.0028209462553182023
0.2 0.0125 0.10875841456324378 0.0037901107560656365
0.2 0.001 0.13118952356750835 0.008054871316094782
0.3 0.99 0.6718630985485015 0.02429877283957384
0.3 0.8 0.23783953645516176 0.002341794380396059
0.3 0.4 0.13487858075738235 0.0047761195829776
0.3 0.2 0.11582118308871751 0.002875721300744551
0.3 0.1 0.1181812568404764 0.003441515252626044
0.3 0.05 0.13498732765945082 0.0032368417872816347
0.3 0.025 0.15744393942137425 0.00450417006869567
0.3 0.0125 0.1797674138614367 0.004590900713791106
0.3 0.001 0.2817265903366749 0.04295230986904851
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.26153064798170134 0.0
0.0 0.8 0.2533805247613701 0.0
0.0 0.4 0.23004080628673707 0.0
0.0 0.2 0.19642142258356401 0.0
0.0 0.1 0.15140511212657487 0.0
0.0 0.05 0.11278152210054591 0.0
0.0 0.025 0.08770617747870728 0.0
0.0 0.0125 0.07012265766540846 0.0
0.0 0.001 0.023769174394975282 0.0
0.1 0.99 0.26175085030890904 8.392223477230087e-05
0.1 0.8 0.25418261204546155 0.0002694680486175075
0.1 0.4 0.23203660186990738 0.0005894278021557493
0.1 0.2 0.20030585529666028 0.0008688353316659991
0.1 0.1 0.15714112905528754 0.0014175372215870464
0.1 0.05 0.11829852493283641 0.0010614184241990472
0.1 0.025 0.09344896473869002 0.0011857756532892341
0.1 0.0125 0.07592479660991878 0.001053351874213409
0.1 0.001 0.0587169249628267 0.0013645664091331115
0.2 0.99 0.26280330171357746 0.00033313081767704023
0.2 0.8 0.2565668116738946 0.000490734150600739
0.2 0.4 0.23732846835764496 0.0012561674158990384
0.2 0.2 0.20997900765613844 0.0021498065105989696
0.2 0.1 0.17182820664687853 0.0025341966582828083
0.2 0.05 0.1338227932916132 0.001547922691162716
0.2 0.025 0.10784527159036258 0.001436205648938557
0.2 0.0125 0.0932597859241224 0.00177477408030495
0.2 0.001 0.13118952356750835 0.008054871316094782
0.3 0.99 0.2642032154019099 0.0005154854858673839
0.3 0.8 0.25985065267751883 0.0008379347794531446
0.3 0.4 0.24478881106718312 0.0013328936814169725
0.3 0.2 0.22374439485980235 0.001587655807206933
0.3 0.1 0.19210275344694655 0.002242225851465886
0.3 0.05 0.15627975959934196 0.003676743574428354
0.3 0.025 0.13065951293126338 0.004462778546757685
0.3 0.0125 0.11756169938692887 0.003526680736307381
0.3 0.001 0.2817265903366749 0.04295230986904851
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.8514218516003781 0.0
0.0 0.8 0.17423536065711664 0.0
0.0 0.4 0.07153400447260017 0.0
0.0 0.2 0.0426625799816099 0.0
0.0 0.1 0.026950823291853433 0.0
0.0 0.05 0.023212595676364408 0.0
0.0 0.025 0.021771433080173215 0.0
0.0 0.0125 0.021943585297099614 0.0
0.0 0.001 0.023769174394975282 0.0
0.1 0.99 0.852485265763319 0.007861422196648293
0.1 0.8 0.18413822901450452 0.0019054004423010981
0.1 0.4 0.07709267173488878 0.0016768645238988756
0.1 0.2 0.050478241000622946 0.00172830768671845
0.1 0.1 0.04144551871694992 0.001049322342383999
0.1 0.05 0.04384573454629243 0.0011743842500646024
0.1 0.025 0.04794209876751785 0.001211384278680234
0.1 0.0125 0.051789860547709024 0.0012477276821368105
0.1 0.001 0.0587169249628267 0.0013645664091331115
0.2 0.99 0.8408314548323632 0.016136150476958766
0.2 0.8 0.21422285036517802 0.0050808243953227306
0.2 0.4 0.09197337164247792 0.001424401055186962
0.2 0.2 0.07181460118358135 0.0030235613605553366
0.2 0.1 0.07188141414267642 0.002862960472454493
0.2 0.05 0.08294067563189514 0.002559112549758695
0.2 0.025 0.09567138029528952 0.00212874166789014
0.2 0.0125 0.10802283103273554 0.0036108736998476496
0.2 0.001 0.13118952356750835 0.008054871316094782
0.3 0.99 0.8359775881049206 0.022574940551918974
0.3 0.8 0.2893190699445056 0.015393679571473681
0.3 0.4 0.11301912986154447 0.0029631920299840304
0.3 0.2 0.10178421989288382 0.0025732499710975853
0.3 0.1 0.11056021791055948 0.002758204305122169
0.3 0.05 0.13012609849438583 0.002521647874051257
0.3 0.025 0.154245857961794 0.0029241472368820385
0.3 0.0125 0.1824500500650738 0.005011402666181719
0.3 0.001 0.2817265903366749 0.04295230986904851
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.26176907357634355 0.0
0.0 0.8 0.25737648801831986 0.0
0.0 0.4 0.2380717652601589 0.0
0.0 0.2 0.20497132376547259 0.0
0.0 0.1 0.15292320728449685 0.0
0.0 0.05 0.10429484147604344 0.0
0.0 0.025 0.07651058678104866 0.0
0.0 0.0125 0.05658306418776406 0.0
0.0 0.001 0.023769174394975282 0.0
0.1 0.99 0.2619727075130125 7.804786102445839e-05
0.1 0.8 0.25796531657384836 0.00012057688275377603
0.1 0.4 0.23999774766666593 0.00041577545775570775
0.1 0.2 0.20890663103471535 0.0008720071988507903
0.1 0.1 0.1596788768384036 0.001682947128399755
0.1 0.05 0.11059935677478269 0.0013292033173343185
0.1 0.025 0.08240256274899171 0.0014064305516321982
0.1 0.0125 0.06282692063242155 0.0015077643013726824
0.1 0.001 0.0587169249628267 0.0013645664091331115
0.2 0.99 0.26298912717885303 0.00033016357357358003
0.2 0.8 0.2598005198493086 0.00031581685927636367
0.2 0.4 0.24489504533875506 0.0008032987374102602
0.2 0.2 0.21876514143041192 0.0018789885764728424
0.2 0.1 0.176658900809636 0.0031151363980191984
0.2 0.05 0.12829543861760245 0.0021753474986908067
0.2 0.025 0.09809755793527879 0.001408776581681979
0.2 0.0125 0.08129149891559301 0.002525005942575945
0.2 0.001 0.13118952356750835 0.008054871316094782
0.3 0.99 0.2643279130469586 0.0005078960688163275
0.3 0.8 0.26238225580702135 0.0006390601762918886
0.3 0.4 0.2515361747181659 0.0009679284590499659
0.3 0.2 0.23189323389102462 0.0013150124382134468
0.3 0.1 0.19818032826331716 0.0023123736432799366
0.3 0.05 0.15244726949571172 0.005038949572545782
0.3 0.025 0.12132980879108539 0.005329033241025868
0.3 0.0125 0.10755846695843137 0.003975549129724922
0.3 0.001 0.2817265903366749 0.04295230986904851
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.01502388509498367 0.0
0.0 0.8 0.014797104337154313 0.0
0.0 0.4 0.01440795240847769 0.0
0.0 0.2 0.01455592370546379 0.0
0.0 0.1 0.014814075659159301 0.0
0.0 0.05 0.015373063216052573 0.0
0.0 0.025 0.016167334612908014 0.0
0.0 0.0125 0.017193048075291727 0.0
0.0 0.001 0.023769174394975282 0.0
0.1 0.99 0.024473749826257284 0.0009227437827716936
0.1 0.8 0.02483992707101328 0.0008752490098760181
0.1 0.4 0.02569871413934796 0.0008697965398781323
0.1 0.2 0.026766482413945282 0.0008572185859865812
0.1 0.1 0.028244824883774815 0.0008513354791712042
0.1 0.05 0.03035645504174131 0.0009327933349009069
0.1 0.025 0.03284022280077821 0.0009574758336122536
0.1 0.0125 0.035676858183218925 0.0010074682424075518
0.1 0.001 0.05661630186659864 0.0006583046470288724
0.2 0.99 0.045927081376641324 0.0014637549037967547
0.2 0.8 0.046626140591942214 0.0014023691101281797
0.2 0.4 0.04927486180021969 0.0010921139581210385
0.2 0.2 0.051992719060593315 0.0010540789214171515
0.2 0.1 0.05558228091662622 0.0011247656216955184
0.2 0.05 0.05998619581549295 0.0013223958859000622
0.2 0.025 0.06565954248216936 0.0014421631006750852
0.2 0.0125 0.07193385981883141 0.0013681544551986183
0.2 0.001 0.13118952356750835 0.008054871316094782
0.3 0.99 0.07595244237323535 0.002880403777644044
0.3 0.8 0.07720326559343532 0.002925209040129758
0.3 0.4 0.08227397522084508 0.0039370962523901
0.3 0.2 0.08698054936470609 0.003993353564990639
0.3 0.1 0.09318003959242836 0.004521563104319278
0.3 0.05 0.0998098270450993 0.005441394334415846
0.3 0.025 0.10950220791986061 0.006088195419470233
0.3 0.0125 0.12162359604677295 0.010469936156434744
0.3 0.001 0.2817265903366749 0.04295230986904851