def skyrmion_number_density_function(self): """ This function returns the skyrmion number density function calculated from the spin texture in this simulation instance. This function can be probed to determine the local nature of the skyrmion number. """ integrand = -0.25 / np.pi * df.dot( self.m_field.f, df.cross(df.Dx(self.m_field.f, 0), df.Dx(self.m_field.f, 1))) # Build the function space of the mesh nodes. dofmap = self.S3.dofmap() S1 = df.FunctionSpace(self.S3.mesh(), "Lagrange", 1, constrained_domain=dofmap.constrained_domain) # Find the skyrmion density at the mesh nodes using the above function # space. nodalSkx = df.dot(integrand, df.TestFunction(S1)) * df.dx nodalVolumeS1 = nodal_volume(S1, self.unit_length) skDensity = df.assemble(nodalSkx).array() * self.unit_length\ ** self.S3.mesh().topology().dim() / nodalVolumeS1 # Build the skyrmion number density dolfin function from the skDensity # array. skDensityFunc = df.Function(S1) skDensityFunc.vector()[:] = skDensity return skDensityFunc
def create_a(self): local_a = 0.0 df.ds = self.ds #Import <---- local_a += (+0.5 * ((df.inner(self.v, (self.SA_x * df.Dx(self.u, 0)))) +\ (df.inner(self.v, (self.SA_y * df.Dx(self.u, 1))))) ) * df.dx local_a += (-0.5 * ((df.inner(df.Dx(self.v, 0),(self.SA_x * self.u))) +\ (df.inner(df.Dx(self.v, 1),(self.SA_y * self.u)))) ) * df.dx local_a += (+0.5 * df.inner(self.v, ((self.BC1 + self.BC2) * self.u))) * df.ds local_a += (df.inner(self.v, (self.SP_Coeff * self.u))) * df.dx return local_a
def skyrmion_number(self): """ This function returns the skyrmion number calculated from the spin texture in this simulation instance. If the sim object is 3D, the skyrmion number is calculated from the magnetisation of the top surface (since the skyrmion number formula is only defined for 2D). Details about computing functionals over subsets of the mesh (the method used in this function to calculate the skyrmion number) can be found at: https://bitbucket.org/fenics-project/dolfin/src/master/demo/undocumented/lift-drag/python/demo_lift-drag.py """ mesh = self.mesh # Get m field and define skyrmion number integrand m = self.m_field.f integrand = -0.25 / np.pi * df.dot(m, df.cross(df.Dx(m, 0), df.Dx(m, 1))) # determine if 3D system or not. Act accordingly. if self.mesh.topology().dim() == 3: mesh_coords = mesh.coordinates() z_max = max(mesh_coords[:, 2]) # Define a subdomain which consists of the top surface of the geometry class Top(df.SubDomain): def inside(self, pt, on_boundary): x, y, z = pt return z >= z_max - df.DOLFIN_EPS and on_boundary # Define a set of Markers from a MeshFunction (which is a function that # can be evaluated at a set of mesh entities). Set all the marks to Zero. markers = df.MeshFunction("size_t", mesh, mesh.topology().dim() - 1) markers.set_all(0) top = Top() # Redefine the marks on the top surface to 1. top.mark(markers, 1) # Define ds so that it only computes where the marker=1 (top surface) ds = df.ds[markers] # Assemble the integrand on the the original domain, but only over the # marked region (top surface). S = df.assemble(form=integrand * ds(1, domain=mesh)) else: S = df.assemble(integrand * df.dx) return S
def apply_stabilization(self): df.dS = self.dS #Important <---- h_msh = df.CellDiameter(self.mesh) h_avg = (h_msh("+") + h_msh("-")) / 2.0 #Output local_stab = 0.0 if self.stab_type == 'cip': if self.moment_order == 3 or self.moment_order == 'ns': local_stab += self.DELTA_T * h_avg**self.ht * df.jump(df.grad(self.u[0]),self.nv)\ * df.jump(df.grad(self.v[0]),self.nv) * df.dS #cip for temp if self.moment_order == 6: local_stab += self.DELTA_P * h_avg**self.hp * df.jump(df.grad(self.u[0]),self.nv)\ * df.jump(df.grad(self.v[0]),self.nv) * df.dS #cip for pressure local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[1]),self.nv)\ * df.jump(df.grad(self.v[1]),self.nv) * df.dS #cip for velocity_x local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[2]),self.nv)\ * df.jump(df.grad(self.v[2]),self.nv) * df.dS #cip for velocity_y if self.moment_order == 13: local_stab += self.DELTA_T * h_avg**self.ht * df.jump(df.grad(self.u[3]),self.nv)\ * df.jump(df.grad(self.v[3]),self.nv) * df.dS #cip for temp local_stab += self.DELTA_P * h_avg**self.hp * df.jump(df.grad(self.u[0]),self.nv)\ * df.jump(df.grad(self.v[0]),self.nv) * df.dS #cip for pressure local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[1]),self.nv)\ * df.jump(df.grad(self.v[1]),self.nv) * df.dS #cip for velocity_x local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[2]),self.nv)\ * df.jump(df.grad(self.v[2]),self.nv) * df.dS #cip for velocity_y if self.moment_order == 'grad13': local_stab += self.DELTA_T * h_avg**self.ht * df.jump(df.grad(self.u[3]),self.nv)\ * df.jump(df.grad(self.v[6]),self.nv) * df.dS #cip for temp local_stab += self.DELTA_P * h_avg**self.hp * df.jump(df.grad(self.u[0]),self.nv)\ * df.jump(df.grad(self.v[0]),self.nv) * df.dS #cip for pressure local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[1]),self.nv)\ * df.jump(df.grad(self.v[1]),self.nv) * df.dS #cip for velocity_x local_stab += self.DELTA_U * h_avg**self.hu * df.jump(df.grad(self.u[2]),self.nv)\ * df.jump(df.grad(self.v[2]),self.nv) * df.dS #cip for velocity_y elif self.stab_type == 'gls': local_stab = (0.0001* h_msh * df.inner(self.SA_x * df.Dx(self.u,0)\ + self.SA_y * df.Dx(self.u,1) + self.SP_Coeff * self.u, self.SA_x * df.Dx(self.v,0)\ + self.SA_y * df.Dx(self.v,1) + self.SP_Coeff * self.v ) * df.dx) return local_stab
def __eval_fexpl(self, u, t): """ Helper routine to evaluate the explicit part of the RHS Args: u (dtype_u): current values t (float): current time Returns: explicit part of RHS """ A = 1.0 * self.K b = self.__apply_mass_matrix(u) psi = self.dtype_u(self.V) df.solve(A, psi.values.vector(), b.values.vector()) fexpl = self.dtype_u(self.V) fexpl.values = df.project( df.Dx(psi.values, 1) * df.Dx(u.values, 0) - df.Dx(psi.values, 0) * df.Dx(u.values, 1), self.V) return fexpl
def d2_dr2(du): d2u_dx2 = df.Dx(df.Dx(du, 0), 0) du_dxdy = df.Dx(df.Dx(du, 0), 1) d2u_dy2 = df.Dx(df.Dx(du, 1), 1) du_dx = d_dx(du) du_dy = d_dy(du) d2u_dr2 = (x * (-x * (x * du_dx + y * du_dy) / (x**2 + y**2)**(3 / 2) + (x * d2u_dx2 + y * du_dxdy + du_dx) / df.sqrt(x**2 + y**2)) + y * (-y * (x * du_dx + y * du_dy) / (x**2 + y**2)**(3 / 2) + (x * du_dxdy + y * d2u_dy2 + du_dy) / df.sqrt(x**2 + y**2)) ) / df.sqrt(x**2 + y**2) return d2u_dr2
def epsilon_r(du): return 1.0 / r * (x * df.Dx(du, 0) + y * df.Dx(du, 1))
def d_dtheta(du): return -y * df.Dx(du, 0) + x * df.Dx(du, 1)
def d_dr(du): return 1.0 / r * (x * df.Dx(du, 0) + y * df.Dx(du, 1))
def d_dy(du): return df.Dx(du, 1)
def d_dx(du): return df.Dx(du, 0)
def s_number(m, dx): s_density = df.dot(m, df.cross(df.Dx(m, 0), df.Dx(m, 1))) return 1/(4*np.pi) * df.assemble(s_density*dx)