Run case through Python

I used the PyFR program on a Linux terminal, and the related file “Myconfig.ini,” “Mytest.mesh,” and “Mytest.pyfrm.” I’m going to try using the Python program to process the PyFR case with Runtest.py. However, I got an error message. I checked the PyFR code ,but the BaseSystem class was initialized without arguments for “rallocs”. Because I am first try. Could you please give me a simple example that uses Python code or a framework?

pipe-2

Runtest.py

import os
from pyfr.solvers.navstokes.system import NavierStokesSystem
from pyfr.integrators.std.steppers import StdRK4Stepper
from pyfr.inifile import Inifile
from pyfr.readers.native import NativeReader
from pyfr.backends.base.backend import BaseBackend
from pyfr.backends import get_backend
from pyfr.solvers.base import BaseSystem

mesh_name='Mytest.mesh'
pyfrm_name='Mytest.pyfrm'
config_name='Myconfig.ini'

#get file pathe
script_dir = os.path.dirname(os.path.abspath(__file__))
mesh_path = os.path.join(script_dir, mesh_name) 
mesh_pyfrm = os.path.join(script_dir, pyfrm_name)
config_path = os.path.join(script_dir, config_name)
output_dir = os.path.join(script_dir, 'results')

config = Inifile.load(config_path)

backend = get_backend('openmp',config)
mesh = NativeReader(mesh_pyfrm)
base_system=BaseSystem(backend,mesh=mesh_pyfrm,initsoln=None,nregs=1,cfg=config)
system = NavierStokesSystem()
integrator = system.get_integrator(tmax=config.getfloat('time-integration', 'tmax'))
integrator.run()

Myconfig.ini

[backend]
precision = double

[constants]
Pc = 1.0
gamma = 1.4
mu = 3.94405318873308E-6
Pr = 0.71
[solver]
system = navier-stokes
order = 2


[solver-time-integrator]
formulation = std
scheme = rk45
controller = none
tstart = 0.0
tend = 2.0
dt = 0.0005

[solver-interfaces]
riemann-solver = hllc
ldg-beta = 0.5
ldg-tau = 0.1
[solver-interfaces-quad]
flux-pts = gauss-legendre

[solver-elements-hex]
soln-pts = gauss-legendre
[soln-plugin-nancheck]
nsteps = 10
[soln-plugin-writer]
dt-out = 1.0
basedir = .
basename = Ode-{t:.1f}
[soln-plugin-residual]
nsteps = 1
file = residual.csv
header = true
[soln-bcs-wall]
type = slp-adia-wall
[soln-bcs-inlet]
type = sup-in-fa
rho =1.0
u = 0.0
v = 0.0
w = 2.0
p = Pc
[soln-bcs-outlet]
type = sup-in-fa
rho =1.0
u = 0.0
v = 0.0
w = 1.0
p = Pc
[soln-ics]
rho =1.0
u = 0.0
v = 0.0
w = 1.0
p = Pc

The error message is quite clear: you are missing a required argument. However, even with the argument, your code would not work as BaseSystem is an abstract class. If you want to see how these interfaces can be used correctly please consult:

Regards, Freddie.

Thank you for your reply @fdw. Can a Python programme control the PyFR runtime process, or not? Could you please show me some tips or a simple guide for writing a Python program?

It depends what you mean by control. What are you trying to accomplish that you can not currently do using the pyfr script?

Regards, Freddie.

I want to exchange and process data while I’m doing my calculations. I don’t want to do any extra development. It’s best to process this in Python programme . I need to use Python to start the calculation and get the results.

It depends what you mean by processing data. Usually post-actions are the best approach here and supported by several plugins. These allow you to run a script every time a file is written out and this script can perform anything you want.

Otherwise, you may want to consider writing your own plugin to perform any required analysis.

Regards, Freddie.

Thank you for your patience. I would like to try to do coupled CFD-DEM calculations. So I need to start the PyFR calculations in Python and send the resulting data to the DEM software at each time step to complete the data exchange.

This is a non-trivial endeavour and will likely require some substantial development work. You will likely need to define your own boundary condition and then in the code for that condition you can query the values at the boundary and pass them onto any associated code.

Regards, Freddie.