.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials_sg/mdo/plot_aerostructure.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_sg_mdo_plot_aerostructure.py: MDO formulations for a toy example in aerostructure =================================================== .. GENERATED FROM PYTHON SOURCE LINES 26-55 .. code-block:: default from __future__ import absolute_import, division, print_function, unicode_literals from copy import deepcopy from future import standard_library from gemseo.api import ( configure_logger, create_discipline, create_scenario, generate_n2_plot, ) from gemseo.problems.aerostructure.aerostructure_design_space import ( AerostructureDesignSpace, ) configure_logger() standard_library.install_aliases() algo_options = { "xtol_rel": 1e-8, "xtol_abs": 1e-8, "ftol_rel": 1e-8, "ftol_abs": 1e-8, "ineq_tolerance": 1e-5, "eq_tolerance": 1e-3, } .. GENERATED FROM PYTHON SOURCE LINES 56-60 Create discipline ----------------- First, we create disciplines (aero, structure, mission) with dummy formulas using the :class:`.AnalyticDiscipline` class. .. GENERATED FROM PYTHON SOURCE LINES 60-85 .. code-block:: default aero_formulas = { "drag": "0.1*((sweep/360)**2 + 200 + " + "thick_airfoils**2-thick_airfoils -4*displ)", "forces": "10*sweep + 0.2*thick_airfoils-0.2*displ", "lift": "(sweep + 0.2*thick_airfoils-2.*displ)/3000.", } aerodynamics = create_discipline( "AnalyticDiscipline", name="Aerodynamics", expressions_dict=aero_formulas ) struc_formulas = { "mass": "4000*(sweep/360)**3 + 200000 + " + "100*thick_panels +200.0*forces", "reserve_fact": "-3*sweep " + "-6*thick_panels+0.1*forces+55", "displ": "2*sweep + 3*thick_panels-2.*forces", } structure = create_discipline( "AnalyticDiscipline", name="Structure", expressions_dict=struc_formulas ) mission_formulas = {"range": "8e11*lift/(mass*drag)"} mission = create_discipline( "AnalyticDiscipline", name="Mission", expressions_dict=mission_formulas ) disciplines = [aerodynamics, structure, mission] .. GENERATED FROM PYTHON SOURCE LINES 86-87 We can see that structure and aerodynamics are strongly coupled: .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: default generate_n2_plot(disciplines, save=False, show=True) .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_001.png :alt: plot aerostructure :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 90-93 Create a MDO scenario with MDF formulation ------------------------------------------ Then, we create a MDO scenario based on the MDF formulation .. GENERATED FROM PYTHON SOURCE LINES 93-106 .. code-block:: default design_space = AerostructureDesignSpace() scenario = create_scenario( disciplines=disciplines, formulation="MDF", objective_name="range", design_space=design_space, maximize_objective=True, ) scenario.add_constraint("reserve_fact", "ineq", value=0.5) scenario.add_constraint("lift", "eq", value=0.5) scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 10, "algo_options": algo_options}) scenario.post_process("OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_002.png :alt: Evolution of the optimization variables :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_003.png :alt: Evolution of the objective value :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_004.png :alt: Distance to the optimum :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_005.png :alt: Hessian diagonal approximation :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_006.png :alt: Evolution of the inequality constraints :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_007.png :alt: Evolution of the equality constraints :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:312: UserWarning: FixedFormatter should only be used together with FixedLocator ax1.set_yticklabels(y_labels) /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:716: MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4. To suppress this warning specify the base keyword argument. norm=SymLogNorm(linthresh=linthresh, vmin=-vmax, vmax=vmax), /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:626: MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4. To suppress this warning specify the base keyword argument. norm=SymLogNorm(linthresh=1.0, vmin=-vmax, vmax=vmax), /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:619: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it. im1 = ax1.imshow( .. GENERATED FROM PYTHON SOURCE LINES 107-110 Create a MDO scenario with bilevel formulation ---------------------------------------------- Then, we create a MDO scenario based on the bilevel formulation .. GENERATED FROM PYTHON SOURCE LINES 110-117 .. code-block:: default sub_scenario_options = { "max_iter": 5, "algo": "NLOPT_SLSQP", "algo_options": algo_options, } design_space_ref = AerostructureDesignSpace() .. GENERATED FROM PYTHON SOURCE LINES 118-122 Create the aeronautics sub-scenario ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For this purpose, we create a first sub-scenario to maximize the range with respect to the thick airfoils, based on the aerodynamics discipline. .. GENERATED FROM PYTHON SOURCE LINES 122-132 .. code-block:: default design_space_aero = deepcopy(design_space_ref).filter(["thick_airfoils"]) aero_scenario = create_scenario( disciplines=[aerodynamics, mission], formulation="DisciplinaryOpt", objective_name="range", design_space=design_space_aero, maximize_objective=True, ) aero_scenario.default_inputs = sub_scenario_options .. GENERATED FROM PYTHON SOURCE LINES 133-137 Create the structure sub-scenario ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We create a second sub-scenario to maximize the range with respect to the thick panels, based on the structure discipline. .. GENERATED FROM PYTHON SOURCE LINES 137-147 .. code-block:: default design_space_struct = deepcopy(design_space_ref).filter(["thick_panels"]) struct_scenario = create_scenario( disciplines=[structure, mission], formulation="DisciplinaryOpt", objective_name="range", design_space=design_space_struct, maximize_objective=True, ) struct_scenario.default_inputs = sub_scenario_options .. GENERATED FROM PYTHON SOURCE LINES 148-152 Create the system scenario ^^^^^^^^^^^^^^^^^^^^^^^^^^ Lastly, we build a system scenario to maximize the range with respect to the sweep, which is a shared variable, based on the previous sub-scenarios. .. GENERATED FROM PYTHON SOURCE LINES 152-168 .. code-block:: default design_space_system = deepcopy(design_space_ref).filter(["sweep"]) system_scenario = create_scenario( disciplines=[aero_scenario, struct_scenario, mission], formulation="BiLevel", objective_name="range", design_space=design_space_system, maximize_objective=True, mda_name="MDAJacobi", tolerance=1e-8, ) system_scenario.add_constraint("reserve_fact", "ineq", value=0.5) system_scenario.add_constraint("lift", "eq", value=0.5) system_scenario.execute( {"algo": "NLOPT_COBYLA", "max_iter": 7, "algo_options": algo_options} ) system_scenario.post_process("OptHistoryView", save=False, show=True) .. rst-class:: sphx-glr-horizontal * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_008.png :alt: Evolution of the optimization variables :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_009.png :alt: Evolution of the objective value :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_010.png :alt: Distance to the optimum :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_011.png :alt: Evolution of the inequality constraints :class: sphx-glr-multi-img * .. image:: /tutorials_sg/mdo/images/sphx_glr_plot_aerostructure_012.png :alt: Evolution of the equality constraints :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:312: UserWarning: FixedFormatter should only be used together with FixedLocator ax1.set_yticklabels(y_labels) /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:626: MatplotlibDeprecationWarning: default base will change from np.e to 10 in 3.4. To suppress this warning specify the base keyword argument. norm=SymLogNorm(linthresh=1.0, vmin=-vmax, vmax=vmax), /home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.0.3/lib/python3.8/site-packages/gemseo/post/opt_history_view.py:619: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it. im1 = ax1.imshow( .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.089 seconds) .. _sphx_glr_download_tutorials_sg_mdo_plot_aerostructure.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_aerostructure.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_aerostructure.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_