├── .flake8 ├── .github ├── codeql │ └── codeql-config.yml ├── conda │ ├── mpich.yml │ └── openmpi.yml ├── dependabot.yml ├── docker │ └── Dockerfile ├── release.yml └── workflows │ ├── codeql-analysis.yml │ ├── conda_test.yml │ ├── coverage.yml │ ├── docker.yml │ ├── docker_ghcr.yml │ ├── ossar-analysis.yml │ ├── publish.yml │ ├── scorecard.yml │ ├── test_demos.yml │ ├── tests.yml │ ├── tests_macos.yml │ ├── tests_parallel.yml │ └── tests_serial.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .prospector.yaml ├── .pylintrc ├── .readthedocs.yml ├── .zenodo.json ├── CHANGELOG.rst ├── CITATION.cff ├── CODE_OF_CONDUCT.rst ├── CONTRIBUTING.rst ├── COPYING ├── README.rst ├── SECURITY.md ├── cashocs ├── __init__.py ├── _cli │ ├── __init__.py │ ├── _convert.py │ └── _extract_mesh.py ├── _constraints │ ├── __init__.py │ ├── constrained_problems.py │ ├── constraints.py │ └── solvers.py ├── _database │ ├── __init__.py │ ├── database.py │ ├── form_database.py │ ├── function_database.py │ ├── geometry_database.py │ └── parameter_database.py ├── _exceptions.py ├── _forms │ ├── __init__.py │ ├── control_form_handler.py │ ├── form_handler.py │ ├── general_form_handler.py │ ├── shape_form_handler.py │ └── shape_regularization.py ├── _optimization │ ├── __init__.py │ ├── cost_functional.py │ ├── line_search │ │ ├── __init__.py │ │ ├── armijo_line_search.py │ │ ├── line_search.py │ │ └── polynomial_line_search.py │ ├── optimal_control │ │ ├── __init__.py │ │ ├── box_constraints.py │ │ ├── control_variable_abstractions.py │ │ └── optimal_control_problem.py │ ├── optimization_algorithms │ │ ├── __init__.py │ │ ├── callback.py │ │ ├── gradient_descent.py │ │ ├── l_bfgs.py │ │ ├── ncg.py │ │ ├── newton.py │ │ └── optimization_algorithm.py │ ├── optimization_problem.py │ ├── optimization_variable_abstractions.py │ ├── shape_optimization │ │ ├── __init__.py │ │ ├── shape_optimization_problem.py │ │ └── shape_variable_abstractions.py │ └── topology_optimization │ │ ├── __init__.py │ │ ├── bisection.py │ │ ├── descent_topology_algorithm.py │ │ ├── topology_optimization_algorithm.py │ │ ├── topology_optimization_problem.py │ │ └── topology_variable_abstractions.py ├── _pde_problems │ ├── __init__.py │ ├── adjoint_problem.py │ ├── control_gradient_problem.py │ ├── hessian_problems.py │ ├── pde_problem.py │ ├── shape_gradient_problem.py │ └── state_problem.py ├── _typing.py ├── _utils │ ├── __init__.py │ ├── forms.py │ ├── helpers.py │ ├── interpolations.py │ └── linalg.py ├── geometry │ ├── __init__.py │ ├── boundary_distance.py │ ├── deformations.py │ ├── measure.py │ ├── mesh.py │ ├── mesh_handler.py │ ├── mesh_testing.py │ └── quality.py ├── io │ ├── __init__.py │ ├── config.py │ ├── function.py │ ├── managers.py │ ├── mesh.py │ └── output.py ├── log.py ├── mpi.py ├── nonlinear_solvers │ ├── __init__.py │ ├── linear_solver.py │ ├── newton_solver.py │ ├── picard_solver.py │ ├── snes.py │ └── ts.py ├── space_mapping │ ├── __init__.py │ ├── optimal_control.py │ └── shape_optimization.py └── verification.py ├── demos ├── documented │ ├── cashocs_as_solver │ │ ├── control_solver │ │ │ ├── config.ini │ │ │ ├── demo_control_solver.py │ │ │ └── img_control_solver.png │ │ └── shape_solver │ │ │ ├── config.ini │ │ │ ├── demo_shape_solver.py │ │ │ ├── img_shape_solver.png │ │ │ ├── mesh │ │ │ ├── mesh.geo │ │ │ ├── mesh.h5 │ │ │ ├── mesh.msh │ │ │ ├── mesh.xdmf │ │ │ ├── mesh_boundaries.h5 │ │ │ └── mesh_boundaries.xdmf │ │ │ └── results │ │ │ └── history.txt │ ├── misc │ │ ├── logging │ │ │ └── demo_logging.py │ │ ├── mpi_comm_self │ │ │ ├── config.ini │ │ │ ├── demo_mpi_comm_self.py │ │ │ ├── img_rank_0.png │ │ │ ├── img_rank_1.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── mpi_custom │ │ │ ├── config.ini │ │ │ ├── demo_mpi_custom.py │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ └── xdmf_io │ │ │ ├── config.ini │ │ │ ├── demo_xdmf_io.py │ │ │ ├── img_shape_gradient.png │ │ │ ├── img_states.png │ │ │ └── mesh │ │ │ ├── mesh.geo │ │ │ ├── mesh.h5 │ │ │ ├── mesh.msh │ │ │ ├── mesh.xdmf │ │ │ ├── mesh_boundaries.h5 │ │ │ └── mesh_boundaries.xdmf │ ├── optimal_control │ │ ├── box_constraints │ │ │ ├── config.ini │ │ │ ├── demo_box_constraints.py │ │ │ └── img_box_constraints.png │ │ ├── constraints │ │ │ ├── config.ini │ │ │ ├── demo_constraints.py │ │ │ └── img_constraints.png │ │ ├── control_boundary_conditions │ │ │ ├── config.ini │ │ │ ├── demo_control_boundary_conditions.py │ │ │ └── img_control_boundary_conditions.png │ │ ├── dirichlet_control │ │ │ ├── config.ini │ │ │ ├── demo_dirichlet_control.py │ │ │ └── img_dirichlet_control.png │ │ ├── heat_equation │ │ │ ├── config.ini │ │ │ └── demo_heat_equation.py │ │ ├── iterative_solvers │ │ │ ├── config.ini │ │ │ ├── demo_iterative_solvers.py │ │ │ └── img_iterative_solvers.png │ │ ├── monolithic_problems │ │ │ ├── config.ini │ │ │ ├── demo_monolithic_problems.py │ │ │ └── img_monolithic_problems.png │ │ ├── multiple_variables │ │ │ ├── config.ini │ │ │ ├── demo_multiple_variables.py │ │ │ └── img_multiple_variables.png │ │ ├── neumann_control │ │ │ ├── config.ini │ │ │ ├── demo_neumann_control.py │ │ │ └── img_neumann_control.png │ │ ├── nonlinear_pdes │ │ │ ├── config.ini │ │ │ ├── demo_nonlinear_pdes.py │ │ │ └── img_nonlinear_pdes.png │ │ ├── picard_iteration │ │ │ ├── config.ini │ │ │ ├── demo_picard_iteration.py │ │ │ └── img_picard_iteration.png │ │ ├── poisson │ │ │ ├── config.ini │ │ │ ├── demo_poisson.py │ │ │ ├── img_poisson.png │ │ │ └── results │ │ │ │ ├── history.json │ │ │ │ └── history.txt │ │ ├── pre_post_callbacks │ │ │ ├── config.ini │ │ │ ├── demo_pre_post_callbacks.py │ │ │ └── img_pre_post_callbacks.png │ │ ├── scalar_control_tracking │ │ │ ├── config.ini │ │ │ ├── demo_scalar_control_tracking.py │ │ │ └── img_scalar_control_tracking.png │ │ ├── sparse_control │ │ │ ├── config.ini │ │ │ ├── demo_sparse_control.py │ │ │ └── img_sparse_control.png │ │ ├── state_constraints │ │ │ ├── config.ini │ │ │ ├── demo_state_constraints.py │ │ │ └── img_state_constraints.png │ │ └── stokes │ │ │ ├── config.ini │ │ │ ├── demo_stokes.py │ │ │ └── img_stokes.png │ ├── shape_optimization │ │ ├── custom_scalar_product │ │ │ ├── config.ini │ │ │ ├── demo_custom_scalar_product.py │ │ │ ├── img_custom_scalar_product.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── inverse_tomography │ │ │ ├── config.ini │ │ │ ├── demo_inverse_tomography.py │ │ │ ├── img_inverse_tomography.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ ├── mesh_boundaries.xdmf │ │ │ │ ├── reference.geo │ │ │ │ ├── reference.h5 │ │ │ │ ├── reference.msh │ │ │ │ ├── reference.xdmf │ │ │ │ ├── reference_boundaries.h5 │ │ │ │ └── reference_boundaries.xdmf │ │ ├── p_laplacian │ │ │ ├── config.ini │ │ │ ├── demo_p_laplacian.py │ │ │ ├── img_p_laplacian.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── prescribed_mu │ │ │ ├── config.ini │ │ │ ├── demo_prescribed_mu.py │ │ │ ├── img_prescribed_mu.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── pseudo_time_stepping │ │ │ ├── config.ini │ │ │ ├── demo_pseudo_time_stepping.py │ │ │ ├── img_pseudo_time_stepping.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── regularization │ │ │ ├── config.ini │ │ │ ├── demo_regularization.py │ │ │ ├── img_regularization.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── remeshing │ │ │ ├── config.ini │ │ │ ├── demo_remeshing.py │ │ │ ├── img_remeshing.png │ │ │ └── mesh │ │ │ │ ├── cashocs_remesh │ │ │ │ ├── mesh_0.msh │ │ │ │ ├── mesh_1.h5 │ │ │ │ ├── mesh_1.msh │ │ │ │ ├── mesh_1.xdmf │ │ │ │ ├── mesh_1_boundaries.h5 │ │ │ │ ├── mesh_1_boundaries.xdmf │ │ │ │ └── remesh.geo │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── scaling │ │ │ ├── config.ini │ │ │ ├── demo_scaling.py │ │ │ ├── img_scaling.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── shape_poisson │ │ │ ├── config.ini │ │ │ ├── demo_shape_poisson.py │ │ │ ├── img_shape_poisson.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── shape_stokes │ │ │ ├── config.ini │ │ │ ├── demo_shape_stokes.py │ │ │ ├── img_shape_stokes.png │ │ │ └── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ └── mesh_boundaries.xdmf │ │ ├── space_mapping_semilinear_transmission │ │ │ ├── config.ini │ │ │ ├── demo_space_mapping_semilinear_transmission.py │ │ │ ├── img_space_mapping_semilinear_transmission.png │ │ │ ├── mesh │ │ │ │ ├── mesh.geo │ │ │ │ ├── mesh.h5 │ │ │ │ ├── mesh.msh │ │ │ │ ├── mesh.xdmf │ │ │ │ ├── mesh_boundaries.h5 │ │ │ │ ├── mesh_boundaries.xdmf │ │ │ │ ├── reference.geo │ │ │ │ ├── reference.h5 │ │ │ │ ├── reference.msh │ │ │ │ ├── reference.xdmf │ │ │ │ ├── reference_boundaries.h5 │ │ │ │ └── reference_boundaries.xdmf │ │ │ └── sm_history.json │ │ └── space_mapping_uniform_flow_distribution │ │ │ ├── config.ini │ │ │ ├── demo_space_mapping_uniform_flow_distribution.py │ │ │ ├── img_space_mapping_uniform_flow_distribution.png │ │ │ ├── mesh │ │ │ ├── fine.geo │ │ │ ├── mesh.geo │ │ │ ├── mesh.h5 │ │ │ ├── mesh.msh │ │ │ ├── mesh.xdmf │ │ │ ├── mesh_boundaries.h5 │ │ │ └── mesh_boundaries.xdmf │ │ │ ├── reference_pipe.png │ │ │ └── sm_history.json │ └── topology_optimization │ │ ├── cantilever │ │ ├── config.ini │ │ ├── demo_cantilever.py │ │ └── img_cantilever.png │ │ ├── pipe_bend │ │ ├── config.ini │ │ ├── demo_pipe_bend.py │ │ └── img_pipe_bend.png │ │ ├── poisson_clover │ │ ├── config.ini │ │ ├── demo_poisson_clover.py │ │ └── img_poisson_clover.png │ │ └── projection │ │ ├── config.ini │ │ ├── demo_projection.py │ │ └── img_projection.png ├── test.py ├── test_mpi.py └── undocumented │ ├── optimal_control │ ├── different_state_adjoint_spaces │ │ ├── config.ini │ │ ├── demo_different_state_adjoint_spaces.py │ │ ├── history.json │ │ └── results │ │ │ ├── history.json │ │ │ └── history.txt │ └── dirichlet_control_via_lagrange_multiplier │ │ ├── config.ini │ │ ├── demo_dirichlet_control_via_lagrange_multiplier.py │ │ └── img_dirichlet_control_via_lagrange_multiplier.png │ ├── shape_optimization │ ├── custom_functional │ │ ├── config.ini │ │ ├── custom_functional.py │ │ └── mesh │ │ │ ├── mesh.geo │ │ │ ├── mesh.h5 │ │ │ ├── mesh.msh │ │ │ ├── mesh.xdmf │ │ │ ├── mesh_boundaries.h5 │ │ │ └── mesh_boundaries.xdmf │ ├── pipe_optimization │ │ ├── config.ini │ │ ├── history.json │ │ ├── history.txt │ │ ├── mesh │ │ │ ├── mesh.geo │ │ │ ├── mesh.h5 │ │ │ ├── mesh.msh │ │ │ ├── mesh.xdmf │ │ │ ├── mesh_boundaries.h5 │ │ │ └── mesh_boundaries.xdmf │ │ ├── pipe_optimization.py │ │ └── results │ │ │ ├── history.json │ │ │ └── history.txt │ └── python_pc │ │ └── python_pc.py │ └── solvers │ └── fieldsplit_nesting.py ├── docs ├── Makefile ├── make.bat ├── requirements.txt └── source │ ├── _static │ ├── cashocs.css │ ├── favicon │ │ ├── favicon-16x16.jpg │ │ └── favicon-32x32.jpg │ └── version_switcher.json │ ├── _templates │ └── autosummary │ │ ├── class.rst │ │ └── module.rst │ ├── about │ ├── citing.rst │ ├── contact.rst │ ├── index.rst │ ├── installation.rst │ ├── license.rst │ └── nutshell.rst │ ├── api │ └── index.rst │ ├── cashocs_banner.jpg │ ├── cli │ ├── generated │ │ ├── cashocs._cli._convert.rst │ │ └── cashocs._cli._extract_mesh.rst │ └── index.rst │ ├── conf.py │ ├── development │ ├── code_of_conduct.rst │ ├── contributing.rst │ └── index.rst │ ├── document_cli.py │ ├── docutils.conf │ ├── global.rst │ ├── icons │ ├── api.svg │ ├── development.svg │ ├── getting_started.svg │ └── user_guide.svg │ ├── index.rst │ ├── jupytext_process.py │ ├── logo.jpg │ ├── release_notes.rst │ └── user │ ├── demos │ ├── cashocs_as_solver │ │ └── index.rst │ ├── misc │ │ └── index.rst │ ├── optimal_control │ │ ├── doc_config.rst │ │ └── index.rst │ ├── shape_optimization │ │ ├── doc_config.rst │ │ └── index.rst │ └── topology_optimization │ │ ├── doc_config.rst │ │ └── index.rst │ └── index.rst ├── logos ├── cashocs_banner.jpg └── logo.jpg ├── pyproject.toml └── tests ├── config_ocp.ini ├── config_ocsm.ini ├── config_picard.ini ├── config_remesh.ini ├── config_sop.ini ├── config_sosm.ini ├── config_top.ini ├── conftest.py ├── mesh ├── mesh.geo ├── mesh.msh ├── mesh3.geo ├── mesh3.msh ├── named_mesh.geo ├── named_mesh.msh ├── physical_names_legacy │ ├── named_mesh.h5 │ ├── named_mesh.msh │ ├── named_mesh.xdmf │ ├── named_mesh_boundaries.h5 │ ├── named_mesh_boundaries.xdmf │ ├── named_mesh_physical_groups.json │ ├── named_mesh_subdomains.h5 │ └── named_mesh_subdomains.xdmf ├── remesh │ ├── mesh.geo │ ├── mesh.h5 │ ├── mesh.msh │ ├── mesh.xdmf │ ├── mesh_boundaries.h5 │ └── mesh_boundaries.xdmf └── unit_circle │ ├── mesh.geo │ ├── mesh.h5 │ ├── mesh.msh │ ├── mesh.xdmf │ ├── mesh_boundaries.h5 │ └── mesh_boundaries.xdmf ├── sm_mesh ├── mesh.geo ├── mesh.h5 ├── mesh.msh ├── mesh.xdmf ├── mesh_boundaries.h5 └── mesh_boundaries.xdmf ├── test_cli.py ├── test_config.ini ├── test_config.py ├── test_control_constraints.py ├── test_exceptions.py ├── test_fieldsplit.py ├── test_geometry.py ├── test_nonlinear_solvers.py ├── test_optimal_control.py ├── test_optimal_control_multiple.py ├── test_optimal_control_space_mapping.py ├── test_output.py ├── test_p_laplacian.py ├── test_pde_problems.py ├── test_picard_iterations.py ├── test_remeshing.py ├── test_shape_constraints.py ├── test_shape_optimization.py ├── test_shape_optimization_space_mapping.py ├── test_topology_optimization.py ├── test_utils.py └── xdmf_state ├── state_0.h5 └── state_0.xdmf /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | max-complexity = 10 -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | name: "cashocs CodeQL config" 2 | 3 | 4 | queries: 5 | - uses: security-and-quality 6 | 7 | paths: 8 | - cashocs 9 | -------------------------------------------------------------------------------- /.github/conda/mpich.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - numpy 6 | - fenics=2019 7 | - meshio>=5.3 8 | - pytest 9 | - matplotlib 10 | - gmsh>=4.8 11 | - scipy 12 | - mpich 13 | -------------------------------------------------------------------------------- /.github/conda/openmpi.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - numpy 6 | - fenics=2019 7 | - meshio>=5.3 8 | - pytest 9 | - matplotlib 10 | - gmsh>=4.8 11 | - scipy 12 | - openmpi 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | day: "monday" 13 | time: "03:00" 14 | timezone: Europe/Berlin 15 | assignees: 16 | - "sblauth" 17 | 18 | - package-ecosystem: "pip" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "monday" 23 | time: "03:00" 24 | timezone: Europe/Berlin 25 | allow: 26 | - dependency-type: "all" 27 | assignees: 28 | - "sblauth" 29 | -------------------------------------------------------------------------------- /.github/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mambaorg/micromamba:1-jammy AS test-env 2 | 3 | USER root 4 | 5 | RUN apt-get update --fix-missing && \ 6 | apt-get install -y libgl1-mesa-dev ffmpeg libsm6 libxext6 curl git gpg jq && \ 7 | apt-get clean && \ 8 | rm -rf /var/lib/apt/lists/* 9 | 10 | USER $MAMBA_USER 11 | 12 | RUN micromamba install -y -n base -c conda-forge \ 13 | fenics=2019 \ 14 | meshio">=5.3" \ 15 | pytest \ 16 | gmsh">=4.8" \ 17 | coverage \ 18 | mpich \ 19 | scipy \ 20 | python=3.13 && \ 21 | micromamba clean --all --yes 22 | 23 | ARG MAMBA_DOCKERFILE_ACTIVATE=1 24 | 25 | FROM test-env AS cashocs 26 | 27 | COPY --chown=$MAMBA_USER:$MAMBA_USER . /home/mambauser/cashocs 28 | 29 | RUN cd /home/mambauser/cashocs && \ 30 | pip install .[all] 31 | 32 | RUN cd /home/mambauser/cashocs && \ 33 | python3 -m pytest -vv tests/ 34 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | authors: 4 | - snyk-bot 5 | categories: 6 | - title: New Features and Improvements 7 | labels: 8 | - enhancement 9 | - title: Bug Fixes 10 | labels: 11 | - bug 12 | - title: Configuration changes 13 | labels: 14 | - config 15 | - title: Changes to the documentation 16 | labels: 17 | - documentation 18 | -------------------------------------------------------------------------------- /.github/workflows/conda_test.yml: -------------------------------------------------------------------------------- 1 | name: Test conda installation 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '42 23 * * *' 7 | 8 | permissions: read-all 9 | 10 | jobs: 11 | conda_test: 12 | name: Test conda installation 13 | strategy: 14 | matrix: 15 | os: [ubuntu-latest, macos-13] 16 | fail-fast: false 17 | runs-on: ${{ matrix.os }} 18 | defaults: 19 | run: 20 | shell: bash -el {0} 21 | 22 | steps: 23 | - name: Setup conda 24 | uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 25 | with: 26 | miniforge-version: latest 27 | auto-activate-base: true 28 | auto-update-conda: true 29 | conda-remove-defaults: true 30 | 31 | - name: Install cashocs 32 | run: conda create -n cashocs cashocs python=3.13 33 | 34 | - name: Test if package was installed properly 35 | run: | 36 | conda run -n cashocs python -c "import cashocs; cashocs.regular_mesh(16)" 37 | conda run -n cashocs mpirun -n 2 python -c "import cashocs; cashocs.regular_mesh(16)" 38 | 39 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Post coverage comment 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["Tests"] 6 | types: 7 | - completed 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | test: 13 | name: Run tests & display coverage 14 | runs-on: ubuntu-latest 15 | if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' 16 | permissions: 17 | # Gives the action the necessary permissions for publishing new 18 | # comments in pull requests. 19 | pull-requests: write 20 | # Gives the action the necessary permissions for editing existing 21 | # comments (to avoid publishing multiple comments in the same PR) 22 | contents: write 23 | # Gives the action the necessary permissions for looking up the 24 | # workflow that launched this workflow, and download the related 25 | # artifact that contains the comment to be published 26 | actions: read 27 | steps: 28 | # DO NOT run actions/checkout here, for security reasons 29 | # For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ 30 | - name: Post comment 31 | uses: py-cov-action/python-coverage-comment-action@970a227e0c16ef4589a99a9970ab0ceb8c53059a # v3.34 32 | with: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} 35 | COVERAGE_DATA_BRANCH: coverage 36 | # Update those if you changed the default values: 37 | # COMMENT_ARTIFACT_NAME: python-coverage-comment-action 38 | # COMMENT_FILENAME: python-coverage-comment-action.txt 39 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker images 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | tags: 7 | - 'v*' 8 | schedule: 9 | - cron: '17 21 * * *' 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | build_test_env: 15 | name: Build sblauth/cashocs-test-env image 16 | runs-on: ubuntu-latest 17 | outputs: 18 | TAG_PREFIX: ${{ steps.tag_name.outputs.TAG_PREFIX }} 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 22 | 23 | - name: Get tag name 24 | id: tag_name 25 | run: | 26 | if [[ ${GITHUB_REF#refs/tags/} == v* ]] 27 | then 28 | echo "TAG_PREFIX=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT 29 | else 30 | echo "TAG_PREFIX=latest" >> $GITHUB_OUTPUT 31 | fi 32 | 33 | - name: Log into the Dockerhub registry 34 | run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin 35 | 36 | - name: Build the Docker image 37 | run: | 38 | docker buildx build --push \ 39 | --no-cache \ 40 | --cache-to=type=inline,mode=max --file ./.github/docker/Dockerfile \ 41 | --target=test-env \ 42 | --tag sblauth/cashocs-test-env:${{ steps.tag_name.outputs.TAG_PREFIX }} . 43 | 44 | 45 | build_user_image: 46 | name: Build sblauth/cashocs image 47 | needs: 48 | - build_test_env 49 | runs-on: ubuntu-latest 50 | steps: 51 | - name: Checkout repository 52 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 53 | 54 | - name: Log into the Dockerhub registry 55 | run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin 56 | 57 | - name: Build the Docker image 58 | run: | 59 | docker buildx build --push \ 60 | --no-cache \ 61 | --cache-to=type=inline,mode=max --file ./.github/docker/Dockerfile \ 62 | --target=cashocs \ 63 | --tag sblauth/cashocs:${{ needs.build_test_env.outputs.TAG_PREFIX }} . 64 | 65 | -------------------------------------------------------------------------------- /.github/workflows/docker_ghcr.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | # GitHub recommends pinning actions to a commit SHA. 7 | # To get a newer version, you will need to update the SHA. 8 | # You can also reference a tag or branch, but the action may change without warning. 9 | 10 | name: ghcr.io images 11 | 12 | on: 13 | workflow_dispatch: 14 | push: 15 | tags: 16 | - 'v*' 17 | schedule: 18 | - cron: '17 21 * * *' 19 | 20 | permissions: read-all 21 | 22 | env: 23 | REGISTRY: ghcr.io 24 | IMAGE_NAME: ${{ github.repository }} 25 | 26 | jobs: 27 | build-and-push-image: 28 | runs-on: ubuntu-latest 29 | permissions: 30 | contents: read 31 | packages: write 32 | 33 | steps: 34 | - name: Checkout repository 35 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 36 | 37 | - name: Log in to the Container registry 38 | uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 39 | with: 40 | registry: ${{ env.REGISTRY }} 41 | username: ${{ github.actor }} 42 | password: ${{ secrets.GITHUB_TOKEN }} 43 | 44 | - name: Extract metadata (tags, labels) for Docker 45 | id: meta 46 | uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 47 | with: 48 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 49 | tags: | 50 | type=ref,event=branch 51 | type=ref,event=pr 52 | type=semver,pattern={{version}} 53 | type=semver,pattern={{major}}.{{minor}} 54 | 55 | - name: Build and push Docker image 56 | uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 57 | with: 58 | context: . 59 | file: ./.github/docker/Dockerfile 60 | push: ${{ github.event_name != 'pull_request' }} 61 | tags: ${{ steps.meta.outputs.tags }} 62 | labels: ${{ steps.meta.outputs.labels }} 63 | -------------------------------------------------------------------------------- /.github/workflows/ossar-analysis.yml: -------------------------------------------------------------------------------- 1 | # This workflow integrates a collection of open source static analysis tools 2 | # with GitHub code scanning. For documentation, or to provide feedback, visit 3 | # https://github.com/github/ossar-action 4 | name: OSSAR 5 | 6 | on: 7 | push: 8 | workflow_dispatch: 9 | pull_request: 10 | schedule: 11 | - cron: '37 22 * * *' 12 | 13 | permissions: read-all 14 | 15 | jobs: 16 | OSSAR-Scan: 17 | # OSSAR runs on windows-latest. 18 | # ubuntu-latest and macos-latest support coming soon 19 | runs-on: windows-latest 20 | permissions: 21 | security-events: write 22 | 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 26 | 27 | # Ensure a compatible version of dotnet is installed. 28 | # The [Microsoft Security Code Analysis CLI](https://aka.ms/mscadocs) is built with dotnet v3.1.201. 29 | # A version greater than or equal to v3.1.201 of dotnet must be installed on the agent in order to run this action. 30 | # GitHub hosted runners already have a compatible version of dotnet installed and this step may be skipped. 31 | # For self-hosted runners, ensure dotnet version 3.1.201 or later is installed by including this action: 32 | # - name: Install .NET 33 | # uses: actions/setup-dotnet@v1 34 | # with: 35 | # dotnet-version: '3.1.x' 36 | 37 | # Run open source static analysis tools 38 | - name: Run OSSAR 39 | uses: github/ossar-action@786a16a90ba92b4ae6228fe7382fb16ef5c51000 # v1 40 | id: ossar 41 | 42 | # Upload results to the Security tab 43 | - name: Upload OSSAR results 44 | uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19 45 | with: 46 | sarif_file: ${{ steps.ossar.outputs.sarifFile }} 47 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | schedule: 8 | - cron: '17 22 * * *' 9 | 10 | permissions: read-all 11 | 12 | env: 13 | OMP_NUM_THREADS: 2 14 | 15 | jobs: 16 | tests: 17 | name: Tests 18 | permissions: 19 | # Gives the action the necessary permissions for publishing new 20 | # comments in pull requests. 21 | pull-requests: write 22 | # Gives the action the necessary permissions for pushing data to the 23 | # python-coverage-comment-action branch, and for editing existing 24 | # comments (to avoid publishing multiple comments in the same PR) 25 | contents: write 26 | runs-on: ubuntu-latest 27 | container: 28 | image: ghcr.io/sblauth/cashocs:main 29 | options: --user=root 30 | 31 | steps: 32 | - name: Delete current installation in docker image 33 | shell: bash 34 | run: | 35 | source /usr/local/bin/_entrypoint.sh 36 | pip uninstall -y cashocs 37 | rm -R /home/mambauser/cashocs 38 | 39 | - name: Checkout repository 40 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 41 | 42 | - name: Install cashocs 43 | shell: bash 44 | run: | 45 | source /usr/local/bin/_entrypoint.sh 46 | pip install .[all] 47 | 48 | - name: Run tests 49 | shell: bash 50 | run: | 51 | source /usr/local/bin/_entrypoint.sh 52 | python3 -m pytest -vv --cov=cashocs --cov-report=xml tests/ 53 | 54 | - name: Coverage comment 55 | id: coverage_comment 56 | uses: py-cov-action/python-coverage-comment-action@970a227e0c16ef4589a99a9970ab0ceb8c53059a # v3.34 57 | with: 58 | GITHUB_TOKEN: ${{ github.token }} 59 | COVERAGE_DATA_BRANCH: coverage 60 | MINIMUM_GREEN: 85 61 | MINIMUM_ORANGE: 70 62 | 63 | - name: Store Pull Request comment to be posted 64 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 65 | if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' 66 | with: 67 | # If you use a different name, update COMMENT_ARTIFACT_NAME accordingly 68 | name: python-coverage-comment-action 69 | # If you use a different name, update COMMENT_FILENAME accordingly 70 | path: python-coverage-comment-action.txt 71 | -------------------------------------------------------------------------------- /.github/workflows/tests_macos.yml: -------------------------------------------------------------------------------- 1 | name: Tests (macos, serial) 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '17 0 * * *' 7 | 8 | permissions: read-all 9 | 10 | jobs: 11 | serial_tests: 12 | name: Test (py=${{ matrix.python-version}}, macos-13) 13 | runs-on: macos-13 14 | defaults: 15 | run: 16 | shell: bash -el {0} 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 21 | 22 | steps: 23 | - name: Checkout repository 24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 25 | 26 | - name: Create conda environment 27 | uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 28 | with: 29 | environment-file: .github/conda/mpich.yml 30 | miniforge-version: latest 31 | python-version: ${{ matrix.python-version }} 32 | activate-environment: test 33 | auto-activate-base: false 34 | conda-remove-defaults: true 35 | 36 | - name: Show conda info 37 | run: conda info 38 | 39 | - name: Show list of all installed packages 40 | run: conda list 41 | 42 | - name: Install package 43 | run: | 44 | pip install .[all] 45 | 46 | - name: Run tests 47 | env: 48 | OMP_NUM_THREADS: 2 49 | run: | 50 | python3 -m pytest -vv tests/ 51 | 52 | -------------------------------------------------------------------------------- /.github/workflows/tests_parallel.yml: -------------------------------------------------------------------------------- 1 | name: Tests (ubuntu, parallel) 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | schedule: 7 | - cron: '03 22 * * *' 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | parallel_tests: 13 | name: Test (py=${{ matrix.python-version}}, ${{ matrix.mpi }}) 14 | runs-on: ubuntu-latest 15 | defaults: 16 | run: 17 | shell: bash -el {0} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 22 | mpi: [mpich, openmpi] 23 | 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 27 | 28 | - name: Create conda environment 29 | uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 30 | with: 31 | environment-file: .github/conda/${{ matrix.mpi }}.yml 32 | miniforge-version: latest 33 | python-version: ${{ matrix.python-version }} 34 | activate-environment: test 35 | auto-activate-base: false 36 | conda-remove-defaults: true 37 | 38 | - name: Show conda info 39 | run: conda info 40 | 41 | - name: Show list of all installed packages 42 | run: conda list 43 | 44 | - name: Install package 45 | run: | 46 | pip install .[all] 47 | 48 | - name: Run tests in parallel 49 | env: 50 | OMP_NUM_THREADS: 1 51 | run: | 52 | mpirun -n 2 python3 -m pytest -vv --timeout=1800 -p no:cacheprovider --randomly-seed=${{ github.run_id }} tests/ 53 | -------------------------------------------------------------------------------- /.github/workflows/tests_serial.yml: -------------------------------------------------------------------------------- 1 | name: Tests (ubuntu, serial) 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | schedule: 7 | - cron: '17 22 * * *' 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | serial_tests: 13 | name: Test (py=${{ matrix.python-version}}, ubuntu-latest) 14 | runs-on: ubuntu-latest 15 | defaults: 16 | run: 17 | shell: bash -el {0} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] 22 | 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 26 | 27 | - name: Create conda environment 28 | uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 29 | with: 30 | environment-file: .github/conda/mpich.yml 31 | miniforge-version: latest 32 | python-version: ${{ matrix.python-version }} 33 | activate-environment: test 34 | auto-activate-base: false 35 | conda-remove-defaults: true 36 | 37 | - name: Show conda info 38 | run: conda info 39 | 40 | - name: Show list of all installed packages 41 | run: conda list 42 | 43 | - name: Install package 44 | run: | 45 | pip install .[all] 46 | 47 | - name: Run tests 48 | env: 49 | OMP_NUM_THREADS: 2 50 | run: | 51 | python3 -m pytest -vv tests/ 52 | 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### python 2 | __pycache__/ 3 | *.pyc 4 | .pytest_cache/ 5 | .coverage 6 | coverage.xml 7 | htmlcov 8 | *.orig 9 | .ruff_cache 10 | 11 | ### paraview 12 | *.pvd 13 | *.vtu 14 | *.pvtu 15 | 16 | **/checkpoints/ 17 | **/xdmf/ 18 | 19 | ### pip 20 | /build 21 | /dist 22 | cashocs.egg-info/ 23 | 24 | ### sphinx 25 | /docs/build 26 | /docs/source/api/generated 27 | 28 | ### cashocs 29 | *._cashocs_remesh_* 30 | /tests/temp 31 | /tests/out 32 | *cashocs_remesh_*/ 33 | 34 | ### Documentation 35 | docs/source/user/demos/*/*.md 36 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | default_language_version: 2 | python: python3.11 3 | 4 | repos: 5 | - repo: https://github.com/regebro/pyroma 6 | rev: "4.2" 7 | hooks: 8 | - id: pyroma 9 | - repo: https://github.com/psf/black 10 | rev: 25.1.0 11 | hooks: 12 | - id: black 13 | - repo: https://github.com/PyCQA/isort 14 | rev: 6.0.1 15 | hooks: 16 | - id: isort 17 | - repo: https://github.com/PyCQA/pydocstyle 18 | rev: 6.3.0 19 | hooks: 20 | - id: pydocstyle 21 | additional_dependencies: ["tomli"] 22 | files: cashocs/ 23 | - repo: https://github.com/PyCQA/flake8 24 | rev: 7.2.0 25 | hooks: 26 | - id: flake8 27 | files: cashocs/ 28 | - repo: https://github.com/PyCQA/bandit 29 | rev: 1.8.3 30 | hooks: 31 | - id: bandit 32 | files: cashocs/ 33 | - repo: https://github.com/PyCQA/pylint 34 | rev: v3.3.7 35 | hooks: 36 | - id: pylint 37 | files: cashocs/ 38 | - repo: https://github.com/pre-commit/mirrors-mypy 39 | rev: v1.16.0 40 | hooks: 41 | - id: mypy 42 | files: cashocs/ 43 | additional_dependencies: ["numpy"] 44 | args: [--config-file, pyproject.toml] 45 | - repo: https://github.com/PyCQA/prospector 46 | rev: v1.17.1 47 | hooks: 48 | - id: prospector 49 | additional_dependencies: 50 | - ".[with_mypy,with_bandit,with_pyroma]" 51 | files: cashocs/ 52 | 53 | - repo: https://github.com/astral-sh/ruff-pre-commit 54 | # Ruff version. 55 | rev: v0.11.13 56 | hooks: 57 | # Run the linter. 58 | - id: ruff 59 | files: cashocs/ 60 | -------------------------------------------------------------------------------- /.prospector.yaml: -------------------------------------------------------------------------------- 1 | output-format: grouped 2 | 3 | inherits: 4 | - strictness_veryhigh 5 | strictness: veryhigh 6 | test-warnings: true 7 | doc-warnings: true 8 | member-warnings: true 9 | ignore-paths: 10 | - docs 11 | ignore-patterns: 12 | - (^|/)skip(this)?(/|$) 13 | autodetect: true 14 | max-line-length: 88 15 | 16 | bandit: 17 | run: false 18 | 19 | dodgy: 20 | run: true 21 | 22 | frosted: 23 | run: false 24 | 25 | mccabe: 26 | run: true 27 | options: 28 | max-complexity: 10 29 | 30 | pep8: 31 | run: true 32 | options: 33 | max-line-length: 88 34 | disable: 35 | - N803 36 | - N806 37 | - N815 38 | 39 | pep257: 40 | run: true 41 | disable: 42 | - D203 43 | - D204 44 | - D213 45 | - D215 46 | - D400 47 | - D401 48 | - D404 49 | - D406 50 | - D407 51 | - D408 52 | - D409 53 | 54 | pyflakes: 55 | run: true 56 | 57 | pylint: 58 | run: false 59 | 60 | pyroma: 61 | run: false 62 | 63 | mypy: 64 | run: false 65 | 66 | vulture: 67 | run: false 68 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: ubuntu-24.04 5 | tools: 6 | python: "3.13" 7 | 8 | sphinx: 9 | configuration: docs/source/conf.py 10 | builder: dirhtml 11 | fail_on_warning: true 12 | 13 | formats: 14 | - pdf 15 | 16 | python: 17 | install: 18 | - requirements: docs/requirements.txt 19 | -------------------------------------------------------------------------------- /.zenodo.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "

cashocs is a computational, adjoint-based shape optimization and optimal control software.

", 3 | "license": "GPL-3.0+", 4 | "title": "cashocs v2.6.0-dev", 5 | "version": "v2.6.0-dev", 6 | "upload_type": "software", 7 | "creators": [ 8 | { 9 | "orcid": "0000-0001-9173-0866", 10 | "name": "Sebastian Blauth" 11 | } 12 | ], 13 | "access_right": "open" 14 | } 15 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Blauth" 5 | given-names: "Sebastian" 6 | orcid: "https://orcid.org/ 0000-0001-9173-0866" 7 | title: "cashocs: A Computational, Adjoint-Based Shape Optimization and Optimal Control Software" 8 | doi: 10.5281/zenodo.4035939 9 | url: "https://github.com/sblauth/cashocs" 10 | preferred-citation: 11 | type: article 12 | authors: 13 | - family-names: "Blauth" 14 | given-names: "Sebastian" 15 | orcid: "https://orcid.org/ 0000-0001-9173-0866" 16 | doi: "10.1016/j.softx.2020.100646" 17 | journal: "SoftwareX" 18 | month: 1 19 | start: 1 20 | end: 7 21 | title: "cashocs: A Computational, Adjoint-Based Shape Optimization and Optimal Control Software" 22 | volume: 13 23 | year: 2021 -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | Contributing Guidelines 2 | ======================= 3 | 4 | First off, thanks a lot for taking the time to contribute to cashocs. 5 | 6 | Code of conduct 7 | --------------- 8 | 9 | The project and everyone that participates in it is governed by the :ref:`cashocs 10 | Code of Conduct `. In particular, this also applies to all 11 | interactions with the project, including issues and pull requests. 12 | 13 | 14 | 15 | Reporting a bug 16 | --------------- 17 | 18 | - Ensure that the bug was not already reported by searching on GitHub under 19 | `Issues `_. 20 | 21 | - If you do not find an open issue that adresses the problem, open a new one. 22 | Please include a clear title and description, and include as much relevant 23 | information as possible, and also a minimal working example that reproduces 24 | the bug. 25 | 26 | 27 | 28 | Fixing a bug 29 | ------------ 30 | 31 | - cashocs uses the `black coding style `_, so please also use that for your suggested fix. 32 | 33 | - Make sure that all tests still pass with your fix. 34 | 35 | - Open a new pull request with the fix. Ensure that the PR description clearly 36 | describes the problem and its solution. Include the corresponding issue number (if applicable). 37 | 38 | 39 | 40 | Adding or modifying a feature 41 | ----------------------------- 42 | 43 | - Please suggest your changes / additions by opening a new issue on GitHub under 44 | `Issues `_, and start writing code (using the conventions 45 | established in the project). 46 | 47 | - If you receive positive feedback for your suggestion, you can open a new pull 48 | request with the changes / additions. Ensure that the PR description clearly 49 | describes your modifications / additions, also reference the corresponding 50 | issue number where you suggested your idea. 51 | 52 | 53 | License 54 | ------- 55 | 56 | By submitting a pull request, you are licensing your code under the project 57 | :ref:`license ` and affirming that you either own copyright (automatic 58 | for most individuals) or are authorized to distribute under the project license 59 | (e.g., in case your employer retains copyright on your work). 60 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security 2 | 3 | The cashocs developers take the security of cashocs seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. 4 | 5 | ## Reporting Security Issues 6 | 7 | To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/sblauth/cashocs/security/advisories/new) tab. 8 | 9 | **Please do not report security vulnerabilities through public GitHub issues** 10 | 11 | The cashocs development team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. 12 | 13 | Report security bugs in third-party modules to the person or team maintaining the module. 14 | -------------------------------------------------------------------------------- /cashocs/_cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Command line interface of cashocs.""" 19 | 20 | from cashocs._cli._convert import convert 21 | from cashocs._cli._extract_mesh import extract_mesh 22 | 23 | __all__ = ["convert", "extract_mesh"] 24 | -------------------------------------------------------------------------------- /cashocs/_constraints/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Optimization problems with additional (in-)equatility constraints.""" 19 | 20 | from cashocs._constraints.constrained_problems import ConstrainedOptimalControlProblem 21 | from cashocs._constraints.constrained_problems import ( 22 | ConstrainedShapeOptimizationProblem, 23 | ) 24 | from cashocs._constraints.constraints import EqualityConstraint 25 | from cashocs._constraints.constraints import InequalityConstraint 26 | 27 | __all__ = [ 28 | "ConstrainedOptimalControlProblem", 29 | "ConstrainedShapeOptimizationProblem", 30 | "EqualityConstraint", 31 | "InequalityConstraint", 32 | ] 33 | -------------------------------------------------------------------------------- /cashocs/_database/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Databases for cashocs.""" 19 | -------------------------------------------------------------------------------- /cashocs/_database/form_database.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Main Database for all of cashocs.""" 19 | 20 | from __future__ import annotations 21 | 22 | from typing import TYPE_CHECKING 23 | 24 | from cashocs._optimization import cost_functional 25 | 26 | if TYPE_CHECKING: 27 | import fenics 28 | 29 | try: 30 | import ufl_legacy as ufl 31 | except ImportError: 32 | import ufl 33 | 34 | from cashocs import _typing 35 | 36 | 37 | class FormDatabase: 38 | """Database for user supplied forms.""" 39 | 40 | def __init__( 41 | self, 42 | cost_functional_list: list[_typing.CostFunctional], 43 | state_forms: list[ufl.Form], 44 | bcs_list: list[list[fenics.DirichletBC]], 45 | preconditioner_forms: list[ufl.Form], 46 | ): 47 | """Initializes the form database. 48 | 49 | Args: 50 | cost_functional_list: The list of cost functionals. 51 | state_forms: The list of state forms. 52 | bcs_list: The list of boundary conditions for the state system. 53 | preconditioner_forms: The list of forms for the preconditioner. The default 54 | is `None`, so that the preconditioner matrix is the same as the system 55 | matrix. 56 | 57 | """ 58 | self.cost_functional_list = cost_functional_list 59 | self.state_forms = state_forms 60 | self.bcs_list = bcs_list 61 | self.preconditioner_forms = preconditioner_forms 62 | 63 | self.lagrangian = cost_functional.Lagrangian( 64 | self.cost_functional_list, self.state_forms 65 | ) 66 | -------------------------------------------------------------------------------- /cashocs/_forms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Derivation and management of weak forms. 19 | 20 | This module is used to carry out form manipulations such as generating the UFL 21 | forms for the adjoint system and for the Riesz gradient identificiation 22 | problems. 23 | """ 24 | 25 | from cashocs._forms.control_form_handler import ControlFormHandler 26 | from cashocs._forms.form_handler import FormHandler 27 | from cashocs._forms.general_form_handler import AdjointFormHandler 28 | from cashocs._forms.general_form_handler import GeneralFormHandler 29 | from cashocs._forms.general_form_handler import StateFormHandler 30 | from cashocs._forms.shape_form_handler import ShapeFormHandler 31 | from cashocs._forms.shape_regularization import ShapeRegularization 32 | 33 | __all__ = [ 34 | "ControlFormHandler", 35 | "FormHandler", 36 | "AdjointFormHandler", 37 | "GeneralFormHandler", 38 | "StateFormHandler", 39 | "ShapeFormHandler", 40 | "ShapeRegularization", 41 | ] 42 | -------------------------------------------------------------------------------- /cashocs/_optimization/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Optimization routines.""" 19 | -------------------------------------------------------------------------------- /cashocs/_optimization/line_search/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Line search algorithms.""" 19 | 20 | from cashocs._optimization.line_search.armijo_line_search import ArmijoLineSearch 21 | from cashocs._optimization.line_search.line_search import LineSearch 22 | from cashocs._optimization.line_search.polynomial_line_search import ( 23 | PolynomialLineSearch, 24 | ) 25 | 26 | __all__ = [ 27 | "ArmijoLineSearch", 28 | "LineSearch", 29 | "PolynomialLineSearch", 30 | ] 31 | -------------------------------------------------------------------------------- /cashocs/_optimization/optimal_control/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Optimal control problems.""" 19 | 20 | from cashocs._optimization.optimal_control.control_variable_abstractions import ( 21 | ControlVariableAbstractions, 22 | ) 23 | from cashocs._optimization.optimal_control.optimal_control_problem import ( 24 | OptimalControlProblem, 25 | ) 26 | 27 | __all__ = ["ControlVariableAbstractions", "OptimalControlProblem"] 28 | -------------------------------------------------------------------------------- /cashocs/_optimization/optimization_algorithms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Optimization algorithms for PDE constrained optimization.""" 19 | 20 | from cashocs._optimization.optimization_algorithms.gradient_descent import ( 21 | GradientDescentMethod, 22 | ) 23 | from cashocs._optimization.optimization_algorithms.l_bfgs import LBFGSMethod 24 | from cashocs._optimization.optimization_algorithms.ncg import NonlinearCGMethod 25 | from cashocs._optimization.optimization_algorithms.newton import NewtonMethod 26 | from cashocs._optimization.optimization_algorithms.optimization_algorithm import ( 27 | OptimizationAlgorithm, 28 | ) 29 | 30 | __all__ = [ 31 | "OptimizationAlgorithm", 32 | "GradientDescentMethod", 33 | "LBFGSMethod", 34 | "NonlinearCGMethod", 35 | "NewtonMethod", 36 | ] 37 | -------------------------------------------------------------------------------- /cashocs/_optimization/shape_optimization/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Shape optimization problems.""" 19 | 20 | from cashocs._optimization.shape_optimization.shape_optimization_problem import ( 21 | ShapeOptimizationProblem, 22 | ) 23 | from cashocs._optimization.shape_optimization.shape_variable_abstractions import ( 24 | ShapeVariableAbstractions, 25 | ) 26 | 27 | __all__ = ["ShapeOptimizationProblem", "ShapeVariableAbstractions"] 28 | -------------------------------------------------------------------------------- /cashocs/_optimization/topology_optimization/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Methods and classes for topology optimization problems.""" 19 | 20 | from cashocs._optimization.topology_optimization.topology_optimization_problem import ( 21 | TopologyOptimizationProblem, 22 | ) 23 | 24 | __all__ = ["TopologyOptimizationProblem"] 25 | -------------------------------------------------------------------------------- /cashocs/_pde_problems/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """PDEs associated to optimization problems.""" 19 | 20 | from cashocs._pde_problems.adjoint_problem import AdjointProblem 21 | from cashocs._pde_problems.control_gradient_problem import ControlGradientProblem 22 | from cashocs._pde_problems.hessian_problems import HessianProblem 23 | from cashocs._pde_problems.pde_problem import PDEProblem 24 | from cashocs._pde_problems.shape_gradient_problem import ShapeGradientProblem 25 | from cashocs._pde_problems.state_problem import StateProblem 26 | 27 | __all__ = [ 28 | "PDEProblem", 29 | "AdjointProblem", 30 | "ControlGradientProblem", 31 | "HessianProblem", 32 | "ShapeGradientProblem", 33 | "StateProblem", 34 | ] 35 | -------------------------------------------------------------------------------- /cashocs/_pde_problems/pde_problem.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """General PDE problem.""" 19 | 20 | from __future__ import annotations 21 | 22 | import abc 23 | from typing import TYPE_CHECKING 24 | 25 | import fenics 26 | 27 | from cashocs import _utils 28 | 29 | if TYPE_CHECKING: 30 | from cashocs._database import database 31 | 32 | 33 | class PDEProblem(abc.ABC): 34 | """Base class for a PDE problem.""" 35 | 36 | def __init__( 37 | self, 38 | db: database.Database, 39 | linear_solver: _utils.linalg.LinearSolver | None = None, 40 | ) -> None: 41 | """Initializes self. 42 | 43 | Args: 44 | db: The database of the problem 45 | linear_solver: The linear solver (KSP) which is used to solve the linear 46 | systems arising from the discretized PDE 47 | 48 | """ 49 | self.db = db 50 | 51 | self.config = db.config 52 | self.has_solution: bool = False 53 | if linear_solver is None: 54 | self.linear_solver = _utils.linalg.LinearSolver() 55 | else: 56 | self.linear_solver = linear_solver 57 | 58 | @abc.abstractmethod 59 | def solve(self) -> fenics.Function | list[fenics.Function]: 60 | """Solves the PDE. 61 | 62 | Returns: 63 | The solution of the PDE. 64 | 65 | """ 66 | pass 67 | -------------------------------------------------------------------------------- /cashocs/io/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Inputs and outputs.""" 19 | 20 | from cashocs.io import config 21 | from cashocs.io import function 22 | from cashocs.io import managers 23 | from cashocs.io import mesh 24 | from cashocs.io import output 25 | from cashocs.io.config import Config 26 | from cashocs.io.config import load_config 27 | from cashocs.io.function import import_function 28 | from cashocs.io.function import read_function_from_xdmf 29 | from cashocs.io.mesh import convert 30 | from cashocs.io.mesh import export_mesh 31 | from cashocs.io.mesh import extract_mesh_from_xdmf 32 | from cashocs.io.mesh import import_mesh 33 | from cashocs.io.mesh import read_mesh_from_xdmf 34 | from cashocs.io.mesh import write_out_mesh 35 | from cashocs.io.output import OutputManager 36 | 37 | __all__ = [ 38 | "config", 39 | "function", 40 | "managers", 41 | "mesh", 42 | "output", 43 | "Config", 44 | "load_config", 45 | "import_function", 46 | "read_function_from_xdmf", 47 | "convert", 48 | "export_mesh", 49 | "extract_mesh_from_xdmf", 50 | "import_mesh", 51 | "read_mesh_from_xdmf", 52 | "write_out_mesh", 53 | "OutputManager", 54 | ] 55 | -------------------------------------------------------------------------------- /cashocs/mpi.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Default MPI communicator for cashocs.""" 19 | 20 | from mpi4py import MPI 21 | 22 | COMM_WORLD = MPI.COMM_WORLD.Dup() 23 | -------------------------------------------------------------------------------- /cashocs/nonlinear_solvers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Custom solvers for nonlinear equations. 19 | 20 | This module has custom solvers for nonlinear PDEs, including a damped Newton method and 21 | a Picard iteration for coupled problems. 22 | """ 23 | 24 | from cashocs.nonlinear_solvers import linear_solver 25 | from cashocs.nonlinear_solvers import newton_solver 26 | from cashocs.nonlinear_solvers import picard_solver 27 | from cashocs.nonlinear_solvers import snes 28 | from cashocs.nonlinear_solvers import ts 29 | from cashocs.nonlinear_solvers.linear_solver import linear_solve 30 | from cashocs.nonlinear_solvers.newton_solver import newton_solve 31 | from cashocs.nonlinear_solvers.picard_solver import picard_iteration 32 | from cashocs.nonlinear_solvers.snes import snes_solve 33 | from cashocs.nonlinear_solvers.ts import ts_pseudo_solve 34 | 35 | __all__ = [ 36 | "linear_solver", 37 | "newton_solver", 38 | "picard_solver", 39 | "snes", 40 | "ts", 41 | "linear_solve", 42 | "newton_solve", 43 | "picard_iteration", 44 | "snes_solve", 45 | "ts_pseudo_solve", 46 | ] 47 | -------------------------------------------------------------------------------- /cashocs/space_mapping/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | """Space mapping algorithms.""" 19 | 20 | from cashocs.space_mapping import optimal_control # noqa: F401 21 | from cashocs.space_mapping import shape_optimization # noqa: F401 22 | 23 | __all__ = ["optimal_control", "shape_optimization"] 24 | -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/control_solver/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/control_solver/img_control_solver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/cashocs_as_solver/control_solver/img_control_solver.png -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [1] 10 | use_pull_back = True 11 | lambda_lame = 1.428571428571429 12 | damping_factor = 0.2 13 | mu_def = 0.35714285714285715 14 | mu_fix = 0.35714285714285715 15 | 16 | [Output] 17 | verbose = True 18 | save_results = False 19 | save_txt = False 20 | -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/img_shape_solver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/cashocs_as_solver/shape_solver/img_shape_solver.png -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/cashocs_as_solver/shape_solver/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/cashocs_as_solver/shape_solver/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/cashocs_as_solver/shape_solver/results/history.txt: -------------------------------------------------------------------------------- 1 | Iteration 0 - Objective value: -1.102e-02 Gradient norm: 6.330e-01 (abs) Mesh Quality: 0.48 (condition_number) 2 | 3 | Iteration 1 - Objective value: -5.901e-02 Gradient norm: 2.896e-01 (rel) Mesh Quality: 0.47 (condition_number) Step size: 2.500e-01 4 | Iteration 2 - Objective value: -6.567e-02 Gradient norm: 2.450e-01 (rel) Mesh Quality: 0.45 (condition_number) Step size: 1.000e+00 5 | Iteration 3 - Objective value: -9.209e-02 Gradient norm: 5.075e-02 (rel) Mesh Quality: 0.32 (condition_number) Step size: 1.000e+00 6 | Iteration 4 - Objective value: -9.338e-02 Gradient norm: 1.730e-02 (rel) Mesh Quality: 0.31 (condition_number) Step size: 1.000e+00 7 | Iteration 5 - Objective value: -9.351e-02 Gradient norm: 3.901e-02 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 8 | Iteration 6 - Objective value: -9.362e-02 Gradient norm: 1.010e-02 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 9 | Iteration 7 - Objective value: -9.364e-02 Gradient norm: 8.655e-03 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 10 | Iteration 8 - Objective value: -9.369e-02 Gradient norm: 9.190e-03 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 11 | Iteration 9 - Objective value: -9.374e-02 Gradient norm: 6.695e-03 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 12 | Iteration 10 - Objective value: -9.375e-02 Gradient norm: 2.055e-02 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 13 | Iteration 11 - Objective value: -9.378e-02 Gradient norm: 3.929e-03 (rel) Mesh Quality: 0.30 (condition_number) Step size: 1.000e+00 14 | 15 | Statistics --- Total iterations: 11 --- Final objective value: -9.378e-02 --- Final gradient norm: 3.929e-03 (rel) 16 | --- State equations solved: 14 --- Adjoint equations solved: 12 17 | -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [AlgoLBFGS] 9 | bfgs_memory_size = 5 10 | use_bfgs_scaling = True 11 | 12 | [ShapeGradient] 13 | shape_bdry_def = [1] 14 | damping_factor = 0.5 15 | 16 | [Output] 17 | save_results = False 18 | save_txt = False 19 | save_state = False -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/img_rank_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_comm_self/img_rank_0.png -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/img_rank_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_comm_self/img_rank_1.png -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_comm_self/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_comm_self/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_comm_self/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [AlgoLBFGS] 9 | bfgs_memory_size = 5 10 | use_bfgs_scaling = True 11 | 12 | [ShapeGradient] 13 | shape_bdry_def = [1] 14 | damping_factor = 0.5 15 | 16 | [Output] 17 | save_results = False 18 | save_txt = False 19 | save_state = False -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_custom/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/mpi_custom/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/misc/mpi_custom/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [1] 10 | lambda_lame = 1.428571428571429 11 | damping_factor = 0.2 12 | mu_def = 0.35714285714285715 13 | mu_fix = 0.35714285714285715 14 | 15 | [Output] 16 | verbose = True 17 | save_results = False 18 | save_txt = False 19 | save_state = True 20 | save_adjoint = True 21 | save_gradient = True 22 | -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/img_shape_gradient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/xdmf_io/img_shape_gradient.png -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/img_states.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/xdmf_io/img_states.png -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/xdmf_io/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/misc/xdmf_io/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/misc/xdmf_io/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/optimal_control/box_constraints/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/box_constraints/img_box_constraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/box_constraints/img_box_constraints.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/constraints/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | max_iter = 250 7 | 8 | [Output] 9 | verbose = False 10 | save_results = False 11 | save_txt = False 12 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/constraints/img_constraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/constraints/img_constraints.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/control_boundary_conditions/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/control_boundary_conditions/img_control_boundary_conditions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/control_boundary_conditions/img_control_boundary_conditions.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/dirichlet_control/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/dirichlet_control/img_dirichlet_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/dirichlet_control/img_dirichlet_control.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/heat_equation/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/iterative_solvers/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 1e-4 7 | 8 | [Output] 9 | save_results = False 10 | save_txt = False 11 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/iterative_solvers/img_iterative_solvers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/iterative_solvers/img_iterative_solvers.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/monolithic_problems/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/monolithic_problems/img_monolithic_problems.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/monolithic_problems/img_monolithic_problems.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/multiple_variables/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/multiple_variables/img_multiple_variables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/multiple_variables/img_multiple_variables.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/neumann_control/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/neumann_control/img_neumann_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/neumann_control/img_neumann_control.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/nonlinear_pdes/config.ini: -------------------------------------------------------------------------------- 1 | [OptimizationRoutine] 2 | algorithm = lbfgs 3 | 4 | [Output] 5 | save_results = False 6 | save_txt = False 7 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/nonlinear_pdes/img_nonlinear_pdes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/nonlinear_pdes/img_nonlinear_pdes.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/picard_iteration/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | picard_iteration = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/picard_iteration/img_picard_iteration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/picard_iteration/img_picard_iteration.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/poisson/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/poisson/img_poisson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/poisson/img_poisson.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/poisson/results/history.json: -------------------------------------------------------------------------------- 1 | { 2 | "stepsize": [ 3 | 1.0, 4 | 1.0, 5 | 1.0, 6 | 0.5, 7 | 1.0, 8 | 1.0, 9 | 1.0, 10 | 1.0 11 | ], 12 | "no_state_solves": [ 13 | 1, 14 | 2, 15 | 3, 16 | 5, 17 | 6, 18 | 7, 19 | 8, 20 | 9 21 | ], 22 | "no_adjoint_solves": [ 23 | 1, 24 | 2, 25 | 3, 26 | 4, 27 | 5, 28 | 6, 29 | 7, 30 | 8 31 | ], 32 | "iteration": [ 33 | 0, 34 | 1, 35 | 2, 36 | 3, 37 | 4, 38 | 5, 39 | 6, 40 | 7 41 | ], 42 | "gradient_norm_initial": [ 43 | 0.006169211292565741, 44 | 0.006169211292565741, 45 | 0.006169211292565741, 46 | 0.006169211292565741, 47 | 0.006169211292565741, 48 | 0.006169211292565741, 49 | 0.006169211292565741, 50 | 0.006169211292565741 51 | ], 52 | "relative_norm": [ 53 | 1.0, 54 | 0.9998432897368272, 55 | 2.30832977854409, 56 | 0.4847576089118498, 57 | 0.0026050032048259607, 58 | 0.0021488104101385387, 59 | 0.0011142631618146434, 60 | 0.0006792261532533874 61 | ], 62 | "gradient_norm": [ 63 | 0.006169211292565741, 64 | 0.006168244513840514, 65 | 0.014240574136759977, 66 | 0.0029905721150561507, 67 | 1.6070815188382262e-05, 68 | 1.3256465447809494e-05, 69 | 6.874124880756906e-06, 70 | 4.190289654856786e-06 71 | ], 72 | "objective_value": [ 73 | 0.12240249296415007, 74 | 0.1223644367783143, 75 | 0.040652832066650914, 76 | 0.008569132714604638, 77 | 0.0007846142266652301, 78 | 0.0007841983794183015, 79 | 0.0007831054455375862, 80 | 0.0007827521435794336 81 | ] 82 | } -------------------------------------------------------------------------------- /demos/documented/optimal_control/poisson/results/history.txt: -------------------------------------------------------------------------------- 1 | 2 | iter, cost function, rel. grad. norm, abs. grad. norm, step size 3 | 4 | 0, 1.224e-01, 1.000e+00, 6.169e-03, 5 | 6 | 1, 1.224e-01, 9.998e-01, 6.168e-03, 1.000e+00 7 | 2, 4.065e-02, 2.308e+00, 1.424e-02, 1.000e+00 8 | 3, 8.569e-03, 4.848e-01, 2.991e-03, 5.000e-01 9 | 4, 7.846e-04, 2.605e-03, 1.607e-05, 1.000e+00 10 | 5, 7.842e-04, 2.149e-03, 1.326e-05, 1.000e+00 11 | 6, 7.831e-04, 1.114e-03, 6.874e-06, 1.000e+00 12 | 7, 7.828e-04, 6.792e-04, 4.190e-06, 1.000e+00 13 | 14 | Optimization was successful. 15 | Statistics: 16 | total iterations: 7 17 | final objective value: 7.828e-04 18 | final gradient norm: 6.792e-04 19 | total number of state systems solved: 9 20 | total number of adjoint systems solved: 8 21 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/pre_post_callbacks/config.ini: -------------------------------------------------------------------------------- 1 | [OptimizationRoutine] 2 | algorithm = lbfgs 3 | 4 | [Output] 5 | save_results = False 6 | save_txt = False 7 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/pre_post_callbacks/img_pre_post_callbacks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/pre_post_callbacks/img_pre_post_callbacks.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/scalar_control_tracking/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False 10 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/scalar_control_tracking/img_scalar_control_tracking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/scalar_control_tracking/img_scalar_control_tracking.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/sparse_control/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [Output] 9 | save_results = False 10 | save_txt = False -------------------------------------------------------------------------------- /demos/documented/optimal_control/sparse_control/img_sparse_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/sparse_control/img_sparse_control.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/state_constraints/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = newton 6 | rtol = 1e-4 7 | 8 | [AlgoTNM] 9 | inner_newton = cg 10 | inner_newton_rtol = 1e-13 11 | 12 | [Output] 13 | save_results = False 14 | save_txt = False 15 | -------------------------------------------------------------------------------- /demos/documented/optimal_control/state_constraints/img_state_constraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/state_constraints/img_state_constraints.png -------------------------------------------------------------------------------- /demos/documented/optimal_control/stokes/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [Output] 8 | save_results = False 9 | save_txt = False -------------------------------------------------------------------------------- /demos/documented/optimal_control/stokes/img_stokes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/optimal_control/stokes/img_stokes.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [1] 10 | 11 | [Output] 12 | save_results = False 13 | save_txt = False 14 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/img_custom_scalar_product.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/custom_scalar_product/img_custom_scalar_product.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/custom_scalar_product/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/custom_scalar_product/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/custom_scalar_product/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-4 7 | 8 | [ShapeGradient] 9 | shape_bdry_fix = [1, 2, 3, 4] 10 | 11 | [Output] 12 | save_results = False 13 | save_txt = False -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/img_inverse_tomography.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/inverse_tomography/img_inverse_tomography.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 1.5e-2; 2 | radius = 0.2; 3 | center_x = 0.5; 4 | center_y = 0.5; 5 | 6 | Point(1) = {0.0, 0.0, 0.0, lc}; 7 | Point(2) = {1.0, 0.0, 0.0, lc}; 8 | Point(3) = {1.0, 1.0, 0.0, lc}; 9 | Point(4) = {0.0, 1.0, 0.0, lc}; 10 | 11 | Point(5) = {center_x - radius, center_y - radius, 0, lc}; 12 | Point(6) = {center_x + radius, center_y - radius, 0, lc}; 13 | Point(7) = {center_x + radius, center_y + radius, 0, lc}; 14 | Point(8) = {center_x - radius, center_y + radius, 0, lc}; 15 | 16 | Line(1) = {1,2}; 17 | Line(2) = {2,3}; 18 | Line(3) = {3,4}; 19 | Line(4) = {4,1}; 20 | 21 | Line(5) = {5,6}; 22 | Line(6) = {6,7}; 23 | Line(7) = {7,8}; 24 | Line(8) = {8,5}; 25 | 26 | 27 | Line Loop(1) = {1,2,3,4}; 28 | Line Loop(2) = {5,6,7,8}; 29 | 30 | Plane Surface(1) = {1,2}; 31 | Plane Surface(2) = {2}; 32 | 33 | Physical Surface(1) = {1}; 34 | Physical Surface(2) = {2}; 35 | 36 | Physical Line(1) = {1}; 37 | Physical Line(2) = {3}; 38 | Physical Line(3) = {4}; 39 | Physical Line(4) = {2}; 40 | 41 | Physical Line(5) = {5}; 42 | Physical Line(6) = {6}; 43 | Physical Line(7) = {7}; 44 | Physical Line(8) = {8}; 45 | 46 | Field[1] = Distance; 47 | Field[1].NNodesByEdge = 1000; 48 | Field[1].EdgesList = {1}; 49 | Field[2] = Threshold; 50 | Field[2].IField = 1; 51 | Field[2].LcMin = lc; 52 | Field[2].LcMax = lc; 53 | Field[2].DistMin = 0.0; 54 | Field[2].DistMax = 0.0; 55 | 56 | Background Field = 2; 57 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/inverse_tomography/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/inverse_tomography/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/reference.geo: -------------------------------------------------------------------------------- 1 | lc = 1.5e-2; 2 | radius = 0.2; 3 | center_x = 0.5; 4 | center_y = 0.5; 5 | 6 | Point(1) = {0.0, 0.0, 0.0, lc}; 7 | Point(2) = {1.0, 0.0, 0.0, lc}; 8 | Point(3) = {1.0, 1.0, 0.0, lc}; 9 | Point(4) = {0.0, 1.0, 0.0, lc}; 10 | 11 | Point(5) = {center_x, center_y, 0, lc}; 12 | Point(6) = {center_x + radius, center_y, 0, lc}; 13 | Point(7) = {center_x, center_y + radius, 0, lc}; 14 | Point(8) = {center_x - radius, center_y, 0, lc}; 15 | Point(9) = {center_x, center_y - radius, 0, lc}; 16 | 17 | Line(1) = {1,2}; 18 | Line(2) = {2,3}; 19 | Line(3) = {3,4}; 20 | Line(4) = {4,1}; 21 | 22 | Circle(5) = {6, 5, 7}; 23 | Circle(6) = {7, 5, 8}; 24 | Circle(7) = {8, 5, 9}; 25 | Circle(8) = {9, 5, 6}; 26 | 27 | 28 | Line Loop(1) = {1,2,3,4}; 29 | Line Loop(2) = {5,6,7,8}; 30 | 31 | Plane Surface(1) = {1,2}; 32 | Plane Surface(2) = {2}; 33 | 34 | Physical Surface(1) = {1}; 35 | Physical Surface(2) = {2}; 36 | 37 | Physical Line(1) = {1}; 38 | Physical Line(2) = {3}; 39 | Physical Line(3) = {4}; 40 | Physical Line(4) = {2}; 41 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/reference.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/inverse_tomography/mesh/reference.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/reference.xdmf: -------------------------------------------------------------------------------- 1 | reference.h5:/data0reference.h5:/data1reference.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/reference_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/inverse_tomography/mesh/reference_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/inverse_tomography/mesh/reference_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | reference_boundaries.h5:/data0reference_boundaries.h5:/data1reference_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = gd 6 | rtol = 1e-2 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [1] 10 | damping_factor = 1e-2 11 | use_p_laplacian = True 12 | p_laplacian_power = 10 13 | 14 | [Output] 15 | save_results = False 16 | save_txt = False 17 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/img_p_laplacian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/p_laplacian/img_p_laplacian.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/p_laplacian/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/p_laplacian/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/p_laplacian/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | max_iter = 250 7 | rtol = 5e-4 8 | 9 | [ShapeGradient] 10 | shape_bdry_def = [4] 11 | shape_bdry_fix = [1,2,3] 12 | use_distance_mu = True 13 | dist_min = 0.05 14 | dist_max = 1.25 15 | mu_min = 5e2 16 | mu_max = 1.0 17 | boundaries_dist = [4] 18 | distance_method = eikonal 19 | 20 | [Regularization] 21 | factor_volume = 1e4 22 | use_initial_volume = True 23 | factor_barycenter = 1e5 24 | use_initial_barycenter = True 25 | 26 | [Output] 27 | save_results = False 28 | save_txt = False 29 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/img_prescribed_mu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/prescribed_mu/img_prescribed_mu.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 3.75e-1; 2 | 3 | length = 3.0; 4 | width = 2.0; 5 | 6 | Point(1) = {-length, -width, 0, lc}; 7 | Point(2) = {length, -width, 0, lc}; 8 | Point(3) = {length, width, 0, lc}; 9 | Point(4) = {-length, width, 0, lc}; 10 | 11 | Point(5) = {0.5, 0, 0, lc}; 12 | Point(6) = {0, 0.5, 0, lc}; 13 | Point(7) = {-0.5, 0, 0, lc}; 14 | Point(8) = {0, -0.5, 0, lc}; 15 | Point(9) = {0, 0, 0, lc}; 16 | 17 | 18 | Line(1) = {1,2}; 19 | Line(2) = {2,3}; 20 | Line(3) = {3,4}; 21 | Line(4) = {4,1}; 22 | 23 | Circle(5) = {5,9,6}; 24 | Circle(6) = {6,9,7}; 25 | Circle(7) = {7,9,8}; 26 | Circle(8) = {8,9,5}; 27 | 28 | Line Loop(1) = {1,2,3,4}; 29 | Line Loop(2) = {5,6,7,8}; 30 | 31 | Plane Surface(1) = {1,2}; 32 | 33 | 34 | Physical Surface(1) = {1}; 35 | 36 | Physical Line(1) = {4}; 37 | Physical Line(2) = {1,3}; 38 | Physical Line(3) = {2}; 39 | Physical Line(4) = {5,6,7,8}; 40 | 41 | 42 | // Inlet and Outlet 43 | Field[1] = Distance; 44 | Field[1].NNodesByEdge = 1000; 45 | Field[1].EdgesList = {5,6,7,8}; 46 | Field[2] = Threshold; 47 | Field[2].IField = 1; 48 | Field[2].LcMin = lc/50; 49 | Field[2].LcMax = lc; 50 | Field[2].DistMin = 0; 51 | Field[2].DistMax = 2.5e-2; 52 | 53 | Background Field = 2; 54 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/prescribed_mu/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/prescribed_mu/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/prescribed_mu/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = False 3 | newton_rtol = 1e-6 4 | newton_atol = 1e-10 5 | backend = petsc 6 | 7 | [OptimizationRoutine] 8 | algorithm = lbfgs 9 | rtol = 5e-4 10 | 11 | [ShapeGradient] 12 | shape_bdry_def = [4] 13 | shape_bdry_fix = [1,2,3] 14 | mu_fix = 1 15 | mu_def = 5e2 16 | 17 | [Regularization] 18 | factor_volume = 1e4 19 | use_initial_volume = True 20 | factor_barycenter = 1e5 21 | use_initial_barycenter = True 22 | 23 | [Output] 24 | save_results = False 25 | save_txt = False 26 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/img_pseudo_time_stepping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/pseudo_time_stepping/img_pseudo_time_stepping.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 3.75e-1; 2 | 3 | length = 3.0; 4 | width = 2.0; 5 | 6 | Point(1) = {-length, -width, 0, lc}; 7 | Point(2) = {length, -width, 0, lc}; 8 | Point(3) = {length, width, 0, lc}; 9 | Point(4) = {-length, width, 0, lc}; 10 | 11 | Point(5) = {0.5, 0, 0, lc}; 12 | Point(6) = {0, 0.5, 0, lc}; 13 | Point(7) = {-0.5, 0, 0, lc}; 14 | Point(8) = {0, -0.5, 0, lc}; 15 | Point(9) = {0, 0, 0, lc}; 16 | 17 | 18 | Line(1) = {1,2}; 19 | Line(2) = {2,3}; 20 | Line(3) = {3,4}; 21 | Line(4) = {4,1}; 22 | 23 | Circle(5) = {5,9,6}; 24 | Circle(6) = {6,9,7}; 25 | Circle(7) = {7,9,8}; 26 | Circle(8) = {8,9,5}; 27 | 28 | Line Loop(1) = {1,2,3,4}; 29 | Line Loop(2) = {5,6,7,8}; 30 | 31 | Plane Surface(1) = {1,2}; 32 | 33 | 34 | Physical Surface(1) = {1}; 35 | 36 | Physical Line(1) = {4}; 37 | Physical Line(2) = {1,3}; 38 | Physical Line(3) = {2}; 39 | Physical Line(4) = {5,6,7,8}; 40 | 41 | 42 | // Inlet and Outlet 43 | Field[1] = Distance; 44 | Field[1].NNodesByEdge = 1000; 45 | Field[1].EdgesList = {5,6,7,8}; 46 | Field[2] = Threshold; 47 | Field[2].IField = 1; 48 | Field[2].LcMin = lc/50; 49 | Field[2].LcMax = lc; 50 | Field[2].DistMin = 0; 51 | Field[2].DistMax = 2.5e-2; 52 | 53 | Background Field = 2; 54 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/pseudo_time_stepping/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [ShapeGradient] 8 | shape_bdry_def = [1] 9 | damping_factor = 0.5 10 | 11 | [Regularization] 12 | factor_volume = 1.0 13 | target_volume = 1.5 14 | factor_surface = 1.0 15 | target_surface = 4.5 16 | factor_curvature = 1e-4 17 | 18 | [Output] 19 | save_results = False 20 | save_txt = False 21 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/img_regularization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/regularization/img_regularization.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/regularization/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/regularization/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/regularization/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/config.ini: -------------------------------------------------------------------------------- 1 | [Mesh] 2 | gmsh_file = ./mesh/mesh.msh 3 | geo_file = ./mesh/mesh.geo 4 | remesh = True 5 | show_gmsh_output = True 6 | 7 | [StateSystem] 8 | is_linear = True 9 | 10 | [OptimizationRoutine] 11 | algorithm = lbfgs 12 | 13 | [ShapeGradient] 14 | shape_bdry_def = [1] 15 | lambda_lame = 1.428571428571429 16 | damping_factor = 0.2 17 | mu_fix = 0.35714285714285715 18 | mu_def = 0.35714285714285715 19 | 20 | [MeshQuality] 21 | tol_lower = 0.1 22 | tol_upper = 0.25 23 | measure = condition_number 24 | 25 | [Output] 26 | save_results = False 27 | save_txt = False 28 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/img_remeshing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/remeshing/img_remeshing.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1.xdmf: -------------------------------------------------------------------------------- 1 | mesh_1.h5:/data0mesh_1.h5:/data1mesh_1.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/mesh_1_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_1_boundaries.h5:/data0mesh_1_boundaries.h5:/data1mesh_1_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/cashocs_remesh/remesh.geo: -------------------------------------------------------------------------------- 1 | Merge 'mesh_1_pre_remesh.msh'; 2 | CreateGeometry; 3 | 4 | lc = 5e-2; 5 | Field[1] = Distance; 6 | Field[1].NNodesByEdge = 1000; 7 | Field[1].NodesList = {2}; 8 | Field[2] = Threshold; 9 | Field[2].IField = 1; 10 | Field[2].DistMin = 1e-1; 11 | Field[2].DistMax = 5e-1; 12 | Field[2].LcMin = lc / 10; 13 | Field[2].LcMax = lc; 14 | Background Field = 2; 15 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 5e-2; 2 | 3 | Point(1) = {0, 0, 0, lc}; 4 | Point(2) = {1, 0, 0, lc}; 5 | Point(3) = {0, 1, 0, lc}; 6 | Point(4) = {-1, 0, 0, lc}; 7 | Point(5) = {0, -1, 0, lc}; 8 | 9 | Circle(1) = {2, 1, 3}; 10 | Circle(2) = {3, 1, 4}; 11 | Circle(3) = {4, 1, 5}; 12 | Circle(4) = {5, 1, 2}; 13 | 14 | Line Loop(1) = {1,2,3,4}; 15 | 16 | Surface(1) = {1}; 17 | 18 | Physical Surface(1) = {1}; 19 | 20 | Physical Line(1) = {1,2,3,4}; 21 | 22 | Field[1] = Distance; 23 | Field[1].NNodesByEdge = 1000; 24 | Field[1].NodesList = {2}; 25 | Field[2] = Threshold; 26 | Field[2].IField = 1; 27 | Field[2].DistMin = 1e-1; 28 | Field[2].DistMax = 5e-1; 29 | Field[2].LcMin = lc / 10; 30 | Field[2].LcMax = lc; 31 | 32 | Background Field = 2; 33 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/remeshing/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/remeshing/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/remeshing/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | 7 | [ShapeGradient] 8 | shape_bdry_def = [1] 9 | damping_factor = 0.5 10 | 11 | [Output] 12 | save_results = False 13 | save_txt = False 14 | 15 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/img_scaling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/scaling/img_scaling.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/scaling/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/scaling/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/scaling/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-3 7 | 8 | [AlgoLBFGS] 9 | bfgs_memory_size = 3 10 | use_bfgs_scaling = True 11 | 12 | [ShapeGradient] 13 | shape_bdry_def = [1] 14 | damping_factor = 0.5 15 | 16 | [Output] 17 | save_results = False 18 | save_txt = False 19 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/img_shape_poisson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_poisson/img_shape_poisson.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_poisson/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_poisson/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_poisson/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = lbfgs 6 | rtol = 5e-4 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [4] 10 | shape_bdry_fix = [1,2,3] 11 | mu_fix = 1 12 | mu_def = 5e2 13 | 14 | [Regularization] 15 | factor_volume = 1e4 16 | use_initial_volume = True 17 | factor_barycenter = 1e5 18 | use_initial_barycenter = True 19 | 20 | [Output] 21 | save_results = False 22 | save_txt = False 23 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/img_shape_stokes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_stokes/img_shape_stokes.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 3.75e-1; 2 | 3 | length = 3.0; 4 | width = 2.0; 5 | 6 | Point(1) = {-length, -width, 0, lc}; 7 | Point(2) = {length, -width, 0, lc}; 8 | Point(3) = {length, width, 0, lc}; 9 | Point(4) = {-length, width, 0, lc}; 10 | 11 | Point(5) = {0.5, 0, 0, lc}; 12 | Point(6) = {0, 0.5, 0, lc}; 13 | Point(7) = {-0.5, 0, 0, lc}; 14 | Point(8) = {0, -0.5, 0, lc}; 15 | Point(9) = {0, 0, 0, lc}; 16 | 17 | 18 | Line(1) = {1,2}; 19 | Line(2) = {2,3}; 20 | Line(3) = {3,4}; 21 | Line(4) = {4,1}; 22 | 23 | Circle(5) = {5,9,6}; 24 | Circle(6) = {6,9,7}; 25 | Circle(7) = {7,9,8}; 26 | Circle(8) = {8,9,5}; 27 | 28 | Line Loop(1) = {1,2,3,4}; 29 | Line Loop(2) = {5,6,7,8}; 30 | 31 | Plane Surface(1) = {1,2}; 32 | 33 | 34 | Physical Surface(1) = {1}; 35 | 36 | Physical Line(1) = {4}; 37 | Physical Line(2) = {1,3}; 38 | Physical Line(3) = {2}; 39 | Physical Line(4) = {5,6,7,8}; 40 | 41 | 42 | // Inlet and Outlet 43 | Field[1] = Distance; 44 | Field[1].NNodesByEdge = 1000; 45 | Field[1].EdgesList = {5,6,7,8}; 46 | Field[2] = Threshold; 47 | Field[2].IField = 1; 48 | Field[2].LcMin = lc/50; 49 | Field[2].LcMax = lc; 50 | Field[2].DistMin = 0; 51 | Field[2].DistMax = 2.5e-2; 52 | 53 | Background Field = 2; 54 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_stokes/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/shape_stokes/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/shape_stokes/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/config.ini: -------------------------------------------------------------------------------- 1 | [OptimizationRoutine] 2 | algorithm = lbfgs 3 | rtol = 1e-2 4 | 5 | [LineSearch] 6 | initial_stepsize = 1e2 7 | 8 | [ShapeGradient] 9 | shape_bdry_fix = [1,2,3,4] 10 | damping_factor = 0.1 11 | 12 | [MeshQuality] 13 | angle_change = 0.3 14 | volume_change = 2.0 15 | 16 | [Output] 17 | verbose = False 18 | save_results = False 19 | save_txt = False 20 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/img_space_mapping_semilinear_transmission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_semilinear_transmission/img_space_mapping_semilinear_transmission.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 1.5e-2; 2 | radius = 0.2; 3 | center_x = 0.5; 4 | center_y = 0.5; 5 | 6 | Point(1) = {0.0, 0.0, 0.0, lc}; 7 | Point(2) = {1.0, 0.0, 0.0, lc}; 8 | Point(3) = {1.0, 1.0, 0.0, lc}; 9 | Point(4) = {0.0, 1.0, 0.0, lc}; 10 | 11 | Point(5) = {center_x, center_y, 0, lc}; 12 | Point(6) = {center_x + radius, center_y, 0, lc}; 13 | Point(7) = {center_x, center_y + radius, 0, lc}; 14 | Point(8) = {center_x - radius, center_y, 0, lc}; 15 | Point(9) = {center_x, center_y - radius, 0, lc}; 16 | 17 | Line(1) = {1,2}; 18 | Line(2) = {2,3}; 19 | Line(3) = {3,4}; 20 | Line(4) = {4,1}; 21 | 22 | Circle(5) = {6, 5, 7}; 23 | Circle(6) = {7, 5, 8}; 24 | Circle(7) = {8, 5, 9}; 25 | Circle(8) = {9, 5, 6}; 26 | 27 | 28 | Line Loop(1) = {1,2,3,4}; 29 | Line Loop(2) = {5,6,7,8}; 30 | 31 | Plane Surface(1) = {1,2}; 32 | Plane Surface(2) = {2}; 33 | 34 | Physical Surface(1) = {1}; 35 | Physical Surface(2) = {2}; 36 | 37 | Physical Line(1) = {1}; 38 | Physical Line(2) = {3}; 39 | Physical Line(3) = {4}; 40 | Physical Line(4) = {2}; 41 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference.geo: -------------------------------------------------------------------------------- 1 | SetFactory("OpenCASCADE"); 2 | Rectangle(1) = {0, 0, 0, 1, 1, 0}; 3 | Ellipse(5) = {0.5, 0.5, 0, 0.3, 0.15, 0, 2*Pi}; 4 | 5 | Rotate {{0.0, 0.0, 1}, {0.5, 0.5, 0}, 30.0*Pi/180.0} { 6 | Curve{5}; 7 | } 8 | Curve Loop(2) = {5}; 9 | Plane Surface(2) = {2}; 10 | 11 | BooleanDifference{ Surface{1}; Delete; }{ Surface{2}; } 12 | 13 | Physical Surface(1) = {1}; 14 | Physical Surface(2) = {2}; 15 | 16 | Physical Curve(1) = {6}; 17 | Physical Curve(2) = {9}; 18 | Physical Curve(3) = {7}; 19 | Physical Curve(4) = {8}; 20 | 21 | lc = 1.5e-2; 22 | 23 | Field[1] = Distance; 24 | Field[1].NNodesByEdge = 1000; 25 | Field[1].EdgesList = {1}; 26 | Field[2] = Threshold; 27 | Field[2].IField = 1; 28 | Field[2].LcMin = lc; 29 | Field[2].LcMax = lc; 30 | Field[2].DistMin = 0.0; 31 | Field[2].DistMax = 0.0; 32 | 33 | Background Field = 2; 34 | 35 | 36 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference.xdmf: -------------------------------------------------------------------------------- 1 | reference.h5:/data0reference.h5:/data1reference.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/mesh/reference_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | reference_boundaries.h5:/data0reference_boundaries.h5:/data1reference_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_semilinear_transmission/sm_history.json: -------------------------------------------------------------------------------- 1 | { 2 | "cost_function_value": [ 3 | 8.43576467497285e-05, 4 | 6.321406373138715e-06, 5 | 3.757248246405087e-07, 6 | 6.492747314444575e-08, 7 | 2.5502281994099945e-08, 8 | 1.045513561000219e-08 9 | ], 10 | "eps": [ 11 | 0.2714689844155716, 12 | 0.09123719674129165, 13 | 0.04209945367935356, 14 | 0.02632393957488272, 15 | 0.011912935969791951, 16 | 0.00429293315489518 17 | ], 18 | "stepsize": [ 19 | 1.0, 20 | 1.0, 21 | 1.0, 22 | 1.0, 23 | 1.0, 24 | 1.0 25 | ], 26 | "MeshQuality": [ 27 | 0.3441862980971556, 28 | 0.38658324849707115, 29 | 0.38460354314010936, 30 | 0.37743786779448596, 31 | 0.37218850386072166, 32 | 0.3665218589984678 33 | ] 34 | } -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = bfgs 6 | rtol = 1e-2 7 | 8 | [ShapeGradient] 9 | shape_bdry_def = [2, 3] 10 | shape_bdry_fix = [1, 4, 5] 11 | inhomogeneous = True 12 | 13 | [Output] 14 | verbose = False 15 | save_results = False 16 | save_txt = False 17 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/img_space_mapping_uniform_flow_distribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/img_space_mapping_uniform_flow_distribution.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/fine.geo: -------------------------------------------------------------------------------- 1 | Merge './fine/mesh.msh'; 2 | CreateGeometry; 3 | 4 | lc = 0.5e-1; 5 | Field[1] = Distance; 6 | Field[1].NNodesByEdge = 5000; 7 | Field[1].EdgesList = {1,2,3,4,5,7,8,9,10,11,13,14,15,16,17,19,20,21}; 8 | Field[2] = Threshold; 9 | Field[2].IField = 1; 10 | Field[2].LcMin = lc/5; 11 | Field[2].LcMax = lc; 12 | Field[2].DistMin = 1e-2; 13 | Field[2].DistMax = 2.5e-1; 14 | 15 | Field[3] = Min; 16 | Field[3].FieldsList = {2}; 17 | 18 | Background Field = 3; 19 | 20 | Mesh.CharacteristicLengthExtendFromBoundary = 0; 21 | 22 | 23 | -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/reference_pipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/reference_pipe.png -------------------------------------------------------------------------------- /demos/documented/shape_optimization/space_mapping_uniform_flow_distribution/sm_history.json: -------------------------------------------------------------------------------- 1 | { 2 | "cost_function_value": [ 3 | 0.018446680546406656, 4 | 0.002968854234065752, 5 | 1.4044251007537854e-05, 6 | 7.436794541939878e-08, 7 | 3.3125779878852174e-10, 8 | 8.482194687660224e-12 9 | ], 10 | "eps": [ 11 | 1.179960634946022, 12 | 0.5402985640019651, 13 | 0.04134590331701034, 14 | 0.0025498084692193185, 15 | 0.0001745737550440082, 16 | 3.498288550331805e-05 17 | ], 18 | "stepsize": [ 19 | 1.0, 20 | 1.0, 21 | 1.0, 22 | 1.0, 23 | 1.0, 24 | 1.0 25 | ], 26 | "MeshQuality": [ 27 | 0.46202415404612307, 28 | 0.48534105296851593, 29 | 0.4752113308318474, 30 | 0.46991474242477005, 31 | 0.47029941170390377, 32 | 0.4703210833311442 33 | ] 34 | } -------------------------------------------------------------------------------- /demos/documented/topology_optimization/cantilever/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = bfgs 6 | 7 | [LineSearch] 8 | initial_stepsize = 1e-3 9 | safeguard_stepsize = False 10 | epsilon_armijo = 1e-20 11 | 12 | [AlgoLBFGS] 13 | bfgs_periodic_restart = 3 14 | 15 | [Output] 16 | verbose = True 17 | save_results = False 18 | save_txt = False 19 | -------------------------------------------------------------------------------- /demos/documented/topology_optimization/cantilever/img_cantilever.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/topology_optimization/cantilever/img_cantilever.png -------------------------------------------------------------------------------- /demos/documented/topology_optimization/pipe_bend/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = bfgs 6 | 7 | [LineSearch] 8 | safeguard_stepsize = False 9 | 10 | [TopologyOptimization] 11 | topological_derivative_is_identical = True 12 | 13 | [Output] 14 | verbose = True 15 | save_results = False 16 | save_txt = False 17 | -------------------------------------------------------------------------------- /demos/documented/topology_optimization/pipe_bend/img_pipe_bend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/topology_optimization/pipe_bend/img_pipe_bend.png -------------------------------------------------------------------------------- /demos/documented/topology_optimization/poisson_clover/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = bfgs 6 | soft_exit = True 7 | 8 | [TopologyOptimization] 9 | topological_derivative_is_identical = True 10 | 11 | [Output] 12 | verbose = True 13 | save_results = False 14 | save_txt = False 15 | 16 | -------------------------------------------------------------------------------- /demos/documented/topology_optimization/poisson_clover/img_poisson_clover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/topology_optimization/poisson_clover/img_poisson_clover.png -------------------------------------------------------------------------------- /demos/documented/topology_optimization/projection/config.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | 4 | [OptimizationRoutine] 5 | algorithm = bfgs 6 | rtol = 1e-10 7 | soft_exit = True 8 | 9 | [LineSearch] 10 | initial_stepsize = 1e-3 11 | safeguard_stepsize = False 12 | epsilon_armijo = 1e-20 13 | 14 | [AlgoLBFGS] 15 | bfgs_periodic_restart = 3 16 | 17 | [Output] 18 | verbose = True 19 | save_results = False 20 | save_txt = False 21 | 22 | 23 | -------------------------------------------------------------------------------- /demos/documented/topology_optimization/projection/img_projection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/documented/topology_optimization/projection/img_projection.png -------------------------------------------------------------------------------- /demos/test.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | import pathlib 19 | import subprocess 20 | import sys 21 | 22 | import pytest 23 | 24 | path = pathlib.Path(__file__).resolve().parent 25 | 26 | demos = [] 27 | demo_files = list(path.glob("**/*.py")) 28 | for f in demo_files: 29 | demos.append((f.parent, f.name)) 30 | 31 | 32 | @pytest.mark.parametrize("path,name", demos) 33 | def test_demos(path, name): 34 | ret = subprocess.run([sys.executable, name], cwd=str(path), check=True) 35 | assert ret.returncode == 0 36 | -------------------------------------------------------------------------------- /demos/test_mpi.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | import pathlib 19 | import subprocess 20 | import sys 21 | 22 | import pytest 23 | 24 | path = pathlib.Path(__file__).resolve().parent 25 | 26 | demos = [] 27 | demo_files = list(path.glob("**/*.py")) 28 | for f in demo_files: 29 | demos.append((f.parent, f.name)) 30 | 31 | 32 | @pytest.mark.parametrize("path,name", demos) 33 | def test_demos(path, name): 34 | ret = subprocess.run( 35 | ["mpirun", "-n", "2", sys.executable, name], cwd=str(path), check=True 36 | ) 37 | assert ret.returncode == 0 38 | -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/different_state_adjoint_spaces/config.ini: -------------------------------------------------------------------------------- 1 | #[Mesh] 2 | #mesh_file = ../mesh/mesh.xdmf 3 | 4 | [StateSystem] 5 | is_linear = True 6 | picard_iteration = False 7 | picard_rtol = 1e-10 8 | picard_atol = 1e-12 9 | picard_iter = 10 10 | newton_atol = 1e-13 11 | newton_rtol = 1e-11 12 | picard_verbose = False 13 | 14 | [OptimizationRoutine] 15 | algorithm = lbfgs 16 | max_iter = 250 17 | rtol = 1e-3 18 | atol = 0.0 19 | gradient_method = direct 20 | gradient_tol = 1e-9 21 | soft_exit = True 22 | 23 | [LineSearch] 24 | initial_stepsize = 1.0 25 | epsilon_armijo = 1e-4 26 | beta_armijo = 2 27 | 28 | [AlgoLBFGS] 29 | bfgs_memory_size = 2 30 | use_bfgs_scaling = True 31 | 32 | [AlgoCG] 33 | cg_method = PR 34 | cg_periodic_restart = False 35 | cg_periodic_its = 5 36 | cg_relative_restart = False 37 | cg_restart_tol = 0.5 38 | 39 | [AlgoTNM] 40 | inner_newton = cg 41 | max_it_inner_newton = 50 42 | inner_newton_rtol = 1e-15 43 | inner_newton_atol = 0.0 44 | 45 | [Output] 46 | verbose = True 47 | save_results = True 48 | save_state = True 49 | -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/different_state_adjoint_spaces/history.json: -------------------------------------------------------------------------------- 1 | {"cost_function_value": [0.12434418714986063, 0.12430461140996252, 0.003266356085905667, 0.0014645241791640647, 0.000776568153649334], "gradient_norm": [1.0, 0.9998398343592984, 0.5677630549749992, 0.2772783973702079, 0.0005706056948303869], "stepsize": [1.0, 1.0, 1.0, 0.125, 1.0], "state_solves": 8, "adjoint_solves": 5, "iterations": 4} -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/different_state_adjoint_spaces/results/history.json: -------------------------------------------------------------------------------- 1 | { 2 | "stepsize": [ 3 | 1.0, 4 | 1.0, 5 | 1.0, 6 | 0.125, 7 | 1.0 8 | ], 9 | "no_state_solves": [ 10 | 1, 11 | 2, 12 | 3, 13 | 7, 14 | 8 15 | ], 16 | "no_adjoint_solves": [ 17 | 1, 18 | 2, 19 | 3, 20 | 4, 21 | 5 22 | ], 23 | "iteration": [ 24 | 0, 25 | 1, 26 | 2, 27 | 3, 28 | 4 29 | ], 30 | "gradient_norm_initial": [ 31 | 0.006291238405211239, 32 | 0.006291238405211239, 33 | 0.006291238405211239, 34 | 0.006291238405211239, 35 | 0.006291238405211239 36 | ], 37 | "relative_norm": [ 38 | 1.0, 39 | 0.9998398343592985, 40 | 0.567763054891682, 41 | 0.2772783973919194, 42 | 0.00057060569440083 43 | ], 44 | "gradient_norm": [ 45 | 0.006291238405211239, 46 | 0.006290230764981262, 47 | 0.0035719327359946067, 48 | 0.001744424502607467, 49 | 3.589816458846729e-06 50 | ], 51 | "objective_value": [ 52 | 0.12434418714986001, 53 | 0.12430461140996305, 54 | 0.0032663560851836316, 55 | 0.0014645241792191005, 56 | 0.000776568153649258 57 | ] 58 | } -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/different_state_adjoint_spaces/results/history.txt: -------------------------------------------------------------------------------- 1 | 2 | iter, cost function, rel. grad. norm, abs. grad. norm, step size 3 | 4 | 0, 1.243e-01, 1.000e+00, 6.291e-03, 5 | 6 | 1, 1.243e-01, 9.998e-01, 6.290e-03, 1.000e+00 7 | 2, 3.266e-03, 5.678e-01, 3.572e-03, 1.000e+00 8 | 3, 1.465e-03, 2.773e-01, 1.744e-03, 1.250e-01 9 | 4, 7.766e-04, 5.706e-04, 3.590e-06, 1.000e+00 10 | 11 | Optimization was successful. 12 | Statistics: 13 | total iterations: 4 14 | final objective value: 7.766e-04 15 | final gradient norm: 5.706e-04 16 | total number of state systems solved: 8 17 | total number of adjoint systems solved: 5 18 | -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/dirichlet_control_via_lagrange_multiplier/config.ini: -------------------------------------------------------------------------------- 1 | #[Mesh] 2 | #mesh_file = ../mesh/mesh.xdmf 3 | 4 | [StateSystem] 5 | is_linear = True 6 | newton_atol = 1e-13 7 | newton_rtol = 1e-11 8 | newton_damped = True 9 | newton_inexact = False 10 | newton_verbose = False 11 | newton_iter = 50 12 | picard_iteration = False 13 | picard_rtol = 1e-10 14 | picard_atol = 1e-12 15 | picard_iter = 10 16 | picard_verbose = False 17 | 18 | [OptimizationRoutine] 19 | algorithm = lbfgs 20 | max_iter = 250 21 | rtol = 5e-2 22 | atol = 0.0 23 | gradient_method = direct 24 | gradient_tol = 1e-9 25 | soft_exit = True 26 | 27 | [LineSearch] 28 | initial_stepsize = 1.0 29 | safeguard_stepsize = True 30 | epsilon_armijo = 1e-4 31 | beta_armijo = 2 32 | 33 | [AlgoLBFGS] 34 | bfgs_memory_size = 3 35 | use_bfgs_scaling = True 36 | 37 | [AlgoCG] 38 | cg_method = PR 39 | cg_periodic_restart = False 40 | cg_periodic_its = 5 41 | cg_relative_restart = False 42 | cg_restart_tol = 0.5 43 | 44 | [AlgoTNM] 45 | inner_newton = cg 46 | max_it_inner_newton = 100 47 | inner_newton_rtol = 1e-15 48 | inner_newton_atol = 0.0 49 | 50 | [Output] 51 | verbose = True 52 | save_results = False 53 | save_txt = False 54 | save_state = False 55 | save_adjoint = False 56 | save_gradient = False 57 | result_dir = ./ 58 | time_suffix = False 59 | -------------------------------------------------------------------------------- /demos/undocumented/optimal_control/dirichlet_control_via_lagrange_multiplier/img_dirichlet_control_via_lagrange_multiplier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/undocumented/optimal_control/dirichlet_control_via_lagrange_multiplier/img_dirichlet_control_via_lagrange_multiplier.png -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/custom_functional/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/custom_functional/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/undocumented/shape_optimization/custom_functional/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/custom_functional/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/custom_functional/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/undocumented/shape_optimization/custom_functional/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/custom_functional/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/config.ini: -------------------------------------------------------------------------------- 1 | #[Mesh] 2 | #mesh_file = ../mesh/mesh.xdmf 3 | 4 | [StateSystem] 5 | is_linear = false 6 | picard_iteration = false 7 | picard_rtol = 1e-10 8 | picard_atol = 1e-12 9 | picard_iter = 10 10 | newton_atol = 1e-13 11 | newton_rtol = 1e-11 12 | newton_damped = True 13 | newton_verbose = False 14 | picard_verbose = false 15 | 16 | [OptimizationRoutine] 17 | algorithm = lbfgs 18 | max_iter = 50 19 | rtol = 5e-4 20 | atol = 0.0 21 | gradient_method = direct 22 | gradient_tol = 1e-9 23 | soft_exit = true 24 | 25 | [LineSearch] 26 | initial_stepsize = 5e-3 27 | epsilon_armijo = 1e-4 28 | beta_armijo = 2 29 | 30 | [AlgoLBFGS] 31 | bfgs_memory_size = 5 32 | use_bfgs_scaling = true 33 | 34 | [AlgoCG] 35 | cg_method = DY 36 | cg_periodic_restart = false 37 | cg_periodic_its = 10 38 | cg_relative_restart = true 39 | cg_restart_tol = 0.25 40 | 41 | [ShapeGradient] 42 | shape_bdry_def = [4] 43 | shape_bdry_fix = [1,2,3] 44 | lambda_lame = 0.0 45 | damping_factor = 0.0 46 | mu_fix = 1 47 | mu_def = 1 48 | inhomogeneous = False 49 | 50 | [Regularization] 51 | factor_volume = 1.0 52 | target_volume = 0.0 53 | use_initial_volume = True 54 | factor_surface = 0.0 55 | target_surface = 0.0 56 | use_initial_surface = True 57 | factor_barycenter = 0.0 58 | target_barycenter = [0.0, 0.0, 0.0] 59 | use_initial_barycenter = True 60 | 61 | [MeshQuality] 62 | angle_change = inf 63 | volume_change = inf 64 | 65 | [Output] 66 | verbose = true 67 | save_results = true 68 | save_state = false 69 | -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/history.json: -------------------------------------------------------------------------------- 1 | {"cost_function_value": [0.9402629412748323, 0.8872662980139608, 0.7179042735637045, 0.663097210130689, 0.6078865654161332, 0.5553725774603613, 0.4958623310463858, 0.45542715107140747, 0.453870184993088, 0.4380974306335549, 0.4370013077232182, 0.4354969440023711, 0.43441784217324586, 0.4338834684931839, 0.43366474679498007, 0.4336089128953991, 0.4333213513570688, 0.43313984038099973, 0.43308707885827563, 0.43306382305389235, 0.43302379462763474, 0.4329964065841464, 0.4329703766419803, 0.4329603822827913, 0.4329582303460143, 0.43294344788230593, 0.43294327853050396, 0.43293927194639403, 0.43293771384568697, 0.4329336343288233, 0.43292768889235583, 0.4329264164602711], "gradient_norm": [1.0, 0.8260093938669778, 0.2967531561190647, 0.1798197524253351, 0.10319760253398844, 0.08522141163085976, 0.21459709051410156, 0.06932964108270863, 0.11823118867815453, 0.032235764979274724, 0.018323897870872432, 0.012939281797466605, 0.00878965071882285, 0.030101637158179116, 0.015381824849372854, 0.011877577750953909, 0.005485473225097383, 0.005031325933495513, 0.0034247931713050285, 0.002409970869370998, 0.0021399708370556797, 0.0017606949445721984, 0.0015088211790733655, 0.002147697398792426, 0.0016859398018190409, 0.0009888158586740985, 0.0022144743986771214, 0.0008364950935814677, 0.0006021363497701607, 0.0005879905429812695, 0.0006405451383512465, 0.0004996548904323804], "stepsize": [1.0, 0.005, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 3.814697265625e-06, 0.0078125, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 0.5, 0.125], "MeshQuality": [0.2660408205050946, 0.26633767441292566, 0.2657664569641771, 0.2561659810341238, 0.24486803984634353, 0.23161053187961744, 0.19578961737268785, 0.04173199247535786, 0.0842779033488934, 0.004511734457151029, 0.027666775582933734, 0.029752984119056913, 0.0365270938392912, 0.0007699601125396027, 0.005783000541462857, 0.015535788578021292, 0.020601908846801353, 0.023358197906280687, 0.024548337474395998, 0.023304977774420643, 0.018408220394519947, 0.011327908445126544, 0.006836321052496541, 0.0014513008708531006, 0.006891757076208815, 0.0044061661690508735, 0.0022274055208387766, 0.0024165817994240557, 0.003516572279941066, 0.003181232770512965, 0.0007904879984890201, 0.0002797089326430635], "initial_gradient_norm": 3.407842207984091, "state_solves": 37, "adjoint_solves": 32, "iterations": 31} -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 3.75e-2; 2 | 3 | Point(1) = {0, 0, 0, lc}; 4 | Point(2) = {1.5, 0, 0, lc}; 5 | Point(3) = {4, 0, 0, lc}; 6 | Point(4) = {4.75, 0.5, 0, lc}; 7 | Point(5) = {6.125, 2.75, 0, lc}; 8 | Point(6) = {7.5, 5, 0, lc}; 9 | Point(7) = {12, 5, 0, lc}; 10 | Point(8) = {15, 5, 0, lc}; 11 | Point(9) = {15, 6, 0, lc}; 12 | Point(10) = {12, 6, 0, lc}; 13 | Point(11) = {7.5, 6, 0, lc}; 14 | Point(12) = {6.75, 5.5, 0, lc}; 15 | Point(13) = {5.375, 3.25, 0, lc}; 16 | Point(14) = {4, 1, 0, lc}; 17 | Point(15) = {1.5, 1, 0, lc}; 18 | Point(16) = {0, 1, 0, lc}; 19 | 20 | Line(1) = {1,2}; 21 | Line(2) = {2,3}; 22 | Line(3) = {3,4}; 23 | Line(4) = {4,5}; 24 | Line(5) = {5,6}; 25 | Line(6) = {6,7}; 26 | Line(7) = {7,8}; 27 | Line(8) = {8,9}; 28 | Line(9) = {9,10}; 29 | Line(10) = {10,11}; 30 | Line(11) = {11,12}; 31 | Line(12) = {12,13}; 32 | Line(13) = {13,14}; 33 | Line(14) = {14,15}; 34 | Line(15) = {15,16}; 35 | Line(16) = {16,1}; 36 | 37 | Line Loop(1) = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; 38 | 39 | Plane Surface(1) = {1}; 40 | 41 | Physical Surface(1) = {1}; 42 | Physical Line(1) = {16}; 43 | Physical Line(2) = {1,7,9,15}; 44 | Physical Line(3) = {8}; 45 | Physical Line(4) = {2,3,4,5,6,9,10,11,12,13,14}; 46 | 47 | 48 | Field[1] = Distance; 49 | Field[1].NNodesByEdge = 1000; 50 | Field[1].NodesList = {5, 12}; 51 | Field[1].EdgesList = {4,6,10,13}; 52 | Field[2] = Threshold; 53 | Field[2].IField = 1; 54 | Field[2].LcMin = lc/5; 55 | Field[2].LcMax = lc; 56 | Field[2].DistMin = 1e-2; 57 | Field[2].DistMax = 1e0; 58 | 59 | //Background Field = 2; 60 | //Mesh.CharacteristicLengthExtendFromBoundary= 0; 61 | -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh.h5 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /demos/undocumented/shape_optimization/pipe_optimization/pipe_optimization.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | from fenics import * 19 | 20 | import cashocs 21 | 22 | # load the config 23 | config = cashocs.load_config("./config.ini") 24 | # define the Reynold's number 25 | Re = 350.0 26 | 27 | # import the mesh and geometry 28 | mesh, subdomains, boundaries, dx, ds, dS = cashocs.import_mesh("./mesh/mesh.xdmf") 29 | 30 | # set up the function space 31 | v_elem = VectorElement("CG", mesh.ufl_cell(), 2, dim=2) 32 | p_elem = FiniteElement("CG", mesh.ufl_cell(), 1) 33 | space = FunctionSpace(mesh, MixedElement([v_elem, p_elem])) 34 | 35 | # define boundary conditions 36 | v_in = Expression(("-6*(x[1] - 1)*(x[1] + 0)", "0.0"), degree=2) 37 | bc_in = DirichletBC(space.sub(0), v_in, boundaries, 1) 38 | bc_wall = DirichletBC(space.sub(0), Constant((0, 0)), boundaries, 2) 39 | bc_gamma = DirichletBC(space.sub(0), Constant((0, 0)), boundaries, 4) 40 | bcs = [bc_in, bc_wall, bc_gamma] 41 | 42 | # set up state and adjoint variables 43 | up = Function(space) 44 | u, p = split(up) 45 | vq = Function(space) 46 | v, q = split(vq) 47 | 48 | # define the PDE constraint 49 | e = ( 50 | Constant(1 / Re) * inner(grad(u), grad(v)) * dx 51 | + inner(grad(u) * u, v) * dx 52 | - p * div(v) * dx 53 | - q * div(u) * dx 54 | ) 55 | 56 | # set up the cost functional 57 | J = cashocs.IntegralFunctional(Constant(1 / Re) * inner(grad(u), grad(u)) * dx) 58 | 59 | # define the optimization problem and solve it 60 | optimization_problem = cashocs.ShapeOptimizationProblem( 61 | e, bcs, J, up, vq, boundaries, config=config 62 | ) 63 | optimization_problem.solve() 64 | -------------------------------------------------------------------------------- /demos/undocumented/solvers/fieldsplit_nesting.py: -------------------------------------------------------------------------------- 1 | from fenics import * 2 | 3 | import cashocs 4 | 5 | mesh, subdomains, boundaries, dx, ds, dS = cashocs.regular_mesh(16) 6 | v_elem = VectorElement("CG", mesh.ufl_cell(), 2) 7 | p_elem = FiniteElement("CG", mesh.ufl_cell(), 1) 8 | V = FunctionSpace(mesh, MixedElement(v_elem, p_elem, p_elem)) 9 | # order of the MixedElement determines (single) prefixes for PETSc solver 10 | # velocity block gets 0, pressure 1, and temperature 2 11 | 12 | upT = Function(V) 13 | u, p, T = split(upT) 14 | v, q, S = TestFunctions(V) 15 | 16 | mu = 1.0 / (T + 1) 17 | 18 | F = ( 19 | mu * inner(grad(u), grad(v)) * dx 20 | + dot(grad(u) * u, v) * dx 21 | - p * div(v) * dx 22 | - q * div(u) * dx 23 | + dot(grad(T), grad(S)) * dx 24 | + dot(u, grad(T)) * S * dx 25 | - Constant(100.0) * S * dx 26 | ) 27 | u_in = Expression(("4.0 * x[1] * (1.0 - x[1])", "0.0"), degree=2) 28 | bcs = cashocs.create_dirichlet_bcs(V.sub(0), u_in, boundaries, 1) 29 | bcs += cashocs.create_dirichlet_bcs(V.sub(0), Constant((0.0, 0.0)), boundaries, [3, 4]) 30 | bcs += cashocs.create_dirichlet_bcs(V.sub(2), Constant(1.0), boundaries, [1, 3, 4]) 31 | 32 | petsc_options = { 33 | "snes_type": "newtonls", 34 | "snes_monitor": None, 35 | "snes_max_it": 7, 36 | "ksp_type": "fgmres", 37 | "ksp_rtol": 1e-1, 38 | "pc_type": "fieldsplit", 39 | "pc_fieldsplit_type": "multiplicative", 40 | "pc_fieldsplit_0_fields": "0,1", # will get prefix fieldsplit_0_ 41 | "pc_fieldsplit_1_fields": "2", # will get prefix fieldsplit_2_ 42 | "fieldsplit_0_ksp_type": "fgmres", 43 | "fieldsplit_0_ksp_rtol": 1e-1, 44 | "fieldsplit_0_pc_type": "fieldsplit", # sub fields get global (mixed) index 45 | "fieldsplit_0_pc_fieldsplit_type": "schur", 46 | "fieldsplit_0_pc_fieldsplit_schur_precondition": "selfp", 47 | "fieldsplit_0_fieldsplit_0_ksp_type": "preonly", 48 | "fieldsplit_0_fieldsplit_0_pc_type": "lu", 49 | "fieldsplit_0_fieldsplit_1_ksp_type": "gmres", 50 | "fieldsplit_0_fieldsplit_1_ksp_rtol": 1e-1, 51 | "fieldsplit_0_fieldsplit_1_pc_type": "hypre", 52 | "fieldsplit_0_fieldsplit_1_ksp_converged_reason": None, 53 | "fieldsplit_2_ksp_type": "gmres", 54 | "fieldsplit_2_ksp_rtol": 1e-1, 55 | "fieldsplit_2_pc_type": "hypre", 56 | } 57 | 58 | cashocs.snes_solve(F, upT, bcs, petsc_options=petsc_options, max_iter=8) 59 | u, p, T = upT.split(True) 60 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.22.2 2 | matplotlib 3 | scipy==1.15.2 4 | Sphinx==8.2.3 5 | sphinx-argparse==0.5.2 6 | sphinx-copybutton==0.5.2 7 | meshio==5.3.5 8 | docutils==0.21.2 9 | pydata-sphinx-theme==0.16.1 10 | sphinx-design==0.6.1 11 | typing_extensions 12 | myst-parser==4.0.1 13 | jupytext==1.17.2 14 | sphinx-favicon==1.0.1 15 | matplotlib 16 | -------------------------------------------------------------------------------- /docs/source/_static/favicon/favicon-16x16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/docs/source/_static/favicon/favicon-16x16.jpg -------------------------------------------------------------------------------- /docs/source/_static/favicon/favicon-32x32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/docs/source/_static/favicon/favicon-32x32.jpg -------------------------------------------------------------------------------- /docs/source/_static/version_switcher.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "dev", 4 | "version": "dev", 5 | "url": "https://cashocs.readthedocs.io/en/latest/" 6 | }, 7 | { 8 | "name": "2.5 (stable)", 9 | "version": "2.5.1", 10 | "url": "https://cashocs.readthedocs.io/en/stable/", 11 | "preferred": true 12 | }, 13 | { 14 | "name": "2.4", 15 | "version": "2.4.3", 16 | "url": "https://cashocs.readthedocs.io/en/v2.4.3/" 17 | }, 18 | { 19 | "name": "2.3", 20 | "version": "2.3.3", 21 | "url": "https://cashocs.readthedocs.io/en/v2.3.3/" 22 | }, 23 | { 24 | "name": "2.2", 25 | "version": "2.2.0", 26 | "url": "https://cashocs.readthedocs.io/en/v2.2.0/" 27 | }, 28 | { 29 | "name": "2.1", 30 | "version": "2.1.4", 31 | "url": "https://cashocs.readthedocs.io/en/v2.1.4/" 32 | }, 33 | { 34 | "name": "2.0", 35 | "version": "2.0.14", 36 | "url": "https://cashocs.readthedocs.io/en/v2.0.14/" 37 | }, 38 | { 39 | "name": "1.8", 40 | "version": "1.8.12", 41 | "url": "https://cashocs.readthedocs.io/en/v1.8.12/" 42 | }, 43 | { 44 | "version": "1.7", 45 | "url": "https://cashocs.readthedocs.io/en/v1.7.8/" 46 | }, 47 | { 48 | "version": "1.6", 49 | "url": "https://cashocs.readthedocs.io/en/v1.6.1/" 50 | }, 51 | { 52 | "version": "1.5", 53 | "url": "https://cashocs.readthedocs.io/en/v1.5.15/" 54 | }, 55 | { 56 | "version": "1.4", 57 | "url": "https://cashocs.readthedocs.io/en/v1.4.8/" 58 | }, 59 | { 60 | "version": "1.3", 61 | "url": "https://cashocs.readthedocs.io/en/v1.3.4/" 62 | }, 63 | { 64 | "version": "1.2", 65 | "url": "https://cashocs.readthedocs.io/en/v1.2.1/" 66 | }, 67 | { 68 | "version": "1.1", 69 | "url": "https://cashocs.readthedocs.io/en/v1.1.1/" 70 | }, 71 | { 72 | "version": "1.0", 73 | "url": "https://cashocs.readthedocs.io/en/v1.0.4/" 74 | } 75 | ] -------------------------------------------------------------------------------- /docs/source/_templates/autosummary/class.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | escape | underline}} 2 | 3 | .. currentmodule:: {{ module }} 4 | 5 | .. autoclass:: {{ objname }} 6 | 7 | {% block methods_summary %} 8 | {% if methods %} 9 | 10 | {% for item in ['__new__', '__init__'] %} 11 | {% if item in methods %} 12 | {% set dummy = methods.remove(item) %} 13 | {% endif %} 14 | {% endfor %} 15 | {% endif %} 16 | 17 | {% if methods %} 18 | .. rubric:: {{ _('Methods Summary') }} 19 | 20 | .. autosummary:: 21 | {% for item in methods %} 22 | ~{{ name }}.{{ item }} 23 | {%- endfor %} 24 | {% endif %} 25 | {% endblock %} 26 | 27 | {% block attributes_summary %} 28 | {% if attributes %} 29 | .. rubric:: {{ _('Attributes Summary') }} 30 | 31 | .. autosummary:: 32 | {% for item in attributes %} 33 | ~{{ name }}.{{ item }} 34 | {%- endfor %} 35 | {% endif %} 36 | {% endblock %} 37 | 38 | {% block methods_documentation %} 39 | {% if methods %} 40 | .. rubric:: {{ _('Methods Documentation') }} 41 | {% for item in methods %} 42 | .. automethod:: {{ item }} 43 | {% endfor %} 44 | {% endif %} 45 | {% endblock %} 46 | 47 | {% block attributes_documentation %} 48 | {% if attributes %} 49 | .. rubric:: {{ _('Attributes Documentation') }} 50 | {% for item in attributes %} 51 | .. autoattribute:: {{ item }} 52 | {% endfor %} 53 | {% endif %} 54 | {% endblock %} 55 | -------------------------------------------------------------------------------- /docs/source/_templates/autosummary/module.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | escape | underline}} 2 | 3 | .. automodule:: {{ fullname }} 4 | 5 | {% block attributes %} 6 | {%- if attributes %} 7 | .. rubric:: {{ _('Module Attributes') }} 8 | 9 | .. autosummary:: 10 | {% for item in attributes %} 11 | {{ item }} 12 | {%- endfor %} 13 | {% endif %} 14 | {%- endblock %} 15 | 16 | {%- block functions %} 17 | {%- if functions %} 18 | .. rubric:: {{ _('Functions') }} 19 | 20 | .. autosummary:: 21 | :toctree: 22 | {% for item in functions %} 23 | {{ item }} 24 | {%- endfor %} 25 | {% endif %} 26 | {%- endblock %} 27 | 28 | {%- block classes %} 29 | {%- if classes %} 30 | .. rubric:: {{ _('Classes') }} 31 | 32 | .. autosummary:: 33 | :toctree: 34 | {% for item in classes %} 35 | {{ item }} 36 | {%- endfor %} 37 | {% endif %} 38 | {%- endblock %} 39 | 40 | {%- block exceptions %} 41 | {%- if exceptions %} 42 | .. rubric:: {{ _('Exceptions') }} 43 | 44 | .. autosummary:: 45 | {% for item in exceptions %} 46 | {{ item }} 47 | {%- endfor %} 48 | {% endif %} 49 | {%- endblock %} 50 | 51 | {%- block modules %} 52 | {%- if modules %} 53 | .. rubric:: Modules 54 | 55 | .. autosummary:: 56 | :toctree: 57 | :recursive: 58 | {% for item in modules %} 59 | {{ item }} 60 | {%- endfor %} 61 | {% endif %} 62 | {%- endblock %} 63 | -------------------------------------------------------------------------------- /docs/source/about/contact.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../../README.rst 2 | :start-after: readme_start_about 3 | :end-before: readme_end_about 4 | -------------------------------------------------------------------------------- /docs/source/about/index.rst: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | The pages below provide a basic overview over cashocs, how to install and cite it, license information, and the history of the package. 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | installation 10 | nutshell 11 | citing 12 | license 13 | contact 14 | -------------------------------------------------------------------------------- /docs/source/about/installation.rst: -------------------------------------------------------------------------------- 1 | .. _installation_instructions: 2 | 3 | .. include:: ../../../README.rst 4 | :start-after: readme_start_installation 5 | :end-before: readme_end_installation 6 | -------------------------------------------------------------------------------- /docs/source/about/license.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../../README.rst 2 | :start-after: readme_start_license 3 | :end-before: readme_end_license 4 | -------------------------------------------------------------------------------- /docs/source/api/index.rst: -------------------------------------------------------------------------------- 1 | cashocs API Reference 2 | ===================== 3 | 4 | Below you find the documented public API of cashocs. 5 | 6 | .. autosummary:: 7 | :toctree: generated 8 | :recursive: 9 | 10 | cashocs 11 | 12 | .. note:: 13 | 14 | Below, you will find only the public API of cashocs. However, cashocs also has a 15 | private API. The way python is structured does not allow to make attributes / 16 | modules, etc. private. We use the definition that every function, class, or module 17 | starting with a leading underscore ``_`` is private. The contents of every private 18 | module are also assumed to be private, as are, e.g., all attributes and methods of 19 | a private class. Additionally, every object starting with two leading underscores 20 | ``__`` is also assumed to private and uses python's name mangling to protect 21 | unintended access. 22 | 23 | .. warning:: 24 | 25 | Users should not use private objects, functions, methods, classes, or modules. 26 | Doing so can lead to unintended behavior, errors, and can break the code. 27 | Moreover, we are trying to make cashocs public API stable and document all changes 28 | made to the public API. There is no warranty that the private API stays the same 29 | and changes to it are not documented. 30 | 31 | .. note:: 32 | 33 | However, cashocs private API is also documented as a help for users to understand 34 | what is going on beneath the surface and for developers to allow for easier 35 | contribution. You can find the private API in cashocs' source code, which can be 36 | easily found and viewed by most IDEs nowadays. 37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/source/cashocs_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/docs/source/cashocs_banner.jpg -------------------------------------------------------------------------------- /docs/source/cli/generated/cashocs._cli._convert.rst: -------------------------------------------------------------------------------- 1 | cashocs-convert 2 | ############### 3 | 4 | .. argparse:: 5 | :module: cashocs._cli._convert 6 | :func: _generate_parser 7 | :prog: cashocs-convert 8 | -------------------------------------------------------------------------------- /docs/source/cli/generated/cashocs._cli._extract_mesh.rst: -------------------------------------------------------------------------------- 1 | cashocs-extract_mesh 2 | #################### 3 | 4 | .. argparse:: 5 | :module: cashocs._cli._extract_mesh 6 | :func: _generate_parser 7 | :prog: cashocs-extract_mesh 8 | -------------------------------------------------------------------------------- /docs/source/cli/index.rst: -------------------------------------------------------------------------------- 1 | cashocs CLI Reference 2 | ##################### 3 | 4 | Below you find the documentation of the command line interface (CLI) of cashocs. These are installed alongside cashocs 5 | and can be used from a terminal / shell. 6 | 7 | 8 | .. toctree:: 9 | :maxdepth: 1 10 | :glob: 11 | 12 | generated/* 13 | -------------------------------------------------------------------------------- /docs/source/development/code_of_conduct.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../../CODE_OF_CONDUCT.rst 2 | -------------------------------------------------------------------------------- /docs/source/development/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/source/development/index.rst: -------------------------------------------------------------------------------- 1 | Contributing to cashocs 2 | ======================= 3 | 4 | Below you can find details on how you can contribute to cashocs. 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | contributing 10 | code_of_conduct 11 | -------------------------------------------------------------------------------- /docs/source/docutils.conf: -------------------------------------------------------------------------------- 1 | [restructuredtext parser] 2 | syntax_highlight = short 3 | -------------------------------------------------------------------------------- /docs/source/global.rst: -------------------------------------------------------------------------------- 1 | .. role:: ini(code) 2 | :language: ini 3 | :class: highlight 4 | 5 | .. role:: python(code) 6 | :language: python 7 | :class: highlight 8 | 9 | .. role:: cpp(code) 10 | :language: cpp 11 | :class: highlight 12 | 13 | .. role:: bash(code) 14 | :language: bash 15 | :class: highlight 16 | -------------------------------------------------------------------------------- /docs/source/icons/api.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/icons/development.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/icons/getting_started.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/icons/user_guide.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/jupytext_process.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | import pathlib 19 | 20 | import jupytext 21 | 22 | 23 | def process(): 24 | """Convert light format demo Python files into MyST flavoured markdown and 25 | ipynb using Jupytext. These files can then be included in Sphinx 26 | documentation""" 27 | # Directories to scan 28 | subdirs = [pathlib.Path("../../demos/documented")] 29 | 30 | # Iterate over subdirectories containing demos 31 | for subdir in subdirs: 32 | # Make demo doc directory 33 | demo_dir = pathlib.Path("./user/demos") 34 | demo_dir.mkdir(parents=True, exist_ok=True) 35 | 36 | # Process each demo using jupytext/myst 37 | for demo in subdir.glob("**/demo*.py"): 38 | # for demo in subdir.glob("**/demo_space_mapping_semilinear_transmission.py"): 39 | python_demo = jupytext.read(demo) 40 | myst_text = jupytext.writes(python_demo, fmt="myst") 41 | 42 | # myst-parser does not process blocks with {code-cell} 43 | myst_text = myst_text.replace("{code-cell}", "python") 44 | myst_file = (demo_dir / demo.parent.parent.name / demo.name).with_suffix( 45 | ".md" 46 | ) 47 | with open(myst_file, "w") as fw: 48 | fw.write(myst_text) 49 | 50 | 51 | if __name__ == "__main__": 52 | process() 53 | -------------------------------------------------------------------------------- /docs/source/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/docs/source/logo.jpg -------------------------------------------------------------------------------- /docs/source/release_notes.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../CHANGELOG.rst 2 | -------------------------------------------------------------------------------- /docs/source/user/demos/cashocs_as_solver/index.rst: -------------------------------------------------------------------------------- 1 | Using cashocs as a solver 2 | ========================= 3 | 4 | Here, we showcase that one can use cashocs optimization routines without its 5 | automatic derivation of adjoint systems and (shape) derivatives, where the user 6 | can choose to supply these forms themselves. 7 | 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Corresponding Demos: 12 | 13 | demo_control_solver.md 14 | demo_shape_solver.md 15 | -------------------------------------------------------------------------------- /docs/source/user/demos/misc/index.rst: -------------------------------------------------------------------------------- 1 | Miscellaneous Topics 2 | ==================== 3 | 4 | In this part of the tutorial, we showcase several other features of cashocs, which do not necessarily have to do with optimization, but are related, e.g., to geometry, meshing, i/o, visualization, etc. 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | :caption: List of all miscellaneous tutorials: 9 | 10 | demo_logging.md 11 | demo_xdmf_io.md 12 | demo_mpi_comm_self.md 13 | demo_mpi_custom.md 14 | -------------------------------------------------------------------------------- /docs/source/user/demos/optimal_control/index.rst: -------------------------------------------------------------------------------- 1 | Optimal Control Problems 2 | ======================== 3 | 4 | In this part of the tutorial, we investigate how optimal control problems can 5 | be treated with cashocs. 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | :caption: List of all optimal control demos: 10 | 11 | demo_poisson.md 12 | doc_config 13 | demo_box_constraints.md 14 | demo_neumann_control.md 15 | demo_multiple_variables.md 16 | demo_monolithic_problems.md 17 | demo_picard_iteration.md 18 | demo_stokes.md 19 | demo_heat_equation.md 20 | demo_nonlinear_pdes.md 21 | demo_dirichlet_control.md 22 | demo_iterative_solvers.md 23 | demo_state_constraints.md 24 | demo_sparse_control.md 25 | demo_scalar_control_tracking.md 26 | demo_constraints.md 27 | demo_control_boundary_conditions.md 28 | demo_pre_post_callbacks.md 29 | -------------------------------------------------------------------------------- /docs/source/user/demos/shape_optimization/index.rst: -------------------------------------------------------------------------------- 1 | Shape Optimization Problems 2 | =========================== 3 | 4 | In this part of the tutorial, we investigate how shape optimization problems can 5 | be treated with cashocs. 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | :caption: List of all shape optimization demos: 10 | 11 | demo_shape_poisson.md 12 | doc_config 13 | demo_regularization.md 14 | demo_inverse_tomography.md 15 | demo_shape_stokes.md 16 | demo_remeshing.md 17 | demo_custom_scalar_product.md 18 | demo_scaling.md 19 | demo_prescribed_mu.md 20 | demo_p_laplacian.md 21 | demo_space_mapping_semilinear_transmission.md 22 | demo_space_mapping_uniform_flow_distribution.md 23 | demo_pseudo_time_stepping 24 | -------------------------------------------------------------------------------- /docs/source/user/demos/topology_optimization/index.rst: -------------------------------------------------------------------------------- 1 | Topology Optimization Problems 2 | ============================== 3 | 4 | In this part of the tutorial, we investigate how topology optimization problems can 5 | be treated with cashocs. 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | :caption: List of all topology optimization demos: 10 | 11 | demo_poisson_clover.md 12 | doc_config 13 | demo_cantilever.md 14 | demo_pipe_bend.md 15 | demo_projection.md 16 | 17 | 18 | .. note:: 19 | 20 | As topology optimization problems are very involved from a theoretical point of view, it is, at the moment, not possible to automatically derive topological derivatives. Therefore, cashocs cannot be used as "black-box" solver for topology optimization problems in general. 21 | 22 | Moreover, our framework for topology optimization of using a level-set function is quite flexible, but requires a lot of theoretical understanding. In :ref:`demo_poisson_clover`, we briefly go over some theoretical foundations required for using cashocs' topology optimization features. We refer the reader, e.g., to `Sokolowski and Novotny - Topological Derivatives in Shape Optimization `_ for an exhaustive treatment of these topics. 23 | -------------------------------------------------------------------------------- /logos/cashocs_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/logos/cashocs_banner.jpg -------------------------------------------------------------------------------- /logos/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/logos/logo.jpg -------------------------------------------------------------------------------- /tests/config_ocp.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | newton_atol = 1e-13 4 | newton_rtol = 1e-11 5 | newton_damped = True 6 | newton_verbose = False 7 | newton_iter = 50 8 | 9 | [OptimizationRoutine] 10 | algorithm = lbfgs 11 | soft_exit = False 12 | 13 | [AlgoLBFGS] 14 | bfgs_memory_size = 3 15 | use_bfgs_scaling = True 16 | 17 | [AlgoCG] 18 | cg_method = PR 19 | cg_periodic_restart = False 20 | cg_periodic_its = 5 21 | cg_relative_restart = False 22 | cg_restart_tol = 0.5 23 | 24 | [AlgoTNM] 25 | inner_newton = cg 26 | max_it_inner_newton = 20 27 | inner_newton_rtol = 1e-7 28 | inner_newton_atol = 0.0 29 | 30 | [Output] 31 | verbose = True 32 | save_results = False 33 | save_txt = False 34 | save_state = False 35 | -------------------------------------------------------------------------------- /tests/config_ocsm.ini: -------------------------------------------------------------------------------- 1 | [Mesh] 2 | #mesh_file = ../mesh/mesh.xdmf 3 | 4 | [StateSystem] 5 | is_linear = True 6 | newton_rtol = 1e-11 7 | newton_atol = 1e-13 8 | newton_iter = 50 9 | newton_damped = True 10 | newton_verbose = False 11 | picard_iteration = False 12 | picard_rtol = 1e-10 13 | picard_atol = 1e-12 14 | picard_iter = 10 15 | picard_verbose = False 16 | 17 | [OptimizationRoutine] 18 | algorithm = lbfgs 19 | rtol = 1e-3 20 | atol = 0.0 21 | max_iter = 250 22 | soft_exit = False 23 | 24 | [LineSearch] 25 | initial_stepsize = 1e0 26 | epsilon_armijo = 1e-4 27 | beta_armijo = 2 28 | 29 | [AlgoLBFGS] 30 | bfgs_memory_size = 5 31 | use_bfgs_scaling = True 32 | 33 | [AlgoCG] 34 | cg_method = PR 35 | cg_periodic_restart = False 36 | cg_periodic_its = 5 37 | cg_relative_restart = False 38 | cg_restart_tol = 0.5 39 | 40 | [AlgoTNM] 41 | inner_newton = cg 42 | max_it_inner_newton = 100 43 | inner_newton_rtol = 1e-15 44 | 45 | [Output] 46 | verbose = False 47 | save_results = False 48 | save_txt = False 49 | save_state = False 50 | save_adjoint = False 51 | save_gradient = False 52 | result_dir = ./ 53 | -------------------------------------------------------------------------------- /tests/config_picard.ini: -------------------------------------------------------------------------------- 1 | [StateSystem] 2 | is_linear = True 3 | newton_atol = 1e-15 4 | newton_rtol = 1e-13 5 | newton_damped = True 6 | newton_verbose = False 7 | newton_iter = 50 8 | picard_iteration = True 9 | picard_rtol = 1e-14 10 | picard_atol = 1e-14 11 | picard_iter = 25 12 | picard_verbose = False 13 | 14 | [OptimizationRoutine] 15 | algorithm = lbfgs 16 | max_iter = 250 17 | rtol = 1e-4 18 | atol = 0.0 19 | soft_exit = False 20 | 21 | [LineSearch] 22 | initial_stepsize = 1.0 23 | epsilon_armijo = 1e-4 24 | beta_armijo = 2 25 | 26 | [AlgoLBFGS] 27 | bfgs_memory_size = 2 28 | use_bfgs_scaling = True 29 | 30 | [AlgoCG] 31 | cg_method = PR 32 | cg_periodic_restart = False 33 | cg_periodic_its = 5 34 | cg_relative_restart = False 35 | cg_restart_tol = 0.5 36 | 37 | [AlgoTNM] 38 | inner_newton = cg 39 | max_it_inner_newton = 20 40 | inner_newton_rtol = 1e-7 41 | inner_newton_atol = 0.0 42 | 43 | [Output] 44 | verbose = True 45 | save_txt = False 46 | save_results = False 47 | save_state = False 48 | -------------------------------------------------------------------------------- /tests/config_remesh.ini: -------------------------------------------------------------------------------- 1 | [Mesh] 2 | gmsh_file = ./mesh/mesh.msh 3 | geo_file = ./mesh/mesh.geo 4 | remesh = True 5 | show_gmsh_output = True 6 | 7 | [StateSystem] 8 | is_linear = True 9 | picard_iteration = False 10 | picard_rtol = 1e-10 11 | picard_atol = 1e-12 12 | picard_iter = 10 13 | newton_atol = 1e-13 14 | newton_rtol = 1e-11 15 | picard_verbose = False 16 | 17 | [OptimizationRoutine] 18 | algorithm = lbfgs 19 | max_iter = 50 20 | rtol = 1e-2 21 | atol = 0.0 22 | soft_exit = True 23 | 24 | [LineSearch] 25 | initial_stepsize = 1.0 26 | epsilon_armijo = 1e-4 27 | beta_armijo = 2 28 | 29 | [AlgoLBFGS] 30 | bfgs_memory_size = 3 31 | use_bfgs_scaling = True 32 | 33 | [AlgoCG] 34 | cg_method = DY 35 | cg_periodic_restart = False 36 | cg_periodic_its = 5 37 | cg_relative_restart = False 38 | cg_restart_tol = 0.5 39 | 40 | [ShapeGradient] 41 | shape_bdry_def = [1] 42 | shape_bdry_fix = [] 43 | lambda_lame = 1.428571428571429 44 | damping_factor = 0.2 45 | mu_fix = 0.35714285714285715 46 | mu_def = 0.35714285714285715 47 | use_sqrt_mu = False 48 | inhomogeneous = False 49 | 50 | [Regularization] 51 | factor_volume = 0.0 52 | target_volume = 3.14 53 | use_initial_volume = True 54 | factor_surface = 0.0 55 | target_surface = 1.0 56 | use_initial_surface = True 57 | factor_barycenter = 0.0 58 | target_barycenter = [0.0, 0.0, 0.0] 59 | use_initial_barycenter = True 60 | 61 | [MeshQuality] 62 | angle_change = inf 63 | volume_change = inf 64 | tol_lower = 0.1 65 | tol_upper = 0.25 66 | measure = condition_number 67 | type = min 68 | 69 | [Output] 70 | verbose = True 71 | save_results = True 72 | save_txt = True 73 | save_state = True 74 | save_adjoint = True 75 | save_gradient = True 76 | save_mesh = True 77 | -------------------------------------------------------------------------------- /tests/config_sop.ini: -------------------------------------------------------------------------------- 1 | [Mesh] 2 | remesh = False 3 | show_gmsh_output = False 4 | 5 | [StateSystem] 6 | is_linear = True 7 | picard_iteration = False 8 | picard_rtol = 1e-10 9 | picard_atol = 1e-12 10 | picard_iter = 10 11 | newton_atol = 1e-13 12 | newton_rtol = 1e-11 13 | picard_verbose = False 14 | 15 | [OptimizationRoutine] 16 | algorithm = lbfgs 17 | max_iter = 50 18 | rtol = 1e-3 19 | atol = 0.0 20 | soft_exit = False 21 | 22 | [LineSearch] 23 | initial_stepsize = 1.0 24 | epsilon_armijo = 1e-4 25 | beta_armijo = 2 26 | 27 | [AlgoLBFGS] 28 | bfgs_memory_size = 3 29 | use_bfgs_scaling = True 30 | 31 | [AlgoCG] 32 | cg_method = DY 33 | cg_periodic_restart = False 34 | cg_periodic_its = 5 35 | cg_relative_restart = False 36 | cg_restart_tol = 0.5 37 | 38 | [ShapeGradient] 39 | shape_bdry_def = [1] 40 | shape_bdry_fix = [] 41 | lambda_lame = 1.428571428571429 42 | damping_factor = 0.2 43 | mu_fix = 0.35714285714285715 44 | mu_def = 0.35714285714285715 45 | use_sqrt_mu = False 46 | inhomogeneous = False 47 | 48 | [Regularization] 49 | factor_volume = 0.0 50 | target_volume = 1.0 51 | use_initial_volume = False 52 | factor_surface = 0.0 53 | target_surface = 1.0 54 | use_initial_surface = False 55 | factor_barycenter = 0.0 56 | target_barycenter = [0.0, 0.0, 0.0] 57 | use_initial_barycenter = False 58 | 59 | [MeshQuality] 60 | angle_change = inf 61 | volume_change = inf 62 | tol_lower = 0.01 63 | tol_upper = 0.02 64 | 65 | [Output] 66 | verbose = True 67 | save_results = False 68 | save_txt = False 69 | save_state = False 70 | save_mesh = False 71 | -------------------------------------------------------------------------------- /tests/config_sosm.ini: -------------------------------------------------------------------------------- 1 | [Mesh] 2 | remesh = False 3 | show_gmsh_output = False 4 | 5 | [StateSystem] 6 | is_linear = True 7 | newton_rtol = 1e-11 8 | newton_atol = 1e-13 9 | newton_iter = 2 10 | newton_damped = True 11 | newton_verbose = False 12 | picard_iteration = False 13 | picard_rtol = 1e-10 14 | picard_atol = 1e-12 15 | picard_iter = 10 16 | picard_verbose = False 17 | 18 | [OptimizationRoutine] 19 | algorithm = bfgs 20 | rtol = 1e-2 21 | atol = 0.0 22 | max_iter = 50 23 | soft_exit = False 24 | 25 | [LineSearch] 26 | initial_stepsize = 1.0 27 | epsilon_armijo = 1e-4 28 | beta_armijo = 2 29 | 30 | [AlgoLBFGS] 31 | bfgs_memory_size = 5 32 | use_bfgs_scaling = True 33 | 34 | [AlgoCG] 35 | cg_method = DY 36 | cg_periodic_restart = False 37 | cg_periodic_its = 5 38 | cg_relative_restart = False 39 | cg_restart_tol = 0.5 40 | 41 | [ShapeGradient] 42 | shape_bdry_def = [2, 3] 43 | shape_bdry_fix = [1, 4, 5] 44 | shape_bdry_fix_x = [] 45 | shape_bdry_fix_y = [] 46 | shape_bdry_fix_z = [] 47 | use_pull_back = True 48 | lambda_lame = 0.0 49 | damping_factor = 0.0 50 | mu_def = 1.0 51 | mu_fix = 1.0 52 | use_sqrt_mu = False 53 | inhomogeneous = True 54 | 55 | [Regularization] 56 | factor_volume = 0.0 57 | target_volume = 0.0 58 | use_initial_volume = True 59 | factor_surface = 0.0 60 | target_surface = 0.0 61 | use_initial_surface = False 62 | factor_curvature = 0.0 63 | factor_barycenter = 0.0 64 | target_barycenter = [0.0, 0.0, 0.0] 65 | use_initial_barycenter = False 66 | use_relative_scaling = False 67 | 68 | [MeshQuality] 69 | angle_change = inf 70 | volume_change = inf 71 | tol_lower = 0.0 72 | tol_upper = 1e-15 73 | measure = skewness 74 | type = min 75 | 76 | [Output] 77 | verbose = False 78 | save_results = False 79 | save_txt = False 80 | save_state = False 81 | save_adjoint = False 82 | save_gradient = False 83 | save_mesh = False 84 | -------------------------------------------------------------------------------- /tests/config_top.ini: -------------------------------------------------------------------------------- 1 | [Output] 2 | verbose = True 3 | save_results = False 4 | save_txt = False 5 | save_state = False 6 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2025 Fraunhofer ITWM and Sebastian Blauth 2 | # 3 | # This file is part of cashocs. 4 | # 5 | # cashocs is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # cashocs is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with cashocs. If not, see . 17 | 18 | import pathlib 19 | 20 | import fenics 21 | import numpy as np 22 | import pytest 23 | 24 | import cashocs 25 | 26 | 27 | @pytest.fixture() 28 | def dir_path(): 29 | return str(pathlib.Path(__file__).parent) 30 | 31 | 32 | @pytest.fixture 33 | def config_ocp(dir_path): 34 | return cashocs.load_config(f"{dir_path}/config_ocp.ini") 35 | 36 | 37 | @pytest.fixture 38 | def config_sop(dir_path): 39 | return cashocs.load_config(f"{dir_path}/config_sop.ini") 40 | 41 | 42 | @pytest.fixture 43 | def config_top(dir_path): 44 | return cashocs.load_config(f"{dir_path}/config_top.ini") 45 | 46 | 47 | @pytest.fixture 48 | def rng(): 49 | return np.random.RandomState(300696) 50 | 51 | 52 | @pytest.fixture 53 | def y_d(geometry): 54 | return fenics.Expression( 55 | "sin(2*pi*x[0])*sin(2*pi*x[1])", degree=1, domain=geometry.mesh 56 | ) 57 | 58 | 59 | @pytest.fixture(params=["FR", "PR", "HS", "DY", "HZ"]) 60 | def setup_cg_method(config_ocp, request): 61 | config_ocp.set("AlgoCG", "cg_method", request.param) 62 | 63 | 64 | @pytest.fixture(params=["cr", "cg"]) 65 | def setup_newton_method(config_ocp, request): 66 | config_ocp.set("AlgoTNM", "inner_newton", request.param) 67 | -------------------------------------------------------------------------------- /tests/mesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 0.5; 2 | 3 | Point(1) = {0, 0, 0, lc}; 4 | Point(2) = {1, 0, 0, lc}; 5 | Point(3) = {1, 1, 0, lc}; 6 | Point(4) = {0, 1, 0, lc}; 7 | 8 | Line(1) = {1,2}; 9 | Line(2) = {2,3}; 10 | Line(3) = {3,4}; 11 | Line(4) = {4,1}; 12 | 13 | Line Loop(1) = {1,2,3,4}; 14 | 15 | Surface(1) = {1}; 16 | 17 | Physical Surface(1) = {1}; 18 | 19 | Physical Line(1) = {1}; 20 | Physical Line(2) = {2}; 21 | Physical Line(3) = {3}; 22 | Physical Line(4) = {4}; 23 | -------------------------------------------------------------------------------- /tests/mesh/mesh.msh: -------------------------------------------------------------------------------- 1 | $MeshFormat 2 | 4.1 0 8 3 | $EndMeshFormat 4 | $Entities 5 | 4 4 1 0 6 | 1 0 0 0 0 7 | 2 1 0 0 0 8 | 3 1 1 0 0 9 | 4 0 1 0 0 10 | 1 0 0 0 1 0 0 1 1 2 1 -2 11 | 2 1 0 0 1 1 0 1 2 2 2 -3 12 | 3 0 1 0 1 1 0 1 3 2 3 -4 13 | 4 0 0 0 0 1 0 1 4 2 4 -1 14 | 1 0 0 0 1 1 0 1 1 4 1 2 3 4 15 | $EndEntities 16 | $Nodes 17 | 9 12 1 12 18 | 0 1 0 1 19 | 1 20 | 0 0 0 21 | 0 2 0 1 22 | 2 23 | 1 0 0 24 | 0 3 0 1 25 | 3 26 | 1 1 0 27 | 0 4 0 1 28 | 4 29 | 0 1 0 30 | 1 1 0 1 31 | 5 32 | 0.499999999998694 0 0 33 | 1 2 0 1 34 | 6 35 | 1 0.499999999998694 0 36 | 1 3 0 1 37 | 7 38 | 0.5000000000020591 1 0 39 | 1 4 0 1 40 | 8 41 | 0 0.5000000000020591 0 42 | 2 1 0 4 43 | 9 44 | 10 45 | 11 46 | 12 47 | 0.2500000000010297 0.7500000000010296 0 48 | 0.3749999970924328 0.3750000029075671 0 49 | 0.7187499979760099 0.2812500030636815 0 50 | 0.6542968741702071 0.6542968818888233 0 51 | $EndNodes 52 | $Elements 53 | 5 22 1 22 54 | 1 1 1 2 55 | 1 1 5 56 | 2 5 2 57 | 1 2 1 2 58 | 3 2 6 59 | 4 6 3 60 | 1 3 1 2 61 | 5 3 7 62 | 6 7 4 63 | 1 4 1 2 64 | 7 4 8 65 | 8 8 1 66 | 2 1 2 14 67 | 9 5 10 1 68 | 10 1 10 8 69 | 11 3 12 6 70 | 12 7 12 3 71 | 13 2 11 5 72 | 14 6 11 2 73 | 15 4 9 7 74 | 16 8 9 4 75 | 17 10 12 9 76 | 18 9 12 7 77 | 19 8 10 9 78 | 20 11 12 10 79 | 21 6 12 11 80 | 22 5 11 10 81 | $EndElements 82 | -------------------------------------------------------------------------------- /tests/mesh/mesh3.geo: -------------------------------------------------------------------------------- 1 | SetFactory("OpenCASCADE"); 2 | Box(1) = {0, 0, 0, 1, 1, 1}; 3 | 4 | 5 | //+ 6 | Physical Volume(1) = {1}; 7 | 8 | Physical Surface(1) = {1}; 9 | Physical Surface(2) = {2}; 10 | Physical Surface(3) = {3}; 11 | Physical Surface(4) = {4}; 12 | Physical Surface(5) = {5}; 13 | Physical Surface(6) = {6}; 14 | -------------------------------------------------------------------------------- /tests/mesh/named_mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 1e-1; 2 | 3 | Point(1) = {0,0,0,lc}; 4 | Point(2) = {1,0,0,lc}; 5 | Point(3) = {1,1,0,lc}; 6 | Point(4) = {0,1,0,lc}; 7 | 8 | Line(1) = {1,2}; 9 | Line(2) = {2,3}; 10 | Line(3) = {3,4}; 11 | Line(4) = {4,1}; 12 | 13 | Curve Loop(1) = {1,2,3,4}; 14 | Plane Surface(1) = {1}; 15 | 16 | Physical Surface("volume", 1) = {1}; 17 | 18 | Physical Curve("inlet", 1) = {4}; 19 | Physical Curve("wall", 2) = {1,3}; 20 | Physical Curve("outlet", 3) = {2}; 21 | -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/physical_names_legacy/named_mesh.h5 -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh.xdmf: -------------------------------------------------------------------------------- 1 | named_mesh.h5:/data0named_mesh.h5:/data1 -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/physical_names_legacy/named_mesh_boundaries.h5 -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | named_mesh_boundaries.h5:/data0named_mesh_boundaries.h5:/data1named_mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh_physical_groups.json: -------------------------------------------------------------------------------- 1 | { 2 | "dx": { 3 | "volume": 1 4 | }, 5 | "ds": { 6 | "inlet": 1, 7 | "wall": 2, 8 | "outlet": 3 9 | } 10 | } -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh_subdomains.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/physical_names_legacy/named_mesh_subdomains.h5 -------------------------------------------------------------------------------- /tests/mesh/physical_names_legacy/named_mesh_subdomains.xdmf: -------------------------------------------------------------------------------- 1 | named_mesh_subdomains.h5:/data0named_mesh_subdomains.h5:/data1named_mesh_subdomains.h5:/data2 -------------------------------------------------------------------------------- /tests/mesh/remesh/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 5e-2; 2 | 3 | Point(1) = {0, 0, 0, lc}; 4 | Point(2) = {1, 0, 0, lc}; 5 | Point(3) = {0, 1, 0, lc}; 6 | Point(4) = {-1, 0, 0, lc}; 7 | Point(5) = {0, -1, 0, lc}; 8 | 9 | Circle(1) = {2, 1, 3}; 10 | Circle(2) = {3, 1, 4}; 11 | Circle(3) = {4, 1, 5}; 12 | Circle(4) = {5, 1, 2}; 13 | 14 | Line Loop(1) = {1,2,3,4}; 15 | 16 | Surface(1) = {1}; 17 | 18 | Physical Surface(1) = {1}; 19 | 20 | Physical Line(1) = {1,2,3,4}; 21 | 22 | Field[1] = Distance; 23 | Field[1].NNodesByEdge = 1000; 24 | Field[1].NodesList = {2}; 25 | Field[2] = Threshold; 26 | Field[2].IField = 1; 27 | Field[2].DistMin = 1e-1; 28 | Field[2].DistMax = 5e-1; 29 | Field[2].LcMin = lc / 10; 30 | Field[2].LcMax = lc; 31 | 32 | Background Field = 2; 33 | -------------------------------------------------------------------------------- /tests/mesh/remesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/remesh/mesh.h5 -------------------------------------------------------------------------------- /tests/mesh/remesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /tests/mesh/remesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/remesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /tests/mesh/remesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /tests/mesh/unit_circle/mesh.geo: -------------------------------------------------------------------------------- 1 | lc = 7.5e-2; 2 | 3 | SetFactory("OpenCASCADE"); 4 | Disk(1) = {0, 0, 0, 1, 1}; 5 | 6 | Mesh.MeshSizeMax = lc; 7 | Mesh.MeshSizeMin = 0.0; 8 | 9 | Physical Curve(1) = {1}; 10 | Physical Surface(1) = {1}; 11 | -------------------------------------------------------------------------------- /tests/mesh/unit_circle/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/unit_circle/mesh.h5 -------------------------------------------------------------------------------- /tests/mesh/unit_circle/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /tests/mesh/unit_circle/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/mesh/unit_circle/mesh_boundaries.h5 -------------------------------------------------------------------------------- /tests/mesh/unit_circle/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /tests/sm_mesh/mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/sm_mesh/mesh.h5 -------------------------------------------------------------------------------- /tests/sm_mesh/mesh.xdmf: -------------------------------------------------------------------------------- 1 | mesh.h5:/data0mesh.h5:/data1mesh.h5:/data2 -------------------------------------------------------------------------------- /tests/sm_mesh/mesh_boundaries.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/sm_mesh/mesh_boundaries.h5 -------------------------------------------------------------------------------- /tests/sm_mesh/mesh_boundaries.xdmf: -------------------------------------------------------------------------------- 1 | mesh_boundaries.h5:/data0mesh_boundaries.h5:/data1mesh_boundaries.h5:/data2 -------------------------------------------------------------------------------- /tests/test_config.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | a = 1 3 | b = 3.14 4 | c = True 5 | d = algorithm 6 | 7 | [B] 8 | a = 2 9 | b = 6.28 10 | c = False 11 | d = cashocs 12 | 13 | [StateSystem] 14 | algorithm = False 15 | -------------------------------------------------------------------------------- /tests/xdmf_state/state_0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sblauth/cashocs/20cf9366f0bb2dcf87a50693a35f881d18f0cd27/tests/xdmf_state/state_0.h5 --------------------------------------------------------------------------------