Ejemplo n.º 1
0
    def set_funcs(self):
        gf_real, gf_imag, extra = self.deriv(*self.deriv_args)
        self.gfr = gf_real
        self.gfi = gf_imag
        self.dim = gf_real.VectorDim()
        name = gf_real.FESpace().FEColl().Name()
        if name.startswith("ND") or name.startswith("RT"):
            self.isVectorFE = True
            self.func_r = mfem.VectorGridFunctionCoefficient(gf_real)
            if gf_imag is not None:
                self.func_i = mfem.VectorGridFunctionCoefficient(gf_imag)
            else:
                self.func_i = None

        else:
            self.isVectorFE = False
            self.func_r = [
                mfem.GridFunctionCoefficient(gf_real, comp=k + 1)
                for k in range(self.dim)
            ]

            if gf_imag is not None:
                self.func_i = [
                    mfem.GridFunctionCoefficient(gf_imag, comp=k + 1)
                    for k in range(self.dim)
                ]
            else:
                self.func_i = None
        self.isDerived = True
        self.extra = extra
Ejemplo n.º 2
0
    def solve(self, update_operator=True):
        engine = self.engine
        phys_target = self.get_phys()
        phys_range = self.get_phys_range()

        engine.access_idx = 0
        name0 = phys_target[0].dep_vars[0]
        r_x = engine.r_x[engine.r_ifes(name0)]
        if len(phys_target[0].dep_vars) > 1:
            name1 = phys_target[0].dep_vars[1]
            dr_x = engine.r_x[engine.r_ifes(name1)]
            do_vector = True
        else:
            do_vector = False

        import mfem.par as mfem

        pfes_s = r_x.ParFESpace()
        pmesh = pfes_s.GetParMesh()

        filt_gf = mfem.ParGridFunction(pfes_s)

        # run heat solver
        if self.gui.solver_type == "heat flow":
            t_param = self.gui.heat_flow_t
            dx = mfem.dist_solver.AvgElementSize(pmesh)

            ds = mfem.dist_solver.HeatDistanceSolver(t_param * dx * dx)
            ds.smooth_steps = 0
            ds.vis_glvis = False

            ls_coeff = mfem.GridFunctionCoefficient(r_x)
            filt_gf.ProjectCoefficient(ls_coeff)

            ls_filt_coeff = mfem.GridFunctionCoefficient(filt_gf)

            ds.ComputeScalarDistance(ls_filt_coeff, r_x)
            if do_vector:
                ds.ComputeVectorDistance(ls_filt_coeff, dr_x)
        else:
            p = self.gui.p_lap_p
            newton_iter = self.gui.p_lap_iter
            ds = mfem.dist_solver.PLapDistanceSolver(p, newton_iter)

            ls_coeff = mfem.GridFunctionCoefficient(r_x)
            filt_gf.ProjectCoefficient(ls_coeff)
            ls_filt_coeff = mfem.GridFunctionCoefficient(filt_gf)

        ds.print_level = self.gui.log_level
        ds.ComputeScalarDistance(ls_filt_coeff, r_x)
        if do_vector:
            ds.ComputeVectorDistance(ls_filt_coeff, dr_x)

        return True
        '''
Ejemplo n.º 3
0
    def SetParameters(self, u):
        u_alpha_gf = mfem.ParGridFunction(self.fespace)
        u_alpha_gf.SetFromTrueDofs(u)
        for i in range(u_alpha_gf.Size()):
            u_alpha_gf[i] = self.kappa + self.alpha * u_alpha_gf[i]

        self.K = mfem.ParBilinearForm(self.fespace)
        u_coeff = mfem.GridFunctionCoefficient(u_alpha_gf)
        self.K.AddDomainIntegrator(mfem.DiffusionIntegrator(u_coeff))
        self.K.Assemble(0)
        self.K.FormSystemMatrix(self.ess_tdof_list, self.Kmat)
        self.T = None
Ejemplo n.º 4
0
 def set_funcs(self):
     # I should come back here to check if this works
     # with vector gf and/or boundary element. probably not...
     gf_real, gf_imag, extra = self.deriv(*self.deriv_args)
     self.gfr = gf_real
     self.gfi = gf_imag
     name = gf_real.FESpace().FEColl().Name()
     if name.startswith("ND") or name.startswith("RT"):
         self.isVectorFE = True
         self.func_r = mfem.VectorGridFunctionCoefficient(gf_real)
         if gf_imag is not None:
             self.func_i = mfem.VectorGridFunctionCoefficient(gf_imag)
         else:
             self.func_i = None
     else:
         self.isVectorFE = False
         self.func_r = mfem.GridFunctionCoefficient(gf_real, comp=self.comp)
         if gf_imag is not None:
             self.func_i = mfem.GridFunctionCoefficient(gf_imag,
                                                        comp=self.comp)
         else:
             self.func_i = None
     self.isDerived = True
     self.extra = extra