Example #1
0
    def run_postprocess(self, engine):
        dprint1("running postprocess: " + self.name())

        name = self.variables.strip()
        if name not in engine.model._variables:
            assert False, name + " is not defined"

        var1 = engine.model._variables[name]
        emesh_idx1 = var1.get_emesh_idx()
        emesh_idx = emesh_idx1[0]

        fes1 = engine.fespaces[name]
        info1 = engine.get_fes_info(fes1)
        if info1 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
        new_lf = engine.new_lf

        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_lf_integrator
        if self.integrator == 'Auto':
            integrator = default_lf_integrator(info1, isDomain)
        else:
            integrator = self.integrator

        lfr = new_lf(fes1)
        self.add_integrator(lfr, engine, integrator, cdim, emesh_idx, isDomain,
                            True)
        lfr.Assemble()

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

        from mfem.common.chypre import LF2PyVec
        V = LF2PyVec(lfr, lfi, horizontal=True)

        V1 = engine.variable2vector(var1)
        #print(V1.shape)
        #print(V.shape)
        value = np.array(V.dot(V1), 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)
Example #2
0
    def assemble(self, *args, **kwargs):
        '''
        integral()
        integral('boundary', [1,3])  # selection type and selection
        integral('boundary', [1,3], integrator = 'auto' or other MFEM linearform integrator
        integral('boundary', [1,3], weight = '1')

        '''

        coeff = kwargs.pop("coeff", "1.0")
        coeff_type = kwargs.pop("coeff_type", "S")

        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 (self.fes1.FEColl().Name().startswith('ND') or
            self.fes1.FEColl().Name().startswith('RT')):
            cdim = self.fes1.GetMesh().SpaceDimension()
        else:
            cdim = self.fes1.GetVDim()

        info1 = engine.get_fes_info(self.fes1)
        emesh_idx = info1['emesh_idx']

        isDomain = (self._sel_mode == 'domain')

        from petram.helper.phys_module_util import default_lf_integrator        
        integrator = kwargs.pop("integrator", "Auto")
        if integrator == 'Auto':
            integrator = default_lf_integrator(info1, isDomain)
        
        global_ns = globals()
        local_ns = {}
        real = True

        try:
            is_complex = np.iscomplex(complex(eval(coeff), global_ns, local_ns))
        except:
            is_complex = kwargs.pop('is_complex', False)

        if isDomain:
            adder = 'AddDomainIntegrator'
        else:
            adder = 'AddBoundaryIntegrator'
            
        from petram.helper.phys_module_util import restricted_integrator
        from mfem.common.chypre import LF2PyVec, PyVec2PyMat, MfemVec2PyVec

        itg = restricted_integrator(engine, integrator, self._sel,
                                    coeff, coeff_type, cdim, 
                                    emesh_idx,
                                    isDomain,
                                    self._ind_vars, local_ns, global_ns, True)
        
        lf1 = engine.new_lf(self._fes1())                    
        getattr(lf1, adder)(itg)
        lf1.Assemble()
        
        if is_complex:
            itg = restricted_integrator(engine, integrator, self._sel,
                                        coeff, coeff_type, cdim, 
                                        emesh_idx, isDomain,
                                        self._ind_vars, local_ns, global_ns, False)
            
            lf2 = engine.new_lf(self._fes1())
            getattr(lf2, adder)(itg)            
            lf2.Assemble()
            v1 = MfemVec2PyVec(engine.b2B(lf1), engine.b2B(lf2))
        else:
            v1 = MfemVec2PyVec(engine.b2B(lf1), None)                       
            lf2 = None            

        v1 = PyVec2PyMat(v1)
        if not self._transpose:        
            v1 = v1.transpose()
        return v1