Setup field-dependent boundary condition
Hi,
I am trying to simulate an electrostatic problem with the boundary condition (electric potential) not fixed but dependent on local charge density. I am very new to SfePy and after learning from the online examples, I was able to set up the simulation with a fixed boundary condition, which works well.
Next I tried to set up a function for the field-dependent boundary condition as the following. Example function taken from poisson_field_dependent_material example http://sfepy.org/doc-devel/examples/diffusion/poisson_field_dependent_materi...
def set_potential(ts, coors, problem, equations=None, mode=None, **kwargs):
# this function updates the potential at region: Electrode
if mode=='qp':
E_values = problem.evaluate('ev_grad.i.Electrode(v)', mode='qp', verbose=False) # calculating the electric field (potential gradient) at the electrode (a short straight line)
return UpdatedPotential(E_values) # the potential on this electrode depends on the local charge density (which is proportional to the local electric field calculated above)
else:
return np.zeros(len(coors)) # for the initial step
ebcs = {
'v1' : ('Boundary', {'v.all' : 1}), # this is one edge of the square box
'v2' : ('Electrode', {'v.all' : 'set_potential'}), # this is one short straight line inside the square. In the fixed ebcs case, it is set to 0
}
functions = {
'set_potential' : (set_potential,),
}
However, it looks like it doesn't really update the boundary condition during runtime. The set_potential function is only called once at the beginning. Any ideas what is wrong here? Thanks a lot.
YT
Hi YT,
On 05/12/2015 07:37 AM, YTC wrote:
Hi,
I am trying to simulate an electrostatic problem with the boundary condition (electric potential) not fixed but dependent on local charge density. I am very new to SfePy and after learning from the online examples, I was able to set up the simulation with a fixed boundary condition, which works well.
Next I tried to set up a function for the field-dependent boundary condition as the following. Example function taken from poisson_field_dependent_material example http://sfepy.org/doc-devel/examples/diffusion/poisson_field_dependent_materi...
<snip>
However, it looks like it doesn't really update the boundary condition during runtime. The set_potential function is only called once at the beginning. Any ideas what is wrong here? Thanks a lot.
It will not be that easy - the functions for setting boundary conditions have a different signature [1], and are indeed called only at the beginning of each time step. So you need to add an auxiliary time-stepping solver, and change the BC in time.
Because the functions for defining boundary conditions have access to the problem instance, you can evaluate the charge density there in the boundary quadrature points just as you did. But then you need to project the data from the quadrature points back to the finite element space, that is, to define the field degrees of freedom on the boundary, as, for example, in [2] for the whole domain. There is no function that does that automatically yet, and I will probably not get to it in the next two weeks.
As a temporary workaround, in case you use a linear approximation, you could define your quadrature points so that they coincide with vertices of the reference element, see [3], but then the data would have to be reshuffled to the order of the BC region vertices.
Does it help?
r.
[1] http://sfepy.org/doc-devel/users_guide.html#id7 (see functions for defining boundary conditions) [2] http://sfepy.org/doc-devel/examples/diffusion/time_poisson_interactive.html (see project_by_component use) [3] http://sfepy.org/doc-devel/primer.html#generating-output-at-element-nodes (integral ivn - define analogously for surface geometry_data of your elements)
participants (2)
-
Robert Cimrman
-
YTC