CliMA / ClimaCore.jl

CliMA model dycore
https://clima.github.io/ClimaCore.jl/dev
Apache License 2.0
87 stars 8 forks source link

The `MatrixFields` module has no user documentation #1985

Open Sbozzolo opened 1 month ago

Sbozzolo commented 1 month ago

The documentation for MatrixFields gives a high-level description of what the module is about, but does not provide guidance on how to use these objects.

For example, the question I am currently trying to answer is "do I have any NaN in my MatrixFields"? I find myself unable to tackle this question.

I still don't have a mental model of FieldMatrixs are supposed to represent and there are several levels of abstractions to go through.

Another example, I (think) I have a FieldMatrixs that represent an identity. When I print it, I see

myJ[@name(c.ρ), @name(c.ρ)] = ClimaCore.MatrixFields.DiagonalMatrixRow{Float32}-valued Field whose first column corresponds to the Square matrix
 0.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅   0.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅    ⋅   0.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅    ⋅    ⋅   0.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅    ⋅    ⋅    ⋅   0.0   ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅    ⋅    ⋅    ⋅    ⋅   0.0   ⋅    ⋅    ⋅    ⋅ 
  ⋅    ⋅    ⋅    ⋅    ⋅    ⋅   0.0   ⋅    ⋅    ⋅ 
  ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅   0.0   ⋅    ⋅ 
  ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅   0.0   ⋅ 

What does this mean? Is "first column" referring to the space? Why a "first column" corresponds to a square matrix?

Osmosys with @dennisYatunin helped me making progress in understanding these objects since I started working with them. One of the misconception I had until a couple of days ago was that they didn't include space information. This misconception was informed by examples like

@. W.matrix[@name(my_var), @name(my_var)] = dtγ * div_matrix() ⋅ grad_matrix() - (LinearAlgebra.I,)

where there is no space information on the right-hand side. (Now, I see how the space comes to be: it is in pre-defining W)

EDIT: The matrix field I thought being an identity was, in fact, not an identity. Now, when I print it, I get

LinearAlgebra.UniformScaling{Bool}
true*I
Sbozzolo commented 1 month ago

This is how I find if there's NaNs in myJ

map(v -> any(isnan, parent(v.entries)), values(myJ))

with myJ being a FieldMatrix.