Calculate total force from cauchy stress
by Patricia Garcia Cañadilla

Dear Robert,
I have a 2D body of hyperelastic material which contracts and I would like
to compute the total force developed by the body from the cauchy stress. I
am trying to follow some of your indications I found in this group, but I
still couldn't make it works. Could you please help me to fix the problem?
I am getting the following error:
key = (region.name, integral.order, integration)
AttributeError: 'dict' object has no attribute 'name'
I am trying to do the following, inside stress_strain post-processing
function:
def stress_strain(out, problem, state, extend = False ):
from sfepy.base.base import Struct
from sfepy.mechanics.tensors import StressTransform
from sfepy.mechanics.tensors import transform_data
from sfepy.discrete.common.mappings import get_normals
ev = problem.evaluate
field = problem.fields['displacement']
region = problem.domain.regions['Gamma']
integral = problem.integrals['i2']
n = get_normals(field,integral,regions)
stress = ev('dw_tl_fib_a.1.Omega(f1.fmax, f1.eps_opt, f1.s, f1.fdir,
f1.act, v, u )',mode='qp', term_mode= 'stress');
F = ev('ev_def_grad.1.Omega(u)',mode='el_avg');
transform = StressTransform(F)
Cstress = transform.get_cauchy_from_2pk(stress)
T = Cstress*n;
Force = ev('ev_surface_integrate.2.Gamma(T)')
And here it is part of the problem configuration file.
fields = {
'displacement': ('real', 'vector', 'Omega', 1),
}
materials = {
'solid' : (None, 'get_elastic_pars'),
'load' : (None, 'linear_tension'),
'f1' : 'get_pars_fibres1',
}
variables = {
'u': ('unknown field', 'displacement', 0),
'v': ('test field', 'displacement', 'u'),
}
regions = {
'Omega' : 'all',
'Fix1' : ('vertices in x < %.10f' % (fix_point + eps2), 'facet'),
'Fix2' : ('vertices in x > %.10f' % (fix_point - eps2), 'facet'),
'Fix' : ('r.Fix1 *v r.Fix2', 'facet'),
'Gamma' : ('vertices of surface','edge'),
}
ebcs = {
'fixb' : ('Fix', {'u.all' : 0.0}),
}
integrals = {
'i1' : ('v', 1),
'i2' : ('s', 2),
}
3 months

Re: material dependent on calculated field
by Robert Cimrman

On 04/19/2018 06:02 PM, Jan Martinek wrote:
> Hello,
>
> thank you for your advice, I tested your proposed way and the material is
> constructed correctly over all the Omega region. Then, I have problems with the
> evaluation of flux, because the get_pars() is called again with the region
> "top" and the set of quadrature points is now different. In an attempt to
> evaluate the field on the surface points corresponding to "top" region I get an
> error message
>
> ValueError: region top has not true cells! (has kind: facet)
>
> Well, that's probably right.
For surface regions you would need the dw_surface_integrate term.
> Anyway, before getting too deep into it, I tried another way using
>
> T.evaluate_at(coors)
>
> but as you have already written, evaluating at arbitrary points is an overkill,
> right?
This is fine and should be reasonably fast - it does not do the projection...
> In this case, increasing the options_order to 2 gives exact results on very
> coarse mesh very quicky, but it is an easy example. Nevertheless, I often fall
> into performance issues so I should stick to recommended methods.
IMHO T.evaluate_at(coors) is by far the easiest way how to do what you need, so
try replacing it only after you find it is a bottleneck. Using the
dw_*_integrate integrate terms should be faster (can you measure it on a
largish mesh?), but there you need to distinguish between surface and volume
regions.
> I attach my script and your comments are welcome - are there any pitfalls with
> such approach?
I do not know, we will see :)
r.
> Jan
>
> On 04/18/2018 02:47 PM, Robert Cimrman wrote:
>> Hi Jan,
>>
>> On 04/18/2018 12:34 PM, Jan Martinek wrote:
>>> Hi again,
>>>
>>> I would like to calculate the electrical current flow through a
>>> material, whose electrical conductivity depends on temperature. I
>>> assume the current is very small and all the heating comes only from
>>> external bath.
>>>
>>> The procedure is composed of these steps:
>>>
>>> 1) the temperature field is calculated (it works)
>>> 2) the electrical conductivity of a material should be now assigned
>>> using a get_pars function. It should take into account the temperature
>>> field. (but how?)
>>> 3) the potential field is calculated (works)
>>> 4) calculate the flux (works, you helped me before)
>>>
>>> The temperature is calculated in nodes, but the material properties
>>> are assigned to cells. I will probably have to use make_l2_projection,
>>> but after many trials and errors I ask for help, again. I attach my
>>> testing script.
>>
>> The easiest way of obtaining a field in quadrature points is to use the
>> ev_volume_integrate term (for volume regions):
>>
>> t_qp = problem.evaluate('ev_volume_integrate.i.Omega(T)',
>> integrals=Integrals([integral]),
>> mode='qp', verbose=False)
>> t_qp.shape = (-1, 1, 1)
>>
>> Just make sure, that the same integral is used above and in get_pars().
>> The reshaping is needed for get_pars().
>>
>> Note that make_l2_projection() would work too, but it is meant for
>> evaluating fields in arbitrary points - here it is an overkill.
>>
>> r.
>>
>>> Thank you
>>> Jan
>>>
>>>
>>> _______________________________________________
>>> SfePy mailing list
>>> sfepy(a)python.org
>>> https://mail.python.org/mm3/mailman3/lists/sfepy.python.org/
>>>
>> _______________________________________________
>> SfePy mailing list
>> sfepy(a)python.org
>> https://mail.python.org/mm3/mailman3/lists/sfepy.python.org/
>
12 months

Problem installing/using Sfepy
by jeanfrancois.louf＠gmail.com

