underworldcode / underworld3

https://underworldcode.github.io/underworld3/
Other
21 stars 10 forks source link

New BC interface: add_bc() #195

Closed julesghub closed 5 months ago

julesghub commented 6 months ago

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


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 commented 6 months ago

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

lmoresi commented 6 months ago

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      |
| ------------------------------------------------------ |
julesghub commented 6 months ago

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

gthyagi commented 6 months ago

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.

julesghub commented 6 months ago

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 commented 6 months ago

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.

lmoresi commented 6 months ago

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

Or deprecation warning.

lmoresi commented 6 months ago

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

julesghub commented 6 months ago

True that. Perhaps unknown field equation id - eqid?

lmoresi commented 6 months ago

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

gthyagi commented 5 months ago

@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.

lmoresi commented 5 months ago

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.

knepley commented 5 months ago

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