Solve a 2D MBB topology optimization problem

from __future__ import annotations

import matplotlib.pyplot as plt
from gemseo.api import configure_logger
from gemseo.api import create_scenario
from gemseo.problems.topo_opt.topopt_initialize import (
    initialize_design_space_and_discipline_to,
)
from matplotlib import colors

configure_logger()
<RootLogger root (INFO)>

Setup the topology optimization problem

Define the target volume fraction:

volume_fraction = 0.3

Define the problem type:

problem_name = "MBB"

Define the number of elements in x- and y- directions:

n_x = 50
n_y = 25

Define the full material Young’s modulus and the Poisson’s ratio:

e0 = 1
nu = 0.3

Define the penalty of the SIMP approach:

penalty = 3

Define the minimum member size in the solution:

min_member_size = 1.5

Instantiate the DesignSpace and the disciplines:

design_space, disciplines = initialize_design_space_and_discipline_to(
    problem=problem_name,
    n_x=n_x,
    n_y=n_y,
    e0=e0,
    nu=nu,
    penalty=penalty,
    min_member_size=min_member_size,
    vf0=volume_fraction,
)

Solve the topology optimization problem

Generate a MDOScenario

scenario = create_scenario(
    disciplines,
    formulation="DisciplinaryOpt",
    objective_name="compliance",
    design_space=design_space,
)

Add the volume fraction constraint to the scenario:

scenario.add_constraint("volume fraction", "ineq", value=volume_fraction)

Generate the XDSM

scenario.xdsmize()
INFO - 16:55:57: Generating HTML XDSM file in : xdsm.html

Execute the scenario

scenario.execute(input_data={"max_iter": 200, "algo": "NLOPT_MMA"})
    INFO - 16:55:57:
    INFO - 16:55:57: *** Start MDOScenario execution ***
    INFO - 16:55:57: MDOScenario
    INFO - 16:55:57:    Disciplines: DensityFilter FininiteElementAnalysis MaterialModelInterpolation VolumeFraction
    INFO - 16:55:57:    MDO formulation: DisciplinaryOpt
    INFO - 16:55:57: Optimization problem:
    INFO - 16:55:57:    minimize compliance(x)
    INFO - 16:55:57:    with respect to x
    INFO - 16:55:57:    subject to constraints:
    INFO - 16:55:57:       volume fraction(x) <= 0.3
    INFO - 16:55:57: Solving optimization problem with algorithm NLOPT_MMA:
    INFO - 16:55:57: ...   0%|          | 0/200 [00:00<?, ?it]
    INFO - 16:55:57: ...   0%|          | 1/200 [00:00<00:16, 12.28 it/sec, obj=1.79e+3]
    INFO - 16:55:57: ...   1%|          | 2/200 [00:00<00:30,  6.45 it/sec, obj=1.79e+3]
    INFO - 16:55:58: ...   2%|▏         | 3/200 [00:00<00:27,  7.20 it/sec, obj=1.78e+3]
    INFO - 16:55:58: ...   2%|▏         | 4/200 [00:00<00:25,  7.81 it/sec, obj=1.77e+3]
    INFO - 16:55:58: ...   2%|▎         | 5/200 [00:00<00:24,  8.06 it/sec, obj=1.75e+3]
    INFO - 16:55:58: ...   3%|▎         | 6/200 [00:00<00:23,  8.36 it/sec, obj=1.71e+3]
    INFO - 16:55:58: ...   4%|▎         | 7/200 [00:00<00:22,  8.48 it/sec, obj=1.65e+3]
    INFO - 16:55:58: ...   4%|▍         | 8/200 [00:00<00:22,  8.68 it/sec, obj=1.41e+3]
    INFO - 16:55:58: ...   4%|▍         | 9/200 [00:01<00:21,  8.77 it/sec, obj=1.19e+3]
    INFO - 16:55:58: ...   5%|▌         | 10/200 [00:01<00:21,  8.91 it/sec, obj=903]
    INFO - 16:55:58: ...   6%|▌         | 11/200 [00:01<00:21,  8.95 it/sec, obj=724]
    INFO - 16:55:59: ...   6%|▌         | 12/200 [00:01<00:20,  9.06 it/sec, obj=612]
    INFO - 16:55:59: ...   6%|▋         | 13/200 [00:01<00:20,  9.08 it/sec, obj=534]
    INFO - 16:55:59: ...   7%|▋         | 14/200 [00:01<00:20,  9.17 it/sec, obj=474]
    INFO - 16:55:59: ...   8%|▊         | 15/200 [00:01<00:20,  9.20 it/sec, obj=444]
    INFO - 16:55:59: ...   8%|▊         | 16/200 [00:01<00:19,  9.28 it/sec, obj=419]
    INFO - 16:55:59: ...   8%|▊         | 17/200 [00:01<00:19,  9.31 it/sec, obj=405]
    INFO - 16:55:59: ...   9%|▉         | 18/200 [00:01<00:19,  9.38 it/sec, obj=387]
    INFO - 16:55:59: ...  10%|▉         | 19/200 [00:02<00:19,  9.38 it/sec, obj=364]
    INFO - 16:55:59: ...  10%|█         | 20/200 [00:02<00:19,  9.44 it/sec, obj=338]
    INFO - 16:55:59: ...  10%|█         | 21/200 [00:02<00:18,  9.44 it/sec, obj=306]
    INFO - 16:55:59: ...  11%|█         | 22/200 [00:02<00:18,  9.49 it/sec, obj=272]
    INFO - 16:56:00: ...  12%|█▏        | 23/200 [00:02<00:18,  9.50 it/sec, obj=253]
    INFO - 16:56:00: ...  12%|█▏        | 24/200 [00:02<00:18,  9.53 it/sec, obj=244]
    INFO - 16:56:00: ...  12%|█▎        | 25/200 [00:02<00:18,  9.54 it/sec, obj=234]
    INFO - 16:56:00: ...  13%|█▎        | 26/200 [00:02<00:18,  9.57 it/sec, obj=224]
    INFO - 16:56:00: ...  14%|█▎        | 27/200 [00:02<00:18,  9.56 it/sec, obj=213]
    INFO - 16:56:00: ...  14%|█▍        | 28/200 [00:02<00:17,  9.61 it/sec, obj=207]
    INFO - 16:56:00: ...  14%|█▍        | 29/200 [00:03<00:17,  9.61 it/sec, obj=202]
    INFO - 16:56:00: ...  15%|█▌        | 30/200 [00:03<00:17,  9.65 it/sec, obj=197]
    INFO - 16:56:00: ...  16%|█▌        | 31/200 [00:03<00:17,  9.65 it/sec, obj=193]
    INFO - 16:56:00: ...  16%|█▌        | 32/200 [00:03<00:17,  9.68 it/sec, obj=190]
    INFO - 16:56:01: ...  16%|█▋        | 33/200 [00:03<00:17,  9.69 it/sec, obj=188]
    INFO - 16:56:01: ...  17%|█▋        | 34/200 [00:03<00:17,  9.72 it/sec, obj=186]
    INFO - 16:56:01: ...  18%|█▊        | 35/200 [00:03<00:16,  9.73 it/sec, obj=185]
    INFO - 16:56:01: ...  18%|█▊        | 36/200 [00:03<00:16,  9.76 it/sec, obj=184]
    INFO - 16:56:01: ...  18%|█▊        | 37/200 [00:03<00:16,  9.76 it/sec, obj=183]
    INFO - 16:56:01: ...  19%|█▉        | 38/200 [00:03<00:16,  9.79 it/sec, obj=182]
    INFO - 16:56:01: ...  20%|█▉        | 39/200 [00:03<00:16,  9.79 it/sec, obj=181]
    INFO - 16:56:01: ...  20%|██        | 40/200 [00:04<00:16,  9.82 it/sec, obj=179]
    INFO - 16:56:01: ...  20%|██        | 41/200 [00:04<00:16,  9.82 it/sec, obj=177]
    INFO - 16:56:01: ...  21%|██        | 42/200 [00:04<00:16,  9.84 it/sec, obj=175]
    INFO - 16:56:02: ...  22%|██▏       | 43/200 [00:04<00:15,  9.84 it/sec, obj=174]
    INFO - 16:56:02: ...  22%|██▏       | 44/200 [00:04<00:15,  9.86 it/sec, obj=173]
    INFO - 16:56:02: ...  22%|██▎       | 45/200 [00:04<00:15,  9.86 it/sec, obj=172]
    INFO - 16:56:02: ...  23%|██▎       | 46/200 [00:04<00:15,  9.89 it/sec, obj=172]
    INFO - 16:56:02: ...  24%|██▎       | 47/200 [00:04<00:15,  9.88 it/sec, obj=172]
    INFO - 16:56:02: ...  24%|██▍       | 48/200 [00:04<00:15,  9.91 it/sec, obj=172]
    INFO - 16:56:02: ...  24%|██▍       | 49/200 [00:04<00:15,  9.91 it/sec, obj=172]
    INFO - 16:56:02: ...  25%|██▌       | 50/200 [00:05<00:15,  9.93 it/sec, obj=172]
    INFO - 16:56:02: ...  26%|██▌       | 51/200 [00:05<00:15,  9.93 it/sec, obj=172]
    INFO - 16:56:02: ...  26%|██▌       | 52/200 [00:05<00:14,  9.94 it/sec, obj=172]
    INFO - 16:56:03: ...  26%|██▋       | 53/200 [00:05<00:14,  9.94 it/sec, obj=172]
    INFO - 16:56:03: ...  27%|██▋       | 54/200 [00:05<00:14,  9.96 it/sec, obj=172]
    INFO - 16:56:03: ...  28%|██▊       | 55/200 [00:05<00:14,  9.96 it/sec, obj=172]
    INFO - 16:56:03: ...  28%|██▊       | 56/200 [00:05<00:14,  9.98 it/sec, obj=172]
    INFO - 16:56:03: ...  28%|██▊       | 57/200 [00:05<00:14,  9.98 it/sec, obj=172]
    INFO - 16:56:03: ...  29%|██▉       | 58/200 [00:05<00:14,  9.99 it/sec, obj=171]
    INFO - 16:56:03: ...  30%|██▉       | 59/200 [00:05<00:14,  9.99 it/sec, obj=171]
    INFO - 16:56:03: ...  30%|███       | 60/200 [00:05<00:13, 10.01 it/sec, obj=171]
    INFO - 16:56:03: ...  30%|███       | 61/200 [00:06<00:13, 10.01 it/sec, obj=171]
    INFO - 16:56:03: ...  31%|███       | 62/200 [00:06<00:13, 10.03 it/sec, obj=171]
    INFO - 16:56:03: ...  32%|███▏      | 63/200 [00:06<00:13, 10.02 it/sec, obj=171]
    INFO - 16:56:04: ...  32%|███▏      | 64/200 [00:06<00:13, 10.04 it/sec, obj=171]
    INFO - 16:56:04: ...  32%|███▎      | 65/200 [00:06<00:13, 10.03 it/sec, obj=171]
    INFO - 16:56:04: ...  33%|███▎      | 66/200 [00:06<00:13, 10.05 it/sec, obj=171]
    INFO - 16:56:04: ...  34%|███▎      | 67/200 [00:06<00:13, 10.04 it/sec, obj=171]
    INFO - 16:56:04: ...  34%|███▍      | 68/200 [00:06<00:13, 10.06 it/sec, obj=171]
    INFO - 16:56:04: ...  34%|███▍      | 69/200 [00:06<00:13, 10.05 it/sec, obj=171]
    INFO - 16:56:04: ...  35%|███▌      | 70/200 [00:06<00:12, 10.07 it/sec, obj=171]
    INFO - 16:56:04: ...  36%|███▌      | 71/200 [00:07<00:12, 10.06 it/sec, obj=171]
    INFO - 16:56:04: ...  36%|███▌      | 72/200 [00:07<00:12, 10.08 it/sec, obj=171]
    INFO - 16:56:04: ...  36%|███▋      | 73/200 [00:07<00:12, 10.08 it/sec, obj=171]
    INFO - 16:56:05: ...  37%|███▋      | 74/200 [00:07<00:12, 10.09 it/sec, obj=171]
    INFO - 16:56:05: ...  38%|███▊      | 75/200 [00:07<00:12, 10.09 it/sec, obj=171]
    INFO - 16:56:05: ...  38%|███▊      | 76/200 [00:07<00:12, 10.10 it/sec, obj=171]
    INFO - 16:56:05: ...  38%|███▊      | 77/200 [00:07<00:12, 10.10 it/sec, obj=171]
    INFO - 16:56:05: ...  39%|███▉      | 78/200 [00:07<00:12, 10.11 it/sec, obj=171]
    INFO - 16:56:05: ...  40%|███▉      | 79/200 [00:07<00:11, 10.11 it/sec, obj=171]
    INFO - 16:56:05: ...  40%|████      | 80/200 [00:07<00:11, 10.12 it/sec, obj=171]
    INFO - 16:56:05: ...  40%|████      | 81/200 [00:08<00:11, 10.12 it/sec, obj=171]
    INFO - 16:56:05: ...  41%|████      | 82/200 [00:08<00:11, 10.13 it/sec, obj=171]
    INFO - 16:56:05: ...  42%|████▏     | 83/200 [00:08<00:11, 10.13 it/sec, obj=171]
    INFO - 16:56:05: ...  42%|████▏     | 84/200 [00:08<00:11, 10.14 it/sec, obj=171]
    INFO - 16:56:06: ...  42%|████▎     | 85/200 [00:08<00:11, 10.14 it/sec, obj=171]
    INFO - 16:56:06: ...  43%|████▎     | 86/200 [00:08<00:11, 10.15 it/sec, obj=171]
    INFO - 16:56:06: ...  44%|████▎     | 87/200 [00:08<00:11, 10.14 it/sec, obj=171]
    INFO - 16:56:06: ...  44%|████▍     | 88/200 [00:08<00:11, 10.16 it/sec, obj=171]
    INFO - 16:56:06: ...  44%|████▍     | 89/200 [00:08<00:10, 10.15 it/sec, obj=171]
    INFO - 16:56:06: ...  45%|████▌     | 90/200 [00:08<00:10, 10.16 it/sec, obj=171]
    INFO - 16:56:06: ...  46%|████▌     | 91/200 [00:08<00:10, 10.16 it/sec, obj=171]
    INFO - 16:56:06: ...  46%|████▌     | 92/200 [00:09<00:10, 10.17 it/sec, obj=171]
    INFO - 16:56:06: ...  46%|████▋     | 93/200 [00:09<00:10, 10.17 it/sec, obj=171]
    INFO - 16:56:06: ...  47%|████▋     | 94/200 [00:09<00:10, 10.18 it/sec, obj=171]
    INFO - 16:56:07: ...  48%|████▊     | 95/200 [00:09<00:10, 10.18 it/sec, obj=171]
    INFO - 16:56:07: ...  48%|████▊     | 96/200 [00:09<00:10, 10.19 it/sec, obj=171]
    INFO - 16:56:07: ...  48%|████▊     | 97/200 [00:09<00:10, 10.18 it/sec, obj=171]
    INFO - 16:56:07: ...  49%|████▉     | 98/200 [00:09<00:10, 10.19 it/sec, obj=171]
    INFO - 16:56:07: ...  50%|████▉     | 99/200 [00:09<00:09, 10.19 it/sec, obj=171]
    INFO - 16:56:07: ...  50%|█████     | 100/200 [00:09<00:09, 10.20 it/sec, obj=171]
    INFO - 16:56:07: ...  50%|█████     | 101/200 [00:09<00:09, 10.20 it/sec, obj=171]
    INFO - 16:56:07: ...  51%|█████     | 102/200 [00:09<00:09, 10.20 it/sec, obj=171]
    INFO - 16:56:07: ...  52%|█████▏    | 103/200 [00:10<00:09, 10.20 it/sec, obj=171]
    INFO - 16:56:07: ...  52%|█████▏    | 104/200 [00:10<00:09, 10.21 it/sec, obj=171]
    INFO - 16:56:07: ...  52%|█████▎    | 105/200 [00:10<00:09, 10.21 it/sec, obj=171]
    INFO - 16:56:08: ...  53%|█████▎    | 106/200 [00:10<00:09, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  54%|█████▎    | 107/200 [00:10<00:09, 10.21 it/sec, obj=171]
    INFO - 16:56:08: ...  54%|█████▍    | 108/200 [00:10<00:09, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  55%|█████▍    | 109/200 [00:10<00:08, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  55%|█████▌    | 110/200 [00:10<00:08, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  56%|█████▌    | 111/200 [00:10<00:08, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  56%|█████▌    | 112/200 [00:10<00:08, 10.23 it/sec, obj=171]
    INFO - 16:56:08: ...  56%|█████▋    | 113/200 [00:11<00:08, 10.22 it/sec, obj=171]
    INFO - 16:56:08: ...  57%|█████▋    | 114/200 [00:11<00:08, 10.23 it/sec, obj=171]
    INFO - 16:56:08: ...  57%|█████▊    | 115/200 [00:11<00:08, 10.23 it/sec, obj=171]
    INFO - 16:56:09: ...  58%|█████▊    | 116/200 [00:11<00:08, 10.24 it/sec, obj=171]
    INFO - 16:56:09: ...  58%|█████▊    | 117/200 [00:11<00:08, 10.24 it/sec, obj=171]
    INFO - 16:56:09: ...  59%|█████▉    | 118/200 [00:11<00:08, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  60%|█████▉    | 119/200 [00:11<00:07, 10.24 it/sec, obj=171]
    INFO - 16:56:09: ...  60%|██████    | 120/200 [00:11<00:07, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  60%|██████    | 121/200 [00:11<00:07, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  61%|██████    | 122/200 [00:11<00:07, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  62%|██████▏   | 123/200 [00:12<00:07, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  62%|██████▏   | 124/200 [00:12<00:07, 10.25 it/sec, obj=171]
    INFO - 16:56:09: ...  62%|██████▎   | 125/200 [00:12<00:07, 10.25 it/sec, obj=170]
    INFO - 16:56:09: ...  63%|██████▎   | 126/200 [00:12<00:07, 10.26 it/sec, obj=170]
    INFO - 16:56:10: ...  64%|██████▎   | 127/200 [00:12<00:07, 10.25 it/sec, obj=170]
    INFO - 16:56:10: ...  64%|██████▍   | 128/200 [00:12<00:07, 10.26 it/sec, obj=170]
    INFO - 16:56:10: ...  64%|██████▍   | 129/200 [00:12<00:06, 10.26 it/sec, obj=170]
    INFO - 16:56:10: ...  65%|██████▌   | 130/200 [00:12<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:10: ...  66%|██████▌   | 131/200 [00:12<00:06, 10.26 it/sec, obj=170]
    INFO - 16:56:10: ...  66%|██████▌   | 132/200 [00:12<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:10: ...  66%|██████▋   | 133/200 [00:12<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:10: ...  67%|██████▋   | 134/200 [00:13<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:10: ...  68%|██████▊   | 135/200 [00:13<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:10: ...  68%|██████▊   | 136/200 [00:13<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:11: ...  68%|██████▊   | 137/200 [00:13<00:06, 10.27 it/sec, obj=170]
    INFO - 16:56:11: ...  69%|██████▉   | 138/200 [00:13<00:06, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  70%|██████▉   | 139/200 [00:13<00:05, 10.27 it/sec, obj=170]
    INFO - 16:56:11: ...  70%|███████   | 140/200 [00:13<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  70%|███████   | 141/200 [00:13<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  71%|███████   | 142/200 [00:13<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  72%|███████▏  | 143/200 [00:13<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  72%|███████▏  | 144/200 [00:13<00:05, 10.29 it/sec, obj=170]
    INFO - 16:56:11: ...  72%|███████▎  | 145/200 [00:14<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:11: ...  73%|███████▎  | 146/200 [00:14<00:05, 10.29 it/sec, obj=170]
    INFO - 16:56:11: ...  74%|███████▎  | 147/200 [00:14<00:05, 10.28 it/sec, obj=170]
    INFO - 16:56:12: ...  74%|███████▍  | 148/200 [00:14<00:05, 10.29 it/sec, obj=170]
    INFO - 16:56:12: ...  74%|███████▍  | 149/200 [00:14<00:04, 10.29 it/sec, obj=170]
    INFO - 16:56:12: ...  75%|███████▌  | 150/200 [00:14<00:04, 10.29 it/sec, obj=170]
    INFO - 16:56:12: ...  76%|███████▌  | 151/200 [00:14<00:04, 10.29 it/sec, obj=170]
    INFO - 16:56:12: ...  76%|███████▌  | 152/200 [00:14<00:04, 10.30 it/sec, obj=170]
    INFO - 16:56:12: ...  76%|███████▋  | 153/200 [00:14<00:04, 10.29 it/sec, obj=170]
    INFO - 16:56:12: ...  77%|███████▋  | 154/200 [00:14<00:04, 10.30 it/sec, obj=170]
    INFO - 16:56:12: ...  78%|███████▊  | 155/200 [00:15<00:04, 10.30 it/sec, obj=170]
    INFO - 16:56:12: ...  78%|███████▊  | 156/200 [00:15<00:04, 10.30 it/sec, obj=170]
    INFO - 16:56:12: ...  78%|███████▊  | 157/200 [00:15<00:04, 10.30 it/sec, obj=170]
    INFO - 16:56:13: ...  79%|███████▉  | 158/200 [00:15<00:04, 10.31 it/sec, obj=170]
    INFO - 16:56:13: ...  80%|███████▉  | 159/200 [00:15<00:03, 10.30 it/sec, obj=170]
    INFO - 16:56:13: ...  80%|████████  | 160/200 [00:15<00:03, 10.31 it/sec, obj=170]
    INFO - 16:56:13: ...  80%|████████  | 161/200 [00:15<00:03, 10.31 it/sec, obj=170]
    INFO - 16:56:13: ...  81%|████████  | 162/200 [00:15<00:03, 10.31 it/sec, obj=170]
    INFO - 16:56:13: ...  82%|████████▏ | 163/200 [00:15<00:03, 10.31 it/sec, obj=170]
    INFO - 16:56:13: ...  82%|████████▏ | 164/200 [00:15<00:03, 10.32 it/sec, obj=170]
    INFO - 16:56:13: ...  82%|████████▎ | 165/200 [00:15<00:03, 10.38 it/sec, obj=Not evaluated]
    INFO - 16:56:13: Optimization result:
    INFO - 16:56:13:    Optimizer info:
    INFO - 16:56:13:       Status: None
    INFO - 16:56:13:       Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
    INFO - 16:56:13:       Number of calls to the objective function by the optimizer: 165
    INFO - 16:56:13:    Solution:
    INFO - 16:56:13:       The solution is feasible.
    INFO - 16:56:13:       Objective: 169.90513692849225
    INFO - 16:56:13:       Standardized constraints:
    INFO - 16:56:13:          volume fraction - 0.3 = 2.1040097875069108e-07
    INFO - 16:56:13: *** End MDOScenario execution (time: 0:00:15.922343) ***

{'max_iter': 200, 'algo': 'NLOPT_MMA'}

Results

Post-process the optimization history:

scenario.post_process(
    "BasicHistory",
    variable_names=["compliance"],
    save=True,
    show=False,
    file_name=problem_name + "_history.png",
)
<gemseo.post.basic_history.BasicHistory object at 0x7fbc38f81d90>
../../_images/MBB_history.png

Plot the solution

plt.ion()  # Ensure that redrawing is possible
fig, ax = plt.subplots()
im = ax.imshow(
    -scenario.optimization_result.x_opt.reshape((n_x, n_y)).T,
    cmap="gray",
    interpolation="none",
    norm=colors.Normalize(vmin=-1, vmax=0),
)
fig.show()
im.set_array(-scenario.optimization_result.x_opt.reshape((n_x, n_y)).T)
fig.canvas.draw()
plt.savefig(problem_name + "_solution.png")
topology optimization MBB../../_images/MBB_solution.png

Total running time of the script: ( 0 minutes 16.503 seconds)

Gallery generated by Sphinx-Gallery