CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   SU2 (https://www.cfd-online.com/Forums/su2/)
-   -   TypeError in pysu2.CSinglezoneDriver in trying to run in Serial mode (https://www.cfd-online.com/Forums/su2/245393-typeerror-pysu2-csinglezonedriver-trying-run-serial-mode.html)

Vishnu Sankar October 4, 2022 03:18

TypeError in pysu2.CSinglezoneDriver while trying to run in Serial mode
 
Hi there,

I want to run the inv_NACA0012 test case from the QuickStart folder (link here) using pysu2 through a python script in serial mode. I have enabled the python wrapper correctly and it gets imported without any error. I have attached my code below:


Code:

import sys
import shutil
import SU2
import pysu2
#from mpi4py import MPI

def main():
    flow_filename = "inv_NACA0012.cfg"
    #comm = MPI.COMM_WORLD
    comm = 0
    FlowDriver = pysu2.CSinglezoneDriver(flow_filename, 1, comm);
    FlowMarkerID = None
    FlowMarkerIDs = FlowDriver.GetAllBoundaryMarkers()
   
    sys.stdout.flush()
    #comm.Barrier()
    FlowDriver.ResetConvergence()
    FlowDriver.Preprocess(0)
    FlowDriver.run()
    FlowDriver.Postprocess()
    stopCalc = FlowDriver.Monitor(0)
    FlowDriver.Output(0)


if __name__ == '__main__':
    main()

I followed the code structure given in the SU2/SU2_PY/SU2_CFD.py (link here). However, it gives the following error:

SU2/bin/pysu2.py", line 527, in __init__ _pysu2.CSinglezoneDriver_swiginit(self, _pysu2.new_CSinglezoneDriver(confFile, val_nZone, MPICommunicator)) TypeError: in method 'new_CSinglezoneDriver', argument 3 of type 'SU2_Comm'

Even if I enable MPI and use comm = MPI.COMM_WORLD instead of comm = 0,I get another error:

The MPI_Comm_rank() function was called before MPI_INIT was invoked.
*** This is disallowed by the MPI standard.
*** Your MPI job will now abort.


Right now I am only interested in running SU2 in the serial mode, could you help me in resolving the issue (the first error)?

Thanks!

--
I am using SU2 version 7.4.0
swig version: 4.0.2
gcc version 4.9.2

Vishnu Sankar November 1, 2022 04:19

Hi there,


Can anyone give some guidance on how to sort out this issue? I tried out running the example codes in mpi4py documentation page (link here), and they work fine. But when I am specifically running this piece of code with SU2 involved in it, I get the error mentioned above.

I went through various online discussion forums but could not get it sorted :/
Thanks in advance!

bigfootedrockmidget November 3, 2022 05:48

I'm not too familiar with it, but have a look in the code at

SU2_CFD/src/python_wrapper_structure
and you see what kind of functions are available.


It looks like there is a Get_Drag() and Get_Lift() function and similar functions are present as well.

bigfootedrockmidget November 3, 2022 06:08

There are a couple of examples for the pywrapper in TestCases/py_wrapper, you can first run them to make sure that everything is working properly on your local machine (if you haven't done so already)

Vishnu Sankar June 17, 2023 02:03

Apologies for the very late reply, apparently I got busy with other projects and had to pause the one with SU2 for a while. Thanks a lot your prompt replies @bigfoot, seems the MPI version was creating the issue. I had a lot of trouble with setting up openMPI in the right way. Here are a few suggestions to get do it right for newbies like me who want to use the python wrapper of SU2


- Install openMPI and mpi4py as mention here: https://mdolab-mach-aero.readthedocs...yPackages.html (best source I ever found for mpi installation)

- Install SU2 in parallel mode
- Install the python wrapper appropriately (look at the last reply from the thread: https://www.cfd-online.com/Forums/su...ror-pysu2.html incase you are facing python path issues)


Python Code for running the Quick Start is re-written with corrections below:
Code:



import sys
import shutil
import SU2
import pysu2
from mpi4py import MPI

def main():
  flow_filename="inv_NACA0012.cfg"
  comm= MPI.COMM_WORLD
  #comm = None
  FlowDriver=pysu2.CSinglezoneDriver(flow_filename, 1, comm);
  FlowMarkerID=None
  FlowMarkerIDs=FlowDriver.GetAllBoundaryMarkers()
  FlowMarkerList=FlowDriver.GetAllBoundaryMarkersTag()
  sys.stdout.flush()
  #comm.Barrier()
  FlowDriver.ResetConvergence()
  FlowDriver.Preprocess(0)
  FlowDriver.Run()
  FlowDriver.Postprocess()
  stopCalc=FlowDriver.Monitor(0)
  FlowDriver.Output(0)
  Cl=FlowDriver.Get_LiftCoeff()
  Cd=FlowDriver.Get_DragCoeff()
  Mz=FlowDriver.Get_Mz()

if __name__=='__main__':

    main()

(Sorry for spacing issue couldn't help it)


All times are GMT -4. The time now is 02:34.