//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////

include::../_part_attributes.asciidoc[]

:leveloffset: -2

[[lang-tut-reuse2-chapter-groups]]
== Groups

indexterm:[group]
indexterm:[component,group]
For large CIF specifications with many automata, it can be beneficial to add more structure to the specification.
For this purpose, CIF has _groups_.
Groups are named collections of automata and other declarations.
For instance, consider the following CIF specification:

[source, cif]
----
group factory:
  group hall1:
    automaton machine1:
      ...
    end

    automaton machine2:
      ...
    end
  end

  group hall2:
    automaton machine1:
      ...
    end

    automaton machine2:
      ...
    end
  end
end
----

This specifications features four automata that model the behavior of machines.
The details of the actual automata are omitted, as they are irrelevant for this lesson.
All four machines are in the same factory, but they are divided into two halls.
This physical subdivision is expressed in the CIF specification using groups named `factory`, `hall1`, and `hall2`.
While in this case the subdivision into a hierarchical specification structure is based on the physical subdivision of the actual system, the modeler is free to base the specification structure on other criteria.

Consider also the following partial CIF specification:

[source, cif]
----
group configuration:
  const int  MAX_PRODUCTS        = 1500;
  const real MAX_PRODUCTION_TIME = 3.7;
  const real ARRIVAL_RATE        = 28.6;
end
----

The `configuration` group is used to group together several configuration values, modeled by constants.
By grouping these constants together, it is more clear that they together are the configuration settings of the system, and that they belong together.

Finally, consider the following CIF specification, based on the link:https://en.wikipedia.org/wiki/Nonlinear_system[non-linear system] from the lesson on <<lang-tut-time-chapter-equations,equations>>.

[source, cif]
----
group tank:
  cont V = 5;
  alg real Qi;
  alg real Qo;

  equation V' = Qi - Qo;
  equation Qi = 1;
  equation Qo = sqrt(V);
end
----

By grouping the declarations and their equations together, it is becomes clear that together they model a `tank`.
This is especially useful if other parts of the specification model something different.
