pygeo/parameterization/DVGeo.py
def demoDesignVars(
        self, directory, includeLocal=True, includeGlobal=True, pointSet=None, CFDSolver=None, callBack=None, freq=2
    ):
        """
        This function can be used to "test" the design variable parametrization
        for a given optimization problem. It should be called in the script
        after DVGeo has been set up. The function will loop through all the
        design variables and write out a deformed FFD volume for the upper
        and lower bound of every design variable. It can also write out
        deformed point sets and surface meshes.

        Parameters
        ----------
        directory : str
            The directory where the files should be written.
        includeLocal : boolean
            False if you don't want to include the shape variables.
        includeGlobal : boolean
            False if you don't want to include global variables.
        pointSet : str
            Name of the point set to write out.
            If None, no point set output is generated.
        CFDSolver : str
            An ADflow instance that will be used to write out deformed surface
            meshes. In addition to having a DVGeo object, CFDSolver must have
            an AeroProblem set, for example with ``CFDSolver.setAeroProblem(ap)``.
            If CFDSolver is None, no surface mesh output is generated.
        callBack : function
            This allows the user to perform an additional task at each new design
            variable iteration. The callback function must take two inputs:

            1. the output directory name (str) and
            2. the iteration count (int).
        freq : int
            Number of snapshots to take between the upper and lower bounds of
            a given variable. If greater than 2, will do a sinusoidal sweep.
        """
        # Generate directories
        os.makedirs(f"{directory}/ffd", exist_ok=True)
        if pointSet is not None:
            os.makedirs(f"{directory}/pointset", exist_ok=True)
        if CFDSolver is not None:
            os.makedirs(f"{directory}/surf", exist_ok=True)

        # Get design variables
        dvDict = self.getValues()

        # Loop through design variables on self and children
        geoList = self.getFlattenedChildren()
        for geo in geoList:
            for key in dvDict:
                lower = []
                upper = []
                if key in geo.DV_listLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listLocal[key].lower
                    upper = geo.DV_listLocal[key].upper

                elif key in geo.DV_listSpanwiseLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listSpanwiseLocal[key].lower
                    upper = geo.DV_listSpanwiseLocal[key].upper

                elif key in geo.DV_listSectionLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listSectionLocal[key].lower
                    upper = geo.DV_listSectionLocal[key].upper

                elif key in geo.DV_listGlobal:
                    if not includeGlobal:
                        continue
                    lower = geo.DV_listGlobal[key].lower
                    upper = geo.DV_listGlobal[key].upper

                if lower is None or upper is None:
                    raise Error("demoDesignVars requires upper and lower bounds on all design variables.")

                x = dvDict[key].flatten()
                nDV = len(lower)
                for j in range(nDV):
                    count = 0
                    if freq == 2:
                        stops = [lower[j], upper[j]]
                    elif freq > 2:
                        sinusoid = np.sin(np.linspace(0, np.pi, freq))
                        down_swing = x[j] + (lower[j] - x[j]) * sinusoid
                        up_swing = x[j] + (upper[j] - x[j]) * sinusoid
                        stops = np.concatenate((down_swing[:-1], up_swing[:-1]))

                    for val in stops:
                        # Add perturbation to the design variable and update
                        old_val = x[j]
                        x[j] = val
                        dvDict.update({key: x})
                        self.setDesignVars(dvDict)

                        # Set output filename
                        outFile = f"{key}_{j:03d}_iter_{count:03d}"

                        # Write FFD
                        self.writeTecplot(f"{directory}/ffd/{outFile}.dat")

                        # Write point set
                        if pointSet is not None:
                            self.update(pointSet)
                            self.writePointSet(pointSet, f"{directory}/pointset/{outFile}")

                        # Write surface mesh
                        if CFDSolver is not None:
                            CFDSolver.DVGeo.setDesignVars(dvDict)
                            CFDSolver.setAeroProblem(CFDSolver.curAP)
                            CFDSolver.writeSurfaceSolutionFileTecplot(f"{directory}/surf/{outFile}")

                        # Call user function
                        if callBack is not None:
                            callBack(directory, count)

                        # Reset variable
                        x[j] = old_val
                        dvDict.update({key: x})

                        # Iterate counter
                        count += 1

        This function can be used to "test" the design variable parametrization
        for a given optimization problem. It should be called in the script
        after DVGeo has been set up. The function will loop through all the
        design variables and write out a deformed FFD volume for the upper
        and lower bound of every design variable. It can also write out
        deformed point sets and surface meshes.

        Parameters
        ----------
        directory : str
            The directory where the files should be written.
        includeLocal : boolean
            False if you don't want to include the shape variables.
        includeGlobal : boolean
            False if you don't want to include global variables.
        pointSet : str
            Name of the point set to write out.
            If None, no point set output is generated.
        CFDSolver : str
            An ADflow instance that will be used to write out deformed surface
            meshes. In addition to having a DVGeo object, CFDSolver must have
            an AeroProblem set, for example with ``CFDSolver.setAeroProblem(ap)``.
            If CFDSolver is None, no surface mesh output is generated.
        callBack : function
            This allows the user to perform an additional task at each new design
            variable iteration. The callback function must take two inputs:

            1. the output directory name (str) and
            2. the iteration count (int).
        freq : int
            Number of snapshots to take between the upper and lower bounds of
            a given variable. If greater than 2, will do a sinusoidal sweep.
        
This function can be used to "test" the design variable parametrization
for a given optimization problem. It should be called in the script
after DVGeo has been set up. The function will loop through all the
design variables and write out a deformed FFD volume for the upper
and lower bound of every design variable. It can also write out
deformed point sets and surface meshes.

Parameters

directory : str
The directory where the files should be written.
includeLocal : boolean
False if you don't want to include the shape variables.
includeGlobal : boolean
False if you don't want to include global variables.
pointSet : str
Name of the point set to write out.
If None, no point set output is generated.
CFDSolver : str
An ADflow instance that will be used to write out deformed surface
meshes. In addition to having a DVGeo object, CFDSolver must have
an AeroProblem set, for example with ``CFDSolver.setAeroProblem(ap)``.
If CFDSolver is None, no surface mesh output is generated.
callBack : function
This allows the user to perform an additional task at each new design
variable iteration. The callback function must take two inputs.

1. the output directory name (str) and
2. the iteration count (int).
freq : int
Number of snapshots to take between the upper and lower bounds of
a given variable. If greater than 2, will do a sinusoidal sweep.
This function can be used to " test " the design variable parametrization for a given optimization problem . It should be called in the script after DVGeo has been set up . The function will loop through all the design variables and write out a deformed FFD volume for the upper and lower bound of every design variable . It can also write out deformed point sets and surface meshes . Parameters directory : str The directory where the files should be written . includeLocal : boolean False if you don ' t want to include the shape variables . includeGlobal : boolean False if you don ' t want to include global variables . pointSet : str Name of the point set to write out . If None no point set output is generated . CFDSolver : str An ADflow instance that will be used to write out deformed surface meshes . In addition to having a DVGeo object CFDSolver must have an AeroProblem set for example with ` ` CFDSolver . setAeroProblem ( ap ) ` ` . If CFDSolver is None no surface mesh output is generated . callBack : function This allows the user to perform an additional task at each new design variable iteration . The callback function must take two inputs . 1 . the output directory name ( str ) and 2 . the iteration count ( int ) . freq : int Number of snapshots to take between the upper and lower bounds of a given variable . If greater than 2 will do a sinusoidal sweep .
def demoDesignVars(
        self, directory, includeLocal=True, includeGlobal=True, pointSet=None, CFDSolver=None, callBack=None, freq=2
    ):
        os.makedirs(f"{directory}/ffd", exist_ok=True)
        if pointSet is not None:
            os.makedirs(f"{directory}/pointset", exist_ok=True)
        if CFDSolver is not None:
            os.makedirs(f"{directory}/surf", exist_ok=True)
        dvDict = self.getValues()
        geoList = self.getFlattenedChildren()
        for geo in geoList:
            for key in dvDict:
                lower = []
                upper = []
                if key in geo.DV_listLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listLocal[key].lower
                    upper = geo.DV_listLocal[key].upper
                elif key in geo.DV_listSpanwiseLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listSpanwiseLocal[key].lower
                    upper = geo.DV_listSpanwiseLocal[key].upper
                elif key in geo.DV_listSectionLocal:
                    if not includeLocal:
                        continue
                    lower = geo.DV_listSectionLocal[key].lower
                    upper = geo.DV_listSectionLocal[key].upper
                elif key in geo.DV_listGlobal:
                    if not includeGlobal:
                        continue
                    lower = geo.DV_listGlobal[key].lower
                    upper = geo.DV_listGlobal[key].upper
                if lower is None or upper is None:
                    raise Error("demoDesignVars requires upper and lower bounds on all design variables.")
                x = dvDict[key].flatten()
                nDV = len(lower)
                for j in range(nDV):
                    count = 0
                    if freq == 2:
                        stops = [lower[j], upper[j]]
                    elif freq > 2:
                        sinusoid = np.sin(np.linspace(0, np.pi, freq))
                        down_swing = x[j] + (lower[j] - x[j]) * sinusoid
                        up_swing = x[j] + (upper[j] - x[j]) * sinusoid
                        stops = np.concatenate((down_swing[:-1], up_swing[:-1]))
                    for val in stops:
                        old_val = x[j]
                        x[j] = val
                        dvDict.update({key: x})
                        self.setDesignVars(dvDict)
                        outFile = f"{key}_{j:03d}_iter_{count:03d}"
                        self.writeTecplot(f"{directory}/ffd/{outFile}.dat")
                        if pointSet is not None:
                            self.update(pointSet)
                            self.writePointSet(pointSet, f"{directory}/pointset/{outFile}")
                        if CFDSolver is not None:
                            CFDSolver.DVGeo.setDesignVars(dvDict)
                            CFDSolver.setAeroProblem(CFDSolver.curAP)
                            CFDSolver.writeSurfaceSolutionFileTecplot(f"{directory}/surf/{outFile}")
                        if callBack is not None:
                            callBack(directory, count)
                        x[j] = old_val
                        dvDict.update({key: x})
                        count += 1
def demoDesignVars ( self , directory , includeLocal = True , includeGlobal = True , pointSet = None , CFDSolver = None , callBack = None , freq = 2 ) : os . makedirs ( f"{directory}/ffd" , exist_ok = True ) if pointSet is not None : os . makedirs ( f"{directory}/pointset" , exist_ok = True ) if CFDSolver is not None : os . makedirs ( f"{directory}/surf" , exist_ok = True ) dvDict = self . getValues ( ) geoList = self . getFlattenedChildren ( ) for geo in geoList : for key in dvDict : lower = [ ] upper = [ ] if key in geo . DV_listLocal : if not includeLocal : continue lower = geo . DV_listLocal [ key ] . lower upper = geo . DV_listLocal [ key ] . upper elif key in geo . DV_listSpanwiseLocal : if not includeLocal : continue lower = geo . DV_listSpanwiseLocal [ key ] . lower upper = geo . DV_listSpanwiseLocal [ key ] . upper elif key in geo . DV_listSectionLocal : if not includeLocal : continue lower = geo . DV_listSectionLocal [ key ] . lower upper = geo . DV_listSectionLocal [ key ] . upper elif key in geo . DV_listGlobal : if not includeGlobal : continue lower = geo . DV_listGlobal [ key ] . lower upper = geo . DV_listGlobal [ key ] . upper if lower is None or upper is None : raise Error ( "demoDesignVars requires upper and lower bounds on all design variables." ) x = dvDict [ key ] . flatten ( ) nDV = len ( lower ) for j in range ( nDV ) : count = 0 if freq == 2 : stops = [ lower [ j ] , upper [ j ] ] elif freq > 2 : sinusoid = np . sin ( np . linspace ( 0 , np . pi , freq ) ) down_swing = x [ j ] + ( lower [ j ] - x [ j ] ) * sinusoid up_swing = x [ j ] + ( upper [ j ] - x [ j ] ) * sinusoid stops = np . concatenate ( ( down_swing [ : - 1 ] , up_swing [ : - 1 ] ) ) for val in stops : old_val = x [ j ] x [ j ] = val dvDict . update ( { key : x } ) self . setDesignVars ( dvDict ) outFile = f"{key}_{j:03d}_iter_{count:03d}" self . writeTecplot ( f"{directory}/ffd/{outFile}.dat" ) if pointSet is not None : self . update ( pointSet ) self . writePointSet ( pointSet , f"{directory}/pointset/{outFile}" ) if CFDSolver is not None : CFDSolver . DVGeo . setDesignVars ( dvDict ) CFDSolver . setAeroProblem ( CFDSolver . curAP ) CFDSolver . writeSurfaceSolutionFileTecplot ( f"{directory}/surf/{outFile}" ) if callBack is not None : callBack ( directory , count ) x [ j ] = old_val dvDict . update ( { key : x } ) count += 1
This function can be used to "test" the design variable parametrization
for a given optimization problem.
This function can be used to " test " the design variable parametrization for a given optimization problem .
"""
        This function can be used to "test" the design variable parametrization
        for a given optimization problem. It should be called in the script
        after DVGeo has been set up. The function will loop through all the
        design variables and write out a deformed FFD volume for the upper
        and lower bound of every design variable. It can also write out
        deformed point sets and surface meshes.

        Parameters
        ----------
        directory : str
            The directory where the files should be written.
        includeLocal : boolean
            False if you don't want to include the shape variables.
        includeGlobal : boolean
            False if you don't want to include global variables.
        pointSet : str
            Name of the point set to write out.
            If None, no point set output is generated.
        CFDSolver : str
            An ADflow instance that will be used to write out deformed surface
            meshes. In addition to having a DVGeo object, CFDSolver must have
            an AeroProblem set, for example with ``CFDSolver.setAeroProblem(ap)``.
            If CFDSolver is None, no surface mesh output is generated.
        callBack : function
            This allows the user to perform an additional task at each new design
            variable iteration. The callback function must take two inputs:

            1. the output directory name (str) and
            2. the iteration count (int).
        freq : int
            Number of snapshots to take between the upper and lower bounds of
            a given variable. If greater than 2, will do a sinusoidal sweep.
        """ # Generate directories # Get design variables # Loop through design variables on self and children # Add perturbation to the design variable and update # Set output filename # Write FFD # Write point set # Write surface mesh # Call user function # Reset variable # Iterate counter
self
directory
includeLocal
includeGlobal
pointSet
CFDSolver
callBack
freq