![]() ![]() clock () u = interpolate ( expr, V ) t1 = time. b * x * x * x ) expr = SineXYZ ( a = 1, b = 2 ) elif method = 'C ' : expr = Expression ( 'a*sin(b*x*x*x)', a = 1, b = 2 ) t0 = time. b = a, b def eval ( self, value, x ): value = self. endswith ( 'sympy.sin' ): from sympy import sin else : raise NotImplementedError ( 'method= %s ' % method ) print ( 'sin:', sin, type ( sin )) class SineXYZ ( Expression ): def _init_ ( self, a, b ): self. endswith ( 'numpy.sin' ): from numpy import sin elif method. endswith ( 'math.sin' ): from math import sin elif method. endswith ( 'fenics.sin' ): # Need sin as local variable in this function from fenics import sin elif method. The recommended way to define subdomains.įrom _future_ import print_function from fenics import * import time def make_sine_Function ( N, method ): """Fill a Function with sin(x*y*z) values.""" mesh = UnitCubeMesh ( N, N, N ) V = FunctionSpace ( mesh, 'Lagrange', 2 ) if method. In such cases the method demonstrated here is Perhaps generated as part of the mesh generation process, and not as a Subdomains may be available as a MeshFunction (from a data file), Since we make use of geometric tests to define the two SubDomainsįor \(\Omega_0\) and \(\Omega_1\), the MeshFunction method may seem likeĪn unnecessary complication of the simple method using anĮxpression with an if-test. This version of the evaluation function has anĪddition cell argument which we can use to check on which cell we are Make use of the member function eval_cell in place of the regularĮval function. ![]() This is similar to the Expression subclass we defined above, but we k_1 k = K ( materials, k_0, k_1, degree = 0 ) k_1 = k_1 def eval_cell ( self, values, x, cell ): if self. Integers ( 'size_t') for numbering the subdomains:Ĭlass K ( Expression ): def _init_ ( self, materials, k_0, k_1, ** kwargs ): self. We start with creating a CellFunction whose values are non-negative Numbers, and 'bool' for logical values 2) a Mesh object.Īlternatively, the constructor can take just a filename and initialize 'size_t' for non-negative (unsigned) integers, 'double' for real Is fed with two arguments: 1) the type of value: 'int' for integers, Since we need to define subdomains of \(\Omega\) in the present example, Provided for easy definition of a MeshFunction of a particular Special subclasses VertexFunction, EdgeFunction etc. Integers or booleans) and its dimension (0 = vertex, 1 = edgeĮtc.). AįEniCS MeshFunction is parameterized both over its data type (like A MeshFunction over cellsĬan also be used to represent boundary markers for mesh refinement. Pieces of external or internal boundaries. MeshFunction over facets (edges or faces) is used to represent Is suitable to represent subdomains (materials), while a A mesh entity in FEniCS is either a vertex, an edge, aįace, or a cell (triangle or tetrahedron). A MeshFunction is a discreteįunction that can be evaluated at a set of so-called meshĮntities. To define the variable coefficient \(\kappa\), we will use a powerful tool inįEniCS called a MeshFunction. Make the cells both above and below the internal boundary belong to This is a little counter-intuitive, but is necessary to Vertices on the internal boundary at \(y = 0.5\) will belong to both In addition, we use a tolerance to make sure that Important that the test holds for all vertices in cells aligned with Not the cell belongs to a particular subdomain. Inside function for each vertex in a cell to determine whether or Also when we define the points, we must specify a length scale that will be used for determining the size of elements in the mesh.Tol = 1E-14 class Omega_0 ( SubDomain ): def inside ( self, x, on_boundary ): return x = 0.5 - tol For the ellipsis, we need two end points, a center point and a point on the major axis (for this example it can be the center points). ![]() For each line segment we need to end points. geo file, that will be input to Gmsh for meshing.įirst we define our points. The geometry specification is written to a. To make a 2D plot we will define points, then lines based on those points, and finally a surface based on the lines. These include Points, Lines, Surfaces, etc. There are several elementary mesh entities in the Gmsh format. Here I will go through meshing up a rectangle with an ellipse in the top and bottom, with the command line interface. It can do a lot of stuff but we will use if for just some very simple things. Gmsh is neat, it comes with a mesh editor and a command line interface for scripting. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |