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.

Model(const Model &rhs)

Copy constructor.

Model(Model &&rhs)

Move constructor.

Model &operator=(Model rhs)

Assignment operator.

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. Returns true if the units is in the model and false otherwise.

Return

true if the named units is in the model and false 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. Returns true if the units is in the model and false otherwise.

Return

true if the units is in the model and false 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 the index is not valid a nullptr 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 the name is not valid a nullptr 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 name name is found then a nullptr 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 with units. 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 with units.

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 to Variables that are not standard units and which are not linked to Units 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 unlinked Units in the model after calling this method.

Unlinked variable units can occur when a Variable's units are set by name. If the Model to which the Variable belongs has Units defined with the same name, then that Variable's Units will not be linked to the Model'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 not Units 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 or Components which are imports. Returns true if the model has at least one Units or Component which is an imported Units or Component.

Return

True if the Model has a Units or Component that is an import, false otherwise.

void resolveImports(const std::string &baseFile)

Resolve all imports in this model.

Resolve all Component and Units imports by loading the models from local disk through relative URLs. The baseFile is used to determine the full path to the source model relative to this one.

Parameters
  • baseFile: The std::string location on local disk of the source Model.

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.

ModelPtr clone() const

Create a clone of this model.

Creates a full separate copy of this model. The component hierarchy and variable equivalence maps will also be copied from this model to the destination model.

Return

a new ModelPtr to the cloned model.

void flatten()

Flatten this model.

Instantiates all imports and removes them from this model. The result is a self-contained model requiring no external resources and having no imports.

The effects of this method cannot be undone.

See

clone

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.

static ModelPtr create(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.