Exemplo n.º 1
0
Sigma = DU

for i in range(DU.shape[2]):
    d = np.array(DU[:, :, i])
    E = (d + d.T) * 0.5
    Sigma[:, :, i] = E
    VM[i] = np.sum(E**2) - (1. / 3.) * np.sum(np.diagonal(E))**2

print 'Von Mises range: ', VM.min(), VM.max()

# export results to VTK (you can use http://mayavi.sourceforge.net/ to view these results )
# i.e. with  "mayavi -d tripod.vtk -m BandedSurfaceMap -f WarpVector"
#sl.export_to_vtk('tripod.vtk', 'ascii', mfe, VM,'Von Mises Stress', mfu, U, 'Displacement')
#sl.export_to_vtk('tripod_edges.vtk','edges')

# export to OpenDX
#sl.export_to_dx('tripod.dx', 'ascii', mfe, VM,'Von Mises Stress')

# export the displacement and the stress tensor field
# can be viewed with mayavi -d ./tripod_ev.vtk -f WarpVector -m TensorGlyphs
SigmaSL = gf.compute_interpolate_on(mfe, Sigma, sl)
#sl.export_to_vtk('tripod_ev.vtk', mfu, U, 'Displacement', SigmaSL, 'stress')

#print 'You can view the tripod with (for example) mayavi:'
#print 'mayavi -d ./tripod.vtk -f WarpVector -m BandedSurfaceMap'

# export to Gmsh
sl.export_to_pos('tripod.pos', mfe, VM, 'Von Mises Stress', mfu, U,
                 'Displacement')
sl.export_to_pos('tripod_ev.pos', mfu, U, 'Displacement', SigmaSL, 'stress')
Exemplo n.º 2
0
md.add_macro("thI", "exp(beta*(thetaI-theta0))")
md.add_macro("SI",
             "((laI*Trace(EI)*Id(2)+2*muI*EI)/thI-1.5*(thI-1/thI)*kaI*Id(2))")

# Increase temperature gap
it = 0
for fact in [0, 0.2, 0.4, 0.6, 0.8, 1.]:
    md.set_variable("theta_T", room_temp + fact * jump_temp)
    md.solve("max_res", 5E-8, "max_iter", 100, "noisy")

    U = md.variable("u")
    theta = md.variable("theta")
    T = md.variable("T")
    print("Gas temperature %g C" % (T - 273))
    P = md.variable("P")
    print("Gas pressure %g MPa" % P)

    V = gf.compute_interpolate_on(mf_u, U, mfv)
    Th = gf.compute_interpolate_on(mf_theta, theta, mfw)
    VM = md.interpolation(
        "sqrt(3/2)*Norm(Deviator(Cauchy_stress_from_PK2(SI, graduI)))", mfvm)

    mfv.export_to_pos("cracked_body_%i.pos" % it, V, "V", mfw, Th,
                      "Temperature", mfvm, VM, "Von Mises stress")
    mfv.export_to_vtk("cracked_body_%i.vtk" % it, V, "V", mfw, Th,
                      "Temperature", mfvm, VM, "Von Mises stress")
    it += 1

print("You can view the solution with (for example):")
print("paraview cracked_body_2.vtk")
Exemplo n.º 3
0
    mim_bound2 = gf.MeshIm(
        'levelset', mls, 'boundary(b)',
        gf.Integ('IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),3)'))
    md.add_linear_term\
    (mim_bound2, '1e17*(Xfem_plus(u)-Xfem_minus(u)).(Xfem_plus(Test_u)-Xfem_minus(Test_u))')

# Assembly of the linear system and solve:
md.solve()
U = md.variable('u')

# Interpolation of the solution on a cut mesh for the drawing purpose
cut_mesh = mls.cut_mesh()
mfv = gf.MeshFem(cut_mesh, 2)
mfv.set_classical_discontinuous_fem(2, 0.001)
mf_ue.set_qdim(2)

V = gf.compute_interpolate_on(mf_u, U, mfv)
Ve = gf.compute_interpolate_on(mf_ue, Ue, mfv)

# Computation of the Von Mises stress
mfvm = gf.MeshFem(cut_mesh)
mfvm.set_classical_discontinuous_fem(2, 0.001)
md.add_initialized_fem_data('u_cut', mfv, V)
VM = md.compute_isotropic_linearized_Von_Mises_or_Tresca(
    'u_cut', 'lambda', 'mu', mfvm)

mfv.export_to_pos('crack.pos', V, 'V', Ve, 'Ve', mfvm, VM, 'Von Mises')

print('You can view the solution with (for example):')
print('gmsh crack.pos')
                else:
                    # Load the final step
                    filename = resultspath + ('/mf_%d.mf' % (NT))
                    m = gf.Mesh('load', filename)
                    mf_u = gf.MeshFem('load', filename, m)
                    filename = resultspath + ('/U_%d.dat' % (NT))
                    U = np.loadtxt(filename)

                    # Load the reference solution
                    m_ref = gf.Mesh('load', refname_mf)
                    mf_u_ref = gf.MeshFem('load', refname_mf, m_ref)
                    U_ref = np.loadtxt(refname_U)
                    mim_ref = gf.MeshIm(m_ref, 6)

                    # Estimate of the difference in L2 and H1 norms
                    Ui = gf.compute_interpolate_on(mf_u, U, mf_u_ref)
                    norm_L2 = gf.compute_L2_norm(mf_u_ref, U_ref, mim_ref)
                    err_L2 = gf.compute_L2_dist(mf_u_ref, Ui, mim_ref,
                                                mf_u_ref, U_ref)
                    norm_H1 = gf.compute_H1_semi_norm(mf_u_ref, U_ref, mim_ref)
                    norm_H1 = np.sqrt(pow(norm_L2, 2) + pow(norm_H1, 2))
                    err_H1 = gf.compute_H1_semi_dist(mf_u_ref, Ui, mim_ref,
                                                     mf_u_ref, U_ref)

                print 'Error in L2 norm: %g' % err_L2
                print 'Error in H1 semi-norm: %g' % err_H1
                errors1[option, i, 0] = err_L2 / norm_L2
                errors1[option, i,
                        1] = np.sqrt(pow(err_H1, 2) + pow(err_L2, 2)) / norm_H1

                # Store the result
Exemplo n.º 5
0
    U = md.variable("u")

    """
    subplot(2,1,1);
    gf_plot(mf, U);
    hold on;
    [h1,h2]=gf_plot(mf_ls, get(ls,'values'), 'contour', 0,'pcolor','off');
    set(h2{1},'LineWidth',2);
    set(h2{1},'Color','green');
    colorbar;
    title('u');
    hold off;
    """
    
    # % Solving the adjoint problem.
    UBASIC = gf.compute_interpolate_on(mf, U, mf_basic)
    F = 2*UBASIC
    md.set_variable('VolumicData', F)
    md.solve()
    W = md.variable("u")

    # % Computation of the topological gradient
    mf_g = gf.MeshFem(m, 1)
    mf_g.set_fem(gf.Fem('FEM_PRODUCT(FEM_PK_DISCONTINUOUS(1,2),FEM_PK_DISCONTINUOUS(1,2))'))
    DU = gf.compute(mf, U, 'gradient', mf_g);
    DW = gf.compute(mf, W, 'gradient', mf_g);
    nbdof = mf_g.nbdof()
    DU = np.reshape(DU, [2, nbdof])
    DW = np.reshape(DW, [2, nbdof])
    
    UU = gf.compute_interpolate_on(mf, U, mf_g)