Exemplo n.º 1
0
md.add_fem_variable('u', mfu)
md.add_fem_data('v', mfu)
md.add_initialized_data('t_N', theta_N)
md.add_initialized_data('g_N', gamma0_N / h)

# Initial conditions
U0 = mfu.eval('0.5-0.5*x')  # Initial displacement
Um1 = np.copy(U0)  # U_{-1} for Paoli-Schatzman scheme
Ndof = U0.size
V0 = np.zeros(Ndof)  # Initial velocity
s0 = 0.  # Initial stress
md.set_variable('u', U0)
md.set_variable('v', V0)

# Mass and stiffness matrices
M = gf.asm_generic(mim, 2, 'u*Test_u', -1, md)
if (lump_mass_matrix == 1):
    assert (u_degree == 1), "Sorry, basic lump only for affine elements"
    for j in range(0, Ndof):
        for i in range(1, u_degree + 1):
            if (j + i < Ndof):
                M[j, j] += M[j, j + i]
                M[j, j + i] = 0.
            if (j - i >= 0):
                M[j, j] += M[j, j - i]
                M[j, j - i] = 0.
K = gf.asm_generic(mim, 2, 'Grad_u*Grad_Test_u', -1, md)

# Dirichlet condition on the top
for i in range(0, u_degree + 1):
    K[Ndof - 1, Ndof - 1 - i] = 0.
Exemplo n.º 2
0
md.solve('max_res', 1E-9, 'max_iter', 100, 'noisy', 'lsearch', 'simplest',  'alpha min', 0.8)
U = md.variable('u');


mfer = gf.MeshFem(m,1)
mfer.set_fem(gf.Fem('FEM_PK(3,{d})'.format(d=0)),listTetra)
mfer.set_fem(gf.Fem('FEM_QK(3,{d})'.format(d=0)),listHexa)
mfer.set_fem(gf.Fem('FEM_PYRAMID_LAGRANGE({d})'.format(d=0)),listPyramid)
mfer.set_fem(gf.Fem('FEM_PK_PRISM(3,{d})'.format(d=0)),listPrism)

divsigma = '(lambda_para+ mu_para)*(Hess_u(1,1,:) + Hess_u(2,2,:) + Hess_u(3,3,:) ) + mu_para*(Hess_u:Id( qdim(u) ))' 
# 1a) interior residual
bulkresidual = 'sqr(element_size)*Norm_sqr({divsigma})*Test_psi'.format(divsigma=divsigma)

ETA1tmp = gf.asm_generic(mim,1,bulkresidual,-1
                        ,md
                        ,'psi',True,mfer,np.zeros(mfer.nbdof())) 
ETA1 = ETA1tmp [ ETA1tmp.size - mfer.nbdof() : ETA1tmp.size ]


# 1b) jump at inner faces    
sig_u = "(lambda_para*Trace(Grad_u)*Id(qdim(u)) + mu_para*(Grad_u + Grad_u'))"
grad_u_neighbor = "Interpolate(Grad_u,neighbor_element)"
sig_u_neighbor = "(lambda_para*Trace({Grad_u})*Id(qdim(u)) + mu_para*(({Grad_u}) + ({Grad_u})'))".format(Grad_u=grad_u_neighbor)

stress_jump_inner = "((({sig_u}) - ({sig_u_neighbor}))*Normal )".format(sig_u=sig_u,sig_u_neighbor=sig_u_neighbor)
edgeresidual = "0.5*(element_size*Norm_sqr({stress_jump_inner})*2*0.5*(Test_psi + Interpolate(Test_psi,neighbor_element)))".format(stress_jump_inner=stress_jump_inner)

ETA2tmp = gf.asm_generic(mim,1,edgeresidual,INNER_FACES
                        ,md
                        ,'psi',True,mfer,np.zeros(mfer.nbdof()))
Exemplo n.º 3
0
        IKSI = md.interval_of_variable('ksi')

        output = (mfu, md.variable('u'),
                  'Displacements', mfp, md.variable('p'), 'Pressure', mfksi,
                  md.variable('ksi'), 'dksi', mf_dirichlet_mult,
                  -md.variable(dirichlet_multname), "Reaction stresses", mfout,
                  VM, 'Von Mises Stress', mfu, RHS[IU[0]:IU[0] + IU[1]],
                  'residual u', mfp, RHS[IP[0]:IP[0] + IP[1]], 'residual p',
                  mfksi, RHS[IKSI[0]:IKSI[0] + IKSI[1]], 'residual ksi')

        md.finite_strain_elastoplasticity_next_iter\
           (mim, "Simo_Miehe", "displacement_and_plastic_multiplier_and_pressure",
            "u", "ksi", "p", "gamma0", "invCp0", _K_, _mu_, "hardening_law")

        GAMMA = gf.asm_generic(mim, 1, "gamma*Test_t", -1, "gamma", False,
                               mimd1, md.variable("gamma0"), "t", True, mfout,
                               np.zeros(mfout.nbdof()))
        GAMMA = np.transpose(gf.linsolve_mumps(mass_mat, GAMMA))
        output += (mfout, GAMMA, "plastic strain")

        mf1.export_to_vtk(
            '%s/finite_strain_plasticity_%i.vtk' % (resultspath, step),
            'ascii', *output)

        DIRMULT = -md.variable(dirichlet_multname)
        DIRMULT = np.reshape(DIRMULT, [1, DIRMULT.size])
        if symmetric and not rigid_grip:
            dfR = gf.asm_boundary_source(R_BOUNDARY, mim, mf1,
                                         mf_dirichlet_mult, DIRMULT)
            f.write(('step=%i fR=(%f,0) sR=(%f,0)\n') %
                    (step, dfR.sum(), dfR.sum() / H))
