I have a block that I've made with a repeating sub-system in my model. This sub system has small variations (pipe diameter changes here, flow rate differences there) that need to be taken account of in the wider model.
Try as I might, I cannot find a way to make this block editable with these small changes since I end up returning to edit the original block which then propagates across all the instances.
A poor workaround right now is taking my original block and copy-pasting the whole shebang into new blocks with each small variation edited into each component manually - but it goes without saying that this is tedious and there must be a better way to do it somehow.
I suspect I need to make use of Extends but I'm not sure how.
Ideally Im trying to get to a point where I can right-click and edit parameters for the block that get used by the components within it - again, I'm not sure how.
Thanks for taking a look.
Right now my goal here is to get a low detail model of a cooling tower for an industrial process.
The tower model is essentially four water spray injectors linked to a common rail pipe network with a prescribed mass flow of hot water to be cooled by the ambient air. Extending the model later for heat exchange is a different problem, right now its just evaluating pressure losses for pump sizing.
My problem here is that I have a common design for the water spray injectors but each individual injector has its own parameters for different hardware in terms of pipe diameter, length and nozzle characteristics. I have the one block that is instanced four times with parameters that are unable to be changed for each instance, only the block model changes.
If this was Python I'd be looking to make the WInj a class and alter parameters in the call statement to get a slightly different variation on the common theme.
And now that I type that I realise that I might very well have rubber ducked my question to irrelevance since I think the pipe model extends a base class with a lot of parameters in it that I can check to use as a template.
Note this answer was written before more information was added to the question. IMHO it still answers it, even though it does not consider the cooling tower model
By design every class and therefore every block in Modelica is reusable. Like in an object oriented programming language you create instances of classes, which are also often called components in the Modelica world. Then you can assign certain values to these components using Modifiers.
Setting parameters for top-level components is maybe the simplest and the most often used way of using modifiers. It is also the one, which is very well supported in OMEdit.
However, as in your case, components often can contain subcomponents. You can also set modifiers for these subcomponents from a higher level.
The code below demonstrates how to do that: Example
is our top level, tractor
the component and we have two sub-components, front_wheel
and rear_wheel
. The radius of the wheels is set to different values.
package Demo
model Example
Vehicle tractor(
m = 7e3,
front_wheel(r=1),
rear_wheel(r=2)
);
end Example;
model Vehicle
parameter Modelica.Units.SI.Mass m;
Wheel front_wheel;
Wheel rear_wheel;
end Vehicle;
model Wheel
parameter Modelica.Units.SI.Radius r;
end Wheel;
end Demo;
You can also add modifiers for sub-components graphically in OMEdit, using the Modifiers tab of a component. There you just enter the modifier equation and it will be added to the code.
Some Modelica tools (like Dymola) also allow you to look graphically into components, not only into classes. Then you can add modifier equations easily by setting parameters of sub-components and you don't have to type the full path. It seems that OMEdit has no such feature yet (at least I have not found it).
However, there is a simple solution to this limitation: You can declare parameters for values you want to change from a higher level and propagate their values to the sub-components. If we do that in the demo code above, Example
and Vehicle
could look like this:
model Example
Vehicle tractor(
m = 7e3,
r_front=1,
r_rear=2);
end Example;
model Vehicle
parameter Modelica.Units.SI.Mass m;
parameter Modelica.Units.SI.Radius r_front;
parameter Modelica.Units.SI.Radius r_rear;
Wheel front_wheel(r=r_front);
Wheel rear_wheel(r=r_rear);
end Vehicle;
Then you can also change these values in the graphical layer: