Skip to content

FATES insert_cohort subroutine does not preserve order of cohorts #1313

@adrifoster

Description

@adrifoster

The insert_cohort subroutine flips the order of cohorts (given identical heights), while sort_cohorts preserves order.

Essentially, this means that if we give insert_cohort a list of cohorts 1...100 (all the same exact height), the resulting list will be ordered 100...1.

This is because of this line:

    current => pshortest
    exitloop = 0
    !starting with shortest tree on the grid, find tree just
    !taller than tree being considered and return its pointer
    if (associated(current)) then
       do while (associated(current).and.exitloop == 0)
          **if (current%height < tsp) then**
             current => current%taller
          else
             exitloop = 1
          endif
       enddo
    endif

if we switch this to if (current%height <= tsp) then we will preserve order.

I think this is not ideal, and is somewhat confusing. I would like to propose we make this change this so that insert_cohort preserves the order.

I have a branch that updates our insert_cohort and sort_cohort routines. Because of this change, it is not B4B. I also propose adding some checks to make sure we don't have any inadvertently disconnected cohorts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    ✔ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions