mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-28 17:20:22 +00:00
26
samples/Modelica/NestedPackages.mo
Normal file
26
samples/Modelica/NestedPackages.mo
Normal file
@@ -0,0 +1,26 @@
|
||||
within ModelicaByExample.PackageExamples;
|
||||
package NestedPackages
|
||||
"An example of how packages can be used to organize things"
|
||||
package Types
|
||||
type Rabbits = Real(quantity="Rabbits", min=0);
|
||||
type Wolves = Real(quantity="Wolves", min=0);
|
||||
type RabbitReproduction = Real(quantity="Rabbit Reproduction", min=0);
|
||||
type RabbitFatalities = Real(quantity="Rabbit Fatalities", min=0);
|
||||
type WolfReproduction = Real(quantity="Wolf Reproduction", min=0);
|
||||
type WolfFatalities = Real(quantity="Wolf Fatalities", min=0);
|
||||
end Types;
|
||||
|
||||
model LotkaVolterra "Lotka-Volterra with types"
|
||||
parameter Types.RabbitReproduction alpha=0.1;
|
||||
parameter Types.RabbitFatalities beta=0.02;
|
||||
parameter Types.WolfReproduction gamma=0.4;
|
||||
parameter Types.WolfFatalities delta=0.02;
|
||||
parameter Types.Rabbits x0=10;
|
||||
parameter Types.Wolves y0=10;
|
||||
Types.Rabbits x(start=x0);
|
||||
Types.Wolves y(start=y0);
|
||||
equation
|
||||
der(x) = x*(alpha-beta*y);
|
||||
der(y) = -y*(gamma-delta*x);
|
||||
end LotkaVolterra;
|
||||
end NestedPackages;
|
||||
24
samples/Modelica/NewtonCooling.mo
Normal file
24
samples/Modelica/NewtonCooling.mo
Normal file
@@ -0,0 +1,24 @@
|
||||
within ModelicaByExample.PackageExamples;
|
||||
model NewtonCooling
|
||||
"Cooling example importing physical types from the Modelica Standard Library"
|
||||
import Modelica.SIunits.Temperature;
|
||||
import Modelica.SIunits.Mass;
|
||||
import Modelica.SIunits.Area;
|
||||
import ConvectionCoefficient = Modelica.SIunits.CoefficientOfHeatTransfer;
|
||||
import SpecificHeat = Modelica.SIunits.SpecificHeatCapacity;
|
||||
|
||||
// Parameters
|
||||
parameter Temperature T_inf=300.0 "Ambient temperature";
|
||||
parameter Temperature T0=280.0 "Initial temperature";
|
||||
parameter ConvectionCoefficient h=0.7 "Convective cooling coefficient";
|
||||
parameter Area A=1.0 "Surface area";
|
||||
parameter Mass m=0.1 "Mass of thermal capacitance";
|
||||
parameter SpecificHeat c_p=1.2 "Specific heat";
|
||||
|
||||
// Variables
|
||||
Temperature T "Temperature";
|
||||
initial equation
|
||||
T = T0 "Specify initial value for T";
|
||||
equation
|
||||
m*c_p*der(T) = h*A*(T_inf-T) "Newton's law of cooling";
|
||||
end NewtonCooling;
|
||||
47
samples/Modelica/Pendulum.mo
Normal file
47
samples/Modelica/Pendulum.mo
Normal file
@@ -0,0 +1,47 @@
|
||||
within ModelicaByExample.Subsystems.Pendula;
|
||||
model Pendulum "A single individual pendulum"
|
||||
import Modelica.Mechanics.MultiBody.Parts;
|
||||
import Modelica.Mechanics.MultiBody.Joints;
|
||||
|
||||
parameter Modelica.SIunits.Position x;
|
||||
parameter Modelica.SIunits.Mass m "Mass of mass point";
|
||||
parameter Modelica.SIunits.Angle phi "Initial angle";
|
||||
parameter Modelica.SIunits.Length L "String length";
|
||||
parameter Modelica.SIunits.Diameter d=0.01;
|
||||
|
||||
Parts.Fixed ground(r={0,0,x}, animation=false)
|
||||
annotation (Placement(
|
||||
transformation(
|
||||
extent={{-10,-10},{10,10}},
|
||||
rotation=270, origin={0,60})));
|
||||
Parts.PointMass ball(m=m, sphereDiameter=5*d)
|
||||
annotation (Placement(transformation(extent={{-10,-90},{10,-70}})));
|
||||
Parts.BodyCylinder string(density=0, r={0,L,0}, diameter=d)
|
||||
annotation (Placement(transformation(
|
||||
extent={{-10,-10},{10,10}},
|
||||
rotation=90,
|
||||
origin={0,-30})));
|
||||
Joints.Revolute revolute(phi(fixed=true, start=phi),
|
||||
cylinderDiameter=d/2, animation=false)
|
||||
annotation (Placement(
|
||||
transformation(
|
||||
extent={{-10,-10},{10,10}},
|
||||
rotation=90,
|
||||
origin={0,20})));
|
||||
equation
|
||||
connect(string.frame_a, ball.frame_a) annotation (Line(
|
||||
points={{0,-40},{0,-40},{0,-80}},
|
||||
color={95,95,95},
|
||||
thickness=0.5,
|
||||
smooth=Smooth.None));
|
||||
connect(revolute.frame_b, ground.frame_b) annotation (Line(
|
||||
points={{0,30},{0,40},{0,40},{0,50}},
|
||||
color={95,95,95},
|
||||
thickness=0.5,
|
||||
smooth=Smooth.None));
|
||||
connect(revolute.frame_a, string.frame_b) annotation (Line(
|
||||
points={{0,10},{0,10},{0,-20},{0,-20}},
|
||||
color={95,95,95},
|
||||
thickness=0.5,
|
||||
smooth=Smooth.None));
|
||||
end Pendulum;
|
||||
16
samples/Modelica/RLC.mo
Normal file
16
samples/Modelica/RLC.mo
Normal file
@@ -0,0 +1,16 @@
|
||||
within ModelicaByExample.PackageExamples;
|
||||
model RLC "An RLC circuit referencing types from the Modelica Standard Library"
|
||||
parameter Modelica.SIunits.Voltage Vb=24 "Battery voltage";
|
||||
parameter Modelica.SIunits.Inductance L = 1;
|
||||
parameter Modelica.SIunits.Resistance R = 100;
|
||||
parameter Modelica.SIunits.Capacitance C = 1e-3;
|
||||
Modelica.SIunits.Voltage V;
|
||||
Modelica.SIunits.Current i_L;
|
||||
Modelica.SIunits.Current i_R;
|
||||
Modelica.SIunits.Current i_C;
|
||||
equation
|
||||
i_R = V/R;
|
||||
i_C = C*der(V);
|
||||
i_L=i_R+i_C;
|
||||
L*der(i_L) = (Vb-V);
|
||||
end RLC;
|
||||
29
samples/Modelica/SecondOrderSystem.mo
Normal file
29
samples/Modelica/SecondOrderSystem.mo
Normal file
@@ -0,0 +1,29 @@
|
||||
within ModelicaByExample.PackageExamples;
|
||||
model SecondOrderSystem
|
||||
"A second order rotational system importing types from Modelica Standard Library"
|
||||
import Modelica.SIunits.*;
|
||||
parameter Angle phi1_init = 0;
|
||||
parameter Angle phi2_init = 1;
|
||||
parameter AngularVelocity omega1_init = 0;
|
||||
parameter AngularVelocity omega2_init = 0;
|
||||
parameter Inertia J1=0.4;
|
||||
parameter Inertia J2=1.0;
|
||||
parameter RotationalSpringConstant k1=11;
|
||||
parameter RotationalSpringConstant k2=5;
|
||||
parameter RotationalDampingConstant d1=0.2;
|
||||
parameter RotationalDampingConstant d2=1.0;
|
||||
Angle phi1;
|
||||
Angle phi2;
|
||||
AngularVelocity omega1;
|
||||
AngularVelocity omega2;
|
||||
initial equation
|
||||
phi1 = phi1_init;
|
||||
phi2 = phi2_init;
|
||||
omega1 = omega1_init;
|
||||
omega2 = omega2_init;
|
||||
equation
|
||||
omega1 = der(phi1);
|
||||
omega2 = der(phi2);
|
||||
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
|
||||
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);
|
||||
end SecondOrderSystem;
|
||||
19
samples/Modelica/System.mo
Normal file
19
samples/Modelica/System.mo
Normal file
@@ -0,0 +1,19 @@
|
||||
within ModelicaByExample.Subsystems.Pendula;
|
||||
model System "A system of pendula"
|
||||
import Modelica.Constants.g_n;
|
||||
import Modelica.Constants.pi;
|
||||
|
||||
parameter Integer n=15 "Number of pendula";
|
||||
parameter Modelica.SIunits.Position x[n] = linspace(0,(n-1)*0.05,n);
|
||||
parameter Modelica.SIunits.Time T = 54;
|
||||
parameter Modelica.SIunits.Time X = 30;
|
||||
parameter Modelica.SIunits.Length lengths[n] = { g_n*(T/(2*pi*(X+(n-i))))^2 for i in 1:n};
|
||||
parameter Modelica.SIunits.Angle phi0 = 0.5;
|
||||
|
||||
Pendulum pendulum[n](x=x, each m=1, each phi=phi0, L=lengths)
|
||||
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
|
||||
inner Modelica.Mechanics.MultiBody.World world
|
||||
annotation (Placement(transformation(extent={{-80,-60},{-60,-40}})));
|
||||
annotation (experiment(StopTime=54,
|
||||
Interval=9e-3, Tolerance=1e-008));
|
||||
end System;
|
||||
4
samples/Modelica/package.mo
Normal file
4
samples/Modelica/package.mo
Normal file
@@ -0,0 +1,4 @@
|
||||
within ;
|
||||
package ModelicaByExample
|
||||
annotation (uses(Modelica(version="3.2.1")));
|
||||
end ModelicaByExample;
|
||||
3
samples/Modelica/package2.mo
Normal file
3
samples/Modelica/package2.mo
Normal file
@@ -0,0 +1,3 @@
|
||||
within ModelicaByExample;
|
||||
package PackageExamples "Examples of using packages"
|
||||
end PackageExamples;
|
||||
3
samples/Modelica/package3.mo
Normal file
3
samples/Modelica/package3.mo
Normal file
@@ -0,0 +1,3 @@
|
||||
within ModelicaByExample.Subsystems;
|
||||
package GearSubsystemModel "Build a subsystem model representing a gear with backlash"
|
||||
end GearSubsystemModel;
|
||||
3
samples/Modelica/package4.mo
Normal file
3
samples/Modelica/package4.mo
Normal file
@@ -0,0 +1,3 @@
|
||||
within ModelicaByExample.Subsystems;
|
||||
package Pendula "Example of using arrays of subsystems to build complete systems"
|
||||
end Pendula;
|
||||
Reference in New Issue
Block a user