API Documentation¶
libCellML Model Reference¶
-
class
Model
: public libcellml::ComponentEntity, public std::enable_shared_from_this<Model>¶ The Model class.
The Model class is for representing a CellML Model.
Public Functions
-
~Model
()¶ Destructor.
-
void
addUnits
(const UnitsPtr &units)¶ Add a child units to this model.
Add a copy of the given units as a child units of this model.
- Parameters
units
: The units to add.
-
bool
removeUnits
(size_t index)¶ Remove the units at the given
index
.Remove the units from this model at the given
index
.index
must be in the range [0, #units).- Return
True if the units were replaced, false otherwise.
- Parameters
index
: The index of the units to remove.
-
bool
removeUnits
(const std::string &name)¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Remove the units with the given
name
.Remove the first units found with the given
name
.- Return
True if the units were replaced, false otherwise.
- Parameters
name
: The name of the units to remove.
-
bool
removeUnits
(const UnitsPtr &units)¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Remove the units with the given pointer.
Remove the units with the pointer
units
.- Return
True if the units were replaced, false otherwise.
- Parameters
units
: The pointer to the units to remove.
-
void
removeAllUnits
()¶ Remove all units stored in this model.
Clears all units that have been added to this model.
-
bool
hasUnits
(const std::string &name) const¶ Tests to see if the units is within this model.
Tests to see if the units with the given
name
is contained within this model. Returnstrue
if the units is in the model andfalse
otherwise.- Return
true
if the named units is in the model andfalse
otherwise.- Parameters
name
: The name of the units to test for existence in this model.
-
bool
hasUnits
(const UnitsPtr &units) const¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Tests to see if the units is within this model.
Tests to see if the given
units
is contained within this model. Returnstrue
if the units is in the model andfalse
otherwise.- Return
true
if the units is in the model andfalse
otherwise.- Parameters
units
: The units to test for existence in this model.
-
UnitsPtr
units
(size_t index) const¶ Get a units at the given
index
.Returns a reference to a units at the given
index
. If theindex
is not valid anullptr
is returned, the range of valid values for the index is [0, #units).- Return
A reference to the units at the given
index
on success,nullptr
otherwise.- Parameters
index
: The index of the units to return.
-
UnitsPtr
units
(const std::string &name) const¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Get a units with the given
name
.Returns a reference to a units with the given
name
. If thename
is not valid anullptr
is returned.- Return
A reference to the units with the given
name
on success,nullptr
otherwise.- Parameters
name
: The name of the units to return.
-
UnitsPtr
takeUnits
(size_t index)¶ Take the units at the given
index
and return it.Removes the units at the given
index
position and returns it.index
must be in the range [0, #units).- Return
A reference to the units at the given
index
if the index is valid,nullptr
otherwise.- Parameters
index
: The index of the units to take.
-
UnitsPtr
takeUnits
(const std::string &name)¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Take the units with the given
name
and return it.Takes the first occurence of the units with the given name
name
and returns it. If no units with namename
is found then anullptr
is returned.- Return
A reference to the units identified with the given
name
if found,nullptr
otherwise.- Parameters
name
: The name of the units to take.
-
bool
replaceUnits
(size_t index, const UnitsPtr &units)¶ Replace a units at the given
index
.Replaces the units at the given
index
withunits
.index
must be in the range [0, #units).- Return
True if the units were replaced, false otherwise.
- Parameters
index
: Index of the units to replace.units
: The units to use for replacement.
-
bool
replaceUnits
(const std::string &name, const UnitsPtr &units)¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Replace a units with the given
name
.Replaces the units with the given
name
withunits
.- Return
True if the units were replaced, false otherwise.
- Parameters
name
: The name of the units to replace.units
: The units to use for replacement.
-
bool
replaceUnits
(const UnitsPtr &oldUnits, const UnitsPtr &newUnits)¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Replace a units with another units.
Replaces one units with another.
- Return
True if the units were replaced, false otherwise.
- Parameters
oldUnits
: The units to be replaced.newUnits
: The units to use for replacement.
-
size_t
unitsCount
() const¶ Get the number of units in the model.
Returns the number of units the model contains.
- Return
The number of units.
-
void
linkUnits
()¶ Link the units used in this model.
Traverses the model looking for
Units
attached toVariables
that are not standard units and which are not linked toUnits
added to the model. This method will link variable units specified by name to units in the model (if they are found). Any variable units that cannot be linked to units in the model are left in an unlinked state. This means it is possible to still have unlinkedUnits
in the model after calling this method.Unlinked variable units can occur when a
Variable's
units are set by name. If theModel
to which theVariable
belongs hasUnits
defined with the same name, then thatVariable's
Units
will not be linked to theModel's
Units
. This method will link the two units (the one from the variable and the one from the model).If a
Variable
has units that are not found in the model then the units will remain unlinked.
-
bool
hasUnlinkedUnits
()¶ Test to determine if any variable units are not linked to model units.
Traverses the model to determine if any
Units
attached to variables are notUnits
attached to the model.- Return
True if any
Units
attached to variables are not linked to units in the model, false otherwise.
-
bool
hasImports
() const¶ Test to determine if there are any import entities.
Checks the model to determine if there are any
Units
orComponents
which are imports. Returnstrue
if the model has at least oneUnits
orComponent
which is an importedUnits
orComponent
.
-
void
resolveImports
(const std::string &baseFile)¶ Resolve all imports in this model.
Resolve all
Component
andUnits
imports by loading the models from local disk through relative URLs. ThebaseFile
is used to determine the full path to the source model relative to this one.- Parameters
baseFile
: Thestd::string
location on local disk of the sourceModel
.
-
bool
hasUnresolvedImports
() const¶ Test if this model has unresolved imports.
Test if this model has unresolved imports.
- Return
True if the
Model
has unresolved imports and false otherwise.
Public Static Functions
-
static ModelPtr
create
()¶ Create a
Model
object.Factory method to create a
Model
. Create a blank model with::ModelPtr model = libcellml::Model::create();
or a named model with name “Model” with::
ModelPtr model = libcellml::Model::create(“Model”);
- Return
A smart pointer to a
Model
object.
-