Skip to content

Commit 8b590e7

Browse files
committed
Reverted commit 6a48c0f.
1 parent e832e17 commit 8b590e7

File tree

64 files changed

+2295
-2297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2295
-2297
lines changed

src/analyser.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -483,36 +483,34 @@ void Analyser::AnalyserImpl::analyseNode(const XmlNodePtr &node,
483483
// +-------------+
484484

485485
auto childCount = mathmlChildCount(node);
486+
AnalyserEquationAstPtr tempAst;
487+
AnalyserEquationAstPtr astRightChild;
486488

487-
analyseNode(mathmlChildNode(node, 0), ast, astParent, component, equation);
488-
489-
if (childCount >= 2) {
490-
analyseNode(mathmlChildNode(node, 1), ast->mPimpl->mOwnedLeftChild, ast, component, equation);
491-
492-
if (childCount >= 3) {
493-
AnalyserEquationAstPtr astRightChild;
494-
AnalyserEquationAstPtr tempAst;
495-
496-
analyseNode(mathmlChildNode(node, childCount - 1), astRightChild, nullptr, component, equation);
497-
498-
for (auto i = childCount - 2; i > 1; --i) {
499-
tempAst = AnalyserEquationAst::create();
500-
501-
analyseNode(mathmlChildNode(node, 0), tempAst, nullptr, component, equation);
502-
analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation);
489+
for (size_t i = childCount - 1; i > 0; --i) {
490+
astRightChild = tempAst;
491+
tempAst = AnalyserEquationAst::create();
503492

493+
if (astRightChild != nullptr) {
494+
if (i == childCount - 2) {
495+
astRightChild->swapLeftAndRightChildren();
496+
tempAst = astRightChild;
497+
} else {
504498
astRightChild->mPimpl->mParent = tempAst;
505-
506499
tempAst->mPimpl->mOwnedRightChild = astRightChild;
507-
astRightChild = tempAst;
508500
}
501+
}
509502

510-
astRightChild->mPimpl->mParent = ast;
511-
512-
ast->mPimpl->mOwnedRightChild = astRightChild;
503+
if (i != childCount - 2) {
504+
analyseNode(mathmlChildNode(node, 0), tempAst, nullptr, component, equation);
513505
}
506+
507+
analyseNode(mathmlChildNode(node, i), tempAst->mPimpl->mOwnedLeftChild, tempAst, component, equation);
514508
}
515509

510+
analyseNode(mathmlChildNode(node, 0), tempAst, astParent, component, equation);
511+
512+
ast = tempAst;
513+
516514
// Relational and logical operators.
517515

518516
} else if (node->isMathmlElement("eq")) {

tests/analyser/analyser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ TEST(Analyser, algebraicSystemWithThreeLinkedUnknownsWithOneExternalVariable)
921921
EXPECT_EQ(size_t(0), parser->issueCount());
922922

923923
const std::vector<std::string> expectedIssues = {
924-
"Variable 'y' in component 'my_algebraic_system' is computed more than once.",
925924
"Variable 'z' in component 'my_algebraic_system' is computed more than once.",
925+
"Variable 'y' in component 'my_algebraic_system' is computed more than once.",
926926
};
927927

928928
auto analyser = libcellml::Analyser::create();
@@ -977,8 +977,8 @@ TEST(Analyser, overconstrainedNlaSystem)
977977
EXPECT_EQ(size_t(0), parser->issueCount());
978978

979979
const std::vector<std::string> expectedIssues = {
980-
"Variable 'x' in component 'my_algebraic_system' is computed more than once.",
981980
"Variable 'y' in component 'my_algebraic_system' is computed more than once.",
981+
"Variable 'x' in component 'my_algebraic_system' is computed more than once.",
982982
};
983983

984984
auto analyser = libcellml::Analyser::create();

tests/analyser/analyserunits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ TEST(AnalyserUnits, powerValues)
883883
"The units in 'eqnPi = pow(x, pi)' in component 'my_component' are not equivalent. 'eqnPi' is in 'second' while 'pow(x, pi)' is in 'second^3.14159'.",
884884
"The units in 'eqnInfinity = pow(x, infinity)' in component 'my_component' are not equivalent. 'eqnInfinity' is in 'second' while 'pow(x, infinity)' is in 'second^inf' (i.e. '10^nan x second^inf').",
885885
"The units in 'eqnNotanumber = pow(x, notanumber)' in component 'my_component' are not equivalent. 'eqnNotanumber' is in 'second' while 'pow(x, notanumber)' is in 'second^nan' (i.e. '10^nan x second^nan').",
886-
"The type of variable 'eqnCoverage' in component 'my_component' is unknown.",
887886
"The type of variable 'u' in component 'my_component' is unknown.",
887+
"The type of variable 'eqnCoverage' in component 'my_component' is unknown.",
888888
"The type of variable 'eqnCoverage2' in component 'my_component' is unknown.",
889889
"The type of variable 'eqnCoverage3' in component 'my_component' is unknown.",
890890
};

tests/resources/coverage/generator/model.c

Lines changed: 200 additions & 200 deletions
Large diffs are not rendered by default.

tests/resources/coverage/generator/model.implementation.out

Lines changed: 195 additions & 195 deletions
Large diffs are not rendered by default.

tests/resources/coverage/generator/model.modified.profile.c

Lines changed: 200 additions & 200 deletions
Large diffs are not rendered by default.

tests/resources/coverage/generator/model.modified.profile.py

Lines changed: 200 additions & 200 deletions
Large diffs are not rendered by default.

tests/resources/coverage/generator/model.out

Lines changed: 189 additions & 189 deletions
Large diffs are not rendered by default.

tests/resources/coverage/generator/model.py

Lines changed: 200 additions & 200 deletions
Large diffs are not rendered by default.

tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const VariableInfo CONSTANT_INFO[] = {
1616
};
1717

1818
const VariableInfo COMPUTED_CONSTANT_INFO[] = {
19-
{"x", "dimensionless", "my_algebraic_eqn"},
20-
{"a", "dimensionless", "my_algebraic_eqn"}
19+
{"a", "dimensionless", "my_algebraic_eqn"},
20+
{"x", "dimensionless", "my_algebraic_eqn"}
2121
};
2222

2323
const VariableInfo ALGEBRAIC_INFO[] = {
@@ -63,12 +63,12 @@ void deleteArray(double *array)
6363

6464
void initialiseVariables(double *constants, double *computedConstants, double *algebraic)
6565
{
66-
computedConstants[1] = 1.0;
66+
computedConstants[0] = 1.0;
6767
}
6868

6969
void computeComputedConstants(double *constants, double *computedConstants)
7070
{
71-
computedConstants[0] = computedConstants[1];
71+
computedConstants[1] = computedConstants[0];
7272
}
7373

7474
void computeVariables(double *constants, double *computedConstants, double *algebraic)

tests/resources/generator/algebraic_eqn_computed_var_on_rhs/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
]
1616

1717
COMPUTED_CONSTANT_INFO = [
18-
{"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn"},
19-
{"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"}
18+
{"name": "a", "units": "dimensionless", "component": "my_algebraic_eqn"},
19+
{"name": "x", "units": "dimensionless", "component": "my_algebraic_eqn"}
2020
]
2121

2222
ALGEBRAIC_INFO = [
@@ -36,11 +36,11 @@ def create_algebraic_array():
3636

3737

3838
def initialise_variables(constants, computed_constants, algebraic):
39-
computed_constants[1] = 1.0
39+
computed_constants[0] = 1.0
4040

4141

4242
def compute_computed_constants(constants, computed_constants):
43-
computed_constants[0] = computed_constants[1]
43+
computed_constants[1] = computed_constants[0]
4444

4545

4646
def compute_variables(constants, computed_constants, algebraic):

tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const VariableInfo COMPUTED_CONSTANT_INFO[] = {
1919
};
2020

2121
const VariableInfo ALGEBRAIC_INFO[] = {
22-
{"x", "dimensionless", "my_algebraic_system"},
22+
{"z", "dimensionless", "my_algebraic_system"},
2323
{"y", "dimensionless", "my_algebraic_system"},
24-
{"z", "dimensionless", "my_algebraic_system"}
24+
{"x", "dimensionless", "my_algebraic_system"}
2525
};
2626

2727
double * createConstantsArray()
@@ -81,9 +81,9 @@ void objectiveFunction0(double *u, double *f, void *data)
8181
algebraic[1] = u[1];
8282
algebraic[2] = u[2];
8383

84-
f[0] = 2.0*algebraic[0]+algebraic[1]-2.0*algebraic[2]-(-1.0);
85-
f[1] = 3.0*algebraic[0]-3.0*algebraic[1]-algebraic[2]-5.0;
86-
f[2] = algebraic[0]-2.0*algebraic[1]+3.0*algebraic[2]-6.0;
84+
f[0] = 2.0*algebraic[2]+algebraic[1]-2.0*algebraic[0]-(-1.0);
85+
f[1] = 3.0*algebraic[2]-3.0*algebraic[1]-algebraic[0]-5.0;
86+
f[2] = algebraic[2]-2.0*algebraic[1]+3.0*algebraic[0]-6.0;
8787
}
8888

8989
void findRoot0(double *constants, double *computedConstants, double *algebraic)

tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const VariableInfo ALGEBRAIC_INFO[] = {
2323
};
2424

2525
const VariableInfo EXTERNAL_INFO[] = {
26-
{"x", "dimensionless", "my_algebraic_system"},
26+
{"z", "dimensionless", "my_algebraic_system"},
2727
{"y", "dimensionless", "my_algebraic_system"},
28-
{"z", "dimensionless", "my_algebraic_system"}
28+
{"x", "dimensionless", "my_algebraic_system"}
2929
};
3030

3131
double * createConstantsArray()

tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
]
2323

2424
EXTERNAL_INFO = [
25-
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"},
25+
{"name": "z", "units": "dimensionless", "component": "my_algebraic_system"},
2626
{"name": "y", "units": "dimensionless", "component": "my_algebraic_system"},
27-
{"name": "z", "units": "dimensionless", "component": "my_algebraic_system"}
27+
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}
2828
]
2929

