bcube-project / Bcube.jl

MIT License
4 stars 2 forks source link

Define a `PhysicalFunction` with another one #20

Closed bmxam closed 9 months ago

bmxam commented 9 months ago

We cannot use a PhysicalFunction in the definition of another one. The following MWE raises an error:

using Bcube
mesh = one_cell_mesh(:line)

ρ = PhysicalFunction(x -> 1.0)
ρu = PhysicalFunction(x -> ρ(x) * 2)

dΩ = Measure(CellDomain(mesh), 1)
@show Bcube.compute(∫(ρu)dΩ)

Of course to overcome this we can use an intermediate variable

_ρ(x) = 1
ρ = PhysicalFunction(x -> _ρ(x))
ρu = PhysicalFunction(x -> _ρ(x) * 2)
ghislainb commented 9 months ago

CellFunction can be evaluated at a CellPoint or a FacePoint because DomainStyle is defined for those points. Here in:

PhysicalFunction(x -> ρ(x) * 2)

x is a SVector of coordinates for which DomainStyle is not defined, so evaluation of ρ(x) is not possible in the inner scope.

We can add a new feature to do so if we assume that x has the same DomainStyle as the CellFunction by default, but it will remove the "safety barriers" in a sense (and it could even be wrong if you compose ReferenceFunction with PhysicalFunction)

ρ = PhysicalFunction(x -> 1.0)
ρu = 2 * ρ
bmxam commented 9 months ago

I agree, the solution is simply what you suggested:

ρ = PhysicalFunction(x -> 1.0)
ρu = 2 * ρ

So no need to change anything.