Passing function values in interactive mode

30 views
Skip to first unread message

David Jessop

unread,
Dec 21, 2016, 2:48:14 PM12/21/16
to sfepy-devel
Hi,

I'm trying to solve a non-linear Poisson type equation where the diffusion coefficient/conductivity depends on the field variable.  Logically, I've tried basing this part of my code on the poisson_field_dependent_material.py case and, of course, it works nicely in "simple" mode but I can't figure out how to pass the value to my material variable "cond" in interactive mode (I require interactive mode for reasons stated in this post).  I define the same get_conductivity function as per poisson_field_dependent_material.py, then declare the function as
conductivity_fun = Function('conductivity_fun', get_conductivity)

get_conductivity returns a dictionary key/value pair {'val' : val} so I figured to call the function as per
cond = Material('cond', conductivity_fun)

should work, but it results in this error:
Traceback (most recent call last):
 
File "examples/diffusion/myPoisson/myPoissonInteractive.py", line 185, in <module>
    main
()
 
File "examples/diffusion/myPoisson/myPoissonInteractive.py", line 116, in main
    cond
= Material('cond', conductivity_fun,) #val=  2.0)
 
File "/usr/local/lib/python2.7/dist-packages/sfepy-2016.3_git_94dff5a051dbd2bf6bd56fce936d75878edef9e8-py2.7-linux-x86_64.egg/sfepy/discrete/materials.py", line 148, in __init__
   
% self.name
TypeError: not enough arguments for format string

I've also tried passing a function handle to cond ('conductivity_fun'), and all the possible combinations of function names that I can think of, but this error persists.  I've looked at the function documentation but unfortunately this hasn't clarified things for me as this issue pertains specifically to the interactive problem specification.

Thank you for your help.
Regards,
David

Robert Cimrman

unread,
Dec 21, 2016, 3:22:53 PM12/21/16
to sfepy...@googlegroups.com
Hi David,

try looking at [1], specifically at:

def get_load(ts, coors, mode=None, **kwargs):
if mode == 'qp':
return {'val' : _get_load(coors).reshape(coors.shape[0], 1, 1)}

load = Material('load', function=Function('get_load', get_load))

in function create_local_problem() (you can ignore the other code).

What you did was almost ok, just use the keyword argument (function=...) for
the function.

The interactive use is not well documented, so it is often necessary to go
through the (interactive) examples as well as look at the function/class docs
(the search button on the website may come handy).

r.

[1] http://sfepy.org/doc-devel/examples/diffusion/poisson_parallel_interactive.html


On 12/21/2016 08:48 PM, David Jessop wrote:
> Hi,
>
> I'm trying to solve a non-linear Poisson type equation where the diffusion
> coefficient/conductivity depends on the field variable. Logically, I've
> tried basing this part of my code on the
> poisson_field_dependent_material.py case and, of course, it works nicely in
> "simple" mode but I can't figure out how to pass the value to my material
> variable "cond" in interactive mode (I require interactive mode for reasons
> stated in this post
> <https://groups.google.com/forum/#!topic/sfepy-devel/es64x4YFEiU>). I
> define the same get_conductivity function as per
> poisson_field_dependent_material.py, then declare the function as
> conductivity_fun = Function('conductivity_fun', get_conductivity)
>
> get_conductivity returns a dictionary key/value pair {'val' : val} so I
> figured to call the function as per
> cond = Material('cond', conductivity_fun)
>
> should work, but it results in this error:
> Traceback (most recent call last):
> File "examples/diffusion/myPoisson/myPoissonInteractive.py", line 185, in
> <module>
> main()
> File "examples/diffusion/myPoisson/myPoissonInteractive.py", line 116, in
> main
> cond = Material('cond', conductivity_fun,) #val= 2.0)
> File
> "/usr/local/lib/python2.7/dist-packages/sfepy-2016.3_git_94dff5a051dbd2bf6bd56fce936d75878edef9e8-py2.7-linux-x86_64.egg/sfepy/discrete/materials.py"
> , line 148, in __init__
> % self.name
> TypeError: not enough arguments for format string
>
> I've also tried passing a function handle to cond ('conductivity_fun'), and
> all the possible combinations of function names that I can think of, but
> this error persists. I've looked at the function documentation
> <http://sfepy.org/doc-devel/users_guide.html#functions> but unfortunately
Reply all
Reply to author
Forward
0 new messages