Skip to main content

No project description provided

Project description

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:

IMAGE ALT TEXT HERE

Please note: due to changes in the file structure ogs6py is now imported by from ogs6py.ogs import OGS

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

1. Creating a new input file

The following example consists of a simle mechanics problem. The names of the method calls are based on the corresponing XML tags. The MKL=True option executes source /opt/intel/mkl/bin/mklvars.sh intel64 before the ogs call.

from ogs6py.ogs import OGS

model = OGS(PROJECT_FILE="simple_mechanics.prj", MKL=True)
model.geo.addGeom(filename="square_1x1.gml")
model.mesh.addMesh(filename="square_1x1_quad_1e2.vtu")
model.processes.setProcess(name="SD",
                           type="SMALL_DEFORMATION",
                           integration_order=2,
                           solid_density="rho_sr",
                           specific_body_force="0 0")
model.processes.setConstitutiveRelation(type="LinearElasticIsotropic",
                                        youngs_modulus="E",
                                        poissons_ratio="nu")
model.processes.addProcessVariable(process_variable="process_variable",
                                   process_variable_name="displacement")
model.processes.addProcessVariable(secondary_variable="sigma",
                                   output_name="sigma")
model.timeloop.addProcess(process="SD",
                          nonlinear_solver_name="basic_newton",
                          convergence_type="DeltaX",
                          norm_type="NORM2",
                          abstol=1e-15,
                          time_discretization="BackwardEuler")
model.timeloop.setStepping(process="SD", type="FixedTimeStepping",
                           t_initial=0,
                           t_end=1,
                           repeat=4,
                           delta_t=0.25)
model.timeloop.addOutput(type="VTK",
                         prefix="blubb",
                         repeat=1,
                         each_steps=10,
                         variables=["displacement", "sigma"])
model.parameters.addParameter(name="E", type="Constant", value=1)
model.parameters.addParameter(name="nu", type="Constant", value=0.3)
model.parameters.addParameter(name="rho_sr", type="Constant", value=1)
model.parameters.addParameter(name="displacement0",
                              type="Constant",
                              values="0 0")
model.parameters.addParameter(name="dirichlet0", type="Constant", value=0)
model.parameters.addParameter(name="dirichlet1", type="Constant", value=0.05)
model.processvars.setIC(process_variable_name="displacement",
                        components=2,
                        order=1,
                        initial_condition="displacement0")
model.processvars.addBC(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="left",
                        type="Dirichlet",
                        component=0,
                        parameter="dirichlet0")
model.processvars.addBC(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="bottom",
                        type="Dirichlet",
                        component=1,
                        parameter="dirichlet0")
model.processvars.addBC(process_variable_name="displacement",
                        geometrical_set="square_1x1_geometry",
                        geometry="top",
                        type="Dirichlet",
                        component=1,
                        parameter="dirichlet1")
model.nonlinsolvers.addNonlinSolver(name="basic_newton",
                                    type="Newton",
                                    max_iter=4,
                                    linear_solver="general_linear_solver")
model.linsolvers.addLinSolver(name="general_linear_solver",
                              kind="lis",
                              solver_type="cg",
                              precon_type="jacobi",
                              max_iteration_step=10000,
                              error_tolerance=1e-16)
model.linsolvers.addLinSolver(name="general_linear_solver",
                              kind="eigen",
                              solver_type="CG",
                              precon_type="DIAGONAL",
                              max_iteration_step=10000,
                              error_tolerance=1e-16)
model.linsolvers.addLinSolver(name="general_linear_solver",
                              kind="petsc",
                              solver_type="cg",
                              precon_type="bjacobi",
                              max_iteration_step=10000,
                              error_tolerance=1e-16)
model.writeInput()
True
model.runModel(path="~/github/ogs/build_mkl/bin")
OGS finished with project file simple_mechanics.prj.
Execution took 0.0639185905456543 s

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

2. 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, MKL=True)
    model.replaceParameter(name="E", value=E)
    model.replaceTxt("out_E="+str(E), xpath="./time_loop/output/prefix")
    model.writeInput()
    model.runModel(path="~/github/ogs/build_mkl/bin")
OGS finished with project file simple_mechanics.prj.
Execution took 0.06496095657348633 s
OGS finished with project file simple_mechanics.prj.
Execution took 0.05861473083496094 s
OGS finished with project file simple_mechanics.prj.
Execution took 0.056302547454833984 s

