def SpaceTimeWeakSet(gfu_e, cf, space_fes): """ Ondocumented feature """ gfu_e_repl = GridFunction(space_fes) gfu_e_repl.Set(cf) gfu_e.vec[:].data = gfu_e_repl.vec
def PartialApproximateWithFESpace(N=64, order=3, f="sin(3·pi·x)", j=2): i = j if f == "sin(3·pi·x)": f = Sin(3 * pi * X) elif f == "sin(3·pi·x)·cos(5·pi·x)": f = Sin(3 * pi * X) * Cos(5 * pi * X) else: print("no function provided") return mesh1D = Mesh1D(N) try: f(mesh1D(0.5)) except: print("expression for f not valid!") return fes = H1(mesh1D, order=order) if (i > fes.ndof): print("j is too large. Setting j = ", fes.ndof - 1) i = fes.ndof gf = GridFunction(fes) gf.Set(f) for j in range(i, fes.ndof): gf.vec[j] = 0 Draw1D(mesh1D, [(gf, "FE Approximation"), (f, "exakte Funktion")], n_p=20) for j in range(i): print("{:5.2f}".format(gf.vec[j]), end=" ") if (j > 0 and j % 18 == 17): print("")
def ApproximateWithFESpace(N=64, order=3, f="sin(3·pi·x)"): if f == "sin(3·pi·x)": f = Sin(3 * pi * X) elif f == "sin(3·pi·x)·cos(5·pi·x)": f = Sin(3 * pi * X) * Cos(5 * pi * X) else: print("no function provided") return mesh1D = Mesh1D(N) try: f(mesh1D(0.5)) except: print("expression for f not valid!") return fes = H1(mesh1D, order=order) gf = GridFunction(fes) gf.Set(f) Draw1D(mesh1D, [(gf, "FE Approximation"), (f, "exakte Funktion")], n_p=20) for i in range(fes.ndof): print("{:5.2f}".format(gf.vec[i]), end=" ") if (i > 0 and i % 18 == 17): print("")
def load_coefficientfunction_into_gridfunction( gfu: ngs.GridFunction, coef_dict: Dict[Optional[int], ngs.CoefficientFunction]) -> None: """ Function to load a coefficientfunction(s) into a gridfunction. Coefficientfunction may have a different dimension than the gridfunction and need to be loaded into a specific component. Args: coef_dict: Dict containing the coefficientfunction(s) and which component they belong to (keys) gfu: The gridfunction to load the values into """ for key, val in coef_dict.items(): if key is None: # Confirm that coef_dict only has one value, otherwise the gfu values will be overwritten multiple times assert len(coef_dict) == 1 gfu.Set(val) else: gfu.components[key].Set(val)
def apply_dirichlet_bcs_to(self, gfu: ngs.GridFunction) -> None: """ Function to set the Dirichlet boundary conditions within the solution GridFunction. Args: gfu: The GridFunction to add the Dirichlet boundary condition values to """ # NOTE: DO NOT change from definedon=self.mesh.Boundaries(marker) to definedon=marker. if len(self.g_D) > 0: if len(gfu.components) == 0: # Single trial functions # TODO: IDE is complaining that we don't specify parameter VOL_OR_BND for .Set() gfu.Set(self.g_D['u'], definedon=self.mesh.Boundaries( self.dirichlet_names['u'])) else: # Multiple trial functions. for component_name in self.g_D.keys(): # Apply Dirichlet or pinned BCs. i = self.model_components[component_name] gfu.components[i].Set( self.g_D[component_name], definedon=self.mesh.Boundaries( self.dirichlet_names[component_name]))