ncsu-landscape-dynamics / pops-core

PoPS Core: C++ library for the Pest or Pathogen Spread Model
https://ncsu-landscape-dynamics.github.io/pops-core
GNU General Public License v2.0
5 stars 2 forks source link

Use host pool and action objects to manage data and operations #184

Closed wenzeslaus closed 1 year ago

wenzeslaus commented 2 years ago

Old code design:

New code design:

Code:

Compatibility:

Last phase pieces:

The results from tests for core and for r.pops.spread are identical with the new code.

For now, this includes also the original pseudo code for host object and actions.

Note: The separate seeds and generators PR (#192) required a lot of changes, so the merge was not trivial.

wenzeslaus commented 2 years ago

Current state in code

20220504_165705

Includes an intermediate state of soils addition.

With a Hosts object

20220506_152446

Includes a concept for the soils addition with a more appropriate behavior.

wenzeslaus commented 1 year ago

For the record: Alternative idea with mortality in the action

My initial idea was to do mortality in the action to keep the special action to the action object, but I ended up implementing mortality in the host pool object and here, just call the right method because mortality behavior is linked to the host. Eventually, even mortality_rate and mortality_time_lag may end up in the host for multi-host because they are linked to the to the host.

class Mortality
{
    void action(Hosts host)
    {
        for (const auto& [i, j] : hosts.suitable_cells) {
            for (host in hosts) {
                for (item in hosts.mortality_at(i, j)) {
                        if (index == 0)
                            mortality = item;
                        else
                            mortality = mortality_rate * item;
                        list.push_back(mortality);
                    }
                hosts.kill_at(i, j, mortality);
                }
        }
    }
};