AlgebraicJulia / SyntacticModels.jl

Specifying models with syntax trees
MIT License
3 stars 3 forks source link

Typo in composite model example? #27

Closed kkaris closed 8 months ago

kkaris commented 10 months ago

The friction sub-model in the composite model example contains the following equation:

https://github.com/AlgebraicJulia/SyntacticModels.jl/blob/0ea6f64fffd6b28824a99d028f5b65d3a0cad4f1/docs/literate/composite_models_examples.jl#L87

Should the second term of the RHS be λ(Q - Q₀), interpreted as the function λ with the argument Q - Q₀, or, is it intended to be a multiplication, i.e. λ*(Q - Q₀)?

jpfairbanks commented 10 months ago

I intended it as unary function application, but I see that I typed the lambda as a constant.

    Decapodes.parse_decapode(quote
      V::Form0{Point}
      Q::Form0{Point}
      κ::Constant{Point}
      λ::Constant{Point}
      Q₀::Parameter{Point}

      ∂ₜ(Q) == κ*V + λ(Q - Q₀)
    end)

This probably is leading to a disordered Decapode where Lambda appears as both a variable and an operator. That is allowed because the operator names and variables live in separate tables. But that is definitely a confusing example. It should be either interpreted as a scalar

    Decapodes.parse_decapode(quote
      V::Form0{Point}
      Q::Form0{Point}
      κ::Constant{Point}
      λ::Constant{Point}
      Q₀::Parameter{Point}

      ∂ₜ(Q) == κ*V + λ*(Q - Q₀)
    end)

or as an operator

    Decapodes.parse_decapode(quote
      V::Form0{Point}
      Q::Form0{Point}
      κ::Constant{Point}
      Q₀::Parameter{Point}

      ∂ₜ(Q) == κ*V + λ(Q - Q₀)
    end)

Both of these are valid models. The existing code is a valid decapode, but it has an unused Constant variable.

bgyori commented 10 months ago

Just guessing here but assuming the idea is that Q is the current temperature and Q₀ is a reference temperature, λ*(Q - Q₀) on the right hand side of the equation would appear as an exponential cooling term in the solution which would make sense physically. If λ were a custom function instead, what would it be?

bgyori commented 10 months ago

On second thought, wouldn't it have to be -λ*(Q - Q₀)?

jpfairbanks commented 10 months ago

If you want a nonlinear material property, then you can have a function like lambda(x) = -(5x^3+8x) which would have exponential cooling when the temperatures are close and super exponential cooling when the temperatures are far apart. I don't know if there is a material with that property. But it was just an example of the syntax.

In general if you have a PDE with a constant times a quantity in it, there is another version of that model where the multiplication by a constant is replaced by applying a more general function.

jpfairbanks commented 10 months ago

Depends on how thoroughly you want to handle corner cases. The test suite should probably include decapodes that have unused variables to help test that people handle that corner case correctly.