def __init__(self, dim, trial_basis_type, test_basis_type, mesh_vtk_file, bc_vtk_file): self.__dim = dim # 检查维数信息 if self.__dim in [1, 2, 3]: pass else: logger.error(__file__ + '---' + "dimension should be 1,2,3, " + str(dim) + "is not allowed!") exit(0) self.__trial_basis_fun = BasisFun(trial_basis_type) self.__test_basis_fun = BasisFun(test_basis_type) # 检查 基函数是否符合维数要求 if self.__trial_basis_fun.is_ok(dim): pass else: logger.error(__file__ + '---' + "the basis function type" + str(trial_basis_type) + " is not allowed for dim " + str(dim)) exit(0) if self.__test_basis_fun.is_ok(dim): pass else: logger.error(__file__ + '---' + "the basis function type" + str(test_basis_type) + " is not allowed for dim " + str(dim)) exit(0) self.__mesh_vtk_file = mesh_vtk_file self.__bc_vtk_file = bc_vtk_file # 检查输入文件后缀名为vtk if self.__mesh_vtk_file.endswith(".vtk"): pass else: logger.error(__file__ + '---' + "input mesh file is only supported vtk") exit(0) self.__bc_vtk_file = bc_vtk_file if self.__bc_vtk_file.endswith(".vtk"): pass else: logger.error(__file__ + '---' + "input boundary mesh file is only supported vtk") exit(0) logger.info("<<--------BEGIN FEM PROCEDURE---------->>") logger.info( "STEP 1:input param are prepared and be checked.------------------------------------OK" )
def estimate_err(self, exact_solution): if self.__input_param.dim == 1: value = 0 for i in range(len(self.mesh.points)): value = max(value, abs(self.u[i] - exact_solution(self.mesh.x(i)))) return value else: logger.error( __file__ + "--" + "this form will update later, now only have the 1 dimension ") # TODO exit(0) logger.info( "<estimating error>Error Estimated.--------------------------------------------------" "----------------------OK")
def __init__(self, kernel): self.mesh = kernel.mesh self.input = kernel.mesh.input_param self.kernel = kernel self.num_of_basis = self.mesh.num_of_basis self.__mat = np.zeros((self.mesh.num_of_basis, self.mesh.num_of_basis), dtype=float) self.__b = np.zeros((self.mesh.num_of_basis, ), dtype=float) self.integrator = None self.choose_integrator() self.assemble_mat() self.assemble_b() self.treat_boundary_condition() logger.info( "STEP5:StiffMatrix are prepared and be checked.------------------------------------OK" )
def __init__(self, input_param): super().__init__(input_param) self.__cells = None # 设置几何边界信息 self.__boundary_info = None self.__boundary_value = None self.__num_of_boundary_points = None # 设置有限元网格信息 self.__fem_points_trial = None self.__fem_points_test = None self.__fem_cells_trial = None self.__fem_cells_test = None self.set_mesh_grid_cells() self.set_boundary_info() self.get_fem_mesh() logger.info( "STEP2:FemMesh are prepared and be checked.------------------------------------OK" )
def __init__(self, mesh, variation_form): super().__init__(mesh, variation_form) logger.info( "STEP4:Kernels are prepared and be checked.------------------------------------OK" )
def solve(self): self.__u = direct_inverse(self.stiff.mat, self.stiff.b) logger.info( "STEP6:The FEM is solved.------------------------------------------------------------------------OK" ) logger.info(">>--------END FEM PROCEDURE----------<<")
def set_variation_form(self, vf): self.variation_form = vf logger.info( "STEP3:variation_form are prepared and be checked.------------------------------------OK" )