kinnala / scikit-fem

Simple finite element assemblers
https://scikit-fem.readthedocs.io
BSD 3-Clause "New" or "Revised" License
500 stars 79 forks source link

Conveniently setting the x in condense #957

Closed HelgeGehring closed 1 year ago

HelgeGehring commented 1 year ago

I'm currently using

    x = basis.zeros()
    for key, value in fixed_boundaries.items():
        x[basis.get_dofs(key)] = value

    temperature = solve(
        *condense(
            thermal_conductivity_lhs,
            joule_heating_rhs,
            D={fixed_boundary: basis.get_dofs(fixed_boundary) for fixed_boundary in fixed_boundaries},
            x=x
        )
    )

to set the boundary condition, where fixed_boundary is a dict of name_of_boundary -> value, e.g. {'left': 0, 'right':1}

As it's allowed to pass a dict of name -> dofs in D, would it be an option to add the possibility to pass a dict name -> value in x? I.e. that the example would simplify to

    temperature = solve(
        *condense(
            thermal_conductivity_lhs,
            joule_heating_rhs,
            D={fixed_boundary: basis.get_dofs(fixed_boundary) for fixed_boundary in fixed_boundaries},
            x=fixed_boundaries
        )
    )

where the value could either be a constant value, or an array of values for the list of dofs?

kinnala commented 1 year ago

A dict for D is allowed only because of backwards compatibility. We used to prefer basis.find_dofs which is now deprecated but returns a dict. I think we shouldn't make those condense, enforce, penalize etc. more complicated than they already are.

HelgeGehring commented 1 year ago

Keep it simple sounds good! If a dict for D is allowed only because of backwards compatibility, would it make sense to also deprecate it and show a warning (and also remove it from the type hint)?

kinnala commented 1 year ago

Yes, let's add warning. I think mypy doesn't like dropping the type hint?

HelgeGehring commented 1 year ago

Oh, didn't see that mypy is used. Then the deprecation warning should be enough :)