def prepare_rhs(A, w, coeff_field, pde): b = 0 * w zero = Multiindex() b[zero].coeffs = pde.assemble_rhs(basis=b[zero].basis, coeff=coeff_field.mean_func, withNeumannBC=True) f = pde.f if f.value_rank() == 0: zero_func = Constant(0.0) else: zero_func = Constant((0.0,) * f.value_size()) zero_func = zero_function(b[zero].basis._fefs) for m in range(w.max_order): eps_m = zero.inc(m) am_f, am_rv = coeff_field[m] beta = am_rv.orth_polys.get_beta(0) if eps_m in b.active_indices(): g0 = b[eps_m].copy() g0.coeffs = pde.assemble_rhs(basis=b[eps_m].basis, coeff=am_f, withNeumannBC=False, f=zero_func) # this equates to homogeneous Neumann bc pde.set_dirichlet_bc_entries(g0, homogeneous=True) b[eps_m] += beta[1] * g0 g0 = b[zero].copy() g0.coeffs = pde.assemble_rhs(basis=b[zero].basis, coeff=am_f, f=zero_func) pde.set_dirichlet_bc_entries(g0, homogeneous=True) b[zero] += beta[0] * g0 return b
# PART A: Simulation Options # ============================================================ # initial mesh elements initial_mesh_N = CONF_initial_mesh_N # plotting flag PLOT_SOLUTION = False # ============================================================ # PART B: Problem Setup # ============================================================ # define initial multiindices mis = list(Multiindex.createCompleteOrderSet(CONF_initial_Lambda, 1)) #mis = list(Multiindex.createCompleteOrderSet(0, 1)) #mis = [mis[0], mis[2]] #mis = [mis[0]] print "MIS", mis # setup domain and meshes mesh0, boundaries, dim = SampleDomain.setupDomain(CONF_domain, initial_mesh_N=initial_mesh_N) if RANDOM_MESHES: meshes = SampleProblem.setupMeshes(mesh0, len(mis), num_refine=10, randref=(0.5, 0.4)) else: meshes = SampleProblem.setupMeshes(mesh0, len(mis), num_refine=0) # define coefficient field # NOTE: for proper treatment of corner points, see elasticity_residual_estimator coeff_types = ("EF-square-cos", "EF-square-sin", "monomials", "constant")
domain = "square" # initial mesh elements initial_mesh_N = 5 * 8 # decay exponent decay_exp = 2 # ============================================================ # PART B: Problem Setup # ============================================================ # define initial multiindices mis = list(Multiindex.createCompleteOrderSet(1, 1)) # mis = list(Multiindex.createCompleteOrderSet(0, 1)) # print mis # os.sys.exit() # setup meshes mesh0 = UnitInterval(initial_mesh_N) meshes = SampleProblem.setupMeshes(mesh0, len(mis), num_refine=0) w = SampleProblem.setupMultiVector(dict([(mu, m) for mu, m in zip(mis, meshes)]), setup_vec) # define coefficient field rvs = lambda i: UniformRV(a=-1, b=1) a0 = Constant(1.0) a = lambda i: Expression("B", B=1.0 / (4.0 + i * i)) coeff_field = ParametricCoefficientField(a0, a, rvs)