Instead of the replaceParameter method, the more general replaceTxt method can be used

model.replaceTxt(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.replaceTxt(E, xpath="./parameters/parameter/value", occurrence=0)

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

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

for a phse property and

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

for a property that lives on the medium level.

3. Log-Parser

To parse the output that is piped into a file named out.log you can simply do:

df = model.parseOut("out_thm.log")
df
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
execution_time time_step/number time_step/t time_step/dt time_step/cpu_time time_step/output_time time_step/iteration/number time_step/iteration/assembly_time time_step/iteration/dirichlet_bc_time time_step/iteration/linear_solver_time time_step/iteration/cpu_time time_step/iteration/component_convergence/number time_step/iteration/component_convergence/dx time_step/iteration/component_convergence/x time_step/iteration/component_convergence/dx_relative
0 25.2781 1 1.0 1.0 2.478990 0.013315 1 0.035883 0.004113 0.091469 0.132779 0 1.884600e+04 2.091500e+04 9.010800e-01
1 25.2781 1 1.0 1.0 2.478990 0.013315 1 0.035883 0.004113 0.091469 0.132779 1 8.858200e+09 8.858200e+09 1.000000e+00
2 25.2781 1 1.0 1.0 2.478990 0.013315 1 0.035883 0.004113 0.091469 0.132779 2 4.439300e-04 4.439300e-04 1.000000e+00
3 25.2781 1 1.0 1.0 2.478990 0.013315 1 0.035883 0.004113 0.091469 0.132779 3 4.579000e-04 4.579000e-04 1.000000e+00
4 25.2781 1 1.0 1.0 2.478990 0.013315 2 0.033763 0.003531 0.064117 0.102725 0 4.063800e+03 2.458900e+04 1.652700e-01
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
995 25.2781 31 50000.0 4514.0 0.581043 0.014266 5 0.035133 0.002944 0.055049 0.094542 3 3.180600e-17 7.074400e-03 4.496000e-15
996 25.2781 31 50000.0 4514.0 0.581043 0.014266 6 0.036252 0.003204 0.055754 0.096534 0 6.841200e-12 4.005500e+04 1.708000e-16
997 25.2781 31 50000.0 4514.0 0.581043 0.014266 6 0.036252 0.003204 0.055754 0.096534 1 8.289800e-07 5.261000e+08 1.575700e-15
998 25.2781 31 50000.0 4514.0 0.581043 0.014266 6 0.036252 0.003204 0.055754 0.096534 2 4.418700e-18 7.150300e-03 6.179700e-16
999 25.2781 31 50000.0 4514.0 0.581043 0.014266 6 0.036252 0.003204 0.055754 0.096534 3 4.490900e-18 7.074400e-03 6.348100e-16

1000 rows × 15 columns

import matplotlib.pyplot as plt
plt.plot(df["time_step/iteration/number"])
plt.xlabel("iterations")
plt.ylabel("iterations per time step")
Text(0, 0.5, 'iterations per time step')

png



          

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ogs6py-0.30.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

ogs6py-0.30-py2.py3-none-any.whl (22.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ogs6py-0.30.tar.gz.

File metadata

  • Download URL: ogs6py-0.30.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.2

File hashes

Hashes for ogs6py-0.30.tar.gz
Algorithm Hash digest
SHA256 7fb7be0ea1f8d4abe1f03f9abbf3f1ca468bb98f77e3b928f6360e5e81033eb3
MD5 d7e9f2daf859db64f0442ff678ac84b2
BLAKE2b-256 7957f5c3568a133b0aa1504673f4ddb2d6263d55e7367962bc56ee111288463a

See more details on using hashes here.

Provenance

File details

Details for the file ogs6py-0.30-py2.py3-none-any.whl.

File metadata

  • Download URL: ogs6py-0.30-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.2

File hashes

Hashes for ogs6py-0.30-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 75d5b2b6c2d48b93210d04ffae3a7da40d10bc8c532c0e5fb6df9c1d525011ca
MD5 f976d82bd2f0640c213bff8c110016bb
BLAKE2b-256 e8367859a488b36f51218b36f9b39e713dc74c06d844ea1c5e480f3d4b290494

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page