Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » CTG
  • » Profile

Posts

Posts

After plotting the desired variables, you can select the csv icon from the Plot Toolbar. This will export in csv format the selected variables. I do not know if there is a way to export automatically all variables.

Hi,
Some of the problems you are having are related to the non-standard construction of the SolarTherm library. For example the problem you had with connections, and now the problem with assigning units to Integer variables. According to the Modelica specification the Integer type has no "unit" attribute, but SolarTherm is using it. You have two options: one is to delete the the unit assignament for the Integer variables, the second is to use the old frontend of OpenModelica, that is much more permissive with this type of non-standard syntax.
Regarding the number of equations and variables, I have found many times this disagreement and in my experience the correct value is the one you obtain when running the model. The identification of the Medium as partial class is clearly a fail of the OpenModelica new frontend, and the problem dissapears with the old one. It seems that 3 equations are missing. As I have no knowledge about SolarTherm I can say nothing more.

Carlos

The connect equation must be used with two connectors, it can't be used for entities that are not connectors. date.t for example is just an output Real. Change the connection equation for just an equation, for example: "date.t = wbus.t;"

Jul-05-21 08:49:19
Advise - library fluid models

All the code inside the model NNMediumExample is just an example of how the package can be used to get the viscosity. You must write your medium package assigning value to the constants according to your substance. Later you can use this medium package inside your models to get the thermodynamic and transport properties needed.

Jun-29-21 20:28:12
Advise - library fluid models

Yes, you can begin with a pure substance and Modelica.Media.Interfaces.PartialLinearFluid seems a good start base. It uses constant isobaric expansion coefficient (beta) and isothermal compressibility (kappa). reference_d, reference_h and reference_s are just the values of density, enthalpy and entropy at reference temperature and pressure. Of course you can assign to reference_h and reference_s any value. The variation in enthalpy and entropy is calculated using a constant Cp and considering that internal energy doesn't depend on pressure. The molecular mass has no influence in the calculation, that is always done in mass units, no in mole units (Cp is in J/(kg·K)).
It follows an example using a power law for viscosity calculation:

package LinearNNMedium "Linear medium with non-Newtonian viscosity"
  extends Modelica.Media.Interfaces.PartialLinearFluid(
    mediumName="Linear medium",
    constantJacobian=true,
    reference_p=101325,
    reference_T=278.15,
    reference_d=900,
    reference_h=0,
    reference_s=0,
    cp_const=3200,
    beta_const=2.5713e-4,
    kappa_const=4.5154e-10,
    MM_const=0.1);

  redeclare function extends dynamicViscosity
    input Real ssr=0 "shear strain rate";
  protected
    DynamicViscosity eta0=0.1 "viscosity at 0 shear strain rate";
    DynamicViscosity etaInf=0.001 "viscosity at infinite shear strain rate";
    Real n=0.5 "flow behavior index";
  algorithm
    eta := if ssr>0 then  etaInf+(eta0-etaInf)*ssr^(n-1.0) else eta0;
  end dynamicViscosity;

  redeclare function extends thermalConductivity
  algorithm
    lambda := 0.572;
  end thermalConductivity;
end LinearNNMedium;

model NNMediumExample
  package Medium=LinearNNMedium;
  parameter Medium.Temperature T=300;
  parameter Medium.AbsolutePressure p=2e5;
  parameter Real ssr=100;
  Medium.ThermodynamicState state;
  Medium.DynamicViscosity eta;
equation
  state=Medium.setState_pTX(p,T);
  eta=Medium.dynamicViscosity(state,ssr);
end NNMediumExample;

The problem you will find when using this type of medium with Modelica.Fluid is that Modelica.Fluid is not prepared for a non-standard medium like this one. When it needs the viscosity it will call the dynamicViscosity function giving just the thermodynamic state and in plus, as far as I know, Modelica.Fluid has no support for shear strain rate consideration. I think that you have here two options: one is to write your own flow models. The second is to define different medium models fixing the shear strain rate at the required value and later calling the needed one.

Jun-28-21 21:27:50
Advise - library fluid models

Hi Tom,
I would say that the difficulty of the solution depends mainly in the possibility, or not, of using a pure substance medium. In a pure substance medium thermodynamic properties are independent of composition or, in other words, composition is fixed.
If you can use a pure substance medium, you can extend from, for example, Modelicas's standard library PartialSimpleMedium, or PartialLinearFluid. Or if you need a more sophisticated calculation, you can use other opensource libraries. In this situation your main work will be writting the dynamicViscosity function. All the media functions are expected to receive as input only a ThermodynamicState record, but in your case the viscosity depends not only on the thermodynamic state but also in the shear strain rate. Nevertheless this doesn't seem a strong limitation: when you extend the partial function dynamicViscosity, you can add as input the shear strain rate, and make the calculation taking it into account.
If you need a medium with properties dependence on composition, as it seems is the Modelon's drilling library case (brine+base oil) , situation is much more complex. As far as I know there is no opensource package covering this for liquids. I have in my plans to develope one using PCSAFT EOS for thermodynamic properties calculation and residual entropy for transport properties, but I will need some months for this. Nevertheless, if you are going to write a media package and need some support, I will try to help.

Regards

Carlos

Jun-21-21 20:37:43
Create a new medium model with TemplateMedium

Hi,
I think that there are two different problems here. One is the definition of the Medium: yes you can define a Medium extending directly from Modelica.....PartialMedium, but it is quite time consuming as you need to redefine all the needed functions. Normally it is easier to extend from a more elaborated partial medium. As I see that you are using fixed values for almost all physical properties, I have selected an extension from PartialSimpleMedium. And also take into account that the values for physical and thermodynamic propeties must be in basic SI units, and referenced to mass and not to moles. You can extend also from more complex models as for example PartialLinearFluid. You can look at how it is done at Modelica.Media.CompressibleLiquids.LinearColdWater.
The second point is related with the use of the medium. If you define a medium package, you must use it, not the partial medium from which it extends.
It follows a medium definition and its use. I have checked that the example runs but I have not checked if it has been build correctly.

package SimpleMedium
  extends Modelica.Media.Interfaces.PartialSimpleMedium(
    mediumName="simple medium",
    cp_const=2000,
    cv_const=2000,
    d_const=1020,
    eta_const=1.0e-3,
    lambda_const=0.1,
    a_const=1000,
    T_min=273.15,
    T_max=573.15,
    T0=273.15,
    MM_const=0.024);
end SimpleMedium;

model Example
  inner Modelica.Fluid.System system annotation(
    Placement(visible = true, transformation(origin = {-270, 84}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Fluid.Sources.MassFlowSource_T boundary(redeclare package Medium =
  SimpleMedium, m_flow = 10, nPorts = 1)  annotation(
    Placement(visible = true, transformation(origin = {-224, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Fluid.Sources.FixedBoundary boundary1(redeclare package Medium =
  SimpleMedium,nPorts = 1)  annotation(
    Placement(visible = true, transformation(origin = {44, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium =
  SimpleMedium,diameter = 5e-2, length = 10)  annotation(
    Placement(visible = true, transformation(origin = {-96, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(boundary.ports[1], pipe.port_a) annotation(
    Line(points = {{-214, 0}, {-108, 0}, {-108, 0}, {-106, 0}}, color = {0, 127, 255}));
  connect(pipe.port_b, boundary1.ports[1]) annotation(
    Line(points = {{-86, 0}, {34, 0}, {34, -2}, {34, -2}}, color = {0, 127, 255}));

annotation(
    uses(Modelica(version = "3.2.2")));
end Example;

Carlos

May-05-21 21:01:02
Problems with connections and property package.

You will need to erase the lines:

  annotation(
    uses(Modelica(version = "3.2.3")));

at the end of the package, that have been added automatically because I  am using Modelica 3.2.3 and not 4.0.0

May-05-21 20:56:09
Problems with connections and property package.

Every element of your model coming from Modelica.Fluid needs the specification of the Medium used. In OMEdit it can be done, from version 1.16 I think, using the graphical interface. In the tab 'General' you can select the Medium from the compatible ones charged. Another normal way is to define an alias for a Medium in your model, and make the Medium of each element equal to this alias. I have used both ways in a modified model.
You have connected an external source to the port  T_in of boundary1, but 0.1 ºK doesn't seem a reasonable value, so I think that you probably wanted to specify 0.1 kg/s for the port flow, and I have changed the connection to the m_flow_in port. Nevertheless you need also to specify that you want to take the value received via the connection by checking the box 'use_m_flow_in'.
For the flow characteristic of the valves you have left the default value of OpPoint. In this case you need to give the operation point, this means to fill the nominal pressure drop at the nominal flow, with the nominal opening. In one of the valves I have changed to Kv and specified the Kv of the valve. It was also necessary to supply the apperture to the valve connectors.
In order to better follow the evolutionof the tank I have specified a simulation time of 3600 s.

ModelicaTest34.mo



May-05-21 09:17:56
Problems with connections and property package.

Hi Cleiton,
Can you post an example of one of your models in trouble? It would help to know where is the problem.

May-03-21 11:41:11
Having problems starting a simulation so I want to view the initial values to debug the problem

Sorry for the delay, I didn't follow the topic.
In Windows, you will find the generated files under your user, in the \AppData\Local\Temp\OpenModelica\OMEdit plus the name of your simulation. The file with .log extension can be opened with a text editor.

Carlos

Hi,
For people working in chemical engineering applications the main limitation with OpenModelica, I think, is the lack of Medium definitions (in fact the complexity of Modelica.Fluid is also a strong limitation). HelmholtzMedia is very powerful but has few fluids implemented and CoolProp is difficult to run. And for many substances transport properties are missing.
I have done a fork of HelmholtzMedia where I am transfering the fluids information from CoolProp and adding, when necessary, transport properties. You will find the fork here
I hope the work can be useful. I want also to thank Matthis Thorade for his encouragement.

Carlos

The saturation properties are independent of each phase fraction, so no need to use it.
You define a SaturationProperties record, that can be constructed from temperature or pressure, and you obtain the properties from it. For the latent heat of vaporization you need to do the substraction. For obtaining the saturation temperature and pressure it is not necessary to use the SaturationProperties record, they are obtained directly:

model SaturationProperties
  package Medium=Modelica.Media.Water.StandardWater;
  Medium.Temperature T;
  Medium.AbsolutePressure P;
  Medium.SaturationProperties sat1,sat2;
  Medium.SpecificEnthalpy Hl1,Hv1,Hl2,Hv2;
 
  Medium.AbsolutePressure Psat;
  Medium.Temperature Tsat;
equation
  T=390;
  sat1=Medium.setSat_T(T);
  Hl1=Medium.bubbleEnthalpy(sat1);
  Hv1=Medium.dewEnthalpy(sat1);
 
  P=0.5e5;
  sat2=Medium.setSat_p(P);
  Hl2=Medium.bubbleEnthalpy(sat2);
  Hv2=Medium.dewEnthalpy(sat2);
 
  Psat=Medium.saturationPressure(T);
  Tsat=Medium.saturationTemperature(P);
end SaturationProperties;

Apr-21-21 07:00:13
Error while using CurvedBend Fitting

Hi Balaji,
As far as I know the developers of OpenModelica are specialists in simulation, but not in each of the areas covered by the Modelica standard library. The Fluid library I guess is built by a working group, with the authors of this paper probaly involved. Of them, Francesco Casella is also one of the leading persons of OpenModelica.

Regards

Carlos

Apr-20-21 22:02:44
Error while using CurvedBend Fitting

Dear Balajik,
The problem with Modelica.Fluid is its complexity. So, it is not easy to analize how it is working. I gave a look at the models and it is really difficult to fully understand them without spendig a some hours, so I finished there. I think that the only persons that probably can help you are the authors or the library.

Regards

Carlos

Apr-14-21 21:34:07
Having problems starting a simulation so I want to view the initial values to debug the problem

In OMEdit  you can open the simulation setup and, in the simulation flags tab, tick LOG_INIT_V. You will find the log in the output path with information about the start values used.

Hi,
Yes it was an old bug than seemed solved, but I have had the same problem just one time with version 1.16.5. I'm using now version 1.17.0 and till now no problem here.

Carlos

I think you are looking for something like this:

package ModelicaTest30
  model M
  end M;
  // model1
  model M1
  extends M;
  parameter Real p1 = 1 "p1";
    Real y "y";
  equation
    y = p1 * time;
  end M1;

  // model2
  model M2
  extends M;
  parameter Real p2 = 1 "p2";
    Real y "y";
  equation
    y = p2 * time + 23.145;
  end M2;

  // system
  model SYS
  parameter Real a = 10 "a";
    parameter Real b = -2 "b";
    Real z "z";
    replaceable M1 m constrainedby M annotation(
      choices(choice(redeclare M1 m(p1 = 10) "Default"), choice(redeclare M2 m(p2 = 20) "Variant")));
  equation
    z = a * m.y + b;
  end SYS;

  // Test
model Essai
//SYS sys1 (redeclare M1 m (p1 = 2)) ;
//SYS sys1 (redeclare M2 m (p2 = 4)) ;
    SYS sys (redeclare M2 m (p2 = 3.254))  annotation(
      Placement(visible = true, transformation(origin = {4, 6}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
end Essai;
end ModelicaTest30;

You can choose between the compatible models, and parameters ,in SYS, but you can't edit graphically the parameters in m. You can specify them manually.

Hi,
Yes the convergence problem comes from the HelmholtzMedia library. The message is related with convergence problems in the setState_phX function. So, of not easy solution.

Carlos

Hi Steven,

I made a fast look at your model and the documentation. One point, I see that you are filling a 350 lts tank with a Kv=0.11 valve, as per the documentation a understand (pag.13 of D4.1) that the valve must fill 4 tanks (1400 lts total volume).
I think that viscosity is not necessary for the valve calculation, normally valves are treated as isenthalpic. You will need it and thermal conductivity for the heat transfer at the tanks.
And one bad new. I see that the medium has convergence problems when arriving close to 400 bars.

Regards

Carlos

Hi Steven,
I gave a look to the documentation. I think you need a package for fluid flow and a package for medium properties calculation. For the fluid flow, the valve should not be a problem, the only requisite is that it grants not to exceed the sound velocity. The tank could be more complicated, as it has a multilayer shell and I see that the temperature at each material layer is calculated, shape could be also important, but I do not know. As there is a dedicated library I would try to use it. It is based in ExternalMedia and CoolProp, but this should be easy to modify. All Medium definitions must support the Modelica defined interface, and in this case (fixed composition and single phase) almost all Mediums should work. A quite different point is the quality of the results offered by the Medium, and the coverage of physical properties it has. At the high pressure you need to work I think that a Medium based in a multiparameter EOS is needed. You have CoolProp, but doesn't work with OpenModelica, and HelmholtzMedia. I'm almost sure that you will need viscosity and thermal conductivity, and the file I sent doesn't perform their calculation.
I think that the easiest for you is to finish the Hydrogen medium adding the viscosity and thermal conductivity calculation. In a dirty and fast way it can be done declaring both models as hardcoded (VS0 for viscosity and TC0 for thermal conductivity) and writing their calculation inside the dynamicViscosity_residual and thermalConductivity_background functions. The calculation of viscosity is available  here. For thermal conductivity you can look at the calculation in CoolProp.
I am extending the HelmholtzMedia package to support transport properties from CoolProp, but I will still need some days to finish.

Regards

Carlos

Hi Steven,

I have run the Test_Valve example of the ThermoCycle library with no problem using: R134A from my own library, R134A from HelmholtzMedia library and the Hydrogen file for the HelmholtzMedia library that I sent to you.
I needed to make first an adjustement. As the valve component is declared as having ThermoCycle.Media.R245fa_CP as Medium, OpenModelica was complaining about the lack of the class ExternalMedia.Media.CooPropMedium. I just changed the Medium declaration in the valve model to one of my library, you can do to one in HelmholtzMedia or in Modelica.Media, and the example run.
On Monday I will have a look to the document you have supplied. But perhaps is good to know what do you want to simulate.


Hi Steven,

The file attached is an XML file with no information.

Hi Steven,
I attach the Hydrogen medium. Decompress and put the folder inside HelmholtzFluids. The limits for enthalpy and entropy are only approximate. I made a fas test and results seem OK.
I review also the HelmholtzMedia treatment of viscosity. It seems inherited from RefProp and the dilute viscosity term is quite confusing. For the residual viscosity there are only very few mediums coded. The treatment in CoolProp is clearer and larger, but still is quite limited, as they develop viscosity only for substances with a reference viscosity equation from temperature and density. I am thinking in rewrite the HelmholtzMedia.Interfaces.PartialHelmholtzMedium.Transport package in order to make it compatible with CoolProp and add calculation from temperature and pressure, but it will need some time.

Regards


Hydrogen.zip

Hi Steven,

I did a Python script to pass the information from CoolProp fluids (json files) to HelmholtzMedia format. In fact I have planned to pass all the fluids in CoolProp and share them, but I have not yet done the transport properties mapping. If you are interested I can make the file for Hydrogen, it should allow for all thermodynamic properties calculation plus surface tension, but viscosity and thermal conductivity will be lacking, and I think you will need them.

Carlos

Hi,
I see that the library is using mediums accessed via the ExternalMedia library linked with CoolProp. I think that ExternalMedia is not working in OpenModelica, perhaps Adrian can confirm if this is the situation or not. If you can't use ExternalMedia and CoolProp, the easiest way for having a good hydrogen Medium definition I think is using HelmholtzMedia, but you will need to do some work.

Carlos

Hi,
I saw other problems. There is not the ports size for the boundary, You must include nPorts=1 inside the parenthesis. The valve needs a value for the apperture, that is missing. The value for T_ambient of the system is -15K, an impossible value. This last problem I see is due to a bug of OMEdit: it allows you to select the units in deg C., but when you enter a minus sign it changes inmediately to Kelvin.
You selected also an incompressible Medium, if it is incompressible the only solution for the system is no flow and pressure in the reservoir equal to that of the boundary. I think you can use Modelica.Media.IdealGases.SingleGases.H2, it is not a good model for high pressure, but is the only one available directly in Modelica. I attach a modified code.

ModelicaTest28.mo


Carlos

Mar-09-21 18:56:01
The model does not work or extremely slow due to minor changes

Hi Steffen,
I have actualized my library with a model for a piston/diafragm pump, and I have updated it at GitHub, including now the fluid flow related packages. If you want to have a look, you will find it  here. Inside the package Pumps/Examples you will find the model PistonPumpTest, with an implementation of one of yours models. It is using the Modelica.Blocks.Sources.Sine block, but you can change it for your Sinus block. I do not know if it is what you need, I hope so.

Regards

Carlos

Mar-08-21 16:40:53
The model does not work or extremely slow due to minor changes

Hi Steffen,
I had never played for a while with Modelica.Fluid and I must acknowledge that it is really confusing, at least in combination with OpenModelica. I understand that the model you are trying is really simple.  As the use of a closed volume is only for taking into account the accumulation of mass (due to density changes) or energy (due to enthalpy changes) I took it out, I replaced also the pipe by an static pipe for the same reason. But two problems remain, one is that it continues to initialize only at sinus of pi/2. I tried to change the dynamics of the swept volume to steady state and it was still worse. The second remaining point is that the swept volume is not a complete possitive displacement pump, as it pushes volume when is shaft possition is going in one way, but it is suctioning when going in the opposite. it is necessary to add check valves, and to connect to a boundary for the suction cycle. If not, we would vaporize the water. It has been impossible for me to make it work.
After this, I have simulated the system with my library with no problem, but I have discovered a point that could be also at the base of some of the problems with Modelica.Fluid. I mounted an integrator in order to be able to record the pumped volume, but it was not working. Finally I discovered that it is due to a numerical problem related to the very low mass pumped when the pump is inverting the movement. I have needed to integrate the mass, and later to pass the mass to volume.
I will try to post part of my library, at least the part related with fluid flow, and the implementation of your test in a few days.

Regards

Carlos

Mar-06-21 10:10:42
The model does not work or extremely slow due to minor changes

Hi Steffen,
I would like to clarify a point. I think you are trying to simulate a dosing pump with its pipe and a flow dampener. If it is the case, I would say that the volume you are defining can't act as dampener. It is declared a constant volume filled with water, but taking into account the water compressibility.... For a dampener we would need a constant initial volume  and a calculation of pressure as a function of the liquid filled volume. Am I right?

Best

Carlos

Congratulations Marco! !

It works perfectly. I have compared the results with my own library and the only difference is at high temperature due to the different ideal gas heat capacity approach. In fact you spent more time than me in polishing, I let there some values from Butane. I did it with CoolProp and Python, using the json parser, because it seemed me easier to automatize than from a text file, and for more substances the work is already done.
There are some points to care about. One is the reference state to use, from CoolProp it seems that the default is IIR and, if not, they add a translation coefficients. For me the more important point now is that of viscosity and thermal conductivity: I gave a look at what HelmholtzFluid is doing, because I want to be sure that it covers all substances for which multiparameter EOS are available, before to work in the mapping between CoolProp and HelmhotzMedia.
In the meanwhile I found and solved the problems of my Media libraries with the BaseProp model. Now the Modelica.Media tests run fine, and also the Modelica.Fluid examples I have tested. I am now checking and polishing and I will update them in a few days.

Best Regards

Carlos

Mar-05-21 08:36:37
The model does not work or extremely slow due to minor changes

Hi Steffen,
I would say that Modelica is the correct tool. I know not too much about the Modelica.Fluid library, that I find too complex for my daily work. There is the possibility of using Modelica.Fluid.Pipes.StaticPipes instead of the DynamicPipe model, but I tested it and gave the same problem. I normally work with my own library , based on static (steady state) approach. There is no problem to share it,  but I do not have the damper model, although it is easy to create, and I do not know if it will converge with your test. Normally it converges much more easily than Modelica.Fluid. Let me take some days, I will create the closed volume damper and test your model. I will inform you in this post.

Regards

Carlos

Mar-04-21 20:59:00
The model does not work or extremely slow due to minor changes

Hi Steffen,
I'm sorry, but I can't help too much here. You are having the normal problems to expect in this type of simulations. The Modelica.Fluid is a highly complex libray, I think that too much for this type of applications, and with complex libraries convergence is always an issue. It seems that when you start at low flow change it converges, but when you go away from this point not. I would have tried what you did, start flow at the expected level for the sinus phase. Another possibility is to record all the values we obtain at 0 radians and enter them as start values.

Hi Franco,

It begins to work. I can export automaticaly from CoolProp to HelmholtzMedia the EOS (ideal and residual parts), the ancillary equations and the surface tension. For viscosity and thermal conductivity I need some more time to clarify the equivalence.
There are some points to polish: for example CoolProp doesn't give the minimum and maximum enthalpy, or density. I do not know if putting here an approximate number is enough. One possibility is to put an approximate value, run the EOS between minimum and maximum temperatures and pressures and re-enter the obtained values.
I have seen that HelmholtzMedia doesn't have some terms needed for the most recent EOS. It lacks Gao, and association, terms, For this reason I have used the Tillner Roth equation for Ammonia instead of the 2020 Gao equation.
I attach the folder and files to put in the HelmholtzFluids folder. You will see that I have suppressed the entries for viscosty and thermal conductivity, so do not use them for now. Can you check if it works for you?
Ammonia.zip

Mar-02-21 12:39:15
Hi, I need to implement an external C function in Modelica.

You can use also other directories if you include them, as follows:

package ChirpP
  class ChirpSignal
    Modelica.Blocks.Interfaces.RealOutput u;
    parameter Modelica.SIunits.AngularVelocity w_start = 1;
    parameter Modelica.SIunits.AngularVelocity w_end = 10;
    parameter Real A = 1;
    parameter Real M = 10;
  equation
    u = Chirp(w_start, w_end, A, M, time);
  end ChirpSignal;

  function Chirp
    input Modelica.SIunits.AngularVelocity w_start;
    input Modelica.SIunits.AngularVelocity w_end;
    input Real A;
    input Real M;
    input Real t;
    output Real u "output signal";
 
    external "C"  annotation(
      IncludeDirectory = "modelica://ChirpP",
      Include = "#include \"Chirp.c\"");
  end Chirp;
end ChirpP;

"modelica://ChirpP" will place you in the directory where ChirpP package is, and you can put the c file there. Or indicate a relative path, for example:  IncludeDirectory = "modelica://ChirpP/Resources" and put the C files in Resources, that is the default.

I have changed w_start from 0 to 1, because if it 0 the result is always 0.

Mar-02-21 11:29:01
The model does not work or extremely slow due to minor changes

I tried your model with ConstantPropertyLiquidWater and it runs, with some difficulties but runs. As you told that you had tried it, it could be related with the OpenModelica version you are using. I use 1.16.5 on Windows.
Regarding the Sinus block, my comment was just related with the placement of the model inside the MSL instead of in your own package. Of course it is optional.

Well, I started today. I think that the soft is very good and it is a pity to have so few substances filled. I am working now with butane, in order to validate the results I will obtain from the CoolProp file against the results from the HelmholtzMedia file. It is not difficult and I expect to finish in two days if I can spend some hours in this. I will inform you.

Regards

Feb-28-21 19:08:07
The model does not work or extremely slow due to minor changes

I would say that you are doing fine. It seems to me a convergence problem due to the sudden change in flow. The problem disappears if you change the frequency up or down, no problem at 100 Hz nor at 5 Hz. It disappears also increasing the damper volume to 3e-4 m3.
I do not understand why you are declaring your Sinus block inside Modelica.Blocks.
I have needed to add the full path to Sinus and Sine inside the System7 model in order to make it runnable.

Regards

Carlos

Hi Franco,
Unfortunately you may not be able to use my library. I use always the functional interface, with no problem, but when running the Modelica.Media test I see that the interface using BaseProperties gives compatibility problems, probably due to some defect in the definition of the model. I will try to find the cause and fix it, but this is the current situation.
In the meantime I have rechecked HelmholtzMedia, which is a great library, but it was not working, at least in OpenModelica. I see that it currently works. You don't have ammonia in the fluids list, but it doesn't seem too difficult to add it from the CoolProp data files, using for example a Python program. I'll try to do it.

Regards

Carlos

Hi Franco,
Yes, it includes ammonia. In fact there is a Windows program and a database in the Resources folder, with the program you can export data from the database in the format needed in Modelica. In the database there are 500 substances, and you can add what you need. My Idea has been maintain the data in the database and export the substances when needed.
I am working now with the version 1.16.5 of OpenModelica, using the MSL 3.2.3. For using  MSL 4.0.0 it is necessary to make some very small changes, that I have already tested, but I am waiting for the version 1.18 of OpenModelica to make the change.
In my program (ExternalMedia library only, because the others library are stright Modelica code) there is no dll, there is C code, that is compiled by OpenModelica at the same time that it does the global compilation.

Regards

Carlos

I knew about it, but I thought it was a comercial library. I will try to make it work, in the first test it didn't find the dll library, that is inside the Resources folder. As I have no experience in linking OpenModelica with dlls I will need some time.
You can check also the media libraries I have written at GitHub. The TMedia one is written completely in Modelica, it is very fast and the main limitation is that it  works only below the critical temperature. The ExternalMedia uses external objets and functions in C, and implements cubic, PCSAFT and multiparameter EOS. Both of them support liquid, gas and biphasic states, although transport properties are only calculated for monophasic ones.

Hi Adrian,
Really you have been very fast bringing the solution. I have discharged and tried  version 1.16.5 and it is working correctly. With the file1.17.0-dev.beta2-64bit.exe I have received the following message when trying to install: "Installer integrity check failed...". I had checked the md5sum and was OK, and I have repeated the discharge with the same problem.

Regards

Sorry I can help too  much, but I would not worry about the violations of  limits along initialization. As the connection between elements is done using enthalpy, and not temperature, the port_a_T and port_b_T values are only informative in this case. As they are calculated from state_a and state_b, its initialization will come from pressure, enthalpy and composition at the ports, but it is difficult to follow the origin. The easy way is to change your difinition of Temperature in the Medium to: Temperature(start = T_default, min=0.0). Of course you solve nothing with this, only not to have warning, but the fact is that there is nothing to solve.
For the initialization of X[2] at -500 at the valve and the pump (interesting that not at your tank) I do not see the reason.

Thank you very much, Adrian.

I have been testing the versions  1.16.4 and 1.17.0.dev-beta1 64 bits in Windows, and I'm not able to graphically edit with OMEdit. First I thought that it was a problem with my library, but I have tried also with the MSL and, for example, I can't edit the example in Modelica/Fluid/Examples/PumpingSystem. It opens (very slowly), but in the Diagraman View it is impossible to open, just to look at, any object. With the 1.17 version I have tried MSL 2.3.2 and 4.0.0. I have tried also to load the Modelica library as user library, and the result is always the same. No problem with version 1.16.2.  I am using Windows 10 with 16 Gb of RAM.
Any idea?

Feb-24-21 21:09:59
Category: Developer

Thanks for the reply.
As I will be still using MSL 3.2.3 for some months I have changed the Modelica version from default to 3.2.3. For me it is somewhat strange that the default is already MSL 4.0.0, if the full switch is planned for version 1.18.

Regards

Feb-23-21 17:45:03
Category: Developer

I discharged yesterday the last oficial release for Windows, labelled as version 16.4. After installation the install directory was 16.3 and the OMEdit told also that it was version 16.3. I think also that MSL was version 4.0, due to the incompatibilities I noticed. I have reinstalled version 16.2, but I would like to know if the last version is 16.3 or 16.4 and  if the change to MSL 4.0 is already done.
Thanks in advance

May-15-20 22:15:18
Div by zero error in simple heat flow model

Hi,

I receive no error when running your model. I am using OpenModelica 1.15-dev-48, 64 bits on Windows10.

Regards

The use is:

V=homotopy(normalCalculation,simplifiedCalculation);
This is an example from one of my programs:
LMTDcoil1 := homotopy((Coil1.Tb - Coil1.Ta) / log((T - Coil1.Ta) / (T - Coil1.Tb)), T - Coil1.Ta);

I observe that I have always used homotopy in the algorithm section, but I think that it doesn't matter.


Carlos

Hi,
I would say that you are thinking as if you were using a sequential language. In the equation section I do not see how to use a while loop. I think it is only for the algorithm section, but also there I do not see clearly how to program in this way. I would use something similar to this:

model Integration
  Real power;
  Real energy;
equation
  power=sin(2*Modelica.Constants.pi*time) "just to have possitive and negative values for power";
  if power>0 then
    der(energy)=power "here we are integrating only possitive power";
  else
    der(energy)=0;
  end if;
end Integration;

Carlos

Do not worry, this type of problems happen to all of us from time to time. At the beginnings I was also surprised by the result.

Regards

Carlos

May-12-20 09:46:43
Application of VehicleInterfaces in OMEdit

I’m afraid that you are entering in a difficult task, due to OpenModelica, but also to Modelica characteristics.
Regarding OpenModelica, there is no popup menu from which to select compatible models. It is a feature highly expected and that I think will be provided in the next version. I have never worked with Dymola but I think this is not the case there. In OMEdit you need to manually edit your model and change the desired part. For example if you want to change the engine to VehicleInterfaces.Engines.MinimalEngine you could write a new model redeclaring the engine like:

model VehicleTest
  extends VehicleInterfaces.Examples.ConventionalManualVehicle (redeclare VehicleInterfaces.Engines.MinimalEngine engine);
end VehicleTest;

But, after this, you will find that this is not correctly working due to the second OMEdit limitation. If you try to edit graphically the engine, you will be editing the original definition of the engine, not the new one. This can be also solved with some work. You copy in your package the original model. First run it. Probably you need to write the full path of the referenced models because, as you are out of the original package, the package reference can be missing at the beginning of the name. Now that you have a runable model you can edit the model and change the declaration of the engine to  VehicleInterfaces.Engines.MinimalEngine
When I tried to run the modified model I got the message that 1 equation was missing. Here begin the Modelica problems. Modelica packages can be prepared in a way that you just change an object definition by a compatible one, edit some parameters and every thing is fine. This is not the normal situation that I’m finding, many times additional modifications are needed and, in order to know what to do, you need an in depth knowledge of the package and of Modelica language. Perhaps this is not the case with the VehicleInterfaces package, I do not know.
I would recommend you to expend some time learning the Modelica language before to play with dedicated libraries.
I attach the tests I did.

Regards

Carlos
ModelicaTest19.mo

If the function goes from 0 to 1 in 0.25, the average derivative is 4. If the function is a sinus, the maximum derivative will be 2*pi, because the function displayed would be  y[1]=sin(2*pi*time), so the result seems not so bad.

Well, I told you not to do reals operations with complex numbers. As stated in Modelica 3.4 specification (3.7.2), the time derivative operator der() works on reals and reals arrays, giving as output a real or a real array. A possible workaround can be something like this:

model ComplexDerivative
  Complex c;
  Real r[2](start={2,2});
equation
  r[1]=c.re;
  r[2]=c.im;
  der(r)={2,3};
end ComplexDerivative;

Where the start and derivative values can be a more sophisticated expression.


Hi,

I have just installed OpenModelica version 1.15.0-dev-48 64 bits for Windows, and I am having trouble with the edition of the models with OMEdit, the edition is disabled. I have created new models that I can edit but, when I save then and unload the library, become non editable after a reload.
No problem with edition if I add the library to the startup download list. Am I missing something?

Carlos

Hi,

In Modelica you need to define the type of the variables. If your variable can take complex values it is a Complex, in the same way a variable than can get integer and fractional values is a Real, not an Integer.
Of course you can't do real operations using complex numbers, but I understand that you can always define a Real and make it equal to the real part of your complex number, and play later with this real. Or use directly the real part of your complex number in the needed operations.

Hi,
I see that the intensity is pulsing with a period of 500 seconds. Of course you need to simulate for more than 500 seconds in order to see it. Here you have a test:

model battery2
  Real II1C;
  Modelica.Blocks.Sources.Pulse signalSource(amplitude = 10, period = 500, width = 50)  annotation(
    Placement(visible = true, transformation(origin = {-56, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  II1C=signalSource.y;
annotation(
    experiment(StartTime = 0, StopTime = 2000, Tolerance = 1e-6, Interval = 4));
end battery2;

Modelica.Blocks.Sources.Pulse is extending Modelica.Blocks.Interfaces.SignalSource, that is itself an extension of Modelica.Blocks.Interfaces.SO, where y is defined as a RealOutput. So y is the output of the block calculation, and inside Modelica.Blocks.Sources.Pulse is coded how this output is calculated as function of time and the configurable parameters.

Carlos

i do not why = was replaced by  current/sad  along copy paste

I hope this can help:

function equation_2nd
  input Real a;
  input Real b;
  input Real c;
  output Real x1;
  output Real x2;
  output Real x0;
  output Complex c1;
  output Complex c2;
protected
  Real d;
algorithm
  d:=b^2-4*a*c;
  if d>0 then
    x1:current/sad-b-sqrt(d))/(2*a);
    x2:current/sad-b+sqrt(d))/(2*a);
  elseif d==0 then
    x0:=-b/(2*a);
  else
    c1:=Complex((-b/(2*a)),(sqrt(-d)/(2*a)));
    c2:=Complex((-b/(2*a)),-(sqrt(-d)/(2*a)));
  end if;
end equation_2nd;

Regards

Carlos

Hi Gabri,
You are importing Modelica.Electrical.Analog.Sources.PulseCurrent. OK you can create now an instance of the model writing for example:
PulseCurrent pulseCurrent;
But what you are doing is defining a Real variable: Real II1C. At the same time you are giving value to this variable by using the = sign. After this sign you could write a numerical value, but you write an expression. This expression should supply the numerical value, but it is not the case. The expression is not a function giving as output a Real value, but a complex model.

I suppose you are looking for something like this:

model battery2
  Real II1C;
  Modelica.Blocks.Sources.Pulse signalSource(amplitude = 10, period = 500, width = 50)  annotation(
    Placement(visible = true, transformation(origin = {-56, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  II1C=signalSource.y;
end battery2;

Why Have I changed the Modelica.Electrical.Analog.Sources.PulseCurrent model by Modelica.Blocks.Sources.Pulse?
It is because your original model is too complex, as it has two pins with its voltage and intensity, and it seems that the only need is to generate a pulse to apply to the intensity.

Regards

Carlos

Mar-18-20 21:11:16
I am newbie to Modelica and having difficulties to create a new medium

Hi Chris,

It seems an OpenModelica fault. I received no error message, but I am using the old frontend by default. When I switched to the new frontend the message appeared. The selected medium should be able to calculate the saturation states at 283 K,  nevertheless I changed the medium to StandardWater, that in fact is WaterIF97_ph, and the problem disappeared also with the new frontend.
Just one question, Why do you make two copies of the Refrigerant package (Gen_H2O and Abs_H2O) instead of using it directly. It seems also better to use Refrigerant.SaturationProperties instead of Modelica.Media.Interfaces.Types.SaturationProperties.
Regarding your media definition, I have not had enough time to review it, but I will try to do it in the next days.

Regards

Carlos

Mar-05-20 16:25:40
Error while initializing

Hi,

I'm not used to Modelica.Fluid but, as far as I know, you should use a PrescribedPump, and redeclare the function flowCharacteristic as the function you want to use to correlate head with flow. You can look at how it is done in Examples.PumpingSystem.

Mar-05-20 15:52:46
Error while initializing

Hi Malik,
I think that the model is far from what is needed. You need to specify the number of ports for tank2, as you did for tank1. The tanks cross area must be also fixed.  use_portsData should be made false in order not to need to specify its size and location. You should use the ControlledPump model instead of the Pump model, in order to easily specify the pump flow. I attach your model and a modified one to compare.

ModelicaTest14.mo


Regards

Hi Lluc,
I think that, without an example of your problem, it is almost impossible to give you any oppinion.

Regards

Mar-03-20 16:18:22
Simple tank and pump system: initialization issues

Hi Anki,
Perhaps you are mixing things. If you just want a more flexible calculation for Valv1.opening, you can just write an equation with its calculation. If what you want is to connect your model with another model that will supply the value for Valve1, the construction is almost OK, but better you drag the RealInput to your model with OMEdit. It will create, in the Icon view, an icon to which you can later connect a RealOutput. Now you can create a new model, drag your first model into it, drag also a model with a RealOutput and its calculation and connect them.

Regards

Carlos

Mar-02-20 13:19:07
Does Modelica have a difficult learning curve?

Well they are just changing now from the old frontend to the new, that is much faster in translation. But, till now, it seems more limited than the old one. We need to wait for its improvement.

Mar-02-20 12:49:04
Does Modelica have a difficult learning curve?

Hi,
I'm getting similar errors when using the new frontend, but no error with the old, that is the one I am using by default.
Could you try to go to Simulation Setup, Translation flags, and activate the check box Enable old frontend for code generation?

Mar-02-20 11:58:19
Does Modelica have a difficult learning curve?

It seems strange, because I am getting no error with your model, just a traslation warning.
Which soft are you using?

Mar-02-20 09:13:55
Simple tank and pump system: initialization issues

Hi,
Yes your model was working till k=0.32. I am using OpenModelica 1.14.1 64 bits on Windows 10.
I attach a file with two models, the first is just your model with the constant k changed to 0.32. The second is the one I made in order to be able to edit the parameters with the GUI. In this one I changed the flow to 1 kg/s and the operating point of the valve.

ModelicaTest12.mo

Regards

Mar-01-20 19:18:53
Simple tank and pump system: initialization issues

Hi,
The problem you are having when going with the valve aperture lower than 0.32 is not a model problem, but a working conditions problem. At aperture of k=0.32, the pressure at valve outlet is just 48.4 mbars. If you close more the valve, you are vaporizing the water, and this is the reported error.
Some other comments are:
A declaration of:
inner Modelica.Fluid.System system;
Is missing in the model, this is the reason of the traslation warnings.
The flow is also very very low (0.0001 kg/s) for the 70 mm. pipe, but it seems that there is no problem.
If you are using OMEdit, better drag the elements to use from the librarries browser, you will be able to edit them graphically.

Regards

Feb-28-20 15:00:03
I am newbie to Modelica and having difficulties to create a new medium

Hi Christian,
As far as I know there is no book that could be a reference for the modeling of media, or mass transfer with Modelica. I found interesting, although now it is quite old, this dissertation from C.C.Richter link.
For me there are three main fields: fluid properties calculation, fluid flow and heat transfer, and mass transfer.
Regarding properties calculation, the Media library from the Modelica standard library is quite adequate, although there are not models for multicomponent, multiphase, mediums. The examples that come with the library, mainly for water and air are good, but quite complex. When you want to work with other fluids you do not find too much to choose, at least open source. There is the External Media library, that allows to link with CoolProp or ReefProp, but as far as I know it is almost impossible to make it work with Open Modelica. There is also the system library HelmholtzMedia, but it is not easy to extend an it is also not working. So I decided to make my own libraries, that you can find here. The more flexible one is using external functions and objects and therefore is not supported by the new frontend of Open Modelica (necessary to wait for its implementation in version 2.0), but yes by the old frontend.
Regarding fluid flow and heat transfer, I think that the Fluid library implemented in Modelica is too complex to be useful, and I see that there is much more people sharing this oppinion. I come from the engineering field where "keep it simple" is a must. I am polishing the library that I have used along some years in order to publish it as open source.
Regarding mass transfer, I understand that the first necessary step is to have a multicomponent, multiphase media definition, but there is nothing here for now. Work for the future.

Cheers

Carlos

Feb-28-20 12:47:49
Modeling of an anti-fall valve

Hi,
I don't find the phrase "extend a component" in my text. I supose you are speaking about the general concept of extension: it is how inheritance is done in Modelica, when you extend a previous model you inherit all declarations, algorithms and equations from it. I would recommend you to look at this web, I think it is the best internet resource for learning Modelica.

Regards

Feb-27-20 19:46:57
I am newbie to Modelica and having difficulties to create a new medium

Hi Christian,

Thank you very much for the information. In fact I didn't take enough care. With the solution I proposed the model compiles and runs on OpenModelica 1.14.1 on Windows, but I didn't look at the Simulation Output window, it is telling that after a successful initialization the simulation terminated by an assert at time 0.00038.
This is different from what you are experiencing. Normally after initial convergence you have no problems. I have written several media packages, and what you tell is completely right: having good reference and default values for pressure, temperature and enthalpy is of great importance for convergence. I normally do not specify smoothOrder, but I know it is a help for the solver.

Regards

Carlos

Feb-27-20 16:02:32
Modeling of an anti-fall valve

Hi,
I reviewed the model, of course it was impossible to know that you were using OpenHydraulics library before reading the code. I didn't know about this library but I have discharged it to test the model.
I think that there are several missunderstandings about how to use the library and connectors.
Regarding the library, the components you are using are extending the model Interfaces.PartialFluidComponent that, in order to supply the media you are going to use and ambient pressure and temperature,  references two outer models: oil and environment. These outer components are supplied by the Interfaces.PartialFluidCircuit model. So, the model that will containt your components should extend  Interfaces.PartialFluidCircuit. When extending you can change the media to the desired one.
Regarding connectors: You connect your components between them and finally you connect to an in port, and to an out port. But as you have two free ports  two equations are missing. This approach is OK if you are going to use your model as a component in connection with other components, but is not correct if you want to run this model as standalone. You need to supply two pressures, or a pressure and flow. If not, how the flow will be calculated?
The last point is regarding the equation you wrote for the realExpression, it seems that it will produce chattering, but I have not looked well to this.
I attach a working code using two tanks at the ends.

model Clapet_Anti_Chute_Debit_OK2
  extends OpenHydraulics.Interfaces.PartialFluidCircuit;
  parameter Real Tarage = 60 "Tarage du clapet (L/min)" annotation(
    Dialog(tab = "Sizing"));
  OpenHydraulics.Basic.OpenTank tank(p_const = 1e6) annotation(
    Placement(visible = true, transformation(extent = {{-58, -36}, {-38, -16}}, rotation = 0)));
  OpenHydraulics.Basic.OpenTank tank1 annotation(
    Placement(transformation(extent = {{50, -40}, {70, -20}}, rotation = 0)));
  OpenHydraulics.Basic.VariableRestriction variableRestriction annotation(
    Placement(transformation(extent = {{20, 10}, {40, 30}}, rotation = 0)));
  OpenHydraulics.Components.Sensors.FlowSensor flowSensor annotation(
    Placement(visible = true, transformation(extent = {{-48, 10}, {-28, 30}}, rotation = 0)));

  Modelica.Blocks.Sources.RealExpression realExpression(y=if ((Tarage*(1/60000))
         < (flowSensor.y)) then 0 else 1)  annotation(
    Placement(visible = true, transformation(origin = {6, -50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(variableRestriction.port_b, tank1.port) annotation(
    Line(points = {{40, 20}, {60, 20}, {60, -20}}, color = {255, 0, 0}));
  connect(realExpression.y, variableRestriction.control) annotation(
    Line(points = {{18, -50}, {30, -50}, {30, 12}, {30, 12}}, color = {0, 0, 127}));
  connect(flowSensor.port_b, variableRestriction.port_a) annotation(
    Line(points = {{-28, 20}, {20, 20}, {20, 20}, {20, 20}}, color = {255, 0, 0}));
  connect(tank.port, flowSensor.port_a) annotation(
    Line(points = {{-48, -16}, {-48, 20}}, color = {255, 0, 0}));
  annotation(
    Diagram(graphics),
    experiment(StopTime = 5),
    experimentSetupOutput);
end Clapet_Anti_Chute_Debit_OK2;

Regards

Carlos

Feb-27-20 11:30:04
Modeling of an anti-fall valve

Is it possible for you to copy and paste, as text, the model inside your answer?

Feb-27-20 09:38:51
Modeling of an anti-fall valve

Could you attach the complete model you are testing? With so little information it is very difficult to know what gone wrong.

Feb-25-20 14:54:20
I am newbie to Modelica and having difficulties to create a new medium

Hi Chris,

The origin of the problem is in the setState_pTX function. In OpenModelica the information message is telling that there are duplicate elements not identical. You are extending the original function and you are redeclaring the input and output variables. If you redeclare the function without extension, or you take out the redeclaration of variables, the problem is solved. For example:
  redeclare function extends setState_pTX "Return thermodynamic state as function of p, T and composition X or Xi" extends Modelica.Icons.Function;
    algorithm
      state := ThermodynamicState(p = p, T = T, X = X);
    annotation(
      Inline = true);
  end setState_pTX;

It is strange that if you change the test to PartialTestModel2, that is an extension of the one you are using, there is no problem with your original code. I would think that there is no problem with your code, but with the tool.

Carlos

Feb-18-20 15:21:46
What is the proper partial model to be used for modeling a four-port stratified heat storage...

Hi Amir,

As I already told you I am not used to this soft. It seems that the EnhancedStratified model introduces a better calculation of the segments temperature using a ThirdOrderStratifier submodel that contains ports. These ports are connected to the already existing ports of the main model, as you can see in the equation section of the EnhancedStratified model. They have erased the fluPorVol ports that gave access to the different segments, I supose that because of a good reason. So It seems that you have to choose between a simpler model, with the possibilitys of geting  liquid from different segments or a more sofisticated model but without this possibility. Perhaps you can try to extend the EnhancedStratified model and add the fluPorVol ports with the corresponding connections, if you are lucky it could work.

Regards

Feb-17-20 11:32:23
What is the proper partial model to be used for modeling a four-port stratified heat storage...

What I see is that port_b, at bottom, is the expected inlet, and port_a at top is the expected outlet. You can connect to those ports as many pipes as you want. The connections to port_b should supply flow, that can be of course at different rate and temperature. The connections to port_a should take flow that can be at different rate but, of course, the flow that are taking are at the enthalpy (so also temperature) of port_a. If you need liquid at different temperature you can't take it from the top of the tank, you need to take from an intermediate level, and this seems the rol of fluPortVol port. I would think that it should be interesting for you to read some documentation regarding the use of connectors, that you can find here  and here

Regards

Carlos

Feb-17-20 10:16:33
What is the proper partial model to be used for modeling a four-port stratified heat storage...

Hi Amin,
I have never worked with the Buildings library, but I made a look to your question. I understand that you are speaking about the fluid ports port_a and port_b, that are connected to the bottom and top of the stratified storage. My first question is, Why do you want to duplicate those ports?. You can connect more than one pipe directly to them. In plus it seems possible to enter or withdrawn liquid from any of the stratified zone trough the fluPorVol port.

Regards

Carlos

I would say that it is not exactly like this. In order a model to be runable it must contain the same number of variables than equations. You can make a model like this and it will run. The limitation is that you can play only with changing the value of the defined parameters. In order to make modeling more flexible you can leave missing equations, normally declaring the model as partial, but the normal way is to define models that are prepared to run in combination with other models.
This is done normally using connectors. The more frequent connector contains one potential variable and one flow variable, and one hiden equation that makes the flow variable equal to 0. You define in your model the internal variables you need and the same number of equations than variables, so your model is internally complete. Then you add the connectors. If you use a connector like the one described, one equation is missing in your model, the value of the potential variable of the connector. After this, you can let the model like this (one equation missing), add an equation for the connector variables(complete), or add two equations for the connector variables(overspecified because the flow variable has two equations, the one that makes it equal to 0 and the one you added). When you make the connections, the overspecified models will compensate the underspecified models.
I'm not sure if this is the correct answer according to the Modelica language standard, but is the way I see this matter.

I think you are having a misunderstanding here. Models not always can be simulated directly. In this case the model is prepared for being connected with other models. You should run the model Buildings.Fluid.Storage.Examples.Stratified, where the object tanSim is an instantiation of the model you are trying to test. You can check the coverage of the Buildings library by OpenModelica here

Hi:
I’m are afraid I don’t understand well which is the problem. I see you are defining the pins as connectors with one potential variable (voltage) and one flow variable (intensity). In this situation there is no need to define the potential variable as input or output, although it can be done, and two pins should be connected with no problem. In fact I think that the flow variable can’t be defined as input or output, but I’m not sure.

I supose that there is a good reason for not using a solution as simple as a direct selection. For the GUI input, it is not possible to have the parameters defined at the base level of the model, but yes those defined in objects inside the model. So the solution is to crate a separate model with the parameters you need as inputs, create an instance inside your model, and make equal the value of the parameters, or use directly those inside the GUI. I would sugest something like this:

package Test_Selection
  model GUI
    parameter Modelica.SIunits.AbsolutePressure p;
    parameter Modelica.SIunits.Temperature T;
    parameter Modelica.SIunits.Enthalpy h;
    parameter Boolean useT=true;
annotation(
        Diagram,
        Icon(graphics = {Text(origin = {-5, -67}, extent = {{105, -23}, {-93, 11}}, textString = "Use p,T: %useT"), Text(origin = {-5, 77}, extent = {{105, -23}, {-93, 11}}, textString = "p: %p"), Text(origin = {-7, 27}, extent = {{105, -23}, {-93, 11}}, textString = "T: %T"), Text(origin = {-7, -21}, extent = {{105, -23}, {-93, 11}}, textString = "h: %h")}));
  end GUI;
 
  model SelectModel2
    package Medium = Modelica.Media.R134a.R134a_ph;
    parameter Modelica.SIunits.AbsolutePressure p=gui.p;
    parameter Modelica.SIunits.Temperature T=gui.T;
    parameter Modelica.SIunits.Enthalpy h=gui.h;
    parameter Boolean useT=gui.useT "if made false enthalpy will be used";
    Medium.ThermodynamicState state;
    FreeFluids.Various.Test_Selection.GUI gui(T = 223.15, h = 1e5, p = 500000, useT = false)  annotation(
        Placement(visible = true, transformation(origin = {1, 1}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
  equation
    if useT then
      state=Medium.setState_pTX(p,T);
    else
      state=Medium.setState_phX(p,h);
    end if;
  end SelectModel2;
end Test_Selection;

Hi Gabri,
I'm receiving no message, in the Message Browser, when runing the code with OpenModelica 1.14.1 on Windows 10. I think that the translation warning is only telling that y has no start value given, but as it is not needed no problem here.
I'm also receiving the same message in the output window. I'm sorry, but I can't give you any information here. Are messages that I get also from time to time, and that I think are related with the solver, and really I do not take care about this.

I attach the code with the annotation of the experiment and flags used:
model Pendolum
  parameter Real m = 1, g = 9.81, L = 0.5;
  Real F;
  Real x(start = 0.5, fixed = true), y;
  Real vx(start = 0, fixed = true), vy;
equation
  m * der(vx) = -x / L * F;
  m * der(vy) = (-y / L * F) - m * g;
  der(x) = vx;
  der(y) = vy;
  x ^ 2 + y ^ 2 = L ^ 2;
  annotation(
    experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002),
    __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian -d=initialization   ",
    __OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));
end Pendolum;

And good luck with Modelica, it is an amaizing tool !

Just after a very fast reading, please do not take it for completely sure:
The message is just telling that the program has taken fixed start values for two variables.
You can't give fixed start values for x and y, as they are related by the equation: x^2+y^2=L^2 and L is fixed, the value of one of them forces the other. So the correct way is:
Real x(start=0.5, fixed=true),  y;
The same is valid for vx and vy, but take into account that at x=-0.5 or x=0.5, the only valid value for vx is 0. So in this case:
Real vx(start=0, fixed=true), vy;
If you want other start values for vx it should be with other values of x.

Jan-17-20 18:47:05
Category: Programming

The initial algorithm or equation are used to improve convergence. Here there is no convergence problem, so I do not think that any initialization is needed.
You are declaring: parameter Integer Res(min = 1, start = 10, fixed = true); the normal way of declaring parameters is just:  parameter Integer Res=10; The use of start is normally for giving a warning that you are using a default value.
You explain that the input and output are boolean values (0 or 1). Why do you use an array of DigitalSignal, that is an enumeration, so integers, and not an array of Modelica.Blocks.Interfaces.BooleanInput, and Output?
You can't use when in the way you do. The when statement is used for changing tha value only when a condition is met, otherwise it remains in the same value, and it can't be used inside loops or if statement, as OpenModelica is telling in the message browser. Change it for if statements.

Jan-16-20 22:48:24
I want write a block,which generate a vector with logic value.But compiler say, The given system...
Category: Programming

The problem is caused by the initial algorithm, although I see nothing wrong there. Do you really need this initial algorithm?
There is also a problem with the dimension of the out variable, it is Stufe, but Stufe is not declared at all. I have used max(Step, Anzahl).
It is also necessary to give the value of out between Step and Anzahl when Anzahl>Step (as you have done when Anzahl<=Step).

If this can be of any help, I am using external C functions with no problem in OpenModelica. Really not exactly with no problems as the new frontend doesn't support external functions yet, and I need to use the old one. I use the method recommended at Modelica by Example web site: no header file necessary. Here is an example:

function densitiesEOS_pT "Return liquid and gas densities at give temperature and pressure, by EOS"
  input AbsolutePressure p;
  input Temperature T;
  input Integer phase = 0 "0=both phases, 1= only gas, 2=only liquid";
  output Density ld;
  output Density gd;

  external "C" FF_densitiesEOS_pT(data, p, T, phase, ld, gd) annotation(
    IncludeDirectory = "modelica://FreeFluids/Resources",
    Include = "#include \"FFmodelicaMedium.c\"");
end densitiesEOS_pT;

Jan-15-20 08:11:30
Resting Time to Zero at a Switching Voltage

OK

A virtual beer coming!

Good luck!

Jan-14-20 20:35:26
Resting Time to Zero at a Switching Voltage

Well; I have prapared a possible solution. The determination of the event to restart the timer is done by a pulse generator (you can change this as needed). I have used connectors, and yes the problem was due to the fact that it is not allowed to connect connectors at the outer (main model) level. I have changed the switch rate, because it has no sense to switch at a speed much faster than the interval of the simulation.

ModelicaTest9.mo

Jan-14-20 20:05:24
Category: Developer

It seems clear what I was doing wrong. Modelica specification (chapter 9.3) doesn't allow the connection of two outer connectors.

Jan-14-20 19:35:58
Resting Time to Zero at a Switching Voltage

Just one sugestion. If you tell me with which condition you want to reinitialize the timer, i will send you a possible implementation.

Jan-14-20 19:33:17
Resting Time to Zero at a Switching Voltage

I understand that you need LTime as a Real, as you are using it for controlling the time. The declaration is immediate:
Modelica.SIunits.Time LTime;
I do not understand why you build types that are already defined in Modelica.
If you declare LTime as boolean, using
Boolean LTime;
It will be impossible to use it for time control.

Jan-14-20 17:49:04
Resting Time to Zero at a Switching Voltage

It seems clear that you need to give value to u in some way. You can declare it just as a Boolean, and to determine its value inside your model.
for example:
  if LTime>0.2 then
    u=true;
  else
    u=false;
  end if;
This will produce LTime to reinitialize every 0.2 seconds. Although here it is easier to put the condition inside the when statement and no need for u.

I think that another possibility should be to declare u as:

Modelica.Blocks.Interfaces.BooleanInput u;

In this way u becomes a connector, and you should be able to connect it with a BooleanOutput connector,  for example with a BooleanPulse, as the one you are already using in the switch. But I have tested this and the old frontend tells me that I am connecting two signal sources, and really I can't understand this. Probably is due to the fact that the BooleanInput should be inside a model part, not directly in the model.

Jan-14-20 10:17:29
Resting Time to Zero at a Switching Voltage

Sorry, but I can't help too much. I would say that in order to reset LTime every time that u is true you need some thing as this in the equation section:
 
LTime = time-entryTime;
  when u then
    entryTime = time;
  end when;

But I do not know how do you determine that u is true. It is also strange for me to see LTime and u with the input qualifier as this is not a function or a connector.

For the open-source users,
I have just updated the FreeFluidsModelica library. It now includes media based on equations of state, so capable for working both below and over the critical temperature.
The media is implemented using an external object for the substances data, and external functions for calculation. Therefore, it is not compatible with the new frontend of OpenModelica, that doesn’t implement external functions yet, but it is compatible with the old frontend. It has been tested with OpenModelica 1.14.1 on Windows. I expect, but I am not sure, compatibility with Linux platform also.
The media uses multiparameter (Seltzmann and Wagner type) equations of state (EOS), and also PCSAFT and cubic type ones. You can switch between them and compare the obtained results if you want. The quality of the thermodynamic calculations depend on the used EOS, being very high if multiparameter type is used. Compared with other applications like CoolProp, the calculation very close to the critical point is weak, as no special technique, as for example cubic splines, is used. The calculation of transport properties is also done using phase specific correlations with pressure correction, instead of multiphase temperature-density dependent functions. On the positive side, it is very easy to use, and you have PCSAFT and cubic EOS for the products for which no reference equation of state is available. You will find several tests inside the packages.
You can download it here

Jan-04-20 20:00:53
Category: Developer

I do not know if I am doing something wrong. I think that the following simple model should run with no  problem, but OpenModelica  is telling me that there are 4 variables(correct) and 6 equations(wrong). It seems that the equations that make the flow variables equal to 0 remain after the connection, instead of being replaced by the sum of flows equal to zero.
I attach the model. I am using OpenModelica 1.14.1 on Windows 10.

ModelicaTest8.mo


Carlos

Jan-02-20 14:53:59
Is there any way to set travel time (open/close) on fluid valves in Modelica?

Well, it seems as if it was there, at least for opening. In the definition of partial model PartialValve, there is the parameter filteredOpening and riseTime, the last defined as the time to arrive to 99.6% opening. What I see is that this partial model is used only in the models ValveIncompressible, ValveVaporizing, and Valvecompressible, but not in ValveLinerar or ValveDiscrete. The ValveIncompressible model is used in the Examples.IncompressibleFluidNetwork, so perhaps you can check its action there. 

While testing some Media libraries I observed a problem, that I do not know if is due to OpenModelica or to ThermoPower. The problem is shown in the attached file, and is the following:
If I extend the ThermoPower model TestWaterFlow1DFV_A (from the Test.DistributedParameterComponets package), redeclaring the Medium, the model runs with no error, but makes no calculation, as is shown in the variable T_out.T. If I copy the model and change the Medium declaration directly, the model runs and the calculation is OK. I observe also that the simulation time for the extended model is shorter than for the copied one.

ModelicaTest7.mo

I think thet the problem is normally related to the fact of assigning to a parameter some value derived from a variable. The parameter is fixed along the simulation, so it can't depend on the value of a variable, that will change along the simulation. I would think that Va is a variable, and that you are making the parameter Vc to be calculated from it..

I'm afraid I 'm posting too much these days, but I will try to answer.
The first answer is not. What I see in Modelica.Thermal.Media is a record named MineralOil, not a package extending Modelica.Media.Interfaces.PartialMedium, that is what is needed as medium for the Fluid library.
After this, yes, probably it is possible to build a valid medium package from the data in the MineralOil record. I see that it is a very simple medium, with constant properties for density, specific heats, thermal conductivity and kinematic viscosity. The closest package in the Media library I think that is the TableBased one. In Modelica.Media.Incompressible.Examples there is tha package named Essotherm650 that probably is already good for your tests. If it is not, I would copy this package in myr work, rename it and put the same values at all temperatures. Taking into account that in the record the viscosity is kinematic and in the package  dynamic.
I have not tested it, but I hope that the BasicHX model is compatible with any package derived from partialMedium.

Dec-17-19 13:08:09
Variable value with initial guess value, use of N iterations to match guess value with calculated...
Category: Programming

With two equations, plus the equation relating LMTD with the temperatures, you can solve three variables, the others should be known by other ways. I understand that you know U,A,Tc and T_in, mdot, and Cp, so the solution should be immediate. Why the iterations? The Modelica solver will take care of founding the solution. The only possible problem I see is with the LMTD that some times goes to indefined mathematical operations. This can be solved by specifying altenative calculations when, for example, inlet and outlet temperature are the same.

Happy about this  current/smile . Now take into account that OpenModelica 1.14 is not too stable, but I am sure they will improve this in a very short time.

All right. I downloaded every thing as you have done and it works on my computer. I have reviewed the error report and seems that the problem begin with the redeclaration of a no redeclarable record, that I do in the FreeFluids library. This makes me think that you are using Modelica 3.2.2 standard library, where the PartialTwoPhaseMedium has the FluidConstants record as not replaceable. This was change in Modelica 3.2.3 and now is replaceable.
Can you check this?

Quite strange. I will try with the same files than you. I will download FreeFluids from Github, not the one I have in my computer.
Are you using OpenModelica 1.14?
I will tell you the result.

From the annotations I see you are using Dymola. At the end I have been successful with your model, not using the AixLib, but using my own library. It is open source and you can download it from here
I attach your original model and a modification where I changed the Medium reference and I returned to the use of Cfnom.
Just to tell you how tricky is the enthalpy issue, I started extending the  CO2 package using “User” reference for enthalpy at 100K. It run, but stopped before arriving to 1e6 seconds. It was due to the fact that the gas was going down 200K that is the limit of its media model. I changed the reference to 120K for CO2 and the problem was solved. The reason is when you are specifying 250e3 for the liquid inlet, you are giving a number that is referenced to the base enthalpy.
The problem has been interesting for me, as I decided to check the compatibility of my library with ThermoPower and solve the remaining problems.

ModelicaTest5a.mo

Dec-15-19 20:02:18
Category: Developer

Well, I think I have found the origin of the problem. The medium is giving negative values for  isothermal compressibility, when they should be possitive. Reviewing the code it seems that a term is missing inside the brackets of the kappa calculation.
I hope not to be wrong and that this can help.

Dec-14-19 19:53:10
Category: Developer

While checking my media models compatibility against ThermoPower, I observed a too high difference in the results obtained in the TestRefrigeranEvaporator test model, using the standard Modelica.Media.R134a.R134a_ph medium and my own medium. I arrived to the conclusion that it was due to the physical properties calculation and checked it. The result I obtain with the Modelica medium seems incorrect regarding density, as you can check with the attached model. The calculation done at 25ºC and 30 bars gives a liquid density result much lower than the saturated one, what seems very strange. I checked the calculation with CoolProp and it seems that the Modelica calculation is erroneous. The calculation at 25ºC is OK till 18 bars.
Can someone check this?

ModelicaTest5.mo

Hi,

May I know wich Modelica Simulation Environment are you using?
I have tried with OpenModelica 1.14 with not too much luck. The original model from ThermoPower runs in the old frontend but very slowly (it doesn't run in the new frontend). Your model fail seems related with inapropiate values for enthalpy.(when using Media packages it is a common problem, as proper start values are needed).  When I replaced in your model the Medium by the original Modelica.Media.R134a.R134a_ph I got the message fluidFlow.Kfnom=0, violating the assertion that must be over 0. After reviewing I see you changed the fluidFlow flow model from Cfnom to Kfnom without giving value to Kfnom. I see also that you changed the air temperature inlet to a quite low temperature.
Disortously it has been impossible for me to open the AixLib to examine the Media model (OpenModelica hangs). What I would try to do first is to be sure that the enthalpies in the liquid part are adequate for the temperatures in the gas part. This can be done by first checking which is the enthalpy reported by the Medium at your desired temperature. Probably it can be done also by specifying temperature in the liquid part, instead of enthalpy, but  I am not sure as I am not too familiar with ThermoPower library. And to correct the Kfnom problem.

Carlos

Hi:

ModelicaTests3.mo

I finished the review and I found the following issues:
There is a miss-understanding about how stream variables work. When you use port_a.h_outflow you are taking the value of h at the port when the flow is going out of the port. But you are using the port as an inlet, so you need to retrieve the value of h for the inlet flow using the function inStream. So the enthalpy variation must be written as:
port_b.h_outflow = inStream(port_a.h_outflow) + (Q/port_a.m_flow);
It is the same for the others stream variables, and for any reference at the value of the variables when the flow is coming in.
The second point is referenced to the lack of equations. For each stream variable there are two associated values: the value when the flow is going in and the value when is going out. When you are connecting the ports ‘a’ to its boundaries, the out value of the boundary is going to the in value of your port, but the out value of your port remains unsolved. As you are using the port ‘a’ as an inlet, this value means nothing, but it is necessary. So, I added:
  port_a.h_outflow=inStream(port_a.h_outflow);
  port_a1.h_outflow=inStream(port_a1.h_outflow);
  port_a.Xi_outflow=inStream(port_a.Xi_outflow);

After doing this the model compiled but didn’t converge. Here there is a recurrent problem with the  medium usage. When you are coming from enthalpy and you need temperature, some mediums use a nonlinear solver type regula-falsi, but if the initial value of enthalpy is outside the expected bracket the solution is not found. It is quite difficult to know which enthalpy value must be assigned to the boundary because the enthalpy value depends also on the selected standard state reference. Normally refrigerants media use the ASHRAE reference (saturated liquid at -40ºC). You can test in a separate model the enthalpy that corresponds to your T and p. I have changed the boundary 2 enthalpy to 3.1e5.
You will find the find the working models as Condenser2 and Condenser_Test2 in the attached file.

Hi:

I have made a fast look to your code. I made a small change to your Condenser_Test model:

Condenser condenser1(redeclare package Medium_1=Medium_1, redeclare package Medium_2=Medium_2) annotation(
    Placement(visible = true, transformation(origin = {-2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

I think that perhaps the problem was in the incompatibility of the Mediums. Your are passing the Medium definition from the condenser to its ports, but you are not granting the same Medium for the boundaries and the condenser ports. In fact you are declaring SimpleAir inside the condenser and MoistAir at the boundary.
In the code is missing also  nPorts=1 for boundary5.
After making these changes I get that the model has 143 equations and 146 variables.
I will look further to your  code. I am developing some open source libraries for media definition,  fluid flow, and heat exchange and, although I do not like Modelica.Fluid too much (the stream approach complicates things in excess), I want to better check some applications with Modelica.Fluid.

Carlos

Nov-04-19 18:35:09
Category: Developer

Thanks, and yes it works. I didn’t expect that option were inside the scope and Options not, as both are at root level inside the same package.

Nov-04-19 14:57:17
Category: Developer

I’m not sure about if it is a bug or a normal behaviour, but it is affecting the use of at least the HelmholtzMedia package. When using a constant enumeration inside a package it is impossible, but only in certain circumstances, to change its value while inheriting. The problem is shown in the attached file: models EnumerationTest1 and EnumerationTest3 run, but not EnumerationTest2. The problem is that media models are normally used as in EnumerationTest2. The problem doesn’t appear if the definition of the enumeration is outside the package.

Oct-15-19 08:56:23
Category: Developer

Although it is not an OpenModelica related problem, I would like to share the following experience.
While checking my own media libraries compatible with Modelica.Media, I have found what I think is a bug in the Modelica.Media.R134a package. The calculation fail is shown in the attached file. Coming from a density between bubble and dew densities, it fails in the calculation of the vapor quality. The origin of the problem seems a bad implementation of the setState_dTX function: the calculation of Helmholtz derivatives and specific enthalpy is done before to check the phase fractions, as if the given density would be a one phase density. This produces a complete fail for calculations in the two phase region coming from density and temperature.
I do not know if this is a known bug, or I am wrong in some point.

I have just uploaded to Github a Modelica package containing three media definition. One for ideal gases, another for mixtures of ideal gases and the last covering the liquid and the saturated gas phases. You can find it at Title
The ideal gas models have been done as a personal exercise in order to better know Modelica.Media, nevertheless they allow for the use of many different ideal gas heat capacity correlations, extending the use to substances not covered by the Nasa Glenn coefficients.
The liquid/saturated gas model extends PartialTwoPhaseMedia and is based in the use of correlations for fast calculation. It has been developed using OpenModelica 1.13.2, so it is fully compatible. I have enterered data for a few substances, but my point of view is that Modelica files is not the best place to store data. So the data is in a relational database and can be exported in the Modelica format when needed. This is done using a program which Windows executable can be found at Title
I expect to extend the packages in the next future, and it would be good to joint efforts with other people interested.

Aug-20-19 21:24:07
How obtain a convergence at a certain value
Category: Programming

Well I would use something like this:
model CvO3
  parameter Real rho1 = 1000.0, p1 = 600.0, p2 = 200.0;
  parameter Real m_r = 1.2;
  Real Cv(start = 0.001), m;
  Real u1;
equation
  u1 = if time > 0.5 then 0.0 else 1.0;
  if u1 >= 1 then
    m = Cv * (2 * rho1 * (p1 - p2))^0.5;
    if (m - m_r > 0.001) then
      der(Cv) = -0.001;
    elseif (m - m_r < (-0.001)) then
      der(Cv) = 0.001;
    else
      der(Cv) = 0;
    end if;
  else
    m=0;
    der(Cv) = 0;
  end if;
end CvO3;
I have configured u1 as a time event, and the variables as parameters, for testing. Probably the use of noEvent is not necessary, and is slowing the simulation. My question regarding mainly p1 and p2 was due to the fact that when u1 becames 0, the equation becames: m=0 and breaks any connection between p1 and p2 (any value of p1 and p2 will fulfill the equation), so their value must be completely determined outside the exposed code. This beccomes clearer in my code, but is also applicable for yours. But if the code is working its means that there is no problem due to this point.

Aug-18-19 22:05:59
How obtain a convergence at a certain value
Category: Programming

Well, I'm not sure about the correctness of using der(Cv) inside when equations, at least OpenModelica 1.13.2 doesn't allow me. It seems easier to use:
  if u1 >= 1 then
    if noEvent(m - m_r > 0.001) then
      der(Cv) = -0.001;
    elseif noEvent(m - m_r < (-0.001)) then
      der(Cv) = 0.001;
    else
      der(Cv) = 0.0;
    end if;
  else
    der(Cv) = 0.0;
  end if;
The second point is about the variables. rho1, p1 and p2 are constant or parameters, or are they variables? And u1 is  Boolean, Integer or Real?

Aug-17-19 05:52:12
How obtain a convergence at a certain value
Category: Programming

Are you looking for some thing like the attached file?


Thank you again.
In fact there is no problem if you make the iteration manually, by indexing 1,2,...

Hi Adrian,
I installed v1.14.0-dev-26644, that solved the iteration over the array of records for the example given, but I am still having problem when the iteration is over an array of records that contains a Real array inside.
I attach the file. Test21 is OK, but not Test22. The new frontend gives the following error:

[1] 00:08:55 Translation Error
[CodegenCFunctions.tpl: 6583:13-6583:13]: Template error: ASUB non-scalar {{5.0, 50.0}, {10.0, 100.0}}[i]. The inner exp has type: Real[2, 2]. After ASUB it is still an array: Real[2].



The old frontend gives no error, but does a bad calculation.
Am I trying to do something forbidden by the Modelica language?

Carlos

Thank you very much. I will try.

Carlos

Hello,
I’m having a quite strange behaviour with OpenModelica while iterating on records. At the beginning I thought it was my fault, but I am receiving also bad calculations from models in Modelica.Media. Is it a known bug or is it my fault? I attach a file with one very simple example. Result is correct in Test1, but not in Test2 or Test3. I’m using OpenModelica 1.13.2 64 bits.
Someone one can help?

Thanks

Aug-02-19 21:11:36
Category: Programming

Hi,
I know nothing about the ThermoFluidPro library, so I will try to comment the code according to my knowledge of Modelica.Media.
I understand that you are selecting a monocomponent medium (isobutane) for a two phases application. If the library is fully compliant with Modelica PartialTwoPhaseMedia, the following comments could apply.
You have an array of states that you are creating from an array of pressures, and an array of temperatures . As you are not supplying composition, I understand that the medium has a fixed composition. My first point is a question. Does the array of pressures correspond to the saturated pressures of the array of temperatures?  My question is due to the name of the array of pressures, and to the fact that a state can´t be constructed by the setState_pTX function if the supplied values correspond to a saturated condition.
You are using the setState_pTX function to build the state. I would say that you should use setState_pT, as there is no specific composition to pass, but this should not be a problem, because if you do not specify the composition the function should use reference_X.
When recovering the thermal conductivity you are using  thermalConductivity_dTX, and passing density, temperature and composition of the previously created state. This seems to mean that composition is a variable inside the ThermodynamicState record. Why don’t you just use thermalConductivity(state[N]). In the way you do, if it works, you will normally create a new state just for the calculation of the thermal conductivity.

Carlos

  • Index
  • » Users
  • » CTG
  • » Profile
You are here: