Skip to content

Commit

Permalink
Merge branch 'issue1260' into issue1218
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Oct 22, 2024
2 parents 26182a4 + 5a3a19e commit 8925f71
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 55 deletions.
1 change: 0 additions & 1 deletion src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License.
#include "libcellml/analyservariable.h"
#include "libcellml/version.h"

#include "commonutils.h"
#include "generator_p.h"
#include "generatorinterpreter_p.h"
#include "generatorprofilesha1values.h"
Expand Down
3 changes: 1 addition & 2 deletions src/generatorinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,7 @@ void GeneratorInterpreter::GeneratorInterpreterImpl::initialiseVariables(std::ve
methodBody += generateInitialisationCode(state);
}

// Use an initial guess of zero for rates computed using an NLA system
// (see the note below).
// Use an initial guess of zero for rates computed using an NLA system (see the note below).

for (const auto &state : mModel->states()) {
if (state->equation(0)->type() == AnalyserEquation::Type::NLA) {
Expand Down
3 changes: 1 addition & 2 deletions src/generatorinterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class GeneratorInterpreter
std::vector<InterpreterStatementPtr> computeVariablesStatements() const;

private:
GeneratorInterpreter(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile,
const std::string &code); /**< Constructor, @private. */
GeneratorInterpreter(const AnalyserModelPtr &model, const GeneratorProfilePtr &profile, const std::string &code); /**< Constructor, @private. */
GeneratorInterpreter(const AnalyserModelPtr &model); /**< Constructor, @private. */
GeneratorInterpreter(const AnalyserEquationAstPtr &ast, const GeneratorProfilePtr &profile); /**< Constructor, @private. */

Expand Down
15 changes: 5 additions & 10 deletions src/generatorinterpreter_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,14 @@ struct GeneratorInterpreter::GeneratorInterpreterImpl
std::string generateVariableNameCode(const VariablePtr &variable,
bool rate = false) const;

std::string generateOperatorCode(const std::string &op,
const AnalyserEquationAstPtr &ast,
std::string generateOperatorCode(const std::string &op, const AnalyserEquationAstPtr &ast,
const InterpreterStatementPtr &statement = nullptr) const;
std::string generateMinusUnaryCode(const AnalyserEquationAstPtr &ast,
const InterpreterStatementPtr &statement) const;
std::string generateOneParameterFunctionCode(const std::string &function,
const AnalyserEquationAstPtr &ast,
std::string generateMinusUnaryCode(const AnalyserEquationAstPtr &ast, const InterpreterStatementPtr &statement) const;
std::string generateOneParameterFunctionCode(const std::string &function, const AnalyserEquationAstPtr &ast,
const InterpreterStatementPtr &statement = nullptr) const;
std::string generateTwoParameterFunctionCode(const std::string &function,
const AnalyserEquationAstPtr &ast,
std::string generateTwoParameterFunctionCode(const std::string &function, const AnalyserEquationAstPtr &ast,
const InterpreterStatementPtr &statement = nullptr) const;
std::string generatePiecewiseIfCode(const std::string &condition,
const std::string &value) const;
std::string generatePiecewiseIfCode(const std::string &condition, const std::string &value) const;
std::string generatePiecewiseElseCode(const std::string &value) const;
std::tuple<std::string, InterpreterStatementPtr> generateCode(const AnalyserEquationAstPtr &ast) const;

Expand Down
56 changes: 16 additions & 40 deletions tests/coverage/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,53 +632,29 @@ TEST(Coverage, generator)
EXPECT_EQ(size_t(1), analyserModel->equation(0)->states().size());
EXPECT_NE(nullptr, analyserModel->equation(0)->state(0));
EXPECT_EQ(nullptr, analyserModel->equation(0)->state(analyserModel->equation(0)->stateCount()));
/*---GRY--- STILL NEEDED?
EXPECT_NE(nullptr, analyserModel->equation(199));
EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencyCount());
EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencies().size());
EXPECT_NE(nullptr, analyserModel->equation(199)->dependency(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->dependency(analyserModel->equation(199)->dependencyCount()));
EXPECT_EQ(size_t(1), analyserModel->equation(199)->nlaSiblingCount());
EXPECT_EQ(size_t(1), analyserModel->equation(199)->nlaSiblings().size());
EXPECT_NE(nullptr, analyserModel->equation(199)->nlaSibling(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->nlaSibling(analyserModel->equation(199)->nlaSiblingCount()));
EXPECT_EQ(size_t(0), analyserModel->equation(199)->computedConstantCount());
EXPECT_EQ(size_t(0), analyserModel->equation(199)->computedConstants().size());
EXPECT_EQ(nullptr, analyserModel->equation(199)->computedConstant(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->computedConstant(analyserModel->equation(199)->computedConstantCount()));
EXPECT_NE(size_t(0), analyserModel->equation(199)->algebraicCount());
EXPECT_NE(size_t(0), analyserModel->equation(199)->algebraic().size());
EXPECT_NE(nullptr, analyserModel->equation(199)->algebraic(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->algebraic(analyserModel->equation(199)->algebraicCount()));
EXPECT_EQ(size_t(0), analyserModel->equation(199)->externalCount());
EXPECT_EQ(size_t(0), analyserModel->equation(199)->externals().size());
EXPECT_EQ(nullptr, analyserModel->equation(199)->external(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->external(analyserModel->equation(199)->externalCount()));
EXPECT_EQ(nullptr, analyserModel->equation(analyserModel->equationCount()));
*/

for (const auto &equation : analyserModel->equations()) {
equation->dependencyCount();
equation->dependency(0);
equation->dependency(equation->dependencyCount());
equation->nlaSiblingCount();
equation->nlaSibling(0);
equation->nlaSibling(equation->nlaSiblingCount());
equation->computedConstantCount();
equation->computedConstant(0);
equation->computedConstant(equation->computedConstantCount());
equation->algebraicCount();
equation->algebraic(0);
equation->algebraic(equation->algebraicCount());
equation->externalCount();
equation->external(0);
equation->external(equation->externalCount());

checkAstTypeAsString(equation->ast());
}

auto generator = libcellml::Generator::create();

EXPECT_EQ(nullptr, analyserModel->voi()->initialisingVariable());

for (size_t i = 0; i < analyserModel->stateCount(); ++i) {
EXPECT_NE(nullptr, analyserModel->state(i)->initialisingVariable());
}

for (size_t i = 0; i < analyserModel->constantCount(); ++i) {
EXPECT_NE(nullptr, analyserModel->constant(i)->initialisingVariable());
}

/*---GRY--- STILL NEEDED?
for (size_t i = 0; i < analyserModel->algebraicCount(); ++i) {
EXPECT_NE(nullptr, analyserModel->algebraic(i)->initialisingVariable());
}
*/

EXPECT_EQ(nullptr, generator->model());
EXPECT_EQ(EMPTY_STRING, generator->interfaceCode());
EXPECT_EQ(EMPTY_STRING, generator->implementationCode());
Expand Down

0 comments on commit 8925f71

Please sign in to comment.