From 4b427c181e870be106becf9fc60c94c0e743cfa2 Mon Sep 17 00:00:00 2001 From: Paul Dechamps <paul.dechamps@uliege.be> Date: Tue, 21 Jan 2025 13:57:49 +0100 Subject: [PATCH] (docs) Added docs --- blast/interfaces/DSolversInterface.py | 42 +++++++++++ blast/interfaces/dart/DartInterface.py | 69 +++++++++++++++++-- .../interpolators/DMatchingInterpolator.py | 56 ++++++++++++--- .../interpolators/DRbfInterpolator.py | 57 +++++++++++++++ 4 files changed, 211 insertions(+), 13 deletions(-) diff --git a/blast/interfaces/DSolversInterface.py b/blast/interfaces/DSolversInterface.py index 17cf147..2e2e5e1 100644 --- a/blast/interfaces/DSolversInterface.py +++ b/blast/interfaces/DSolversInterface.py @@ -5,7 +5,41 @@ import tbox from blast.interfaces.DDataStructure import Group class SolversInterface: + """ + Interface for solvers. + + Attributes: + ---------- + vSolver : object + Viscous solver object. + cfg : dict + Configuration dictionary. + iBnd : list + Inviscid boundary groups. + vBnd : list + Viscous boundary groups. + interpolator : object + Interpolator object. + deltaStarExt : list + Displacement thickness for the quasi-simultaneous interaction law. + xxExt : list + Surface local coordinates for the quasi-simultaneous interaction law. + vtExt : list + Velocity at the edge of the boundary layer for the quasi-simultaneous interaction law. + vinit : bool + Flag used to check if the viscous solver has been initialized. + """ def __init__(self, _vSolver, _cfg): + """ + Initialize the SolversInterface. + + Parameters: + ---------- + _vSolver : object + Viscous solver object. + _cfg : dict + Configuration dictionary. + """ self.vSolver = _vSolver self.cfg = _cfg @@ -89,6 +123,14 @@ class SolversInterface: self.vtExt[iSec][i] = np.asarray(self.sec[iSec][i].vt) def interpolate(self, dir): + """Interpolate solution between inviscid and viscous meshes. + args: + ---- + dir: str + Direction of interpolation. + 'i2v': inviscid to viscous. + 'v2i': viscous to inviscid. + """ if dir == 'i2v': self.interpolator.inviscidToViscous(self.iBnd, self.vBnd) elif dir == 'v2i': diff --git a/blast/interfaces/dart/DartInterface.py b/blast/interfaces/dart/DartInterface.py index 7913ab5..7640634 100644 --- a/blast/interfaces/dart/DartInterface.py +++ b/blast/interfaces/dart/DartInterface.py @@ -25,7 +25,31 @@ from fwk.coloring import ccolors from blast.interfaces.DSolversInterface import SolversInterface class DartInterface(SolversInterface): + """Interface to the Dart solver. + + Attributes + ---------- + iobj : dict + Dart objects defined in core api of dart. + solver : object + Solver object. + blw : list + Blowing boundaries. + adjointSolver : object + Adjoint solver object. + """ def __init__(self, dartCfg, vSolver, _cfg): + """Constructor. + + Parameters + ---------- + dartCfg : dict + Dart core api configuration. + vSolver : object + Viscous solver object. + _cfg : dict + Configuration parameters of the VII interface. + """ try: from modules.dartflo.dart.api.core import init_dart self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True) @@ -37,8 +61,7 @@ class DartInterface(SolversInterface): else: print('Dart successfully loaded for analysis.') except: - print(ccolors.ANSI_RED, 'Could not load DART. Make sure it is installed.', ccolors.ANSI_RESET) - raise RuntimeError('Import error') + raise ImportError(ccolors.ANSI_RED, 'Could not load DART.', ccolors.ANSI_RESET) _cfg['Format'] = dartCfg['Format'] if 'iMsh' not in _cfg: @@ -46,10 +69,17 @@ class DartInterface(SolversInterface): 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. + """Write Cp distribution around the airfoil on file. + + Parameters + ---------- + sfx : str, optional + Suffix to be added to the file name. The default is ''. """ # Extract Cp on elements self.save(sfx=sfx) @@ -96,40 +126,67 @@ class DartInterface(SolversInterface): invUtils.write_slices(self.iobj['msh'].name, self.cfg['writeSections'], self.cfg['saveTag'], sfx=sfx) def save(self, sfx='inviscid'): + """Save the solution. + + Parameters + ---------- + sfx : str, optional + Suffix to be added to the file name. The default is 'inviscid'. + """ self.solver.save(self.iobj['wrt'], sfx) def getAoA(self): + """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. + """ return self.solver.Cl def getCd(self): + """Return the drag coefficient. + """ return self.solver.Cd def getCm(self): + """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 + """Extract the inviscid paramaters at the edge of the boundary layer and use it as a boundary condition in the viscous solver. Params @@ -146,7 +203,7 @@ class DartInterface(SolversInterface): self.iBnd[n].Rho[iRow] = self.solver.rho[row] def setBlowingVelocity(self): - """ Extract the solution of the viscous calculation (blowing velocity) + """Extract the solution of the viscous calculation (blowing velocity) and use it as a boundary condition in the inviscid solver. """ # Impose blowing velocities. @@ -157,6 +214,8 @@ class DartInterface(SolversInterface): self.blw[n].setU(i, blw) def getWing(self): + """Extract the wing mesh. + """ if self.getnDim() == 2: self.__getWing2D() elif self.getnDim() == 3: diff --git a/blast/interfaces/interpolators/DMatchingInterpolator.py b/blast/interfaces/interpolators/DMatchingInterpolator.py index 3a42cd6..1dd052e 100644 --- a/blast/interfaces/interpolators/DMatchingInterpolator.py +++ b/blast/interfaces/interpolators/DMatchingInterpolator.py @@ -1,23 +1,63 @@ import numpy as np class MatchingInterpolator: - def __init__(self, _cfg, _nDim): - self.cfg = _cfg - self.nDim = _nDim + """ + Matching Interpolator for inviscid and viscous data. + + Attributes: + ---------- + cfg : dict + Configuration dictionary. + nDim : int + Number of dimensions. + """ + def __init__(self, cfg, ndim): + """ + Initialize the MatchingInterpolator. + + Parameters: + ---------- + _cfg : dict + Configuration dictionary. + _nDim : int + Number of dimensions. + """ + self._cfg = cfg + self._ndim = ndim def inviscidToViscous(self, iDict, vDict): - if self.nDim == 2: + """ + Interpolate inviscid data to viscous data. + + Parameters: + ---------- + iDict : dict + Inviscid data dictionary. + vDict : dict + Viscous data dictionary. + """ + if self._ndim == 2: for iReg in range(len(iDict)): vDict[0][iReg].updateVars(iDict[iReg].V, iDict[iReg].M, iDict[iReg].Rho) - elif self.nDim == 3: - for iSec, ysec in enumerate(self.cfg['sections']): + elif self._ndim == 3: + for iSec, ysec in enumerate(self._cfg['sections']): for iReg in range(2): print(iDict[iReg].nodesCoord[iDict[iReg].nodesCoord[:,1] == ysec]) print(iDict[iReg].V[iDict[iReg].nodesCoord[:,1] == ysec]) vDict[iSec][iReg].updateVars(iDict[iReg].V[iDict[iReg].nodesCoord[:,1] == ysec], iDict[iReg].Rho[iDict[iReg].nodesCoord[:,1] == ysec]) def viscousToInviscid(self, iDict, vDict): - if self.nDim == 2: + """ + Interpolate viscous data to inviscid data. + + Parameters: + ---------- + iDict : dict + Inviscid data dictionary. + vDict : dict + Viscous data dictionary. + """ + if self._ndim == 2: for iReg in range(2): iDict[iReg].blowingVel = vDict[0][iReg].blowingVel else: - raise RuntimeError('Incorrect number of dimensions', self.nDim) \ No newline at end of file + raise RuntimeError('Incorrect number of dimensions', self._ndim) \ No newline at end of file diff --git a/blast/interfaces/interpolators/DRbfInterpolator.py b/blast/interfaces/interpolators/DRbfInterpolator.py index d18b723..1a203fe 100644 --- a/blast/interfaces/interpolators/DRbfInterpolator.py +++ b/blast/interfaces/interpolators/DRbfInterpolator.py @@ -3,13 +3,43 @@ import numpy as np from scipy.interpolate import RBFInterpolator class RbfInterpolator: + """ + Radial Basis Function (RBF) Interpolator for inviscid and viscous data. + + Attributes: + ---------- + _cfg : dict + Configuration dictionary. + _ndim : int + Number of dimensions (2 or 3). + """ def __init__(self, cfg, ndim): + """ + Initialize the RbfInterpolator. + + Parameters: + ---------- + cfg : dict + Configuration dictionary. + ndim : int + Number of dimensions (must be 2 or 3). + """ self._cfg = cfg if ndim != 2 and ndim != 3: raise ValueError('Number of dimensions must be 2 or 3 but {} was given'.format(ndim)) self._ndim = ndim def inviscidToViscous(self, iDict, vDict): + """ + Interpolate inviscid data to viscous data. + + Parameters: + ---------- + iDict : dict + Inviscid data dictionary. + vDict : dict + Viscous data dictionary. + """ ## Airfoil # Find stagnation point for iSec in range(len(vDict)): @@ -24,6 +54,16 @@ class RbfInterpolator: vDict[iSec][iReg].updateVars(v, M, rho) def viscousToInviscid(self, iDict, vDict): + """ + Interpolate viscous data to inviscid data. + + Parameters: + ---------- + iDict : dict + Inviscid data dictionary. + vDict : dict + Viscous data dictionary. + """ if self._ndim == 2: for iReg, reg in enumerate(iDict): iDict[iReg].blowingVel = self.__rbfToSection(vDict[0][iReg].elemsCoordTr[:,:(self._ndim-1 if 'vAirfoil' in reg.name else 1)], vDict[0][iReg].blowingVel, reg.elemsCoordTr[:,:(self._ndim-1 if reg.name == 'iWing' else 1)]) @@ -43,6 +83,23 @@ class RbfInterpolator: reg.blowingVel = self.__rbfToSection(viscElemsCoord, viscBlowing, reg.elemsCoord[:,:3]) def __rbfToSection(self, x, var, xs): + """ + Perform RBF interpolation. + + Parameters: + ---------- + x : array_like + Input coordinates. + var : array_like + Variable values at input coordinates. + xs : array_like + Output coordinates. + + Returns: + ------- + array_like + Interpolated variable values at output coordinates. + """ if np.all(var == var[0]): varOut = RBFInterpolator(x, var, neighbors=1, kernel='linear', smoothing=0.0, degree=0)(xs) else: -- GitLab