Skip to content

Commit

Permalink
Dymola to OpenModelica
Browse files Browse the repository at this point in the history
  • Loading branch information
sAbdelhaleem committed May 11, 2024
1 parent f82ce25 commit 9b76efe
Show file tree
Hide file tree
Showing 8 changed files with 661 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@
{% for borefield in range( sys_params["number_of_borefields"] ) %}

connect(supHeaWat[{{borefield+1}}].ports[1], T{{ coupling.plant.id[6:] }}In[{{borefield+1}}].port_a)
{% raw %}annotation (Line(points={{-212,20},{-200,20}}, color={0,127,255}));
{% raw %}annotation (Line(points={{-220,20},{-200,20}}, color={0,127,255}));
{% endraw %}

{#
// start code block 6 (if you apply comment out code block 7 below, and code block 5 in /home/sabdelh/GitHubRepos/geojson-modelica-translator/geojson_modelica_translator/model_connectors/plants/templates/Borefield_Instance.mopt)
// Dymola alternative (before moving to OpenModelica)

connect(T{{ coupling.plant.id[6:] }}In[{{borefield+1}}].port_b, {{ coupling.plant.id }}[{{borefield+1}}].port_a)
{% raw %}annotation (Line(points={{-180,20},{-150,20}}, color={0,127,255}));
{% endraw %}
connect({{ coupling.plant.id }}[{{borefield+1}}].port_b, T{{ coupling.plant.id[6:] }}Out[{{borefield+1}}].port_a)
{% raw %}annotation (Line(points={{-130,20},{-100,20}}, color={0,127,255}));
{% endraw %}

// end code block 6
#}


// start code block 7

// OpenModelica alternative (using code block 4 in OpenModelica resulted in error, most probably because OpenModelica does not allow records to have array parameters). https://trac.openmodelica.org/OpenModelica/ticket/5991#comment:15:~:text=I%20suspect%20the%20issue%20is%20the%20same%20that%20plagues%20the%20Building%20library%2C%20which%20often%20uses%20record%20to%20hold%20datasheets%2C%20which%20may%20contain%20structural%20parameters%20for%20array%20dimensions.)


connect({{ coupling.plant.id }}_{{borefield+1}}.port_a,T{{ coupling.plant.id[6:] }}In[{{borefield+1}}].port_b)
annotation (Line(points={{sys_params["diagram_ghe_components_OpenModelica"][borefield]["Line"]["TUTubIn_boreFieUTub"]["points"]}}));

connect({{ coupling.plant.id }}_{{borefield+1}}.port_b, T{{ coupling.plant.id[6:] }}Out[{{borefield+1}}].port_a)
annotation (Line(points={{sys_params["diagram_ghe_components_OpenModelica"][borefield]["Line"]["boreFieUTub_TUTubOut"]["points"]}}));

// end code block 7


connect(T{{ coupling.plant.id[6:] }}Out[{{borefield+1}}].port_b, sinHeaWat[{{borefield+1}}].ports[1])
{% raw %}annotation (Line(points={{-80,20},{-70,20}}, color={0,127,255}));
{% raw %}annotation (Line(points={{-100,20},{-80,20}}, color={0,127,255}));
{% endraw %}
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// No components for borefield and ambient loop coupling
{% for num_of_ghe_group in range(sys_params["num_of_ghe_groups"]) %}

{#
// start code block 4
// Dymola alternative (before moving to OpenModelica)

Buildings.Experimental.DHC.EnergyTransferStations.BaseClasses.Pump_m_flow pumStoGrp_{{num_of_ghe_group}} [nBorFieGrp_{{num_of_ghe_group}}](
redeclare final package Medium = Medium,
// datDes needs adjustment #SMA_TBD
Expand Down Expand Up @@ -39,4 +43,53 @@
"Scale with nominal mass flow rate"
annotation (Placement(transformation(extent={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Placement"]["gaiStoGrp"]["extent_coo"]}})));

// end code block 4

#}

// start code block 5

// OpenModelica alternative (using code block 4 in OpenModelica resulted in error, most probably because OpenModelica does not allow records to have array parameters). https://trac.openmodelica.org/OpenModelica/ticket/5991#comment:15:~:text=I%20suspect%20the%20issue%20is%20the%20same%20that%20plagues%20the%20Building%20library%2C%20which%20often%20uses%20record%20to%20hold%20datasheets%2C%20which%20may%20contain%20structural%20parameters%20for%20array%20dimensions.)

Buildings.Experimental.DHC.EnergyTransferStations.BaseClasses.Pump_m_flow pumStoGrp_{{num_of_ghe_group}} [nBorFieGrp_{{num_of_ghe_group}}](
redeclare final package Medium = Medium,
// datDes needs adjustment #SMA_TBD
// !!!!!! important !!!!!! #SMA_TBD
m_flow_nominal={% raw %}{{% endraw %}{% for borefield in range( sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] ) %}{% if loop.index != sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal,{% else %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal}){% endif %}{% endfor %}
"Bore field pump"
annotation (Placement(transformation(extent={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Placement"]["pumSto"]["extent_coo"]}})));

Buildings.Experimental.DHC.Networks.Combined.UnidirectionalSeries
disStoGrp_{{num_of_ghe_group}}(
redeclare final package Medium = Medium,
final nCon=nBorFieGrp_{{num_of_ghe_group}},
show_TOut=true,
// check #SMA_TBD
// !!!!!! important !!!!!! #SMA_TBD
final mDis_flow_nominal=datDes_buiGrp_{{sys_params["ghe_groups_by_num"][num_of_ghe_group]["building_group_out"]}}.mPipDis_flow_nominal,
final mCon_flow_nominal={% raw %}{{% endraw %}{% for borefield in range( sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] ) %}{% if loop.index != sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal,{% else %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal}{% endif %}{% endfor %},
// these are parameters of the conSto component (not for this component) (check it out) #SMA_TBD
// !!!!!! important !!!!!! #SMA_TBD
// final dhDis=0.2, #SMA_TBD
// final dhCon=0.2, #SMA_TBD
// this was included in original dis component (check it out) #SMA_TBD
// !!!!!! important !!!!!! #SMA_TBD
//final dp_length_nominal=datDes.dp_length_nominal, #SMA_TBD
final lDis=fill(0, nBorFieGrp_{{num_of_ghe_group}}),
final lCon=fill(0, nBorFieGrp_{{num_of_ghe_group}}),
// this was included in original dis component (check it out) #SMA_TBD
// !!!!!! important !!!!!! #SMA_TBD
final lEnd={{sys_params["ghe_parameters"]["geometric_constraints"]["lEnd"]}},
dp_length_nominal=150,
final allowFlowReversal=allowFlowReversalSer)
"Distribution network (Connection to the bore field)"
annotation (Placement(transformation(extent={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Placement"]["disSto"]["extent_coo"]}})));

Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiStoGrp_{{num_of_ghe_group}} [nBorFieGrp_{{num_of_ghe_group}}](
k={% raw %}{{% endraw %}{% for borefield in range( sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] ) %}{% if loop.index != sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal,{% else %}{{coupling.plant.id}}DatGrp_{{num_of_ghe_group}}_{{borefield+1}}.conDat.mBorFie_flow_nominal}{% endif %}{% endfor %})
"Scale with nominal mass flow rate"
annotation (Placement(transformation(extent={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Placement"]["gaiStoGrp"]["extent_coo"]}})));

// end code block 5

{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,35 @@
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["disStoGrp_pumStoGrp"]["points"]}}));
connect(pumStoGrp_{{num_of_ghe_group}}.port_b, T{{ coupling.plant.id[6:] }}InGrp_{{num_of_ghe_group}}.port_a)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["pumStoGrp_TUTubInGrp"]["points"]}}));

{#
// start code block 6 (if you apply comment out code block 7 below, and code block 5 in /home/sabdelh/GitHubRepos/geojson-modelica-translator/geojson_modelica_translator/model_connectors/plants/templates/Borefield_Instance.mopt)
// Dymola alternative (before moving to OpenModelica)

connect(T{{ coupling.plant.id[6:] }}InGrp_{{num_of_ghe_group}}.port_b, {{ coupling.plant.id }}Grp_{{num_of_ghe_group}}.port_a)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["TUTubInGrp_borFieUTubGrp"]["points"]}}));
connect({{ coupling.plant.id }}Grp_{{num_of_ghe_group}}.port_b, disStoGrp_{{num_of_ghe_group}}.ports_aCon)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["borFieUTubGrp_disStoGrp"]["points"]}}));

{% for borefield in range( sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] ) %}
// end code block 6
#}

connect(gaiStoGrp_{{num_of_ghe_group}}.y, pumStoGrp_{{num_of_ghe_group}}.m_flow_in)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["gaiStoGrp_pumStoGrp"]["points"]}}));

{% for borefield in range( sys_params["ghe_groups_by_num"][num_of_ghe_group]["num_ghes_in_group"] ) %}

// start code block 7

// OpenModelica alternative (using code block 4 in OpenModelica resulted in error, most probably because OpenModelica does not allow records to have array parameters). https://trac.openmodelica.org/OpenModelica/ticket/5991#comment:15:~:text=I%20suspect%20the%20issue%20is%20the%20same%20that%20plagues%20the%20Building%20library%2C%20which%20often%20uses%20record%20to%20hold%20datasheets%2C%20which%20may%20contain%20structural%20parameters%20for%20array%20dimensions.)

connect({{ coupling.plant.id }}Grp_{{num_of_ghe_group}}_{{borefield+1}}.port_a,T{{ coupling.plant.id[6:] }}InGrp_{{num_of_ghe_group}}[{{borefield+1}}].port_b)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["borefields_diagram"][borefield]["Line"]["TUTubInGrp_borFieUTubGrp"]["points"]}}));
connect({{ coupling.plant.id }}Grp_{{num_of_ghe_group}}_{{borefield+1}}.port_b, disStoGrp_{{num_of_ghe_group}}.ports_aCon[{{borefield+1}}])
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["borefields_diagram"][borefield]["Line"]["borFieUTubGrp_disStoGrp"]["points"]}}));

