Commit 41388b83 authored by hazrmard's avatar hazrmard
Browse files

added modelica spring example, powershell clearfiles script

parent 7a59293a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
*.ini
*.mat
*.o
*.libs
*.log
*.makefile
*.c
*.h
*.xml
*.exe
*_info.json
.ipynb_checkpoints/
+34 −8
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

# Modelica x Jupyter

These cells contain modelica code that can be run via Jupyter.

To install:

* Install OpenModelica
* Install Anaconda
* Create environment in `env.yml`

```
    conda env create -f env.yml
```

%% Cell type:code id: tags:

``` OpenModelica
class Pendulum "Planar Pendulum"
class Pendulum "Pendulum"
   constant Real PI=3.141592653589793;
   parameter Real m=1, g=9.81, L=0.5;
   Real F;
   Real F;  // External force tengential to motion
   output Real x(start=0.5),y(start=0);
   output Real vx,vy;
   output Real vx,vy;      // x and y velocities
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;
   m*der(vx)=-(x/L)*F;     // Force equation in x direction
   m*der(vy)=-(y/L)*F-m*g; // Force equation in y direction
   der(x)=vx;              // Relating x position to x velocity
   der(y)=vy;              // Relating y position to y velocity
   x^2+y^2=L^2;            // Constraining x, y to string length
end Pendulum;
```

%% Cell type:code id: tags:

``` OpenModelica
simulate(Pendulum)
```

%% Cell type:code id: tags:

``` OpenModelica
plot(der(x),der(y),m)
```

%% Cell type:code id: tags:

``` OpenModelica
class Spring "Damped Spring"
    // mass, gravity, spring constant, air, contact resistance
    parameter Real m=0.5, g=9.81, k=3, r_a=0.1, r_c=0.0;
    output Real x(start=0.0);  // x position
    output Real vx(start=0.2); // x velocity
equation
    m*der(vx)= -k*x - r_a*vx - r_c*m*g; // force equation
    der(x)=vx;  // relating position to velocity
end Spring;
```

%% Cell type:code id: tags:

``` OpenModelica
simulate(Spring)
```

%% Cell type:code id: tags:

``` OpenModelica
plot(der(x), x)
```
+2 −0
Original line number Diff line number Diff line
@@ -11,3 +11,5 @@ To install:
```
    conda env create -f env.yml
```

On Windows, set the environment variable `OPENMODELICAHOME` to point to the installation directory for OpenModelica.
 No newline at end of file

clearfiles.ps1

0 → 100644
+10 −0
Original line number Diff line number Diff line
rm *.o
rm *.libs
rm *.log
rm *.makefile
rm *.c
rm *.h
rm *.xml
rm *.exe
rm *_info.json
rm dygraph-combined.js
 No newline at end of file