def assemble(self, *args, **kwargs): engine = self._engine() direction = kwargs.pop("direction", 0) self.process_kwargs(engine, kwargs) x = args[0] y = args[1] if len(args)>1 else 0 z = args[2] if len(args)>2 else 0 sdim = self.fes1.GetMesh().SpaceDimension() if direction == 0: if sdim == 3: d = mfem.DeltaCoefficient(x, y, z, 1) elif sdim == 2: d = mfem.DeltaCoefficient(x, y, 1) elif sdim == 1: d = mfem.DeltaCoefficient(x, 1) else: assert False, "unsupported dimension" intg = mfem.DomainLFIntegrator(d) else: dir = mfem.Vector(direction) if sdim == 3: d = mfem.VectorDeltaCoefficient(dir, x, y, z, 1) elif sdim == 2: d = mfem.VectorDeltaCoefficient(dir, x, y, 1) elif sdim == 1: d = mfem.VectorDeltaCoefficient(dir,x, 1) else: assert False, "unsupported dimension" if self.fes1.FEColl().Name().startswith('ND'): intg = mfem.VectorFEDomainLFIntegrator(d) elif self.fes1.FEColl().Name().startswith('RT'): intg = mfem.VectorFEDomainLFIntegrator(d) else: intg = mfem.VectorDomainLFIntegrator(d) lf1 = engine.new_lf(self.fes1) lf1.AddDomainIntegrator(intg) lf1.Assemble() from mfem.common.chypre import LF2PyVec, PyVec2PyMat, MfemVec2PyVec v1 = MfemVec2PyVec(engine.b2B(lf1), None) v1 = PyVec2PyMat(v1) if not self._transpose: v1 = v1.transpose() return v1
def assemble(self, *args, **kwargs): engine = self._engine() direction = kwargs.pop("direction", None) weight = kwargs.pop("weight", 1.0) weight = np.atleast_1d(weight) do_sum = kwargs.pop("sum", False) info1 = engine.get_fes_info(self.fes1) sdim = info1['sdim'] vdim = info1['vdim'] if (info1['element'].startswith('ND') or info1['element'].startswith('RT')): vdim = sdim if vdim > 1: if direction is None: direction = [0]*vdim direction[0] = 1 direction = np.atleast_1d(direction).astype(float, copy=False) direction = direction.reshape(-1, sdim) self.process_kwargs(engine, kwargs) pts = np.array(args[0], copy = False).reshape(-1, sdim) from mfem.common.chypre import LF2PyVec, PyVec2PyMat, MfemVec2PyVec, HStackPyVec vecs = [] for k, pt in enumerate(pts): w = float(weight[0] if len(weight) == 1 else weight[k]) if vdim == 1: if sdim == 3: x, y, z = pt d = mfem.DeltaCoefficient(x, y, z, w) elif sdim == 2: x, y = pt print("DeltaCoefficient call", type(x), type(y), type(x)) d = mfem.DeltaCoefficient(x, y, w) elif sdim == 1: x = pt d = mfem.DeltaCoefficient(x, w) else: assert False, "unsupported dimension" intg = mfem.DomainLFIntegrator(d) else: dir = direction[0] if len(direction) == 1 else direction[k] dd = mfem.Vector(dir) if sdim == 3: x, y, z = pt d = mfem.VectorDeltaCoefficient(dd, x, y, z, w) elif sdim == 2: x, y = pt d = mfem.VectorDeltaCoefficient(dd, x, y, w) elif sdim == 1: x = pt d = mfem.VectorDeltaCoefficient(dd,x, w) else: assert False, "unsupported dimension" if self.fes1.FEColl().Name().startswith('ND'): intg = mfem.VectorFEDomainLFIntegrator(d) elif self.fes1.FEColl().Name().startswith('RT'): intg = mfem.VectorFEDomainLFIntegrator(d) else: intg = mfem.VectorDomainLFIntegrator(d) if do_sum: if k == 0: lf1 = engine.new_lf(self.fes1) lf1.AddDomainIntegrator(intg) else: lf1 = engine.new_lf(self.fes1) lf1.AddDomainIntegrator(intg) lf1.Assemble() vecs.append(LF2PyVec(lf1)) if do_sum: lf1.Assemble() v1 = MfemVec2PyVec(engine.b2B(lf1), None) v1 = PyVec2PyMat(v1) else: v1 = HStackPyVec(vecs) if not self._transpose: v1 = v1.transpose() return v1