# 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 np.savetxt(resname, errors1.reshape(errors1.size))
E = (np.vdot(MMV0, V0) + np.vdot(KU0, U0)) * 0.5 E_org = E if (version == 2): # Energy stored in the penalized contact E += (gamma0_P / h) * pow(min(0., U0[0]), 2) / 2 if (version == 3): # Nitsche Energy E += (0.5 * theta_N) * (h / gamma0_N) * (s0 * s0 - ux * ux) # Store the data to be ploted at the end store_u0[nit] = U0[0] store_u0_ex[nit] = uExact(0., t) store_v0[nit] = V0[0] store_v0_ex[nit] = uExact(0., t, 2) store_s0[nit] = s0 store_s0_ex[nit] = uExact(0., t, 1) store_E[nit] = E store_VL2_ex[nit] = gf.compute_L2_norm(mfu, Vex, mim) store_UL2_ex[nit] = gf.compute_L2_norm(mfu, Uex, mim) store_UH1_ex[nit] = gf.compute_H1_norm(mfu, Uex, mim) store_VL2[nit] = gf.compute_L2_norm(mfu, V0 - Vex, mim) store_UL2[nit] = gf.compute_L2_norm(mfu, U0 - Uex, mim) store_UH1[nit] = gf.compute_H1_norm(mfu, U0 - Uex, mim) # Draw the approximated and exact solutions if (t >= tplot - (1e-10)): tplot += dtplot print(("Time %3f" % t), "/", T, end=' ') print((" Energy %7f" % E), (" Mech energy %7f" % E_org)) if (do_inter_plot): UUex = np.copy(Xdraw) plt.figure(1)
curl_testb_curl_b_exp = '({L}).({M})'.format(L=CURL_VAR_.format(var='Test_b'), M=CURL_VAR_.format(var='b')) cross_jump_a = JUMP_VPRODUCT_VAR_.format(var='a') cross_jump_test_a = JUMP_VPRODUCT_VAR_.format(var='Test_a') jump_a = JUMP_VVAR_N_.format(v='a') jump_test_a = JUMP_VVAR_N_.format(v='Test_a') #magentec potential model mdmag = gf.Model('real') ###################################################################################################################### #Interpolate and export exact fields intonme = mfb CurlBexact = mdmag.interpolation(CurlBexact_exp, intonme) intonme.export_to_vtk('curl_exact3d.vtk', 'ascii', CurlBexact) print('exact curl B norm l2', gf.compute_L2_norm(intonme, CurlBexact, mim)) Bexact = mdmag.interpolation(Bexact_exp, intonme) intonme.export_to_vtk('field_exact3d.vtk', 'ascii', Bexact) print('exact B norm l2', gf.compute_L2_norm(intonme, Bexact, mim)) #Interpolate and export exact fields END ###################################################################################################################### WITH_B_CROSS_N = True # Main potential unknown mdmag.add_fem_variable('b', mfb) # lagrange augmentation unknown for potential mdmag.add_fem_variable('p', mfdiv_mult) tm = time.time() # building (curl b, curl \tau) term