underworld3 icon indicating copy to clipboard operation
underworld3 copied to clipboard

New BC interface: add_bc()

Open julesghub opened this issue 1 year ago • 10 comments

Unifying the two BC functions add_dirichlet and add_natural in generic solvers.pyx

  • The single add_bc() function is much easier to maintain.
  • Improvements in the handling of what 'conds' can be was also made.

def add_bc(bc_type, cond, boundary, components)
Parameters
----------
type: string
    BC type. Either 'dirichlet' (essential) or 'neumman' (natural) conditions.
conds: array_like of floats or a sympy.Matrix
    eg. For a 3D model with an unconstraint x component: (None, 5, 1.2) or sympy.Matrix([sympy.oo, 5, 1.2])
boundary: string
    The label name to apply the BC. To find a boundary name run something like
    [print(x) for x in mesh.boundaries]
components: array_like, single int value or None.
    (optional) tuple, or int of active conds components to use. Use 'None' for all conds to be used.
    If 'None' and components in 'cond' equal sympy.oo or -sympy.oo those components won't be used.
    eg. For the 3D example cond = (2, 5, 1.2), components = (1,2) the x components is ignored and uncontrainted.
"""

Existing functions add_dirichlet / add_natural now point to new add_bc() and are there to support existing models.

julesghub avatar May 22 '24 06:05 julesghub

@lmoresi @jcgraciosa please have a look - we can discuss tomorrow.

julesghub avatar May 22 '24 06:05 julesghub

One comment. To find boundary names, use uwmesh.view() ... that's not programmatic, of course, but it is a central place for information. For example:

Mesh # 0: tmp_shear_inclusion.msh

| Variable Name       | component | degree |     type        |
| ---------------------------------------------------------- |
| U                   |    2      |   2    |     VECTOR      |
| P                   |    1      |   1    |     SCALAR      |
| Stress              |    3      |   2    |   SYM_TENSOR    |
| eps_dot             |    1      |   2    |     SCALAR      |
| tau                 |    1      |   2    |     SCALAR      |
| psi_star_sl_1_0     |    3      |   1    |   SYM_TENSOR    |
| ---------------------------------------------------------- |


| Boundary Name            | ID    | Min Size | Max Size |
| ------------------------------------------------------ |
| bottom                   | 1     | 79       | 79       |
| right                    | 2     | 27       | 27       |
| top                      | 3     | 79       | 79       |
| left                     | 4     | 27       | 27       |
| inclusion                | 5     | 51       | 51       |
| All_Boundaries           | 1001  | 135      | 135      |
| ------------------------------------------------------ |

lmoresi avatar May 22 '24 07:05 lmoresi

Nice - i'll add the suggestion. Thanks @lmoresi

julesghub avatar May 22 '24 07:05 julesghub

How about also adding variable_type in the add_bc function? This way, users can easily identify whether the boundary condition is applied to a velocity or pressure variable. In a way, this information is conveyed by the number of components in cond.

gthyagi avatar May 23 '24 02:05 gthyagi

Thanks Tyagi - that's a nice idea that JC and I have discussed previously. I can add it but we need to do lots of tests going forward. Especially getting the variable correct. We don't want to always assume v & p. Better to use Petsc's internal representation for the system unknowns.

julesghub avatar May 23 '24 02:05 julesghub

Added the request @gthyagi and @lmoresi. New conditions function looks like add_condition(self, f_id, c_type, conds, boundary, components):

You can specify the f_id to apply it. As I mentioned this is untested numerically with the solver configuration we have.

julesghub avatar May 23 '24 07:05 julesghub

Components is not really needed any more. Can we absorb it as extra args but not encourage it.

Or deprecation warning.

lmoresi avatar May 23 '24 07:05 lmoresi

Regarding the variable type - this makes sense for the essential boundary conditions but not so much for natural bc/s.

lmoresi avatar May 23 '24 09:05 lmoresi

True that. Perhaps unknown field equation id - eqid?

julesghub avatar May 23 '24 10:05 julesghub

Or you could have two different interfaces - one for essential and one for natural ... oh wait a minute ...

lmoresi avatar May 23 '24 10:05 lmoresi

@julesghub @lmoresi Can we also add surface integration feature? Currently we have volume integration over the entire mesh. This can help to compute average quantities on inner/outer surfaces in Annulus/Spherical benchmarks.

gthyagi avatar May 28 '24 04:05 gthyagi

We have talked about this and I agree that it would be helpful. It's one for @julesghub to implement.

Suggest we create an issue type for "enhancement" and create a new issue.

lmoresi avatar May 28 '24 04:05 lmoresi

@julesghub Can you use https://petsc.org/main/manualpages/DMPlex/DMPlexComputeBdIntegral/ ?

knepley avatar May 28 '24 11:05 knepley