Exemple #1
0
 def __init__(self, dim):
     num_equation = globals()['num_equation']
     self.flux = mfem.DenseMatrix(num_equation, dim)
     self.shape = mfem.Vector()
     self.dshapedr = mfem.DenseMatrix()
     self.dshapedx = mfem.DenseMatrix()
     super(DomainIntegrator, self).__init__()
Exemple #2
0
    def Mult(self, x, y):
        globals()['max_char_speed'] = 0.;
        num_equation = globals()['num_equation']
        # 1. Create the vector z with the face terms -<F.n(u), [w]>.
        self.A.Mult(x, self.z);

        # 2. Add the element terms.
        # i.  computing the flux approximately as a grid function by interpolating
        #     at the solution nodes.
        # ii. multiplying this grid function by a (constant) mixed bilinear form for
        #     each of the num_equation, computing (F(u), grad(w)) for each equation.

        xmat = mfem.DenseMatrix(x.GetData(), self.vfes.GetNDofs(), num_equation)
        self.GetFlux(xmat, self.flux)

        for k in range(num_equation):
           fk = mfem.Vector(self.flux[k].GetData(), self.dim * self.vfes.GetNDofs())
           o = k * self.vfes.GetNDofs()
           zk = self.z[o: o+self.vfes.GetNDofs()]
           self.Aflux.AddMult(fk, zk)

        # 3. Multiply element-wise by the inverse mass matrices.
        zval = mfem.Vector()
        vdofs = mfem.intArray()
        dof = self.vfes.GetFE(0).GetDof()
        zmat = mfem.DenseMatrix()
        ymat = mfem.DenseMatrix(dof, num_equation)        

        for i in range(self.vfes.GetNE()):
            # Return the vdofs ordered byNODES
            vdofs = mfem.intArray(self.vfes.GetElementVDofs(i))
            self.z.GetSubVector(vdofs, zval)
            zmat.UseExternalData(zval.GetData(), dof, num_equation)
            mfem.Mult(self.Me_inv[i], zmat, ymat);
            y.SetSubVector(vdofs, ymat.GetData())
Exemple #3
0
 def __init__(self, lambda_, mu_, si=0, sj=0):
     super(StressCoefficient, self).__init__(0)
     self.lam = lambda_   # coefficient
     self.mu  = mu_       # coefficient
     self.si  = si ; self.sj = sj     # component
     self.u  = None   # displacement GridFunction
     self.grad = mfem.DenseMatrix()
Exemple #4
0
    def __init__(self, vfes, A, A_flux):
        self.dim = vfes.GetFE(0).GetDim()
        self.vfes = vfes
        self.A = A
        self.Aflux = A_flux
        self.Me_inv = mfem.DenseTensor(vfes.GetFE(0).GetDof(),
                                       vfes.GetFE(0).GetDof(),
                                       vfes.GetNE())

        self.state = mfem.Vector(num_equation)
        self.f = mfem.DenseMatrix(num_equation, self.dim)
        self.flux = mfem.DenseTensor(vfes.GetNDofs(), self.dim, num_equation)
        self.z = mfem.Vector(A.Height())
        
        dof = vfes.GetFE(0).GetDof()
        Me = mfem.DenseMatrix(dof)
        inv = mfem.DenseMatrixInverse(Me)
        mi = mfem.MassIntegrator()
        for i in range(vfes.GetNE()):
            mi.AssembleElementMatrix(vfes.GetFE(i), vfes.GetElementTransformation(i), Me)
            inv.Factor()
            inv.GetInverseMatrix(self.Me_inv(i))
        super(FE_Evolution, self).__init__(A.Height())            
