Пример #1
0
    def initialize_adjoint(self, scenario, bodies):
        # Instantiate the SU2 flow solver
        if self.su2ad is None:
            # Delete the primal if it exists at this point...
            if self.su2 is not None:
                del self.su2
                self.su2 = None

            # Create the discrete adjoint version of SU2
            self.su2ad = pysu2ad.CDiscAdjSinglezoneDriver(
                self.su2ad_config, 1, self.comm)
            self._initialize_mesh(self.su2ad, scenario, bodies)

        return
Пример #2
0
def main():

    # Command line options
    parser = OptionParser()
    parser.add_option("-f",
                      "--file",
                      dest="filename",
                      help="Read config from FILE",
                      metavar="FILE")
    parser.add_option("--parallel",
                      action="store_true",
                      help="Specify if we need to initialize MPI",
                      dest="with_MPI",
                      default=False)

    (options, args) = parser.parse_args()
    options.nDim = 2
    options.nZone = 1

    print(args)

    # Import mpi4py for parallel run
    if options.with_MPI == True:
        from mpi4py import MPI
        comm = MPI.COMM_WORLD
        rank = comm.Get_rank()
    else:
        comm = 0
        rank = 0

    # Initialize the corresponding driver of SU2, this includes solver preprocessing
    SU2Driver = pysu2.CDiscAdjSinglezoneDriver(options.filename, options.nZone,
                                               comm)

    MarkerID = None
    MarkerName = 'RightBeamS'  # Specified by the user

    # Get all the boundary tags
    MarkerList = SU2Driver.GetAllBoundaryMarkersTag()

    # Get all the markers defined on this rank and their associated indices.
    allMarkerIDs = SU2Driver.GetAllBoundaryMarkers()

    #Check if the specified marker exists and if it belongs to this rank.
    if MarkerName in MarkerList and MarkerName in allMarkerIDs.keys():
        MarkerID = allMarkerIDs[MarkerName]

    # Time loop is defined in Python so that we have acces to SU2 functionalities at each time step
    if rank == 0:
        print(
            "\n------------------------------ Begin Solver -----------------------------\n"
        )
    sys.stdout.flush()
    if options.with_MPI == True:
        comm.Barrier()

    # Define the load at the target vertex
    SU2Driver.SetFEA_Loads(MarkerID, 5, 0, -0.005, 0)

    # Time iteration preprocessing
    SU2Driver.Preprocess(0)

    # Run one time-step (static: one simulation)
    SU2Driver.Run()

    # Update the solver for the next time iteration
    SU2Driver.Update()

    # Monitor the solver and output solution to file if required
    SU2Driver.Monitor(0)

    # Output the solution to file
    SU2Driver.Output(0)

    sens = []
    disp = []
    # Recover the sensitivity
    sens.append(SU2Driver.GetFlowLoad_Sensitivity(MarkerID, 5))
    disp.append(SU2Driver.GetFEA_Displacements(MarkerID, 5))

    print("Sens[0]\tSens[1]\tDisp[0]\tDisp[1]\t")
    print(100, 100, sens[0][0], sens[0][1], disp[0][0], disp[0][1])

    # Postprocess the solver and exit cleanly
    SU2Driver.Postprocessing()

    if SU2Driver != None:
        del SU2Driver
Пример #3
0
def main():

    # Command line options
    parser = OptionParser()
    parser.add_option("-f",
                      "--file",
                      dest="filename",
                      help="Read config from FILE",
                      metavar="FILE")
    parser.add_option("--parallel",
                      action="store_true",
                      help="Specify if we need to initialize MPI",
                      dest="with_MPI",
                      default=False)

    (options, args) = parser.parse_args()
    options.nDim = 2
    options.nZone = 1

    print(args)

    # Import mpi4py for parallel run
    if options.with_MPI == True:
        from mpi4py import MPI
        comm = MPI.COMM_WORLD
        rank = comm.Get_rank()
    else:
        comm = 0
        rank = 0

    # Initialize the corresponding driver of SU2, this includes solver preprocessing
    SU2Driver = pysu2.CDiscAdjSinglezoneDriver(options.filename, options.nZone,
                                               comm)

    MarkerID = None
    MarkerName = 'wallF'  # Specified by the user

    # Get all the boundary tags
    MarkerList = SU2Driver.GetAllBoundaryMarkersTag()

    # Get all the markers defined on this rank and their associated indices.
    allMarkerIDs = SU2Driver.GetAllBoundaryMarkers()

    #Check if the specified marker exists and if it belongs to this rank.
    if MarkerName in MarkerList and MarkerName in allMarkerIDs.keys():
        MarkerID = allMarkerIDs[MarkerName]

    # Number of vertices on the specified marker (per rank)
    nVertex_Marker = 0  #total number of vertices (physical + halo)

    if MarkerID != None:
        nVertex_Marker = SU2Driver.GetNumberVertices(MarkerID)

    # Time loop is defined in Python so that we have acces to SU2 functionalities at each time step
    if rank == 0:
        print(
            "\n------------------------------ Begin Solver -----------------------------\n"
        )
    sys.stdout.flush()
    if options.with_MPI == True:
        comm.Barrier()

    # Time iteration preprocessing
    SU2Driver.Preprocess(0)

    # Run one time-step (static: one simulation)
    SU2Driver.Run()

    # Postprocess
    SU2Driver.Postprocess()

    # Update the solver for the next time iteration
    SU2Driver.Update()

    # Monitor the solver and output solution to file if required
    SU2Driver.Monitor(0)

    # Output the solution to file
    SU2Driver.Output(0)

    # Sensitivities of the marker
    print(
        "\n------------------------------ Sensitivities -----------------------------\n"
    )
    for iVertex in range(nVertex_Marker):
        sensX, sensY, sensZ = SU2Driver.GetMeshDisp_Sensitivity(
            MarkerID, iVertex)

        if (iVertex == 30):
            print(1000, 1000, iVertex, sensX, sensY, sensZ)

    # Postprocess the solver and exit cleanly
    SU2Driver.Postprocessing()

    if SU2Driver != None:
        del SU2Driver