Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve COMPARTMENT names & documentation. #1498

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/language/nmodl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1527,18 +1527,18 @@
- Compartment:
nmodl: COMPARTMENT
members:
- name:
brief: "TODO"
- index_name:
brief: "Name of the index variable in volume expression"
type: Name
optional: true
prefix: {value: " "}
suffix: {value: ","}
- expression:
brief: "TODO"
- volume:
brief: "The volume of the compartment"
type: Expression
prefix: {value: " "}
- names:
brief: "TODO"
- species:
brief: "The names of the species that reside in this compartment"
type: Name
vector: true
prefix: {value: " {"}
Expand Down
14 changes: 7 additions & 7 deletions src/visitors/kinetic_block_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void KineticBlockVisitor::compute_compartment_factor(ast::Compartment& node,
const auto it = state_var_index.find(var_name);
if (it != state_var_index.cend()) {
int var_index = it->second;
auto expr = node.get_expression();
auto expr = node.get_volume();
std::string expression = to_nmodl(expr);

set_compartment_factor(var_index, expression);
Expand All @@ -178,7 +178,7 @@ void KineticBlockVisitor::compute_compartment_factor(ast::Compartment& node,
void KineticBlockVisitor::compute_indexed_compartment_factor(ast::Compartment& node,
const ast::Name& name) {
auto array_var_name = name.get_node_name();
auto index_name = node.get_name()->get_node_name();
auto index_name = node.get_index_name()->get_node_name();

auto pattern = fmt::format("^{}\\[([0-9]*)\\]$", array_var_name);
std::regex re(pattern);
Expand All @@ -189,8 +189,8 @@ void KineticBlockVisitor::compute_indexed_compartment_factor(ast::Compartment& n

if (matches) {
int index_value = std::stoi(m[1]);
auto volume_expr = node.get_expression();
auto expr = std::shared_ptr<ast::Expression>(node.get_expression()->clone());
auto volume_expr = node.get_volume();
auto expr = std::shared_ptr<ast::Expression>(volume_expr->clone());
IndexRemover(index_name, index_value).visit_expression(*expr);

std::string expression = to_nmodl(*expr);
Expand All @@ -203,9 +203,9 @@ void KineticBlockVisitor::visit_compartment(ast::Compartment& node) {
// COMPARTMENT block has an expression, and a list of state vars it applies to.
// For each state var, the rhs of the differential eq should be divided by the expression.
// Here we store the expressions in the compartment_factors vector
logger->debug("KineticBlockVisitor :: COMPARTMENT expr: {}", to_nmodl(node.get_expression()));
for (const auto& name_ptr: node.get_names()) {
if (node.get_name() == nullptr) {
logger->debug("KineticBlockVisitor :: COMPARTMENT expr: {}", to_nmodl(node.get_volume()));
for (const auto& name_ptr: node.get_species()) {
if (node.get_index_name() == nullptr) {
compute_compartment_factor(node, *name_ptr);
} else {
compute_indexed_compartment_factor(node, *name_ptr);
Expand Down
Loading