Boundary constraints on a section of an edge of the geometry

The problem that I am working on demands for constraints on a section of edge of the problem geometry. The issue can be illustrated using the following diagram.

I want my constraints to be imposed on BC portion of the edge AD. In my case I tried imposing the constraint as follows

    rec = Rectangle((0, -0.3), (13.0, 0.7))
    IC_s = PointwiseBoundaryConstraint(
        nodes=nodes,
        geometry=rec,
        outvar={"c": 1.0},
        batch_size=cfg.batch_size.IC,
        parameterization={t_symbol: 0.0, x:(6.5,7.5), y:0.7},
    )
    domain.add_constraint(IC_s, "IC_s")

But I was running into an error as depicted below

Error executing job with overrides: []
Traceback (most recent call last):
  File "SingleGeom.py", line 84, in run
    IC_s = PointwiseBoundaryConstraint(
  File "/modulus/modulus/domain/constraint/continuous.py", line 276, in __init__
    invar = geometry.sample_boundary(
  File "/modulus/modulus/geometry/geometry.py", line 479, in sample_boundary
    assert np.sum(curve_areas) > 0, "Geometry has no surface"
AssertionError: Geometry has no surface

This error is thrown only if the constraint is imposed on an intermediate portion or a point of geometry edge. For example, there’s no error if “x: (6.5,7.5)” is not specified under parametrization option of PointwiseBoundaryConstraint(). Also, the program runs fine if ‘x’ is at one of the corners (i.e. x=0 or x =13) of problem geometry.

Is there a way around this issue?

Hi @shubhamsp2195 ,

First, have you considered using the Line primitives instead of the Rectangle? This way you’d be able to break apart your domain into line segments:

Geometry in Modulus Docs

Second option, and probably the one that requires least modification to your code, is that you could retain your rectangle geometry but make use of the ‘criteria’ argument for PointwiseBoundaryConstraint.

PointwiseBC in Modulus Docs

I’m not sure I have the numbers right, but you could use something like:

IC_s = PointwiseBoundaryConstraint(
        nodes=nodes,
        geometry=original_geometry_instead_of_rec,
        outvar={"c": 1.0},
        batch_size=cfg.batch_size.IC,
        criteria=And((x>6.5), (x<7.5),(y>0.5))
        parameterization={t_symbol: 0.0, x:(6.5,7.5), y:0.7},
    )

Make sure you get the logical operators from Sympy if you take this approach:

from sympy import Symbol, Or, And

Hi @patterson ,
Thank you for sharing this information.
I tried the second option suggested by you where very few modifications are needed. I hope that you wanted the parameterization to include

parameterization={t_symbol: 0.0},

instead of

parameterization={t_symbol: 0.0, x:(6.5,7.5), y:0.7},

There’s no error if (y>0.5) is used under “criteria”. But imposing y==0.7 leads to similar issues.
Also, I feel that the functionality of “criteria” is the same as that of “parameterization”. What I mean is that the “criteria” option is performing the same operation as achieved with ranges for variables in “parameterization” (My earlier approach).

Hi @shubhamsp2195 ,

If you’ve set up the problem to parameterize t_symbol, then your parameterization with only t_symbol should be correct. If you are also parameterizing the location of the location/size of the BC line then you would need to include x and y in the parameterization.

Is there a reason you need to use y== 0.7? If you are using a boundary constraint and the boundary is above the threshold you pick (I picked 0.5 somewhat arbitrarily, it was greater than -0.3 and less than 0.7 so it would only pick points from the top line when combined with the x-location criteria). You could test that the PointwiseBoundaryConstraint is only sampling from the boundary by sampling the boundary of the rectangle with the same criteria:

sample_dictionary = rec.sample_boundary(nr_points = 50, criteria=And((x>6.5), (x<7.5),(y>0.5)))
print(sample_dictionary)

If you need to specify y is a specific value instead of just greater than something else, you could use sympy Eq:

import Symbol, Eq, Or, And

The Three Fin example has a few cases of this:

    constraint_outlet = PointwiseBoundaryConstraint(
        nodes=flow_nodes,
        geometry=geo.outlet,
        outvar={"p": 0},
        batch_size=cfg.batch_size.Outlet,
        criteria=Eq(x, channel_origin[0] + channel_dim[0]),
        lambda_weighting={"p": 1.0},
        parameterization=geo.pr,
        batch_per_epoch=5000,
    )
    flow_domain.add_constraint(constraint_outlet, "outlet")

Three Fin example in Gitlab

I disagree about the criteria vs parameterization. Criteria are used for sampling points for Boundary or Interior Samples within given ranges and specifying regions where Constraints are applied, either on a Boundary or an Interior. Parameterization is a modification of how constraints are formulated and applied and how the architecture is formulated:

Parameterized Geometry in the documentation

2 Likes

Hi @patterson
Thanks a lot. This indeed would be very helpful for me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.