# -*- coding: utf-8 -*-## This file is subject to the terms and conditions defined in# file 'LICENSE.txt', which is part of this source code package.#fromtypingimportOptionalimportnumpyasnpfromMuscat.MeshContainers.MeshimportMeshfromMuscat.LinAlg.LinearSolverimportLinearProblem
[docs]classFeaBase():""" Base class for a finite element solver, this class is experimental normally a finite element solver has a mesh (self.mesh), a solution vector (self.sol), a linear solver (self.solver), the dimensionality of the physical space (1D,2D,3D) (self.spaceDim), and the number of dofs to allocate the objects. All the other parts (assembly operator, IO). must be defined in the derived class """def__init__(self,spaceDim=3,size=1):super().__init__()self.mesh:Optional[Mesh]=Noneself.sol=Noneself.solver=LinearProblem()self.spaceDim=spaceDimself.totalNumberOfDof=0self.solutionFields=None
[docs]defSetMesh(self,mesh):""" To set the mesh """self.mesh=mesh
[docs]defComputeDofNumbering(self,elementFilter=None):""" This fuction must be eliminated (it uses self.space). """fromMuscat.FE.DofNumberingimportComputeDofNumberingfromMuscat.FE.Spaces.FESpacesimportLagrangeSpaceGeoifself.spaceisLagrangeSpaceGeoandelementFilterisNone:# fast generation of the numbering based on the physical Geo space# warning !!!!!!# will add numbering for lonely nodes alsoself.numbering=ComputeDofNumbering(self.mesh,self.space,fromConnectivity=True,dofs=self.numbering)else:self.numbering=ComputeDofNumbering(self.mesh,self.space,fromConnectivity=False,dofs=self.numbering,elementFilter=elementFilter)
[docs]defReset(self):""" To eliminate the solution vector and to reset the linear solver """self.sol=Noneself.solver.u=Nonepass
[docs]defComputeConstraintsEquations(self):""" To computhe the cinematic relation in terms of dofs. The the cinematic relations are stored in the solver """self.solver.constraints.ComputeConstraintsEquations(self.mesh,self.unknownFields)
[docs]defSolve(self,cleanK,cleanff):""" Solve a linear system using the internal solver with the cinematic reations calculated previously """self.solver.SetOp(cleanK.tocsc())self.Resolve(cleanff)
[docs]defResolve(self,cleanff):""" To solve a problem with the same tangent operator but with a different RHS term """self.sol=self.solver.Solve(cleanff)
[docs]defPushSolutionVectorToUnknownFields(self):""" Function to extract fields from the solution vector and to put it into fields data """fromMuscat.FE.Fields.FieldToolsimportVectorToFEFieldsDataVectorToFEFieldsData(self.sol,self.unknownFields)
[docs]defPushUnknownFieldsToSolutionVector(self):""" Function to extract from the Unknown fields a solution vector """fromMuscat.FE.Fields.FieldToolsimportFEFieldsDataToVectorself.sol=FEFieldsDataToVector(self.unknownFields)self.solver.u=self.sol