r""" Transient Laplace equation with non-constant initial conditions given by a function. Find :math:`T(t)` for :math:`t \in [0, t_{\rm final}]` such that: .. math:: \int_{\Omega} s \pdiff{T}{t} + \int_{\Omega} c \nabla s \cdot \nabla T = 0 \;, \quad \forall s \;. """ from __future__ import absolute_import from sfepy import data_dir filename_mesh = data_dir + '/meshes/3d/steel_cylinder.med' t0 = 0.0 t1 = 100.0 n_step = 11 material_2 = { 'name' : 'coef', 'values' : {'val' : 0.01}, 'kind' : 'stationary', # 'stationary' or 'time-dependent' } field_1 = { 'name' : 'temperature', 'dtype' : 'real', 'shape' : (1,), 'region' : 'Omega', 'approx_order' : 1, } variable_1 = { 'name' : 'T', 'kind' : 'unknown field', 'field' : 'temperature', 'order' : 0, 'history' : 1, } variable_2 = { 'name' : 's', 'kind' : 'test field', 'field' : 'temperature', 'dual' : 'T', } regions = { 'Omega' : 'all', 'Gamma_Top' : ('vertices in (z > 999)', 'facet'), 'Gamma_Bottom' : ('vertices in (z < 0.01)', 'facet'), } ebcs = { 'T1': ('Gamma_Top', {'T.0' : 20.0}), 'T2': ('Gamma_Bottom', {'T.0' : 0.0}), } def get_ic(coor, ic): """Non-constant initial condition.""" import numpy as nm # Normalize z coordinate. mi, ma = coor[:,0].min(), coor[:,0].max() nz = (coor[:,0] - mi) / (ma - mi) return nm.where( (nz > 250) & (nz < 750 ), 8.0 * (nz - 500), 0.0 ) functions = { 'get_ic' : (get_ic,), } ics = { 'ic' : ('Omega', {'T.0' : 'get_ic'}), } integral_1 = { 'name' : 'i', 'order' : 1, } equations = { 'Temperature' : """dw_volume_dot.i.Omega( s, dT/dt ) + dw_laplace.i.Omega( coef.val, s, T ) = 0""" } solver_0 = { 'name' : 'ls', 'kind' : 'ls.scipy_direct', 'presolve' : True, } solver_1 = { 'name' : 'newton', 'kind' : 'nls.newton', 'i_max' : 1, 'eps_a' : 1e-10, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 1.1, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6, 'is_linear' : True, } solver_2 = { 'name' : 'ts', 'kind' : 'ts.simple', 't0' : t0, 't1' : t1, 'dt' : None, 'n_step' : n_step, # has precedence over dt! } options = { 'nls' : 'newton', 'ls' : 'ls', 'ts' : 'ts', 'save_steps' : -1, }