diff --git a/tests/generator/generator.cpp b/tests/generator/generator.cpp index b1c946483c..c5387bc373 100644 --- a/tests/generator/generator.cpp +++ b/tests/generator/generator.cpp @@ -911,6 +911,30 @@ TEST(Generator, cellmlLeadingPlusSign) EXPECT_EQ_FILE_CONTENTS("generator/cellml_leading_plus_sign/model.py", generator->implementationCode(analyserModel, profile)); } +TEST(Generator, notOperandWithParentheses) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/cellml_not/model.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ(size_t(0), analyser->issueCount()); + + auto analyserModel = analyser->analyserModel(); + auto generator = libcellml::Generator::create(); + + EXPECT_EQ_FILE_CONTENTS("generator/cellml_not/model.h", generator->interfaceCode(analyserModel)); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_not/model.c", generator->implementationCode(analyserModel)); + + auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + EXPECT_EQ_FILE_CONTENTS("generator/cellml_not/model.py", generator->implementationCode(analyserModel, profile)); +} + TEST(Generator, dependentEqns) { auto parser = libcellml::Parser::create(); diff --git a/tests/generator/generatornot.cpp b/tests/generator/generatornot.cpp deleted file mode 100644 index cdd9d40c1b..0000000000 --- a/tests/generator/generatornot.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright libCellML Contributors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "test_utils.h" - -#include "gtest/gtest.h" - -#include - -TEST(GeneratorNot, operandWithParentheses) -{ - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/not/model.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - - analyser->analyseModel(model); - - EXPECT_EQ(size_t(0), analyser->issueCount()); - - auto generator = libcellml::Generator::create(); - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_NE(std::string::npos, implementationCode.find("computedConstants[0] = !constants[0];\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[0] = !(voi > 5.5);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[1] = !((voi > 5.5) && (voi < 2.5));\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[2] = !!(voi > 5.5);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[3] = !(voi > 5.5) && (voi < 2.5);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[4] = (!(voi > 5.5))?1.0:0.0;\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[5] = !(voi+constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[6] = !-voi;\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[7] = !(voi*constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[8] = !((voi > 5.5) || constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[9] = !(voi/constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[10] = !((voi > 5.5)?1.0:0.0);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[11] = !(voi+constants[0]);\n")); -} diff --git a/tests/generator/generatorunary.cpp b/tests/generator/generatorunary.cpp index 2353fb03f2..d0aaa621eb 100644 --- a/tests/generator/generatorunary.cpp +++ b/tests/generator/generatorunary.cpp @@ -20,152 +20,96 @@ limitations under the License. #include -TEST(GeneratorUnaryMinus, example01) +// Unary minus tests. + +namespace { + +static void expectUnaryMinusExample(const std::string &example) { - // rates[0] = --1.0; auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_01.cellml")); + auto model = parser->parseModel(fileContents("generator/cellml_unary_minus/" + example + ".cellml")); - EXPECT_NE(nullptr, model); + EXPECT_EQ(size_t(0), parser->issueCount()); auto analyser = libcellml::Analyser::create(); + analyser->analyseModel(model); EXPECT_EQ(size_t(0), analyser->issueCount()); + auto analyserModel = analyser->analyserModel(); auto generator = libcellml::Generator::create(); + auto profile = libcellml::GeneratorProfile::create(); - auto implementationCode = generator->implementationCode(analyser->analyserModel()); + profile->setInterfaceFileNameString(example + ".h"); - EXPECT_TRUE(implementationCode.find("rates[0] = -(-1.0);\n") != std::string::npos); -} + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".h", generator->interfaceCode(analyserModel, profile)); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".c", generator->implementationCode(analyserModel, profile)); -TEST(GeneratorUnaryMinus, example02) -{ - // rates[0] = --2.0*constants[0]; - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_02.cellml")); + profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); - EXPECT_NE(nullptr, model); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".py", generator->implementationCode(analyserModel, profile)); +} - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); +} // namespace - EXPECT_EQ(size_t(0), analyser->issueCount()); +TEST(GeneratorUnary, unaryMinusExample01) +{ + // rates[0] = --1.0; - auto generator = libcellml::Generator::create(); + expectUnaryMinusExample("example_01"); +} - auto implementationCode = generator->implementationCode(analyser->analyserModel()); +TEST(GeneratorUnary, unaryMinusExample02) +{ + // rates[0] = --2.0*constants[0]; - EXPECT_TRUE(implementationCode.find("rates[0] = -(-2.0*constants[0]);\n") != std::string::npos); + expectUnaryMinusExample("example_02"); } -TEST(GeneratorUnaryMinus, example03) +TEST(GeneratorUnary, unaryMinusExample03) { // rates[0] = --constants[1]/constants[0]; - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_03.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); - - EXPECT_EQ(size_t(0), analyser->issueCount()); - - auto generator = libcellml::Generator::create(); - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_TRUE(implementationCode.find("rates[0] = -(-constants[1]/constants[0]);\n") != std::string::npos); + expectUnaryMinusExample("example_03"); } -TEST(GeneratorUnaryMinus, example04) +TEST(GeneratorUnary, unaryMinusExample04) { // rates[0] = -(-1.0); - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_04.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); - - EXPECT_EQ(size_t(0), analyser->issueCount()); - - auto generator = libcellml::Generator::create(); - - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - EXPECT_TRUE(implementationCode.find("rates[0] = -(-1.0);\n") != std::string::npos); + expectUnaryMinusExample("example_04"); } -TEST(GeneratorUnaryMinus, example05) +TEST(GeneratorUnary, unaryMinusExample05) { // rates[0] = -(-constants[1]+constants[0]); - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_05.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); - - EXPECT_EQ(size_t(0), analyser->issueCount()); - auto generator = libcellml::Generator::create(); - - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_TRUE(implementationCode.find("rates[0] = -(-constants[1]+constants[0]);\n") != std::string::npos); + expectUnaryMinusExample("example_05"); } -TEST(GeneratorUnaryMinus, example06) +TEST(GeneratorUnary, unaryMinusExample06) { // rates[0] = -pow(-constants[1], constants[0]); - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_06.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); - - EXPECT_EQ(size_t(0), analyser->issueCount()); - - auto generator = libcellml::Generator::create(); - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_TRUE(implementationCode.find("rates[0] = -pow(-constants[1], constants[0]);\n") != std::string::npos); + expectUnaryMinusExample("example_06"); } -TEST(GeneratorUnaryMinus, example07) +TEST(GeneratorUnary, unaryMinusExample07) { // rates[0] = constants[1]-(-constants[0]); - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_minus/example_07.cellml")); - - EXPECT_NE(nullptr, model); - - auto analyser = libcellml::Analyser::create(); - analyser->analyseModel(model); - EXPECT_EQ(size_t(0), analyser->issueCount()); - - auto generator = libcellml::Generator::create(); - - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_TRUE(implementationCode.find("rates[0] = constants[1]-(-constants[0]);\n") != std::string::npos); + expectUnaryMinusExample("example_07"); } -TEST(GeneratorUnaryPlus, operandWithParentheses) +// Unary plus tests. + +TEST(GeneratorUnary, unaryPlusOperandWithParentheses) { auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("generator/unary_plus/model.cellml")); + auto model = parser->parseModel(fileContents("generator/cellml_unary_plus/model.cellml")); - EXPECT_NE(nullptr, model); + EXPECT_EQ(size_t(0), parser->issueCount()); auto analyser = libcellml::Analyser::create(); @@ -173,36 +117,13 @@ TEST(GeneratorUnaryPlus, operandWithParentheses) EXPECT_EQ(size_t(0), analyser->issueCount()); + auto analyserModel = analyser->analyserModel(); auto generator = libcellml::Generator::create(); - auto implementationCode = generator->implementationCode(analyser->analyserModel()); - - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[0] = voi*(voi+constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[1] = voi-(voi+constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[2] = voi/(voi+constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[3] = ((voi > 5.5) || constants[0]) && constants[0];\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[4] = (voi > 5.5)*constants[0];\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[5] = (voi+constants[0])*voi;\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[6] = voi/(voi*constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[7] = voi+(voi > 5.5);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[8] = -(voi+constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[9] = -voi*constants[0];\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[10] = voi-(-constants[0]);\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[11] = pow(constants[0], 1.0/(voi+constants[0]));\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[12] = constants[0] || ((voi > 5.5) && constants[0]);\n")); - - implementationCode = generator->implementationCode(analyser->analyserModel(), libcellml::GeneratorProfile::Profile::PYTHON); - - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[0] = voi*(voi+constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[1] = voi-(voi+constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[2] = voi/(voi+constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[3] = and_func(or_func(gt_func(voi, 5.5), constants[0]), constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[4] = gt_func(voi, 5.5)*constants[0]\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[5] = (voi+constants[0])*voi\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[6] = voi/(voi*constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[7] = voi+gt_func(voi, 5.5)\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[8] = -(voi+constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[9] = -voi*constants[0]\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[10] = voi-(-constants[0])\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[11] = pow(constants[0], 1.0/(voi+constants[0]))\n")); - EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[12] = or_func(constants[0], and_func(gt_func(voi, 5.5), constants[0]))\n")); + + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_plus/model.h", generator->interfaceCode(analyserModel)); + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_plus/model.c", generator->implementationCode(analyserModel)); + + auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_plus/model.py", generator->implementationCode(analyserModel, profile)); } diff --git a/tests/generator/tests.cmake b/tests/generator/tests.cmake index f1b92ac9e6..3c484fcd13 100644 --- a/tests/generator/tests.cmake +++ b/tests/generator/tests.cmake @@ -5,7 +5,6 @@ list(APPEND LIBCELLML_TESTS ${CURRENT_TEST}) set(${CURRENT_TEST}_SRCS ${CMAKE_CURRENT_LIST_DIR}/generator.cpp - ${CMAKE_CURRENT_LIST_DIR}/generatornot.cpp ${CMAKE_CURRENT_LIST_DIR}/generatorprofile.cpp ${CMAKE_CURRENT_LIST_DIR}/generatorunary.cpp ${CMAKE_CURRENT_LIST_DIR}/generatorvariabletracker.cpp diff --git a/tests/resources/generator/cellml_not/model.c b/tests/resources/generator/cellml_not/model.c new file mode 100644 index 0000000000..6ea87ea0c1 --- /dev/null +++ b/tests/resources/generator/cellml_not/model.c @@ -0,0 +1,124 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_VARIABLE_COUNT = 12; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"x0", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"x6", "dimensionless", "c"} +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { + {"x1", "dimensionless", "c"}, + {"x2", "dimensionless", "c"}, + {"x3", "dimensionless", "c"}, + {"x4", "dimensionless", "c"}, + {"x5", "dimensionless", "c"}, + {"x7", "dimensionless", "c"}, + {"x8", "dimensionless", "c"}, + {"x9", "dimensionless", "c"}, + {"x10", "dimensionless", "c"}, + {"x11", "dimensionless", "c"}, + {"x12", "dimensionless", "c"}, + {"x13", "dimensionless", "c"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 0.0; + constants[0] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + computedConstants[0] = !constants[0]; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = 1.0; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + algebraicVariables[0] = !(voi > 5.5); + algebraicVariables[1] = !((voi > 5.5) && (voi < 2.5)); + algebraicVariables[2] = !!(voi > 5.5); + algebraicVariables[3] = !(voi > 5.5) && (voi < 2.5); + algebraicVariables[4] = (!(voi > 5.5))?1.0:0.0; + algebraicVariables[5] = !(voi+constants[0]); + algebraicVariables[6] = !-voi; + algebraicVariables[7] = !(voi*constants[0]); + algebraicVariables[8] = !((voi > 5.5) || constants[0]); + algebraicVariables[9] = !(voi/constants[0]); + algebraicVariables[10] = !((voi > 5.5)?1.0:0.0); + algebraicVariables[11] = !(voi+constants[0]); +} diff --git a/tests/resources/generator/not/model.cellml b/tests/resources/generator/cellml_not/model.cellml similarity index 100% rename from tests/resources/generator/not/model.cellml rename to tests/resources/generator/cellml_not/model.cellml diff --git a/tests/resources/generator/cellml_not/model.h b/tests/resources/generator/cellml_not/model.h new file mode 100644 index 0000000000..ff49002cc8 --- /dev/null +++ b/tests/resources/generator/cellml_not/model.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[4]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_not/model.py b/tests/resources/generator/cellml_not/model.py new file mode 100644 index 0000000000..17426e4f55 --- /dev/null +++ b/tests/resources/generator/cellml_not/model.py @@ -0,0 +1,106 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_VARIABLE_COUNT = 12 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "x0", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "x6", "units": "dimensionless", "component": "c"} +] + +ALGEBRAIC_VARIABLE_INFO = [ + {"name": "x1", "units": "dimensionless", "component": "c"}, + {"name": "x2", "units": "dimensionless", "component": "c"}, + {"name": "x3", "units": "dimensionless", "component": "c"}, + {"name": "x4", "units": "dimensionless", "component": "c"}, + {"name": "x5", "units": "dimensionless", "component": "c"}, + {"name": "x7", "units": "dimensionless", "component": "c"}, + {"name": "x8", "units": "dimensionless", "component": "c"}, + {"name": "x9", "units": "dimensionless", "component": "c"}, + {"name": "x10", "units": "dimensionless", "component": "c"}, + {"name": "x11", "units": "dimensionless", "component": "c"}, + {"name": "x12", "units": "dimensionless", "component": "c"}, + {"name": "x13", "units": "dimensionless", "component": "c"} +] + + +def lt_func(x, y): + return 1.0 if x < y else 0.0 + + +def gt_func(x, y): + return 1.0 if x > y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def or_func(x, y): + return 1.0 if bool(x) | bool(y) else 0.0 + + +def not_func(x): + return 1.0 if not bool(x) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 0.0 + constants[0] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + computed_constants[0] = not_func(constants[0]) + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = 1.0 + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + algebraic_variables[0] = not_func(gt_func(voi, 5.5)) + algebraic_variables[1] = not_func(and_func(gt_func(voi, 5.5), lt_func(voi, 2.5))) + algebraic_variables[2] = not_func(not_func(gt_func(voi, 5.5))) + algebraic_variables[3] = and_func(not_func(gt_func(voi, 5.5)), lt_func(voi, 2.5)) + algebraic_variables[4] = 1.0 if not_func(gt_func(voi, 5.5)) else 0.0 + algebraic_variables[5] = not_func(voi+constants[0]) + algebraic_variables[6] = not_func(-voi) + algebraic_variables[7] = not_func(voi*constants[0]) + algebraic_variables[8] = not_func(or_func(gt_func(voi, 5.5), constants[0])) + algebraic_variables[9] = not_func(voi/constants[0]) + algebraic_variables[10] = not_func(1.0 if gt_func(voi, 5.5) else 0.0) + algebraic_variables[11] = not_func(voi+constants[0]) diff --git a/tests/resources/generator/cellml_unary_minus/example_01.c b/tests/resources/generator/cellml_unary_minus/example_01.c new file mode 100644 index 0000000000..440b9df29f --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_01.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_01.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"a", "dimensionless", "c"}, + {"b", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 2.0; + constants[1] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -(-1.0); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_01.cellml b/tests/resources/generator/cellml_unary_minus/example_01.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_01.cellml rename to tests/resources/generator/cellml_unary_minus/example_01.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_01.h b/tests/resources/generator/cellml_unary_minus/example_01.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_01.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_01.py b/tests/resources/generator/cellml_unary_minus/example_01.py new file mode 100644 index 0000000000..353095ba53 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_01.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "c"}, + {"name": "b", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 2.0 + constants[1] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -(-1.0) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_02.c b/tests/resources/generator/cellml_unary_minus/example_02.c new file mode 100644 index 0000000000..65843667ff --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_02.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_02.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"a", "dimensionless", "c"}, + {"b", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 2.0; + constants[1] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -(-2.0*constants[0]); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_02.cellml b/tests/resources/generator/cellml_unary_minus/example_02.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_02.cellml rename to tests/resources/generator/cellml_unary_minus/example_02.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_02.h b/tests/resources/generator/cellml_unary_minus/example_02.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_02.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_02.py b/tests/resources/generator/cellml_unary_minus/example_02.py new file mode 100644 index 0000000000..a05f2ac68e --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_02.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "c"}, + {"name": "b", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 2.0 + constants[1] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -(-2.0*constants[0]) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_03.c b/tests/resources/generator/cellml_unary_minus/example_03.c new file mode 100644 index 0000000000..57ea63aa6d --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_03.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_03.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"b", "dimensionless", "c"}, + {"a", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 3.0; + constants[1] = 2.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -(-constants[1]/constants[0]); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_03.cellml b/tests/resources/generator/cellml_unary_minus/example_03.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_03.cellml rename to tests/resources/generator/cellml_unary_minus/example_03.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_03.h b/tests/resources/generator/cellml_unary_minus/example_03.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_03.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_03.py b/tests/resources/generator/cellml_unary_minus/example_03.py new file mode 100644 index 0000000000..704873d5e6 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_03.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "b", "units": "dimensionless", "component": "c"}, + {"name": "a", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 3.0 + constants[1] = 2.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -(-constants[1]/constants[0]) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_04.c b/tests/resources/generator/cellml_unary_minus/example_04.c new file mode 100644 index 0000000000..e9686a99c1 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_04.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_04.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"a", "dimensionless", "c"}, + {"b", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 2.0; + constants[1] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -(-1.0); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_04.cellml b/tests/resources/generator/cellml_unary_minus/example_04.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_04.cellml rename to tests/resources/generator/cellml_unary_minus/example_04.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_04.h b/tests/resources/generator/cellml_unary_minus/example_04.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_04.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_04.py b/tests/resources/generator/cellml_unary_minus/example_04.py new file mode 100644 index 0000000000..353095ba53 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_04.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "c"}, + {"name": "b", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 2.0 + constants[1] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -(-1.0) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_05.c b/tests/resources/generator/cellml_unary_minus/example_05.c new file mode 100644 index 0000000000..235387eab9 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_05.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_05.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"b", "dimensionless", "c"}, + {"a", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 3.0; + constants[1] = 2.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -(-constants[1]+constants[0]); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_05.cellml b/tests/resources/generator/cellml_unary_minus/example_05.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_05.cellml rename to tests/resources/generator/cellml_unary_minus/example_05.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_05.h b/tests/resources/generator/cellml_unary_minus/example_05.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_05.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_05.py b/tests/resources/generator/cellml_unary_minus/example_05.py new file mode 100644 index 0000000000..c85571818e --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_05.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "b", "units": "dimensionless", "component": "c"}, + {"name": "a", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 3.0 + constants[1] = 2.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -(-constants[1]+constants[0]) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_06.c b/tests/resources/generator/cellml_unary_minus/example_06.c new file mode 100644 index 0000000000..1112328bf4 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_06.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_06.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"b", "dimensionless", "c"}, + {"a", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 3.0; + constants[1] = 2.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = -pow(-constants[1], constants[0]); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_06.cellml b/tests/resources/generator/cellml_unary_minus/example_06.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_06.cellml rename to tests/resources/generator/cellml_unary_minus/example_06.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_06.h b/tests/resources/generator/cellml_unary_minus/example_06.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_06.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_06.py b/tests/resources/generator/cellml_unary_minus/example_06.py new file mode 100644 index 0000000000..2f208dad61 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_06.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "b", "units": "dimensionless", "component": "c"}, + {"name": "a", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 3.0 + constants[1] = 2.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = -pow(-constants[1], constants[0]) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_minus/example_07.c b/tests/resources/generator/cellml_unary_minus/example_07.c new file mode 100644 index 0000000000..7cc0d3ed01 --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_07.c @@ -0,0 +1,100 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "example_07.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 2; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"a", "dimensionless", "c"}, + {"b", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 2.0; + constants[1] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = constants[1]-(-constants[0]); +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/unary_minus/example_07.cellml b/tests/resources/generator/cellml_unary_minus/example_07.cellml similarity index 100% rename from tests/resources/generator/unary_minus/example_07.cellml rename to tests/resources/generator/cellml_unary_minus/example_07.cellml diff --git a/tests/resources/generator/cellml_unary_minus/example_07.h b/tests/resources/generator/cellml_unary_minus/example_07.h new file mode 100644 index 0000000000..cab8dce21a --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_07.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_minus/example_07.py b/tests/resources/generator/cellml_unary_minus/example_07.py new file mode 100644 index 0000000000..160a80c9fc --- /dev/null +++ b/tests/resources/generator/cellml_unary_minus/example_07.py @@ -0,0 +1,64 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 2 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "a", "units": "dimensionless", "component": "c"}, + {"name": "b", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 2.0 + constants[1] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = constants[1]-(-constants[0]) + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/cellml_unary_plus/model.c b/tests/resources/generator/cellml_unary_plus/model.c new file mode 100644 index 0000000000..04bc4c1173 --- /dev/null +++ b/tests/resources/generator/cellml_unary_plus/model.c @@ -0,0 +1,124 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 13; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "c"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "c"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"x0", "dimensionless", "c"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { + {"x1", "dimensionless", "c"}, + {"x2", "dimensionless", "c"}, + {"x3", "dimensionless", "c"}, + {"x4", "dimensionless", "c"}, + {"x5", "dimensionless", "c"}, + {"x6", "dimensionless", "c"}, + {"x7", "dimensionless", "c"}, + {"x8", "dimensionless", "c"}, + {"x9", "dimensionless", "c"}, + {"x10", "dimensionless", "c"}, + {"x11", "dimensionless", "c"}, + {"x12", "dimensionless", "c"}, + {"x13", "dimensionless", "c"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 0.0; + constants[0] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = 1.0; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + algebraicVariables[0] = voi*(voi+constants[0]); + algebraicVariables[1] = voi-(voi+constants[0]); + algebraicVariables[2] = voi/(voi+constants[0]); + algebraicVariables[3] = ((voi > 5.5) || constants[0]) && constants[0]; + algebraicVariables[4] = (voi > 5.5)*constants[0]; + algebraicVariables[5] = (voi+constants[0])*voi; + algebraicVariables[6] = voi/(voi*constants[0]); + algebraicVariables[7] = voi+(voi > 5.5); + algebraicVariables[8] = -(voi+constants[0]); + algebraicVariables[9] = -voi*constants[0]; + algebraicVariables[10] = voi-(-constants[0]); + algebraicVariables[11] = pow(constants[0], 1.0/(voi+constants[0])); + algebraicVariables[12] = constants[0] || ((voi > 5.5) && constants[0]); +} diff --git a/tests/resources/generator/unary_plus/model.cellml b/tests/resources/generator/cellml_unary_plus/model.cellml similarity index 100% rename from tests/resources/generator/unary_plus/model.cellml rename to tests/resources/generator/cellml_unary_plus/model.cellml diff --git a/tests/resources/generator/cellml_unary_plus/model.h b/tests/resources/generator/cellml_unary_plus/model.h new file mode 100644 index 0000000000..ff49002cc8 --- /dev/null +++ b/tests/resources/generator/cellml_unary_plus/model.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[4]; + char units[14]; + char component[2]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/cellml_unary_plus/model.py b/tests/resources/generator/cellml_unary_plus/model.py new file mode 100644 index 0000000000..8187712c39 --- /dev/null +++ b/tests/resources/generator/cellml_unary_plus/model.py @@ -0,0 +1,99 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.2. + +from enum import Enum +from math import * + + +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" + +STATE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 13 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "c"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "c"} +] + +CONSTANT_INFO = [ + {"name": "x0", "units": "dimensionless", "component": "c"} +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ + {"name": "x1", "units": "dimensionless", "component": "c"}, + {"name": "x2", "units": "dimensionless", "component": "c"}, + {"name": "x3", "units": "dimensionless", "component": "c"}, + {"name": "x4", "units": "dimensionless", "component": "c"}, + {"name": "x5", "units": "dimensionless", "component": "c"}, + {"name": "x6", "units": "dimensionless", "component": "c"}, + {"name": "x7", "units": "dimensionless", "component": "c"}, + {"name": "x8", "units": "dimensionless", "component": "c"}, + {"name": "x9", "units": "dimensionless", "component": "c"}, + {"name": "x10", "units": "dimensionless", "component": "c"}, + {"name": "x11", "units": "dimensionless", "component": "c"}, + {"name": "x12", "units": "dimensionless", "component": "c"}, + {"name": "x13", "units": "dimensionless", "component": "c"} +] + + +def gt_func(x, y): + return 1.0 if x > y else 0.0 + + +def and_func(x, y): + return 1.0 if bool(x) & bool(y) else 0.0 + + +def or_func(x, y): + return 1.0 if bool(x) | bool(y) else 0.0 + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 0.0 + constants[0] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + pass + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = 1.0 + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + algebraic_variables[0] = voi*(voi+constants[0]) + algebraic_variables[1] = voi-(voi+constants[0]) + algebraic_variables[2] = voi/(voi+constants[0]) + algebraic_variables[3] = and_func(or_func(gt_func(voi, 5.5), constants[0]), constants[0]) + algebraic_variables[4] = gt_func(voi, 5.5)*constants[0] + algebraic_variables[5] = (voi+constants[0])*voi + algebraic_variables[6] = voi/(voi*constants[0]) + algebraic_variables[7] = voi+gt_func(voi, 5.5) + algebraic_variables[8] = -(voi+constants[0]) + algebraic_variables[9] = -voi*constants[0] + algebraic_variables[10] = voi-(-constants[0]) + algebraic_variables[11] = pow(constants[0], 1.0/(voi+constants[0])) + algebraic_variables[12] = or_func(constants[0], and_func(gt_func(voi, 5.5), constants[0]))