- Index
- » Users
- » Czzzzz
- » Profile
Posts
Posts
Hallo everyone
I am now using CoolProp from ExternalMedia for the fluid property calculation. for single substance such as CO2 it works well.
But now I need to use humid air. I am confused, because I don't know how to call the Humid air in Modelica.
for CO2 I just need to define:
package CO2CoolProp "CoolProp model of CO2"
extends ExternalMedia.Media.CoolPropMedium(mediumName = "CarbonDioxide", substanceNames = {"CO2|debug=0|calc_transport=1"}, ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph);
end CO2CoolProp;
an it worked.
but when i do the same for humid air:
model HumidAirCoolProp
extends ExternalMedia.Media.CoolPropMedium(
mediumName = "HumidAir",
substanceNames = {"moist air"},
ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph);
end HumidAirCoolProp;
when the simulation runs, it tells me:
terminate called after throwing an instance of 'ValueError'
what(): Bad Fluid name [moist air] - not a CoolProp fluid
dose anyone know how to use the Humid air from Coolprop in OpenModelica
best regards
Hi everyone,
I now use Thermocycle together with externalmedia, wenn i do some caculation i get error.
when I go to the debugg mode, It usually show "torn", "residual" and "jacobian" in Equation-brower.
Could someone explain to me, what the meaning of this?
best regards
thanks very much.
Hello, i am a little bit confused by the for loop:
I try to connect two different component array using for loop, but it dosent work.
model Test
parameter Integer N = 2;
Modelica.Blocks.Sources.Constant const[N](each k = 273.15 + 100);
ThermoCycle.Components.HeatFlow.Sources.Source_T_cell source_T_cell[N]
equation
// it dose not work
for i in 1: N-1 loop
connect(const[N].y, source_T_cell[N].Temperature);
end for;
/* but the following works
connet(const.y, source_T_cell.Temperature);
*/
end Test;
can some one tell me, how to connet two differnt array of components in Modelica.
best regards
Hello,
I am reading Modelica Code from some Librarys. in the code there is always some norminal values. For example, in a model variable x is declared and the author then declare a parameter x_nom and claim it is the norminal value for x. I am not quite understand the thought behind this. Why should norminal value be defined?
thanks
Hello, every one
I try to do a optimization with OMOptim. I follow the instruction at page https://www.openmodelica.org/doc/OpenMo … tion.html.
But after I add my model in OMOptim (Problem->Optimization), a new form is displayed, but the variables are not.
according to the tutorial "If variables are not displayed, right click on model name in model hierarchy, and select Read variables." so i go to model hierachy and right click. but there is also no Option "select Read variables".
the vesion of OMOptim is the vesion with OMEdit 1.4.1 and my OS is windows 7. Is OMOptim is broken or there are some solutions?
best Regards
thanks, so is the model selection through GUI also not possible in 1.14?
as my first post, I want to creat a Model, which select submodel to be used via Boolean parameter. Is it also not possible?
I think that bei using ModelicaReference.Annotations.choices can do what i want, selecting model via the GUI. so I change my code.
according to the documentation, when annotation(choices(choice(redaclare bla bla))) be added to the code, there will be a selection list in the GUI. but it dosen't work.
could someone give me a example for how to use annotation.example? I tryed the example in https://build.openmodelica.org/Document … oices.html but it dosen't work either
------------------------------------------------------
model Model_P
package Medium = Modelica.Media.R134a.R134a_ph;
parameter Modelica.SIunits.AbsolutePressure p;
Medium.ThermodynamicState state;
equation
end Model_P;
model Model_PT
extends Test_Selection.Model_P;
parameter Modelica.SIunits.Temperature T;
equation
state = Medium.setState_pTX(p, T);
end Model_PT;
model Model_PH
extends Test_Selection.Model_P;
parameter Modelica.SIunits.Enthalpy h;
equation
state = Medium.setState_phX(p,h);
end Model_PH;
model selectModel
replaceable Model_PT model_final(p = p, T=secondInput) annotation(choices(
choice(redeclare Model_PH model_final(p=p, h= secondInput))));
parameter Modelica.SIunits.AbsolutePressure p;
parameter Real secondInput = 0;
end selectModel;
------------------------------------------------------------------------------------------------
Morning, everyone,
I have two very similar model. Model_PT calculat the thermodynamic state based on pressure and Temperature. Model_PH calculat the thermodynamic state based on pressure and enthalpy. so I want to write a model to unify them. In this model there is two boolen parameter called Use_T and Use_h. if Use_T = true, then model_PT will be used, if use_h = true, then model_PH is used.
but I didn't find a way to do it in openModelica.
Could some one give a hint?
Best Regards
Here is my code:
----------------------------------------------------------------------------------------------------------
package Test_Selection
model Model_PT
package Medium = Modelica.Media.R134a.R134a_ph;
parameter Modelica.SIunits.AbsolutePressure p;
parameter Modelica.SIunits.Temperature T;
Medium.ThermodynamicState state;
equation
state = Medium.setState_pTX(p, T);
end Model_PT;
model Model_PH
package Medium = Modelica.Media.R134a.R134a_ph;
parameter Modelica.SIunits.AbsolutePressure p;
parameter Modelica.SIunits.Enthalpy h;
Medium.ThermodynamicState state;
equation
state = Medium.setState_phX(p,h);
end Model_PH;
model selectModel
//selct model based on boolen Parameter
package Medium = Modelica.Media.R134a.R134a_ph;
parameter Modelica.SIunits.AbsolutePressure p;
parameter Boolean Use_T = false;
parameter Boolean Use_h = false;
parameter Real secondInput = 0;
Medium.ThermodynamicState state;
equation
if Use_T then
Model_PT model_PT(p = p, T = secondInput);
state = model_PT.state;
elseif Use_h then
Model_PH model_PH(p = p, h = secondInput);
state = model_PT.state;
end if;
end selectModel;
end Test_Selection;
----------------------------------------------------------------------------------
Thanks, it worked!
I add /bin/rm to my code, but it does not word. Here is my Code
-----------------------------------------------------------------------------------------
cd("C:\Users\USERNAME\Desktop\Modelica_Uebung\ParameterSweep\TestModels");
//loadFile("package.mo");
//loadFile("Model.mo");
getErrorString();
str_model := "RefrigerationCycle_Demo.Simple_Cycle_SL.Tests.Test_Cycle";
simulate(RefrigerationCycle_Demo.Simple_Cycle_SL.Tests.Test_Cycle);
//stringTypeName(str_model);
//simulate(stringTypeName(str_model));
getErrorString();
for p in {926901, 956901, 986901, 1036901, 1066901} loop
str_p := String(p);
getErrorString();
//str_cmd := str_model + ".exe -override a=" + str_a;
//print(str_cmd + "\n");
//getErrorString();
//system(str_cmd, "output.txt");
//system("RefrigerationCycle_Demo.Simple_Cycle_2.Tests.test_Cycle.exe -override RefrigerationCycle_Demo.Simple_Cycle_2.Tests.test_Cycle.simpleHeatExchanger_m_dot.p_ex=" + String(p) + " -r=Model_" + String(p) + "_res.mat");
system(str_model + ".exe -override Kondensator.p_ex=" + String(p) + " -r=Model_" + String(p) + "_res.mat");
getErrorString();
//res := readSimulationResult("Model_res.mat", x); getErrorString();
//results := results + str_a + "," + String(res[size(res, 1), size(res, 2)]) + ",\n";
//closeSimulationResultFile();
end for;
#!/bin/bash
rm *.o;
rm *.c;
rm *.h;
Hallo, every one,
now I use openmodelica Scripting in oder to simulate a Model with different Parameters. It worked. but during the simulation OM creats a lot of Intermediate Files, which is very in convienient. In OM Connection editor, in Tools->Option->Simulation there is a Option "delete intermediate Compilation files". When it is choosed, OMC will automatically delete the Intermediate files. However in Openmodelica Scripting I only find a function "deleteFiles", that can only delelte a file at once.
Is there a way to solve this?
best regards
I add another member to the struct and now it worked.
C-header:-------
-----------------------------------------------------------------------------
typedef struct {
//! Temperature
double p;
double M;
} State;
void setState_C_impl(double p, double M, State *state); // it works
//void setState_C_impl(double p, State *state); // it dosent
----------------------------------------------------------------------------
C-source:
----------------------------------------------------------------------------
#include "State.h"
void setState_C_impl(double p, double M, State *state){
state->p = p;
state->M = M;
}
/*
void setState_C_impl(double p, State *state){
state->p = p;
}
*/
-----------------------------------------------------------------------------
OpenModelica file:
------------------------------------------------------------------------------
within;
package VersuchPointer
record State
Real T;
Real M;
end State;
function setState
input Real p;
input Real M;
output State state;
external "C" setState_C_impl(p, M, state) annotation(
/*Library = "State.o",*/
IncludeDirectory = "modelica://VersuchPointer/Resources/Library",
Include = "#include \"State.c\"");
end setState;
model CallState
Real p;
Real M;
State state;
//Real y;
equation
p = 20;
M = 30;
//state = setState(p);
state = setState(p,M);
end CallState;
end VersuchPointer;
------------------------------------------------------------------------------------
Thank you very much! this Problem has botherd me for a whole day
Hello, i am new to openModelica. I use the Version 1.14 64bit in Windows 7. Now i am trying to passing a record in external C function and then give a Value to the member of the record. at last, the c function should return the modified record.
I do it through "struct". Hier ist the C code;
Header file: State.h
-----------------------------------------------------------------
typedef struct {
//! Temperature
double T;
} State;
void setState_C_impl(double p, State *state);
--------------------------------------------------------------------
Source file: State.c
--------------------------------------------------------------------
#include "State.h"
void setState_C_impl(double p, State *state){
state->T = p;
}
--------------------------------------------------------------------
the Modelica file:
--------------------------------------------------------------------
within;
package VersuchPointer
// the record--------
record State
Real T;
end State;
//------------------the function
function setState
input Real p;
output State state;
external "C" setState_C_impl(p, state) annotation(
/*Library = "State.o",*/
IncludeDirectory = "modelica://VersuchPointer/Resources/Library",
Include = "#include \"State.c\"");
end setState;
//--------------the modell that calls the function
model CallState
Real p;
State state;
//Real y;
equation
p = 20;
state = setState(p);
end CallState;
end VersuchPointer;
//------------------------------------------------------------------
but I alway get the error report:
VersuchPointer.CallState_08bnd.c: In function 'VersuchPointer_CallState_eqFunction_3':
VersuchPointer.CallState_08bnd.c:46:58: error: incompatible types when assigning to type 'modelica_real {aka double}' from type 'VersuchPointer_State {aka struct <anonymous>}'
data->localData[0]->realVars[1] /* state.T variable */ = omc_VersuchPointer_setState(threadData, 20.0);
also I get the Warning report:
VersuchPointer.CallState_functions.c: In function 'omc_VersuchPointer_setState':
VersuchPointer.CallState_functions.c:29:27: warning: passing argument 2 of 'setState_C_impl' from incompatible pointer type [-Wincompatible-pointer-types]
setState_C_impl(_p_ext, &_state_ext);
^
In file included from VersuchPointer.CallState_includes.h:4:0,
from VersuchPointer.CallState_functions.c:7:
C:/OpenModelica1.14.1-64bit/lib/omlibrary/VersuchPointer/Resources/Library/State.c:3:6: note: expected 'State * {aka struct <anonymous> *}' but argument is of type 'VersuchPointer_State * {aka struct <anonymous> *}'
void setState_C_impl(double p, State *state){
Could someone help me, how can I passing a record in external C function and then return it to Openmodelica.
- Index
- » Users
- » Czzzzz
- » Profile