Skip to content

Commit a7c7774

Browse files
committed
Generator: added an external array.
1 parent 09fcc1f commit a7c7774

File tree

202 files changed

+500
-5
lines changed

Some content is hidden

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

202 files changed

+500
-5
lines changed

src/analyser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3281,7 +3281,8 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model)
32813281
internalEquation->mNlaSystemIndex,
32823282
equationNlaSiblings,
32833283
{},
3284-
algebraic);
3284+
algebraic,
3285+
{});
32853286

32863287
mModel->mPimpl->mEquations.push_back(equation);
32873288
}

src/analyserequation.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void AnalyserEquation::AnalyserEquationImpl::populate(AnalyserEquation::Type typ
3434
size_t nlaSystemIndex,
3535
const std::vector<AnalyserEquationPtr> &nlaSiblings,
3636
const std::vector<AnalyserVariablePtr> &computedConstants,
37-
const std::vector<AnalyserVariablePtr> &algebraic)
37+
const std::vector<AnalyserVariablePtr> &algebraic,
38+
const std::vector<AnalyserVariablePtr> &externals)
3839
{
3940
mType = type;
4041
mAst = ast;
@@ -44,6 +45,7 @@ void AnalyserEquation::AnalyserEquationImpl::populate(AnalyserEquation::Type typ
4445
std::copy(nlaSiblings.begin(), nlaSiblings.end(), back_inserter(mNlaSiblings));
4546
std::copy(computedConstants.begin(), computedConstants.end(), back_inserter(mComputedConstants));
4647
std::copy(algebraic.begin(), algebraic.end(), back_inserter(mAlgebraic));
48+
std::copy(externals.begin(), externals.end(), back_inserter(mExternals));
4749
}
4850

4951
bool AnalyserEquation::AnalyserEquationImpl::isEmptyDependency(const AnalyserEquationWeakPtr &dependency)
@@ -60,6 +62,12 @@ bool AnalyserEquation::AnalyserEquationImpl::isEmptyDependency(const AnalyserEqu
6062
return false;
6163
}
6264

65+
auto externals = dependency.lock()->externals();
66+
67+
if (std::any_of(externals.begin(), externals.end(), [](const auto &v) { return v != nullptr; })) {
68+
return false;
69+
}
70+
6371
return true;
6472
}
6573

@@ -199,4 +207,23 @@ AnalyserVariablePtr AnalyserEquation::algebraic(size_t index) const
199207
return mPimpl->mAlgebraic[index];
200208
}
201209

210+
size_t AnalyserEquation::externalCount() const
211+
{
212+
return mPimpl->mExternals.size();
213+
}
214+
215+
std::vector<AnalyserVariablePtr> AnalyserEquation::externals() const
216+
{
217+
return mPimpl->mExternals;
218+
}
219+
220+
AnalyserVariablePtr AnalyserEquation::external(size_t index) const
221+
{
222+
if (index >= mPimpl->mExternals.size()) {
223+
return {};
224+
}
225+
226+
return mPimpl->mExternals[index];
227+
}
228+
202229
} // namespace libcellml

src/analyserequation_p.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct AnalyserEquation::AnalyserEquationImpl
3737
bool mIsStateRateBased = false;
3838
std::vector<AnalyserVariablePtr> mComputedConstants;
3939
std::vector<AnalyserVariablePtr> mAlgebraic;
40+
std::vector<AnalyserVariablePtr> mExternals;
4041

4142
static AnalyserEquationPtr create();
4243

@@ -46,7 +47,8 @@ struct AnalyserEquation::AnalyserEquationImpl
4647
size_t nlaSystemIndex,
4748
const std::vector<AnalyserEquationPtr> &nlaSiblings,
4849
const std::vector<AnalyserVariablePtr> &computedConstants,
49-
const std::vector<AnalyserVariablePtr> &algebraic);
50+
const std::vector<AnalyserVariablePtr> &algebraic,
51+
const std::vector<AnalyserVariablePtr> &externals);
5052