Hello,
I am trying to use sfepy instead of comsol, and I have some issues with the installation. The sfepy website recommend to post the output of the failed test ran in debug mode here, so that's what I'm trying to do.
I am using a mac OS 10.13.4, with Python 3.6.4. A lot of tests are failing, the first one is assembling, so when I run:
python3 run_tests.py --debug tests/test_assembling.py
Here is the output:
<<< directory: tests, test files: 1
<<< [1] tests/test_assembling.py
[1] sfepy: left over: ['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__file__', '__cached__', '__builtins__', 'absolute_import', 'nm', 'sps', 'TestCommon', 'verbose', '_filename']
>>> test instance prepared (4 test(s))
>>> <class 'ModuleNotFoundError'>
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~/sfepy/run_tests.py in <module>()
232
233 if __name__ == '__main__':
--> 234 sys.exit(main())
global sys.exit = <built-in function exit>
global main = <function main at 0x10a41fea0>
~/sfepy/run_tests.py in main()
221 for test_filename in options.test_filename:
222 dirname, filename = op.split(test_filename)
--> 223 run_tests(stats, dirname, [filename])
run_tests = <function wrap_run_tests.<locals>.run_tests at 0x10996aea0>
stats = [0, 0, 0, 0.0]
dirname = 'tests'
filename = 'test_assembling.py'
224 else:
225 for dirpath, dirnames, filenames in os.walk(options.test_dir):
~/sfepy/run_tests.py in run_tests(stats=[0, 0, 0, 0.0], dir_name='tests', filenames=['test_assembling.py'])
142
143 n_fail, n_total, test_time = run_test(conf_name, options,
--> 144 stats[0] + 1)
stats = [0, 0, 0, 0.0]
145
146 stats[0] += 1
~/sfepy/run_tests.py in run_test(conf_name='tests/test_assembling.py', options=Namespace(debug=True, filter_less=False, filter_...sts', test_filename=['tests/test_assembling.py']), ifile=1)
106 output.set_output_prefix(orig_prefix)
107 ok, n_fail, n_total = test.run(debug=options.raise_on_error,
--> 108 ifile=ifile)
ifile = 1
109 output.set_output_prefix('[%d] %s' % (ifile, orig_prefix))
110 test_time = time.clock() - tt
~/sfepy/sfepy/base/testing.py in run(self=Test, debug=True, ifile=1)
65
66 try:
---> 67 ret = test_method()
ret = undefined
test_method = <bound method Test.test_assemble_matrix of Test>
68 except:
69 if debug:
~/sfepy/tests/test_assembling.py in test_assemble_matrix(self=Test)
62
63 def test_assemble_matrix(self):
---> 64 from sfepy.discrete.common.extmods.assemble import assemble_matrix
global sfepy.discrete.common.extmods.assemble = undefined
assemble_matrix = undefined
65
66 mtx = sps.csr_matrix(nm.ones((self.num, self.num),
~/sfepy/sfepy/discrete/__init__.py in <module>()
7 from .functions import Functions, Function
8 from .conditions import Conditions
----> 9 from .variables import Variables, Variable, FieldVariable, create_adof_conns
global variables = undefined
global Variables = undefined
global Variable = undefined
global FieldVariable = undefined
global create_adof_conns = undefined
10 from .materials import Materials, Material
11 from .equations import Equations, Equation
~/sfepy/sfepy/discrete/variables.py in <module>()
12 output, OneTypeList, Container, Struct, basestr,
13 iter_dict_of_lists)
---> 14 import sfepy.linalg as la
global sfepy.linalg = undefined
global la = undefined
15 from sfepy.discrete.functions import Function
16 from sfepy.discrete.conditions import get_condition_value
~/sfepy/sfepy/linalg/__init__.py in <module>()
1 from __future__ import absolute_import
----> 2 from .extmods.crcm import rcm, permute_in_place
global extmods.crcm = undefined
global rcm = undefined
global permute_in_place = undefined
3 from .sparse import *
4 from .utils import *
5 from .geometry import *
ModuleNotFoundError: No module named 'sfepy.linalg.extmods.crcm'
> /Users/jeff/sfepy/sfepy/linalg/__init__.py(2)<module>()
1 from __future__ import absolute_import
----> 2 from .extmods.crcm import rcm, permute_in_place
3 from .sparse import *
4 from .utils import *
5 from .geometry import *
ipdb>
Thank you in advance for any help provided.
12 months

Re: Problem with linear elasticity
by Robert Cimrman

FYI: it is now fixed, so you can try the current git master.
r.
On 04/18/2018 02:56 PM, Robert Cimrman wrote:
> Hi Tuomas,
>
> it is a bug that manifests when using a single quadrature point per element. It
> will be fixed soon, but in the meantime, try increasing the order to 2 in
> integrals. After that your script runs, but I am getting some nan values - you
> will need some more debugging of the code you inherited.
>
> r.
12 months

material dependent on calculated field
by Jan Martinek

Hi again,
I would like to calculate the electrical current flow through a
material, whose electrical conductivity depends on temperature. I assume
the current is very small and all the heating comes only from external bath.
The procedure is composed of these steps:
1) the temperature field is calculated (it works)
2) the electrical conductivity of a material should be now assigned
using a get_pars function. It should take into account the temperature
field. (but how?)
3) the potential field is calculated (works)
4) calculate the flux (works, you helped me before)
The temperature is calculated in nodes, but the material properties are
assigned to cells. I will probably have to use make_l2_projection, but
after many trials and errors I ask for help, again. I attach my testing
script.
Thank you
Jan
1 year

material dependent on calculated field
by Jan Martinek

Hi again,
I would like to calculate the electrical current flow through a
material, whose electrical conductivity depends on temperature. I assume
the current is very small and all the heating comes only from external bath.
The procedure is composed of these steps:
1) the temperature field is calculated (it works)
2) the electrical conductivity of a material should be now assigned
using a get_pars function. It should take into account the temperature
field. (but how?)
3) the potential field is calculated (works)
4) calculate the flux (works, you helped me before)
The temperature is calculated in nodes, but the material properties are
assigned to cells. I will probably have to use make_l2_projection, but
after many trials and errors I ask for help, again. I attach my testing
script.
Thank you
Jan
1 year