// end code block 7

connect(gaiStoGrp_{{num_of_ghe_group}}[{{borefield+1}}].u, One.y)
annotation (Line(points={{sys_params["ghe_groups_by_num"][num_of_ghe_group]["Line"]["one_gaiStoGrp"]["points"]}}));
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@
connect(TDisWatRet.port_b, pumDis.port_a)
annotation (Line(points={{sys_params["bldg_groups_by_num"][num_of_bldg_group]["Line"]["TDisWatRet_pumDis"]["points"]}}));

connect(gai.y, pumDis.m_flow_in)
annotation (Line(points={{sys_params["bldg_groups_by_num"][num_of_bldg_group]["Line"]["gai_pumDis"]["points"]}}));

connect(One.y, gai.u)
annotation (Line(points={{sys_params["bldg_groups_by_num"][num_of_bldg_group]["Line"]["one_gai"]["points"]}}));

{% endif %}

{% endfor %}

connect(One.y, gai.u)
{% raw %}annotation (Line(points={{-280,-160},{-240,-160}}, color={0,0,127}));
{% endraw %}
connect(gai.y, pumDis.m_flow_in)
{% raw %}annotation (Line(points={{-220,-160},{400,-160}}, color={0,0,127}));
{% endraw %}
Loading

0 comments on commit 9b76efe

Please sign in to comment.