3030

tests/resources/generator/algebraic_system_with_three_linked_unknowns/model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
]
1919

2020
ALGEBRAIC_INFO = [
21-
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"},
21+
{"name": "z", "units": "dimensionless", "component": "my_algebraic_system"},
2222
{"name": "y", "units": "dimensionless", "component": "my_algebraic_system"},
23-
{"name": "z", "units": "dimensionless", "component": "my_algebraic_system"}
23+
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}
2424
]
2525

2626

@@ -48,9 +48,9 @@ def objective_function_0(u, f, data):
4848
algebraic[1] = u[1]
4949
algebraic[2] = u[2]
5050

51-
f[0] = 2.0*algebraic[0]+algebraic[1]-2.0*algebraic[2]-(-1.0)
52-
f[1] = 3.0*algebraic[0]-3.0*algebraic[1]-algebraic[2]-5.0
53-
f[2] = algebraic[0]-2.0*algebraic[1]+3.0*algebraic[2]-6.0
51+
f[0] = 2.0*algebraic[2]+algebraic[1]-2.0*algebraic[0]-(-1.0)
52+
f[1] = 3.0*algebraic[2]-3.0*algebraic[1]-algebraic[0]-5.0
53+
f[2] = algebraic[2]-2.0*algebraic[1]+3.0*algebraic[0]-6.0
5454

5555

5656
def find_root_0(constants, computed_constants, algebraic):

tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ const size_t COMPUTED_CONSTANT_COUNT = 1;
1313
const size_t ALGEBRAIC_COUNT = 3;
1414

1515
const VariableInfo CONSTANT_INFO[] = {
16-
{"x", "dimensionless", "my_algebraic_system"},
17-
{"y", "dimensionless", "my_algebraic_system"}
16+
{"y", "dimensionless", "my_algebraic_system"},
17+
{"x", "dimensionless", "my_algebraic_system"}
1818
};
1919

2020
const VariableInfo COMPUTED_CONSTANT_INFO[] = {
2121
{"a", "dimensionless", "my_algebraic_system"}
2222
};
2323

2424
const VariableInfo ALGEBRAIC_INFO[] = {
25-
{"d", "dimensionless", "my_algebraic_system"},
25+
{"c", "dimensionless", "my_algebraic_system"},
2626
{"b", "dimensionless", "my_algebraic_system"},
27-
{"c", "dimensionless", "my_algebraic_system"}
27+
{"d", "dimensionless", "my_algebraic_system"}
2828
};
2929

3030
double * createConstantsArray()
@@ -80,42 +80,42 @@ void objectiveFunction0(double *u, double *f, void *data)
8080
double *computedConstants = ((RootFindingInfo *) data)->computedConstants;
8181
double *algebraic = ((RootFindingInfo *) data)->algebraic;
8282

83-
algebraic[2] = u[0];
83+
algebraic[0] = u[0];
8484
algebraic[1] = u[1];
8585

86-
f[0] = 3.0*computedConstants[0]+2.0*algebraic[1]+algebraic[2]-57.0;
87-
f[1] = computedConstants[0]+3.0*algebraic[1]-algebraic[2]-19.0;
86+
f[0] = 3.0*computedConstants[0]+2.0*algebraic[1]+algebraic[0]-57.0;
87+
f[1] = computedConstants[0]+3.0*algebraic[1]-algebraic[0]-19.0;
8888
}
8989

9090
void findRoot0(double *constants, double *computedConstants, double *algebraic)
9191
{
9292
RootFindingInfo rfi = { constants, computedConstants, algebraic };
9393
double u[2];
9494

95-
u[0] = algebraic[2];
95+
u[0] = algebraic[0];
9696
u[1] = algebraic[1];
9797

9898
nlaSolve(objectiveFunction0, u, 2, &rfi);
9999

100-
algebraic[2] = u[0];
100+
algebraic[0] = u[0];
101101
algebraic[1] = u[1];
102102
}
103103

104104
void initialiseVariables(double *constants, double *computedConstants, double *algebraic)
105105
{
106-
constants[0] = 3.0;
107-
constants[1] = 5.0;
106+
constants[0] = 5.0;
107+
constants[1] = 3.0;
108+
algebraic[0] = 1.0;
108109
algebraic[1] = 1.0;
109-
algebraic[2] = 1.0;
110110
}
111111

112112
void computeComputedConstants(double *constants, double *computedConstants)
113113
{
114-
computedConstants[0] = 3.0*constants[0]+constants[1];
114+
computedConstants[0] = 3.0*constants[1]+constants[0];
115115
}
116116

117117
void computeVariables(double *constants, double *computedConstants, double *algebraic)
118118
{
119119
findRoot0(constants, computedConstants, algebraic);
120-
algebraic[0] = algebraic[1]+algebraic[2];
120+
algebraic[2] = algebraic[1]+algebraic[0];
121121
}

tests/resources/generator/algebraic_system_with_various_dependencies/model.not.ordered.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
ALGEBRAIC_COUNT = 3
1313

1414
CONSTANT_INFO = [
15-
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"},
16-
{"name": "y", "units": "dimensionless", "component": "my_algebraic_system"}
15+
{"name": "y", "units": "dimensionless", "component": "my_algebraic_system"},
16+
{"name": "x", "units": "dimensionless", "component": "my_algebraic_system"}
1717
]
1818

1919
COMPUTED_CONSTANT_INFO = [
2020
{"name": "a", "units": "dimensionless", "component": "my_algebraic_system"}
2121
]
2222

2323
ALGEBRAIC_INFO = [
24-
{"name": "d", "units": "dimensionless", "component": "my_algebraic_system"},
24+
{"name": "c", "units": "dimensionless", "component": "my_algebraic_system"},
2525
{"name": "b", "units": "dimensionless", "component": "my_algebraic_system"},
26-
{"name": "c", "units": "dimensionless", "component": "my_algebraic_system"}
26+
{"name": "d", "units": "dimensionless", "component": "my_algebraic_system"}
2727
]
2828

2929

@@ -47,36 +47,36 @@ def objective_function_0(u, f, data):
4747
computed_constants = data[1]
4848
algebraic = data[2]
4949

50-
algebraic[2] = u[0]
50+
algebraic[0] = u[0]
5151
algebraic[1] = u[1]
5252

53-
f[0] = 3.0*computed_constants[0]+2.0*algebraic[1]+algebraic[2]-57.0
54-
f[1] = computed_constants[0]+3.0*algebraic[1]-algebraic[2]-19.0
53+
f[0] = 3.0*computed_constants[0]+2.0*algebraic[1]+algebraic[0]-57.0
54+
f[1] = computed_constants[0]+3.0*algebraic[1]-algebraic[0]-19.0
5555

5656

5757
def find_root_0(constants, computed_constants, algebraic):
5858
u = [nan]*2
5959

60-
u[0] = algebraic[2]
60+
u[0] = algebraic[0]
6161
u[1] = algebraic[1]
6262

6363
u = nla_solve(objective_function_0, u, 2, [constants, computed_constants, algebraic])
6464

65-
algebraic[2] = u[0]
65+
algebraic[0] = u[0]
6666
algebraic[1] = u[1]
6767

6868

6969
def initialise_variables(constants, computed_constants, algebraic):
70-
constants[0] = 3.0
71-
constants[1] = 5.0
70+
constants[0] = 5.0
71+
constants[1] = 3.0
72+
algebraic[0] = 1.0
7273
algebraic[1] = 1.0
73-
algebraic[2] = 1.0
7474

7575

7676
def compute_computed_constants(constants, computed_constants):
77-
computed_constants[0] = 3.0*constants[0]+constants[1]
77+
computed_constants[0] = 3.0*constants[1]+constants[0]
7878

7979

8080
def compute_variables(constants, computed_constants, algebraic):
8181
find_root_0(constants, computed_constants, algebraic)
82-
algebraic[0] = algebraic[1]+algebraic[2]
82+
algebraic[2] = algebraic[1]+algebraic[0]

tests/resources/generator/algebraic_system_with_various_dependencies/model.ordered.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const size_t COMPUTED_CONSTANT_COUNT = 1;
1313
const size_t ALGEBRAIC_COUNT = 3;
1414

1515
const VariableInfo CONSTANT_INFO[] = {
16-
{"x", "dimensionless", "my_algebraic_system"},
17-
{"y", "dimensionless", "my_algebraic_system"}
16+
{"y", "dimensionless", "my_algebraic_system"},
17+
{"x", "dimensionless", "my_algebraic_system"}
1818
};
1919

2020
const VariableInfo COMPUTED_CONSTANT_INFO[] = {
@@ -103,15 +103,15 @@ void findRoot0(double *constants, double *computedConstants, double *algebraic)
103103

104104
void initialiseVariables(double *constants, double *computedConstants, double *algebraic)
105105
{
106-
constants[0] = 3.0;
107-
constants[1] = 5.0;
106+
constants[0] = 5.0;
107+
constants[1] = 3.0;
108108
algebraic[0] = 1.0;
109109
algebraic[1] = 1.0;
110110
}
111111

112112
void computeComputedConstants(double *constants, double *computedConstants)
113113
{
114-
computedConstants[0] = 3.0*constants[0]+constants[1];
114+
computedConstants[0] = 3.0*constants[1]+constants[0];
115115
}
116116

117117
void computeVariables(double *constants, double *computedConstants, double *algebraic)

0 commit comments

Comments
 (0)