Skip to content

Commit

Permalink
Generator profile: added setters/getters for constants, computed cons…
Browse files Browse the repository at this point in the history
…tants, and algebraic arrays.
  • Loading branch information
agarny committed Aug 8, 2024
1 parent 0f8fbf3 commit c2504d7
Show file tree
Hide file tree
Showing 119 changed files with 3,904 additions and 3,778 deletions.
56 changes: 47 additions & 9 deletions src/api/libcellml/generatorprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3034,23 +3034,61 @@ class LIBCELLML_EXPORT GeneratorProfile
void setRatesArrayString(const std::string &ratesArrayString);

/**
* @brief Get the @c std::string for the name of the variables array.
* @brief Get the @c std::string for the name of the constants array.
*
* Return the @c std::string for the name of the variables array.
* Return the @c std::string for the name of the constants array.
*
* @return The @c std::string for the name of the variables array.
* @return The @c std::string for the name of the constants array.
*/
std::string variablesArrayString() const;
std::string constantsArrayString() const;

/**
* @brief Set the @c std::string for the name of the variables array.
* @brief Set the @c std::string for the name of the constants array.
*
* Set the @c std::string for the name of the variables array.
* Set the @c std::string for the name of the constants array.
*
* @param variablesArrayString The @c std::string to use for the name of the
* variables array.
* @param constantsArrayString The @c std::string to use for the name of the
* constants array.
*/
void setConstantsArrayString(const std::string &constantsArrayString);

/**
* @brief Get the @c std::string for the name of the computed constants array.
*
* Return the @c std::string for the name of the computed constants array.
*
* @return The @c std::string for the name of the computed constants array.
*/
std::string computedConstantsArrayString() const;

/**
* @brief Set the @c std::string for the name of the computed constants array.
*
* Set the @c std::string for the name of the computed constants array.
*
* @param computedConstantsArrayString The @c std::string to use for the name of the
* computed constants array.
*/
void setComputedConstantsArrayString(const std::string &computedConstantsArrayString);

/**
* @brief Get the @c std::string for the name of the algebraic array.
*
* Return the @c std::string for the name of the algebraic array.
*
* @return The @c std::string for the name of the algebraic array.
*/
std::string algebraicArrayString() const;

/**
* @brief Set the @c std::string for the name of the algebraic array.
*
* Set the @c std::string for the name of the algebraic array.
*
* @param algebraicArrayString The @c std::string to use for the name of the
* algebraic array.
*/
void setVariablesArrayString(const std::string &variablesArrayString);
void setAlgebraicArrayString(const std::string &algebraicArrayString);

