Skip to content

Commit

Permalink
Make geometry spline interpolation mesh independent (mdolab#435)
Browse files Browse the repository at this point in the history
* Make geometry spline interpolation mesh independent

* Fix remaining interpolated values

* Fix tests

* flake8 fixes
  • Loading branch information
A-CGray authored Jul 19, 2024
1 parent 97be635 commit 9c123a3
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 76 deletions.
16 changes: 8 additions & 8 deletions openaerostruct/geometry/geometry_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import openmdao.api as om
from openaerostruct.utils.check_surface_dict import check_surface_dict_keys
from openaerostruct.utils.interpolation import get_normalized_span_coords


class Geometry(om.Group):
Expand Down Expand Up @@ -29,7 +30,6 @@ def setup(self):

# Get the surface name and create a group to contain components
# only for this surface
ny = surface["mesh"].shape[1]

if self.options["DVGeo"]:
from openaerostruct.geometry.ffd_component import GeometryMesh
Expand All @@ -39,7 +39,7 @@ def setup(self):
if "t_over_c_cp" in surface.keys():
n_cp = len(surface["t_over_c_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"t_over_c_bsp",
om.SplineComp(
Expand Down Expand Up @@ -67,7 +67,7 @@ def setup(self):
if "twist_cp" in surface.keys():
n_cp = len(surface["twist_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny))
x_interp = get_normalized_span_coords(surface)
comp = self.add_subsystem(
"twist_bsp",
om.SplineComp(
Expand All @@ -86,7 +86,7 @@ def setup(self):
if "chord_cp" in surface.keys():
n_cp = len(surface["chord_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny))
x_interp = get_normalized_span_coords(surface)
comp = self.add_subsystem(
"chord_bsp",
om.SplineComp(
Expand All @@ -103,7 +103,7 @@ def setup(self):
if "t_over_c_cp" in surface.keys():
n_cp = len(surface["t_over_c_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"t_over_c_bsp",
om.SplineComp(
Expand All @@ -119,7 +119,7 @@ def setup(self):
if "xshear_cp" in surface.keys():
n_cp = len(surface["xshear_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny))
x_interp = get_normalized_span_coords(surface)
comp = self.add_subsystem(
"xshear_bsp",
om.SplineComp(
Expand All @@ -136,7 +136,7 @@ def setup(self):
if "yshear_cp" in surface.keys():
n_cp = len(surface["yshear_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny))
x_interp = get_normalized_span_coords(surface)
comp = self.add_subsystem(
"yshear_bsp",
om.SplineComp(
Expand All @@ -153,7 +153,7 @@ def setup(self):
if "zshear_cp" in surface.keys():
n_cp = len(surface["zshear_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny))
x_interp = get_normalized_span_coords(surface)
comp = self.add_subsystem(
"zshear_bsp",
om.SplineComp(
Expand Down
8 changes: 3 additions & 5 deletions openaerostruct/structures/tube_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import openmdao.api as om
from openaerostruct.structures.section_properties_tube import SectionPropertiesTube
from openaerostruct.geometry.radius_comp import RadiusComp
from openaerostruct.utils.interpolation import get_normalized_span_coords


class TubeGroup(om.Group):
Expand All @@ -14,13 +14,11 @@ def initialize(self):

def setup(self):
surface = self.options["surface"]
mesh = surface["mesh"]
ny = mesh.shape[1]

if "thickness_cp" in surface.keys():
n_cp = len(surface["thickness_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"thickness_bsp",
om.SplineComp(
Expand All @@ -35,7 +33,7 @@ def setup(self):
if "radius_cp" in surface.keys():
n_cp = len(surface["radius_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"radius_bsp",
om.SplineComp(
Expand Down
7 changes: 3 additions & 4 deletions openaerostruct/structures/wingbox_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import openmdao.api as om
from openaerostruct.structures.section_properties_wingbox import SectionPropertiesWingbox
from openaerostruct.structures.wingbox_geometry import WingboxGeometry
from openaerostruct.utils.interpolation import get_normalized_span_coords


class WingboxGroup(om.Group):
Expand All @@ -12,12 +12,11 @@ def initialize(self):

def setup(self):
surface = self.options["surface"]
ny = surface["mesh"].shape[1]

if "spar_thickness_cp" in surface.keys():
n_cp = len(surface["spar_thickness_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"spar_thickness_bsp",
om.SplineComp(
Expand All @@ -32,7 +31,7 @@ def setup(self):
if "skin_thickness_cp" in surface.keys():
n_cp = len(surface["skin_thickness_cp"])
# Add bspline components for active bspline geometric variables.
x_interp = np.linspace(0.0, 1.0, int(ny - 1))
x_interp = get_normalized_span_coords(surface, mid_panel=True)
comp = self.add_subsystem(
"skin_thickness_bsp",
om.SplineComp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def test(self):

prob.run_driver()

assert_near_equal(prob["aero_point_0.wing_perf.CL"][0], 0.464191542231, 1e-6)
assert_near_equal(prob["aero_point_0.wing_perf.CD"][0], 0.020417875291205534, 1e-6)
assert_near_equal(prob["aero_point_0.CM"][1], -1.859570880469676, 1e-6)
assert_near_equal(prob["aero_point_0.CL"][0], 0.46419154063077483, 1e-6)
assert_near_equal(prob["aero_point_0.CD"][0], 0.020863555824806052, 1e-6)
assert_near_equal(prob["aero_point_0.CM"][1], -1.8595708973535592, 1e-6)


if __name__ == "__main__":
Expand Down
11 changes: 7 additions & 4 deletions openaerostruct/tests/test_aero_opt_wavedrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openaerostruct.geometry.utils import generate_mesh
from openaerostruct.geometry.geometry_group import Geometry
from openaerostruct.aerodynamics.aero_groups import AeroPoint
from openaerostruct.utils.testing import assert_opt_successful

import openmdao.api as om

Expand Down Expand Up @@ -106,11 +107,13 @@ def test(self):
# Set up the problem
prob.setup()

prob.run_driver()
optResult = prob.run_driver()

assert_near_equal(prob["aero_point_0.wing_perf.CL"][0], 0.5, 1e-6)
assert_near_equal(prob["aero_point_0.wing_perf.CD"][0], 0.020838936785019083, 1e-6)
assert_near_equal(prob["aero_point_0.CM"][1], -2.081989092575424, 1e-6)
assert_opt_successful(self, optResult)

assert_near_equal(prob["aero_point_0.CL"][0], 0.5, 1e-6)
assert_near_equal(prob["aero_point_0.CD"][0], 0.021353004050991248, 1e-6)
assert_near_equal(prob["aero_point_0.CM"][1], -2.0819892547514067, 1e-6)


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions openaerostruct/tests/test_aerostruct.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from openmdao.utils.assert_utils import assert_near_equal
import unittest
from openaerostruct.utils.testing import assert_opt_successful


class Test(unittest.TestCase):
Expand Down Expand Up @@ -144,9 +145,10 @@ def test(self):
# group.
assert_near_equal(prob["AS_point_0.beta"], 0.0)

prob.run_driver()
optResult = prob.run_driver()
assert_opt_successful(self, optResult)

assert_near_equal(prob["AS_point_0.fuelburn"][0], 92369.79279575823, 1e-8)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 92523.945549167, 1e-8)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions openaerostruct/tests/test_aerostruct_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def test(self):

prob.run_model()

assert_near_equal(prob["AS_point_0.fuelburn"][0], 251362.24734663023, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.7033677364356814, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 263398.25938918366, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.6462808405237332, 1e-5)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions openaerostruct/tests/test_aerostruct_analysis_Sref.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test(self):

prob.run_model()

assert_near_equal(prob["AS_point_0.CL"][0], 1.6217443031469607, 1e-6)
assert_near_equal(prob["AS_point_0.CM"][1], -1.9988780195141023, 1e-5)
assert_near_equal(prob["AS_point_0.CL"][0], 1.6210175228727655, 1e-6)
assert_near_equal(prob["AS_point_0.CM"][1], -1.8365760768848112, 1e-5)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions openaerostruct/tests/test_aerostruct_analysis_compressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test(self):

prob.run_model()

assert_near_equal(prob["AS_point_0.fuelburn"][0], 213840.78859689648, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.9866929184880228, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 224121.12881258246, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.9083682371351329, 1e-5)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions openaerostruct/tests/test_aerostruct_engine_thrusts.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def test(self):
print(prob["AS_point_0.fuelburn"][0])
print(prob["AS_point_0.CM"][1])

assert_near_equal(prob["AS_point_0.fuelburn"][0], 251929.9085951508, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.7008367976235399, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 263992.6780138112, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.6438933659444002, 1e-5)


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions openaerostruct/tests/test_aerostruct_ffd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
import numpy as np
from openaerostruct.utils.constants import grav_constant
from openaerostruct.utils.testing import assert_opt_successful

# check if pygeo is available
try:
Expand Down Expand Up @@ -165,9 +166,10 @@ def test(self):
prob.setup()

# prob.run_model()
prob.run_driver()
optResult = prob.run_driver()
assert_opt_successful(self, optResult)

assert_near_equal(prob["AS_point_0.fuelburn"][0], 92343.61493294379, 1e-3)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 92474.52106288195, 1e-3)


if __name__ == "__main__":
Expand Down
16 changes: 10 additions & 6 deletions openaerostruct/tests/test_aerostruct_groundeffect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from openmdao.utils.assert_utils import assert_near_equal
import unittest
from openaerostruct.utils.testing import assert_check_totals
from openaerostruct.utils.testing import assert_check_totals, assert_opt_successful


class Test(unittest.TestCase):
Expand Down Expand Up @@ -144,17 +144,21 @@ def test(self):
# Set up the problem
prob.setup(check=True)

prob.run_driver()
assert_near_equal(prob["AS_point_0.fuelburn"][0], 92369.74980979414, 1e-6)
optResult = prob.run_driver()
assert_opt_successful(self, optResult)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 92523.90218121602, 1e-6)

prob["height_agl"] = 20.0
prob.run_driver()
optResult = prob.run_driver()
assert_opt_successful(self, optResult)
# the fuel burn should be less in ground effect
assert_near_equal(prob["AS_point_0.fuelburn"][0], 86910.5549671242, 1e-6)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 86980.04655202407, 1e-6)
totals = prob.check_totals(
of=["AS_point_0.L_equals_W", "AS_point_0.fuelburn", "AS_point_0.wing_perf.failure"],
wrt=["wing.twist_cp", "alpha", "height_agl"],
compact_print=True,
out_stream=None,
abs_err_tol=1e-2,
rel_err_tol=1e-5,
)
assert_check_totals(totals, atol=1e-2, rtol=1e-5)

Expand Down
4 changes: 2 additions & 2 deletions openaerostruct/tests/test_aerostruct_point_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def test(self):

prob.run_model()

assert_near_equal(prob["AS_point_0.fuelburn"][0], 252038.66600566648, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.7006002684582702, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 264106.7825178142, 1e-4)
assert_near_equal(prob["AS_point_0.CM"][1], -0.6436834908660709, 1e-5)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def test(self):

prob.run_model()

assert_near_equal(prob["AS_point_0.fuelburn"][0], 84598.60636387265, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0] / 1.25, 24009.5230566, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 87333.56998786073, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0], 34500.40422127632, 1e-5)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions openaerostruct/tests/test_aerostruct_wingbox_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ def test(self):
print(prob["wing.structural_mass"][0] / 1.25)
print(prob["AS_point_0.wing_perf.failure"][0])

assert_near_equal(prob["AS_point_0.fuelburn"][0], 84999.8396153129, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0] / 1.25, 24009.5230566, 1e-5)
assert_near_equal(prob["AS_point_0.wing_perf.failure"][0], 1.6254327137382174, 1e-5)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 87760.55423816708, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0], 34500.40422127632, 1e-5)
assert_near_equal(prob["AS_point_0.wing_perf.failure"][0], -0.15727437869018163, 1e-5)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from openaerostruct.geometry.utils import generate_mesh
from openaerostruct.utils.testing import assert_opt_successful

from openaerostruct.integration.aerostruct_groups import AerostructGeometry, AerostructPoint

Expand Down Expand Up @@ -426,15 +427,17 @@ def test(self):
# Set up the problem
prob.setup()

prob.run_driver()
optResult = prob.run_driver()

print(prob["AS_point_0.fuelburn"][0])
print(prob["wing.structural_mass"][0] / 1.25)
print(prob["fuel_vol_delta.fuel_vol_delta"][0])

assert_near_equal(prob["AS_point_0.fuelburn"][0], 76869.38586654868, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0] / 1.25, 11619.131535449487, 1e-4)
assert_near_equal(prob["fuel_vol_delta.fuel_vol_delta"][0], 42.98939210455205, 1e-4)
assert_opt_successful(self, optResult)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 76869.3858256513, 1e-4)
assert_near_equal(prob["wing.structural_mass"][0], 14523.135605406405, 1e-4)
assert_near_equal(prob["fuel_vol_delta.fuel_vol_delta"][0], 42.99371350246894, 1e-4)
assert_near_equal(prob["AS_point_0.CL"][0], 0.5, 1e-5)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from openmdao.utils.assert_utils import assert_near_equal
from openaerostruct.utils.testing import assert_opt_successful
import unittest
import numpy as np

Expand Down Expand Up @@ -428,11 +429,12 @@ def test(self):
# Set up the problem
prob.setup()

optFailed = prob.run_driver()
optResult = prob.run_driver()

self.assertFalse(optFailed)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 85348.88283214, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0], 13029.71120634, 1e-5)
assert_opt_successful(self, optResult)
assert_near_equal(prob["AS_point_0.fuelburn"][0], 85374.45357945036, 1e-5)
assert_near_equal(prob["wing.structural_mass"][0], 13048.465090719292, 1e-5)
assert_near_equal(prob["AS_point_0.CL"][0], 0.5, 1e-5)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 9c123a3

Please sign in to comment.