def test_reference_triangle_face(self, verbose=True): """ Args: verbose: Returns: """ euclidean_dimension = 2 polynomial_orders = [1, 2, 3] element_types = [ElementType.HDG_LOW, ElementType.HDG_EQUAL, ElementType.HDG_HIGH] for polynomial_order in polynomial_orders: for element_type in element_types: # --- DEFINE POLYNOMIAL ORDER AND INTEGRATION ORDER finite_element = FiniteElement( element_type=element_type, polynomial_order=polynomial_order, euclidean_dimension=euclidean_dimension, ) # --- DEFINE POLYNOMIAL BASIS cell_basis_k = finite_element.cell_basis_k cell_basis_l = finite_element.cell_basis_l # --- DEFINE RANDOM POLYNOMIAL COEFFICIENTS range_min = -3.0 range_max = +3.0 coefficients_k = np.array([uniform(range_min, range_max) for _i in range(cell_basis_k.dimension)]) coefficients_l = np.array([uniform(range_min, range_max) for _i in range(cell_basis_l.dimension)]) if verbose: print("COEFS_K : \n{}".format(coefficients_k)) print("COEFS_L : \n{}".format(coefficients_l)) # --- DEFINE MONOMIAL VALUES COMPUTATION def test_function( polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, coefficients: ndarray ) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter) ** _exponent[_x_dir] prod *= coefficients[_i] value += prod return value def test_function_derivative( polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, direction: int, coefficients: ndarray, ) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): if _x_dir == direction: _pt0 = point[_x_dir] - centroid[_x_dir] _pt1 = _pt0 / diameter if _exponent[_x_dir] == 0: _exp = _exponent[_x_dir] else: _exp = _exponent[_x_dir] - 1 _pt2 = _pt1 ** _exp # prod *= (_exponent[_x_dir] / diameter) * ( # ((point[_x_dir] - centroid[_x_dir]) / diameter) ** (_exponent[_x_dir] - 1) # ) prod *= (_exponent[_x_dir] / diameter) * _pt2 else: prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter) ** _exponent[_x_dir] prod *= coefficients[_i] value += prod return value # --- DEFINE TRIANGLE COORDINATES v0 = np.array([0.0, 0.0], dtype=real) v1 = np.array([1.0, 0.0], dtype=real) v2 = np.array([0.0, 1.0], dtype=real) triangle_vertices = np.array([v0, v1, v2], dtype=real).T # --- BUILD CELL cell_triangle = Shape(ShapeType.TRIANGLE, triangle_vertices) x_c = cell_triangle.get_centroid() h_c = cell_triangle.get_diameter() _io = finite_element.construction_integration_order cell_quadrature_points = cell_triangle.get_quadrature_points(_io) cell_quadrature_weights = cell_triangle.get_quadrature_weights(_io) cell_quadrature_size = cell_triangle.get_quadrature_size(_io) # --- CHECK INTEGRATION IN CELL bases = [cell_basis_k, cell_basis_l] # orders = [face_polynomial_order, cell_polynomial_order] coefs = [coefficients_k, coefficients_l] # scheme = quadpy.t2.get_good_scheme(2 * finite_element.construction_integration_order) scheme = quadpy.t2.get_good_scheme(finite_element.construction_integration_order) for basis_0, coef_0 in zip(bases, coefs): order_0 = basis_0.polynomial_order for basis_1, coef_1 in zip(bases, coefs): order_1 = basis_1.polynomial_order for _i in range(euclidean_dimension): for _j in range(euclidean_dimension): mass_mat = np.zeros((basis_0.dimension, basis_1.dimension), dtype=real) stif_mat = np.zeros((basis_0.dimension, basis_1.dimension), dtype=real) advc_mat = np.zeros((basis_0.dimension, basis_1.dimension), dtype=real) for _qc in range(cell_quadrature_size): _x_qc = cell_quadrature_points[:, _qc] _w_qc = cell_quadrature_weights[_qc] phi_0 = basis_0.evaluate_function(_x_qc, x_c, h_c) phi_1 = basis_1.evaluate_function(_x_qc, x_c, h_c) d_phi_0_i = basis_0.evaluate_derivative(_x_qc, x_c, h_c, _i) d_phi_1_j = basis_1.evaluate_derivative(_x_qc, x_c, h_c, _j) mass_mat += _w_qc * np.tensordot(phi_0, phi_1, axes=0) stif_mat += _w_qc * np.tensordot(d_phi_0_i, d_phi_1_j, axes=0) advc_mat += _w_qc * np.tensordot(phi_0, d_phi_1_j, axes=0) mass_integral = coef_0 @ mass_mat @ coef_1 stif_integral = coef_0 @ stif_mat @ coef_1 advc_integral = coef_0 @ advc_mat @ coef_1 f_mass_check = lambda x: test_function(order_0, x, x_c, h_c, coef_0) * test_function( order_1, x, x_c, h_c, coef_1 ) f_stif_check = lambda x: test_function_derivative( order_0, x, x_c, h_c, _i, coef_0 ) * test_function_derivative(order_1, x, x_c, h_c, _j, coef_1) f_advc_check = lambda x: test_function( order_0, x, x_c, h_c, coef_0 ) * test_function_derivative(order_1, x, x_c, h_c, _j, coef_1) mass_integral_check = scheme.integrate(f_mass_check, triangle_vertices.T) stif_integral_check = scheme.integrate(f_stif_check, triangle_vertices.T) advc_integral_check = scheme.integrate(f_advc_check, triangle_vertices.T) rtol = 1.0e-15 atol = 1.0e-15 if verbose: print( "MASS INTEGRAL CHECK | ORDER : {} | ELEM : {}".format( polynomial_order, element_type ) ) print("- QUADPY : {}".format(mass_integral_check)) print("- H2O : {}".format(mass_integral)) print( "STIFFNESS INTEGRAL CHECK | ORDER : {} | ELEM : {}".format( polynomial_order, element_type ) ) print("- QUADPY : {}".format(stif_integral_check)) print("- H2O : {}".format(stif_integral)) print( "ADVECTION INTEGRAL CHECK | ORDER : {} | ELEM : {}".format( polynomial_order, element_type ) ) print("- QUADPY : {}".format(advc_integral_check)) print("- H2O : {}".format(advc_integral)) np.testing.assert_allclose(mass_integral_check, mass_integral, rtol=rtol, atol=atol) np.testing.assert_allclose(stif_integral_check, stif_integral, rtol=rtol, atol=atol) np.testing.assert_allclose(advc_integral_check, advc_integral, rtol=rtol, atol=atol)
def test_operators_triangle(self): euclidean_dimension = 2 polynomial_orders = [1, 2, 3] element_types = [ElementType.HDG_LOW, ElementType.HDG_EQUAL, ElementType.HDG_HIGH] for polynomial_order in polynomial_orders: for element_type in element_types: # -------------------------------------------------------------------------------------------------------------- # DEFINE POLYNOMIAL ORDER AND INTEGRATION ORDER # -------------------------------------------------------------------------------------------------------------- finite_element = FiniteElement( element_type=element_type, polynomial_order=polynomial_order, euclidean_dimension=euclidean_dimension, ) field = Field("TEST", FieldType.DISPLACEMENT_SMALL_STRAIN_PLANE_STRAIN) # -------------------------------------------------------------------------------------------------------------- # DEFINE POLYNOMIAL BASIS # -------------------------------------------------------------------------------------------------------------- cell_basis_k = finite_element.cell_basis_k cell_basis_l = finite_element.cell_basis_l cell_basis_r = finite_element.cell_basis_r face_basis_k = finite_element.face_basis_k # -------------------------------------------------------------------------------------------------------------- # DEFINE RANDOM POLYNOMIAL COEFFICIENTS # -------------------------------------------------------------------------------------------------------------- range_min = -3.0 range_max = +3.0 coefficients_k_list = [] coefficients_l_list = [] coefficients_r_list = [] for _i in range(field.field_dimension): coefficients_k = np.array( [uniform(range_min, range_max) for _iloc in range(cell_basis_k.dimension)] ) coefficients_l = np.array( [uniform(range_min, range_max) for _iloc in range(cell_basis_l.dimension)] ) coefficients_r = np.array( [uniform(range_min, range_max) for _iloc in range(cell_basis_r.dimension)] ) coefficients_k_list.append(coefficients_k) coefficients_l_list.append(coefficients_l) coefficients_r_list.append(coefficients_r) # print("COEFS_K : \n{}".format(coefficients_k)) # print("COEFS_L : \n{}".format(coefficients_l)) # -------------------------------------------------------------------------------------------------------------- # DEFINE MONOMIAL VALUES COMPUTATION # -------------------------------------------------------------------------------------------------------------- def test_function( polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, coefficients: ndarray ) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter) ** _exponent[_x_dir] prod *= coefficients[_i] value += prod return value def test_function_derivative( polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, direction: int, coefficients: ndarray, ) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): if _x_dir == direction: _pt0 = point[_x_dir] - centroid[_x_dir] _pt1 = _pt0 / diameter if _exponent[_x_dir] == 0: _exp = _exponent[_x_dir] else: _exp = _exponent[_x_dir] - 1 _pt2 = _pt1 ** _exp # prod *= (_exponent[_x_dir] / diameter) * ( # ((point[_x_dir] - centroid[_x_dir]) / diameter) ** (_exponent[_x_dir] - 1) # ) prod *= (_exponent[_x_dir] / diameter) * _pt2 else: prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter) ** _exponent[_x_dir] prod *= coefficients[_i] value += prod return value # -------------------------------------------------------------------------------------------------------------- # DEFINE TRIANGLE COORDINATES # -------------------------------------------------------------------------------------------------------------- v0 = np.array([1.0, 1.7], dtype=real) v1 = np.array([2.0, 1.6], dtype=real) v2 = np.array([1.9, 3.0], dtype=real) triangle_vertices = np.array([v0, v1, v2], dtype=real).T # -------------------------------------------------------------------------------------------------------------- # BUILD CELL # -------------------------------------------------------------------------------------------------------------- cell_triangle = Shape(ShapeType.TRIANGLE, triangle_vertices) # -------------------------------------------------------------------------------------------------------------- # BUILD FACES # -------------------------------------------------------------------------------------------------------------- faces_segment = [ Shape(ShapeType.SEGMENT, triangle_vertices[:, [0, 1]]), Shape(ShapeType.SEGMENT, triangle_vertices[:, [1, 2]]), Shape(ShapeType.SEGMENT, triangle_vertices[:, [2, 0]]), ] def get_element_projection_vector(cell: Shape, faces: List[Shape], function: List[Callable]): _d = euclidean_dimension _dx = field.field_dimension _cl = cell_basis_l.dimension _fk = face_basis_k.dimension _nf = len(faces) _es = _dx * (_cl + _nf * _fk) # x_c = cell.centroid h_c = cell.diameter _io = finite_element.construction_integration_order cell_quadrature_points = cell.get_quadrature_points(_io) cell_quadrature_weights = cell.get_quadrature_weights(_io) cell_quadrature_size = cell.get_quadrature_size(_io) matrix = np.zeros((_es, _es), dtype=real) vector = np.zeros((_es,), dtype=real) for _dir in range(_dx): m_mas = np.zeros((_cl, _cl), dtype=real) vc = np.zeros((_cl,), dtype=real) for qc in range(cell_quadrature_size): x_q_c = cell_quadrature_points[:, qc] w_q_c = cell_quadrature_weights[qc] phi_l = cell_basis_l.evaluate_function(x_q_c, x_c, h_c) m_mas += w_q_c * np.tensordot(phi_l, phi_l, axes=0) vc += w_q_c * phi_l * function[_dir](x_q_c) _i = _cl * _dir _j = _cl * (_dir + 1) matrix[_i:_j, _i:_j] += m_mas vector[_i:_j] += vc for _f, face in enumerate(faces): face_rotation_matrix = get_rotation_matrix(face.type, face.vertices) x_f = face.centroid h_f = face.diameter # --- PROJECT ON HYPERPLANE s_f = (face_rotation_matrix @ x_f)[:-1] _io = finite_element.construction_integration_order face_quadrature_points = face.get_quadrature_points(_io) face_quadrature_weights = face.get_quadrature_weights(_io) face_quadrature_size = face.get_quadrature_size(_io) for _dir in range(_dx): m_mas_f = np.zeros((_fk, _fk), dtype=real) vf = np.zeros((_fk,), dtype=real) for qf in range(face_quadrature_size): x_q_f = face_quadrature_points[:, qf] w_q_f = face_quadrature_weights[qf] # s_f = (face_rotation_matrix @ x_f)[:-1] s_q_f = (face_rotation_matrix @ x_q_f)[:-1] psi_k = face_basis_k.evaluate_function(s_q_f, s_f, h_f) m_mas_f += w_q_f * np.tensordot(psi_k, psi_k, axes=0) vf += w_q_f * psi_k * function[_dir](x_q_f) _i = _cl * _dx + _f * _fk * _dx + _dir * _fk _j = _cl * _dx + _f * _fk * _dx + (_dir + 1) * _fk matrix[_i:_j, _i:_j] += m_mas_f vector[_i:_j] += vf projection_vector = np.linalg.solve(matrix, vector) return projection_vector def get_gradient_projection_vector(cell: Shape, function: Callable): _d = euclidean_dimension _dx = field.field_dimension _ck = cell_basis_k.dimension # x_c = cell.centroid h_c = cell.diameter _io = finite_element.construction_integration_order cell_quadrature_points = cell.get_quadrature_points(_io) cell_quadrature_weights = cell.get_quadrature_weights(_io) cell_quadrature_size = cell.get_quadrature_size(_io) matrix = np.zeros((_ck, _ck), dtype=real) vector = np.zeros((_ck,), dtype=real) for qc in range(cell_quadrature_size): x_q_c = cell_quadrature_points[:, qc] w_q_c = cell_quadrature_weights[qc] phi_k = cell_basis_k.evaluate_function(x_q_c, x_c, h_c) matrix += w_q_c * np.tensordot(phi_k, phi_k, axes=0) vector += w_q_c * phi_k * function(x_q_c) projection_vector = np.linalg.solve(matrix, vector) return projection_vector # fun = [ # lambda x: test_function( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # coefficients_l_list[0], # ), # lambda x: test_function( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # coefficients_l_list[1], # ) # ] # # fun_grad_regular = [ # [ # lambda x: test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[0], # ), # lambda x: test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[0], # ), # ], # [ # lambda x: test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[1], # ), # lambda x: test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[1], # ), # ], # ] # # fun_grad_symmetric = [ # [ # lambda x: (1.0 / 2.0) # * ( # test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[0], # ) # + test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[0], # ) # ), # lambda x: (1.0 / 2.0) # * ( # test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[0], # ) # + test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[1], # ) # ), # ], # [ # lambda x: (1.0 / 2.0) # * ( # test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 0, # coefficients_l_list[1], # ) # + test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[0], # ) # ), # lambda x: (1.0 / 2.0) # * ( # test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[1], # ) # + test_function_derivative( # finite_element.cell_basis_l.polynomial_order, # x, # cell_triangle.centroid, # cell_triangle.diameter, # 1, # coefficients_l_list[1], # ) # ), # ], # ] fun = [ lambda x: test_function( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, coefficients_r_list[0], ), lambda x: test_function( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, coefficients_r_list[1], ), ] fun_grad_regular = [ [ lambda x: test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[0], ), lambda x: test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[0], ), ], [ lambda x: test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[1], ), lambda x: test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[1], ), ], ] fun_grad_symmetric = [ [ lambda x: (1.0 / 2.0) * ( test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[0], ) + test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[0], ) ), lambda x: (1.0 / 2.0) * ( test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[0], ) + test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[1], ) ), ], [ lambda x: (1.0 / 2.0) * ( test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 0, coefficients_r_list[1], ) + test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[0], ) ), lambda x: (1.0 / 2.0) * ( test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[1], ) + test_function_derivative( finite_element.cell_basis_r.polynomial_order, x, cell_triangle.centroid, cell_triangle.diameter, 1, coefficients_r_list[1], ) ), ], ] # -------------------------------------------------------------------------------------------------------------- # BUILD AND TEST STABILIZATION # -------------------------------------------------------------------------------------------------------------- fun_proj = get_element_projection_vector(cell_triangle, faces_segment, fun) # stab_matrix, stab_matrix_0, stab_matrix2 = get_stabilization_operator(cell_triangle, faces_segment) stabilization_operator = stabop.get_stabilization_operator2( field, finite_element, cell_triangle, faces_segment ) print( "--- FUN PROJ | k : {} | l : {}".format( cell_basis_k.polynomial_order, cell_basis_l.polynomial_order ) ) print(fun_proj) print( "--- STABILIZATION | k : {} | l : {}".format( cell_basis_k.polynomial_order, cell_basis_l.polynomial_order ) ) stab_val = fun_proj @ stabilization_operator @ fun_proj print(stab_val) rtol = 1000000.0 atol = 1.0e-11 # np.testing.assert_allclose(stab_val, 0.0, rtol=rtol, atol=atol) correspondance = {0: (0, 0), 1: (1, 1), 2: (0, 1), 3: (1, 0)} for key, val in correspondance.items(): dir_x = val[0] dir_y = val[1] # rtol = 1.0e-12 # rtol = 1.0e-3 rtol = 1000000.0 atol = 1.0e-11 print( "--- SYMMETRIC GRADIENT | k : {} | l : {}".format( cell_basis_k.polynomial_order, cell_basis_l.polynomial_order ) ) fun_proj = get_element_projection_vector(cell_triangle, faces_segment, fun) grad_comp = gradop.get_symmetric_gradient_component_matrix( field, finite_element, cell_triangle, faces_segment, dir_x, dir_y ) # fun_grad_proj = get_gradient_projection_vector(cell_triangle, fun_grad_sym[choice]) # fun_grad_proj = get_gradient_projection_vector(cell_triangle, fun_grad_symmetric[dir_x][dir_y]) fun_grad_proj = get_gradient_projection_vector(cell_triangle, fun_grad_symmetric[dir_y][dir_x]) grad_check = grad_comp @ fun_proj print("- GRAD REC | {} | {}".format(dir_x, dir_y)) print(grad_check) print("- GRAD PROJ | {} | {}".format(dir_x, dir_y)) print(fun_grad_proj) np.testing.assert_allclose(grad_check, fun_grad_proj, rtol=rtol, atol=atol) print( "--- REGULAR GRADIENT | k : {} | l : {}".format( cell_basis_k.polynomial_order, cell_basis_l.polynomial_order ) ) fun_proj = get_element_projection_vector(cell_triangle, faces_segment, fun) grad_comp = gradop.get_regular_gradient_component_matrix( field, finite_element, cell_triangle, faces_segment, dir_x, dir_y ) # fun_grad_proj = get_gradient_projection_vector(cell_triangle, fun_grad_sym[choice]) fun_grad_proj = get_gradient_projection_vector(cell_triangle, fun_grad_regular[dir_x][dir_y]) grad_check = grad_comp @ fun_proj print("- GRAD REC | {} | {}".format(dir_x, dir_y)) print(grad_check) print("- GRAD PROJ | {} | {}".format(dir_x, dir_y)) print(fun_grad_proj) np.testing.assert_allclose(grad_check, fun_grad_proj, rtol=rtol, atol=atol)
def test_cook_small_strain_linear_elasticity(self): # --- VALUES time_steps = np.linspace(0.0, 6.0e-3, 50) P_min = 1. P_max = 70.e9 / 16. # P_min = 0.01 # P_max = 1. / 16. time_steps = np.linspace(P_min, P_max, 2) iterations = 100 # ------- P_min = 1000. P_max = 5.e6 / (16.e-3) # P_min = 0.01 # P_max = 1. / 16. # time_steps = np.linspace(P_min, P_max, 20)[:-3] time_steps = np.linspace(P_min, P_max, 5) print(time_steps) iterations = 10 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [Load(volumetric_load, 0), Load(volumetric_load, 1)] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("RIGHT", pull, BoundaryType.PRESSURE, 1), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 1), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), ] # --- MESH mesh_file_path = "meshes/cook_quadrangles_1.msh" mesh_file_path = "meshes/cook_quadrangles_0.msh" mesh_file_path = "meshes/cook_triangles_0.msh" mesh_file_path = "meshes/cook_30.geof" # mesh_file_path = "meshes/cook_5.geof" # --- FIELD # displacement = Field(label="U", field_type=FieldType.DISPLACEMENT_SMALL_STRAIN_PLANE_STRAIN) displacement = Field( label="U", field_type=FieldType.DISPLACEMENT_LARGE_STRAIN_PLANE_STRAIN) # --- FINITE ELEMENT finite_element = FiniteElement( element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=displacement.euclidean_dimension, basis_type=BasisType.MONOMIAL, ) # --- PROBLEM # p = Problem( # mesh_file_path=mesh_file_path, # field=displacement, # finite_element=finite_element, # time_steps=time_steps, # iterations=iterations, # boundary_conditions=boundary_conditions, # loads=loads, # quadrature_type=QuadratureType.GAUSS, # tolerance=1.0e-4, # res_folder_path=get_current_res_folder_path() # ) # --- MATERIAL parameters = {"YoungModulus": 70.0e9, "PoissonRatio": 0.4999} stabilization_parameter = 0.0005 * parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) # stabilization_parameter = parameters["YoungModulus"] / (1.0 + parameters["PoissonRatio"]) # mat = Material( # nq=p.mesh.number_of_cell_quadrature_points_in_mesh, # library_path="behaviour/src/libBehaviour.so", # library_name="Elasticity", # hypothesis=mgis_bv.Hypothesis.PLANESTRAIN, # stabilization_parameter=stabilization_parameter, # lagrange_parameter=parameters["YoungModulus"], # field=displacement, # parameters=None, # ) # --- SOLVE # solve_newton_2(p, mat, verbose=False, debug_mode=DebugMode.NONE) # solve_newton_exact(p, mat, verbose=False, debug_mode=DebugMode.NONE) res_folder = "res" from os import walk, path import matplotlib.pyplot as plt from matplotlib.colors import LinearSegmentedColormap def __plot(column: int): _, _, filenames = next(walk(res_folder)) for time_step_index in range(len(time_steps)): for filename in filenames: if "{}".format(time_step_index).zfill( 6) in filename and "qdp" in filename: hho_file_path = path.join(res_folder, filename) with open(hho_file_path, "r") as hho_res_file: fig, ax0d = plt.subplots(nrows=1, ncols=1) c_hho = hho_res_file.readlines() field_label = c_hho[0].split(",")[column] number_of_points = len(c_hho) - 1 eucli_d = displacement.euclidean_dimension points = np.zeros((eucli_d, number_of_points), dtype=real) field_vals = np.zeros((number_of_points, ), dtype=real) for l_count, line in enumerate(c_hho[1:]): x_coordinates = float(line.split(",")[0]) y_coordinates = float(line.split(",")[1]) field_value = float(line.split(",")[column]) points[0, l_count] += x_coordinates points[1, l_count] += y_coordinates field_vals[l_count] += field_value x, y = points colors = [(0, 0, 1), (0, 1, 1), (0, 1, 0), (1, 1, 0), (1, 0, 0)] perso = LinearSegmentedColormap.from_list("perso", colors, N=1000) # vmin = min(field_vals[:]) # vmax = max(field_vals[:]) vmin = -3900.e6 vmax = 627.e6 levels = np.linspace(vmin, vmax, 50, endpoint=True) ticks = np.linspace(vmin, vmax, 10, endpoint=True) datad = ax0d.tricontourf(x, y, field_vals[:], cmap=perso, levels=levels) ax0d.get_xaxis().set_visible(False) ax0d.get_yaxis().set_visible(False) ax0d.set_xlabel("map of the domain $\Omega$") cbar = fig.colorbar(datad, ax=ax0d, ticks=ticks) cbar.set_label("{}".format(field_label), rotation=270, labelpad=15.0) # plt.savefig("/home/dsiedel/Projects/pythhon/plots/{}.png".format(time_step)) plt.show() __plot(15)
def test_reference_polyhedron_cell(self, verbose=True): """ V3 o________________o V2 /| /| / | / | / | / | Y / | / | ^ V7 o________________o V6 | | | | | | 0---> X | V0 o___________|____o V1 / | / | / Z | / | / | / | / |/ |/ V4 o________________o V5 V3 o________________o V2 /| /| / | / | / | / | Y / | / | ^ V8 o________________o V7 | | | | | | 0---> X | V0 o___________|____o V1 / | / | / Z | / o V6 | / | / | / |/ |/ V4 o________________o V5 V2 o |\.. | \.. | \.. | \.. | \.. | \ o_V0_____________o V1 | / ..../ / ..../ / / ..../ :/.../ V2 o Args: verbose: Returns: """ euclidean_dimension = 3 polynomial_orders = [1, 2, 3] element_types = [ ElementType.HDG_LOW, ElementType.HDG_EQUAL, ElementType.HDG_HIGH ] for polynomial_order in polynomial_orders: for element_type in element_types: # --- DEFINE POLYNOMIAL ORDER AND INTEGRATION ORDER finite_element = FiniteElement( element_type=element_type, polynomial_order=polynomial_order, euclidean_dimension=euclidean_dimension, ) # --- DEFINE POLYNOMIAL BASIS cell_basis_k = finite_element.cell_basis_k cell_basis_l = finite_element.cell_basis_l # --- DEFINE RANDOM POLYNOMIAL COEFFICIENTS range_min = -3.0 range_max = +3.0 coefficients_k = np.array([ uniform(range_min, range_max) for _i in range(cell_basis_k.dimension) ]) coefficients_l = np.array([ uniform(range_min, range_max) for _i in range(cell_basis_l.dimension) ]) if verbose: print("COEFS_K : \n{}".format(coefficients_k)) print("COEFS_L : \n{}".format(coefficients_l)) # --- DEFINE MONOMIAL VALUES COMPUTATION def test_function(polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, coefficients: ndarray) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter)**_exponent[_x_dir] prod *= coefficients[_i] value += prod return value def test_function_derivative( polynomial_ord: int, point: ndarray, centroid: ndarray, diameter: float, direction: int, coefficients: ndarray, ) -> float: basis = Monomial(polynomial_ord, euclidean_dimension) value = 0.0 for _i, _exponent in enumerate(basis.exponents): prod = 1.0 for _x_dir in range(basis.exponents.shape[1]): if _x_dir == direction: # _pt0 = point[_x_dir] - centroid[_x_dir] # _pt1 = _pt0 / diameter # if _exponent[_x_dir] == 0: # _exp = _exponent[_x_dir] # else: # _exp = _exponent[_x_dir] - 1 # _pt2 = _pt1 ** _exp if _exponent[_x_dir] != 0: prod *= (_exponent[_x_dir] / diameter) * ( ((point[_x_dir] - centroid[_x_dir]) / diameter)**(_exponent[_x_dir] - 1)) else: prod *= 0.0 # prod *= (_exponent[_x_dir] / diameter) * _pt2 else: prod *= ((point[_x_dir] - centroid[_x_dir]) / diameter)**_exponent[_x_dir] prod *= coefficients[_i] value += prod return value # --- DEFINE TRIANGLE COORDINATES v0 = np.array([0.0, 0.0, 0.0], dtype=real) v1 = np.array([1.0, 0.0, 0.0], dtype=real) v2 = np.array([1.0, 1.0, 0.0], dtype=real) v3 = np.array([0.0, 1.0, 0.0], dtype=real) v4 = np.array([0.0, 0.0, 1.0], dtype=real) v5 = np.array([1.0, 0.0, 1.0], dtype=real) v6 = np.array([0.5, 0.5, 1.0], dtype=real) v7 = np.array([1.0, 1.0, 1.0], dtype=real) v8 = np.array([0.0, 1.0, 1.0], dtype=real) vertices = np.array([v0, v1, v2, v3, v4, v5, v6, v7, v8], dtype=real).T # --- CONNECTIVITY, COUNTER CLOCK WISE # connectivity = [ # [0, 3, 2, 1], # [0, 1, 5, 4], # [1, 2, 7, 5], # [2, 3, 8, 7], # [3, 0, 4, 8], # [4, 5, 6], # [5, 7, 6], # [7, 8, 6], # [8, 4, 6], # ] # --- CONNECTIVIY, CLOCK WISE connectivity = [ [0, 1, 2, 3], [0, 4, 5, 1], [1, 5, 7, 2], [2, 7, 8, 3], [3, 8, 4, 0], [6, 5, 4], [6, 7, 5], [6, 8, 7], [6, 4, 8], ] # --- BUILD CELL shape = Shape(ShapeType.POLYHEDRON, vertices, connectivity=connectivity) x_c = shape.get_centroid() h_c = shape.get_diameter() _io = finite_element.construction_integration_order cell_quadrature_points = shape.get_quadrature_points(_io) cell_quadrature_weights = shape.get_quadrature_weights(_io) cell_quadrature_size = shape.get_quadrature_size(_io) # --- CHECK INTEGRATION IN CELL bases = [cell_basis_k, cell_basis_l] # orders = [face_polynomial_order, cell_polynomial_order] coefs = [coefficients_k, coefficients_l] # scheme = quadpy.t2.get_good_scheme(2 * finite_element.construction_integration_order) scheme = quadpy.c3.get_good_scheme( finite_element.construction_integration_order) for basis_0, coef_0 in zip(bases, coefs): order_0 = basis_0.polynomial_order for basis_1, coef_1 in zip(bases, coefs): order_1 = basis_1.polynomial_order for _i in range(euclidean_dimension): for _j in range(euclidean_dimension): mass_mat = np.zeros( (basis_0.dimension, basis_1.dimension), dtype=real) stif_mat = np.zeros( (basis_0.dimension, basis_1.dimension), dtype=real) advc_mat = np.zeros( (basis_0.dimension, basis_1.dimension), dtype=real) for _qc in range(cell_quadrature_size): _x_qc = cell_quadrature_points[:, _qc] _w_qc = cell_quadrature_weights[_qc] phi_0 = basis_0.evaluate_function( _x_qc, x_c, h_c) phi_1 = basis_1.evaluate_function( _x_qc, x_c, h_c) d_phi_0_i = basis_0.evaluate_derivative( _x_qc, x_c, h_c, _i) d_phi_1_j = basis_1.evaluate_derivative( _x_qc, x_c, h_c, _j) mass_mat += _w_qc * np.tensordot( phi_0, phi_1, axes=0) stif_mat += _w_qc * np.tensordot( d_phi_0_i, d_phi_1_j, axes=0) advc_mat += _w_qc * np.tensordot( phi_0, d_phi_1_j, axes=0) mass_integral = coef_0 @ mass_mat @ coef_1 stif_integral = coef_0 @ stif_mat @ coef_1 advc_integral = coef_0 @ advc_mat @ coef_1 f_mass_check = lambda x: test_function( order_0, x, x_c, h_c, coef_0 ) * test_function(order_1, x, x_c, h_c, coef_1) f_stif_check = lambda x: test_function_derivative( order_0, x, x_c, h_c, _i, coef_0 ) * test_function_derivative( order_1, x, x_c, h_c, _j, coef_1) f_advc_check = lambda x: test_function( order_0, x, x_c, h_c, coef_0 ) * test_function_derivative( order_1, x, x_c, h_c, _j, coef_1) mass_integral_check = scheme.integrate( f_mass_check, [[[v0, v4], [v3, v8]], [[v1, v5], [v2, v7]]]) stif_integral_check = scheme.integrate( f_stif_check, [[[v0, v4], [v3, v8]], [[v1, v5], [v2, v7]]]) advc_integral_check = scheme.integrate( f_advc_check, [[[v0, v4], [v3, v8]], [[v1, v5], [v2, v7]]]) rtol = 1.0e-12 atol = 1.0e-12 if verbose: print( "MASS INTEGRAL CHECK | ORDER : {} | ELEM : {} | dir {}, {}, | order {}, {}" .format(polynomial_order, element_type, _i, _j, order_0, order_1)) print("- QUADPY : {}".format( mass_integral_check)) print("- H2O : {}".format(mass_integral)) print( "STIFFNESS INTEGRAL CHECK | ORDER : {} | ELEM : {} | dir {}, {} | order {}, {}" .format(polynomial_order, element_type, _i, _j, order_0, order_1)) print("- QUADPY : {}".format( stif_integral_check)) print("- H2O : {}".format(stif_integral)) print( "ADVECTION INTEGRAL CHECK | ORDER : {} | ELEM : {} | dir {}, {} | order {}, {}" .format(polynomial_order, element_type, _i, _j, order_0, order_1)) print("- QUADPY : {}".format( advc_integral_check)) print("- H2O : {}".format(advc_integral)) np.testing.assert_allclose(mass_integral_check, mass_integral, rtol=rtol, atol=atol) np.testing.assert_allclose(stif_integral_check, stif_integral, rtol=rtol, atol=atol) np.testing.assert_allclose(advc_integral_check, advc_integral, rtol=rtol, atol=atol)
def test_square_finite_strain_isotropic_voce_hardening(self): # --- VALUES spacing = 3 time_steps_1 = np.linspace(0.0, 7.0e-3, spacing) time_steps_2 = np.linspace(7.0e-3, -1.0e-2, spacing) time_steps_3 = np.linspace(-1.0e-2, 2.0e-2, spacing) time_steps_4 = np.linspace(2.0e-2, -3.0e-2, spacing) time_steps_5 = np.linspace(-3.0e-2, 4.0e-2, spacing) time_steps = [] for ts in [ time_steps_1, time_steps_2[1:], time_steps_3[1:], time_steps_4[1:], time_steps_5[1:] ]: # time_steps += list(np.sqrt(2.)*ts) time_steps += list(ts) time_steps = np.array(time_steps) time_steps = np.linspace(0.0, 4.0e-2, 11, endpoint=True) iterations = 100 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [Load(volumetric_load, 0), Load(volumetric_load, 1)] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("RIGHT", pull, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("BOTTOM", fixed, BoundaryType.DISPLACEMENT, 1), ] # --- MESH mesh_file_path = ( # "meshes/triang_r.geof" # "meshes/triang_2.geof" # "meshes/square_1.geof" # "meshes/pentag_1.geof" # "meshes/triangles_0.msh" "meshes/quadrangles_2.msh" # "meshes/quadrangles_0.msh" # "meshes/triangles_3.msh" # "meshes/triang_3.geof" ) # --- FIELD displacement = Field( label="U", field_type=FieldType.DISPLACEMENT_LARGE_STRAIN_PLANE_STRAIN) # --- FINITE ELEMENT finite_element = FiniteElement( element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=displacement.euclidean_dimension, basis_type=BasisType.MONOMIAL, ) # --- PROBLEM p = Problem(mesh_file_path=mesh_file_path, field=displacement, finite_element=finite_element, time_steps=time_steps, iterations=iterations, boundary_conditions=boundary_conditions, loads=loads, quadrature_type=QuadratureType.GAUSS, tolerance=1.0e-4, res_folder_path=get_current_res_folder_path()) # --- MATERIAL parameters = { "YoungModulus": 70.0e9, "PoissonRatio": 0.34, "HardeningSlope": 10.0e9, "YieldStress": 300.0e6 } stabilization_parameter = parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) mat = Material( nq=p.mesh.number_of_cell_quadrature_points_in_mesh, library_path="behaviour/src/libBehaviour.so", library_name="Voce", hypothesis=mgis_bv.Hypothesis.PLANESTRAIN, stabilization_parameter=stabilization_parameter, lagrange_parameter=parameters["YoungModulus"], field=displacement, parameters=None, # finite_strains=False ) # --- SOLVE solve_newton_2(p, mat, verbose=False) # solve_newton_exact(p, mat, verbose=False) # --- POST PROCESSING from pp.plot_data import plot_data mtest_file_path = "mtest/finite_strain_isotropic_voce_hardening.res" hho_res_dir_path = "res" number_of_time_steps = len(time_steps) m_x_inedx = 1 m_y_index = 6 d_x_inedx = 4 d_y_inedx = 9 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 7 d_x_inedx = 4 d_y_inedx = 10 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 8 d_x_inedx = 4 d_y_inedx = 11 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 9 d_x_inedx = 4 d_y_inedx = 12 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx)
def test_problem_build(self, verbose=True): # --- VALUES p_min = 0.0 p_max = 1. / 16. time_steps = np.linspace(p_min, p_max, 10) iterations = 100 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [Load(volumetric_load, 0), Load(volumetric_load, 1)] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("RIGHT", pull, BoundaryType.PRESSURE, 1), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 1), ] # --- MESH mesh_file_path = ("meshes/triang_r.geof") # --- FIELD displacement = Field( label="U", field_type=FieldType.DISPLACEMENT_SMALL_STRAIN_PLANE_STRAIN, ) # --- FINITE ELEMENT finite_element = FiniteElement(element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=2, basis_type=BasisType.MONOMIAL) # --- PROBLEM p = Problem(mesh_file_path=mesh_file_path, field=displacement, finite_element=finite_element, time_steps=time_steps, iterations=iterations, boundary_conditions=boundary_conditions, loads=loads, quadrature_type=QuadratureType.GAUSS, tolerance=1.0e-4, res_folder_path=get_current_res_folder_path()) # --- MATERIAL parameters = {"YoungModulus": 70.0e9, "PoissonRatio": 0.34} stabilization_parameter = parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) mat = Material( nq=p.mesh.number_of_cell_quadrature_points_in_mesh, library_path= "../../test_mechanics/test_element/2D/test_2D_small_strain_linear_elasticity/behaviour/src/libBehaviour.so", library_name="Elasticity", hypothesis=mgis_bv.Hypothesis.PLANESTRAIN, stabilization_parameter=stabilization_parameter, lagrange_parameter=parameters["YoungModulus"], field=displacement, parameters=None, # finite_strains=False ) # --- SOLVE solve_newton_2(p, mat)
def test_sphere_finite_strain(self): # --- VALUES time_steps = np.linspace(0.0, 6.0e-3, 150) iterations = 100 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [ Load(volumetric_load, 0), Load(volumetric_load, 1), Load(volumetric_load, 2) ] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("BOTTOM", pull, BoundaryType.DISPLACEMENT, 1), BoundaryCondition("RIGHT", fixed, BoundaryType.DISPLACEMENT, 2), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("INTERIOR", fixed, BoundaryType.PRESSURE, 0), ] # --- MESH mesh_file_path = "meshes/sphere_triangles_0.msh" # mesh_file_path = "meshes/ssna.msh" # mesh_file_path = "meshes/ssna_quad.msh" # mesh_file_path = "meshes/ssna303_triangles_1.msh" # --- FIELD displacement = Field(label="U", field_type=FieldType.DISPLACEMENT_LARGE_STRAIN) # --- FINITE ELEMENT finite_element = FiniteElement( element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=displacement.euclidean_dimension, basis_type=BasisType.MONOMIAL, ) # --- PROBLEM p = Problem(mesh_file_path=mesh_file_path, field=displacement, finite_element=finite_element, time_steps=time_steps, iterations=iterations, boundary_conditions=boundary_conditions, loads=loads, quadrature_type=QuadratureType.GAUSS, tolerance=1.0e-4, res_folder_path=get_current_res_folder_path()) # --- MATERIAL parameters = { "YoungModulus": 70.0e9, "PoissonRatio": 0.34, "HardeningSlope": 10.0e9, "YieldStress": 300.0e6 } # stabilization_parameter = 0.001 * parameters["YoungModulus"] / (1.0 + parameters["PoissonRatio"]) stabilization_parameter = parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) mat = Material( nq=p.mesh.number_of_cell_quadrature_points_in_mesh, library_path="behaviour/src/libBehaviour.so", library_name="Voce", # library_name="FiniteStrainIsotropicLinearHardeningPlasticity", hypothesis=mgis_bv.Hypothesis.TRIDIMENSIONAL, stabilization_parameter=stabilization_parameter, lagrange_parameter=parameters["YoungModulus"], field=displacement, parameters=None, ) # --- SOLVE solve_newton_2(p, mat, verbose=False, debug_mode=DebugMode.NONE) # solve_newton_exact(p, mat, verbose=False, debug_mode=DebugMode.NONE) from pp.plot_ssna import plot_det_f
def test_square_small_strain_linear_elasticity(self): # --- VALUES u_min = 0.0 u_max = 0.008 time_steps = np.linspace(u_min, u_max, 9) iterations = 100 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [Load(volumetric_load, 0), Load(volumetric_load, 1)] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("RIGHT", pull, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), BoundaryCondition("BOTTOM", fixed, BoundaryType.DISPLACEMENT, 1), ] # --- MESH mesh_file_path = ( # "meshes/triang_r.geof" # "meshes/triang_2.geof" # "meshes/square_1.geof" # "meshes/pentag_1.geof" # "meshes/triangles_0.msh" "meshes/quadrangles_0.msh" # "meshes/triang_3.geof" ) # --- FIELD displacement = Field( label="U", field_type=FieldType.DISPLACEMENT_SMALL_STRAIN_PLANE_STRAIN) # --- FINITE ELEMENT finite_element = FiniteElement( element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=displacement.euclidean_dimension, basis_type=BasisType.MONOMIAL, ) # --- PROBLEM p = Problem(mesh_file_path=mesh_file_path, field=displacement, finite_element=finite_element, time_steps=time_steps, iterations=iterations, boundary_conditions=boundary_conditions, loads=loads, quadrature_type=QuadratureType.GAUSS, tolerance=1.0e-4, res_folder_path=get_current_res_folder_path()) # --- MATERIAL parameters = {"YoungModulus": 70.0e9, "PoissonRatio": 0.34} stabilization_parameter = parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) mat = Material( nq=p.mesh.number_of_cell_quadrature_points_in_mesh, library_path="behaviour/src/libBehaviour.so", library_name="Elasticity", hypothesis=mgis_bv.Hypothesis.PLANESTRAIN, stabilization_parameter=stabilization_parameter, lagrange_parameter=parameters["YoungModulus"], field=displacement, parameters=None, ) # --- SOLVE solve_newton_2(p, mat, verbose=False) # solve_newton_exact(p, mat, verbose=False) # --- POST PROCESSING from pp.plot_data import plot_data mtest_file_path = "mtest/small_strain_linear_elasticity.res" hho_res_dir_path = "res" number_of_time_steps = len(time_steps) m_x_inedx = 1 m_y_index = 5 d_x_inedx = 4 d_y_inedx = 8 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 6 d_x_inedx = 4 d_y_inedx = 9 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 7 d_x_inedx = 4 d_y_inedx = 10 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx) m_x_inedx = 1 m_y_index = 8 d_x_inedx = 4 d_y_inedx = 11 plot_data(mtest_file_path, hho_res_dir_path, number_of_time_steps, m_x_inedx, m_y_index, d_x_inedx, d_y_inedx)
def test_cook_finite_strain_voce_isotropic_hardening(self): # --- VALUES time_steps = np.linspace(0.0, 7.0e-3, 50) time_steps = np.linspace(0.0, 14.e-3, 150) P_min = 0.0 P_max = 5.e6 / (16.e-3) # P_max = 3.e8 # P_min = 0.01 # P_max = 1. / 16. # time_steps = np.linspace(P_min, P_max, 20)[:-3] time_steps = np.linspace(P_min, P_max, 10) time_steps = list(time_steps) + [P_max] print(time_steps) iterations = 10 # --- LOAD def volumetric_load(time: float, position: ndarray): return 0 loads = [Load(volumetric_load, 0), Load(volumetric_load, 1)] # --- BC def pull(time: float, position: ndarray) -> float: return time def fixed(time: float, position: ndarray) -> float: return 0.0 boundary_conditions = [ BoundaryCondition("RIGHT", pull, BoundaryType.PRESSURE, 1), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 1), BoundaryCondition("LEFT", fixed, BoundaryType.DISPLACEMENT, 0), ] # --- MESH mesh_file_path = "meshes/cook_5.geof" # mesh_file_path = "meshes/cook_30.geof" # mesh_file_path = "meshes/cook_quadrangles_1.msh" # mesh_file_path = "meshes/cook_quadrangles_0.msh" # mesh_file_path = "meshes/cook_20_quadrangles_structured.msh" # mesh_file_path = "meshes/cook_01_quadrangles_structured.msh" # mesh_file_path = "meshes/cook_10_triangles_structured.msh" mesh_file_path = "meshes/cook_16_triangles_structured.msh" # --- FIELD displacement = Field( label="U", field_type=FieldType.DISPLACEMENT_LARGE_STRAIN_PLANE_STRAIN) # --- FINITE ELEMENT finite_element = FiniteElement( element_type=ElementType.HDG_EQUAL, polynomial_order=1, euclidean_dimension=displacement.euclidean_dimension, basis_type=BasisType.MONOMIAL, ) # --- PROBLEM p = Problem(mesh_file_path=mesh_file_path, field=displacement, finite_element=finite_element, time_steps=time_steps, iterations=iterations, boundary_conditions=boundary_conditions, loads=loads, quadrature_type=QuadratureType.GAUSS, tolerance=1.0e-6, res_folder_path=get_current_res_folder_path()) # --- MATERIAL parameters = { "YoungModulus": 206.e9, "PoissonRatio": 0.29, "HardeningSlope": 10.0e9, "YieldStress": 300.0e6 } # stabilization_parameter = 1000. * parameters["YoungModulus"] / (1.0 + parameters["PoissonRatio"]) stabilization_parameter = 0.00005 * parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) stabilization_parameter = 0.001 * parameters["YoungModulus"] / ( 1.0 + parameters["PoissonRatio"]) # stabilization_parameter = 0.0000 * parameters["YoungModulus"] / (1.0 + parameters["PoissonRatio"]) # stabilization_parameter = 1.0 * parameters["YoungModulus"] / (1.0 + parameters["PoissonRatio"]) mat = Material( nq=p.mesh.number_of_cell_quadrature_points_in_mesh, library_path="behaviour/src/libBehaviour.so", library_name="Voce", hypothesis=mgis_bv.Hypothesis.PLANESTRAIN, stabilization_parameter=stabilization_parameter, lagrange_parameter=parameters["YoungModulus"], field=displacement, parameters=None, ) # --- SOLVE solve_newton_2(p, mat, verbose=False, debug_mode=DebugMode.NONE) # solve_newton_exact(p, mat, verbose=False, debug_mode=DebugMode.NONE) from pp.plot_ssna import plot_det_f # plot_det_f(46, "res") res_folder = "res" # res_folder = "/home/dsiedel/projetcs/h2o/tests/test_mechanics/test_cook_finite_strain_isotropic_voce_hardening/res_cook_20_ord1_quad/res" from os import walk, path import matplotlib.pyplot as plt from matplotlib.colors import LinearSegmentedColormap def __plot(column: int, time_step_index: int): _, _, filenames = next(walk(res_folder)) # for time_step_index in range(1, len(time_steps)): # for time_step_index in range(30, len(time_steps)): for filename in filenames: if "{}".format(time_step_index).zfill( 6) in filename and "qdp" in filename: hho_file_path = path.join(res_folder, filename) with open(hho_file_path, "r") as hho_res_file: fig, ax0d = plt.subplots(nrows=1, ncols=1) c_hho = hho_res_file.readlines() field_label = c_hho[0].split(",")[column] number_of_points = len(c_hho) - 1 # for _iloc in range(len(c_hho)): # line = c_hho[_iloc] # x_coordinates = float(line.split(",")[0]) # y_coordinates = float(line.split(",")[1]) # if (x_coordinates - 0.0) ** 2 + (y_coordinates) eucli_d = displacement.euclidean_dimension points = np.zeros((eucli_d, number_of_points), dtype=real) field_vals = np.zeros((number_of_points, ), dtype=real) field_min_val = np.inf field_max_val = -np.inf for l_count, line in enumerate(c_hho[1:]): x_coordinates = float(line.split(",")[0]) y_coordinates = float(line.split(",")[1]) field_value = float(line.split(",")[column]) points[0, l_count] += x_coordinates points[1, l_count] += y_coordinates field_vals[l_count] += field_value # if field_vals[l_count] x, y = points colors = [(0, 0, 1), (0, 1, 1), (0, 1, 0), (1, 1, 0), (1, 0, 0)] # perso = LinearSegmentedColormap.from_list("perso", colors, N=1000) perso = LinearSegmentedColormap.from_list("perso", colors, N=20) vmin = min(field_vals[:]) vmax = max(field_vals[:]) # vmin = 300.e6 # vmax = 400.e6 # vmin = 8.e8/3. # vmax = 12.e8/3. # levels = np.linspace(vmin, vmax, 50, endpoint=True) levels = np.linspace(vmin, vmax, 20, endpoint=True) ticks = np.linspace(vmin, vmax, 10, endpoint=True) datad = ax0d.tricontourf(x, y, field_vals[:], cmap=perso, levels=levels) ax0d.get_xaxis().set_visible(False) ax0d.get_yaxis().set_visible(False) ax0d.set_xlabel("map of the domain $\Omega$") cbar = fig.colorbar(datad, ax=ax0d, ticks=ticks) cbar.set_label("{} : {}".format( field_label, time_step_index), rotation=270, labelpad=15.0) # plt.savefig("/home/dsiedel/Projects/pythhon/plots/{}.png".format(time_step)) plt.show() for tsindex in [1, 50, 100, 192]: # __plot(15, tsindex) pass # __plot(15, 19) __plot(15, 34)