|
| 1 | +""" |
| 2 | +Display geometry and results: |
| 3 | +
|
| 4 | + sfepy-view beam_shell_foam.vtk -f mat_id:e:m2:o0:p0 mat_id:e:m1:o1:p0 --color-map=cool --camera-position="-0.18,0.07,0.57,0.04,-0.03,0.24,0.12,0.98,-0.19" |
| 5 | + sfepy-view beam_shell_foam.vtk -f mat_id:e:m2:o1:p0 mat_id:e:m1:o0:p0 --color-map=cool --camera-position="-0.18,0.07,0.57,0.04,-0.03,0.24,0.12,0.98,-0.19" |
| 6 | + sfepy-view results/beam_shell_foam.vtk -f uf:wuf:f10:m2:p0 0:vw:m2:p0 us_disp:wus_disp:f10:m1:p1 --camera-position="-0.4,0.16,0.57,0.02,0,0.23,0.22,0.97,-0.11" --grid-vector1="0, 1.6, 0" |
| 7 | +""" |
| 8 | +import numpy as nm |
| 9 | +import os.path as osp |
| 10 | +from sfepy.base.base import Struct |
| 11 | +from sfepy.mechanics.matcoefs import stiffness_from_youngpoisson |
| 12 | +from sfepy.discrete import Integral |
| 13 | +import sfepy.mechanics.shell10x as sh |
| 14 | + |
| 15 | +wdir = osp.dirname(__file__) |
| 16 | + |
| 17 | +filename_mesh, np = 'beam_shell_foam.vtk', 13 |
| 18 | +thickness = 0.002 |
| 19 | + |
| 20 | + |
| 21 | +def match_nodes(coors1, coors2): |
| 22 | + """ |
| 23 | + Match coordinates `coors1` with `coors2`. |
| 24 | + """ |
| 25 | + from sfepy.discrete.fem.mesh import find_map |
| 26 | + |
| 27 | + if coors1.shape != coors2.shape: |
| 28 | + raise ValueError('incompatible shapes: %s == %s'\ |
| 29 | + % (coors1.shape, coors2.shape)) |
| 30 | + |
| 31 | + i1, i2 = find_map(coors1, coors2, join=False) |
| 32 | + |
| 33 | + if i1.shape[0] != coors1.shape[0]: |
| 34 | + print(coors1[i1]) |
| 35 | + print(coors2[i2]) |
| 36 | + ii = nm.setdiff1d(nm.arange(coors1.shape[0]), i1) |
| 37 | + print(coors1[ii]) |
| 38 | + print(coors2[ii]) |
| 39 | + raise ValueError('cannot match nodes!') |
| 40 | + |
| 41 | + return i1, i2 |
| 42 | + |
| 43 | + |
| 44 | +def pp_hook(out, pb, state, extend=False): |
| 45 | + stress = pb.evaluate('ev_cauchy_stress.if.OmegaF(foam.D, uf)', |
| 46 | + mode='el_eval') |
| 47 | + strain = pb.evaluate('ev_cauchy_strain.if.OmegaF(uf)', mode='el_eval') |
| 48 | + out['E'] = Struct(name='strain', mode='cell', data=strain, region='OmegaF') |
| 49 | + out['S'] = Struct(name='stress', mode='cell', data=stress, region='OmegaF') |
| 50 | + |
| 51 | + idxs = pb.domain.regions['OmegaS'].vertices |
| 52 | + |
| 53 | + v = out['us_disp'].data |
| 54 | + aux = nm.zeros((pb.domain.shape.n_nod, v.shape[1]), dtype=v.dtype) |
| 55 | + aux[idxs] = v |
| 56 | + out['us_disp'].data = aux |
| 57 | + |
| 58 | + v = out['us_rot'].data |
| 59 | + aux = nm.zeros((pb.domain.shape.n_nod, v.shape[1]), dtype=v.dtype) |
| 60 | + aux[idxs] = v |
| 61 | + out['us_rot'].data = aux |
| 62 | + |
| 63 | + return out |
| 64 | + |
| 65 | + |
| 66 | +regions = { |
| 67 | + # shell |
| 68 | + 'OmegaS': 'cells of group 1', |
| 69 | + 'LeftS': ('vertices in (z < 0.0001)', 'vertex', 'OmegaS'), |
| 70 | + 'RightS': ('vertices in (z > 0.3999)', 'vertex', 'OmegaS'), |
| 71 | + 'TopS': ('vertices in (y > 0.01399)', 'vertex', 'OmegaS'), |
| 72 | + 'EdgeS': ('r.RightS *v r.TopS', 'vertex', 'OmegaS'), |
| 73 | + # solid foam |
| 74 | + 'OmegaF': 'cells of group 2', |
| 75 | + 'LeftF': ('vertices in (z < 0.0001)', 'facet', 'OmegaF'), |
| 76 | + 'RightF': ('vertices in (z > 0.3999)', 'facet', 'OmegaF'), |
| 77 | + 'SurfaceF_': ('vertices of surface', 'facet', 'OmegaF'), |
| 78 | + 'SurfaceF__': ('r.SurfaceF_ -s r.LeftF', 'facet', 'OmegaF'), |
| 79 | + 'SurfaceF': ('r.SurfaceF__ -s r.RightF', 'facet', 'OmegaF'), |
| 80 | +} |
| 81 | + |
| 82 | +force = 1e3 |
| 83 | +pload = nm.array([[0.0, -force / np, 0.0, 0.0, 0.0, 0.0]] * np) |
| 84 | + |
| 85 | +options = { |
| 86 | + 'output_dir': osp.join(wdir, 'results'), |
| 87 | + 'post_process_hook': pp_hook, |
| 88 | +} |
| 89 | + |
| 90 | +materials = { |
| 91 | + 'shell': ({ |
| 92 | + 'D': sh.create_elastic_tensor(young=210e9, poisson=0.3), |
| 93 | + '.drill': 1e-7, |
| 94 | + },), |
| 95 | + 'load': ({'.val': pload},), |
| 96 | + 'foam': ({'D': stiffness_from_youngpoisson(3, 20e9, 0.25), },), |
| 97 | +} |
| 98 | + |
| 99 | +fields = { |
| 100 | + 'fu': ('real', 6, 'OmegaS', 1, 'H1', 'shell10x'), |
| 101 | + 'displacement': ('real', 'vector', 'OmegaF', 1), |
| 102 | +} |
| 103 | + |
| 104 | +variables = { |
| 105 | + 'us': ('unknown field', 'fu', 0), |
| 106 | + 'vs': ('test field', 'fu', 'us'), |
| 107 | + 'uf': ('unknown field', 'displacement', 1), |
| 108 | + 'vf': ('test field', 'displacement', 'uf'), |
| 109 | +} |
| 110 | + |
| 111 | +# Custom integral. |
| 112 | +aux = Integral('i', order=3) |
| 113 | +qp_coors, qp_weights = aux.get_qp('3_8') |
| 114 | +qp_coors[:, 2] = thickness * (qp_coors[:, 2] - 0.5) |
| 115 | +qp_weights *= thickness |
| 116 | + |
| 117 | +integrals = { |
| 118 | + 'is': ('custom', qp_coors, qp_weights), |
| 119 | + 'if': 2, |
| 120 | +} |
| 121 | + |
| 122 | +ebcs = { |
| 123 | + 'FixedS': ('LeftS', {'us.all': 0.0}), |
| 124 | + 'FixedF': ('LeftF', {'uf.all': 0.0}), |
| 125 | +} |
| 126 | + |
| 127 | +functions = { |
| 128 | + 'match_nodes': (match_nodes,), |
| 129 | +} |
| 130 | + |
| 131 | +lcbcs = { |
| 132 | + 'match_surface': (['OmegaS', 'SurfaceF'], {'us.[0,1,2]': 'uf.[0,1,2]'}, |
| 133 | + 'match_nodes', 'match_dofs'), |
| 134 | +} |
| 135 | + |
| 136 | +equations = { |
| 137 | + 'balance_of_forces - shell': |
| 138 | + """dw_shell10x.is.OmegaS(shell.D, shell.drill, vs, us) |
| 139 | + = dw_point_load.is.EdgeS(load.val, vs)""", |
| 140 | + 'balance_of_forces - foam': |
| 141 | + """dw_lin_elastic.if.OmegaF(foam.D, vf, uf) = 0""", |
| 142 | +} |
| 143 | + |
| 144 | +solvers = { |
| 145 | + 'ls': ('ls.mumps', {}), |
| 146 | + 'newton': ('nls.newton', {'eps_a': 1e-6}), |
| 147 | +} |
0 commit comments