示例#1
0
    def nodal_values(self, iele=None, el2v=None, wverts=None, **kwargs):
        # iele = None, elattr = None, el2v = None,
        # wverts = None, locs = None, g = None

        if iele is None: return
        if not self.isDerived: self.set_funcs()

        size = len(wverts)

        ans = []
        for comp in range(self.dim):
            if self.gfi is None:
                ret = np.zeros(size, dtype=np.float)
            else:
                ret = np.zeros(size, dtype=np.complex)
            for kk, m in zip(iele, el2v):
                if kk < 0: continue
                values = mfem.doubleArray()
                self.gfr.GetNodalValues(kk, values, comp + 1)
                for k, idx in m:
                    ret[idx] = ret[idx] + values[k]
                if self.gfi is not None:
                    arr = mfem.doubleArray()
                    self.gfi.GetNodalValues(kk, arr, comp + 1)
                    for k, idx in m:
                        ret[idx] = ret[idx] + arr[k] * 1j
            ans.append(ret / wverts)
        ret = np.transpose(np.vstack(ans))
        return ret
示例#2
0
    def nodal_values(self, iele=None, el2v=None, wverts=None, **kwargs):
        if iele is None: return
        if not self.isDerived: self.set_funcs()

        size = len(wverts)
        if self.gfi is None:
            ret = np.zeros(size, dtype=np.float)
        else:
            ret = np.zeros(size, dtype=np.complex)
        for kk, m in zip(iele, el2v):
            if kk < 0: continue
            values = mfem.doubleArray()
            self.gfr.GetNodalValues(kk, values, self.comp)

            for k, idx in m:
                ret[idx] = ret[idx] + values[k]
            if self.gfi is not None:
                arr = mfem.doubleArray()
                self.gfi.GetNodalValues(kk, arr, self.comp)
                for k, idx in m:
                    ret[idx] = ret[idx] + arr[k] * 1j
        ret = ret / wverts
        return ret
示例#3
0
else:
    amg.SetSystemsOptions(dim)

lobpcg = mfem.HypreLOBPCG(MPI.COMM_WORLD)
lobpcg.SetPreconditioner(amg)
lobpcg.SetMaxIter(100)
lobpcg.SetTol(1e-8)
lobpcg.SetPrecondUsageMode(1)
lobpcg.SetPrintLevel(1)
lobpcg.SetMassMatrix(M)
lobpcg.SetOperator(A)

# 10. Compute the eigenmodes and extract the array of eigenvalues. Define a
#     parallel grid function to represent each of the eigenmodes returned by
#     the solver.
eigenvalues = mfem.doubleArray()
lobpcg.Solve()
lobpcg.GetEigenvalues(eigenvalues)
x = mfem.ParGridFunction(fespace)

# 11. For non-NURBS meshes, make the mesh curved based on the finite element
#     space. This means that we define the mesh elements through a fespace
#     based transformation of the reference element. This allows us to save
#     the displaced mesh as a curved mesh when using high-order finite
#     element displacement field. We assume that the initial mesh (read from
#     the file) is not higher order curved mesh compared to the chosen FE
#     space.
if not use_nodal_fespace:
    pmesh.SetNodalFESpace(fespace)

# 12. Save the refined mesh and the modes in parallel. This output can be
示例#4
0
M = m.ParallelAssemble()

ams = mfem.HypreAMS(A, fespace)
ams.SetPrintLevel(0)
ams.SetSingularProblem()

ame = mfem.HypreAME(MPI.COMM_WORLD)
ame.SetNumModes(nev)
ame.SetPreconditioner(ams)
ame.SetMaxIter(100)
ame.SetTol(1e-8)
ame.SetPrintLevel(1)
ame.SetMassMatrix(M)
ame.SetOperator(A)

eigenvalues = doubleArray()
ame.Solve()
ame.GetEigenvalues(eigenvalues)
x = mfem.ParGridFunction(fespace)

smyid = '{:0>6d}'.format(myid)
mesh_name = "ex13_mesh." + smyid

pmesh.PrintToFile(mesh_name, 8)

for i in range(nev):
    sol_name = "ex13_mode_" + str(i) + "." + smyid
    x.Assign(ame.GetEigenvector(i))
    x.SaveToFile(sol_name, 8)

eigenvalues.Print()