Пример #1
0
    def assemble(self, *args, **kwargs):
        engine = self._engine()        
        self.process_kwargs(engine, kwargs)
        
        if len(args)>0: self._sel_mode = args[0]
        if len(args)>1: self._sel = args[1]

        if not self.fes1.FEColl().Name().startswith('L2'):
           assert False, "range should be L2"           
        if not self.fes2.FEColl().Name().startswith('RT'):
           assert False, "domain should be RT"

        dim1 = self.fes1.GetMesh().Dimension()
        dim2 = self.fes2.GetMesh().Dimension()

        if use_parallel:
            import mfem.par as mfem
            DiscreteLinearOperator = mfem.ParDiscreteLinearOperator
        else:
            import mfem.ser as mfem
            DiscreteLinearOperator = mfem.DiscreteLinearOperator
        
        div = DiscreteLinearOperator(self.fes2, self.fes1)
        itp = mfem.DivergenceInterpolator()
        div.AddDomainInterpolator(itp)
        div.Assemble();
        div.Finalize();
        
        from mfem.common.chypre import BF2PyMat
        
        M = BF2PyMat(div)

        return M
Пример #2
0
    def assemble(self, *args, **kwargs):
        engine = self._engine()
        self.process_kwargs(engine, kwargs)

        if len(args) > 0:
            self._sel_mode = args[0]
        if len(args) > 1:
            self._sel = args[1]

        if not self.fes1.FEColl().Name().startswith('ND'):
            assert False, "range should be ND"
        if not self.fes2.FEColl().Name().startswith('H1'):
            assert False, "domain should be H1"

        dim1 = self.fes1.GetMesh().Dimension()
        dim2 = self.fes2.GetMesh().Dimension()

        if use_parallel:
            import mfem.par as mfem
            DiscreteLinearOperator = mfem.ParDiscreteLinearOperator
        else:
            import mfem.ser as mfem
            DiscreteLinearOperator = mfem.DiscreteLinearOperator

        grad = DiscreteLinearOperator(self.fes2, self.fes1)
        itp = mfem.GradientInterpolator()
        grad.AddDomainInterpolator(itp)
        grad.Assemble()
        grad.Finalize()

        from mfem.common.chypre import BF2PyMat

        M = BF2PyMat(grad)

        return M
Пример #3
0
    def run_postprocess(self, engine):
        dprint1("running postprocess: " + self.name())

        names = [x.strip() for x in self.variables.split(',')]
        if len(names) != 2:
            assert False, "wrong setting. specify two variables: " + self.variables
        if names[0] not in engine.model._variables:
            assert False, names[0] + " is not defined"
        if names[1] not in engine.model._variables:
            assert False, names[1] + " is not defined"

        var1 = engine.model._variables[names[0]]
        var2 = engine.model._variables[names[1]]

        emesh_idx1 = var1.get_emesh_idx()
        emesh_idx2 = var2.get_emesh_idx()

        if (len(emesh_idx1) != 1 or len(emesh_idx2) != 1
                or emesh_idx1[0] != emesh_idx2[0]):
            assert False, "can not perform integration between different extended-mesh"
        emesh_idx = emesh_idx1[0]

        fes1 = engine.fespaces[names[0]]
        fes2 = engine.fespaces[names[1]]
        info1 = engine.get_fes_info(fes1)
        info2 = engine.get_fes_info(fes2)
        if info1 is None or info2 is None:
            assert False, "fes info is not found"

        if info1['sdim'] == self.sdim:
            isDomain = True
        elif info1['sdim'] == self.sdim + 1:
            isDomain = False
        else:
            warnings.warn("Can not perform integration (skipping)",
                          RuntimeWarning)
            return

        isComplex = var1.complex or var2.complex
        if fes1 != fes2:
            new_bf = engine.new_mixed_bf
        else:
            new_bf = engine.new_bf

        cdim = 1
        if (info1['element'].startswith('ND')
                or info1['element'].startswith('RT')):
            cdim = info1['sdim']
        else:
            cdim = info1['vdim']

        from petram.helper.phys_module_util import default_bf_integrator
        if self.integrator == 'Auto':
            integrator = default_bf_integrator(info1, info2, isDomain)
            '''
            if fes1 == fes2:
                if (info1['element'].startswith('ND') or
                    info1['element'].startswith('RT')):
                    integrator = 'VectorFEMassIntegrator'
                elif info1['element'].startswith('DG'):
                    assert False, "auto selection is not supported for GD"
                elif info1['vdim'] > 1:
                    integrator = 'VectorMassIntegrator'
                elif not isDomain:
                    integrator = 'BoundaryMassIntegrator'
                else:
                    integrator = 'MassIntegrator'
            else:
                if (((info1['element'].startswith('ND') or
                      info1['element'].startswith('RT'))and
                     (info2['element'].startswith('ND') or
                      info2['element'].startswith('RT')))):
                    integrator = 'MixedVectorMassIntegrator'
                elif info1['element'].startswith('DG'):
                    assert False, "auto selection is not supported for GD"
                elif (info1['vdim'] == 1 and info1['vdim'] == info2['vdim']):
                    integrator = 'MixedScalarMassIntegrator'                    
                else:
                    assert False, "No proper integrator is found"
            '''
        else:
            integrator = self.integrator

        bfr = new_bf(fes2, fes1)
        self.add_integrator(bfr, engine, integrator, cdim, emesh_idx, isDomain,
                            True)
        bfr.Assemble()

        if isComplex:
            bfi = new_bf(fes2, fes1)
            self.add_integrator(bfi, engine, integrator, cdim, emesh_idx,
                                isDomain, False)
            bfi.Assemble()
        else:
            bfi = None

        from mfem.common.chypre import BF2PyMat

        M = BF2PyMat(bfr, bfi, finalize=True)

        V1 = engine.variable2vector(var1, horizontal=True)
        V2 = engine.variable2vector(var2)
        if self.use_conj:
            try:
                V2 = V2.conj()
            except:
                V2[1] *= -1
        #print(M.shape)
        #print(V1.shape)
        #print(V2.shape)
        value = np.array(V1.dot(M.dot(V2)), copy=False)
        #value = np.array(V1.dot(V2), copy=False)
        dprint1("Integrated Value :" + self.integration_name + ":" +
                str(value))
        engine.store_pp_extra(self.integration_name, value, save_once=True)