def error_majorant_distribution_nd(mesh, dim, ed_var, md_var, mf_var, V_exact): cell_num = mesh.num_cells() ed_distr = allocate_array_1d(cell_num) md_distr = allocate_array_1d(cell_num) maj_distr = allocate_array_1d(cell_num) md = project(md_var, V_exact) mf = project(mf_var, V_exact) ed = project(ed_var, V_exact) scheme_order = 4 gauss = integrators.SpaceIntegrator(scheme_order, dim) for c in cells(mesh): # Obtaining the coordinates of the vertices in the cell verts = c.get_vertex_coordinates().reshape(dim + 1, dim) x_n_transpose = verts.T # Calculating the area of the cell matrix = postprocess.allocate_array_2d(dim + 1, dim + 1) matrix[0:dim, 0:dim + 1] = x_n_transpose matrix[dim, 0:dim + 1] = numpy.array([1.0 for i in range(dim + 1)]) meas = float(1.0 / math.factorial(dim)) * abs(numpy.linalg.det(matrix)) ed_distr[c.index()] = gauss.integrate(ed, meas, x_n_transpose) md_distr[c.index()] = gauss.integrate(md, meas, x_n_transpose) maj_distr[c.index()] = gauss.integrate(mf, meas, x_n_transpose) print "ed_distr int total = %8.2e" % numpy.sum(ed_distr) print "md_distr int total = %8.2e" % numpy.sum(md_distr) print "maj_distr int total = %8.2e\n" % numpy.sum(maj_distr) return ed_distr, md_distr, maj_distr, ed, md, mf
def error_majorant_distribution_nd(mesh, domain, dim, u_e, grad_u_e, u, V_exact, y, f, lmbd, beta): cell_num = mesh.num_cells() #e_distr = postprocess.allocate_array(cell_num) #m_distr = postprocess.allocate_array(cell_num) ed_distr = postprocess.allocate_array(cell_num) md_distr = postprocess.allocate_array(cell_num) # Define error and residuals r_d = abs(Grad(u, dim) - y) r_f = abs(f + Div(y, dim) - lmbd * u) #C_FD = calculate_CF_of_domain(domain, dim) u_ve = interpolate(u, V_exact) u_exact_ve = interpolate(u_e, V_exact) e = u_ve - u_exact_ve #w_opt = (C_FD ** 2) * (1 + beta) / (beta + (C_FD ** 2) * (1 + beta) * lmbd) # Project UFL forms on the high-order functional space to obtain functions #ed = project(sqrt(inner(Grad(e, dim), Grad(e, dim))), V_exact) #md = project(sqrt(inner(r_d, r_d)), V_exact) ed = project(inner(Grad(e, dim), Grad(e, dim)), V_exact) md = project(inner(r_d, r_d), V_exact) #ed_test = assemble(sqrt(inner(Grad(e, dim), Grad(e, dim))) * dx) #md_test = assemble(sqrt(inner(r_d, r_d)) * dx) #e = project(sqrt(inner(Grad(e, dim), Grad(e, dim)) + lmbd * inner(e, e)), V_exact) #m = project(sqrt((1 + beta) * inner(r_d, r_d) + w_opt * inner(r_f, r_f)), V_exact) dofmap = V_exact.dofmap() scheme_order = 4 gauss = integration.SpaceIntegrator(scheme_order, dim) for c in cells(mesh): verts = dofmap.tabulate_coordinates(c) x_n = verts[0:dim + 1, :] x_n_transpose = x_n.transpose() matrix = postprocess.allocate_array_2d(dim + 1, dim + 1) matrix[0:dim, 0:dim + 1] = x_n_transpose matrix[dim, 0:dim + 1] = numpy.array([1.0 for i in range(dim + 1)]) meas = abs(numpy.linalg.det(matrix)) ed_distr[c.index()] = gauss.integrate(ed, meas, x_n_transpose) md_distr[c.index()] = gauss.integrate(md, meas, x_n_transpose) #e_distr[c.index()] = gauss.integrate(e, meas, x_n_transpose) #m_distr[c.index()] = gauss.integrate(m, meas, x_n_transpose) print 'sum of m_cells', numpy.sum(md_distr) print 'sum of e_cells', numpy.sum(ed_distr) return ed_distr, md_distr
def error_majorant_distribution_nd(mesh, dim, V_exact, var_grad_e, var_delta_e, var_m_d, var_m_f_w_opt, beta, C_FD): cell_num = mesh.num_cells() ed_distr = postprocess.allocate_array(cell_num) delta_e_distr = postprocess.allocate_array(cell_num) md_distr = postprocess.allocate_array(cell_num) maj_distr = postprocess.allocate_array(cell_num) # Project UFL forms on the high-order functional space to obtain functions ed = project((var_grad_e), V_exact) delta_e = project(var_delta_e, V_exact) md = project((var_m_d), V_exact) mf_wopt = project(var_m_f_w_opt, V_exact) scheme_order = 4 gauss = integration.SpaceIntegrator(scheme_order, dim) for c in cells(mesh): # Obtaining the coordinates of the vertices in the cell verts = c.get_vertex_coordinates().reshape(dim + 1, dim) x_n_transpose = verts.T # Calculating the area of the cell matrix = postprocess.allocate_array_2d(dim + 1, dim + 1) matrix[0:dim, 0:dim + 1] = x_n_transpose matrix[dim, 0:dim + 1] = numpy.array([1.0 for i in range(dim + 1)]) # print "matrix = ", matrix meas = abs(numpy.linalg.det(matrix)) # Integrating over the cell ed_distr[c.index()] = gauss.integrate(ed, meas, x_n_transpose) delta_e_distr[c.index()] = gauss.integrate(delta_e, meas, x_n_transpose) md_distr[c.index()] = gauss.integrate(md, meas, x_n_transpose) #maj_distr[c.index()] = gauss.integrate(mdf, meas, x_n_transpose) #print 'num md_cells', md_distr #print 'ed_cells', ed_distr #print 'delta_e_cells', delta_e_distr #print 'maj_cells', maj_distr #print 'e_cells', e_distr print '\nmd = Sum_K md_K = %8.2e' % sum(md_distr) print 'ed = Sum_K ed_K = %8.2e' % sum(ed_distr) return ed_distr, md_distr, maj_distr
def error_majorant_distribution_nd(mesh, dim, V_exact, var_grad_e, var_delta_e, var_m_d, var_m_f_w_opt, beta): # Allocate arrays for error and majorant distributions cell_num = mesh.num_cells() ed_distr = postprocess.allocate_array(cell_num) delta_e_distr = postprocess.allocate_array(cell_num) md_distr = postprocess.allocate_array(cell_num) mf_distr = postprocess.allocate_array(cell_num) # Project UFL forms on the high-order functional space to obtain functions ed = project(var_grad_e, V_exact) delta_e = project(var_delta_e, V_exact) md = project(var_m_d, V_exact) mf_wopt = project(var_m_f_w_opt, V_exact) # Obtained the mapping #dofmap = V_exact #mesh_coordimates = dofmap. # Define integration scheme order and assign the integrator scheme_order = 4 gauss = integration.SpaceIntegrator(scheme_order, dim) # Iterate over cells of the mesh and obtain local value of the majorant for c in cells(mesh): # Obtaining the coordinates of the vertices in the cell verts = c.get_vertex_coordinates().reshape(dim + 1, dim) x_n_transpose = verts.T # Calculating the area of the cell matrix = postprocess.allocate_array_2d(dim + 1, dim + 1) matrix[0:dim, 0:dim + 1] = x_n_transpose matrix[dim, 0:dim + 1] = numpy.array([1.0 for i in range(dim + 1)]) #print "matrix = ", matrix meas = abs(numpy.linalg.det(matrix)) # Integrating over the cell ed_distr[c.index()] = gauss.integrate(ed, meas, x_n_transpose) delta_e_distr[c.index()] = gauss.integrate(delta_e, meas, x_n_transpose) md_distr[c.index()] = gauss.integrate(md, meas, x_n_transpose) mf_distr[c.index()] = gauss.integrate(mf_wopt, meas, x_n_transpose) # Calculate majorant based on the parameter value if sum(mf_distr) <= DOLFIN_EPS: maj_distr = md_distr else: if sum(md_distr) <= DOLFIN_EPS: maj_distr = mf_distr else: maj_distr = ( 1.0 + beta ) * md_distr + mf_distr # here (1 + 1/beta) weight is ommited since it is included into the optimal mf_wopt e_distr = ed_distr + delta_e_distr #print 'md_cells', md_distr #print 'ed_cells', ed_distr print 'sum md_cells', sum(md_distr) print 'sum maj_cells', sum(maj_distr) print 'sum e_cells', sum(e_distr) return ed_distr, delta_e_distr, e_distr, md_distr, mf_distr, maj_distr, ed, md