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
  • » JPG84
  • » Profile

Posts

Posts

I try to connect a component with know parameters with one with variable dimension array : error message " Failed to deduce dimension 1 of conc due to missing bind"

The idea behind is that a connector could propagate all the data I need but failed.

package TestCharge2
  //
  type Conc = Real(final quantity = "Concentration", final unit = "mol/L", min = 0.0);
  //

  package Interfaces "Connectors to connect the Streams and Unit Operations"
    extends Modelica.Icons.InterfacesPackage;

    connector port_solution
      parameter Integer nbr_espece;
      Conc conc[nbr_espece];
      flow Real debit(unit = "L/h");
      annotation(
        Icon(coordinateSystem(initialScale = 0.1), graphics = {Rectangle(lineColor = {0, 70, 70}, fillColor = {0, 70, 70}, fillPattern = FillPattern.Solid, extent = {{-50, 50}, {50, -50}})}));
    end port_solution;

     connector port_in
      Conc conc[:] "Array";
      flow Real debit(unit = "L/h");
      annotation(
        Icon(coordinateSystem(initialScale = 0.1), graphics = {Rectangle(lineColor = {0, 70, 70}, fillColor = {0, 70, 70}, fillPattern = FillPattern.Solid, extent = {{-50, 50}, {50, -50}})}));
    end port_in;
  end Interfaces;

  //

  model Charge_aq_1 "Définitions des charges  "
    parameter Real Q = 1.;
    parameter Conc C1 = 0.5;
    parameter Conc C2 = 1.45;
    parameter Conc C3 = 3.;
   
    Interfaces.port_solution outlet_aq(nbr_espece = 3) annotation(
      Placement(visible = true, transformation(origin = {-110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-110, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
     
  equation
    outlet_aq.debit = - Q "Débit sortant >0";
//
    outlet_aq.conc[:] = {C1, C2, C3};
  end Charge_aq_1;

  model App
    Interfaces.port_in inlet_aq "Inlet" annotation(
      Placement(visible = true, transformation(origin = {-110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 110}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
    Real C1;
  equation
    C1 = inlet_aq.conc[1];
  end App;

model Essai
  TestCharge2.Charge_aq_1 c1 annotation(
    Placement(visible = true, transformation(origin = {32, 32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
App app annotation(
    Placement(visible = true, transformation(origin = {-22, 6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(c1.outlet_aq, app.inlet_aq) annotation(
  Line(points = {{22, 32}, {-10, 32}, {-10, 18}}, color = {0, 70, 70}));

end Essai;
end TestCharge2;

Nobody knows ?
Best regards

I would like to have access to the dialog for parameters of two replaceable models M1 (x,y,z) and M2 (u,v) but as they are defined in an upper model SYS, the dialogs are not visibles

package TwoLevelParameter
  model M1
    parameter Real x;
    parameter Real y;
    parameter Real z;
    Real R;
  equation
    R = x + y + z;
  end M1;
 
   model M2
    parameter Real u;
    parameter Real v;
    Real R;
  equation
    R = u * v;
  end M2;
 
model SYS
  replaceable M1 m annotation(
    choices(choice(redeclare M1 m "Default"),
     choice(redeclare M2 m "Variant")));
end SYS;
 
 

  model Essai
  M1 m1(x = 1, y = 2, z = 3)  annotation(
      Placement(visible = true, transformation(origin = {-58, 54}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  M2 m2(u = 2.3, v = 5.)  annotation(
      Placement(visible = true, transformation(origin = {36, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  SYS sys annotation(
      Placement(visible = true, transformation(origin = {-26, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  equation

  end Essai;

end TwoLevelParameter;

Mar-25-21 14:18:01
How to have choice between two models in modelica

Thank you,

I have just combined your different propositions to change the instantiation of M1 and M2 like this :

  M1 m1 if I==1 "Conditional component";
  M2 m2 if I==2 "Conditional component";

works and avoids to run both models as can be seen in the flat modelica :

class TestChoices2.fullmodel
  final parameter Integer I = 1;
  parameter Real x = 5.0;
  Real y;
  parameter Real m1.T;
  Real m1.f;
equation
  m1.f = 1.0 + time;
  y = m1.f;
end TestChoices2.fullmodel;

without conditional definition :

class TestChoices2.Essai
...
equation
  full2.m1.f = 1.0 + time;
  full2.m2.f = 2.0 + time;
  full2.y = full2.m1.f;
end TestChoices2.Essai;

I migth choose this solution with the parameter "I" in a inner/outer declaration (like system in the fluid library) so that all the models and connectors can be change with only an parameter.

Maybe it's an old fortran 66's way of programmation !

Mar-24-21 12:56:51
How to have choice between two models in modelica

I just want to choose between Model 1 and 2 and I don't  understand how to do it in modelica :

package TestChoices

model M1
  parameter Real T ;
  Real f;
equation
  f = 1. + time;
end M1;

model M2
  parameter Real T ;
  Real f;
equation
  f = 2. + time;
end M2;



model fullmodel
  parameter Integer I = 1;
  parameter Real x = 5. ;
  Real y ;
//
equation

if 1 == I then
  "CALL MODEL1"          ?
elseif  1 == 2  then
  "CALL MODEL 2"         ?
end if;

end fullmodel;

  model Essai
  fullmodel full2(I = 2, x = 2.5)  annotation(
      Placement(visible = true, transformation(origin = {-20, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  equation

  end Essai;


end TestChoices;

In version 1.17 and 1.18 a dialog box appears for replaceable model, in my case for m. Is it possible to change from M1 to M2 using this dialog : (Sorry but I could not upload an image)

package TestRedeclare

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

  // model2
  model M2
  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 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 TestRedeclare;

works fine in 1.17.0-dev beta3 and 1.18. dev 171
.
Thank you very much

Thank you

In fact I should had been more specific : there is an error :

Could not evaluate structural parameter (or constant): dim1[1] which gives dimensions of array: x[dim1[1]]. Array dimensions must be known at compile time.

I try to read a matrix with readRealMatrix and mutiply it by a vector x.

How can I create the vector x with dimension equal to those of the matrix :

model TestRead
  "Demonstrate usage of function Streams.readRealMatrix"
  import Modelica.Utilities.Streams.print;
  extends Modelica.Icons.Example;
   final parameter String file1 = Modelica.Utilities.Files.loadResource("modelica://Modelica/Resources/Data/Utilities/Test_RealMatrix_v4.mat") "File name of check matrix 1";

  final parameter String matrixName1 = "Matrix_A" "Names of check matrices";
  final parameter Integer dim1[2] = Modelica.Utilities.Streams.readMatrixSize(file1,matrixName1) "Dimension of check matrix 1";

  final parameter Real A1[:,:] = Modelica.Utilities.Streams.readRealMatrix(file1,matrixName1,dim1[1],dim1[2]) "Data of check matrix 1";

  Real x[dim1[1]] (each fixed = false)  "Dummy state" ;
  Real y ;
  initial equation
  x = fill(1.,dim1[1]) ;
equation

y  = -A1[1,1]*x[1];

end TestRead;

Is there an equivalent dialog box in openmodelica  ?

In dymola, you can use the compnent browser to set the r3 Array (see attachment) and choose the number of rows and set element by element value.

Sorry by I could not upload an image every time I've try I have a message saying that :"The request page can't be found.

Best regards

Mar-06-21 08:02:12
Category: Developer

Hello,

Is it possible to build controls in modelica similar to those of Visual Basic so that the user can enter a list of concentrations, define chemical reactions ... ?

If yes can you gshow me where to find the documentation.

Best Regards

Problem solved as I shift to a transient formulation. I just had a C * der ( x) to transport equation and no more initialization problem !
The model converge toward a steady-state !

Hello

I have program a 3 units liquid-liquid extraction steady state model.

It works fine for one units (with 8 stages), fine in SimulationX for two units (but not in openmodelica) and works with 3 units if I decrease the number of stage from 8 to 3.

It fails to find a correct initializationwith the three units.

What can I do ? Try to make the model transient and run it until steady state ?

Thank for your help

Hello;
Is this behavior OK ?
Best Regards

When I use the integer (Test28.mo) as parameter I can change it so x also change but when I try to use a String it is impossible ?
Test29.mo

Test28.mo

Nobody knows howto use this functionnality ?
Best Regards

Hello,
sometime, I got very interesting notifications but sometimes not (even if there is a problem of initialization)  :

Ecriture Notification
It was not possible to solve the under-determined initial system (81 equations and 107 variables)
...
========================================
Variables (107)
...
Equations (44, 81)
....
Incidence Matrix (row: equation)  ...

And so on, HOW CAN I GET IT AT WILL ?

Best Regards

You are rigth I am a beginner in modelica. I find it very diffiult to learn as I usually program in unspecified language like Matlab ...

Thank you,

It works ! 

I guess that equations are also compiled (Only one ?)

May be this should be explained in some tutorial.

Best Regard

Hi,
Noboby can help ?
Best Regards

I have tried to fit the size of an array depending on a boolean :

The error message is  :

[1] 09:04:41 Traduction Erreur
[Test16: 16:5-16:14]: Could not evaluate structural parameter (or constant): N which gives dimensions of array: A. Array dimensions must be known at compile time.

package Test16
  model R1
    parameter Integer N (fixed = false)  ;
    parameter Boolean iB = true ;
    equation
    if iB then
    N = 3 ;
    else
    N = 1 ;
    end if ;
  end R1;

  model R2
    extends R1;
    Real x  ;
    Real A[N];
  equation
    x = 2.;
  end R2;
end Test16;

In fact there is a problem of dimension of nbr_reaction = 7 and it should be 8

I don't understand how nu_org[1, 1] could be equal to 1
:

See : uploaded model for simulation

I would like to define the inlet of a chemical unit but when I try to define an equation for the flow, there is an error saying that

"Too many equations, over-determined system. The model has 5 equation(s) and 4 variable(s)."

Here is the test :

package Test9

constant Integer nbr = 3 ;

connector Mixture
  Real C[nbr];
  flow Real q_aq ;
end Mixture;

 
class inlet
    parameter Real Q = 5.55;
    parameter Real C1 = 2.3;
    parameter Real C2 = 0.12;
    parameter Real C3 = 0.475;
    Mixture mixture;
  equation
    mixture.q_aq = Q*2.5 ;
    mixture.C[1] = C1;
    mixture.C[2] = C2 * 2.;
    mixture.C[3] = C3 * 3.1245;
  end inlet;
 
end Test9;

Thank for your help

Jan-14-21 15:00:43
Problem with initialisation of the values of an array

Thank you for the answer,

in fact this is not exactly what I need to do.

Most of the matric nu_aq should be zero and for some specific element another value, for example aq_nu[1,1] = -1,  aq_nu[3,1] = -4,  aq_nu[4,4] = -3

I managed to do it like this for a 2x2 matrix  :

parameter Integer nbr_reaction = 2;
  parameter Integer nbr_espece_aq = 2;
  parameter Integer nu_aq[nbr_reaction, nbr_espece_aq] = [1,2;3,4];

But this is very awkward and cumbersome when the matrix is large and you have only very few element to set

Jan-14-21 12:08:54
Problem with initialisation of the values of an array

Nobody can help me  ?

Jan-12-21 15:37:14
Problem with initialisation of the values of an array

model Test
parameter Integer nbr_reaction = 3;
parameter Integer nbr_espece_aq = 7;
Integer nu_aq[nbr_reaction, nbr_espece_aq] = fill(0,nbr_reaction, nbr_espece_aq);

equation
//
  nu_aq[1,1] = -1 ;
  nu_aq[1,2] = -1 ;


end Test;

I have not found how to assign values to nu_aq

Thank you very much I found it

But where is the  tool ?

Sep-29-20 12:42:32
Category: Developer

Hi,
I can't see array values in the local browsers window of the Algorithmic Debugger.
How can I manage this issue ?
Best regards

Is there a MATLAB to Modelica Translator available ?
Best Regards

Sep-25-20 07:33:09
Still a bug
Category: Developer

I got the following message :

[6] 09:31:37 Traduction Erreur
[CodegenCFunctions.tpl: 5352:15-5352:15]: Template error: This should have been handled in indexed assign and should not have gotten here. eigenvalues[:,2].

It seems to have a bug since 5 years ?

https://trac.openmodelica.org/OpenModel … t/3592#no1

Sep-25-20 07:30:02
Simple way to make an script (similar to scilab)
Sep-23-20 06:39:23
Simple way to make an script (similar to scilab)

Hello,

I have made a function (prodcut difference algorithm for quadrature from moments) and I would like to make a script similar to those of scilab or Matlab to test itby comparison with  validated data.

Is there a possibility to make those kind of script (an example would be appreciated) ?

Thanks in advance

BTW, is there a fast method to initialise a matrix to zero ?

Sep-23-20 06:39:23
Simple way to make an script (similar to scilab)

Hello,

I have made a function (prodcut difference algorithm for quadrature from moments) and I would like to make a script similar to those of scilab or Matlab to test itby comparison with  validated data.

Is there a possibility to make those kind of script (an example would be appreciated) ?

Thanks in advance

BTW, is there a fast method to initialise a matrix to zero ?

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