Fix quadratic time complexity for increasing of numer of species with no reactions
Summary
Time complexity on multiple species does not look correct when there are no reactions.
Steps to reproduce
Run several programs with a different number of species with diffusion and no reaction.
What is the current bug behaviour?
The time to solve will increase quadratically. That is not correct since problems are not coupled.
What is the expected correct behaviour?
Linear time complexity is expected.
Relevant logs, screenshots, files...?
The computation complexity looks like this for both dune_copasi_sd
and dune_copasi_md
executables:
Reproducing input
I modified the parameter tree for the test_cell
test at run time by deciding the numbers of species to have with:
for (auto compartment : model_config.sub("compartments").getValueKeys())
{
auto& comp_config = model_config.sub(compartment);
auto& react_config = comp_config.sub("reaction");
auto& reactjac_config = react_config.sub("jacobian");
auto& diff_config = comp_config.sub("diffusion");
auto& init_config = comp_config.sub("initial");
int vars = comp_config.template get<int>("auto_vars");
for (size_t i = 0; i < vars; i++)
{
auto var_name = "u" + std::to_string(i) + "g";
react_config[var_name] = "0";
init_config[var_name] = "exp(-((x-0.5)^2+(y-0.5)^2)/(4*t*0.005)) / (4*pi*t*0.005)";
diff_config[var_name] = "1";
for (size_t j = 0; j < vars; j++)
{
auto varjac_name = "d" + var_name + "_du" + std::to_string(j) + "g";
reactjac_config[varjac_name] = "0";
}
}
}
Ideas how to fix this?
After instrumenting the code with llvm-xray
, I found that the whole problem is coming from the jacobian volume. The loop to evaluate jacobian expressions may be moved into the same loop that accumulates the local jacobian matrix.
Edited by Santiago Ospina De Los Ríos