From 4b6a17832319003564d878f12fe13c394199fbf1 Mon Sep 17 00:00:00 2001 From: acrovato <adrien.crovato@onera.fr> Date: Wed, 5 Feb 2025 14:44:55 +0100 Subject: [PATCH] Fix API by passing 'task' correctly. --- blast/api/blaster_api.py | 3 +- blast/interfaces/dart/blDartInterface.py | 41 +++++++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/blast/api/blaster_api.py b/blast/api/blaster_api.py index ef1d3bc..e6725a0 100644 --- a/blast/api/blaster_api.py +++ b/blast/api/blaster_api.py @@ -41,6 +41,7 @@ def init_blaster(cfg, icfg, iSolverName='DART', task='analysis'): All inputs have default values except Re. - icg: Dict with options. Inviscid solver configuration. - iSolverName (string): Name of the inviscid solver. + - task (string): Type of task (available: analysis, optimization) (default: analysis) Outputs ------- @@ -104,7 +105,7 @@ def init_blaster(cfg, icfg, iSolverName='DART', task='analysis'): # Viscous solver object. vSolver = blast.Driver(_Re, _Minf, _cfl0, _nSections, _xtrF[0], _xtrF[1], _span, _verbose =_verbose) # Solvers interface. - solverAPI = interface(icfg, vSolver, cfg) + solverAPI = interface(icfg, vSolver, cfg, task) # Coupler coupler = Coupler(solverAPI, vSolver, _maxCouplIter = _couplIter, _couplTol = _couplTol, _iterPrint = _iterPrint, _resetInv = _resetInv) diff --git a/blast/interfaces/dart/blDartInterface.py b/blast/interfaces/dart/blDartInterface.py index 68ea7f9..007ac6b 100644 --- a/blast/interfaces/dart/blDartInterface.py +++ b/blast/interfaces/dart/blDartInterface.py @@ -40,7 +40,7 @@ class DartInterface(SolversInterface): adjointSolver : object Adjoint solver object. """ - def __init__(self, dartCfg, vSolver, _cfg): + def __init__(self, dartCfg, vSolver, _cfg, task): """Constructor. Parameters @@ -51,13 +51,16 @@ class DartInterface(SolversInterface): Viscous solver object. _cfg : dict Configuration parameters of the VII interface. + task : string, optional + Type of task (available: analysis, optimization) (default: analysis) + """ # Load DART module if 'dart_path' in dartCfg: # First try imposed path try: init_dart = __import__(dartCfg['dart_path'], fromlist=['init_dart']).init_dart - print(f'DART loaded from specified path {dartCfg["dart_path"]} for {dartCfg["task"]}.') + print(f'DART loaded from specified path {dartCfg["dart_path"]} for {task}.') except ImportError: raise ImportError(f'{ccolors.ANSI_RED}Could not load DART from specified path: {dartCfg["dart_path"]}.{ccolors.ANSI_RESET}') else: @@ -65,14 +68,14 @@ class DartInterface(SolversInterface): for name, path in dartflo_import_paths.items(): try: init_dart = __import__(path, fromlist=['init_dart']).init_dart - print(f'DART loaded from {name} path for {dartCfg["task"]}.') + print(f'DART loaded from {name} path for {task}.') break except ImportError: continue else: raise ImportError(f'{ccolors.ANSI_RED}Could not load DART.{ccolors.ANSI_RESET}') - self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True) + self.iobj = init_dart(dartCfg, task=task, viscous=True) self.solver = self.iobj.get('sol') # Solver self.blw = [self.iobj.get('blwb'), self.iobj.get('blww')] self.adjointSolver = self.iobj.get('adj') @@ -81,12 +84,12 @@ class DartInterface(SolversInterface): if 'iMsh' not in _cfg: _cfg['iMsh'] = self.blw SolversInterface.__init__(self, vSolver, _cfg) - + def run(self): """Run the solver. """ return self.solver.run() - + def writeCp(self, sfx=''): """Write Cp distribution around the airfoil on file. @@ -123,7 +126,7 @@ class DartInterface(SolversInterface): if self.getVerbose() > 1: print('writing data file ' + 'Cp' +sfx + '.dat') np.savetxt('Cp'+sfx+'.dat', data, fmt='%1.6e', delimiter=', ', header='x, y, z, Cp', comments='') - + elif self.getnDim() == 3: # Save surface cp data = np.zeros((self.iobj['bnd'].nodes.size(), 4)) @@ -138,7 +141,7 @@ class DartInterface(SolversInterface): if self.getVerbose() > 1: print('Saving Cp files in vtk format. Msh {:s}, Tag {:.0f}'.format(self.iobj['msh'].name, self.cfg['saveTag'])) invUtils.write_slices(self.iobj['msh'].name, self.cfg['writeSections'], self.cfg['saveTag'], sfx=sfx) - + def save(self, sfx='inviscid'): """Save the solution. @@ -153,17 +156,17 @@ class DartInterface(SolversInterface): """Return the angle of attack. """ return self.solver.pbl.alpha - + def setAoA(self, aoa): """Set the angle of attack. """ self.solver.pbl.update(aoa) - + def getMinf(self): """Return the Mach number. """ return self.solver.pbl.M_inf - + def getCl(self): """Return the lift coefficient. """ @@ -178,27 +181,27 @@ class DartInterface(SolversInterface): """Return the moment coefficient. """ return self.solver.Cm - + def getVerbose(self): """Return the verbosity level. """ return self.solver.verbose - + def getnDim(self): """Return the number of dimensions. """ return self.iobj['pbl'].nDim - + def getnNodesDomain(self): """Return the number of nodes in the domain. """ return self.solver.pbl.msh.nodes.size() - + def reset(self): """Reset the solution. """ self.solver.reset() - + def getInviscidBC(self): """Extract the inviscid paramaters at the edge of the boundary layer and use it as a boundary condition in the viscous solver. @@ -238,7 +241,7 @@ class DartInterface(SolversInterface): raise RuntimeError('dartInterface::Could not resolve how to set\ the mesh. Either ''nDim'' is incorrect or ''msh'' was not set for\ 3D computations') - + def getMesh(self): """Return the mesh on blowing boundaries """ @@ -355,7 +358,7 @@ class DartInterface(SolversInterface): connect2 = np.zeros((len(connectListElems)), dtype=int) for i, e in enumerate(self.blw[0].tag.elems): connect2[connectListElems[i]] = i - + self.iBnd[0].nodesCoord = np.column_stack((data[:,1], data[:,2],\ data[:,3], data[:,4])) self.iBnd[0].setConnectList(connectListNodes, connect2) @@ -403,7 +406,7 @@ class DartInterface(SolversInterface): dataW[:,4] = dataW[connectListNodes,4] self.iBnd[1].nodesCoord = np.column_stack((dataW[:,1], dataW[:,2], \ dataW[:,3], dataW[:,4])) - + connect2_w = np.zeros((len(connectListElems)), dtype=int) for i, e in enumerate(self.blw[1].tag.elems): connect2_w[connectListElems[i]] = i -- GitLab