possible bug: initial condition for a vector variable
Hi,
I have a vector variable u, defined over a region omega, that I'm trying to initialize to the uniform value (1,2): U = Field.from_args('U', sp.float64, 'vector', omega, approx_order=1) u = FieldVariable('u', 'unknown', U, history=1) InitialCondition('ic', omega, {'u.0': 1., 'u.1': 2.})
This, however, initializes u to (0.,2.).
Is this intentional? Is there a better way to initialize a vector field?
The source of this behavior seems to be at the end of sfepy.discrete.variables.FieldVariable.setup_initial_conditions: ic_vec = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) ic_vec[eq] = vv self.initial_condition = ic_vec This sets every component to zero before applying the initial condition under consideration, therefore erasing any previous initial condition.
Replacing the code above with if self.initial_condition==None: self.initial_condition = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) self.initial_condition[eq] = vv seems to solve the problem, i.e. in my example u initializes to (1.,2.).
Best, Yaouen
Hi Yaouen,
On 08/09/2015 03:26 AM, Yaouen wrote:
Hi,
I have a vector variable u, defined over a region omega, that I'm trying to initialize to the uniform value (1,2): U = Field.from_args('U', sp.float64, 'vector', omega, approx_order=1) u = FieldVariable('u', 'unknown', U, history=1) InitialCondition('ic', omega, {'u.0': 1., 'u.1': 2.})
This, however, initializes u to (0.,2.).
Is this intentional? Is there a better way to initialize a vector field?
The source of this behavior seems to be at the end of sfepy.discrete.variables.FieldVariable.setup_initial_conditions: ic_vec = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) ic_vec[eq] = vv self.initial_condition = ic_vec This sets every component to zero before applying the initial condition under consideration, therefore erasing any previous initial condition.
You are right, it is a bug. Thanks for reporting it and posting a fix.
There is no example in sfepy, that solves a timedependent problem with a vector field, so the bug kept escaping.
Replacing the code above with if self.initial_condition==None: self.initial_condition = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) self.initial_condition[eq] = vv seems to solve the problem, i.e. in my example u initializes to (1.,2.).
Would you like to create a pull request? If not, I will fix it myself.
Cheers, r.
On 08/09/2015 09:50 PM, Robert Cimrman wrote:
Hi Yaouen,
On 08/09/2015 03:26 AM, Yaouen wrote:
Hi,
I have a vector variable u, defined over a region omega, that I'm trying to initialize to the uniform value (1,2): U = Field.from_args('U', sp.float64, 'vector', omega, approx_order=1) u = FieldVariable('u', 'unknown', U, history=1) InitialCondition('ic', omega, {'u.0': 1., 'u.1': 2.})
This, however, initializes u to (0.,2.).
Is this intentional? Is there a better way to initialize a vector field?
The source of this behavior seems to be at the end of sfepy.discrete.variables.FieldVariable.setup_initial_conditions: ic_vec = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) ic_vec[eq] = vv self.initial_condition = ic_vec This sets every component to zero before applying the initial condition under consideration, therefore erasing any previous initial condition.
You are right, it is a bug. Thanks for reporting it and posting a fix.
There is no example in sfepy, that solves a timedependent problem with a vector field, so the bug kept escaping.
Replacing the code above with if self.initial_condition==None: self.initial_condition = nm.zeros((di.n_dof[self.name],), dtype=self.dtype) self.initial_condition[eq] = vv seems to solve the problem, i.e. in my example u initializes to (1.,2.).
Would you like to create a pull request? If not, I will fix it myself.
Does [1] fix the bug? I have used a slightly simpler code than you proposed.
r. [1] https://github.com/rc/sfepy
It does fix the problem, and it does improve on my suggested edit. Thanks for writing sfepy by the way, and for being so responsive.
Yaouen
participants (2)

Robert Cimrman

Yaouen