• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Simulator
  • IntegrationBase
  • 4.11.14

IntegrationBase Class

(CDPSim::IntegrationBase)

The IntegrationBase is a base class of all integration algorithms. Inherit it to add custom algorithms. More...

Header: #include <Integration/IntegrationBase.h>
Inherits: CDP::StudioAPI::CDPNode
  • List of all members, including inherited members

Public Functions

IntegrationBase()
virtual ~IntegrationBase() override
virtual void Configure(XMLElementEx *integration, SimulatorManager *owner)
virtual std::vector<DynamicSimComponent *> &GetSimComponents()
virtual void Integrate(double t, double &dt, double &T) = 0
virtual void RegisterMatrix1D(Matrix1D *matrix1D)
virtual void ScheduleSubComponents()

Reimplemented Public Functions

virtual void FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const override
virtual const std::string GetNodeName() const override
virtual std::string GetNodeTypeName() const override
  • 26 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Protected Variables

Matrix1D Y
Matrix1D Y_ddt
Matrix1D Y_tmp
CDPProperty<std::string> m_model
CDPProperty<std::string> m_name
SimulatorManager *m_owner

Additional Inherited Members

  • 1 protected function inherited from CDP::StudioAPI::CDPNode

Detailed Description

The IntegrationBase is a base class of all integration algorithms. Inherit it to add custom algorithms.

Inheriting class must override Integrate() method. See example in Integrate() documentation.

Member Function Documentation

IntegrationBase::IntegrationBase()

Default constructs an instance of IntegrationBase.

[override virtual] IntegrationBase::~IntegrationBase()

Destroys the instance of IntegrationBase. The destructor is virtual.

[virtual] void IntegrationBase::Configure(XMLElementEx *integration, SimulatorManager *owner)

Reads configuration from XML. Called automatically by parent.

[override virtual] void IntegrationBase::FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const

Reimplemented from CDPNode::FillNodeChildren().

Exposes child nodes of this node to StudioAPI.

Must be overridden if node has child nodes to expose.

[override virtual] const std::string IntegrationBase::GetNodeName() const

Reimplemented from ICDPNode::GetNodeName().

Returns node's unique name.

[override virtual] std::string IntegrationBase::GetNodeTypeName() const

Reimplemented from ICDPNode::GetNodeTypeName().

Returns node's model name "CDPNode".

[virtual] std::vector<DynamicSimComponent *> &IntegrationBase::GetSimComponents()

Returns a list of all simulator components. Needed to implement Integrate()

[pure virtual] void IntegrationBase::Integrate(double t, double &dt, double &T)

Calls EvaluateDiffEquations() of every DynamicSimComponent and integrates all values. Before EvaluateDiffEquations(), PreIntegrate() is called on every DynamicSimComponent, and after EvaluateDiffEquations(), PostIntegrate() is called on every DynamicSimComponent.

Parameters passed to the method are:

  • T – Timestep (requested simulation period).
  • t – simulator time
  • dt – Time since previous calculation. Should equal T, but may not be exactly T because of scheduler imperfection.

Fields this method should use:

  • Y – State variables.
  • Y_tmp – Temporary matrix used to pass state variables to the EvaluateDiffEquations() method.
  • Y_ddt – Derivative of the state variables.

Example implementation using Euler algorithm.

void Euler::Integrate(double t, double& dt, double& T)
{
  auto simComponents = GetSimComponents();
  for (auto comp : simComponents)
    comp->PreIntegrate();  // In this function, the state variables may be set directly using StateVariable::OverrideStateValue() (mapped to Y and Y_tmp)

  for (auto comp : simComponents)
    comp->EvaluateDiffEquations(t);
  Y += dt * Y_ddt;         // Assign result to Y which is mapped to StateVariable's value and will be published

  Y_tmp = Y;               // Sync Y and Y_tmp after calculations
  for (auto comp : simComponents)
    comp->PostIntegrate(); // Usually used to publish values to output SimSignals or to cap StateVariable values
}

Note that previous code can be optimized as Y += dt * Y_ddt; will allocate memory for calculating intermediate values. This can be improved by using another matrix for temporary values.

// In header file
class Euler : public CDPSim::IntegrationBase
{
...
private:
  CDPSim::Matrix1D tmp;
};

// In cpp file:
void Euler::Configure(XMLElementEx* integration, CDPSim::SimulatorManager* owner)
{
  CDPSim::IntegrationBase::Configure(integration, owner);
  RegisterMatrix1D(&tmp);
}

void Euler::Integrate(double t, double& dt, double& T)
{
  ...
  // Instead of 'Y += dt * Y_ddt;'
  tmp = Y_ddt; // Use tmp to prevent allocating memory for intermediate values every time this method is called
  tmp *= dt;
  Y += tmp;
  ...
}

[virtual] void IntegrationBase::RegisterMatrix1D(Matrix1D *matrix1D)

Registeres the matrix meaning that enough memory will be allocated for it to hold all state variables of all simulator components. These matrixes can be for example used as temporary buffers for calculations done in Integrate().

[virtual] void IntegrationBase::ScheduleSubComponents()

Schedules all the subcomponents (operators)

Member Variable Documentation

Matrix1D IntegrationBase::Y

This variable holds state variables. Used when implementing Integrate().

Matrix1D IntegrationBase::Y_ddt

This variable holds derivative of the state variables. Used when implementing Integrate().

Matrix1D IntegrationBase::Y_tmp

This variable holds temporary matrix used to pass state variables to the EvaluateDiffEquations() method. Used when implementing Integrate().

CDPProperty<std::string> IntegrationBase::m_model

This variable specifies the type name of the node.

CDPProperty<std::string> IntegrationBase::m_name

This variable holds unique name given to this node.

SimulatorManager *IntegrationBase::m_owner

This variable holds parent of this node.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top