Skip to content

Commit

Permalink
Merge pull request #59 from anilyil/refactor_mach
Browse files Browse the repository at this point in the history
Refactor mach wrappers and examples for the new api. also adds the aeropropulsive scenario
  • Loading branch information
anilyil authored Apr 13, 2021
2 parents 3bd2c14 + 49dbcad commit 392b4fa
Show file tree
Hide file tree
Showing 15 changed files with 1,469 additions and 1,405 deletions.
109 changes: 47 additions & 62 deletions examples/mach_tutorials/aero/mphys_aero.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,80 @@
import numpy as np
from mpi4py import MPI

import openmdao.api as om
from mphys.multipoint import Multipoint
from mphys.mphys_adflow import ADflowBuilder
from baseclasses import *
from mpi4py import MPI
from baseclasses import AeroProblem
from mphys.scenario_aerodynamic import ScenarioAerodynamic

class Top(om.Group):

class Top(Multipoint):
def setup(self):

aero_options = {
# I/O Parameters
'gridFile':'wing_vol.cgns',
'outputDirectory':'.',
'monitorvariables':['resrho','cl','cd'],
'writeTecplotSurfaceSolution':True,

"gridFile": "wing_vol.cgns",
"outputDirectory": ".",
"monitorvariables": ["resrho", "cl", "cd"],
"writeTecplotSurfaceSolution": True,
# Physics Parameters
'equationType':'RANS',

"equationType": "RANS",
# Solver Parameters
'smoother':'DADI',
'CFL':0.5,
'CFLCoarse':0.25,
'MGCycle':'sg',
'MGStartLevel':-1,
'nCyclesCoarse':250,

"smoother": "DADI",
"CFL": 0.5,
"CFLCoarse": 0.25,
"MGCycle": "sg",
"MGStartLevel": -1,
"nCyclesCoarse": 250,
# ANK Solver Parameters
'useANKSolver':True,
'nsubiterturb': 5,
'anksecondordswitchtol':1e-4,
'ankcoupledswitchtol': 1e-6,
'ankinnerpreconits':2,
'ankouterpreconits':2,
'anklinresmax': 0.1,

"useANKSolver": True,
"nsubiterturb": 5,
"anksecondordswitchtol": 1e-4,
"ankcoupledswitchtol": 1e-6,
"ankinnerpreconits": 2,
"ankouterpreconits": 2,
"anklinresmax": 0.1,
# Termination Criteria
'L2Convergence':1e-12,
'L2ConvergenceCoarse':1e-2,
'nCycles':1000,
"L2Convergence": 1e-12,
"L2ConvergenceCoarse": 1e-2,
"nCycles": 1000,
}

adflow_builder = ADflowBuilder(aero_options)
adflow_builder = ADflowBuilder(aero_options, scenario="aerodynamic")
adflow_builder.initialize(self.comm)

################################################################################
# MPHY setup
################################################################################

# ivc to keep the top level DVs
dvs = self.add_subsystem('dvs', om.IndepVarComp(), promotes=['*'])

# create the multiphysics multipoint group.
mp = self.add_subsystem(
'mp_group',
Multipoint(aero_builder = adflow_builder)
)
self.add_subsystem("dvs", om.IndepVarComp(), promotes=["*"])

# this is the method that needs to be called for every point in this mp_group
mp.mphys_add_scenario('s0')
# create the mesh and cruise scenario because we only have one analysis point
self.add_subsystem("mesh", adflow_builder.get_mesh_coordinate_subsystem())
self.mphys_add_scenario("cruise", ScenarioAerodynamic(aero_builder=adflow_builder))
self.connect("mesh.x_aero0", "cruise.x_aero")

def configure(self):
# create the aero problems for both analysis point.
# this is custom to the ADflow based approach we chose here.
# any solver can have their own custom approach here, and we don't
# need to use a common API. AND, if we wanted to define a common API,
# it can easily be defined on the mp group, or the aero group.
aoa = 1.5
ap0 = AeroProblem(
name='ap0',
mach=0.8,
altitude=10000,
alpha=aoa,
areaRef=45.5,
chordRef=3.25,
evalFuncs=['cl','cd']
name="ap0", mach=0.8, altitude=10000, alpha=aoa, areaRef=45.5, chordRef=3.25, evalFuncs=["cl", "cd"]
)
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')
ap0.addDV("alpha", value=aoa, name="aoa", units="deg")

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
# just flow conditions is probably a better general API
# this call automatically adds the DVs for the respective scenario
self.mp_group.s0.solver_group.aero.mphys_set_ap(ap0)
self.mp_group.s0.aero_funcs.mphys_set_ap(ap0)
# set the aero problem in the coupling and post coupling groups
self.cruise.coupling.mphys_set_ap(ap0)
self.cruise.aero_post.mphys_set_ap(ap0)

# add dvs to ivc and connect
self.dvs.add_output('aoa', val=aoa, units='deg')
self.dvs.add_output("aoa", val=aoa, units="deg")

# call the promote inputs to propagate aoa dvs
# TODO does not work now
# self.cruise._mphys_promote_inputs()
# so connect manually
self.connect("aoa", ["cruise.coupling.aoa", "cruise.aero_post.aoa"])

self.connect('aoa', ['mp_group.s0.solver_group.aero.aoa','mp_group.s0.aero_funcs.aoa'])

################################################################################
# OpenMDAO setup
Expand All @@ -98,7 +83,7 @@ def configure(self):
prob.model = Top()

prob.setup()
om.n2(prob, show_browser=False, outfile='mphys_aero.html')
om.n2(prob, show_browser=False, outfile="mphys_aero.html")

prob.run_model()

Expand All @@ -108,5 +93,5 @@ def configure(self):
# prob.model.list_outputs()
if MPI.COMM_WORLD.rank == 0:
print("Scenario 0")
print('cl =',prob['mp_group.s0.aero_funcs.cl'])
print('cd =',prob['mp_group.s0.aero_funcs.cd'])
print("cl =", prob["cruise.aero_post.cl"])
print("cd =", prob["cruise.aero_post.cd"])
Loading

0 comments on commit 392b4fa

Please sign in to comment.