Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maginor committed Aug 5, 2024
1 parent c055041 commit 8a2096d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
Binary file modified docs/img/datafiles/flags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/mobiviewdocs/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ has_children: true

You can use the plot to visualize inputs and results of the model. Time series can be selected in the result and model input trees to the left of the plot.

![Series selecter](../img/mobiview/series_selecter.png)
![Series selecter](../img/mobiview/series_selection.png)

Series are organized in a tree structure according to their [location](../mobius2docs/central_concepts.html#components-and-locations). For instance, the soil water organic carbon is found under `Soil->Water->Organic carbon`. Non-primary state variables are instead organized under the location that makes the most sense, for instance a flux is organized under its source location if it is valid, otherwise its target location.

Expand Down
14 changes: 14 additions & 0 deletions src/model_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,20 @@ Model_Application::find_base_flux(Var_Id dissolved_flux_id) {
return result_id;
}

Var_Id
Model_Application::find_flux_var_of_decl(Entity_Id flux_id) {
// Find the flux state variable corresponding to a model flux declaration.

// TODO: This is a bit inefficient, should we have a lookup structure for it?
for(auto var_id : vars.all_fluxes()) {
auto var = vars[var_id];
if(var->type != State_Var::Type::declared) continue;
if(as<State_Var::Type::declared>(var)->decl_id == flux_id)
return var_id;
}
return invalid_var;
}

std::string
Model_Application::serialize(Var_Id id) {

Expand Down
6 changes: 3 additions & 3 deletions src/model_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@ Model_Application {

bool all_indexes_are_set();

Math_Expr_FT *
get_index_count_code(Entity_Id index_set, Index_Exprs &indexes);
Math_Expr_FT * get_index_count_code(Entity_Id index_set, Index_Exprs &indexes);

Sub_Indexed_Component *find_connection_component(Entity_Id conn_id, Entity_Id comp_id, bool make_error = true);
Var_Location get_primary_location(Var_Id source, bool &is_conc);
Expand All @@ -464,6 +463,7 @@ Model_Application {
Var_Id get_connection_target_variable(Var_Id source, Entity_Id connection_id, Entity_Id target_component);

Var_Id find_base_flux(Var_Id dissolved_flux_id);
Var_Id find_flux_var_of_decl(Entity_Id flux_id);

void build_from_data_set(Data_Set *data_set);
void save_to_data_set(Model_Data *save_from=nullptr);
Expand Down Expand Up @@ -496,7 +496,7 @@ read_single_parameter_data(Model_Application *app, Entity_Id par_id, Parameter_D
Entity_Id
avoid_index_set_dependency(Model_Application *app, Var_Loc_Restriction restriction);

// The point of this one is to make a structure that can be used for local computations, this is not the same as the connection_structure, which is used in the model code generation itself.
// The use case of this one is to make a structure that can be used for local computations, this is not the same as the connection_structure, which is used in the model code generation itself.
void
make_connection_component_indexing_structure(Model_Application *app, Storage_Structure<Entity_Id> *components, Entity_Id connection_id);

Expand Down
28 changes: 13 additions & 15 deletions src/model_compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,16 +1049,21 @@ set_up_external_computation_instruction(Model_Application *app, Var_Id var_id, s
}

void
maybe_process_discrete_flux(Model_Application *app, std::vector<Model_Instruction> &instructions, Var_Id var_id, bool is_aggregate, bool has_aggregate) {
maybe_process_discrete_flux(Model_Application *app, std::vector<Model_Instruction> &instructions, Var_Id var_id) {

// Generate instructions for updating quantities based on discrete fluxes.

auto model = app->model;
auto var = app->vars[var_id];

if(!var->is_flux()) return;

auto loc1 = var->loc1;
auto loc2 = var->loc2;

bool is_aggregate = var->type == State_Var::Type::regular_aggregate;
bool has_aggregate = var->has_flag(State_Var::has_aggregate);

std::vector<int> sub_add_instrs;

bool is_discrete = false;
Expand Down Expand Up @@ -1157,14 +1162,10 @@ maybe_process_discrete_flux(Model_Application *app, std::vector<Model_Instructio
bool after = false;
for(auto flux_id : discrete_order->fluxes) {
if(after) {
// TODO: Ugh, we have to do this just to find the single state variable corresponding to a given flux declaration.
// should have a lookup structure for it!
for(auto var_id_2 : app->vars.all_fluxes()) {
auto var2 = app->vars[var_id_2];
if(var2->type != State_Var::Type::declared) continue;
if(as<State_Var::Type::declared>(var2)->decl_id == flux_id)
instructions[var_id_2.id].depends_on_instruction.insert(sub_add_instrs.begin(), sub_add_instrs.end());
}
auto var_id_2 = app->find_flux_var_of_decl(flux_id);

if(is_valid(var_id_2))
instructions[var_id_2.id].depends_on_instruction.insert(sub_add_instrs.begin(), sub_add_instrs.end());
}
if(flux_id == flux_decl_id)
after = true;
Expand Down Expand Up @@ -1239,15 +1240,12 @@ build_instructions(Model_Application *app, std::vector<Model_Instruction> &instr

auto var = app->vars[var_id];

bool is_aggregate = var->type == State_Var::Type::regular_aggregate;
bool has_aggregate = var->has_flag(State_Var::has_aggregate);

if(var->type == State_Var::Type::external_computation) {
set_up_external_computation_instruction(app, var_id, instructions, initial);
continue;
}

if(is_aggregate) {
if(var->type == State_Var::Type::regular_aggregate) {

// NOTE: We have to look up the solver here. This is because we can't necessarily set it up before this point.
// although TODO: Couldn't we though?
Expand Down Expand Up @@ -1293,9 +1291,9 @@ build_instructions(Model_Application *app, std::vector<Model_Instruction> &instr
insert_dependency(app, agg_instr, index_set);
}

if(initial || !var->is_flux()) continue;
if(initial) continue;

maybe_process_discrete_flux(app, instructions, var_id, is_aggregate, has_aggregate);
maybe_process_discrete_flux(app, instructions, var_id);

}
}
Expand Down

0 comments on commit 8a2096d

Please sign in to comment.