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.indexmust 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
nameis contained within this model. Returnstrueif the units is in the model andfalseotherwise.- Return
trueif the named units is in the model andfalseotherwise.- 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
unitsis contained within this model. Returnstrueif the units is in the model andfalseotherwise.- Return
trueif the units is in the model andfalseotherwise.- 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 theindexis not valid anullptris returned, the range of valid values for the index is [0, #units).- Return
A reference to the units at the given
indexon success,nullptrotherwise.- 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 thenameis not valid anullptris returned.- Return
A reference to the units with the given
nameon success,nullptrotherwise.- Parameters
name: The name of the units to return.
-
UnitsPtr
takeUnits(size_t index)¶ Take the units at the given
indexand return it.Removes the units at the given
indexposition and returns it.indexmust be in the range [0, #units).- Return
A reference to the units at the given
indexif the index is valid,nullptrotherwise.- 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
nameand return it.Takes the first occurence of the units with the given name
nameand returns it. If no units with namenameis found then anullptris returned.- Return
A reference to the units identified with the given
nameif found,nullptrotherwise.- 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
indexwithunits.indexmust 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
namewithunits.- 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
Unitsattached toVariablesthat are not standard units and which are not linked toUnitsadded 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 unlinkedUnitsin the model after calling this method.Unlinked variable units can occur when a
Variable'sunits are set by name. If theModelto which theVariablebelongs hasUnitsdefined with the same name, then thatVariable'sUnitswill not be linked to theModel'sUnits. This method will link the two units (the one from the variable and the one from the model).If a
Variablehas 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
Unitsattached to variables are notUnitsattached to the model.- Return
True if any
Unitsattached 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
UnitsorComponentswhich are imports. Returnstrueif the model has at least oneUnitsorComponentwhich is an importedUnitsorComponent.
-
void
resolveImports(const std::string &baseFile)¶ Resolve all imports in this model.
Resolve all
ComponentandUnitsimports by loading the models from local disk through relative URLs. ThebaseFileis used to determine the full path to the source model relative to this one.- Parameters
baseFile: Thestd::stringlocation 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
Modelhas unresolved imports and false otherwise.
Public Static Functions
-
static ModelPtr
create()¶ Create a
Modelobject.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
Modelobject.
-