Using a parameter field variable

74 views
Skip to first unread message

Adolfo Rodriguez

unread,
Mar 30, 2016, 8:02:40 PM3/30/16
to sfepy-devel
I am trying to use a "parameter" field variable in interactive mode. What I am trying to do is very similar to the thermo-elaticity example, but for some reason I cannot make it work in interactive mode. 

In the thermo-elasticity example the parameter field variable is defined as follows 

def get_temperature_load(ts, coors, region=None):
    """
    Temperature load depends on the `x` coordinate.
    """
    x = coors[:, 0]
    return (x - x.min())**2 - T0

fields = {
    'displacement': ('real', 3, 'Omega', 1),
    'temperature': ('real', 1, 'Omega', 1),
}

variables = {
    'u' : ('unknown field', 'displacement', 0),
    'v' : ('test field', 'displacement', 'u'),
    'T' : ('parameter field', 'temperature',
           {'setter' : 'get_temperature_load'}),
}

equations = {
    'balance_of_forces' :
    """dw_lin_elastic.2.Omega( solid.D, v, u )
     - dw_biot.2.Omega( solid.alpha, v, T )
     = 0""",
}

In interactive mode this is what I am doing the following:

field_p = Field.from_args('fp', nm.float64, 1, omega,

                               approx_order=order_p)


press_load = Function('press_load',get_pressure_load)

press = FieldVariable('pressure','parameter',field_p,special={'setter':press_load},

                          primary_var_name='(set-to-None)')


And the corresponding term:


t20 = Term.new('dw_laplace(matalpha.k, q, press)',

                   integral, omega, matalpha=matalpha, q=q, press=press)


But this does not work.


Any thoughts?


Thanks

Robert Cimrman

unread,
Mar 31, 2016, 2:46:43 AM3/31/16
to sfepy...@googlegroups.com
Hi Adolfo,

On 03/31/2016 02:02 AM, Adolfo Rodriguez wrote:
> I am trying to use a "parameter" field variable in interactive mode. What I
> am trying to do is very similar to the thermo-elaticity example, but for
> some reason I cannot make it work in interactive mode.

Note that you can set data of a variable directly in the interactive mode,
using Variable.set_data().
Could you send the code that does not work, that could be run and tried? There
might be a bug because I have never used a setter function in the interactive
mode - I use set_data() directly instead - see also FieldVariable.time_update().

r.

Adolfo Rodriguez

unread,
Mar 31, 2016, 9:15:14 AM3/31/16
to sfepy-devel
Robert,

My script goes attached. The function is specified in line 262, defined in line 41 and used in term t4 in line 302. 

Thanks!
fractures_shadow.py

Robert Cimrman

unread,
Mar 31, 2016, 9:43:02 AM3/31/16
to sfepy...@googlegroups.com
I cannot run the script without the mesh .geo file, but anyway, a few remarks:

- the press_load Function instance is not used anywhere, do something like:

functions = Functions([press_load])
...
pb = Problem('elasticity', equations=eqs, nls=nls, ls=ls, functions=functions)

- then the function will be available for equations etc.
(Problem.time_update() also can take 'functions' argument.)

- line 338: use get_mat instead of get_mat1

Could you send also the geometry file, so that I could run it?

r.

Adolfo Rodriguez

unread,
Mar 31, 2016, 10:13:00 AM3/31/16
to sfepy-devel
I am attaching the *.geo file. 
frac3.geo

Adolfo Rodriguez

unread,
Mar 31, 2016, 10:24:00 AM3/31/16
to sfepy-devel
Robert,

You will need two additional files to run the problem. Find them attached.

Adolfo
geo.txt
input.txt

Adolfo Rodriguez

unread,
Mar 31, 2016, 11:42:55 AM3/31/16
to sfepy...@googlegroups.com
I am still getting an error related to the press_load function. Probably is related to the way the corresponding field variable is defined, I have the following lines:

field = Field.from_args('fu', nm.float64, 'vector', omega, approx_order=1)

press_load = Function('press_load',get_pressure_load)

 functions = Functions([press_load])

press = FieldVariable('pressure','parameter',field,special={'setter':'press_load'}, primary_var_name='(set-to-None)')

t4 = Term.new('dw_biot(matalpha.alpha, v, p)'integral, omega, matalpha=matalpha, v=v, p=press)


eq_elastic = Equation('Elastic',t1-t3-t3_hmax-t3_hmin-t4)

I get an error at this line:


Traceback (most recent call last):

  File "fractures_shadow.py", line 414, in <module>

    main()

  File "fractures_shadow.py", line 312, in main

    eqs = Equations([eq_elastic])

  File "/Users/adantra/anaconda/envs/default/lib/python2.7/site-packages/sfepy/discrete/equations.py", line 82, in __init__

    self.collect_conn_info()

  File "/Users/adantra/anaconda/envs/default/lib/python2.7/site-packages/sfepy/discrete/equations.py", line 187, in collect_conn_info

    eq.collect_conn_info(self.conn_info)

  File "/Users/adantra/anaconda/envs/default/lib/python2.7/site-packages/sfepy/discrete/equations.py", line 801, in collect_conn_info

    conn_info[key] = term.get_conn_info()

  File "/Users/adantra/anaconda/envs/default/lib/python2.7/site-packages/sfepy/terms/terms.py", line 728, in get_conn_info

    is_trace = self.arg_traces[pvar.name]

KeyError: 'press'


I am pretty sure it is related to the way I am defining the Field Variable but I don't know how to fix it. Any suggestion?


Regards,


Adolfo


--
You received this message because you are subscribed to a topic in the Google Groups "sfepy-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sfepy-devel/vlwtFrdnWgw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sfepy-devel...@googlegroups.com.
To post to this group, send email to sfepy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sfepy-devel.

Robert Cimrman

unread,
Mar 31, 2016, 12:15:07 PM3/31/16
to sfepy...@googlegroups.com
See the attached diff w.r.t. the original version of fractures_shadow.py you sent.

The variable names in the equations/terms have to be the same as given to the
FieldVariable instances.

After the proposed changes, get_pressure_load() gets called. However, it returs
a scalar instead of values in the provided coordinates, so the setting of
values fails - you need to fix that.

Does it help?

r.
diff.txt

Adolfo Rodriguez

unread,
Mar 31, 2016, 1:46:48 PM3/31/16
to sfepy-devel
Yes!!, It worked. Thanks a lot.

Robert Cimrman

unread,
Mar 31, 2016, 5:39:56 PM3/31/16
to sfepy...@googlegroups.com
On 03/31/2016 07:46 PM, Adolfo Rodriguez wrote:
> Yes!!, It worked. Thanks a lot.

OK, good luck with the rest!

Reply all
Reply to author
Forward
0 new messages