Exemplo n.º 4
0
                if pseudodynamic:
                    if MM < 1e-4:
                        MM = 0.
                        pseudodynamic = False
                    elif nit <= 6:
                        MM /= 2.
                else:
                    TMP = md.interpolation("max(psi0_max,psi0)", mimd1, -1)
                    md.set_variable("psi0_max", TMP)
                    break

        out = (mfu, md.variable("u"), "Displacements", mfphi,
               md.variable("phi"), "phi")
        for i, j in [[1, 1], [2, 2], [1, 2]]:
            sigma = gf.asm_generic(mim, 1, "{sigma}({i},{j})*Test_t".format(sigma=_sigma_, i=i, j=j),
                                   -1, md, "t", True, mfout, np.zeros(mfout.nbdof()))\
                    [md.nbdof():]
            sigma = np.transpose(gf.linsolve_mumps(mass_mat, sigma))
            out += (mfout, sigma, "Cauchy Stress {i}{j}".format(i=i, j=j))

        mfout.export_to_vtk("%s/demo_phase_field_%i.vtk" % (resultspath, step),
                            *out)

        DIRMULT = -md.variable(dirmultname)
        DIRMULT = np.reshape(DIRMULT, [1, DIRMULT.size])
        dfT = gf.asm_boundary_source(T_BOUNDARY, mim, mfu,
                                     md.mesh_fem_of_variable(dirmultname),
                                     DIRMULT)
        f.write(("step=%i eps=%e fR=(%e,%e)\n") %
                (step, eps, dfT[0::N].sum(), dfT[1::N].sum()))
        f.flush()
Exemplo n.º 5
0
md.add_initialized_data("f", [0,0])
md.add_initialized_data("dt", [dt])
md.add_initialized_data("nu", [nu])

md.add_Dirichlet_condition_with_multipliers(mim, "p", mfp, IN_RG, "p_in")
md.add_nonlinear_term\
(mim, "1/dt*(v-v0).Test_v + (Grad_v0*v0).Test_v + nu*Grad_v:Grad_Test_v - f.Test_v")
md.add_nonlinear_term\
(mim, "Grad_p.Grad_Test_p + 1/dt*Trace(Grad_v)*Test_p")

mmat_v = gf.asm_mass_matrix(mim, mfv)
#mmat_v = gf.asm_generic(mim, 2, "Test2_v.Test_v", -1, "v", 1, mfv, np.zeros(mfv.nbdof()))
IV = md.interval_of_variable("v")

t = 0
step = 0
while t < T+1e-8:
   print("Solving step at t=%f" % t)
   md.set_variable\
   ("p_in", mfp_.eval(p_in_str.format(t), globals(), locals()).flatten("F"))
   md.set_variable("v0", md.variable("v"))
   md.solve("noisy", "lsolver", "mumps", "max_res", 1e-8)
   vv = (gf.asm_generic(mim, 1, "(v-dt*Grad_p).Test_v", -1, md))[IV[0]:IV[0]+IV[1]]
   md.set_variable("v", gf.linsolve_mumps(mmat_v, vv))

   mfv.export_to_vtk("results_%i.vtk" % step,
                     mfv, md.variable("v"), "Velocity",
                     mfp, md.variable("p"), "Pressure")
   t += dt
   step += 1
Exemplo n.º 6
0
md.add_initialized_data("f", [0, 0])
md.add_initialized_data("dt", [dt])
md.add_initialized_data("nu", [nu])

md.add_Dirichlet_condition_with_multipliers(mim, "p", mfp, IN_RG, "p_in")
md.add_nonlinear_generic_assembly_brick\
(mim, "1/dt*(v-v0).Test_v + (Grad_v0*v0).Test_v + nu*Grad_v:Grad_Test_v - f.Test_v")
md.add_nonlinear_generic_assembly_brick\
(mim, "Grad_p.Grad_Test_p + 1/dt*Trace(Grad_v)*Test_p")

mmat_v = gf.asm_mass_matrix(mim, mfv)
#mmat_v = gf.asm_generic(mim, 2, "Test2_v.Test_v", -1, "v", 1, mfv, np.zeros(mfv.nbdof()))
IV = md.interval_of_variable("v")
IV = range(IV[0], IV[0] + IV[1])

