Skip to content

Removing the 3rd dimension in the u arrays (or determining they are beneficial) #89

@jhalpern30

Description

@jhalpern30

From conversations with @logan-nc:
The regular u matrix is mpert x mpert x 2, which actually represents a mpert x (2 x mpert) matrix representing the mpert solution vectors, each of size 2 * mpert to contain the mpert displacements and their mpert conjugate momenta. It adds a lot of confusion because the third dimension was just differentiates the two components of the column vector, and the matrix dimensions end up not matching what one would expect based on the paper. This is also used in the asymptotics (ua, ca, vmat, mmat, etc.) and makes things very confusing.

The most obvious example: the entire sing_get_ca function would just be

ca = lu(ua) \ u # where ua is 2mpert x 2mpert and u is mpert x 2mpert

but instead we spend 90% of the function constructing and deconstructing the full 2D matrices from the sliced 3D version

# Build temp1
temp1 = zeros(ComplexF64, 2 * intr.mpert, 2 * intr.mpert)
temp1[1:intr.mpert, :] .= ua[:, :, 1]
temp1[intr.mpert+1:2*intr.mpert, :] .= ua[:, :, 2]

# Built temp2
temp2 = zeros(ComplexF64, 2 * intr.mpert, intr.mpert)
temp2[1:intr.mpert, :] .= odet.u[:, :, 1]
temp2[intr.mpert+1:2*intr.mpert, :] .= odet.u[:, :, 2]

# LU factorization and solve
temp2 .= lu(temp1) \ temp2

# Build ca
ca = zeros(ComplexF64, intr.mpert, intr.mpert, 2)
ca[:, :, 1] .= temp2[1:intr.mpert, :]
ca[:, :, 2] .= temp2[intr.mpert+1:2*intr.mpert, :]

My suspicion is because the most efficient way of computing u' = Lu in sing_der is to first compute the displacement derivative, i.e. du[:, :, 1], and then to use that in the computation of the conjugate momenta derivative since it just reappears in the expression for du[:, :, 2] = Gu[:, :, 1] - adjoint(K) - du{:, :, 1], and this makes the code look more clean than slicing from 1:mpert and mpert+1:2*mpert over and over. But in Julia we do these operations via views already so there's no advantage in this case, we'd just be modifying which slice the view operations are taking at the beginning of this function.

If there are no other obvious reasons why slicing the matrix into a third dimension is beneficial that are still applicable to the Julia code, I think this would be a massive improvement to the code since it would make the fundamental matrices in the code directly line up with what is presented in the DCON papers

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions