.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery_examples/verifications/make_cantilever_min_volume.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_examples_verifications_make_cantilever_min_volume.py: Minimize volume with maximum compliance ####################################### .. GENERATED FROM PYTHON SOURCE LINES 7-9 This is a variation of the standart design optimisation problem where the minimum volume structure is seeked given a maximum compliance.  It illustrate the modularity of how Functions is implemented in HydrOpTop and can be used either as a constrain or a main objective. .. GENERATED FROM PYTHON SOURCE LINES 9-64 .. code-block:: Python import numpy as np from HydrOpTop.Functions.verification import Mechanical_Compliance, Volume_Percentage from HydrOpTop.Functions import Volume_Percentage from HydrOpTop.Materials import SIMP from HydrOpTop.Filters import Density_Filter, Heaviside_Filter from HydrOpTop.Crafter import Steady_State_Crafter from HydrOpTop.Solvers import Linear_Elasticity_2D #create solver simulation object sim = Linear_Elasticity_2D("cantilever") #get cell ids in the region to optimize and parametrize permeability #same name than in pflotran input file young_modulus = SIMP(cell_ids_to_parametrize="all", property_name="YOUNG_MODULUS", bounds=[0, 2000], power=3) #define cost function max_vol = Volume_Percentage("parametrized_cell") #define maximum compliance MC = Mechanical_Compliance(ids_to_consider="everywhere") MC.constraint_tol = 5e-2 #define filter dfilter = Density_Filter(0.3) hfilter = Heaviside_Filter(0.5, 1) #craft optimization problem #i.e. create function to optimize, initiate IO array in classes... crafted_problem = Steady_State_Crafter(max_vol, sim, [young_modulus], [MC], filters=[dfilter, hfilter]) crafted_problem.IO.output_every_iteration(2) crafted_problem.IO.define_output_format("vtu") #initialize optimizer p_ini = np.ones(crafted_problem.get_problem_size(),dtype='f8') #optimize in several pass to reach discrete distribution out = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=50, ftol=1e-10, initial_guess=p_ini) hfilter.stepness = 2 out = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=20, initial_guess=out.p_opt) hfilter.stepness = 4 out = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=20, initial_guess=out.p_opt) hfilter.stepness = 8 out = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=20, initial_guess=out.p_opt) hfilter.stepness = 20 out = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=30, initial_guess=out.p_opt) crafted_problem.IO.write_fields_to_file([out.p_opt_filtered], "./out.vtu", ["Filtered_density"]) .. _sphx_glr_download_gallery_examples_verifications_make_cantilever_min_volume.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: make_cantilever_min_volume.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: make_cantilever_min_volume.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_