def get_coefficient_from_expression(self,
                                        c,
                                        cotype,
                                        use_dual=False,
                                        real=True,
                                        is_conj=False):
        from petram.phys.coefficient import SCoeff, VCoeff, DCoeff, MCoeff

        if self.get_root_phys().vdim > 1:
            dim = self.get_root_phys().vdim
        else:
            dim = self.get_root_phys().geom_dim

        if cotype == 'S':
            # for b in self.itg_choice():
            #   if b[0] == self.integrator: break
            # if not "S*2" in b[3]:
            if not use_dual:
                c_coeff = SCoeff(c,
                                 self.get_root_phys().ind_vars,
                                 self._local_ns,
                                 self._global_ns,
                                 real=real,
                                 conj=is_conj)
            else:  # so far this is only for an elastic integrator
                c_coeff = (SCoeff(c,
                                  self.get_root_phys().ind_vars,
                                  self._local_ns,
                                  self._global_ns,
                                  real=real,
                                  conj=is_conj,
                                  component=0),
                           SCoeff(c,
                                  self.get_root_phys().ind_vars,
                                  self._local_ns,
                                  self._global_ns,
                                  real=real,
                                  conj=is_conj,
                                  component=1))
        elif cotype == 'V':
            c_coeff = VCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)
        elif cotype == 'M':
            c_coeff = MCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)
        elif cotype == 'D':
            c_coeff = DCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)
        return c_coeff
def Mu_Coeff(exprs, ind_vars, l, g, omega):
    fac = mu0
    coeff = MCoeff(3, exprs, ind_vars, l, g, return_complex=True, scale=fac)
    return coeff
def Sigma_Coeff(exprs, ind_vars, l, g, omega):
    # v = - 1j * self.omega * v
    fac = -1j * omega
    coeff = MCoeff(3, exprs, ind_vars, l, g, return_complex=True, scale=fac)
    return coeff
def Epsilon_Coeff(exprs, ind_vars, l, g, omega):
    # - omega^2 * epsilon0 * epsilonr
    fac = -epsilon0 * omega * omega
    coeff = MCoeff(3, exprs, ind_vars, l, g, return_complex=True, scale=fac)
    return coeff
Exemple #5
0
    def add_contribution(self,
                         engine,
                         a,
                         real=True,
                         is_trans=False,
                         is_conj=False):
        c = self.vt_coeff.make_value_or_expression(self)[0]

        if real:
            dprint1(
                "Add " + self.integrator + " contribution(real)" +
                str(self._sel_index), "c", c)
        else:
            dprint1(
                "Add " + self.integrator + " contribution(imag)" +
                str(self._sel_index), "c", c)

        cotype = self.coeff_type[0]

        if self.get_root_phys().vdim > 1:
            dim = self.get_root_phys().vdim
        else:
            el_name = self.get_root_phys().element
            dim = self.get_root_phys().geom_dim
            '''
            if el_name.startswith("ND"):
                dim = self.get_root_phys().geom_dim            
            elif el_name.startswith("RT"):
                dim = self.get_root_phys().geom_dim
            else:
                dim = 1  #H1 scalar (this case does not exist..)
            '''
        if cotype == 'S':
            for b in self.itg_choice():
                if b[0] == self.integrator: break
            if not "S*2" in b[3]:
                c_coeff = SCoeff(c,
                                 self.get_root_phys().ind_vars,
                                 self._local_ns,
                                 self._global_ns,
                                 real=real,
                                 conj=is_conj)
            else:  # so far this is only for an elastic integrator
                c_coeff = (SCoeff(c,
                                  self.get_root_phys().ind_vars,
                                  self._local_ns,
                                  self._global_ns,
                                  real=real,
                                  conj=is_conj,
                                  component=0),
                           SCoeff(c,
                                  self.get_root_phys().ind_vars,
                                  self._local_ns,
                                  self._global_ns,
                                  real=real,
                                  conj=is_conj,
                                  component=1))
        elif cotype == 'V':
            c_coeff = VCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)
        elif cotype == 'M':
            c_coeff = MCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)
        elif cotype == 'D':
            c_coeff = DCoeff(dim,
                             c,
                             self.get_root_phys().ind_vars,
                             self._local_ns,
                             self._global_ns,
                             real=real,
                             conj=is_conj)

        integrator = getattr(mfem, self.integrator)
        if isinstance(self, Bdry):
            #print "Bdry Integrator"
            adder = a.AddBoundaryIntegrator
        elif isinstance(self, Domain):
            #print "Domain Integrator"
            adder = a.AddDomainIntegrator
        else:
            assert False, "this class is not supported in weakform"
        self.add_integrator(engine,
                            'c',
                            c_coeff,
                            adder,
                            integrator,
                            transpose=is_trans)
def Mu_Coeff(exprs, ind_vars, l, g, omega):
    # v = mu * v
    fac = mu0
    return MCoeff(3, exprs, ind_vars, l, g, return_complex=True, scale=fac)