I'm trying to create a model in OpenModelica which contains several other components (pipes, reservoirs). Currently I'm modifying a pipe in the Modelica.Fluid-library using a staggered grid, and need to determine the smallest step size dx in the entire model.
Is it possible to do the following?
I have calculated both dx_1 in pipe 1 and dx_2 in pipe 2, and created an array in a data storage model similar to Fluid.System. I am, however, struggling with sending the step sizes to the data storage model, and sending them back again after determining the smallest dx.
Is this even possible? How would one go about to do so?
Yes, there are several possibilities.
As you mention, the pipes can access variables/parameters in the data storage model if this is instantiated as inner
in your global model and declared as outer
in each pipe model. As with the Modelica.Fluid
models referring to Fluid.System
, the pipes can access dx_min
in the data storage model.
This is a code example, loosely based on your question:
model Pipe
outer DataStorage dataStorage;
Real dx_min = dataStorage.dx_min;
Real dx "calculated in this model";
...
end Pipe;
model DataStorage
parameter Integer nPipes;
input Real dx_array[nPipes];
Real dx_min=min(dx_array);
...
end DataStorage;
model GlobalModel
Pipe pipe1;
Pipe pipe2;
inner DataStorage dataStorage(nPipes=2, dx_array={pipe1.dx, pipe2.dx});
...
end GlobalModel;
You should beware of the variability of the different "dx's" as you cannot assign a time-varying "dx" to a "dx" declared as a parameter
.
If the only purpose of the DataStorage
model is to take the minimum entry in an array then you could also put its three lines of code in GlobalModel
, reducing the code to:
model Pipe
input Real dx_min;
Real dx "calculated in this model";
...
end Pipe;
model GlobalModel
parameter Integer nPipes=2;
Real dx_array[nPipes]={pipe1.dx, pipe2.dx};
Real dx_min=min(dx_array);
Pipe pipe1(dx_min=dx_min);
Pipe pipe2(dx_min=dx_min);
...
end GlobalModel;