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)
# 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 J_outer_conductor *= -current / np.dot(J_outer_conductor, load_integral) A = solve( *condense(K_mag, J_inner_conductor + J_outer_conductor, D=dofs['boundary'])) # magnetic field energy from FEM E_mag = 0.5 * np.dot(A, K_mag * A) # energy stored in inductor: E = 0.5*L*I^2 # thus, L = 2*E/I^2 L = 2 * E_mag / (current**2) print(f'L={L} H/m') # assemble the parts of the stiffness matrix for each material separately K_elec_inner_insulator = asm(laplace, inner_insulator_basis) * eps0 * eps_ptfe K_elec_outer_insulator = asm(laplace, outer_insulator_basis) * eps0 * eps_fep # use dummy value for permittivity, uniform U in conductor K_elec_inner_conductor = asm(laplace, inner_conductor_basis) * eps0 # use dummy value for permittivity, uniform U in conductor