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

        g = mfem.Geometry()
        size = len(iverts_f)
        #wverts = np.zeros(size)
        ret = np.zeros((size, self.sdim))
        if ibele is None: return

        ibe = ibele[0]
        el = mesh.GetBdrElement(ibe)
        rule = g.GetVertices(el.GetGeometryType())
        nv = rule.GetNPoints()

        for ibe in ibele:
            T = mesh.GetBdrElementTransformation(ibe)
            bverts = mesh.GetBdrElement(ibe).GetVerticesArray()

            for i in range(nv):
                nor = mfem.Vector(self.sdim)
                T.SetIntPoint(rule.IntPoint(i))
                mfem.CalcOrtho(T.Jacobian(), nor)
                idx = np.searchsorted(iverts_f, bverts[i])

                ret[idx, :] += nor.GetDataArray().copy()
                #wverts[idx] = wverts[idx] + 1

        #for i in range(self.sdim): ret[:,i] /= wvert
        # normalize to length one.
        ret = ret / np.sqrt(np.sum(ret**2, 1)).reshape(-1, 1)

        if self.comp == -1: return ret
        return ret[:, self.comp - 1]
  from nodal values and H1 weight. 

'''
import numpy as np
import parser
import weakref
import six
from petram.mfem_config import use_parallel
if use_parallel:
    import mfem.par as mfem
    from mfem.par import GlobGeometryRefiner as GR    
else:
    import mfem.ser as mfem
    from mfem.ser import GlobGeometryRefiner as GR
    
Geom = mfem.Geometry()

weight = {}

def surface_weight(refine, gtype):
    if (refine, gtype) in globals()['weight']:
        return globals()['weight'][(refine, gtype)]
    
    quad_v = [[0, 0], [1, 0], [1, 1], [0, 3]]
    quad_e = [[0, 1, 2, 3]]
    tri_v =   [[0, 0], [1, 0], [0, 1]]
    tri_e = [[0, 1, 2,]]
    seg_v =   [[0,], [1, ],]
    seg_e = [[0, 1,]]

    if gtype == mfem.Geometry.TRIANGLE: