Hi everyone,
I am solving a time dependent problem, and I am building the InitialConditions class. My problem is a bit complicated so I want to use the steady state solution that I computed previously as an initial condition. Given the structure of my problem, I have to evaluate the initial conditions inside the InitialConditions class, but I cannot find the right way to import the solution there. I am using a mixed finite element formulation.
For reference, my spaces are
V = VectorElement("CG", triangle, 2)
Q = FiniteElement("CG", triangle, 1)
S = Finiteelement("CG", triangle, 1)
W = FunctionSpace(mesh, MixedElement([V, Q, S]))
Here is an example of what I am trying to do (where w0.h5) contains my steady state solution.
class InitialConditions(UserExpression):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def eval(self, values, x):
fFile = HDF5File(MPI.comm_world, "w0.h5", "r")
fFile.read(values, "/f")
fFile.close()
def value_shape(self):
return (4,)
which gives the error ‘numpy.ndarray’ object has no attribute ‘_cpp_object’.
I have also tried to do this
class InitialConditions(UserExpression):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.uin = 2
self.Qfun = 2.3710
self.x2 = 0.9
self.x1 = 0.7
def eval(self, values, x):
w0 = Function(W)
fFile = HDF5File(MPI.comm_world, "w0.h5", "r")
fFile.read(values, "/f")
fFile.close()
u0, p0, T0 = split(w0)
values[0] = u0[0]
values[1] = u0[1]
values[2] = p0
values[3] = T0
def value_shape(self):
return (4,)
which then gives the error " values[0] = u0[0] , setting an array element with a sequence"
I can just use fFile outside of the class, when I am starting the time-stepping. This works only for one time-step, and then my solution stops getting updated properly (like I mentioned here), so I think I need to import the file somehow inside the class.
Does anyone know how to do it?