.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery_examples/drainage_bassin/make_optimization_drainage.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_drainage_bassin_make_optimization_drainage.py: Drainage bassin ############### In the same category than https://onlinelibrary.wiley.com/doi/abs/10.1002/nme.1811 .. GENERATED FROM PYTHON SOURCE LINES 7-56 .. code-block:: Python import sys import os path = os.getcwd() + '/../../' sys.path.append(path) import numpy as np import h5py import nlopt from HydrOpTop.Functions import Mean_Liquid_Piezometric_Head #objective from HydrOpTop.Functions import Volume_Percentage #constrain from HydrOpTop.Materials import Log_SIMP from HydrOpTop.Crafter import Steady_State_Crafter from HydrOpTop.Filters import Density_Filter from HydrOpTop.Solvers import PFLOTRAN if __name__ == "__main__": #create PFLOTRAN simulation object pflotranin = "pflotran.in" sim = PFLOTRAN(pflotranin) #get cell ids in the region to optimize and parametrize permeability #same name than in pflotran input file perm = Log_SIMP(cell_ids_to_parametrize="all", property_name="PERMEABILITY", bounds=[1e-14, 1e-10], power=3) #define cost function as sum of the head in the pit cf = Mean_Liquid_Piezometric_Head(ids_to_sum="everywhere", penalizing_power=1) #define maximum volume constrains max_vol = Volume_Percentage("parametrized_cell") max_vol.constraint_tol = 0.2 filter_ = Density_Filter(10.) #craft optimization problem #i.e. create function to optimize, initiate IO array in classes... crafted_problem = Steady_State_Crafter(cf, sim, [perm], [max_vol], [filter_]) crafted_problem.IO.output_every_iteration(1) crafted_problem.IO.output_gradient() crafted_problem.IO.output_material_properties() crafted_problem.IO.define_output_format("vtu") #initialize optimizer p = np.zeros(crafted_problem.get_problem_size(),dtype='f8') + 0.15 p_opt = crafted_problem.optimize(optimizer="nlopt-mma", action="minimize", max_it=75, ftol=0.0001, initial_guess=p) .. _sphx_glr_download_gallery_examples_drainage_bassin_make_optimization_drainage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: make_optimization_drainage.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: make_optimization_drainage.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_