Exemple #5
0
def make_mask(values, X, Y, Z, mask_start=0, logfile=None):
    '''
    mask for interpolation
    '''
    mask = np.zeros(len(X.flatten()), dtype=int) - 1

    for kk, data in enumerate(values):
        ptx, ret, gfr = data

        xmax = np.max(ptx[:, 0])
        xmin = np.min(ptx[:, 0])
        ymax = np.max(ptx[:, 1])
        ymin = np.min(ptx[:, 1])
        zmax = np.max(ptx[:, 2])
        zmin = np.min(ptx[:, 2])

        i1 = np.logical_and(xmax >= X.flatten(), xmin <= X.flatten())
        i2 = np.logical_and(ymax >= Y.flatten(), ymin <= Y.flatten())
        i3 = np.logical_and(zmax >= Z.flatten(), zmin <= Z.flatten())
        ii = np.logical_and(np.logical_and(i1, i2), i3)

        mesh = gfr.FESpace().GetMesh()

        XX = X.flatten()[ii]
        YY = Y.flatten()[ii]
        ZZ = Z.flatten()[ii]
        size = len(XX)

        m = mfem.DenseMatrix(3, size)
        ptx = np.vstack([XX, YY, ZZ])

        if logfile is not None:
            txt = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
            logfile.write(txt + "\n")
            logfile.write("calling FindPoints : size = " + str(XX.shape) +
                          " " + str(kk + 1) + '/' + str(len(values)) + "\n")

        m.Assign(ptx)
        ips = mfem.IntegrationPointArray()
        elem_ids = mfem.intArray()

        pts_found = mesh.FindPoints(m, elem_ids, ips)

        ii = np.where(ii)[0][np.array(elem_ids.ToList()) != -1]
        mask[ii] = kk + mask_start
        if logfile is not None:
            logfile.write("done\n")

    return mask
Exemple #6
0
    def AssembleFaceVector(self, el1, el2, Tr, elfun, elvect):
        num_equation = globals()['num_equation']
        # Compute the term <F.n(u),[w]> on the interior faces.
        dof1 = el1.GetDof()
        dof2 = el2.GetDof()

        self.shape1.SetSize(dof1)
        self.shape2.SetSize(dof2)

        elvect.SetSize((dof1 + dof2) * num_equation)
        elvect.Assign(0.0)

        elfun1_mat = mfem.DenseMatrix(elfun.GetData(), dof1, num_equation)
        elfun2_mat = mfem.DenseMatrix(elfun[dof1 * num_equation:].GetData(),
                                      dof2, num_equation)

        elvect1_mat = mfem.DenseMatrix(elvect.GetData(), dof1, num_equation)
        elvect2_mat = mfem.DenseMatrix(elvect[dof1 * num_equation:].GetData(),
                                       dof2, num_equation)

        # Integration order calculation from DGTraceIntegrator
        if (Tr.Elem2No >= 0):
            intorder = (min(Tr.Elem1.OrderW(), Tr.Elem2.OrderW()) +
                        2 * max(el1.GetOrder(), el2.GetOrder()))
        else:
            intorder = Tr.Elem1.OrderW() + 2 * el1.GetOrder()

        if (el1.Space() == mfem.FunctionSpace().Pk):
            intorder += 1

        ir = mfem.IntRules.Get(Tr.FaceGeom, intorder)
        for i in range(ir.GetNPoints()):
            ip = ir.IntPoint(i)
            Tr.Loc1.Transform(ip, self.eip1)
            Tr.Loc2.Transform(ip, self.eip2)

            # Calculate basis functions on both elements at the face
            el1.CalcShape(self.eip1, self.shape1)
            el2.CalcShape(self.eip2, self.shape2)

            # Interpolate elfun at the point
            elfun1_mat.MultTranspose(self.shape1, self.funval1)
            elfun2_mat.MultTranspose(self.shape2, self.funval2)
            Tr.Face.SetIntPoint(ip)

            # Get the normal vector and the flux on the face

            mfem.CalcOrtho(Tr.Face.Jacobian(), self.nor)

            mcs = self.rsolver.Eval(self.funval1, self.funval2, self.nor,
                                    self.fluxN)

            # Update max char speed
            if mcs > globals()['max_char_speed']:
                globals()['max_char_speed'] = mcs

            self.fluxN *= ip.weight

            #
            fluxN = np.atleast_2d(self.fluxN.GetDataArray())
            shape1 = np.atleast_2d(self.shape1.GetDataArray())
            shape2 = np.atleast_2d(self.shape2.GetDataArray())
            mat1 = elvect1_mat.GetDataArray()
            mat2 = elvect2_mat.GetDataArray()
            mat1 -= shape1.transpose().dot(fluxN)
            mat2 += shape2.transpose().dot(fluxN)
            '''
Exemple #7
0
 def __init__(self, model, x):
     self.x = x
     self.model = model
     self.J = mfem.DenseMatrix()
     mfem.PyCoefficient.__init__(self)