def get_hyperelastic_Y(pb, term, micro_state, im, region_name='Y'):
    from sfepy.terms import Term

    region = pb.domain.regions[region_name]
    el = region.get_cells().shape[0]
    nqp = tuple(term.integral.qps.values())[0].n_point
    npts = el * nqp

    mvars = pb.create_variables(['U', 'P'] +
                                ['P%d' % ch for ch in pb.conf.chs])
    state_u, state_p = mvars['U'], mvars['P']

    termY = Term.new('ev_grad(U)', term.integral, region, U=mvars['U'])

    if state_u.data[0] is None:
        state_u.init_data()

    u_mic = micro_state['coors'][im] - pb.domain.get_mesh_coors(actual=False)
    state_u.set_data(u_mic)
    state_u.field.clear_mappings()
    family_data = pb.family_data(state_u, region, term.integral,
                                 term.integration)

    if len(state_u.field.mappings0) == 0:
        state_u.field.save_mappings()

    n_el, n_qp, dim, _, _ = state_u.get_data_shape(term.integral,
                                                   term.integration,
                                                   region_name)

    # relative displacement
    state_u.set_data(micro_state['coors'][im] -
                     micro_state['coors_prev'][im])  # \bar u (du_prev)
    grad_du_qp = state_u.evaluate(mode='grad', integral=term.integral).reshape(
        (npts, dim, dim))
    div_du_qp = nm.trace(grad_du_qp, axis1=1, axis2=2).reshape((npts, 1, 1))

    press_qp = nm.zeros((n_el, n_qp, 1, 1), dtype=nm.float64)
    grad_press_qp = nm.zeros((n_el, n_qp, dim, 1), dtype=nm.float64)

    if micro_state['p'] is not None:
        p_mic = micro_state['p'][im]
        state_p.set_data(p_mic)
        cells = state_p.field.region.get_cells()
        press_qp[cells, ...] = state_p.evaluate(integral=term.integral)
        grad_press_qp[cells, ...] = state_p.evaluate(mode='grad',
                                                     integral=term.integral)

        pch_mic = {}
        for ch in pb.conf.chs:
            state_pi = mvars['P%d' % ch]
            pch_mic[ch] = micro_state['p%d' % ch][im]
            state_pi.set_data(micro_state['p%d' % ch][im])
            cells = mvars['P%d' % ch].field.region.get_cells()
            press_qp[cells, ...] = state_pi.evaluate(integral=term.integral)
            grad_press_qp[cells,
                          ...] = state_pi.evaluate(mode='grad',
                                                   integral=term.integral)

        press_qp = press_qp.reshape((npts, 1, 1))
        grad_press_qp = grad_press_qp.reshape((npts, dim, 1))
    else:
        p_mic = nm.zeros((state_p.n_dof, ), dtype=nm.float64)
        pch_mic = {
            ch: nm.zeros((mvars['P%d' % ch].n_dof, ), dtype=nm.float64)
            for ch in pb.conf.chs
        }
        press_qp = nm.zeros((npts, 1, 1), dtype=nm.float64)
        grad_press_qp = nm.zeros((npts, dim, 1), dtype=nm.float64)

    conf_mat = pb.conf.materials
    solid_key = [key for key in conf_mat.keys() if 'solid' in key][0]
    solid_mat = conf_mat[solid_key].values
    mat = {}
    for mat_key in ['mu', 'K']:
        if isinstance(solid_mat[mat_key], dict):
            mat_fun = ConstantFunctionByRegion({mat_key: solid_mat[mat_key]})
            mat0 = mat_fun.function(ts=None,
                                    coors=nm.empty(npts),
                                    mode='qp',
                                    term=termY,
                                    problem=pb)[mat_key]
            mat[mat_key] = mat0.reshape((n_el, n_qp) + mat0.shape[-2:])
        else:
            mat[mat_key] = nm.ones((n_el, n_qp, 1, 1)) * solid_mat[mat_key]

    shape = family_data.green_strain.shape[:2]
    assert (npts == nm.prod(shape))
    sym = family_data.green_strain.shape[-2]
    dim2 = dim**2

    fargs = [
        family_data.get(name) for name in NeoHookeanULTerm.family_data_names
    ]
    stress_eff = nm.empty(shape + (sym, 1), dtype=nm.float64)
    tanmod_eff = nm.empty(shape + (sym, sym), dtype=nm.float64)
    NeoHookeanULTerm.stress_function(stress_eff, mat['mu'], *fargs)
    NeoHookeanULTerm.tan_mod_function(tanmod_eff, mat['mu'], *fargs)

    stress_eff_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    tanmod_eff_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    sym2nonsym(stress_eff_ns, stress_eff)
    sym2nonsym(tanmod_eff_ns, tanmod_eff)

    J = family_data.det_f.reshape((npts, 1, 1))
    mtx_f = family_data.mtx_f.reshape((npts, dim, dim))

    stress_p = -press_qp * J * sym_eye[dim]

    mat_A = (tanmod_eff_ns + stress_eff_ns).reshape((npts, dim2, dim2))\
        + J * press_qp * nonsym_delta[dim]

    mtxI = nm.eye(dim)
    mat_BI = (mtxI * div_du_qp - grad_du_qp).transpose(0, 2, 1) + mtxI

    mat['K'] = mat['K'].reshape((npts, dim, dim))
    mat_H = div_du_qp * mat['K']\
        - la.dot_sequences(mat['K'], grad_du_qp, 'ABT')\
        - la.dot_sequences(grad_du_qp, mat['K'], 'ABT')

    out = {
        'E': 0.5 *
        (la.dot_sequences(mtx_f, mtx_f, 'ATB') - nm.eye(dim)),  # Green strain
        'S': (stress_eff.reshape(
            (npts, sym, 1)) + stress_p) / J,  # Cauchy stress
        'A': mat_A / J,  # tangent elastic tensor, eq. (20)
        'BI': mat_BI,
        'KH': mat['K'] + mat_H,
        'H': mat_H,
        'dK': mat['K'] * 0,  # constant permeability => dK = 0
        'w': -grad_press_qp * mat['K'],  # perfusion velocity
    }

    return out
