Coder Social home page Coder Social logo

eqrisi / ogs6py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joergbuchwald/ogs6py

0.0 0.0 0.0 2.13 MB

Python-API for the OpenGeoSys (http://www.opengeosys.org) software.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

ogs6py's Introduction

DOI ogs6py_test codecov DOI

ogs6py

ogs6py is a python-API for the OpenGeoSys finite element sofware. Its main functionalities include creating and altering OGS6 input files as well as executing OGS. The package allows to streamline OGS-workflows with python or Julia entirely in jupyter or pluto notebooks as demonstrated in the following video:

video presentation of ogs6py and vtu interface

To alter and execute OGS input, e.g., for looping over parameter ranges, two approaches exist:

1. creating a new input file using python method calls
2. altering existing input files

0. Installation

ogs6py can be easily installed from PyPI

# pip install [--user] ogs6py

or the latest version from github:

# pip install [--user] https://github.com/joergbuchwald/ogs6py/archive/refs/heads/master.zip

Note that the logfile parser of ogs6py requires at least Python 3.8.

Unittests can be run via

# python tests/test_ogs6py.py

CAUTION: naming style of methods has changed (2021-05-20)

1. Documentation for ogs6py

You can find the documentation under https://joergbuchwald.github.io/ogs6py-doc

2. Creating a new input file

The following example consists of a simple mechanics problem. The source file can be found in the examples directory The names of the method calls are based on the corresponing XML tags.

from ogs6py import ogs

model = ogs.OGS(PROJECT_FILE="simple_mechanics.prj")
model.geo.add_geom(filename="square_1x1.gml")
model.mesh.add_mesh(filename="square_1x1_quad_1e2.vtu")
model.processes.set_process(name="SD",
                           type="SMALL_DEFORMATION",
                           integration_order="2",
                           solid_density="rho_sr",
                           specific_body_force="0 0")
model.processes.set_constitutive_relation(type="LinearElasticIsotropic",
                                        youngs_modulus="E",
                                        poissons_ratio="nu")
model.processes.add_process_variable(process_variable="process_variable",
                                   process_variable_name="displacement")
model.processes.add_process_variable(secondary_variable="sigma",
                                   output_name="sigma")
model.timeloop.add_process(process="SD",
                          nonlinear_solver_name="basic_newton",
                          convergence_type="DeltaX",
                          norm_type="NORM2",
                          abstol="1e-15",
                          time_discretization="BackwardEuler")
model.timeloop.set_stepping(process="SD", type="FixedTimeStepping",
                           t_initial="0",
                           t_end="1",
                           repeat="4",
                           delta_t="0.25")
model.timeloop.add_output(type="VTK",
                         prefix="blubb",
                         repeat="1",
                         each_steps="10",
                         variables=["displacement", "sigma"])
model.parameters.add_parameter(name="E", type="Constant", value="1")
model.parameters.add_parameter(name="nu", type="Constant", value="0.3")
model.parameters.add_parameter(name="rho_sr", type="Constant", value="1")
model.parameters.add_parameter(name="displacement0",
                              type="Constant",
                              values="0 0")
model.parameters.add_parameter(name="dirichlet0", type="Constant", value="0")
model.parameters.add_parameter(name="dirichlet1", type="Constant", value="0.05")
model.processvars.set_ic(process_variable_name="displacement",
                        components="2",
                        order="1",
                        initial_condition="displacement0")
model.processvars.add_bc(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="left",
                        type="Dirichlet",
                        component="0",
                        parameter="dirichlet0")
model.processvars.add_bc(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="bottom",
                        type="Dirichlet",
                        component="1",
                        parameter="dirichlet0")
model.processvars.add_bc(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="top",
                        type="Dirichlet",
                        component="1",
                        parameter="dirichlet1")
model.nonlinsolvers.add_non_lin_solver(name="basic_newton",
                                    type="Newton",
                                    max_iter="4",
                                    linear_solver="general_linear_solver")
model.linsolvers.add_lin_solver(name="general_linear_solver",
                              kind="lis",
                              solver_type="cg",
                              precon_type="jacobi",
                              max_iteration_step="10000",
                              error_tolerance="1e-16")
model.linsolvers.add_lin_solver(name="general_linear_solver",
                              kind="eigen",
                              solver_type="CG",
                              precon_type="DIAGONAL",
                              max_iteration_step="10000",
                              error_tolerance="1e-16")
model.linsolvers.add_lin_solver(name="general_linear_solver",
                              kind="petsc",
                              prefix="sd",
                              solver_type="cg",
                              precon_type="bjacobi",
                              max_iteration_step="10000",
                              error_tolerance="1e-16")
model.write_input()
model.run_model(logfile="out.log")
model.runModel(path="~/github/ogs/build_mkl/bin")

An example using the MPL can be find in example_THM.py.

3. Alternatively it is possible to alter existing files using the available replace methods:

E.g., to iterate over three Young's moduli one can use the replace parameter method:

Es = [1,2,3]
filename = "simple_mechanics.prj"
for E in Es:
    model = OGS(INPUT_FILE=filename, PROJECT_FILE=filename)
    model.replace_parameter(name="E", value=E)
    model.replace_text("out_E="+str(E), xpath="./time_loop/output/prefix")
    model.write_input()
    model.run_model(path="~/github/ogs/build_mkl/bin")

Instead of the replace_parameter method, the more general replace_text method can also be used to replace the young modulus in this example:

model.replace_text(E, xpath="./parameters/parameter[name='E']/value")

The Young's modulus in this file can also be accessed through 0'th occurrence of the place addressed by the xpath ./parameters/parameter/value

model.replace_text(E, xpath="./parameters/parameter/value", occurrence=0)

For MPL based processes, there exist specific functions to set phase and medium properties: e.g.,

model.replace_phase_property(mediumid=0, phase="Solid", name="thermal_expansivity", value="42")

for a phse property and

model.replace_medium_property(mediumid=0, name="porosity", value="0.24")

for a property that lives on the medium level.

4. Log-Parser

To parse the OGS output that is piped into a file do

df = model.parse_out("examples/out_thm.log")

which returns a pandas dataframe.

5. Examples

There are examples that have been used in OGS workflows and may be generalized to other use cases

  • generating an input file (prj) from a file template by reading parameters from a data file (csv),
  • finding the optimal coupling scheme parameter for the staggered scheme.

6. FAQ/Troubleshooting

  • OGS exectution fails and nothing is written to the logfile. Please check whether OGS is executed correctly from the terminal. A common issue is related to the fact that the interactive python environment differs from the environment in the terminal. Usually, this can be fixed by setting the required environment variables via a wrapper command. E.g., model.run_model(wrapper="source /opt/intel/oneapi/setvars.sh intel64 &&").

ogs6py's People

Contributors

joergbuchwald avatar dominik-kern avatar eqrisi avatar nagelt avatar oliverpetschick avatar tomfischer avatar endjunction avatar bilke avatar olafkolditz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.