def project(self, interp, facets=None): """Perform :math:`L^2` projection onto the basis on the boundary. The values of the interior DOFs remain zero. Parameters ---------- interp An object of type :class:`~skfem.element.DiscreteField` which is a function (to be projected) evaluated at global quadrature points at the boundary of the domain. If a function is given, then :class:`~skfem.element.DiscreteField` is created by passing an array of global quadrature point locations to the function. facets Optionally perform the projection on a subset of facets. The values of the remaining DOFs are zero. """ from skfem.utils import solve, condense M, f = self._projection(interp) if facets is not None: return solve(*condense(M, f, I=self.get_dofs(facets=facets))) return solve(*condense(M, f, I=self.get_dofs(facets=self.find)))
def project(self, interp, elements=None): """Perform :math:`L^2` projection onto the basis. See :ref:`l2proj` for more information. Parameters ---------- interp An object of type :class:`~skfem.element.DiscreteField` which is a function (to be projected) evaluated at global quadrature points. If a function is given, then :class:`~skfem.element.DiscreteField` is created by passing an array of global quadrature point locations to the function. elements Optionally perform the projection on a subset of elements. The values of the remaining DOFs are zero. """ from skfem.utils import solve, condense M, f = self._projection(interp) if elements is not None: return solve(*condense(M, f, I=self.get_dofs(elements=elements))) elif self.tind is not None: return solve(*condense(M, f, I=self.get_dofs(elements=self.tind))) return solve(M, f)
def calculate_axial_from_stress(self, R, J): """ Calculate the axial force by integrating sigma_zz over the area Parameters: R final residual J final jacobian """ #pylint: disable=no-value-for-parameter, invalid-unary-operand-type if self.state_np1.ndim == 1: dx = self.state_np1.basis.interpolate( self.state_np1.mesh.p[0] )[0][0] * self.state_np1.basis.dx * 2.0 * np.pi else: dx = self.state_np1.basis.dx fake_force = self._internal_force(self.state_np1.tangent[:, :, 2, 2]) de = utils.solve(*utils.condense(J, fake_force, D=self.edofs), solver=utils.solver_direct_scipy()) fake_strain = self.calculate_strain(de) integrand1 = np.einsum('iijk', self.state_np1.tangent[2, 2] * fake_strain) integrand2 = self.state_np1.tangent[2, 2, 2, 2] self.state_np1.force = np.sum(self.state_np1.stress[2, 2] * dx) self.state_np1.stiffness = np.sum( (-integrand1 + integrand2) * dx) / self.state_np1.h
def linear_solve(self, J, R): """ Do the linear solve for a particular jacobian and residual Parameters: J Jacobian sparse matrix R residual vector """ #pylint: disable=no-value-for-parameter return utils.solve(*utils.condense(J, R, D=self.edofs), solver=utils.solver_direct_scipy())
def test_simple_cg_solver(): m = MeshTri().refined(3) basis = CellBasis(m, ElementTriP1()) A0 = laplace.coo_data(basis) A1 = laplace.assemble(basis) f = unit_load.assemble(basis) D = m.boundary_nodes() x1 = solve(*condense(A1, f, D=D)) f[D] = 0 x0 = A0.solve(f, D=D) assert_almost_equal(x0, x1)
inner_conductor_outer_surface_basis = FacetBasis( mesh, element, facets=mesh.boundaries['inner_conductor_outer_surface']) outer_conductor_inner_surface_basis = FacetBasis( mesh, element, facets=mesh.boundaries['outer_conductor_inner_surface']) dofs = { 'boundary': global_basis.get_dofs(mesh.boundaries['boundary']), 'inner_conductor_outer_surface': global_basis.get_dofs(mesh.boundaries['inner_conductor_outer_surface']), 'outer_conductor_inner_surface': global_basis.get_dofs(mesh.boundaries['outer_conductor_inner_surface']) } # functional to compute the integral of a load vector over the domain load_integral = solve(asm(mass, global_basis), asm(unit_load, global_basis)) # all materials have a relative permeability of effectively 1 K_mag = asm(laplace, global_basis) * (1 / mu0) # pass 1A through the conductors current = 1 J_inner_conductor = asm(unit_load, inner_conductor_basis) # scale inner conductor current density to have an integral # equal to current over domain J_inner_conductor *= current / np.dot(J_inner_conductor, load_integral) J_outer_conductor = asm(unit_load, outer_conductor_basis) # scale outer conductor current density to have an integral # equal to -current over domain