Skip to content
Snippets Groups Projects
Verified Commit 988d8aa1 authored by Paul Dechamps's avatar Paul Dechamps :speech_balloon:
Browse files

(feat) Coupler now takes dict as input

parent 0851ad2d
No related branches found
No related tags found
No related merge requests found
...@@ -25,15 +25,21 @@ import numpy as np ...@@ -25,15 +25,21 @@ import numpy as np
import blast.blUtils as vutils import blast.blUtils as vutils
class Coupler: class Coupler:
def __init__(self, iSolverAPI, vSolver, _maxCouplIter=150, _couplTol=1e-4, _iterPrint=1, _resetInv=False, sfx=''): def __init__(self, iSolverAPI, vSolver, vconfig):
self.isol = iSolverAPI self.isol = iSolverAPI
self.vsol = vSolver self.vsol = vSolver
self.maxIter = _maxCouplIter self.maxIter = vconfig.get('couplIter', 50)
self.tol = _couplTol self.tol = vconfig.get('couplTol', 1e-4)
self.resetInviscid = _resetInv self.resetInviscid = vconfig.get('resetInv', True)
self.iterPrint = _iterPrint if self.isol.getVerbose() == 0 and self.vsol.verbose == 0 else 1 self.iterPrint = vconfig.get('iterPrint', 1)
self.iterSaveRestart = vconfig.get('iterSaveRestart', float('inf'))
self.saveCouplingIters = vconfig.get('saveCouplingIters', False)
self.iterPrint = self.iterPrint if self.isol.getVerbose() == 0 and self.vsol.verbose == 0 else 1
self.tms = fwk.Timers() self.tms = fwk.Timers()
self.filesfx = sfx self.filesfx = vconfig.get('filesfx', '')
self.restart = vconfig.get('restart_solution', False)
print('') print('')
print(' ######################################################## ') print(' ######################################################## ')
print('| ___ __ ___ _________________ |') print('| ___ __ ___ _________________ |')
...@@ -59,18 +65,20 @@ class Coupler: ...@@ -59,18 +65,20 @@ class Coupler:
print(f'{"Verbosity level:":<30s} {self.isol.getVerbose():<2.0f}') print(f'{"Verbosity level:":<30s} {self.isol.getVerbose():<2.0f}')
print('') print('')
def run(self, write=True): def run(self, write=True, doit=False):
# Aerodynamic coefficients. # Aerodynamic coefficients.
aeroCoeffs = {'Cl':[], 'Cd': [], 'Cdwake': []} aeroCoeffs = {'Cl':[], 'Cd': [], 'Cdwake': []}
# Convergence parameters. # Convergence parameters.
couplIter = 0 couplIter = 0
cdPrev = 0.0 if self.restart:
cdPrev = self.isol.cdPrev
else:
cdPrev = 0.0
self.isol.getBlowingBoundary(couplIter)
while couplIter < self.maxIter: while couplIter < self.maxIter:
# Impose blowing boundary condition in the inviscid solver.
self.tms['processing'].start() self.tms['processing'].start()
self.isol.getBlowingBoundary(couplIter)
self.isol.interpolate('v2i') self.isol.interpolate('v2i')
self.isol.setBlowingVelocity() self.isol.setBlowingVelocity()
self.tms['processing'].stop() self.tms['processing'].stop()
...@@ -102,6 +110,8 @@ class Coupler: ...@@ -102,6 +110,8 @@ class Coupler:
vEc = self.vsol.run() vEc = self.vsol.run()
self.tms['viscous'].stop() self.tms['viscous'].stop()
self.isol.getBlowingBoundary(couplIter+1)
aeroCoeffs['Cl'].append(self.isol.getCl()) aeroCoeffs['Cl'].append(self.isol.getCl())
aeroCoeffs['Cd'].append(self.isol.getCd() + self.vsol.Cdf) aeroCoeffs['Cd'].append(self.isol.getCd() + self.vsol.Cdf)
aeroCoeffs['Cdwake'].append(self.vsol.Cdt) aeroCoeffs['Cdwake'].append(self.vsol.Cdt)
...@@ -111,6 +121,11 @@ class Coupler: ...@@ -111,6 +121,11 @@ class Coupler:
#cd = self.vsol.Cdt if self.vsol.Cdt != 0 else self.vsol.Cdf + self.isol.getCd() #cd = self.vsol.Cdt if self.vsol.Cdt != 0 else self.vsol.Cdf + self.isol.getCd()
error = abs((cd - cdPrev) / cd) if cd != 0 else 1 error = abs((cd - cdPrev) / cd) if cd != 0 else 1
# Save restart file
if couplIter % self.iterSaveRestart == 0:
_sfx = '_'+str(couplIter) if self.saveCouplingIters else ''
self.isol.save_restart(cd, sfx=_sfx)
if error <= self.tol: if error <= self.tol:
print(ccolors.ANSI_GREEN, '{:>4.0f}| {:>7.5f} {:>7.5f} {:>7.5f} | {:>6.4f} {:>6.4f} | {:>5.0f} {:>5.0f} | {:>6.3f}\n'.format(couplIter, self.isol.getCl(), self.isol.getTotalDrag(), self.vsol.Cdt, self.vsol.bodies[0].getAvgxtr(0), self.vsol.bodies[0].getAvgxtr(1), iEc, vEc, np.log10(error)), ccolors.ANSI_RESET) print(ccolors.ANSI_GREEN, '{:>4.0f}| {:>7.5f} {:>7.5f} {:>7.5f} | {:>6.4f} {:>6.4f} | {:>5.0f} {:>5.0f} | {:>6.3f}\n'.format(couplIter, self.isol.getCl(), self.isol.getTotalDrag(), self.vsol.Cdt, self.vsol.bodies[0].getAvgxtr(0), self.vsol.bodies[0].getAvgxtr(1), iEc, vEc, np.log10(error)), ccolors.ANSI_RESET)
if iEc != 0 or vEc != 0: if iEc != 0 or vEc != 0:
...@@ -156,12 +171,10 @@ class Coupler: ...@@ -156,12 +171,10 @@ class Coupler:
# Blowing velocity # Blowing velocity
for ibody in range(self.isol.getnBodies()): for ibody in range(self.isol.getnBodies()):
for b in self.isol.iBnd[ibody]: for b in self.isol.iBnd[ibody]:
for i in range(len(b.blowingVel)): b.setBlowingVelocity(np.zeros(b.getnElms()))
b.blowingVel[i] = 0.
for sec in self.isol.vBnd[ibody]: for sec in self.isol.vBnd[ibody]:
for side in sec: for side in sec:
for i in range(len(side.blowingVel)): side.setBlowingVelocity(np.zeros(side.getnElms()))
side.blowingVel[i] = 0.
self.isol.setBlowingVelocity() self.isol.setBlowingVelocity()
for ibody, body in enumerate(self.vsol.bodies): for ibody, body in enumerate(self.vsol.bodies):
......
...@@ -112,11 +112,9 @@ def initBlast(iconfig, vconfig, iSolver='DART', task='analysis'): ...@@ -112,11 +112,9 @@ def initBlast(iconfig, vconfig, iSolver='DART', task='analysis'):
vsol = initBL(vconfig['Re'], isol.getMinf(), vconfig['CFL0'], vconfig['sections'], types, vconfig['spans'], vconfig['xtrF'], isol.getVerbose()) vsol = initBL(vconfig['Re'], isol.getMinf(), vconfig['CFL0'], vconfig['sections'], types, vconfig['spans'], vconfig['xtrF'], isol.getVerbose())
isol.addViscousSolver(vsol) isol.addViscousSolver(vsol)
# Coupler # Coupler
import blast.blCoupler as blastCoupler import blast.blCoupler as blastCoupler
coupler = blastCoupler.Coupler(isol, vsol, _maxCouplIter=vconfig['couplIter'], _couplTol=vconfig['couplTol'], _iterPrint=vconfig['iterPrint'], _resetInv=vconfig['resetInv'], sfx=vconfig['sfx']) coupler = blastCoupler.Coupler(isol, vsol, vconfig)
return coupler, isol, vsol return coupler, isol, vsol
def mesh(file, pars): def mesh(file, pars):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment