def _construct_fes(self) -> FESpace: if self.element['u'] == 'RT': # Raviart-Thomas elements are a type of HDiv finite element. fes_u = ngs.HDiv(self.mesh, order=self.interp_ord, dirichlet=self.dirichlet_names.get('u', ''), dgjumps=self.DG, RT=True) else: fes_u = getattr(ngs, self.element['u'])( self.mesh, order=self.interp_ord, dirichlet=self.dirichlet_names.get('u', ''), dgjumps=self.DG) if self.element['p'] == 'L2' and 'p' in self.dirichlet_names.keys(): raise ValueError( 'Not able to pin pressure at a point on L2 spaces.') else: fes_p = getattr(ngs, self.element['p'])( self.mesh, order=self.interp_ord - 1, dirichlet=self.dirichlet_names.get('p', ''), dgjumps=self.DG) return ngs.FESpace([fes_u, fes_p], dgjumps=self.DG)
def presets_load_coefficientfunction_into_gridfunction(): # 2D mesh_2d = ngs.Mesh(unit_square.GenerateMesh(maxh=0.1)) fes_scalar_2d = ngs.H1(mesh_2d, order=2) fes_vector_2d = ngs.HDiv(mesh_2d, order=2) fes_mixed_2d = ngs.FESpace([fes_vector_2d, fes_scalar_2d]) # 3D geo_3d = CSGeometry() geo_3d.Add(OrthoBrick(Pnt(-1, 0, 0), Pnt(1, 1, 1)).bc('outer')) mesh_3d = ngs.Mesh(geo_3d.GenerateMesh(maxh=0.3)) fes_scalar_3d = ngs.H1(mesh_3d, order=2) fes_vector_3d = ngs.HDiv(mesh_3d, order=2) fes_mixed_3d = ngs.FESpace([fes_vector_3d, fes_scalar_3d]) return mesh_2d, fes_scalar_2d, fes_vector_2d, fes_mixed_2d, mesh_3d, fes_scalar_3d, fes_vector_3d, fes_mixed_3d
def _construct_fes(self) -> FESpace: if not self.DG: if self.element['u'] == 'HDiv' or self.element['u'] == 'RT': print( 'We recommended that you NOT use HDIV spaces without DG due to numerical issues.' ) if self.element['p'] == 'L2': print( 'We recommended that you NOT use L2 spaces without DG due to numerical issues.' ) if self.element['u'] == 'RT': # Raviart-Thomas elements are a type of HDiv finite element. fes_u = ngs.HDiv(self.mesh, order=self.interp_ord, dirichlet=self.dirichlet_names.get('u', ''), dgjumps=self.DG, RT=True) else: fes_u = getattr(ngs, self.element['u'])( self.mesh, order=self.interp_ord, dirichlet=self.dirichlet_names.get('u', ''), dgjumps=self.DG) if self.element['p'] == 'L2' and 'p' in self.dirichlet_names.keys(): raise ValueError( 'Not able to pin pressure at a point on L2 spaces.') else: fes_p = getattr(ngs, self.element['p'])( self.mesh, order=self.interp_ord - 1, dirichlet=self.dirichlet_names.get('p', ''), dgjumps=self.DG) return ngs.FESpace([fes_u, fes_p], dgjumps=self.DG)
def solve(self): # disable garbage collector # --------------------------------------------------------------------# gc.disable() while (gc.isenabled()): time.sleep(0.1) # --------------------------------------------------------------------# # measure how much memory is used until here process = psutil.Process() memstart = process.memory_info().vms # starts timer tstart = time.time() if self.show_gui: import netgen.gui # create mesh with initial size 0.1 self._mesh = ngs.Mesh(unit_square.GenerateMesh(maxh=0.1)) #create finite element space self._fes = ngs.H1(self._mesh, order=2, dirichlet=".*", autoupdate=True) # test and trail function u = self._fes.TrialFunction() v = self._fes.TestFunction() # create bilinear form and enable static condensation self._a = ngs.BilinearForm(self._fes, condense=True) self._a += ngs.grad(u) * ngs.grad(v) * ngs.dx # creat linear functional and apply RHS self._f = ngs.LinearForm(self._fes) self._f += (-4) * v * ngs.dx # preconditioner: multigrid - what prerequisits must the problem have? self._c = ngs.Preconditioner(self._a, "multigrid") # create grid function that holds the solution and set the boundary to 0 self._gfu = ngs.GridFunction(self._fes, autoupdate=True) # solution self._g = self._ngs_ex self._gfu.Set(self._g, definedon=self._mesh.Boundaries(".*")) # draw grid function in gui if self.show_gui: ngs.Draw(self._gfu) # create Hcurl space for flux calculation and estimate error self._space_flux = ngs.HDiv(self._mesh, order=2, autoupdate=True) self._gf_flux = ngs.GridFunction(self._space_flux, "flux", autoupdate=True) # TaskManager starts threads that (standard thread nr is numer of cores) with ngs.TaskManager(): # this is the adaptive loop while self._fes.ndof < self.max_ndof: self._solveStep() self._estimateError() self._mesh.Refine() # since the adaptive loop stopped with a mesh refinement, the gfu must be # calculated one last time self._solveStep() if self.show_gui: ngs.Draw(self._gfu) # set measured exectution time self._exec_time = time.time() - tstart # set measured used memory memstop = process.memory_info().vms - memstart self._mem_consumption = memstop # enable garbage collector # --------------------------------------------------------------------# gc.enable() gc.collect()