/**
* @brief Get the @c std::string for the type definition of an external
Expand Down
20 changes: 16 additions & 4 deletions src/bindings/interface/generatorprofile.i
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,23 @@ and units of a variable respectively.";
%feature("docstring") libcellml::GeneratorProfile::setRatesArrayString
"Sets the string for the name of the rates array.";

%feature("docstring") libcellml::GeneratorProfile::variablesArrayString
"Returns the string for the name of the variables array.";
%feature("docstring") libcellml::GeneratorProfile::constantsArrayString
"Returns the string for the name of the constants array.";

%feature("docstring") libcellml::GeneratorProfile::setVariablesArrayString
"Sets the string for the name of the variables array.";
%feature("docstring") libcellml::GeneratorProfile::setConstantsArrayString
"Sets the string for the name of the constants array.";

%feature("docstring") libcellml::GeneratorProfile::computedConstantsArrayString
"Returns the string for the name of the computed constants array.";

%feature("docstring") libcellml::GeneratorProfile::setComputedConstantsArrayString
"Sets the string for the name of the computed constants array.";

%feature("docstring") libcellml::GeneratorProfile::algebraicArrayString
"Returns the string for the name of the algebraic array.";

%feature("docstring") libcellml::GeneratorProfile::setAlgebraicArrayString
"Sets the string for the name of the algebraic array.";

%feature("docstring") libcellml::GeneratorProfile::externalVariableMethodTypeDefinitionString
"Returns the string for the type definition of an external variable method.";
Expand Down
8 changes: 6 additions & 2 deletions src/bindings/javascript/generatorprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,12 @@ EMSCRIPTEN_BINDINGS(libcellml_generatorprofile)
.function("setStatesArrayString", &libcellml::GeneratorProfile::setStatesArrayString)
.function("ratesArrayString", &libcellml::GeneratorProfile::ratesArrayString)
.function("setRatesArrayString", &libcellml::GeneratorProfile::setRatesArrayString)
.function("variablesArrayString", &libcellml::GeneratorProfile::variablesArrayString)
.function("setVariablesArrayString", &libcellml::GeneratorProfile::setVariablesArrayString)
.function("constantsArrayString", &libcellml::GeneratorProfile::constantsArrayString)
.function("setConstantsArrayString", &libcellml::GeneratorProfile::setConstantsArrayString)
.function("computedConstantsArrayString", &libcellml::GeneratorProfile::computedConstantsArrayString)
.function("setComputedConstantsArrayString", &libcellml::GeneratorProfile::setComputedConstantsArrayString)
.function("algebraicArrayString", &libcellml::GeneratorProfile::algebraicArrayString)
.function("setAlgebraicArrayString", &libcellml::GeneratorProfile::setAlgebraicArrayString)
.function("externalVariableMethodTypeDefinitionString", &libcellml::GeneratorProfile::externalVariableMethodTypeDefinitionString)
.function("setExternalVariableMethodTypeDefinitionString", &libcellml::GeneratorProfile::setExternalVariableMethodTypeDefinitionString)
.function("externalVariableMethodCallString", &libcellml::GeneratorProfile::externalVariableMethodCallString)
Expand Down
18 changes: 13 additions & 5 deletions src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,11 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
for (i = 0; i < variablesCount; ++i) {
auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ?
mProfile->ratesArrayString() :
mProfile->variablesArrayString();
(variables[i]->type() == AnalyserVariable::Type::CONSTANT) ?
mProfile->constantsArrayString() :
(variables[i]->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) ?
mProfile->computedConstantsArrayString() :
mProfile->algebraicArrayString();

methodBody += mProfile->indentString()
+ arrayString + mProfile->openArrayString() + convertToString(variables[i]->index()) + mProfile->closeArrayString()
Expand Down Expand Up @@ -851,7 +855,7 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
for (i = 0; i < variablesCount; ++i) {
auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ?
mProfile->ratesArrayString() :
mProfile->variablesArrayString();
mProfile->algebraicArrayString();

methodBody += mProfile->indentString()
+ mProfile->uArrayString() + mProfile->openArrayString() + convertToString(i) + mProfile->closeArrayString()
Expand All @@ -871,7 +875,7 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
for (i = 0; i < variablesCount; ++i) {
auto arrayString = (variables[i]->type() == AnalyserVariable::Type::STATE) ?
mProfile->ratesArrayString() :
mProfile->variablesArrayString();
mProfile->algebraicArrayString();

methodBody += mProfile->indentString()
+ arrayString + mProfile->openArrayString() + convertToString(variables[i]->index()) + mProfile->closeArrayString()
Expand Down Expand Up @@ -923,7 +927,7 @@ std::string Generator::GeneratorImpl::generateDoubleOrConstantVariableNameCode(c
auto initValueVariable = owningComponent(variable)->variable(variable->initialValue());
auto analyserInitialValueVariable = analyserVariable(initValueVariable);

return mProfile->variablesArrayString() + mProfile->openArrayString() + convertToString(analyserInitialValueVariable->index()) + mProfile->closeArrayString();
return mProfile->constantsArrayString() + mProfile->openArrayString() + convertToString(analyserInitialValueVariable->index()) + mProfile->closeArrayString();
}

std::string Generator::GeneratorImpl::generateVariableNameCode(const VariablePtr &variable,
Expand All @@ -950,8 +954,12 @@ std::string Generator::GeneratorImpl::generateVariableNameCode(const VariablePtr
arrayName = state ?
mProfile->statesArrayString() :
mProfile->ratesArrayString();
} else if (analyserVariable->type() == AnalyserVariable::Type::CONSTANT) {
arrayName = mProfile->constantsArrayString();
} else if (analyserVariable->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) {
arrayName = mProfile->computedConstantsArrayString();
} else {
arrayName = mProfile->variablesArrayString();
arrayName = mProfile->algebraicArrayString();
}

return arrayName + mProfile->openArrayString() + convertToString(analyserVariable->index()) + mProfile->closeArrayString();
Expand Down
40 changes: 33 additions & 7 deletions src/generatorprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ struct GeneratorProfile::GeneratorProfileImpl

std::string mStatesArrayString;
std::string mRatesArrayString;
std::string mVariablesArrayString;
std::string mConstantsArrayString;
std::string mComputedConstantsArrayString;
std::string mAlgebraicArrayString;

std::string mExternalVariableMethodTypeDefinitionFamString;
std::string mExternalVariableMethodTypeDefinitionFdmString;
Expand Down Expand Up @@ -580,7 +582,9 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi

mStatesArrayString = "states";
mRatesArrayString = "rates";
mVariablesArrayString = "variables";
mConstantsArrayString = "constants";
mComputedConstantsArrayString = "computedConstants";
mAlgebraicArrayString = "algebraic";

mExternalVariableMethodTypeDefinitionFamString = "typedef double (* ExternalVariable)(double *variables, size_t index);\n";
mExternalVariableMethodTypeDefinitionFdmString = "typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index);\n";
Expand Down Expand Up @@ -1014,7 +1018,9 @@ void GeneratorProfile::GeneratorProfileImpl::loadProfile(GeneratorProfile::Profi

mStatesArrayString = "states";
mRatesArrayString = "rates";
mVariablesArrayString = "variables";
mConstantsArrayString = "constants";
mComputedConstantsArrayString = "computed_constants";
mAlgebraicArrayString = "algebraic";

mExternalVariableMethodTypeDefinitionFamString = "";
mExternalVariableMethodTypeDefinitionFdmString = "";
Expand Down Expand Up @@ -2535,14 +2541,34 @@ void GeneratorProfile::setRatesArrayString(const std::string &ratesArrayString)
mPimpl->mRatesArrayString = ratesArrayString;
}

std::string GeneratorProfile::variablesArrayString() const
std::string GeneratorProfile::constantsArrayString() const
{
return mPimpl->mVariablesArrayString;
return mPimpl->mConstantsArrayString;
}

void GeneratorProfile::setVariablesArrayString(const std::string &variablesArrayString)
void GeneratorProfile::setConstantsArrayString(const std::string &constantsArrayString)
{
mPimpl->mVariablesArrayString = variablesArrayString;
mPimpl->mConstantsArrayString = constantsArrayString;
}

std::string GeneratorProfile::computedConstantsArrayString() const
{
return mPimpl->mComputedConstantsArrayString;
}

void GeneratorProfile::setComputedConstantsArrayString(const std::string &computedConstantsArrayString)
{
mPimpl->mComputedConstantsArrayString = computedConstantsArrayString;
}

std::string GeneratorProfile::algebraicArrayString() const
{
return mPimpl->mAlgebraicArrayString;
}

void GeneratorProfile::setAlgebraicArrayString(const std::string &algebraicArrayString)
{
mPimpl->mAlgebraicArrayString = algebraicArrayString;
}

std::string GeneratorProfile::externalVariableMethodTypeDefinitionString(bool forDifferentialModel) const
Expand Down
4 changes: 2 additions & 2 deletions src/generatorprofilesha1values.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace libcellml {
* The content of this file is generated, do not edit this file directly.
* See docs/dev_utilities.rst for further information.
*/
static const char C_GENERATOR_PROFILE_SHA1[] = "060945ab10d8ce4ce063e4b64199f684ec0150a5";
static const char PYTHON_GENERATOR_PROFILE_SHA1[] = "859d7920e76c1a12345a2d642940163d41d27112";
static const char C_GENERATOR_PROFILE_SHA1[] = "f36d3c679b030a09095376711d4dc9a638a5c7b3";
static const char PYTHON_GENERATOR_PROFILE_SHA1[] = "bb03c147d17a9741667957068ef629058846d2e4";

} // namespace libcellml
4 changes: 3 additions & 1 deletion src/generatorprofiletools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ std::string generatorProfileAsString(const GeneratorProfilePtr &generatorProfile

profileContents += generatorProfile->statesArrayString()
+ generatorProfile->ratesArrayString()
+ generatorProfile->variablesArrayString();
+ generatorProfile->constantsArrayString()
+ generatorProfile->computedConstantsArrayString()
+ generatorProfile->algebraicArrayString();

profileContents += generatorProfile->externalVariableMethodTypeDefinitionString(false)
+ generatorProfile->externalVariableMethodTypeDefinitionString(true);
Expand Down
18 changes: 15 additions & 3 deletions tests/bindings/javascript/generatorprofile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,11 +897,23 @@ describe("GeneratorProfile tests", () => {
x.setRatesArrayString("something")
expect(x.ratesArrayString()).toBe("something")
});
test("Checking GeneratorProfile.variablesArrayString.", () => {
test("Checking GeneratorProfile.constantsArrayString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setVariablesArrayString("something")
expect(x.variablesArrayString()).toBe("something")
x.setConstantsArrayString("something")
expect(x.constantsArrayString()).toBe("something")
});
test("Checking GeneratorProfile.computedConstantsArrayString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setComputedConstantsArrayString("something")
expect(x.computedConstantsArrayString()).toBe("something")
});
test("Checking GeneratorProfile.algebraicArrayString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)

x.setAlgebraicArrayString("something")
expect(x.algebraicArrayString()).toBe("something")
});
test("Checking GeneratorProfile.externalVariableMethodTypeDefinitionString.", () => {
const x = new libcellml.GeneratorProfile(libcellml.GeneratorProfile.Profile.C)
Expand Down
26 changes: 22 additions & 4 deletions tests/bindings/python/test_generator_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,14 +1607,32 @@ def test_variable_type_object_string(self):
g.setVariableTypeObjectString(True, True, GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.variableTypeObjectString(True, True))

def test_variables_array_string(self):
def test_constants_array_string(self):
from libcellml import GeneratorProfile

g = GeneratorProfile()

self.assertEqual('variables', g.variablesArrayString())
g.setVariablesArrayString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.variablesArrayString())
self.assertEqual('constants', g.constantsArrayString())
g.setConstantsArrayString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.constantsArrayString())

