def initialize(self, scenario, bodies, first_pass=False): # Instantiate the SU2 flow solver if first_pass or self.su2 is None: self.su2 = pysu2.CSinglezoneDriver(self.su2_config, 1, self.comm) self._initialize_mesh(self.su2, scenario, bodies) return 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("--nDim", dest="nDim", default=2, help="Define the number of DIMENSIONS", metavar="DIMENSIONS") parser.add_option("--nZone", dest="nZone", default=1, help="Define the number of ZONES", metavar="ZONES") parser.add_option("--parallel", action="store_true", help="Specify if we need to initialize MPI", dest="with_MPI", default=False) parser.add_option("--fsi", dest="fsi", default="False", help="Launch the FSI driver", metavar="FSI") parser.add_option("--fem", dest="fem", default="False", help="Launch the FEM driver (General driver)", metavar="FEM") parser.add_option("--harmonic_balance", dest="harmonic_balance", default="False", help="Launch the Harmonic Balance (HB) driver", metavar="HB") parser.add_option("--poisson_equation", dest="poisson_equation", default="False", help="Launch the poisson equation driver (General driver)", metavar="POIS_EQ") parser.add_option("--wave_equation", dest="wave_equation", default="False", help="Launch the wave equation driver (General driver)", metavar="WAVE_EQ") parser.add_option("--heat_equation", dest="heat_equation", default="False", help="Launch the heat equation driver (General driver)", metavar="HEAT_EQ") (options, args) = parser.parse_args() options.nDim = int( options.nDim ) options.nZone = int( options.nZone ) options.fsi = options.fsi.upper() == 'TRUE' options.fem = options.fem.upper() == 'TRUE' options.harmonic_balance = options.harmonic_balance.upper() == 'TRUE' options.poisson_equation = options.poisson_equation.upper() == 'TRUE' options.wave_equation = options.wave_equation.upper() == 'TRUE' options.heat_equation = options.heat_equation.upper() == 'TRUE' # 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 try: if (options.nZone == 1) and ( options.fem or options.poisson_equation or options.wave_equation or options.heat_equation ): SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm); elif options.harmonic_balance: SU2Driver = pysu2.CHBDriver(options.filename, options.nZone, comm); elif (options.nZone == 2) and (options.fsi): SU2Driver = pysu2.CFSIDriver(options.filename, options.nZone, comm); else: SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm); except TypeError as exception: print('A TypeError occured in pysu2.CDriver : ',exception) if options.with_MPI == True: print('ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.') else: print('ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.') return MovingMarkerID = None MovingMarker = 'plate' #specified by the user # Get all the tags with the moving option MovingMarkerList = SU2Driver.GetAllMovingMarkersTag() # Get all the markers defined on this rank and their associated indices. allMarkerIDs = SU2Driver.GetAllBoundaryMarkers() # Check if the specified marker has a moving option and if it exists on this rank. if MovingMarker in MovingMarkerList and MovingMarker in allMarkerIDs.keys(): MovingMarkerID = allMarkerIDs[MovingMarker] # Number of vertices on the specified marker (per rank) nVertex_MovingMarker = 0 #total number of vertices (physical + halo) nVertex_MovingMarker_HALO = 0 #number of halo vertices nVertex_MovingMarker_PHYS = 0 #number of physical vertices if MovingMarkerID != None: nVertex_MovingMarker = SU2Driver.GetNumberVertices(MovingMarkerID) nVertex_MovingMarker_HALO = SU2Driver.GetNumberHaloVertices(MovingMarkerID) nVertex_MovingMarker_PHYS = nVertex_MovingMarker - nVertex_MovingMarker_HALO # Retrieve some control parameters from the driver deltaT = SU2Driver.GetUnsteady_TimeStep() TimeIter = SU2Driver.GetTime_Iter() nTimeIter = SU2Driver.GetnTimeIter() time = TimeIter*deltaT # Extract the initial position of each node on the moving marker CoordX = np.zeros(nVertex_MovingMarker) CoordY = np.zeros(nVertex_MovingMarker) for iVertex in range(nVertex_MovingMarker): CoordX[iVertex] = SU2Driver.GetVertexCoordX(MovingMarkerID, iVertex) CoordY[iVertex] = SU2Driver.GetVertexCoordY(MovingMarkerID, iVertex) # 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() while (TimeIter < nTimeIter): # Define the rigid body displacement and set the new coords of each node on the marker d_y = 0.0175*sin(2*pi*time) for iVertex in range(nVertex_MovingMarker): newCoordX = CoordX[iVertex] newCoordY = CoordY[iVertex] + d_y SU2Driver.SetVertexCoordX(MovingMarkerID, iVertex, newCoordX) SU2Driver.SetVertexCoordY(MovingMarkerID, iVertex, newCoordY) SU2Driver.SetVertexCoordZ(MovingMarkerID, iVertex, 0.0) SU2Driver.SetVertexVarCoord(MovingMarkerID, iVertex) # Time iteration preprocessing SU2Driver.Preprocess(TimeIter) # Run one time iteration (e.g. dual-time) SU2Driver.Run() # Update the solver for the next time iteration SU2Driver.Update() # Monitor the solver and output solution to file if required stopCalc = SU2Driver.Monitor(TimeIter) SU2Driver.Output(TimeIter) if (stopCalc == True): break # Update control parameters TimeIter += 1 time += deltaT # Postprocess the solver and exit cleanly SU2Driver.Postprocessing() if SU2Driver != None: del SU2Driver
def main(): # Command line options parser=OptionParser() parser.add_option("-f", "--file", dest="filename", help="Read config from FILE", metavar="FILE") parser.add_option("--nDim", dest="nDim", default=2, help="Define the number of DIMENSIONS", metavar="DIMENSIONS") parser.add_option("--nZone", dest="nZone", default=1, help="Define the number of ZONES", metavar="NZONE") parser.add_option("--parallel", action="store_true", help="Specify if we need to initialize MPI", dest="with_MPI", default=False) parser.add_option("--fsi", dest="fsi", default="False", help="Launch the FSI driver", metavar="FSI") parser.add_option("--fem", dest="fem", default="False", help="Launch the FEM driver (General driver)", metavar="FEM") parser.add_option("--harmonic_balance", dest="harmonic_balance", default="False", help="Launch the Harmonic Balance (HB) driver", metavar="HB") parser.add_option("--poisson_equation", dest="poisson_equation", default="False", help="Launch the poisson equation driver (General driver)", metavar="POIS_EQ") parser.add_option("--wave_equation", dest="wave_equation", default="False", help="Launch the wave equation driver (General driver)", metavar="WAVE_EQ") parser.add_option("--heat_equation", dest="heat_equation", default="False", help="Launch the heat equation driver (General driver)", metavar="HEAT_EQ") (options, args) = parser.parse_args() options.nDim = int( options.nDim ) options.nZone = int( options.nZone ) options.fsi = options.fsi.upper() == 'TRUE' options.fem = options.fem.upper() == 'TRUE' options.harmonic_balance = options.harmonic_balance.upper() == 'TRUE' options.poisson_equation = options.poisson_equation.upper() == 'TRUE' options.wave_equation = options.wave_equation.upper() == 'TRUE' options.heat_equation = options.heat_equation.upper() == 'TRUE' if options.filename == None: raise Exception("No config file provided. Use -f flag") if options.with_MPI == True: from mpi4py import MPI # use mpi4py for parallel run (also valid for serial) comm = MPI.COMM_WORLD else: comm = 0 # Initialize the corresponding driver of SU2, this includes solver preprocessing try: if (options.nZone == 1) and ( options.fem or options.poisson_equation or options.wave_equation or options.heat_equation ): SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm); elif options.harmonic_balance: SU2Driver = pysu2.CHBDriver(options.filename, options.nZone, comm); elif (options.nZone >= 2): SU2Driver = pysu2.CMultizoneDriver(options.filename, options.nZone, comm); else: SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm); except TypeError as exception: print('A TypeError occured in pysu2.CDriver : ',exception) if options.with_MPI == True: print('ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.') else: print('ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.') return # Launch the solver for the entire computation SU2Driver.StartSolver() # Postprocess the solver and exit cleanly SU2Driver.Postprocessing() if SU2Driver != None: del SU2Driver
def main(): # --- Get the FSI conig file name form the 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() if options.with_MPI: from mpi4py import MPI # MPI is initialized from now by python and can be continued in C++ ! comm = MPI.COMM_WORLD myid = comm.Get_rank() numberPart = comm.Get_size() have_MPI = True else: comm = 0 myid = 0 numberPart = 1 have_MPI = False rootProcess = 0 # --- Set the working directory --- # if myid == rootProcess: if os.getcwd() not in sys.path: sys.path.append(os.getcwd()) print("Setting working directory : {}".format(os.getcwd())) else: print("Working directory is set to {}".format(os.getcwd())) if have_MPI: comm.barrier() # starts timer start = timer.time() confFile = str(options.filename) FSI_config = FSI.FSIConfig(confFile) # FSI configuration file CFD_ConFile = FSI_config['CFD_CONFIG_FILE_NAME'] # CFD configuration file CSD_ConFile = FSI_config['CSD_CONFIG_FILE_NAME'] # CSD configuration file CSD_Solver = FSI_config['CSD_SOLVER'] # CSD solver if have_MPI: comm.barrier() # --- Initialize the fluid solver --- # if myid == rootProcess: print("\n") print(" Initializing fluid solver ".center(80, "*")) try: FluidSolver = pysu2.CSinglezoneDriver(CFD_ConFile, 1, comm) except TypeError as exception: print('A TypeError occured in pysu2.CSinglezoneDriver : ', exception) if have_MPI: print( 'ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.' ) else: print( 'ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.' ) return if have_MPI: comm.barrier() # --- Initialize the solid solver --- # (!! for now we are using only serial solid solvers) if myid == rootProcess: print("\n") print(" Initializing solid solver ".center(80, "*")) if CSD_Solver == 'AEROELASTIC': from SU2_Nastran import pysu2_nastran SolidSolver = pysu2_nastran.Solver(CSD_ConFile, False) elif CSD_Solver == 'IMPOSED': from SU2_Nastran import pysu2_nastran SolidSolver = pysu2_nastran.Solver(CSD_ConFile, True) else: print("\n Invalid solid solver option") else: SolidSolver = None if have_MPI: comm.barrier() # --- Initialize and set the FSI interface (coupling environement) --- # if myid == rootProcess: print("\n") print(" Initializing FSI interface ".center(80, "*")) if have_MPI: comm.barrier() FSIInterface = FSI.Interface(FSI_config, FluidSolver, SolidSolver, have_MPI) if myid == rootProcess: print("\n") print(" Connect fluid and solid solvers ".center(80, "*")) if have_MPI: comm.barrier() FSIInterface.connect(FSI_config, FluidSolver, SolidSolver) if myid == rootProcess: print("\n") print(" Mapping fluid-solid interfaces ".center(80, "*")) if have_MPI: comm.barrier() FSIInterface.interfaceMapping(FluidSolver, SolidSolver, FSI_config) if have_MPI: comm.barrier() # --- Launch a steady or unsteady FSI computation --- # if FSI_config['TIME_MARCHING'] == "YES": try: FSIInterface.UnsteadyFSI(FSI_config, FluidSolver, SolidSolver) except NameError as exception: if myid == rootProcess: print('An NameError occured in FSIInterface.UnsteadyFSI : ', exception) except TypeError as exception: if myid == rootProcess: print('A TypeError occured in FSIInterface.UnsteadyFSI : ', exception) except KeyboardInterrupt as exception: if myid == rootProcess: print( 'A KeyboardInterrupt occured in FSIInterface.UnsteadyFSI : ', exception) else: try: FSIInterface.SteadyFSI(FSI_config, FluidSolver, SolidSolver) except NameError as exception: if myid == rootProcess: print('An NameError occured in FSIInterface.SteadyFSI : ', exception) except TypeError as exception: if myid == rootProcess: print('A TypeError occured in FSIInterface.SteadyFSI : ', exception) except KeyboardInterrupt as exception: if myid == rootProcess: print( 'A KeyboardInterrupt occured in FSIInterface.SteadyFSI : ', exception) if have_MPI: comm.barrier() # --- Exit cleanly the fluid and solid solvers --- # FluidSolver.Postprocessing() if myid == rootProcess: SolidSolver.exit() if have_MPI: comm.barrier() # stops timer stop = timer.time() elapsedTime = stop - start if myid == rootProcess: print("\n Computation successfully performed in {} seconds.".format( elapsedTime)) return
from __future__ import print_function from mpi4py import MPI import numpy as np import matplotlib.pyplot as plt import sys # Import SU2 import pysu2 from tacs import TACS, elements, constitutive from funtofem import TransferScheme comm = MPI.COMM_WORLD rank = comm.Get_rank() # initialize SU2 SU2_CFD_ConfigFile = 'sz_4deg_inv_flow.cfg' SU2Driver = pysu2.CSinglezoneDriver(SU2_CFD_ConfigFile, 1, comm) # initialize markers CHTMarkerID = None CHTMarker = 'wall' # Get all the tags with the CHT option # if this list is empty, you probably didn't add # MARKER_PYTHON_CUSTOM= ( your_marker ) to the .cfg file CHTMarkerList = SU2Driver.GetAllCHTMarkersTag() # Get all the markers defined on this rank and their associated indices. allMarkerIDs = SU2Driver.GetAllBoundaryMarkers() #Check if the specified marker has a CHT option and if it exists on this rank. if CHTMarker in CHTMarkerList and CHTMarker in allMarkerIDs.keys():
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 = int(2) options.nZone = int(1) # 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 try: SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm) except TypeError as exception: print('A TypeError occured in pysu2.CDriver : ', exception) if options.with_MPI == True: print( 'ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.' ) else: print( 'ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.' ) return MovingMarkerID = None MovingMarker = 'plate' #specified by the user # Get all the tags with the moving option MovingMarkerList = SU2Driver.GetAllDeformMeshMarkersTag() # Get all the markers defined on this rank and their associated indices. allMarkerIDs = SU2Driver.GetAllBoundaryMarkers() # Check if the specified marker has a moving option and if it exists on this rank. if MovingMarker in MovingMarkerList and MovingMarker in allMarkerIDs.keys( ): MovingMarkerID = allMarkerIDs[MovingMarker] # Number of vertices on the specified marker (per rank) nVertex_MovingMarker = 0 #total number of vertices (physical + halo) nVertex_MovingMarker_HALO = 0 #number of halo vertices nVertex_MovingMarker_PHYS = 0 #number of physical vertices if MovingMarkerID != None: nVertex_MovingMarker = SU2Driver.GetNumberVertices(MovingMarkerID) nVertex_MovingMarker_HALO = SU2Driver.GetNumberHaloVertices( MovingMarkerID) nVertex_MovingMarker_PHYS = nVertex_MovingMarker - nVertex_MovingMarker_HALO # Retrieve some control parameters from the driver deltaT = SU2Driver.GetUnsteady_TimeStep() TimeIter = SU2Driver.GetTime_Iter() nTimeIter = SU2Driver.GetnTimeIter() time = TimeIter * deltaT # Extract the initial position of each node on the moving marker CoordX = np.zeros(nVertex_MovingMarker) CoordY = np.zeros(nVertex_MovingMarker) CoordZ = np.zeros(nVertex_MovingMarker) for iVertex in range(nVertex_MovingMarker): CoordX[iVertex], CoordY[iVertex], CoordZ[ iVertex] = SU2Driver.GetInitialMeshCoord(MovingMarkerID, iVertex) # 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() while (TimeIter < nTimeIter): # Define the rigid body displacement and set the new coords of each node on the marker d_y = 0.0175 * sin(2 * pi * time) for iVertex in range(nVertex_MovingMarker): SU2Driver.SetMeshDisplacement(MovingMarkerID, int(iVertex), 0.0, d_y, 0.0) # Time iteration preprocessing SU2Driver.Preprocess(TimeIter) # Run one time iteration (e.g. dual-time) SU2Driver.Run() # Postprocess the solver SU2Driver.Postprocess() # Update the solver for the next time iteration SU2Driver.Update() # Monitor the solver and output solution to file if required stopCalc = SU2Driver.Monitor(TimeIter) SU2Driver.Output(TimeIter) if (stopCalc == True): break # Update control parameters TimeIter += 1 time += deltaT # Postprocess the solver and exit cleanly SU2Driver.Postprocessing() if SU2Driver != None: del SU2Driver
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 = int(2) options.nZone = int(1) # 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 try: SU2Driver = pysu2.CSinglezoneDriver(options.filename, options.nZone, comm); except TypeError as exception: print('A TypeError occured in pysu2.CDriver : ',exception) if options.with_MPI == True: print('ERROR : You are trying to initialize MPI with a serial build of the wrapper. Please, remove the --parallel option that is incompatible with a serial build.') else: print('ERROR : You are trying to launch a computation without initializing MPI but the wrapper has been built in parallel. Please add the --parallel option in order to initialize MPI for the wrapper.') return CHTMarkerID = None CHTMarker = 'plate' # Specified by the user # Get all the tags with the CHT option CHTMarkerList = SU2Driver.GetAllCHTMarkersTag() # Get all the markers defined on this rank and their associated indices. allMarkerIDs = SU2Driver.GetAllBoundaryMarkers() #Check if the specified marker has a CHT option and if it exists on this rank. if CHTMarker in CHTMarkerList and CHTMarker in allMarkerIDs.keys(): CHTMarkerID = allMarkerIDs[CHTMarker] # Number of vertices on the specified marker (per rank) nVertex_CHTMarker = 0 #total number of vertices (physical + halo) nVertex_CHTMarker_HALO = 0 #number of halo vertices nVertex_CHTMarker_PHYS = 0 #number of physical vertices if CHTMarkerID != None: nVertex_CHTMarker = SU2Driver.GetNumberVertices(CHTMarkerID) nVertex_CHTMarker_HALO = SU2Driver.GetNumberHaloVertices(CHTMarkerID) nVertex_CHTMarker_PHYS = nVertex_CHTMarker - nVertex_CHTMarker_HALO # Retrieve some control parameters from the driver deltaT = SU2Driver.GetUnsteady_TimeStep() TimeIter = SU2Driver.GetTime_Iter() nTimeIter = SU2Driver.GetnTimeIter() time = TimeIter*deltaT # 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() while (TimeIter < nTimeIter): # Time iteration preprocessing SU2Driver.Preprocess(TimeIter) # Define the homogeneous unsteady wall temperature on the structure (user defined) WallTemp = 293.0 + 57.0*sin(2*pi*time) # Set this temperature to all the vertices on the specified CHT marker for iVertex in range(nVertex_CHTMarker): SU2Driver.SetVertexTemperature(CHTMarkerID, iVertex, WallTemp) # Tell the SU2 drive to update the boundary conditions SU2Driver.BoundaryConditionsUpdate() # Run one time iteration (e.g. dual-time) SU2Driver.Run() # Postprocess the solver and exit cleanly SU2Driver.Postprocess() # Update the solver for the next time iteration SU2Driver.Update() # Monitor the solver and output solution to file if required stopCalc = SU2Driver.Monitor(TimeIter) SU2Driver.Output(TimeIter) if (stopCalc == True): break # Update control parameters TimeIter += 1 time += deltaT if SU2Driver != None: del SU2Driver