-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear_elastic_tractions_beam.py
160 lines (134 loc) · 4.31 KB
/
linear_elastic_tractions_beam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
Linear elasticity with pressure traction load on a surface and
constrained to one-dimensional motion.
"""
import numpy as nm
def linear_tension(ts, coor, mode=None, region=None, ig=None):
if mode == 'qp':
print coor.shape[0] ;
print coor;
#val = nm.tile( -1.0, (coor.shape[0], 1, 1))
val = nm.zeros([coor.shape[0],3,1])
#val[:] = [-1.0,0.,0.]
val[:,1,:]=1.
print val;
print val.shape ;
return {'val' : val}
# Define the function post_process, that will be called after the problem is
# solved.
def post_process(out, problem, state, extend=False):
"""
This will be called after the problem is solved.
Parameters
----------
out : dict
The output dictionary, where this function will store additional data.
problem : ProblemDefinition instance
The current ProblemDefinition instance.
state : array
The computed state vector, containing FE coefficients of all the
unknown variables.
extend : bool
The flag indicating whether to extend the output data to the whole
domain. It can be ignored if the problem is solved on the whole domain
already.
Returns
-------
out : dict
The updated output dictionary.
"""
from sfepy.base.base import Struct
# Cauchy strain averaged in elements.
strain = problem.evaluate('de_cauchy_strain.i1.Omega( u )')
out['cauchy_strain'] = Struct(name='output_data',
mode='cell', data=strain,
dofs=None)
# Cauchy stress averaged in elements.
stress = problem.evaluate('de_cauchy_stress.i1.Omega( solid.D, u )')
out['cauchy_stress'] = Struct(name='output_data',
mode='cell', data=stress,
dofs=None)
return out
def define():
"""Define the problem to solve."""
from sfepy import data_dir
filename_mesh = data_dir + '/meshes/3d/block.mesh'
options = {
'post_process_hook' : 'post_process',
'nls' : 'newton',
'ls' : 'ls',
}
functions = {
'linear_tension' : (linear_tension,),
}
fields = {
'displacement': ('real', 3, 'Omega', 1),
}
materials = {
'solid' : ({
'lam' : 5.769,
'mu' : 3.846,
},),
'load' : (None, 'linear_tension')
}
from sfepy.mechanics.matcoefs import stiffness_tensor_lame
solid = materials['solid'][0]
lam, mu = solid['lam'], solid['mu']
solid.update({
'D' : stiffness_tensor_lame(3, lam=lam, mu=mu),
})
variables = {
'u' : ('unknown field', 'displacement', 0),
'v' : ('test field', 'displacement', 'u'),
}
regions = {
'Omega' : ('all', {}),
'Left' : ('nodes in (x < -4.99)', {}),
'Right' : ('nodes in (x > 4.99)', {}),
}
ebcs = {
'fixb' : ('Left', {'u.all' : 0.0}),
# 'fixt' : ('Right', {'u.[1,2]' : 0.0}),
}
#! Integrals
#! ---------
#! Define the integral type Volume/Surface and quadrature rule
#! (here: dim=3, order=1).
integrals = {
'i1' : ('v', 'gauss_o1_d3'),
}
##
# Balance of forces.
equations = {
'elasticity' :
"""dw_lin_elastic_iso.i1.Omega( solid.lam, solid.mu, v, u )
= - dw_surface_ltr.i1.Right( load.val, v )""",
}
##
# Solvers etc.
solvers = {
'ls' : ('ls.scipy_direct', {}),
'newton' : ('nls.newton',
{ 'i_max' : 1,
'eps_a' : 1e-10,
'eps_r' : 1.0,
'macheps' : 1e-16,
# Linear system error < (eps_a * lin_red).
'lin_red' : 1e-2,
'ls_red' : 0.1,
'ls_red_warp' : 0.001,
'ls_on' : 1.1,
'ls_min' : 1e-5,
'check' : 0,
'delta' : 1e-6,
'is_plot' : False,
# 'nonlinear' or 'linear' (ignore i_max)
'problem' : 'nonlinear'}),
}
##
# FE assembling parameters.
fe = {
'chunk_size' : 1000,
'cache_override' : False,
}
return locals()