t = 0
step = 0
while t < T + 1e-8:
    print("Solving step at t=%f" % t)
    md.set_variable\
    ("p_in", mfp_.eval(p_in_str.format(t), globals(), locals()).flatten("F"))
    md.set_variable("v0", md.variable("v"))
    md.solve("noisy", "lsolver", "mumps", "max_res", 1e-8)
    vv = gf.asm_generic(mim, 1, "(v-dt*Grad_p).Test_v", -1, md)[IV]
    md.set_variable("v", gf.linsolve_mumps(mmat_v, vv))

    mfv.export_to_vtk("results_%i.vtk" % step, mfv, md.variable("v"),
                      "Velocity", mfp, md.variable("p"), "Pressure")
    t += dt
    step += 1
Exemplo n.º 7
0
elast_law = 'SaintVenant Kirchhoff'
md.add_initialized_data('elast_params', [Lambda, Mu])
md.add_nonlinear_elasticity_brick(mim_1, 'u_1', elast_law, 'elast_params')
md.add_nonlinear_elasticity_brick(mim_2, 'u_2', elast_law, 'elast_params')
md.add_nonlinear_elasticity_brick(mim_p1, 'u_p1', elast_law, 'elast_params')
md.add_nonlinear_elasticity_brick(mim_p2, 'u_p2', elast_law, 'elast_params')
md.add_nonlinear_elasticity_brick(mim_p3, 'u_p3', elast_law, 'elast_params')

# Dirichlet BC's
F = md.interpolation('[0,0]', mfu_2, RG_DIRICHLET_2)
md.add_initialized_fem_data('dirichlet_2', mfu_2, F)
md.add_Dirichlet_condition_with_multipliers(mim_2, 'u_2', mfu_2,
                                            RG_DIRICHLET_2, 'dirichlet_2')

# Load
area_1_in = gf.asm_generic(mim_1, 0, "1", RG_NEUMANN_1)
m1 = torsion / area_1_in
_expr_load_ = "{m}/Norm_sqr(X+u_1)*[-X(2)-u_1(2);X(1)+u_1(1)].Test_u_1".format(
    m=m1)
md.add_nonlinear_generic_assembly_brick(mim_1, _expr_load_, RG_NEUMANN_1)

# Add inertia, used temporarily for getting an initial solution
md.add_initialized_data('penalty_param', 1e0)
#ibin_1 = md.add_mass_brick(mim_1, 'u_1', 'penalty_param')
##ibin_2 = md.add_mass_brick(mim_2, 'u_2', 'penalty_param')
#ibin_p1 = md.add_mass_brick(mim_p1, 'u_p1', 'penalty_param')
#ibin_p2 = md.add_mass_brick(mim_p2, 'u_p2', 'penalty_param')
#ibin_p3 = md.add_mass_brick(mim_p3, 'u_p3', 'penalty_param')

ibin_1 = md.add_linear_generic_assembly_brick(mim_1,
                                              'penalty_param*u_1.Test_u_1')
print("Dirichlet mult dofs: %i" % md.mesh_fem_of_variable("dirmult").nbdof())

shutil.copyfile(os.path.abspath(sys.argv[0]),resultspath+"/"+sys.argv[0])
starttime_overall = time.process_time()
with open("%s/tension_3D.dat" % resultspath, "w") as f1:
   for step in range(steps_t+1):
      md.set_variable("disp", disp*step/float(steps_t))
      print('STEP %i: Solving with disp = %g' % (step, md.variable("disp")))

      starttime = time.process_time()
      md.solve('noisy', 'max_iter', 25, 'max_res', 1e-10,
               'lsearch', 'simplest', 'alpha max ratio', 100, 'alpha min', 0.2, 'alpha mult', 0.6,
               'alpha threshold res', 1e9)
      print('STEP %i COMPLETED IN %f SEC' % (step, time.process_time()-starttime))

      F = gf.asm_generic(mim, 0, "dirmult", XP_RG, md)
      print("Displacement %g, total force %g" % (md.variable("disp"), F))

      A = gf.asm_generic(mim, 0, "Norm(J*Inv(F')*[1;0;0])", XP_RG, md)
      V = gf.asm_generic(mim, 0, "1", -1, md)
      sigma11 = gf.asm_generic(mim, 0, "sigma(1,1)", -1, md)/V
      gamma = gf.asm_generic(mim, 0, "gamma", -1, md)/V
      f1.write("%.10g %.10g %.10g %.10g %10g %10g\n"
               % (md.variable("disp"), F, A, F/A, sigma11, gamma))
      f1.flush()

      output = (mfout1, md.local_projection(mim, "sqrt(1.5)*Norm(sigmaD)", mfout1), "Von Mises Stress",
                mfout1, md.local_projection(mim, "J", mfout1), "J",
                mfout1, md.local_projection(mim, "sigma(1,1)", mfout1), "Cauchy stress 11",
                mfout1, md.local_projection(mim, "sigma(2,2)", mfout1), "Cauchy stress 22",
                mfout1, md.local_projection(mim, "sigma(1,2)", mfout1), "Cauchy stress 12",