def test_affine_shape_parametrization_from_vertices_mapping_hole(): filename = "vertices_mapping_hole" assert VerticesMappingIO.exists_file(data_dir, filename) vertices_mappings = VerticesMappingIO.load_file(data_dir, filename) shape_parametrization_expression = [ affine_shape_parametrization_from_vertices_mapping(2, vertices_mapping) for vertices_mapping in vertices_mappings] # Auxiliary symbolic quantities x = MatrixSymbol("x", 2, 1) mu = MatrixSymbol("mu", 2, 1) # Start checks assert len(shape_parametrization_expression) == 8 # Check subdomain 1 assert len(shape_parametrization_expression[0]) == 2 assert symbolic_equal( shape_parametrization_expression[0][X], "2 - 2 * mu[0] + mu[0] * x[0] + (2 - 2 * mu[0]) * x[1]", x, mu) assert symbolic_equal( shape_parametrization_expression[0][Y], "2 - 2 * mu[1] + (2 - mu[1]) * x[1]", x, mu) # Check subdomain 2 assert len(shape_parametrization_expression[1]) == 2 assert symbolic_equal( shape_parametrization_expression[1][X], "2 * mu[0]- 2 + x[0] + (mu[0] - 1) * x[1]", x, mu) assert symbolic_equal( shape_parametrization_expression[1][Y], "2 - 2 * mu[1] + (2 - mu[1]) * x[1]", x, mu) # Check subdomain 3 assert len(shape_parametrization_expression[2]) == 2 assert symbolic_equal( shape_parametrization_expression[2][X], "2 - 2 * mu[0] + (2 - mu[0]) * x[0]", x, mu) assert symbolic_equal( shape_parametrization_expression[2][Y], "2 - 2 * mu[1] + (2- 2*mu[1]) * x[0] + mu[1] * x[1]", x, mu) # Check subdomain 4 assert len(shape_parametrization_expression[3]) == 2 assert symbolic_equal( shape_parametrization_expression[3][X], "2 - 2 * mu[0] + (2 - mu[0]) * x[0]", x, mu) assert symbolic_equal( shape_parametrization_expression[3][Y], "2 * mu[1] - 2 + (mu[1] - 1) * x[0] + x[1]", x, mu) # Check subdomain 5 assert len(shape_parametrization_expression[4]) == 2 assert symbolic_equal( shape_parametrization_expression[4][X], "2 * mu[0] - 2 + (2 - mu[0]) * x[0]", x, mu) assert symbolic_equal( shape_parametrization_expression[4][Y], "2 - 2 * mu[1] + (2 * mu[1]- 2) * x[0] + mu[1] * x[1]", x, mu) # Check subdomain 6 assert len(shape_parametrization_expression[5]) == 2 assert symbolic_equal( shape_parametrization_expression[5][X], "2 * mu[0] - 2 + (2 - mu[0]) * x[0]", x, mu) assert symbolic_equal( shape_parametrization_expression[5][Y], "2 * mu[1] - 2 + (1 - mu[1]) * x[0] + x[1]", x, mu) # Check subdomain 7 assert len(shape_parametrization_expression[6]) == 2 assert symbolic_equal( shape_parametrization_expression[6][X], "2 - 2 * mu[0] + mu[0] * x[0] + (2 * mu[0] - 2) * x[1]", x, mu) assert symbolic_equal( shape_parametrization_expression[6][Y], "2 * mu[1] - 2 + (2 - mu[1]) * x[1]", x, mu) # Check subdomain 8 assert len(shape_parametrization_expression[7]) == 2 assert symbolic_equal( shape_parametrization_expression[7][X], "2 * mu[0] - 2 + x[0] + (1 - mu[0]) * x[1]", x, mu) assert symbolic_equal( shape_parametrization_expression[7][Y], "2 * mu[1] - 2 + (2 - mu[1]) * x[1]", x, mu)
def AffineShapeParametrizationDecoratedProblem(*shape_parametrization_vertices_mappings, **decorator_kwargs): if "shape_parametrization_vertices_mappings" in decorator_kwargs: assert len(shape_parametrization_vertices_mappings) is 0 shape_parametrization_vertices_mappings = decorator_kwargs["shape_parametrization_vertices_mappings"] # Possibly read vertices mappings from file if ( len(shape_parametrization_vertices_mappings) is 1 and isinstance(shape_parametrization_vertices_mappings[0], str) ): filename = shape_parametrization_vertices_mappings[0] assert filename != "identity", "It does not make any sense to use this if you only have one subdomain without parametrization" assert VerticesMappingIO.exists_file("", filename) shape_parametrization_vertices_mappings = VerticesMappingIO.load_file("", filename) # Detect the mesh dimension based on the number of vertices to be mapped dim = None for vertices_mapping in shape_parametrization_vertices_mappings: if isinstance(vertices_mapping, str): assert vertices_mapping.lower() == "identity" continue else: assert isinstance(vertices_mapping, dict) assert len(vertices_mapping) in (3, 4) if len(vertices_mapping) is 3: if dim is None: dim = 2 else: assert dim is 2 elif len(vertices_mapping) is 4: if dim is None: dim = 3 else: assert dim is 3 assert dim is not None, "It does not make any sense to use this of all your subdomains are not parametrized" # Get the shape parametrization expression from vertices mappings shape_parametrization_expression = [affine_shape_parametrization_from_vertices_mapping(dim, vertices_mapping) for vertices_mapping in shape_parametrization_vertices_mappings] if decorator_kwargs.get("debug", False): print("=== DEBUGGING AFFINE SHAPE PARAMETRIZATION ===") for (subdomain, (vertices_mapping, expression)) in enumerate(zip(shape_parametrization_vertices_mappings, shape_parametrization_expression)): print("Subdomain", subdomain + 1) print("\tvertices mapping =", vertices_mapping) print("\tshape parametrization expression =", expression) decorator_kwargs.pop("debug", None) # Apply the parent decorator AffineShapeParametrizationDecoratedProblem_Decorator_Base = ShapeParametrizationDecoratedProblem(*shape_parametrization_expression, **decorator_kwargs) # Further decorate the resulting class from rbnics.shape_parametrization.problems.affine_shape_parametrization import AffineShapeParametrization @ProblemDecoratorFor(AffineShapeParametrization, shape_parametrization_vertices_mappings=shape_parametrization_vertices_mappings) def AffineShapeParametrizationDecoratedProblem_Decorator(ParametrizedDifferentialProblem_DerivedClass): AffineShapeParametrizationDecoratedProblem_Class = AffineShapeParametrizationDecoratedProblem_Decorator_Base(ParametrizedDifferentialProblem_DerivedClass) # return value (a class) for the decorator return AffineShapeParametrizationDecoratedProblem_Class # return the decorator itself return AffineShapeParametrizationDecoratedProblem_Decorator