diff --git a/pynestml/codegeneration/nest_compartmental_code_generator.py b/pynestml/codegeneration/nest_compartmental_code_generator.py
index 179f3062e..30716efbc 100644
--- a/pynestml/codegeneration/nest_compartmental_code_generator.py
+++ b/pynestml/codegeneration/nest_compartmental_code_generator.py
@@ -27,6 +27,7 @@
from jinja2 import TemplateRuntimeError
from odetoolbox import analysis
+from pynestml.codegeneration.printers.sympy_simple_expression_printer import SympySimpleExpressionPrinter
import pynestml
from pynestml.cocos.co_cos_manager import CoCosManager
@@ -180,7 +181,7 @@ def setup_printers(self):
self._ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
self._ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
self._ode_toolbox_printer = ODEToolboxExpressionPrinter(
- simple_expression_printer=CppSimpleExpressionPrinter(
+ simple_expression_printer=SympySimpleExpressionPrinter(
variable_printer=self._ode_toolbox_variable_printer,
constant_printer=self._constant_printer,
function_call_printer=self._ode_toolbox_function_call_printer))
diff --git a/pynestml/codegeneration/printers/gsl_variable_printer.py b/pynestml/codegeneration/printers/gsl_variable_printer.py
index 4de36651a..463833a43 100644
--- a/pynestml/codegeneration/printers/gsl_variable_printer.py
+++ b/pynestml/codegeneration/printers/gsl_variable_printer.py
@@ -18,16 +18,19 @@
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see .
-
+from pynestml.codegeneration.nest_unit_converter import NESTUnitConverter
from pynestml.codegeneration.printers.cpp_variable_printer import CppVariablePrinter
from pynestml.meta_model.ast_variable import ASTVariable
+from pynestml.symbols.predefined_units import PredefinedUnits
from pynestml.symbols.symbol import SymbolKind
from pynestml.utils.ast_utils import ASTUtils
+from pynestml.utils.logger import Logger, LoggingLevel
+from pynestml.utils.messages import Messages
class GSLVariablePrinter(CppVariablePrinter):
r"""
- Reference converter for C++ syntax and using the GSL (GNU Scientific Library) API from inside the ``extern "C"`` stepping function.
+ Variable printer for C++ syntax and using the GSL (GNU Scientific Library) API from inside the ``extern "C"`` stepping function.
"""
def print_variable(self, node: ASTVariable) -> str:
@@ -39,6 +42,16 @@ def print_variable(self, node: ASTVariable) -> str:
assert isinstance(node, ASTVariable)
symbol = node.get_scope().resolve_to_symbol(node.get_complete_name(), SymbolKind.VARIABLE)
+ if symbol is None:
+ # test if variable name can be resolved to a type
+ if PredefinedUnits.is_unit(node.get_complete_name()):
+ return str(NESTUnitConverter.get_factor(PredefinedUnits.get_unit(node.get_complete_name()).get_unit()))
+
+ code, message = Messages.get_could_not_resolve(node.get_name())
+ Logger.log_message(log_level=LoggingLevel.ERROR, code=code, message=message,
+ error_position=node.get_source_position())
+ return ""
+
if node.is_delay_variable():
return self._print_delay_variable(node)
diff --git a/pynestml/codegeneration/printers/sympy_simple_expression_printer.py b/pynestml/codegeneration/printers/sympy_simple_expression_printer.py
index e6a01d465..bf9c64bea 100644
--- a/pynestml/codegeneration/printers/sympy_simple_expression_printer.py
+++ b/pynestml/codegeneration/printers/sympy_simple_expression_printer.py
@@ -20,6 +20,7 @@
# along with NEST. If not, see .
from pynestml.codegeneration.nest_unit_converter import NESTUnitConverter
+from pynestml.codegeneration.printers.cpp_simple_expression_printer import CppSimpleExpressionPrinter
from pynestml.codegeneration.printers.simple_expression_printer import SimpleExpressionPrinter
from pynestml.meta_model.ast_function_call import ASTFunctionCall
from pynestml.meta_model.ast_node import ASTNode
@@ -29,7 +30,7 @@
from pynestml.symbols.symbol import SymbolKind
-class SympySimpleExpressionPrinter(SimpleExpressionPrinter):
+class SympySimpleExpressionPrinter(CppSimpleExpressionPrinter):
r"""
Printer for ASTSimpleExpressions in Sympy syntax.
"""
diff --git a/pynestml/utils/mechanism_processing.py b/pynestml/utils/mechanism_processing.py
index bc069dbb8..d45257adf 100644
--- a/pynestml/utils/mechanism_processing.py
+++ b/pynestml/utils/mechanism_processing.py
@@ -23,6 +23,8 @@
import copy
+from pynestml.codegeneration.printers.sympy_simple_expression_printer import SympySimpleExpressionPrinter
+
from pynestml.codegeneration.printers.cpp_simple_expression_printer import CppSimpleExpressionPrinter
from pynestml.codegeneration.printers.nestml_printer import NESTMLPrinter
from pynestml.codegeneration.printers.constant_printer import ConstantPrinter
@@ -56,7 +58,7 @@ class MechanismProcessing:
_ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
_ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
_ode_toolbox_printer = ODEToolboxExpressionPrinter(
- simple_expression_printer=CppSimpleExpressionPrinter(
+ simple_expression_printer=SympySimpleExpressionPrinter(
variable_printer=_ode_toolbox_variable_printer,
constant_printer=_constant_printer,
function_call_printer=_ode_toolbox_function_call_printer))