Skip to content
Snippets Groups Projects

Version 1.2

Merged Adrien Crovato requested to merge adri into master
4 files
+ 8
8
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 17
14
@@ -17,15 +17,13 @@
## Initialize SDPM
# Adrien Crovato
def init_sdpm(cfg, use_ad=False):
def init_sdpm(cfg):
"""Initialize SDPM components
Parameters
----------
cfg : dict
Dictionary of parameters to configure SDPM
use_ad : bool, optional
Whether to use AD within SDPM (default: False)
Returns
-------
@@ -44,13 +42,13 @@ def init_sdpm(cfg, use_ad=False):
Lifting body
sol : sdpm.Solver object
Direct solver
adj : sdpm.Adjoint object
Adjoint solver
grd : sdpm.Gradient object
Gradient calculator
"""
# Imports
import sdpm
from sdpm.gmsh import MeshLoader
from sdpm.utils import interpolate_modes
from sdpm.utils import interpolate_modes, interpolate_pressure
import math
# Sanity checks
@@ -58,14 +56,14 @@ def init_sdpm(cfg, use_ad=False):
raise RuntimeError('Symmetric (half) geometric model cannot be used with nonzero angle of sideslip (AoS)!\n')
# Mesh
pars = {} if 'Pars' not in cfg else cfg['Pars']
pars = cfg.get('Pars', {})
_msh = MeshLoader(cfg['File']).run(pars)
_wrt = sdpm.GmshExport(_msh)
# Problem
aoa = 0 if 'AoA' not in cfg else cfg['AoA'] * math.pi / 180
aos = 0 if 'AoS' not in cfg else cfg['AoS'] * math.pi / 180
minf = 0 if 'Mach' not in cfg else cfg['Mach']
aoa = cfg.get('AoA', 0.) * math.pi / 180
aos = cfg.get('AoS', 0.) * math.pi / 180
minf = cfg.get('Mach', 0.)
_pbl = sdpm.Problem(_msh)
_pbl.setGeometry(cfg['s_ref'], cfg['c_ref'], cfg['x_ref'], cfg['y_ref'], cfg['z_ref'], cfg['Symmetry'])
_pbl.setFreestream(aoa, aos, minf)
@@ -79,12 +77,17 @@ def init_sdpm(cfg, use_ad=False):
x_modes, amp_modes = interpolate_modes(cfg['Modes'], _bdy.getNodes())
for i in range(cfg['Num_modes']):
_bdy.setFlexibleMotion(i, 1 / amp_modes[i], x_modes[:, 3*i:3*i+3])
if 'Transonic_pressure_grad' in cfg:
dcp = interpolate_pressure(cfg['Transonic_pressure_grad'], _bdy.getNodes())
_bdy.setTransonicPressureGrad(dcp[:, 0])
_pbl.addBody(_bdy)
# Solver
vrb = cfg['Verb_lvl'] if 'Verb_lvl' in cfg else 1
_sol = sdpm.Solver(_pbl, vrb)
_adj = sdpm.Adjoint(_sol) if use_ad else None
vrb = cfg.get('Verb_lvl', 1)
_sol = sdpm.Solver(_pbl, vrb) if 'Transonic_pressure_grad' not in cfg else sdpm.SolverTransonic(_pbl, vrb)
# Gradient
_grd = sdpm.Gradient(_sol)
# Return
return {
@@ -95,5 +98,5 @@ def init_sdpm(cfg, use_ad=False):
'pbl': _pbl,
'bdy': _bdy,
'sol': _sol,
'adj': _adj
'grd': _grd
}
Loading