Skip to content

Commit

Permalink
Get rid of GeoOnly and just do two connections from the user side
Browse files Browse the repository at this point in the history
  • Loading branch information
kejacobson committed Apr 15, 2024
1 parent ee74529 commit 399381e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 50 deletions.
4 changes: 4 additions & 0 deletions mphys/scenarios/aerodynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ def _mphys_scenario_setup(self):
MPhysVariables.Aerodynamics.Surface.Geometry.COORDINATES_INPUT)
self.connect(MPhysVariables.Aerodynamics.Surface.Geometry.COORDINATES_OUTPUT,
MPhysVariables.Aerodynamics.Surface.COORDINATES)
self.connect(MPhysVariables.Aerodynamics.Surface.Geometry.COORDINATES_OUTPUT,
MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL)
else:
self.mphys_add_subsystem('mesh',aero_builder.get_mesh_coordinate_subsystem(self.name))
self.connect(MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES,
MPhysVariables.Aerodynamics.Surface.COORDINATES)
self.connect(MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES,
MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL)

self._mphys_add_pre_coupling_subsystem_from_builder('aero', aero_builder, self.name)
self.mphys_add_subsystem('coupling',aero_builder.get_coupling_group_subsystem(self.name))
Expand Down
5 changes: 1 addition & 4 deletions mphys/scenarios/aerostructural.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import openmdao.api as om

from mphys.core import Scenario, CouplingGroup, MPhysVariables, Builder
from mphys.scenarios.geo_disp import GeoDisp, GeoOnly
from mphys.scenarios.geo_disp import GeoDisp


class ScenarioAeroStructural(Scenario):
Expand Down Expand Up @@ -78,9 +78,6 @@ def _mphys_check_coupling_order_inputs(self, given_options):
)

def _mphys_add_pre_coupling_subsystems(self):
if self.options["coupling_group_type"] != "full_coupling":
self.mphys_add_subsystem('geo', GeoOnly(number_of_nodes=self.options["aero_builder"].get_number_of_nodes()))

self._mphys_check_coupling_order_inputs(self.options["pre_coupling_order"])
for discipline in self.options["pre_coupling_order"]:
self._mphys_add_pre_coupling_subsystem_from_builder(
Expand Down
40 changes: 0 additions & 40 deletions mphys/scenarios/geo_disp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,3 @@ def compute_jacvec_product(self,inputs,d_inputs,d_outputs,mode):
d_inputs[self.x_aero0_name] += d_outputs[self.x_aero_name]
if self.u_aero_name in d_inputs:
d_inputs[self.u_aero_name] += d_outputs[self.x_aero_name]

class GeoOnly(om.ExplicitComponent):
"""
This component translates from x_aero0 to x_aero when there are no displacements.
Stand-in for aerostructural scenarios with no structures in the coupling group
"""
def initialize(self):
self.options.declare('number_of_nodes')

def setup(self):
nnodes = self.options['number_of_nodes']
local_size = nnodes * 3

self.x_aero0_name = MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL
self.x_aero_name = MPhysVariables.Aerodynamics.Surface.COORDINATES

self.add_input(self.x_aero0_name,
shape_by_conn=True,
distributed=True,
desc='aerodynamic surface with geom changes',
tags=['mphys_coordinates'])

self.add_output(self.x_aero_name,
shape=local_size,
distributed=True,
desc='deformed aerodynamic surface',
tags=['mphys_coupling'])

def compute(self,inputs,outputs):
outputs[self.x_aero_name] = inputs[self.x_aero0_name]

def compute_jacvec_product(self,inputs,d_inputs,d_outputs,mode):
if mode == 'fwd':
if self.x_aero_name in d_outputs:
if self.x_aero0_name in d_inputs:
d_outputs[self.x_aero_name] += d_inputs[self.x_aero0_name]
if mode == 'rev':
if self.x_aero_name in d_outputs:
if self.x_aero0_name in d_inputs:
d_inputs[self.x_aero0_name] += d_outputs[self.x_aero_name]
9 changes: 8 additions & 1 deletion tests/unit_tests/test_scenario_aerodynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def setUp(self):
self.prob.model.add_subsystem('scenario', ScenarioAerodynamic(aero_builder=builder))
self.prob.model.connect(f'mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}',
f'scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES}')
self.prob.model.connect(f'mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}',
f'scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL}')
self.prob.setup()

def test_mphys_components_were_added(self):
Expand Down Expand Up @@ -94,7 +96,12 @@ def test_subsystem_order(self):

def test_coordinates_connected_from_geometry(self):
scenario = self.prob.model.scenario
systems = ['aero_pre', 'coupling', 'aero_post']
systems = ['aero_pre']
for sys in systems:
self.assertEqual(scenario._conn_global_abs_in2out[f'scenario.{sys}.{MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL}'],
f'scenario.geometry.{MPhysVariables.Aerodynamics.Surface.Geometry.COORDINATES_OUTPUT}')

systems = ['coupling', 'aero_post']
for sys in systems:
self.assertEqual(scenario._conn_global_abs_in2out[f'scenario.{sys}.{MPhysVariables.Aerodynamics.Surface.COORDINATES}'],
f'scenario.geometry.{MPhysVariables.Aerodynamics.Surface.Geometry.COORDINATES_OUTPUT}')
Expand Down
12 changes: 7 additions & 5 deletions tests/unit_tests/test_scenario_aerostructural.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from mphys import MPhysVariables
from mphys.scenarios.aerostructural import ScenarioAeroStructural, CouplingAeroStructural
from mphys.scenarios.geo_disp import GeoDisp, GeoOnly
from mphys.scenarios.geo_disp import GeoDisp

from common_methods import CommonMethods
from fake_aero import AeroBuilder, AeroMeshComp, AeroPreCouplingComp, AeroCouplingComp, AeroPostCouplingComp
Expand Down Expand Up @@ -228,6 +228,8 @@ def setUp(self):
)
self.prob.model.connect(f"aero_mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL}")
self.prob.model.connect(f"aero_mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES}")

self.prob.model.connect(f"struct_mesh.{MPhysVariables.Structures.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Structures.COORDINATES}")
Expand All @@ -237,15 +239,14 @@ def test_run_model(self):
self.common.test_run_model(self)

def test_scenario_components_were_added(self):
self.assertIsInstance(self.prob.model.scenario.geo, GeoOnly)
self.assertIsInstance(self.prob.model.scenario.aero_pre, AeroPreCouplingComp)
self.assertIsInstance(self.prob.model.scenario.struct_pre, StructPreCouplingComp)
self.assertIsInstance(self.prob.model.scenario.aero, AeroCouplingComp)
self.assertIsInstance(self.prob.model.scenario.aero_post, AeroPostCouplingComp)
self.assertIsInstance(self.prob.model.scenario.struct_post, StructPostCouplingCompForNoCoupling)

def test_scenario_subsystem_order(self):
expected_order = ["geo", "aero_pre", "struct_pre", "aero", "aero_post", "struct_post"]
expected_order = ["aero_pre", "struct_pre", "aero", "aero_post", "struct_post"]
self.common.test_subsystem_order(self, self.prob.model.scenario, expected_order)

def test_no_autoivcs(self):
Expand Down Expand Up @@ -295,6 +296,8 @@ def setUp(self):
)
self.prob.model.connect(f"aero_mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES_INITIAL}")
self.prob.model.connect(f"aero_mesh.{MPhysVariables.Aerodynamics.Surface.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Aerodynamics.Surface.COORDINATES}")

self.prob.model.connect(f"struct_mesh.{MPhysVariables.Structures.Mesh.COORDINATES}",
f"scenario.{MPhysVariables.Structures.COORDINATES}")
Expand All @@ -304,14 +307,13 @@ def test_run_model(self):
self.common.test_run_model(self)

def test_scenario_components_were_added(self):
self.assertIsInstance(self.prob.model.scenario.geo, GeoOnly)
self.assertIsInstance(self.prob.model.scenario.aero_pre, AeroPreCouplingComp)
self.assertIsInstance(self.prob.model.scenario.struct_pre, StructPreCouplingComp)
self.assertIsInstance(self.prob.model.scenario.aero_post, AeroPostCouplingCompForNoCoupling)
self.assertIsInstance(self.prob.model.scenario.struct_post, StructPostCouplingCompForNoCoupling)

def test_scenario_subsystem_order(self):
expected_order = ["geo","aero_pre", "struct_pre", "aero_post", "struct_post"]
expected_order = ["aero_pre", "struct_pre", "aero_post", "struct_post"]
self.common.test_subsystem_order(self, self.prob.model.scenario, expected_order)

def test_no_autoivcs(self):
Expand Down

0 comments on commit 399381e

Please sign in to comment.