auto-updatemodelica

conversion script for pipe(redeclare package Medium=NewMedium)


Several models in a library have been moved, and now I need to update many modifiers that redeclare these. An example model that needs to be updated could look like this:

model mySystemModel
  Modelica.Fluid.Pipes.DynamicPipe pipe(
    redeclare package Medium = Modelica.Media.CompressibleLiquids.LinearColdWater,
    use_HeatTransfer=true,
    redeclare model HeatTransfer = Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.ConstantFlowHeatTransfer)
    annotation (Placement(transformation(extent={{-20,0},{0,20}})));
  annotation (uses(Modelica(version="4.0.0")));
end mySystemModel;

Assuming the library has been restructured such that
Modelica.Media.CompressibleLiquids.LinearColdWater is now instead located in
Modelica.Media.RealLiquids.LinearColdWater, and
Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.ConstantFlowHeatTransfer is now moved to
Modelica.ThermoFluid.HeatTransfer.ConstantFlowHeatTransfer, what would the conversion script look like that updates all redeclarations from modifiers?

Currently, my understanding is that I have to write one conversion for every component that might use these classes in a modifier, but the Medium can be used in hundreds of components, and the HT correlation also in many!? And, multiple classes inside the package have been moved (or, package has been renamed).


Solution

  • It should suffice with

    convertClass("Modelica.Media.CompressibleLiquids.LinearColdWater", "Modelica.Media.RealLiquids.LinearColdWater");
    convertClass("Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.ConstantFlowHeatTransfer", "Modelica.ThermoFluid.HeatTransfer.ConstantFlowHeatTransfer");
    

    Having a conversion for every class isn't needed here, but is when you change something in a base-class - e.g., if you renamed 'Medium' to 'WaterMedium' in a base-class.

    If you use Dymola (I believe it was introduced in Dymola 2021) you can automatically generate such conversions (assuming you have the old version of the library) by checking the conversion (which also detects other issues).