Access of shared inner Environment variable

A rather common kind of implicit interaction is where a shared attribute of a single environment object is accessed by a number of components within that environment. For example, we might have anenvironment including house components, each accessing a shared environment temperature, or a circuit board environment with electronic components accessing the board temperature. A Modelica environment-component example model along these lines is shown below, where a shared environment temperature variable T0 is declared as a definition declaration marked by the keyword inner. This declaration is implicitly accessed by the reference declarations of T0 marked by the prefix outer in the components comp1 and comp2.





The instance hierarchy lookup is from an outer reference declaration to a matching inner definition declaration with the same name. The search is upward in the instance hierarchy starting from the currentinstance. In this example, the search starts at the components comp1 or comp2 upward to the Environment instances env1 or env2 where the matching inner definition declaration of T0 is found. Note that there exists only one actual instance of T0 in each environment, marked by the prefix inner. All outer reference declarations of T0 within the components of an environment are just references to this single instance. A nice property of the instance hierarchy lookup mechanism provided by the inner/outer language feature is its selectiveness. Thus we can have several simultaneously existing environment hierarchies, with independent lookup within each hierarchy.


We simulate the EnvironmentInstances model containing the two environments env1 and env2





Both environments have a sine-shaped temperature profile T0 as a function of time (Figure 5-34), but the second environment temperature is varying faster in time since the coefficient k=4 compared to k=1 forthe first environment.