fform.Update(R_space, rhs.GetBlock(0), 0) fform.AddDomainIntegrator(mfem.VectorFEDomainLFIntegrator(fcoeff)) fform.AddBoundaryIntegrator(mfem.VectorFEBoundaryFluxLFIntegrator(fnatcoeff)) fform.Assemble() fform.ParallelAssemble(trueRhs.GetBlock(0)) gform = mfem.ParLinearForm() gform.Update(W_space, rhs.GetBlock(1), 0) gform.AddDomainIntegrator(mfem.DomainLFIntegrator(gcoeff)) gform.Assemble() gform.ParallelAssemble(trueRhs.GetBlock(1)) mVarf = mfem.ParBilinearForm(R_space) bVarf = mfem.ParMixedBilinearForm(R_space, W_space) mVarf.AddDomainIntegrator(mfem.VectorFEMassIntegrator(k)) mVarf.Assemble() mVarf.Finalize() M = mVarf.ParallelAssemble() bVarf.AddDomainIntegrator(mfem.VectorFEDivergenceIntegrator()) bVarf.Assemble() bVarf.Finalize() B = bVarf.ParallelAssemble() B *= -1 BT = B.Transpose() darcyOp = mfem.BlockOperator(block_trueOffsets) darcyOp.SetBlock(0, 0, M) darcyOp.SetBlock(0, 1, BT) darcyOp.SetBlock(1, 0, B)
if (myid == 0): print("Number of unknowns: " + str(size)) one = mfem.ConstantCoefficient(1.0) ess_bdr = intArray() if (pmesh.bdr_attributes.Size() > 0): ess_bdr.SetSize(pmesh.bdr_attributes.Max()) ess_bdr.Assign(1) a = mfem.ParBilinearForm(fespace) a.AddDomainIntegrator(mfem.CurlCurlIntegrator(one)) if (pmesh.bdr_attributes.Size() == 0): # Add a mass term if the mesh has no boundary, e.g. periodic mesh or # closed surface. a.AddDomainIntegrator(mfem.VectorFEMassIntegrator(one)) a.Assemble() a.EliminateEssentialBCDiag(ess_bdr, 1.0) a.Finalize() m = mfem.ParBilinearForm(fespace) m.AddDomainIntegrator(mfem.VectorFEMassIntegrator(one)) m.Assemble() # shift the eigenvalue corresponding to eliminated dofs to a large value m.EliminateEssentialBCDiag(ess_bdr, 2.3e-308) m.Finalize() A = a.ParallelAssemble() M = m.ParallelAssemble()
def run_test(): #meshfile = expanduser(join(mfem_path, 'data', 'semi_circle.mesh')) mesh = mfem.Mesh(3, 3, 3, "TETRAHEDRON") mesh.ReorientTetMesh() order = 1 dim = mesh.Dimension() sdim = mesh.SpaceDimension() fec1 = mfem.H1_FECollection(order, dim) fespace1 = mfem.FiniteElementSpace(mesh, fec1, 1) fec2 = mfem.ND_FECollection(order, dim) fespace2 = mfem.FiniteElementSpace(mesh, fec2, 1) print("Element order :", order) print('Number of H1 finite element unknowns: ' + str(fespace1.GetTrueVSize())) print('Number of ND finite element unknowns: ' + str(fespace2.GetTrueVSize())) print("Checking scalar") gf = mfem.GridFunction(fespace1) c1 = mfem.NumbaFunction(s_func, sdim).GenerateCoefficient() c2 = s_coeff() gf.Assign(0.0) start = time.time() gf.ProjectCoefficient(c1) end = time.time() data1 = gf.GetDataArray().copy() print("Numba time (scalar)", end - start) gf.Assign(0.0) start = time.time() gf.ProjectCoefficient(c2) end = time.time() data2 = gf.GetDataArray().copy() print("Python time (scalar)", end - start) check(data1, data2, "scalar coefficient does not agree with original") print("Checking vector") gf = mfem.GridFunction(fespace2) c3 = mfem.VectorNumbaFunction(v_func, sdim, dim).GenerateCoefficient() c4 = v_coeff(dim) gf.Assign(0.0) start = time.time() gf.ProjectCoefficient(c3) end = time.time() data1 = gf.GetDataArray().copy() print("Numba time (vector)", end - start) gf.Assign(0.0) start = time.time() gf.ProjectCoefficient(c4) end = time.time() data2 = gf.GetDataArray().copy() print("Python time (vector)", end - start) check(data1, data2, "vector coefficient does not agree with original") print("Checking matrix") a1 = mfem.BilinearForm(fespace2) a2 = mfem.BilinearForm(fespace2) c4 = mfem.MatrixNumbaFunction(m_func, sdim, dim).GenerateCoefficient() c5 = m_coeff(dim) a1.AddDomainIntegrator(mfem.VectorFEMassIntegrator(c4)) a2.AddDomainIntegrator(mfem.VectorFEMassIntegrator(c5)) start = time.time() a1.Assemble() end = time.time() a1.Finalize() M1 = a1.SpMat() print("Numba time (matrix)", end - start) start = time.time() a2.Assemble() end = time.time() a2.Finalize() M2 = a2.SpMat() print("Python time (matrix)", end - start) #from mfem.commmon.sparse_utils import sparsemat_to_scipycsr #csr1 = sparsemat_to_scipycsr(M1, float) #csr2 = sparsemat_to_scipycsr(M2, float) check(M1.GetDataArray(), M2.GetDataArray(), "matrix coefficient does not agree with original") check(M1.GetIArray(), M2.GetIArray(), "matrix coefficient does not agree with original") check(M1.GetJArray(), M2.GetJArray(), "matrix coefficient does not agree with original") print("PASSED")
# solution. Note that only values from the boundary faces will be used # when eliminating the non-homogeneous boundary condition to modify the # r.h.s. vector b. x = mfem.ParGridFunction(fespace) F = E_exact(sdim) x.ProjectCoefficient(F) # 10. Set up the parallel bilinear form corresponding to the H(div) # diffusion operator grad alpha div + beta I, by adding the div-div and # the mass domain integrators. alpha = mfem.ConstantCoefficient(1.0) beta = mfem.ConstantCoefficient(1.0) a = mfem.ParBilinearForm(fespace) a.AddDomainIntegrator(mfem.DivDivIntegrator(alpha)) a.AddDomainIntegrator(mfem.VectorFEMassIntegrator(beta)) # 11. Assemble the parallel bilinear form and the corresponding linear # system, applying any necessary transformations such as: parallel # assembly, eliminating boundary conditions, applying conforming # constraints for non-conforming AMR, static condensation, # hybridization, etc. if (static_cond): a.EnableStaticCondensation() elif (hybridization): hfec = mfem.DG_Interface_FECollection(order - 1, dim) hfes = mfem.ParFiniteElementSpace(mesh, hfec) a.EnableHybridization(hfes, mfem.NormalTraceJumpIntegrator(), ess_tdof_list) a.Assemble() A = mfem.HypreParMatrix()
# when eliminating the non-homogeneous boundary condition to modify the # r.h.s. vector b. x = mfem.ParGridFunction(fespace) E = E_exact() x.ProjectCoefficient(E) # 10. Set up the bilinear form corresponding to the EM diffusion operator # curl muinv curl + sigma I, by adding the curl-curl and the mass domain # integrators. muinv = mfem.ConstantCoefficient(1.0) sigma = mfem.ConstantCoefficient(1.0) a = mfem.ParBilinearForm(fespace) a.AddDomainIntegrator(mfem.CurlCurlIntegrator(muinv)) a.AddDomainIntegrator(mfem.VectorFEMassIntegrator(sigma)) # 11. Assemble the bilinear form and the corresponding linear system, # applying any necessary transformations such as: eliminating boundary # conditions, applying conforming constraints for non-conforming AMR, # static condensation, etc. if (static_cond): a.EnableStaticCondensation() a.Assemble() A = mfem.HypreParMatrix() B = mfem.Vector() X = mfem.Vector() a.FormLinearSystem(ess_tdof_list, x, b, A, X, B) if verbose: print("Size of linear system: " + str(A.GetGlobalNumRows()))