Пример #2
0
def def_mat(ts, mode, coors, term, pb):
    if not (mode == 'qp'):
        return

    if not hasattr(pb, 'family_data'):
        pb.family_data = HyperElasticULFamilyData()

    update_var = pb.conf.options.mesh_update_variable
    if pb.equations is None:
        state_u = pb.create_variables([update_var])[update_var]
    else:
        state_u = pb.get_variables()[update_var]

    if state_u.data[0] is None:
        state_u.init_data()

    state_u.set_data(
        pb.domain.get_mesh_coors(actual=True) - pb.domain.get_mesh_coors())
    state_u.field.clear_mappings()
    family_data = pb.family_data(state_u, term.region, term.integral,
                                 term.integration)

    if len(state_u.field.mappings0) == 0:
        state_u.field.save_mappings()

    n_el, n_qp, dim, n_en, n_c = state_u.get_data_shape(
        term.integral, term.integration, term.region.name)

    conf_mat = pb.conf.materials
    solid_key = [key for key in conf_mat.keys() if 'solid' in key][0]
    solid_mat = conf_mat[solid_key].values
    mat = {}
    for mat_key in ['mu', 'K']:
        if isinstance(solid_mat[mat_key], dict):
            mat_fun = ConstantFunctionByRegion({mat_key: solid_mat[mat_key]})
            mat[mat_key] = mat_fun.function(ts=ts,
                                            coors=coors,
                                            mode='qp',
                                            term=term,
                                            problem=pb)[mat_key].reshape(
                                                (n_el, n_qp, 1, 1))
    else:
        mat[mat_key] = nm.ones((n_el, n_qp, 1, 1)) * solid_mat[mat_key]

    shape = family_data.green_strain.shape[:2]
    sym = family_data.green_strain.shape[-2]
    dim2 = dim**2

    fargs = [
        family_data.get(name) for name in NeoHookeanULTerm.family_data_names
    ]
    stress = nm.empty(shape + (sym, 1), dtype=nm.float64)
    tanmod = nm.empty(shape + (sym, sym), dtype=nm.float64)
    NeoHookeanULTerm.stress_function(stress, mat['mu'], *fargs)
    NeoHookeanULTerm.tan_mod_function(tanmod, mat['mu'], *fargs)

    fargs = [
        family_data.get(name) for name in BulkPenaltyULTerm.family_data_names
    ]
    stress_p = nm.empty(shape + (sym, 1), dtype=nm.float64)
    tanmod_p = nm.empty(shape + (sym, sym), dtype=nm.float64)
    BulkPenaltyULTerm.stress_function(stress_p, mat['K'], *fargs)
    BulkPenaltyULTerm.tan_mod_function(tanmod_p, mat['K'], *fargs)

    stress_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    tanmod_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    sym2nonsym(stress_ns, stress + stress_p)
    sym2nonsym(tanmod_ns, tanmod + tanmod_p)

    npts = nm.prod(shape)
    J = family_data.det_f
    mtx_f = family_data.mtx_f.reshape((npts, dim, dim))

    out = {
        'E': 0.5 * (la.dot_sequences(mtx_f, mtx_f, 'ATB') - nm.eye(dim)),
        'A': ((tanmod_ns + stress_ns) / J).reshape((npts, dim2, dim2)),
        'S': ((stress + stress_p) / J).reshape((npts, sym, 1)),
    }

    return out
