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

How to plot a variable ?

How to plot a variable ?

I am new in Modelica, and I would find some help on how to plot a variable ?
Using the code below, nothing is plotted !? What did I forget ? Where can I find some help ?
Many thanks.

class Essai2

type Voltage=Real(unit="V");
type Current=Real(unit="A");

connector Pin
  Voltage v;
  flow Current i;
end Pin;

partial model TwoPin
Pin p,n;
Voltage v "Différence de potentiel";
Current i "Intensité";
equation
  v=p.v-n.v;
  p.i+n.i=0;
  i=p.i;
end TwoPin;

model TensionSinusoidale "source tension sinusoidale"
extends TwoPin;
parameter Real Ac (start=10);
parameter Real f (start=10);
          Real MonPi=3.1416;
equation
  v=Ac*sin(2*MonPi*f*time);
end TensionSinusoidale;

model Resistor
extends TwoPin;
parameter Real R(start=10);
equation
  v=R*i;
end Resistor;

model Ground "masse idéale"
Pin P;
equation
p.v=0.0;
end Ground;

  model Circuit
    // Déclaration des composants
    TensionSinusoidale Alim(Ac = 250, f = 50);
    Resistor R1(R = 2);
    Ground G;
  equation
// Description des connexions
    connect(Alim.p, R1.p);
    connect(Alim.n, G);
    connect(R1.n, G);
  end Circuit;
 
end Essai2;

Re: How to plot a variable ?

The model "Essai2" by itself has no variables, hence nothing is displayed.
You might want to convert it into a package and I am guessing the model that you want to run is "Circuit"

I have made some changes in your code and this seems to work :

Code:

package Essai2 


type Voltage=Real(unit="V");
type Current=Real(unit="A");

connector Pin
  Voltage v;
  flow Current i;
end Pin;

partial model TwoPin
Pin p,n;
Voltage v "Différence de potentiel";
Current i "Intensité";
equation
  v=p.v-n.v;
  p.i+n.i=0;
  i=p.i;
end TwoPin;

model TensionSinusoidale "source tension sinusoidale"
extends TwoPin;
parameter Real Ac (start=10);
parameter Real f (start=10);
          Real MonPi=3.1416;
equation
  v=Ac*sin(2*MonPi*f*time);
end TensionSinusoidale;

model Resistor
extends TwoPin;
parameter Real R(start=10);
equation
  v=R*i;
end Resistor;

model Ground "masse idéale"
Pin P;
equation
P.v=0.0;
end Ground;


  model Circuit
    // Déclaration des composants
    TensionSinusoidale Alim(Ac = 250, f = 50);
    Resistor R1(R = 2);
    Ground G;
  equation
// Description des connexions
    connect(Alim.p, R1.p);
    connect(Alim.n, G.P);
    connect(R1.n, G.P);
  end Circuit;

 
end Essai2;

Re: How to plot a variable ?

Thank you very much !
It works ! So I can go on with the discovery of Modelica and Omedit

There are 0 guests and 0 other users also viewing this topic