Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

93 resolutionspec insideoutside entity #100

Merged
merged 8 commits into from
Dec 8, 2024

Conversation

simbilod
Copy link
Owner

@simbilod simbilod commented Dec 8, 2024

add restrict field

@simbilod simbilod linked an issue Dec 8, 2024 that may be closed by this pull request
@simbilod
Copy link
Owner Author

simbilod commented Dec 8, 2024

@fedeinthemix this PR adds a new attribute to ThresholdField and ExponentialField to restrict the field to a list of entities

This allows these fields to be only applied to one side of an interface. Should be useful for skin effect as discussed in #91

For instance:

for restrict_to in [None, ["inner_left"],  ["inner_right"],  ["outer", "inner_right"]]: 
    large_rect = 20
    small_rect = 5

    polygon1 = shapely.Polygon(
        [[0, 0], [large_rect, 0], [large_rect, large_rect], [0, large_rect], [0, 0]],
    )
    polygon2 = shapely.Polygon(
        [
            [large_rect / 2 - small_rect / 2, large_rect / 2 - small_rect / 2],
            [large_rect / 2 + small_rect / 2, large_rect / 2 - small_rect / 2],
            [large_rect / 2 + small_rect / 2, large_rect / 2 + small_rect / 2],
            [large_rect / 2 - small_rect / 2, large_rect / 2 + small_rect / 2],
            [large_rect / 2 - small_rect / 2, large_rect / 2 - small_rect / 2],
        ],
    )

    model = Model(n_threads=1)
    poly_outer = PolySurface(
        polygons=polygon1,
        model=model,
        mesh_order=2,
        physical_name="outer",
    )
    poly_left = PolySurface(
        polygons=shapely.affinity.translate(polygon2, xoff=-3.1),
        model=model,
        mesh_order=1,
        physical_name="inner_left",
        resolutions=[
            ThresholdField(
                sizemin=0.05,
                distmax=10,
                sizemax=1,
                apply_to="curves",
                restrict_to=restrict_to, # new argument
            )
        ],
    )
    poly_right = PolySurface(
        polygons=shapely.affinity.translate(polygon2, xoff=3.1),
        model=model,
        mesh_order=1,
        physical_name="inner_right",
    )
    entities_list = [poly_outer, poly_left, poly_right]
    model.mesh(
        entities_list=entities_list,
        default_characteristic_length=1,
        verbosity=0,
        filename=f"mesh_restrict_{restrict_to}.msh",
    )

Gives:

None (old behavior, default, isotropic field)

image

["inner_left"] (apply only inside)

image

["outer", "inner_right"] (apply only to the others listed)

image

You can add multiple fields to control the different interfaces differently:

    """Test different threshold fields on each side of an interface."""
    # Create outer square
    outer_square = shapely.Polygon([
        [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]
    ])

    # Create inner square
    inner_square = shapely.Polygon([
        [4, 4], [6, 4], [6, 6], [4, 6], [4, 4]
    ])

    model = Model(n_threads=1)

    # Create outer polysurface with coarser exponential field
    poly_outer = PolySurface(
        polygons=outer_square,
        model=model,
        mesh_order=2,
        physical_name="outer",
        resolutions=[
            ExponentialField(
                sizemin=0.05,
                lengthscale=2.0,
                growth_factor=3,
                apply_to="curves",
                not_sharing=["None"],
                restrict_to=["outer"]
            )
        ]
    )

    # Create inner polysurface with finer exponential field
    poly_inner = PolySurface(
        polygons=inner_square,
        model=model,
        mesh_order=1,
        physical_name="inner",
        resolutions=[
            ExponentialField(
                sizemin=0.05
                lengthscale=0.5,  # Shorter transition distance
                growth_factor=3.0,
                apply_to="curves",
                restrict_to=["inner"]
            )
        ]
    )

    # Mesh the model
    model.mesh(
        entities_list=[poly_outer, poly_inner],
        default_characteristic_length=2.0,  # Increased default size
        verbosity=0,
        filename="mesh_interface_thresholds.msh"
    )

image

Closes #93

@simbilod simbilod merged commit 05ba28b into main Dec 8, 2024
2 checks passed
@fedeinthemix
Copy link

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ResolutionSpec inside/outside entity
2 participants