Reusing a subsystem across models with component files
Some parts of a model are worth building only once: a battery with the air around it, a pump with its controller, a room with its heater. A subsystem already collects such a part into one box. Saving it as a component file lets other models use it, and a change made to the file reaches every model that is linked to it.
This page builds one from the bundled Thermal Management example, places it twice in an empty model and then changes it. If subsystems are new to you, start with "Subsystems and relationship groups".
Make the subsystem
Open Thermal Management from Examples. Shift-click Battery module and Enclosed air, press Create subsystem in the toolbar and name it Battery pack. Electrical losses stays outside.

Say what it offers
Click the box's label to open its card. Two lists under Component decide what another model can see and change.
- Ports are states the component offers outside. The battery's temperature is connected to something outside, so it is listed already. Press Keep as a port to make it part of the component.
- Parameters that you expose can differ from one placement to another. Under Expose a parameter, choose Battery thermal capacitance.
Do this before saving. Once the subsystem is linked to its file, ports and exposed parameters are changed in the file.
Save it as a component file
Press Save as component file… on the card, or choose it from the box's right-click menu, and pick a name. The file is an ordinary .kjt project that also records what the component offers.
Saving does more than write a copy: the subsystem you saved from is now linked to the file. The file is where the component is changed from here on, and this model follows it.

Inside a linked subsystem the cards of its nodes and of the relationships among them are read only. They say where the component is changed and offer Open in new window.
If you wanted a separate copy that you can edit here, choose Detach on the subsystem's card.
Place it in another model
Start a new project, open the Add menu and choose Component from file….

Choose the file. Konjugate shows what it offers before placing anything.

Press Place. To use the same component again, open its card and press Place another instance. The second box is called Battery pack 2.
Give each its own value
In the card of Battery pack 2, the exposed capacitance has a field of its own. Change it from 1000 to 4000 J/K. The first pack keeps the default.
Run the model for 600 seconds. Nothing is connected to either port here, so each battery simply exchanges heat with its own enclosed air.
Change the component once
Close the results. On either pack's card press Open in new window. The component file opens as a project, and a bar says what it offers.

Change the starting temperature of Enclosed air to 283.15 K and save. The model with the two packs takes the change in and says so.

What to remember
- Saving a component file links the subsystem you saved from to that file.
- Keep your ports and expose your parameters before saving.
- A linked instance is changed in the file. Detach turns it into a copy kept in your model.
- Exposed parameters are what can differ between instances.
Some changes to a component affect what is connected to it, and a file can be moved. "Keeping linked components in step" covers both. To keep parts inside the app instead of in files of your own, see "The component library".
Follow Konjugate on LinkedIn for updates, or subscribe via RSS.
Comments
Post a Comment