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)
示例#2
0
class Walls(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and (
            abs(x[0]) < DOLFIN_EPS or abs(x[1] - D - t - S) < DOLFIN_EPS or
            ((x[1] <= L or x[1] >= L + t) and abs(x[0] - D) < DOLFIN_EPS) or
            (x[0] >= D and
             (abs(x[1] - L) < DOLFIN_EPS or abs(x[1] - L - t) < DOLFIN_EPS)))


boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
inlet = Inlet()
inlet_ID = 1
inlet.mark(boundaries, inlet_ID)
outlet = Outlet()
outlet_ID = 2
outlet.mark(boundaries, outlet_ID)
walls = Walls()
walls_ID = 3
walls.mark(boundaries, walls_ID)

# Save to xml file
VerticesMappingIO.save_file(vertices_mappings, ".",
                            "t_bypass_vertices_mapping.vmp")
File("t_bypass.xml") << mesh
File("t_bypass_physical_region.xml") << subdomains
File("t_bypass_facet_region.xml") << boundaries
XDMFFile("t_bypass.xdmf").write(mesh)
XDMFFile("t_bypass_physical_region.xdmf").write(subdomains)
XDMFFile("t_bypass_facet_region.xdmf").write(boundaries)
示例#3
0
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
示例#4
0

boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
bottomInner = BottomInner()
bottomInner.mark(boundaries, 1)
leftInner = LeftInner()
leftInner.mark(boundaries, 2)
topInner = TopInner()
topInner.mark(boundaries, 3)
rightInner = RightInner()
rightInner.mark(boundaries, 4)
bottomOuter = BottomOuter()
bottomOuter.mark(boundaries, 5)
leftOuter = LeftOuter()
leftOuter.mark(boundaries, 6)
topOuter = TopOuter()
topOuter.mark(boundaries, 7)
rightOuter = RightOuter()
rightOuter.mark(boundaries, 8)

# Save
VerticesMappingIO.save_file(vertices_mappings, ".",
                            "hole_vertices_mapping.vmp")
File("hole.xml") << mesh
File("hole_physical_region.xml") << subdomains
File("hole_facet_region.xml") << boundaries
XDMFFile("hole.xdmf").write(mesh)
XDMFFile("hole_physical_region.xdmf").write(subdomains)
XDMFFile("hole_facet_region.xdmf").write(boundaries)
示例#5
0
class Bottom(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and abs(x[1] + 1.0) < DOLFIN_EPS


class Top(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and abs(x[1] - 1.0) < DOLFIN_EPS


boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
bottom = Bottom()
bottom.mark(boundaries, 1)
left = Left()
left.mark(boundaries, 4)  ##########
right = Right()
right.mark(boundaries, 2)
top = Top()
top.mark(boundaries, 3)  ##########

VerticesMappingIO.save_file(vertices_mappings, ".",
                            "cellAffine_vertices_mapping.vmp")
File("cellAffine.xml") << mesh
File("cellAffine_physical_region.xml") << subdomains
File("cellAffine_facet_region.xml") << boundaries

# plot(mesh)
# plt.show()