.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_prjfile/plot_creation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_prjfile_plot_creation.py: How to Create Simple Mechanics Problem ====================================== .. sectionauthor:: Jörg Buchwald (Helmholtz Centre for Environmental Research GmbH - UFZ) The following example consists of a simple mechanics problem. The source file can be found in the [OGS benchmark folder](https://gitlab.opengeosys.org/ogs/ogs/-/blob/master/Tests/Data/Mechanics/Linear/square_1e2.prj?ref_type=heads). The names of the method calls are based on the corresponding XML tags. .. GENERATED FROM PYTHON SOURCE LINES 14-15 Initialize the ogs6py object: .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python import ogstools as ogs from ogstools.definitions import EXAMPLES_DIR prj = ogs.Project(output_file=EXAMPLES_DIR / "prj" / "mechanics_new.prj") .. GENERATED FROM PYTHON SOURCE LINES 22-23 Define geometry and/or meshes: .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python prj.geometry.add_geometry(filename="square_1x1.gml") prj.mesh.add_mesh(filename="square_1x1_quad_1e2.vtu") .. GENERATED FROM PYTHON SOURCE LINES 27-28 Set process and provide process related data: .. GENERATED FROM PYTHON SOURCE LINES 28-42 .. code-block:: Python prj.processes.set_process( name="SD", type="SMALL_DEFORMATION", integration_order="2", specific_body_force="0 0", ) prj.processes.set_constitutive_relation( type="LinearElasticIsotropic", youngs_modulus="E", poissons_ratio="nu" ) prj.processes.add_process_variable( process_variable="process_variable", process_variable_name="displacement" ) prj.processes.add_secondary_variable(internal_name="sigma", output_name="sigma") .. GENERATED FROM PYTHON SOURCE LINES 43-44 Define time stepping and output cycles: .. GENERATED FROM PYTHON SOURCE LINES 44-76 .. code-block:: Python prj.time_loop.add_process( process="SD", nonlinear_solver_name="basic_newton", convergence_type="DeltaX", norm_type="NORM2", abstol="1e-15", time_discretization="BackwardEuler", ) prj.time_loop.set_stepping( process="SD", type="FixedTimeStepping", t_initial="0", t_end="1", repeat="4", delta_t="0.25", ) prj.time_loop.add_output( type="VTK", prefix="blubb", repeat="1", each_steps="10", variables=["displacement", "sigma"], ) prj.media.add_property( medium_id="0", phase_type="Solid", name="density", type="Constant", value="1", ) .. GENERATED FROM PYTHON SOURCE LINES 77-78 Define parameters needed for material properties and BC: .. GENERATED FROM PYTHON SOURCE LINES 78-87 .. code-block:: Python prj.parameters.add_parameter(name="E", type="Constant", value="1") prj.parameters.add_parameter(name="nu", type="Constant", value="0.3") prj.parameters.add_parameter(name="rho_sr", type="Constant", value="1") prj.parameters.add_parameter( name="displacement0", type="Constant", values="0 0" ) prj.parameters.add_parameter(name="dirichlet0", type="Constant", value="0") prj.parameters.add_parameter(name="dirichlet1", type="Constant", value="0.05") .. GENERATED FROM PYTHON SOURCE LINES 88-89 Set initial and boundary conditions: .. GENERATED FROM PYTHON SOURCE LINES 89-120 .. code-block:: Python prj.process_variables.set_ic( process_variable_name="displacement", components="2", order="1", initial_condition="displacement0", ) prj.process_variables.add_bc( process_variable_name="displacement", geometrical_set="square_1x1_geometry", geometry="left", type="Dirichlet", component="0", parameter="dirichlet0", ) prj.process_variables.add_bc( process_variable_name="displacement", geometrical_set="square_1x1_geometry", geometry="bottom", type="Dirichlet", component="1", parameter="dirichlet0", ) prj.process_variables.add_bc( process_variable_name="displacement", geometrical_set="square_1x1_geometry", geometry="top", type="Dirichlet", component="1", parameter="dirichlet1", ) .. GENERATED FROM PYTHON SOURCE LINES 121-122 Set linear and nonlinear solver(s): .. GENERATED FROM PYTHON SOURCE LINES 122-154 .. code-block:: Python prj.nonlinear_solvers.add_non_lin_solver( name="basic_newton", type="Newton", max_iter="4", linear_solver="general_linear_solver", ) prj.linear_solvers.add_lin_solver( name="general_linear_solver", kind="lis", solver_type="cg", precon_type="jacobi", max_iteration_step="10000", error_tolerance="1e-16", ) prj.linear_solvers.add_lin_solver( name="general_linear_solver", kind="eigen", solver_type="CG", precon_type="DIAGONAL", max_iteration_step="10000", error_tolerance="1e-16", ) prj.linear_solvers.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", ) .. GENERATED FROM PYTHON SOURCE LINES 155-156 Write project file to disc: .. GENERATED FROM PYTHON SOURCE LINES 156-158 .. code-block:: Python prj.write_input() .. GENERATED FROM PYTHON SOURCE LINES 159-160 Execute file and pipe output to logfile out.log: .. GENERATED FROM PYTHON SOURCE LINES 160-162 .. code-block:: Python prj.run_model(logfile="out.log") .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /builds/ogs/tools/ogstools/ogstools/examples/prj/mechanics_new.prj. Execution took 0.13594722747802734 s Project file written to output. .. GENERATED FROM PYTHON SOURCE LINES 163-165 If the desired OGS version is not in PATH, a separate path containing the OGS binary can be specified. `model.run_model(path="~/github/ogs/build_mkl/bin")` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.140 seconds) .. _sphx_glr_download_auto_examples_howto_prjfile_plot_creation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_creation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_creation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_creation.zip `