def test_computed_constants_array_string(self):
from libcellml import GeneratorProfile

g = GeneratorProfile()

self.assertEqual('computedConstants', g.computedConstantsArrayString())
g.setComputedConstantsArrayString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.computedConstantsArrayString())

def test_algebraic_array_string(self):
from libcellml import GeneratorProfile

g = GeneratorProfile()

self.assertEqual('algebraic', g.algebraicArrayString())
g.setAlgebraicArrayString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.algebraicArrayString())

def test_external_variable_method_type_definition_string(self):
from libcellml import GeneratorProfile
Expand Down
12 changes: 9 additions & 3 deletions tests/generator/generatorprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ TEST(GeneratorProfile, defaultMiscellaneousValues)

EXPECT_EQ("states", generatorProfile->statesArrayString());
EXPECT_EQ("rates", generatorProfile->ratesArrayString());
EXPECT_EQ("variables", generatorProfile->variablesArrayString());
EXPECT_EQ("constants", generatorProfile->constantsArrayString());
EXPECT_EQ("computedConstants", generatorProfile->computedConstantsArrayString());
EXPECT_EQ("algebraic", generatorProfile->algebraicArrayString());

EXPECT_EQ("typedef double (* ExternalVariable)(double *variables, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(false));
EXPECT_EQ("typedef double (* ExternalVariable)(double voi, double *states, double *rates, double *variables, size_t index);\n", generatorProfile->externalVariableMethodTypeDefinitionString(true));
Expand Down Expand Up @@ -909,7 +911,9 @@ TEST(GeneratorProfile, miscellaneous)

generatorProfile->setStatesArrayString(value);
generatorProfile->setRatesArrayString(value);
generatorProfile->setVariablesArrayString(value);
generatorProfile->setConstantsArrayString(value);
generatorProfile->setComputedConstantsArrayString(value);
generatorProfile->setAlgebraicArrayString(value);

generatorProfile->setExternalVariableMethodTypeDefinitionString(false, value);
generatorProfile->setExternalVariableMethodTypeDefinitionString(true, value);
Expand Down Expand Up @@ -1044,7 +1048,9 @@ TEST(GeneratorProfile, miscellaneous)

EXPECT_EQ(value, generatorProfile->statesArrayString());
EXPECT_EQ(value, generatorProfile->ratesArrayString());
EXPECT_EQ(value, generatorProfile->variablesArrayString());
EXPECT_EQ(value, generatorProfile->constantsArrayString());
EXPECT_EQ(value, generatorProfile->computedConstantsArrayString());
EXPECT_EQ(value, generatorProfile->algebraicArrayString());

EXPECT_EQ(value, generatorProfile->externalVariableMethodTypeDefinitionString(false));
EXPECT_EQ(value, generatorProfile->externalVariableMethodTypeDefinitionString(true));
Expand Down
Loading

0 comments on commit c2504d7

Please sign in to comment.