Problem with linear elasticity
by Tuomas Turpeinen

I have an older code that I am trying to update to up-to-date -version of SfePy. The code has been running with the SfePy 2014.4. Now when updating to Anaconda, python 3.6 and SfePy 2018.1 the same script gives me the error message below. Is this a problem with my script or a bug in SfePy?
Thank you for you help!
-Tuomas
sfepy: guessing abaqus
sfepy: reading mesh [tri3, quad4, tetra4, hexa8] (Z:\Projektit\Sfepy\data\models\mesh.inp)...
sfepy: ...done in 0.22 s
sfepy: creating regions...
sfepy: Omega
sfepy: Left
sfepy: Right
sfepy: Center
sfepy: CenterBottom
sfepy: ...done in 0.12 s
sfepy: equation "balance_of_forces":
sfepy: dw_lin_elastic_iso.i.Omega( variable_lam.val, variable_mu.val, v, u ) = dw_point_load.0.Center(Load.force, v)
sfepy: using solvers:
ts: no ts
nls: newton
ls: ls
sfepy: updating variables...
sfepy: ...done
sfepy: setting up dof connectivities...
sfepy: ...done in 0.01 s
sfepy: matrix shape: (55308, 55308)
sfepy: assembling matrix graph...
sfepy: ...done in 0.38 s
sfepy: matrix structural nonzeros: 1846422 (-1.49e-03% fill)
sfepy: updating variables...
sfepy: ...done
sfepy: updating materials...
sfepy: variable_mu
sfepy: Load
sfepy: variable_lam
sfepy: ...done in 0.07 s
sfepy: giving up!
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\script\simple.py", line 177, in <module>
main()
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\script\simple.py", line 174, in main
app()
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\applications\application.py", line 29, in call_basic
return self.call(**kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\applications\pde_solver_app.py", line 218, in call
post_process_hook_final=self.post_process_hook_final)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\discrete\problem.py", line 1383, in solve
status=status)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\solvers\ts_solvers.py", line 34, in _standard_ts_call
status=status, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\solvers\ts_solvers.py", line 75, in __call__
vec = nls(vec0)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\solvers\nls.py", line 257, in __call__
vec_r = fun(vec_x)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\discrete\evaluate.py", line 76, in eval_residual
vec_r = self.problem.equations.eval_residuals(vec)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\discrete\equations.py", line 701, in eval_residuals
self.evaluate(mode='weak', dw_mode='vector', asm_obj=out)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\discrete\equations.py", line 634, in evaluate
term_mode=term_mode, asm_obj=asm_obj)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\discrete\equations.py", line 853, in evaluate
ret_status=True)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\terms\terms.py", line 1402, in evaluate
diff_var, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\terms\terms.py", line 1280, in eval_real
status = self.call_function(out, fargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\sfepy\terms\terms.py", line 1257, in call_function
status = self.function(out, *fargs)
File "sfepy\terms\extmods\terms.pyx", line 1331, in sfepy.terms.extmods.terms.dw_lin_elastic
File "sfepy\discrete\common\extmods\_fmfield.pyx", line 5, in sfepy.discrete.common.extmods._fmfield.array2fmfield4
ValueError: Buffer has wrong number of dimensions (expected 4, got 3)
1 year

poisson's equation, flow calculation, standalone
by Jan Martinek

Hi,
I am trying to write a standalone script, which solves the Poisson's
equation and calculates flux over a given surface area. The flux
calculation does not work and this line
flow = problem.evaluate('d_surface_flux.2.top(m.elcond, phi)',
mode='eval', copy_materials=True, verbose=False)
gives me this error:
ValueError: material argument m not found!
I have done it many times successfuly before, but I was using standard
way of writing sfepy applications using dictionaries in configuration file.
I am trying different way now. I attach the file. What am I doing wrong?
Thank you
Jan
1 year

Post to this list
by Jean-François Louf

Hello,
I would like to be able to post to this list.
Best regards,
Jean-François Louf
1 year