コード例 #1
0
def ulf_init(pb):
    pb.family_data = HyperElasticULFamilyData()
    pb_vars = pb.get_variables()
    pb_vars['u'].init_data()

    pb.update_materials_flag = True
    pb.iiter = 0
コード例 #2
0
def ulf_init(pb):
    pb.family_data = HyperElasticULFamilyData()
    pb.init_solvers()
    pb.nls.fun = MyEvalResidual(pb).eval_residual
    pb.nls_iter_hook = ulf_iteration_hook
    pb.domain.mesh.coors_act = pb.domain.mesh.coors.copy()
    pb_vars = pb.get_variables()
    pb_vars['u'].init_data()

    pb.update_materials_flag = True
    pb.iiter = 0
コード例 #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
コード例 #4
0
def def_mat(ts, coors, mode=None, term=None, problem=None, **kwargs):
    if not (mode == 'qp'):
        return

    pb = problem

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

    macro_data = pb.homogenization_macro_data
    micro_state, im = pb.micro_state
    mac_id = micro_state['id'][im]
    cache_key = ('Y', term.integral.name, term.integration, im,
                 macro_data['macro_time_step'])

    if cache_key not in material_cache:
        out = get_hyperelastic_Y(pb, term, micro_state, im)
        material_cache[cache_key] = out

        # clear cache
        to_remove = []
        for k in material_cache.keys():
            if not (k[-1] == macro_data['macro_time_step']):
                to_remove.append(k)
        for k in to_remove:
            del (material_cache[k])

        if 'recovery_idxs' in macro_data and\
            mac_id in macro_data['recovery_idxs'] and\
            macro_data['macro_time_step'] > 0:

            output('>>> recovery: %d / %d / %d'\
                % (im, macro_data['macro_time_step'], mac_id))

            qp_data = {}
            for k in ['S', 'E', 'w']:
                qp_data[k] = out[k]

            nodal_data = {}
            nodal_data['u'] =\
                micro_state['coors'][im] - pb.domain.get_mesh_coors(actual=False)
            for st in ['p', 'p1', 'p2']:
                nodal_data[st] = micro_state[st][im]

            state_u = pb.create_variables(['U'])['U']
            state_u_det = state_u.field.get_mapping(term.region,
                                                    term.integral,
                                                    term.integration,
                                                    get_saved=True)[0].det
            post_process_hook(pb, nodal_data, qp_data,
                              macro_data['macro_ccoor'][im], state_u_det, im,
                              macro_data['macro_time_step'], pb.conf.eps0)
    else:
        out = material_cache[cache_key]

    npts = coors.shape[0]
    region = term.region

    if region.name == 'Y':
        return out
    else:
        el = region.get_cells()[:, nm.newaxis]
        nel = el.shape[0]
        nqp = tuple(term.integral.qps.values())[0].n_point

        assert (npts == nel * nqp)

        idxs = (el * nm.array([nqp] * nqp) + nm.arange(nqp)).flatten()
        lout = {k: v[idxs, ...] for k, v in out.items()}

        return lout