5153
static bool isEmptyDependency(const AnalyserEquationWeakPtr &dependency);
5254

src/analysermodel.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,33 @@ AnalyserVariablePtr AnalyserModel::algebraic(size_t index) const
202202
return mPimpl->mAlgebraic[index];
203203
}
204204

205+
size_t AnalyserModel::externalCount() const
206+
{
207+
if (!isValid()) {
208+
return 0;
209+
}
210+
211+
return mPimpl->mExternals.size();
212+
}
213+
214+
std::vector<AnalyserVariablePtr> AnalyserModel::externals() const
215+
{
216+
if (!isValid()) {
217+
return {};
218+
}
219+
220+
return mPimpl->mExternals;
221+
}
222+
223+
AnalyserVariablePtr AnalyserModel::external(size_t index) const
224+
{
225+
if (!isValid() || (index >= mPimpl->mExternals.size())) {
226+
return {};
227+
}
228+
229+
return mPimpl->mExternals[index];
230+
}
231+
205232
size_t AnalyserModel::equationCount() const
206233
{
207234
if (!isValid()) {

src/analysermodel_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct AnalyserModel::AnalyserModelImpl
3838
std::vector<AnalyserVariablePtr> mConstants;
3939
std::vector<AnalyserVariablePtr> mComputedConstants;
4040
std::vector<AnalyserVariablePtr> mAlgebraic;
41+
std::vector<AnalyserVariablePtr> mExternals;
4142
std::vector<AnalyserEquationPtr> mEquations;
4243

4344
bool mNeedEqFunction = false;

src/api/libcellml/analyserequation.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,35 @@ class LIBCELLML_EXPORT AnalyserEquation
223223
*/
224224
AnalyserVariablePtr algebraic(size_t index) const;
225225

226+
/**
227+
* @brief Get the number of external variables computed by this @ref AnalyserEquation.
228+
*
229+
* Return the number of external variables computed by this @ref AnalyserEquation.
230+
*
231+
* @return The number of external variables.
232+
*/
233+
size_t externalCount() const;
234+
235+
/**
236+
* @brief Get the external variables computed by this @ref AnalyserEquation.
237+
*
238+
* Return the external variables computed by this @ref AnalyserEquation.
239+
*
240+
* @return The external variables as a @c std::vector.
241+
*/
242+
std::vector<AnalyserVariablePtr> externals() const;
243+
244+
/**
245+
* @brief Get the external variable, at @p index, computed by this @ref AnalyserEquation.
246+
*
247+
* Return the external variable, at @p index, computed by this @ref AnalyserEquation.
248+
*
249+
* @param index The index of the external variable to return.
250+
*
251+
* @return The external variable, at @p index, on success, @c nullptr on failure.
252+
*/
253+
AnalyserVariablePtr external(size_t index) const;
254+
226255
private:
227256
AnalyserEquation(); /**< Constructor, @private. */
228257

src/api/libcellml/analysermodel.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,36 @@ class LIBCELLML_EXPORT AnalyserModel
231231
*/
232232
AnalyserVariablePtr algebraic(size_t index) const;
233233

234+
/**
235+
* @brief Get the number of external variables.
236+
*
237+
* Return the number of external variables in the @ref AnalyserModel.
238+
*
239+
* @return The number of external variables.
240+
*/
241+
size_t externalCount() const;
242+
243+
/**
244+
* @brief Get the external variables.
245+
*
246+
* Return the external variables in the @ref AnalyserModel.
247+
*
248+
* @return The external variables as a @c std::vector.
249+
*/
250+
std::vector<AnalyserVariablePtr> externals() const;
251+
252+
/**
253+
* @brief Get the external variable at @p index.
254+
*
255+
* Return the external variable at the index @p index for the @ref AnalyserModel.
256+
*
257+
* @param index The index of the external variable to return.
258+
*
259+
* @return The external variable at the given @p index on success, @c nullptr on
260+
* failure.
261+
*/
262+
AnalyserVariablePtr external(size_t index) const;
263+
234264
/**
235265
* @brief Get the number of equations.
236266
*

src/api/libcellml/generatorprofile.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,54 @@ class LIBCELLML_EXPORT GeneratorProfile
26052605
*/
26062606
void setImplementationAlgebraicCountString(const std::string &implementationAlgebraicCountString);
26072607

2608+
/**
2609+
* @brief Get the @c std::string for the interface of the external count
2610+
* constant.
2611+
*
2612+
* Return the @c std::string for the interface of the external count
2613+
* constant.
2614+
*
2615+
* @return The @c std::string for the interface of the external count
2616+
* constant.
2617+
*/
2618+
std::string interfaceExternalCountString() const;
2619+
2620+
/**
2621+
* @brief Set the @c std::string for the interface of the external count
2622+
* constant.
2623+
*
2624+
* Set the @c std::string for the interface of the external count constant.
2625+
*
2626+
* @param interfaceExternalCountString The @c std::string to use for the
2627+
* interface of the external count constant.
2628+
*/
2629+
void setInterfaceExternalCountString(const std::string &interfaceExternalCountString);
2630+
2631+
/**
2632+
* @brief Get the @c std::string for the implementation of the external
2633+
* count constant.
2634+
*
2635+
* Return the @c std::string for the implementation of the external count
2636+
* constant.
2637+
*
2638+
* @return The @c std::string for the implementation of the external count
2639+
* constant.
2640+
*/
2641+
std::string implementationExternalCountString() const;
2642+
2643+
/**
2644+
* @brief Set the @c std::string for the implementation of the external
2645+
* count constant.
2646+
*
2647+
* Set the @c std::string for the implementation of the external count
2648+
* constant. To be useful, the string should contain the [EXTERNAL_COUNT]
2649+
* tag, which will be replaced with the number of states in the model.
2650+
*
2651+
* @param implementationExternalCountString The @c std::string to use for
2652+
* the implementation of the external count constant.
2653+
*/
2654+
void setImplementationExternalCountString(const std::string &implementationExternalCountString);
2655+
26082656
/**
26092657
* @brief Get the @c std::string for the data structure for the variable
26102658
* type object.

src/bindings/interface/analyserequation.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
%feature("docstring") libcellml::AnalyserEquation::algebraic
6262
"Returns the algebraic variable, at the given index, computed by this :class:`AnalyserEquation` object.";
6363

64+
%feature("docstring") libcellml::AnalyserEquation::externalCount
65+
"Returns the number of external variables computed by this :class:`AnalyserEquation` object.";
66+
67+
%feature("docstring") libcellml::AnalyserEquation::externals
68+
"Returns the external variables computed by this :class:`AnalyserEquation` object.";
69+
70+
%feature("docstring") libcellml::AnalyserEquation::external
71+
"Returns the external variable, at the given index, computed by this :class:`AnalyserEquation` object.";
72+
6473
%{
6574
#include "libcellml/analyserequation.h"
6675
%}

src/bindings/interface/analysermodel.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
%feature("docstring") libcellml::AnalyserModel::algebraic
6262
"Returns the algebraic variable, specified by index, contained by this :class:`AnalyserModel` object.";
6363

64+
%feature("docstring") libcellml::AnalyserModel::externalCount
65+
"Returns the number of external variables contained by this :class:`AnalyserModel` object.";
66+
67+
%feature("docstring") libcellml::AnalyserModel::externals
68+
"Returns the external variables contained by this :class:`AnalyserModel` object.";
69+
70+
%feature("docstring") libcellml::AnalyserModel::external
71+
"Returns the external variable, specified by index, contained by this :class:`AnalyserModel` object.";
72+
6473
%feature("docstring") libcellml::AnalyserModel::equationCount
6574
"Returns the number of equations contained by this :class:`AnalyserModel` object.";
6675

0 commit comments

Comments
 (0)