| 1 |
|
| 2 |
.. # gedit: set fileencoding=utf8 : |
| 3 |
|
| 4 |
.. _demo_elastodynamics: |
| 5 |
|
| 6 |
============================================ |
| 7 |
Time-integration of elastodynamics equation |
| 8 |
============================================ |
| 9 |
|
| 10 |
This demo is implemented in a single Python file, |
| 11 |
:download:`demo_elastodynamics.py`, which contains both the |
| 12 |
variational forms and the solver. |
| 13 |
|
| 14 |
This demo shows how to perform time integration of transient elastodynamics using the generalized-:math:`\alpha` method [ERL2002]_. In particular it demonstrates how to: |
| 15 |
|
| 16 |
* formulate mass and damping forms of the elastodynamics equation |
| 17 |
* implement the generalized-:math:`\alpha` method and its influence on the solution |
| 18 |
* perform efficient computation of stresses using ``LocalSolver`` |
| 19 |
|
| 20 |
The deformed structure evolution over time along with the axial stress will look as follows: |
| 21 |
|
| 22 |
.. image:: elastodynamics-transient_deformation.gif |
| 23 |
:width: 70% |
| 24 |
:align: center |
| 25 |
|
| 26 |
|
| 27 |
----------------------------------------- |
| 28 |
Introduction and elastodynamics equation |
| 29 |
----------------------------------------- |
| 30 |
|
| 31 |
The elastodynamics equation combine the balance of linear momentum: |
| 32 |
|
| 33 |
.. math:: |
| 34 |
\nabla \cdot \sigma + \rho b = \rho \ddot{u} |
| 35 |
|
| 36 |
where :math:`u` is the displacement vector field, :math:`\ddot{u}=\partial^2 u/\partial t^2` is the acceleration, |
| 37 |
:math:`\rho` the material density, :math:`b` a given body force and :math:`\sigma` the stress tensor which is related |
| 38 |
to the displacement through a constitutive equation. In the case of isotropic linearized elasticity, one has: |
| 39 |
|
| 40 |
.. math:: |
| 41 |
\sigma =\lambda \text{tr}(\varepsilon)\mathbb{1} + 2\mu\varepsilon |
| 42 |
|
| 43 |
where :math:`\varepsilon = (\nabla u + (\nabla u)^T)/2` is the linearized strain tensor, :math:`\mathbb{1}` is the |
| 44 |
identity of second-rank tensors and :math:`\lambda=\dfrac{E\nu}{(1+\nu)(1-2\nu)},\mu=\dfrac{E}{2(1+\nu)}` are the |
| 45 |
Lame coefficients given as functions of the Young modulus :math:`E` and the Poisson ratio :math:`\nu`. |
| 46 |
|
| 47 |
The weak form is readily obtained by integrating by part the balance equation using a test function :math:`v\in V` |
| 48 |
with :math:`V` being a suitable function space that satisfies the displacement boundary conditions: |
| 49 |
|
| 50 |
.. math:: |
| 51 |
\int_{\Omega} \rho \ddot{u}\cdot v \, {\rm d} x + \int_{\Omega} \sigma(u):\varepsilon(v) \, {\rm d} x = |
| 52 |
\int_{\Omega} \rho b \cdot v \, {\rm d} x + \int_{\partial\Omega} (\sigma\cdot n) \cdot v \, {\rm d} s \quad \text{for all } v\in V |
| 53 |
|
| 54 |
The previous equation can be written as follows: |
| 55 |
|
| 56 |
.. math:: |
| 57 |
\text{Find }u\in V\text{ such that } m(\ddot{u},v) + k(u,v) = L(v) \quad \text{for all } v\in V |
| 58 |
|
| 59 |
where :math:`m` is the symmetric bilinear form associated with the mass matrix and :math:`k` the one associated with the stiffness matrix. |
| 60 |
|
| 61 |
After introducing the finite element space interpolation, one obtains the corresponding discretized evolution equation: |
| 62 |
|
| 63 |
.. math:: |
| 64 |
\text{Find }\{u\}\in\mathbb{R}^n\text{ such that } \{v\}^T[M]\{\ddot{u}\} + \{v\}^T[K]\{u\} = \{v\}^T\{F\} \quad \text{for all } \{v\}\in\mathbb{R}^n |
| 65 |
|
| 66 |
which is a generalized :math:`n`-dof harmonic oscillator equation. |
| 67 |
|
| 68 |
Quite often in structural dynamics, structures do not oscillate perfectly but lose energy through various dissipative mechanisms (friction with air or supports, |
| 69 |
internal dissipation through plasticity, damage, etc.). Dissipative terms can be introduced at the level of the constitutive equation if these mechanisms are well |
| 70 |
known but quite often it is not the case. Dissipation can then be modeled by adding an *ad hoc* damping term depending on the structure velocity :math:`\dot{u}` |
| 71 |
to the previous evolution equation: |
| 72 |
|
| 73 |
.. math:: |
| 74 |
\text{Find }u\in V\text{ such that } m(\ddot{u},v) + c(\dot{u},v) + k(u,v) = L(v) \quad \text{for all } v\in V |
| 75 |
|
| 76 |
The damping form will be considered here as bilinear and symmetric, being therefore associated with a damping matrix :math:`[C]`. |
| 77 |
|
| 78 |
~~~~~~~~~~~~~~~~~ |
| 79 |
Rayleigh damping |
| 80 |
~~~~~~~~~~~~~~~~~ |
| 81 |
|
| 82 |
When little is known about the origin of damping in the structure, a popular choice for the damping matrix, known as *Rayleigh damping*, consists in using |
| 83 |
a linear combination of the mass and stiffness matrix :math:`[C] = \eta_M[M]+\eta_K[K]` with two positive parameters :math:`\eta_M,\eta_K` which |
| 84 |
can be fitted against experimental measures for instance (usually by measuring the damping ratio of two natural modes of vibration). |
| 85 |
|
| 86 |
--------------------------------------------------------------- |
| 87 |
Time discretization using the generalized-:math:`\alpha` method |
| 88 |
--------------------------------------------------------------- |
| 89 |
|
| 90 |
We now introduce a time discretization of the interval study :math:`[0;T]` in :math:`N+1` time increments :math:`t_0=0,t_1,\ldots,t_N,t_{N+1}=T` |
| 91 |
with :math:`\Delta t=T/N` denoting the time step (supposed constant). The resolution will make use of the generalized-:math:`\alpha` method |
| 92 |
which can be seen as an extension of the widely used Newmark-:math:`\beta` method in structural dynamics. As an implicit method, it is unconditionally |
| 93 |
stable for a proper choice of coefficients so that quite large time steps can be used. It also allows for high frequency dissipation and offers a |
| 94 |
second-order accuracy, i.e. in :math:`O(\Delta t^2)`. |
| 95 |
|
| 96 |
The method consists in solving the dynamic evolution equation at intermediate time between :math:`t_n` and :math:`t_{n+1}` as follows: |
| 97 |
|
| 98 |
.. math:: |
| 99 |
[M]\{\ddot{u}_{n+1-\alpha_m}\} + [C]\{\dot{u}_{n+1-\alpha_f}\}+[K]\{u_{n+1-\alpha_f}\} = \{F(t_{n+1-\alpha_f})\} |
| 100 |
|
| 101 |
with the notation :math:`X_{n+1-\alpha} = (1-\alpha)X_{n+1}+\alpha X_{n}`. In addition, the following approximation for the displacement and velocity |
| 102 |
at :math:`t_{n+1}` are used: |
| 103 |
|
| 104 |
.. math:: |
| 105 |
\begin{align*} |
| 106 |
\{u_{n+1}\} &= \{u_{n}\}+\Delta t \{\dot{u}_{n}\} + \dfrac{\Delta t^2}{2}\left((1-2\beta)\{\ddot{u}_{n}\}+2\beta\{\ddot{u}_{n+1}\}\right) \\ |
| 107 |
\{\dot{u}_{n+1}\} &= \{\dot{u}_{n}\} + \Delta t\left((1-\gamma)\{\ddot{u}_{n}\}+\gamma\{\ddot{u}_{n+1}\}\right) |
| 108 |
\end{align*} |
| 109 |
|
| 110 |
It can be seen that these are the relations of the Newmark method. The latter is therefore obtained as a particular case when :math:`\alpha_f=\alpha_m=0`. |
| 111 |
|
| 112 |
The problem can then be formulated in terms of unkown displacement at :math:`t_{n+1}` with: |
| 113 |
|
| 114 |
.. math:: |
| 115 |
\{\ddot{u}_{n+1}\} = \dfrac{1}{\beta\Delta t^2}\left(\{u_{n+1}\} - \{u_{n}\}-\Delta t \{\dot{u}_{n}\} \right) - \dfrac{1-2\beta}{2\beta}\{\ddot{u}_{n}\} |
| 116 |
|
| 117 |
After plugging into the evolution and rearranging the known and unknown terms, one obtains the following system to solve: |
| 118 |
|
| 119 |
.. math:: |
| 120 |
\begin{align*} |
| 121 |
[\bar{K}]\{u_{n+1}\} &= \{F(t_{n+1-\alpha_f})\} - \alpha_f[K]\{u_n\} \\ |
| 122 |
&- [C](c_1\{u_n\}+c_2\{\dot{u}_n\}+c_3\{\ddot{u}_n\})-[M](m_1\{u_n\}+m_2\{\dot{u}_n\}+m_3\{\ddot{u}_n\}) |
| 123 |
\end{align*} |
| 124 |
|
| 125 |
where: |
| 126 |
* :math:`[\bar{K}] = [K]+c_1[C]+m_1[M]` |
| 127 |
* :math:`c_1 = \dfrac{\gamma(1-\alpha_f)}{\beta\Delta t}` |
| 128 |
* :math:`c_2 = 1-\gamma(1-\alpha_f)/\beta` |
| 129 |
* :math:`c_3 = \Delta t(1-\alpha_f)(1-\dfrac{\gamma}{2\beta})` |
| 130 |
* :math:`m_1 = \dfrac{(1-\alpha_m)}{\beta\Delta t^2}` |
| 131 |
* :math:`m_2 = \dfrac{(1-\alpha_m)}{\beta\Delta t}` |
| 132 |
* :math:`m_3 = 1-\dfrac{1-\alpha_m}{2\beta}` |
| 133 |
|
| 134 |
Once the linear system has been solved for :math:`\{u_{n+1}\}`, the new velocity and acceleration are computed using the previous formulae. |
| 135 |
|
| 136 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 137 |
Popular choice of parameters |
| 138 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 139 |
|
| 140 |
The most popular choice for the parameters is: :math:`\alpha_m,\alpha_f \leq 1/2` and :math:`\gamma=\dfrac{1}{2}+\alpha_m-\alpha_f`, |
| 141 |
:math:`\beta=\dfrac{1}{4}\left(\gamma+\dfrac{1}{2}\right)^2` which ensures unconditional stability, optimal dissipation and second-order accuracy. |
| 142 |
|
| 143 |
|
| 144 |
--------------- |
| 145 |
Implementation |
| 146 |
--------------- |
| 147 |
|
| 148 |
We consider a rectangular beam clamped at one end and loaded by a uniform vertical traction at the other end. |
| 149 |
After importing the relevant modules, the mesh and subdomains for boundary conditions are defined:: |
| 150 |
|
| 151 |
from dolfin import * |
| 152 |
import numpy as np |
| 153 |
import matplotlib.pyplot as plt |
| 154 |
|
| 155 |
# Form compiler options |
| 156 |
parameters["form_compiler"]["cpp_optimize"] = True |
| 157 |
parameters["form_compiler"]["optimize"] = True |
| 158 |
|
| 159 |
# Define mesh |
| 160 |
mesh = BoxMesh(Point(0., 0., 0.), Point(1., 0.1, 0.04), 60, 10, 5) |
| 161 |
|
| 162 |
# Sub domain for clamp at left end |
| 163 |
def left(x, on_boundary): |
| 164 |
return near(x[0], 0.) and on_boundary |
| 165 |
|
| 166 |
# Sub domain for rotation at right end |
| 167 |
def right(x, on_boundary): |
| 168 |
return near(x[0], 1.) and on_boundary |
| 169 |
|
| 170 |
|
| 171 |
Material parameters for the elastic constitutive relation, the material density :math:`\rho` |
| 172 |
for the mass matrix and the two parameters defining the Rayleigh damping :math:`\eta_M,\eta_K` |
| 173 |
(initially zero damping is considered but this value can be changed) are now defined:: |
| 174 |
|
| 175 |
# Elastic parameters |
| 176 |
E = 1000.0 |
| 177 |
nu = 0.3 |
| 178 |
mu = Constant(E / (2.0*(1.0 + nu))) |
| 179 |
lmbda = Constant(E*nu / ((1.0 + nu)*(1.0 - 2.0*nu))) |
| 180 |
|
| 181 |
# Mass density |
| 182 |
rho = Constant(1.0) |
| 183 |
|
| 184 |
# Rayleigh damping coefficients |
| 185 |
eta_m = Constant(0.) |
| 186 |
eta_k = Constant(0.) |
| 187 |
|
| 188 |
Parameters used for the time discretization scheme are now defined. First, the four parameters used by the |
| 189 |
generalized-:math:`\alpha` method are chosen. Here, we used the optimal dissipation and second-order accuracy |
| 190 |
choice for :math:`\beta` and :math:`\gamma`, namely :math:`\beta=\dfrac{1}{4}\left(\gamma+\dfrac{1}{2}\right)^2` and |
| 191 |
:math:`\gamma=\dfrac{1}{2}+\alpha_m-\alpha_f` with :math:`\alpha_m=0.2` and :math:`\alpha_f=0.4` ensuring unconditional stability:: |
| 192 |
|
| 193 |
# Generalized-alpha method parameters |
| 194 |
alpha_m = Constant(0.2) |
| 195 |
alpha_f = Constant(0.4) |
| 196 |
gamma = Constant(0.5+alpha_f-alpha_m) |
| 197 |
beta = Constant((gamma+0.5)**2/4.) |
| 198 |
|
| 199 |
We also define the final time of the interval, the number of time steps and compute the associated time interval |
| 200 |
between two steps:: |
| 201 |
|
| 202 |
# Time-stepping parameters |
| 203 |
T = 4.0 |
| 204 |
Nsteps = 50 |
| 205 |
dt = Constant(T/Nsteps) |
| 206 |
|
| 207 |
|
| 208 |
We now define the time-dependent loading. Body forces are zero and the imposed loading consists of a uniform vertical traction |
| 209 |
applied at the ``right`` extremity. The loading amplitude will vary linearly from :math:`0` to :math:`p_0=1` over the time interval |
| 210 |
:math:`[0;T_c=T/5]`, after :math:`T_c` the loading is removed. For this purpose, we used the following JIT-compiled ``Expression``. |
| 211 |
In particular, it uses a conditional syntax using operators ``?`` and ``:`` :: |
| 212 |
|
| 213 |
p0 = 1. |
| 214 |
cutoff_Tc = T/5 |
| 215 |
# Define the loading as an expression depending on t |
| 216 |
p = Expression(("0", "t <= tc ? p0*t/tc : 0", "0"), t=0, tc=cutoff_Tc, p0=p0, degree=0) |
| 217 |
|
| 218 |
A standard vectorial :math:`P^1` FunctionSpace is now defined for the displacement, velocity and acceleration fields. We also |
| 219 |
define a tensorial DG-0 FunctionSpace for saving the stress field evolution:: |
| 220 |
|
| 221 |
# Define function space for displacement, velocity and acceleration |
| 222 |
V = VectorFunctionSpace(mesh, "CG", 1) |
| 223 |
# Define function space for stresses |
| 224 |
Vsig = TensorFunctionSpace(mesh, "DG", 0) |
| 225 |
|
| 226 |
Test and trial functions are defined and the unkown displacement (corresponding to :math:`\{u_{n+1}\}` for the current time step) |
| 227 |
will be represented by the Function ``u``. Displacement, velocity and acceleration fields of the previous increment |
| 228 |
:math:`t_n` will respectively be represented by functions ``u_old``, ``v_old`` and ``a_old``:: |
| 229 |
|
| 230 |
# Test and trial functions |
| 231 |
du = TrialFunction(V) |
| 232 |
u_ = TestFunction(V) |
| 233 |
# Current (unknown) displacement |
| 234 |
u = Function(V, name="Displacement") |
| 235 |
# Fields from previous time step (displacement, velocity, acceleration) |
| 236 |
u_old = Function(V) |
| 237 |
v_old = Function(V) |
| 238 |
a_old = Function(V) |
| 239 |
|
| 240 |
We now use a ``MeshFunction`` for distinguishing the different boundaries and mark the right extremity using an ``AutoSubDomain``. |
| 241 |
The exterior surface measure ``ds`` is then defined using the boundary subdomains. Simple Dirichlet boundary conditions are also defined at the left extremity:: |
| 242 |
|
| 243 |
# Create mesh function over the cell facets |
| 244 |
boundary_subdomains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1) |
| 245 |
boundary_subdomains.set_all(0) |
| 246 |
force_boundary = AutoSubDomain(right) |
| 247 |
force_boundary.mark(boundary_subdomains, 3) |
| 248 |
|
| 249 |
# Define measure for boundary condition integral |
| 250 |
dss = ds(subdomain_data=boundary_subdomains) |
| 251 |
|
| 252 |
# Set up boundary condition at left end |
| 253 |
zero = Constant((0.0, 0.0, 0.0)) |
| 254 |
bc = DirichletBC(V, zero, left) |
| 255 |
|
| 256 |
Python functions are now defined to obtain the elastic stress tensor :math:`\sigma` (linear isotropic elasticity), the bilinear mass and stiffness forms as well |
| 257 |
as the damping form obtained as a linear combination of the mass and stiffness forms (Rayleigh damping). The linear form corresponding to the work of external forces is also defined:: |
| 258 |
|
| 259 |
# Stress tensor |
| 260 |
def sigma(r): |
| 261 |
return 2.0*mu*sym(grad(r)) + lmbda*tr(sym(grad(r)))*Identity(len(r)) |
| 262 |
|
| 263 |
# Mass form |
| 264 |
def m(u, u_): |
| 265 |
return rho*inner(u, u_)*dx |
| 266 |
|
| 267 |
# Elastic stiffness form |
| 268 |
def k(u, u_): |
| 269 |
return inner(sigma(u), sym(grad(u_)))*dx |
| 270 |
|
| 271 |
# Rayleigh damping form |
| 272 |
def c(u, u_): |
| 273 |
return eta_m*m(u, u_) + eta_k*k(u, u_) |
| 274 |
|
| 275 |
# Work of external forces |
| 276 |
def Wext(u_): |
| 277 |
return dot(u_, p)*dss(3) |
| 278 |
|
| 279 |
Functions for implementing the time stepping scheme are also defined. ``update_a`` returns :math:`\{\ddot{u}_{n+1}\}` |
| 280 |
as a function of the variables at the previous increment and of the new displacement :math:`\{u_{n+1}\}`. The function accepts a keyword ``ufl`` so that the expressions involved can be used with UFL representations if ``True`` or with array of values if ``False`` (we will make use of both possibilities later). |
| 281 |
In particular, the time step ``dt`` and time-stepping scheme parameters are either ``Constant`` or floats depending on the case. |
| 282 |
Function ``update_v`` does the same but for the new velocity :math:`\{\dot{u}_{n+1}\}` as a function of the previous variables |
| 283 |
and of the new acceleration. Finally, function ``update_fields`` performs the final update at the end of the time step when the new |
| 284 |
displacement :math:`\{u_{n+1}\}` has effectively been computed. In this context, the new acceleration and velocities are computed |
| 285 |
using the vector representation of the different fields. The variables keeping track of the values at the previous increment are now assigned the new values computed for the current increment:: |
| 286 |
|
| 287 |
# Update formula for acceleration |
| 288 |
# a = 1/(2*beta)*((u - u0 - v0*dt)/(0.5*dt*dt) - (1-2*beta)*a0) |
| 289 |
def update_a(u, u_old, v_old, a_old, ufl=True): |
| 290 |
if ufl: |
| 291 |
dt_ = dt |
| 292 |
beta_ = beta |
| 293 |
else: |
| 294 |
dt_ = float(dt) |
| 295 |
beta_ = float(beta) |
| 296 |
return (u-u_old-dt_*v_old)/beta_/dt_**2 - (1-2*beta_)/2/beta_*a_old |
| 297 |
|
| 298 |
# Update formula for velocity |
| 299 |
# v = dt * ((1-gamma)*a0 + gamma*a) + v0 |
| 300 |
def update_v(a, u_old, v_old, a_old, ufl=True): |
| 301 |
if ufl: |
| 302 |
dt_ = dt |
| 303 |
gamma_ = gamma |
| 304 |
else: |
| 305 |
dt_ = float(dt) |
| 306 |
gamma_ = float(gamma) |
| 307 |
return v_old + dt_*((1-gamma_)*a_old + gamma_*a) |
| 308 |
|
| 309 |
def update_fields(u, u_old, v_old, a_old): |
| 310 |
"""Update fields at the end of each time step.""" |
| 311 |
|
| 312 |
# Get vectors (references) |
| 313 |
u_vec, u0_vec = u.vector(), u_old.vector() |
| 314 |
v0_vec, a0_vec = v_old.vector(), a_old.vector() |
| 315 |
|
| 316 |
# use update functions using vector arguments |
| 317 |
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec, ufl=False) |
| 318 |
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec, ufl=False) |
| 319 |
|
| 320 |
# Update (u_old <- u) |
| 321 |
v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec |
| 322 |
u_old.vector()[:] = u.vector() |
| 323 |
|
| 324 |
The system variational form is now built by expressing the new acceleration :math:`\{\ddot{u}_{n+1}\}` as a function of |
| 325 |
the TrialFunction ``du`` using ``update_a``, which here works as a UFL expression. Using this new acceleration, the same is |
| 326 |
done for the new velocity using ``update_v``. Intermediate averages using parameters :math:`\alpha_m,\alpha_f` of the generalized- :math:`\alpha` |
| 327 |
method are obtained with a user-defined fuction ``avg``. The weak form evolution equation is then written using all these |
| 328 |
quantities. Since the problem is linear, we then extract the bilinear and linear parts using ``rhs`` and ``lhs``:: |
| 329 |
|
| 330 |
def avg(x_old, x_new, alpha): |
| 331 |
return alpha*x_old + (1-alpha)*x_new |
| 332 |
|
| 333 |
# Residual |
| 334 |
a_new = update_a(du, u_old, v_old, a_old, ufl=True) |
| 335 |
v_new = update_v(a_new, u_old, v_old, a_old, ufl=True) |
| 336 |
res = m(avg(a_old, a_new, alpha_m), u_) + c(avg(v_old, v_new, alpha_f), u_) \ |
| 337 |
+ k(avg(u_old, du, alpha_f), u_) - Wext(u_) |
| 338 |
a_form = lhs(res) |
| 339 |
L_form = rhs(res) |
| 340 |
|
| 341 |
Alternatively, the use of ``derivative`` can be made for non-linear problems for instance or one can also directly |
| 342 |
formulate the system to solve, involving the modified stiffness matrix :math:`[\bar{K}]` and the various coefficients introduced earlier. |
| 343 |
|
| 344 |
Since the system matrix to solve is the same for each time step (constant time step), it is not necessary to factorize the system at each increment. |
| 345 |
It can be done once and for all and only perform assembly of the varying right-hand side and backsubstitution to obtain the solution |
| 346 |
much more efficiently. This is done by defining a ``LUSolver`` object while PETSc handles caching factorizations:: |
| 347 |
|
| 348 |
# Define solver for reusing factorization |
| 349 |
K, res = assemble_system(a_form, L_form, bc) |
| 350 |
solver = LUSolver(K, "mumps") |
| 351 |
solver.parameters["symmetric"] = True |
| 352 |
|
| 353 |
We now initiate the time stepping loop. We will keep track of the beam vertical tip displacement over time as well as the different |
| 354 |
parts of the system total energy. We will also compute the stress field and save it, along with the displacement field, in a ``XDMFFile``. |
| 355 |
The option `flush_ouput` enables to open the result file before the loop is finished, the ``function_share_mesh`` option tells that only one |
| 356 |
mesh is used for all functions of a given time step (displacement and stress) while the ``rewrite_function_mesh`` enforces that the same mesh |
| 357 |
is used for all time steps. These two options enables writing the mesh information only once instead of :math:`2N_{steps}` times:: |
| 358 |
|
| 359 |
# Time-stepping |
| 360 |
time = np.linspace(0, T, Nsteps+1) |
| 361 |
u_tip = np.zeros((Nsteps+1,)) |
| 362 |
energies = np.zeros((Nsteps+1, 4)) |
| 363 |
E_damp = 0 |
| 364 |
E_ext = 0 |
| 365 |
sig = Function(Vsig, name="sigma") |
| 366 |
xdmf_file = XDMFFile("elastodynamics-results.xdmf") |
| 367 |
xdmf_file.parameters["flush_output"] = True |
| 368 |
xdmf_file.parameters["functions_share_mesh"] = True |
| 369 |
xdmf_file.parameters["rewrite_function_mesh"] = False |
| 370 |
|
| 371 |
The time loop is now started, the loading is first evaluated at :math:`t=t_{n+1-\alpha_f}`. The corresponding system right-hand side is then |
| 372 |
assembled and the system is solved. The different fields are then updated with the newly computed quantities. Finally, some post-processing is |
| 373 |
performed: stresses are computed and written to the result file and the tip displacement and the different energies are recorded:: |
| 374 |
|
| 375 |
def local_project(v, V, u=None): |
| 376 |
"""Element-wise projection using LocalSolver""" |
| 377 |
dv = TrialFunction(V) |
| 378 |
v_ = TestFunction(V) |
| 379 |
a_proj = inner(dv, v_)*dx |
| 380 |
b_proj = inner(v, v_)*dx |
| 381 |
solver = LocalSolver(a_proj, b_proj) |
| 382 |
solver.factorize() |
| 383 |
if u is None: |
| 384 |
u = Function(V) |
| 385 |
solver.solve_local_rhs(u) |
| 386 |
return u |
| 387 |
else: |
| 388 |
solver.solve_local_rhs(u) |
| 389 |
return |
| 390 |
|
| 391 |
for (i, dt) in enumerate(np.diff(time)): |
| 392 |
|
| 393 |
t = time[i+1] |
| 394 |
print("Time: ", t) |
| 395 |
|
| 396 |
# Forces are evaluated at t_{n+1-alpha_f}=t_{n+1}-alpha_f*dt |
| 397 |
p.t = t-float(alpha_f*dt) |
| 398 |
|
| 399 |
# Solve for new displacement |
| 400 |
res = assemble(L_form) |
| 401 |
bc.apply(res) |
| 402 |
solver.solve(K, u.vector(), res) |
| 403 |
|
| 404 |
|
| 405 |
# Update old fields with new quantities |
| 406 |
update_fields(u, u_old, v_old, a_old) |
| 407 |
|
| 408 |
# Save solution to XDMF format |
| 409 |
xdmf_file.write(u, t) |
| 410 |
|
| 411 |
# Compute stresses and save to file |
| 412 |
local_project(sigma(u), Vsig, sig) |
| 413 |
xdmf_file.write(sig, t) |
| 414 |
|
| 415 |
p.t = t |
| 416 |
# Record tip displacement and compute energies |
| 417 |
# Note: Only works in serial |
| 418 |
if MPI.comm_world.size == 1: |
| 419 |
u_tip[i+1] = u(1., 0.05, 0.)[1] |
| 420 |
E_elas = assemble(0.5*k(u_old, u_old)) |
| 421 |
E_kin = assemble(0.5*m(v_old, v_old)) |
| 422 |
E_damp += dt*assemble(c(v_old, v_old)) |
| 423 |
# E_ext += assemble(Wext(u-u_old)) |
| 424 |
E_tot = E_elas+E_kin+E_damp #-E_ext |
| 425 |
energies[i+1, :] = np.array([E_elas, E_kin, E_damp, E_tot]) |
| 426 |
|
| 427 |
Note that in the above, the stresses are computed using a ``LocalSolver`` through the ``local_project`` function. Since the stress function space |
| 428 |
is a DG-0 space, the projection on this space can be performed element-wise in a very efficient manner. We therefore take advantage of the ``LocalSolver`` |
| 429 |
functionality which is precisely dedicated to such situations. Since this projection is performed at each time step, the savings in terms of computing |
| 430 |
time can be quite important. |
| 431 |
|
| 432 |
As regards the computation of the various energies, the elastic and kinetic energies are respectively given by: |
| 433 |
|
| 434 |
.. math:: |
| 435 |
E_{elas} = \int_{\Omega} \dfrac{1}{2}\sigma(u):\varepsilon(u) \, {\rm d} x |
| 436 |
.. math:: |
| 437 |
E_{kin} = \int_{\Omega} \dfrac{1}{2}\rho \dot{u}\cdot\dot{u} \, {\rm d} x |
| 438 |
|
| 439 |
which are readily computed from the respective stiffness and mass forms ``k`` and ``m`` and the current displacement and velocity. The energy related to damping |
| 440 |
is computed from the corresponding dissipation term :math:`\mathcal{D}=c(\dot{u},\dot{u})` and integrated over time: |
| 441 |
|
| 442 |
.. math:: |
| 443 |
E_{damp} = \int_0^T \mathcal{D} \, {\rm d} t |
| 444 |
|
| 445 |
As for the work developed by the external forces, the contribution to the energy is added at each time step. Finally, the total energy of the sytem is given by: |
| 446 |
|
| 447 |
.. math:: |
| 448 |
E_{tot} = E_{elas}+E_{kin}+E_{damp}-E_{ext} |
| 449 |
|
| 450 |
When the time evolution loop is finished, the evolution of the tip displacement as well as the different contributions of the energy are plotted as functions of time:: |
| 451 |
|
| 452 |
if MPI.comm_world.size == 1: |
| 453 |
# Plot tip displacement evolution |
| 454 |
plt.figure() |
| 455 |
plt.plot(time, u_tip) |
| 456 |
plt.xlabel("Time") |
| 457 |
plt.ylabel("Tip displacement") |
| 458 |
plt.ylim(-0.5, 0.5) |
| 459 |
plt.show() |
| 460 |
|
| 461 |
if (MPI.comm_world.rank == 0): |
| 462 |
# Plot energies evolution |
| 463 |
plt.figure() |
| 464 |
plt.plot(time, energies) |
| 465 |
plt.legend(("elastic", "kinetic", "damping", "total")) |
| 466 |
plt.xlabel("Time") |
| 467 |
plt.ylabel("Energies") |
| 468 |
plt.ylim(0, 0.0011) |
| 469 |
plt.show() |
| 470 |
|
| 471 |
--------------------- |
| 472 |
Analyzing the results |
| 473 |
--------------------- |
| 474 |
|
| 475 |
We first consider the case of zero Rayleigh damping :math:`\eta_M=\eta_K=0`. In this case, it can be observed that the evolution of the total energy depends |
| 476 |
on the choice of the time-stepping scheme parameters. With :math:`\alpha_m=\alpha_f=0`, we recover the Newmark-:math:`\beta` method with :math:`\beta=0.25,\gamma=0.5`. |
| 477 |
This scheme is known for being conservative. This can be observed (figure-left) in the constant total energy for :math:`t\geq T_c` when the loading is removed. On the contrary, |
| 478 |
for non zero alpha parameters, e.g. :math:`\alpha_m=0.2, \alpha_f=0.4`, it can be observed (figure-right) that the energy is decreasing during this phase, indicating numerical damping. |
| 479 |
For both cases, the scheme is unconditionally stable. Moreover, these differences vanish when reducing the time step. |
| 480 |
|
| 481 |
.. figure:: elastodynamics-energies_newmark.png |
| 482 |
:width: 60% |
| 483 |
:align: center |
| 484 |
|
| 485 |
Newmark-:math:`\beta` method :math:`\alpha_m=\alpha_f=0` |
| 486 |
|
| 487 |
.. figure:: elastodynamics-energies_generalized_alpha.png |
| 488 |
:width: 60% |
| 489 |
:align: center |
| 490 |
|
| 491 |
Generalized-:math:`\alpha` with :math:`\alpha_m=0.2, \alpha_f=0.4` |
| 492 |
|
| 493 |
For non-zero Rayleigh damping :math:`\eta_M=\eta_K=0.01`, the total energy including viscous dissipation tends to oscillate around a constant value, with oscillations vanishing for decreasing time steps. |
| 494 |
|
| 495 |
.. image:: elastodynamics-energies_generalized_alpha_damping.png |
| 496 |
:width: 60% |
| 497 |
:align: center |
| 498 |
|
| 499 |
----------- |
| 500 |
References |
| 501 |
----------- |
| 502 |
|
| 503 |
.. [ERL2002] Silvano Erlicher, Luca Bonaventura, Oreste Bursi. The analysis of the Generalized-alpha method for non-linear dynamic problems. Computational Mechanics, Springer Verlag, 2002, 28, pp.83-104, doi:10.1007/s00466-001-0273-z |