Trouble with surface traction function
Hi all,
I'm having problems with using a function to define a surface traction load. I attached my modified version of linear_elastic.py and the mesh (block.med).
The function is define as follows:
materials = { 'solid' : ('Omega', {'lam' : lam, 'mu' : mu}), 'traction' : ('Right', {'val' : [1.0e-6, 0., 0.]}), #'traction' :('Right', None, 'tractionLoad'), }
def tractionLoad( ts, coors, region, ig=None, mode=None ): """ts = TimeStepper, coor = coordinates of field nodes in region.""" val = nm.array([[[1.0e-6, 0.0, 0.0]]]) val = nm.tile(val, (coors.shape[0], 1, 1)) print val.shape return {'val' : val}
functions = { 'tractionLoad' : (tractionLoad,), }
When I use the constant value, everything is fine, but when I switch to the function, I get the following output:
<snip> sfepy: updating materials... sfepy: solid sfepy: traction (300, 1, 3) (1331, 1, 3) sfepy: ...done in 0.00 s sfepy: updating variables... sfepy: ...done /usr/lib/python2.5/site-packages/scipy/linsolve/__init__.py:4: DeprecationWarning: scipy.linsolve has moved to scipy.sparse.linalg.dsolve warn('scipy.linsolve has moved to scipy.sparse.linalg.dsolve', DeprecationWarning) sfepy: infs or nans in the residual: [ 0. 0. 0. ..., 0.03059925 0. 0. ] sfepy: False > /home/logan/projects/sfepy/sfepy/solvers/nls.py(197)__call__() 196 --> 197 if self.log is not None: 198 self.log(err, it)
Is there a problem with the function definition? I looked at the ConstantFunction class in sfepy/fem/functions.py and I think I'm returning a similarly shaped array for the 'val' key in the returned dictionary in my function.
Thanks! Logan
-- You received this message because you are subscribed to the Google Groups "sfepy-devel" group. To post to this group, send email to sfepy...@googlegroups.com. To unsubscribe from this group, send email to sfepy-devel...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sfepy-devel?hl=en.
Hi Logan,
the traction vector is expected to be a "column" vector of shape (dim, 1), and the tractionLoad() function should return data only if mode == 'qp'. So the following works:
materials = { 'solid' : ('Omega', {'lam' : lam, 'mu' : mu}), # 'traction' : ('Right', {'val' : [[1.0e-6], [0.], [0.]]}), 'traction' :('Right', None, 'tractionLoad'), }
def tractionLoad( ts, coors, region, ig=None, mode=None ): """ts = TimeStepper, coor = coordinates of field nodes in region.""" if mode == 'qp': val = nm.array([[1.0e-6], [0.], [0.]]) val = nm.tile(val, (coors.shape[0], 1, 1)) print val.shape return {'val' : val}
More comments below...
On 05/13/10 22:11, Logan Sorenson wrote:
Hi all,
I'm having problems with using a function to define a surface traction load. I attached my modified version of linear_elastic.py and the mesh (block.med).
The function is define as follows:
materials = { 'solid' : ('Omega', {'lam' : lam, 'mu' : mu}), 'traction' : ('Right', {'val' : [1.0e-6, 0., 0.]}), #'traction' :('Right', None, 'tractionLoad'), }
If you compiled (via 'make') the extension modules with
debug_flags = '-DDEBUG_FMF'
in your site_cfg.py, you would see that the traction should be column, as the C code would have thrown an exception.
def tractionLoad( ts, coors, region, ig=None, mode=None ): """ts = TimeStepper, coor = coordinates of field nodes in region.""" val = nm.array([[[1.0e-6, 0.0, 0.0]]]) val = nm.tile(val, (coors.shape[0], 1, 1)) print val.shape return {'val' : val}
This a so common mistake, that maybe we should make the mode argument to have 'qp' as default?
functions = { 'tractionLoad' : (tractionLoad,), }
When I use the constant value, everything is fine, but when I switch to the function, I get the following output:
No :] Even in case of the constant value the code computes with wrong data, it just does not check it when debug flags are off.
There is already an issue for this (Issue 70)... We should check all material parameter shapes at Python level.
<snip> sfepy: updating materials... sfepy: solid sfepy: traction (300, 1, 3) (1331, 1, 3) sfepy: ...done in 0.00 s sfepy: updating variables... sfepy: ...done /usr/lib/python2.5/site-packages/scipy/linsolve/__init__.py:4: DeprecationWarning: scipy.linsolve has moved to scipy.sparse.linalg.dsolve warn('scipy.linsolve has moved to scipy.sparse.linalg.dsolve', DeprecationWarning) sfepy: infs or nans in the residual: [ 0. 0. 0. ..., 0.03059925 0. 0. ] sfepy: False > /home/logan/projects/sfepy/sfepy/solvers/nls.py(197)__call__() 196 --> 197 if self.log is not None: 198 self.log(err, it)
Is there a problem with the function definition? I looked at the ConstantFunction class in sfepy/fem/functions.py and I think I'm returning a similarly shaped array for the 'val' key in the returned dictionary in my function.
Yes, it was almost ok :)
cheers, r.
-- You received this message because you are subscribed to the Google Groups "sfepy-devel" group. To post to this group, send email to sfepy...@googlegroups.com. To unsubscribe from this group, send email to sfepy-devel...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sfepy-devel?hl=en.
Hi Robert,
On Fri, May 14, 2010 at 4:29 AM, Robert Cimrman cimr...@ntc.zcu.cz wrote:
Hi Logan,
the traction vector is expected to be a "column" vector of shape (dim, 1), and the tractionLoad() function should return data only if mode == 'qp'. So the following works:
materials = { 'solid' : ('Omega', {'lam' : lam, 'mu' : mu}), # 'traction' : ('Right', {'val' : [[1.0e-6], [0.], [0.]]}), 'traction' :('Right', None, 'tractionLoad'), }
def tractionLoad( ts, coors, region, ig=None, mode=None ): """ts = TimeStepper, coor = coordinates of field nodes in region.""" if mode == 'qp': val = nm.array([[1.0e-6], [0.], [0.]]) val = nm.tile(val, (coors.shape[0], 1, 1)) print val.shape return {'val' : val}
Oh, ok, I see now I needed to check for mode=='qp' to keep from returning incorrect data for, e.g., mode=='special'.
I was a little confused on the array shape for the traction force since I was looking at an old example from the mailing list. It seems like as progress is made on issue 70, the situation will be clearer. :)
More comments below...
On 05/13/10 22:11, Logan Sorenson wrote:
Hi all,
I'm having problems with using a function to define a surface traction load. I attached my modified version of linear_elastic.py and the mesh (block.med).
The function is define as follows:
materials = { 'solid' : ('Omega', {'lam' : lam, 'mu' : mu}), 'traction' : ('Right', {'val' : [1.0e-6, 0., 0.]}), #'traction' :('Right', None, 'tractionLoad'), }
If you compiled (via 'make') the extension modules with
debug_flags = '-DDEBUG_FMF'
in your site_cfg.py, you would see that the traction should be column, as the C code would have thrown an exception.
Ah, I see this now. I was unaware of the DEBUG_FMF flag.
def tractionLoad( ts, coors, region, ig=None, mode=None ): """ts = TimeStepper, coor = coordinates of field nodes in region.""" val = nm.array([[[1.0e-6, 0.0, 0.0]]]) val = nm.tile(val, (coors.shape[0], 1, 1)) print val.shape return {'val' : val}
This a so common mistake, that maybe we should make the mode argument to have 'qp' as default?
Since I'm still learning what gets passed in to user functions, I didn't think about why the mode has to be checked. But now it makes sense. I guess we can think about it and decide whether it makes sense to assume mode=='qp' if not given, or if it's better just to add a warning to the documentation.
functions = { 'tractionLoad' : (tractionLoad,), }
When I use the constant value, everything is fine, but when I switch to the function, I get the following output:
No :] Even in case of the constant value the code computes with wrong data, it just does not check it when debug flags are off.
There is already an issue for this (Issue 70)... We should check all material parameter shapes at Python level.
<snip> sfepy: updating materials... sfepy: solid sfepy: traction (300, 1, 3) (1331, 1, 3) sfepy: ...done in 0.00 s sfepy: updating variables... sfepy: ...done /usr/lib/python2.5/site-packages/scipy/linsolve/__init__.py:4: DeprecationWarning: scipy.linsolve has moved to scipy.sparse.linalg.dsolve warn('scipy.linsolve has moved to scipy.sparse.linalg.dsolve', DeprecationWarning) sfepy: infs or nans in the residual: [ 0. 0. 0. ..., 0.03059925 0. 0. ] sfepy: False > > /home/logan/projects/sfepy/sfepy/solvers/nls.py(197)__call__()
196 --> 197 if self.log is not None: 198 self.log(err, it)
Is there a problem with the function definition? I looked at the ConstantFunction class in sfepy/fem/functions.py and I think I'm returning a similarly shaped array for the 'val' key in the returned dictionary in my function.
Yes, it was almost ok :)
cheers, r.
Thanks for the help! That clears a lot up.
Logan
-- You received this message because you are subscribed to the Google Groups "sfepy-devel" group. To post to this group, send email to sfepy...@googlegroups.com. To unsubscribe from this group, send email to sfepy-devel...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sfepy-devel?hl=en.
participants (2)
-
Logan Sorenson
-
Robert Cimrman