# converting them to a list of true dofs. ess_tdof_list = intArray(); if mesh.bdr_attributes.Size(): ess_bdr = intArray(mesh.bdr_attributes.Max()) ess_bdr = intArray([1]*mesh.bdr_attributes.Max()) fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list); # 6. Set up the linear form b(.) which corresponds to the right-hand side # of the FEM linear system, which in this case is (f,phi_i) where f is # given by the function f_exact and phi_i are the basis functions in the # finite element fespace. b = mfem.LinearForm(fespace); f = f_exact() dd = mfem.VectorFEDomainLFIntegrator(f); b.AddDomainIntegrator(dd) b.Assemble(); # 7. Define the solution vector x as a finite element grid function # corresponding to fespace. Initialize x by projecting the exact # solution. Note that only values from the boundary edges will be used # when eliminating the non-homogeneous boundary condition to modify the # r.h.s. vector b. #from mfem.examples.ex3 import E_exact_cb x = mfem.GridFunction(fespace) E = E_exact() x.ProjectCoefficient(E); # 8. Set up the bilinear form corresponding to the EM diffusion operator
block_offsets.PartialSum() k = mfem.ConstantCoefficient(1.0) fcoeff = fFunc(dim) fnatcoeff = f_natural() gcoeff = gFunc() ucoeff = uFunc_ex(dim) pcoeff = pFunc_ex() x = mfem.BlockVector(block_offsets) rhs = mfem.BlockVector(block_offsets) fform = mfem.LinearForm() fform.Update(R_space, rhs.GetBlock(0), 0) fform.AddDomainIntegrator(mfem.VectorFEDomainLFIntegrator(fcoeff)) fform.AddBoundaryIntegrator(mfem.VectorFEBoundaryFluxLFIntegrator(fnatcoeff)) fform.Assemble() gform = mfem.LinearForm() gform.Update(W_space, rhs.GetBlock(1), 0) gform.AddDomainIntegrator(mfem.DomainLFIntegrator(gcoeff)) gform.Assemble() mVarf = mfem.BilinearForm(R_space) bVarf = mfem.MixedBilinearForm(R_space, W_space) mVarf.AddDomainIntegrator(mfem.VectorFEMassIntegrator(k)) mVarf.Assemble() mVarf.Finalize() M = mVarf.SpMat()