@@ -28,6 +28,7 @@ limitations under the License.
28
28
#include " libcellml/version.h"
29
29
30
30
#include " generator_p.h"
31
+ #include " generatorinterpreter_p.h"
31
32
#include " generatorprofilesha1values.h"
32
33
#include " generatorprofiletools.h"
33
34
#include " utilities.h"
@@ -41,28 +42,6 @@ void Generator::GeneratorImpl::reset()
41
42
mCode = {};
42
43
}
43
44
44
- bool Generator::GeneratorImpl::modelHasOdes () const
45
- {
46
- switch (mModel ->type ()) {
47
- case AnalyserModel::Type::ODE:
48
- case AnalyserModel::Type::DAE:
49
- return true ;
50
- default :
51
- return false ;
52
- }
53
- }
54
-
55
- bool Generator::GeneratorImpl::modelHasNlas () const
56
- {
57
- switch (mModel ->type ()) {
58
- case AnalyserModel::Type::NLA:
59
- case AnalyserModel::Type::DAE:
60
- return true ;
61
- default :
62
- return false ;
63
- }
64
- }
65
-
66
45
AnalyserVariablePtr analyserVariable (const AnalyserModelPtr &model, const VariablePtr &variable)
67
46
{
68
47
// Find and return the analyser variable associated with the given variable.
@@ -330,7 +309,7 @@ void Generator::GeneratorImpl::addStateAndVariableCountCode(bool interface)
330
309
{
331
310
std::string code;
332
311
333
- if (modelHasOdes ()
312
+ if (mModelHasOdes
334
313
&& ((interface && !mProfile ->interfaceStateCountString ().empty ())
335
314
|| (!interface && !mProfile ->implementationStateCountString ().empty ()))) {
336
315
code += interface ?
@@ -416,12 +395,12 @@ void Generator::GeneratorImpl::addInterfaceVariableInfoCode()
416
395
{
417
396
std::string code;
418
397
419
- if (modelHasOdes ()
398
+ if (mModelHasOdes
420
399
&& !mProfile ->interfaceVoiInfoString ().empty ()) {
421
400
code += mProfile ->interfaceVoiInfoString ();
422
401
}
423
402
424
- if (modelHasOdes ()
403
+ if (mModelHasOdes
425
404
&& !mProfile ->interfaceStateInfoString ().empty ()) {
426
405
code += mProfile ->interfaceStateInfoString ();
427
406
}
@@ -482,11 +461,11 @@ void Generator::GeneratorImpl::doAddImplementationVariableInfoCode(const std::st
482
461
483
462
void Generator::GeneratorImpl::addImplementationVariableInfoCode ()
484
463
{
485
- if (modelHasOdes () ) {
464
+ if (mModelHasOdes ) {
486
465
doAddImplementationVariableInfoCode (mProfile ->implementationVoiInfoString (), {mModel ->voi ()}, true );
487
466
}
488
467
489
- if (modelHasOdes () ) {
468
+ if (mModelHasOdes ) {
490
469
doAddImplementationVariableInfoCode (mProfile ->implementationStateInfoString (), mModel ->states (), false );
491
470
}
492
471
@@ -653,7 +632,7 @@ void Generator::GeneratorImpl::addInterfaceCreateDeleteArrayMethodsCode()
653
632
{
654
633
std::string code;
655
634
656
- if (modelHasOdes ()
635
+ if (mModelHasOdes
657
636
&& !mProfile ->interfaceCreateStatesArrayMethodString ().empty ()) {
658
637
code += mProfile ->interfaceCreateStatesArrayMethodString ();
659
638
}
@@ -688,7 +667,7 @@ void Generator::GeneratorImpl::addInterfaceCreateDeleteArrayMethodsCode()
688
667
689
668
void Generator::GeneratorImpl::addImplementationCreateDeleteArrayMethodsCode ()
690
669
{
691
- if (modelHasOdes ()
670
+ if (mModelHasOdes
692
671
&& !mProfile ->implementationCreateStatesArrayMethodString ().empty ()) {
693
672
mCode += newLineIfNeeded ()
694
673
+ mProfile ->implementationCreateStatesArrayMethodString ();
@@ -724,7 +703,7 @@ void Generator::GeneratorImpl::addImplementationCreateDeleteArrayMethodsCode()
724
703
void Generator::GeneratorImpl::addExternalVariableMethodTypeDefinitionCode ()
725
704
{
726
705
if (mModel ->hasExternalVariables ()) {
727
- auto externalVariableMethodTypeDefinitionString = mProfile ->externalVariableMethodTypeDefinitionString (modelHasOdes () );
706
+ auto externalVariableMethodTypeDefinitionString = mProfile ->externalVariableMethodTypeDefinitionString (mModelHasOdes );
728
707
729
708
if (!externalVariableMethodTypeDefinitionString.empty ()) {
730
709
mCode += newLineIfNeeded ()
@@ -735,16 +714,16 @@ void Generator::GeneratorImpl::addExternalVariableMethodTypeDefinitionCode()
735
714
736
715
void Generator::GeneratorImpl::addRootFindingInfoObjectCode ()
737
716
{
738
- if (modelHasNlas ()
739
- && !mProfile ->rootFindingInfoObjectString (modelHasOdes () , mModel ->hasExternalVariables ()).empty ()) {
717
+ if (mModelHasNlas
718
+ && !mProfile ->rootFindingInfoObjectString (mModelHasOdes , mModel ->hasExternalVariables ()).empty ()) {
740
719
mCode += newLineIfNeeded ()
741
- + mProfile ->rootFindingInfoObjectString (modelHasOdes () , mModel ->hasExternalVariables ());
720
+ + mProfile ->rootFindingInfoObjectString (mModelHasOdes , mModel ->hasExternalVariables ());
742
721
}
743
722
}
744
723
745
724
void Generator::GeneratorImpl::addExternNlaSolveMethodCode ()
746
725
{
747
- if (modelHasNlas ()
726
+ if (mModelHasNlas
748
727
&& !mProfile ->externNlaSolveMethodString ().empty ()) {
749
728
mCode += newLineIfNeeded ()
750
729
+ mProfile ->externNlaSolveMethodString ();
@@ -753,10 +732,10 @@ void Generator::GeneratorImpl::addExternNlaSolveMethodCode()
753
732
754
733
void Generator::GeneratorImpl::addNlaSystemsCode ()
755
734
{
756
- if (modelHasNlas ()
757
- && !mProfile ->objectiveFunctionMethodString (modelHasOdes () , mModel ->hasExternalVariables ()).empty ()
758
- && !mProfile ->findRootMethodString (modelHasOdes () , mModel ->hasExternalVariables ()).empty ()
759
- && !mProfile ->nlaSolveCallString (modelHasOdes () , mModel ->hasExternalVariables ()).empty ()) {
735
+ if (mModelHasNlas
736
+ && !mProfile ->objectiveFunctionMethodString (mModelHasOdes , mModel ->hasExternalVariables ()).empty ()
737
+ && !mProfile ->findRootMethodString (mModelHasOdes , mModel ->hasExternalVariables ()).empty ()
738
+ && !mProfile ->nlaSolveCallString (mModelHasOdes , mModel ->hasExternalVariables ()).empty ()) {
760
739
// Note: only states and algebraic variables can be computed through an NLA system. Constants, computed
761
740
// constants, and external variables cannot, by definition, be computed through an NLA system.
762
741
@@ -804,7 +783,7 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
804
783
}
805
784
806
785
mCode += newLineIfNeeded ()
807
- + replace (replace (mProfile ->objectiveFunctionMethodString (modelHasOdes () , mModel ->hasExternalVariables ()),
786
+ + replace (replace (mProfile ->objectiveFunctionMethodString (mModelHasOdes , mModel ->hasExternalVariables ()),
808
787
" [INDEX]" , convertToString (equation->nlaSystemIndex ())),
809
788
" [CODE]" , generateMethodBodyCode (methodBody));
810
789
@@ -828,7 +807,7 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
828
807
829
808
methodBody += newLineIfNeeded ()
830
809
+ mProfile ->indentString ()
831
- + replace (replace (mProfile ->nlaSolveCallString (modelHasOdes () , mModel ->hasExternalVariables ()),
810
+ + replace (replace (mProfile ->nlaSolveCallString (mModelHasOdes , mModel ->hasExternalVariables ()),
832
811
" [INDEX]" , convertToString (equation->nlaSystemIndex ())),
833
812
" [SIZE]" , convertToString (variablesCount));
834
813
@@ -849,7 +828,7 @@ void Generator::GeneratorImpl::addNlaSystemsCode()
849
828
}
850
829
851
830
mCode += newLineIfNeeded ()
852
- + replace (replace (replace (mProfile ->findRootMethodString (modelHasOdes () , mModel ->hasExternalVariables ()),
831
+ + replace (replace (replace (mProfile ->findRootMethodString (mModelHasOdes , mModel ->hasExternalVariables ()),
853
832
" [INDEX]" , convertToString (equation->nlaSystemIndex ())),
854
833
" [SIZE]" , convertToString (variablesCount)),
855
834
" [CODE]" , generateMethodBodyCode (methodBody));
@@ -1744,16 +1723,16 @@ std::string Generator::GeneratorImpl::generateEquationCode(const AnalyserEquatio
1744
1723
res += mProfile ->indentString ()
1745
1724
+ generateVariableNameCode (variable->variable ())
1746
1725
+ mProfile ->equalityString ()
1747
- + replace (mProfile ->externalVariableMethodCallString (modelHasOdes () ),
1726
+ + replace (mProfile ->externalVariableMethodCallString (mModelHasOdes ),
1748
1727
" [INDEX]" , convertToString (variable->index ()))
1749
1728
+ mProfile ->commandSeparatorString () + " \n " ;
1750
1729
}
1751
1730
1752
1731
break ;
1753
1732
case AnalyserEquation::Type::NLA:
1754
- if (!mProfile ->findRootCallString (modelHasOdes () , mModel ->hasExternalVariables ()).empty ()) {
1733
+ if (!mProfile ->findRootCallString (mModelHasOdes , mModel ->hasExternalVariables ()).empty ()) {
1755
1734
res += mProfile ->indentString ()
1756
- + replace (mProfile ->findRootCallString (modelHasOdes () , mModel ->hasExternalVariables ()),
1735
+ + replace (mProfile ->findRootCallString (mModelHasOdes , mModel ->hasExternalVariables ()),
1757
1736
" [INDEX]" , convertToString (equation->nlaSystemIndex ()));
1758
1737
}
1759
1738
@@ -1778,7 +1757,7 @@ std::string Generator::GeneratorImpl::generateEquationCode(const AnalyserEquatio
1778
1757
1779
1758
void Generator::GeneratorImpl::addInterfaceComputeModelMethodsCode ()
1780
1759
{
1781
- auto interfaceInitialiseVariablesMethodString = mProfile ->interfaceInitialiseVariablesMethodString (modelHasOdes () );
1760
+ auto interfaceInitialiseVariablesMethodString = mProfile ->interfaceInitialiseVariablesMethodString (mModelHasOdes );
1782
1761
std::string code;
1783
1762
1784
1763
if (!interfaceInitialiseVariablesMethodString.empty ()) {
@@ -1791,12 +1770,12 @@ void Generator::GeneratorImpl::addInterfaceComputeModelMethodsCode()
1791
1770
1792
1771
auto interfaceComputeRatesMethodString = mProfile ->interfaceComputeRatesMethodString (mModel ->hasExternalVariables ());
1793
1772
1794
- if (modelHasOdes ()
1773
+ if (mModelHasOdes
1795
1774
&& !interfaceComputeRatesMethodString.empty ()) {
1796
1775
code += interfaceComputeRatesMethodString;
1797
1776
}
1798
1777
1799
- auto interfaceComputeVariablesMethodString = mProfile ->interfaceComputeVariablesMethodString (modelHasOdes () ,
1778
+ auto interfaceComputeVariablesMethodString = mProfile ->interfaceComputeVariablesMethodString (mModelHasOdes ,
1800
1779
mModel ->hasExternalVariables ());
1801
1780
1802
1781
if (!interfaceComputeVariablesMethodString.empty ()) {
@@ -1836,7 +1815,7 @@ std::string Generator::GeneratorImpl::generateConstantInitialisationCode(const s
1836
1815
1837
1816
void Generator::GeneratorImpl::addImplementationInitialiseVariablesMethodCode (std::vector<AnalyserEquationPtr> &remainingEquations)
1838
1817
{
1839
- auto implementationInitialiseVariablesMethodString = mProfile ->implementationInitialiseVariablesMethodString (modelHasOdes () );
1818
+ auto implementationInitialiseVariablesMethodString = mProfile ->implementationInitialiseVariablesMethodString (mModelHasOdes );
1840
1819
1841
1820
if (!implementationInitialiseVariablesMethodString.empty ()) {
1842
1821
// Initialise our states (after, if needed, initialising the constant on which it depends).
@@ -1931,7 +1910,7 @@ void Generator::GeneratorImpl::addImplementationComputeRatesMethodCode(std::vect
1931
1910
{
1932
1911
auto implementationComputeRatesMethodString = mProfile ->implementationComputeRatesMethodString (mModel ->hasExternalVariables ());
1933
1912
1934
- if (modelHasOdes ()
1913
+ if (mModelHasOdes
1935
1914
&& !implementationComputeRatesMethodString.empty ()) {
1936
1915
std::string methodBody;
1937
1916
@@ -1958,7 +1937,7 @@ void Generator::GeneratorImpl::addImplementationComputeRatesMethodCode(std::vect
1958
1937
1959
1938
void Generator::GeneratorImpl::addImplementationComputeVariablesMethodCode (std::vector<AnalyserEquationPtr> &remainingEquations)
1960
1939
{
1961
- auto implementationComputeVariablesMethodString = mProfile ->implementationComputeVariablesMethodString (modelHasOdes () ,
1940
+ auto implementationComputeVariablesMethodString = mProfile ->implementationComputeVariablesMethodString (mModelHasOdes ,
1962
1941
mModel ->hasExternalVariables ());
1963
1942
1964
1943
if (!implementationComputeVariablesMethodString.empty ()) {
@@ -2012,6 +1991,8 @@ AnalyserModelPtr Generator::model()
2012
1991
void Generator::setModel (const AnalyserModelPtr &model)
2013
1992
{
2014
1993
mPimpl ->mModel = model;
1994
+ mPimpl ->mModelHasOdes = modelHasOdes (model);
1995
+ mPimpl ->mModelHasNlas = modelHasNlas (model);
2015
1996
}
2016
1997
2017
1998
std::string Generator::interfaceCode () const
0 commit comments