Пример #3
0
def def_mat(ts, mode, coors, term, pb):
    if not (mode == 'qp'):
        return

    if not hasattr(pb, 'family_data'):
        pb.family_data = HyperElasticULFamilyData()

    update_var = pb.conf.options.mesh_update_variable
    if pb.equations is None:
        state_u = pb.create_variables([update_var])[update_var]
    else:
        state_u = pb.get_variables()[update_var]

    if state_u.data[0] is None:
        state_u.init_data()

    state_u.set_data(
        pb.domain.get_mesh_coors(actual=True) - pb.domain.get_mesh_coors())
    state_u.field.clear_mappings()
    family_data = pb.family_data(state_u, term.region,
                                 term.integral, term.integration)

    if len(state_u.field.mappings0) == 0:
        state_u.field.save_mappings()

    n_el, n_qp, dim, n_en, n_c = state_u.get_data_shape(term.integral,
                                                        term.integration,
                                                        term.region.name)

    conf_mat = pb.conf.materials
    solid_key = [key for key in conf_mat.keys() if 'solid' in key][0]
    solid_mat = conf_mat[solid_key].values
    mat = {}
    for mat_key in ['mu', 'K']:
        if isinstance(solid_mat[mat_key], dict):
            mat_fun = ConstantFunctionByRegion({mat_key: solid_mat[mat_key]})
            mat[mat_key] = mat_fun.function(ts=ts, coors=coors, mode='qp',
                term=term, problem=pb)[mat_key].reshape((n_el, n_qp, 1, 1))
    else:
        mat[mat_key] = nm.ones((n_el, n_qp, 1, 1)) * solid_mat[mat_key]

    shape = family_data.green_strain.shape[:2]
    sym = family_data.green_strain.shape[-2]
    dim2 = dim**2

    fargs = [family_data.get(name)
             for name in NeoHookeanULTerm.family_data_names]
    stress = nm.empty(shape + (sym, 1), dtype=nm.float64)
    tanmod = nm.empty(shape + (sym, sym), dtype=nm.float64)
    NeoHookeanULTerm.stress_function(stress, mat['mu'], *fargs)
    NeoHookeanULTerm.tan_mod_function(tanmod, mat['mu'], *fargs)

    fargs = [family_data.get(name)
             for name in BulkPenaltyULTerm.family_data_names]
    stress_p = nm.empty(shape + (sym, 1), dtype=nm.float64)
    tanmod_p = nm.empty(shape + (sym, sym), dtype=nm.float64)
    BulkPenaltyULTerm.stress_function(stress_p, mat['K'], *fargs)
    BulkPenaltyULTerm.tan_mod_function(tanmod_p, mat['K'], *fargs)

    stress_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    tanmod_ns = nm.zeros(shape + (dim2, dim2), dtype=nm.float64)
    sym2nonsym(stress_ns, stress + stress_p)
    sym2nonsym(tanmod_ns, tanmod + tanmod_p)

    npts = nm.prod(shape)
    J = family_data.det_f
    mtx_f = family_data.mtx_f.reshape((npts, dim, dim))

    out = {
        'E': 0.5 * (la.dot_sequences(mtx_f, mtx_f, 'ATB') - nm.eye(dim)),
        'A': ((tanmod_ns + stress_ns) / J).reshape((npts, dim2, dim2)),
        'S': ((stress + stress_p) / J).reshape((npts, sym, 1)),
    }

    return out