Dear all,
I am currently simulating the flow past a cylinder with legacy FEniCS 2019.1.0, and I would like to store the velocity and pressure data at certain timesteps.
In my code, I use the folloing code to create the files.
self.xdmffile_u = XDMFFile('navier_stokes_cylinder/velocity.xdmf')
self.xdmffile_p = XDMFFile('navier_stokes_cylinder/pressure.xdmf')
self.timeseries_u = TimeSeries('navier_stokes_cylinder/velocity_series')
self.timeseries_p = TimeSeries('navier_stokes_cylinder/pressure_series')
self.mesh_for_cylinder = File('navier_stokes_cylinder/cylinder.xml.gz')
And later I use the following lines in an attempt to write the data into the files.
self.mesh_for_cylinder << self.mesh
self.xdmffile_u.write(self.u_, self.t)
self.xdmffile_p.write(self.p_, self.t)
self.timeseries_u.store(self.u_.vector(), self.t)
self.timeseries_p.store(self.p_.vector(), self.t)
After running the code, I checked my computer. The cylinder.xml.gz is inside the folder ‘navier_stokes_cylinder’, but other files for storing the velocity and pressure are just nowhere to be found. I would be grateful if anyone could tell me why they are not created and what was wrong in my coding?
A minimal working example will be like this:
from fenics import *
from mshr import *
class Env2DCylinder():
def __init__(self):
# Files for storing the data
self.xdmffile_u = XDMFFile('velocity.xdmf')
self.xdmffile_p = XDMFFile('pressure.xdmf')
# TimeSeries files
self.timeseries_u = TimeSeries('velocity_series')
self.timeseries_p = TimeSeries('pressure_series')
self.mesh = UnitSquareMesh(10, 10)
self.V = VectorFunctionSpace(self.mesh, 'P', 2)
self.Q = FunctionSpace(self.mesh, 'P', 1)
self.u = TrialFunction(self.V)
self.v = TestFunction(self.V)
self.p = TrialFunction(self.Q)
self.q = TestFunction(self.Q)
self.u_ = Function(self.V)
self.p_ = Function(self.Q)
self.A1 = inner(grad(self.u), grad(self.v))*dx
self.L1 = dot(Constant((1, 0)), self.v)*dx
self.A2 = inner(grad(self.p), grad(self.q))*dx
self.L2 = Constant(0)*self.q*dx
def evolve(self):
solve(self.A1 == self.L1, self.u_)
solve(self.A2 == self.L2, self.p_)
# Issue with writing XDMF files
self.xdmffile_u.write(self.u_, 0)
self.xdmffile_p.write(self.p_, 0)
# Issue with writing TimeSeries files
self.timeseries_u.store(self.u_.vector(), 0)
self.timeseries_p.store(self.p_.vector(), 0)
env = Env2DCylinder()
env.evolve()
Many thanks for the help in advance!