def get_init_coeff(self, engine, real=True, kfes=0): names = self.get_root_phys().dep_vars_base if not getattr(self, 'use_' + names[kfes] + '_init'): return f_name = self.vt3.make_value_or_expression(self) el = self.get_root_phys().element if el.startswith('H1') or el.startswith('L2'): ll = self.get_root_phys().vdim else: ll = self.get_root_phys().ndim kwargs = {} from petram.phys.coefficient import SCoeff, VCoeff if ll == 1: coeff = SCoeff(f_name[0], self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) else: coeff = VCoeff(ll, f_name, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) kwargs['vec'] = True return self.restrict_coeff(coeff, engine, **kwargs)
def apply_essential_1(self, method, real, c0, vdim, vvdim, bdr_attr): if vdim == 1: coeff1 = SCoeff(c0, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) else: coeff1 = VCoeff(vdim, c0, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) assert not (vvdim != -1 and vdim > 1), "Wrong setting...(vvdim != -1 and vdim > 1)" #print vvdim, vdim, method, coeff1 if vvdim == -1: method(coeff1, mfem.intArray(bdr_attr)) else: for cp in vvdim: method(coeff1, mfem.intArray(bdr_attr), cp)
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 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 apply_essential(self, engine, gf, real=False, kfes=0): if kfes > 0: return c0, vdim0 = self.vt.make_value_or_expression(self) if real: dprint1("Apply Ess.(real)" + str(self._sel_index), 'c0, v0', c0, vdim0) else: dprint1("Apply Ess.(imag)" + str(self._sel_index), 'c0, v0', c0, vdim0) name = self.get_root_phys().dep_vars[0] fes = engine.get_fes(self.get_root_phys(), name=name) vdim = fes.GetVDim() vvdim = -1 if vdim0 != 'all': lvdim = len(self.esse_vdim.split(",")) #assert lvdim == 1, "Specify only one vdim" vvdim = [int(x) for x in self.esse_vdim.split(",")] else: vvdim = -1 fec_name = fes.FEColl().Name() mesh = engine.get_emesh(mm=self) ibdr = mesh.bdr_attributes.ToList() bdr_attr = [0] * mesh.bdr_attributes.Max() for idx in self._sel_index: bdr_attr[idx - 1] = 1 if fec_name.startswith("ND"): assert vdim == 1, "ND element vdim must be one" vdim = mesh.Dimension() method = gf.ProjectBdrCoefficientTangent self.apply_essential_1(method, real, c0, vdim, vvdim, bdr_attr) elif fec_name.startswith("RT"): assert vdim == 1, "RT element vdim must be one" vdim = mesh.Dimension() method = gf.ProjectBdrCoefficientNormal self.apply_essential_1(method, real, c0, vdim, vvdim, bdr_attr) #elif self.get_root_phys().vdim == 1: # ProjectBdrCoefficient does not realy work in parallel # since shadow vertex are not always set... # method = gf.ProjectBdrCoefficient # self.apply_essential_1(method, real, c0, vdim, vvdim, bdr_attr) else: #H1 or L2 # vector field FE. method = gf.ProjectCoefficient ess_vdofs = mfem.intArray() fes.GetEssentialVDofs(mfem.intArray(bdr_attr), ess_vdofs, 0) vdofs = np.where(np.array(ess_vdofs.ToList()) == -1)[0] dofs = mfem.intArray([fes.VDofToDof(i) for i in vdofs]) fes.BuildDofToArrays() if self.get_root_phys().vdim == 1: coeff1 = SCoeff(c0, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) gf.ProjectCoefficient(coeff1, dofs, 0) elif vdim0 == 'all': coeff1 = VCoeff(vdim, c0, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real) gf.ProjectCoefficient(coeff1, dofs) else: for k, cp in enumerate(vvdim): coeff1 = SCoeff(c0, self.get_root_phys().ind_vars, self._local_ns, self._global_ns, real=real, component=k) gf.ProjectCoefficient(coeff1, dofs, cp)
def jwJ_Coeff(exprs, ind_vars, l, g, omega): # iomega x Jext fac = 1j * omega return VCoeff(3, exprs, ind_vars, l, g, return_complex=True, scale=fac)