소스 검색

bond graph materials and docker file

Claudio Gomes 6 년 전
부모
커밋
6c908d974f

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 248 - 0
materials/3-BondGraphs/BondGraphs.ipynb


BIN
materials/3-BondGraphs/resources/mass-spring-damper.png


materials/1-NewtonsLaws/resources/mass-spring-damper.svg → materials/3-BondGraphs/resources/mass-spring-damper.svg


materials/1-NewtonsLaws/resources/mass-spring-damper.png → materials/3-BondGraphs/resources/mass-spring.png


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 3942 - 0
materials/3-BondGraphs/resources/mass-spring.svg


+ 49 - 0
materials/Dockerfile

@@ -0,0 +1,49 @@
+FROM jupyter/minimal-notebook:latest
+
+# Install fmipy
+RUN /opt/conda/bin/conda install -c conda-forge fmpy -y --quiet
+
+# Install simpy
+RUN /opt/conda/bin/conda install sympy
+
+# Install scipy
+RUN /opt/conda/bin/conda install scipy
+
+USER root
+
+# Install Julia 0.6
+RUN mkdir /opt/julia && \
+		cd /opt/julia && \
+		wget --quiet https://julialang-s3.julialang.org/bin/linux/x64/0.6/julia-0.6.4-linux-x86_64.tar.gz && \
+		tar -xzf julia-0.6.4-linux-x86_64.tar.gz --directory . --strip-components=1 && \
+		ln -s /opt/julia/bin/julia /usr/bin/julia && \
+		julia --version
+
+RUN mkdir /opt/bondgraphs
+
+COPY test_bondgraphs.py /opt/bondgraphs/
+
+# Install BondGraphTools and run test file (forces installation of dependencies)
+RUN apt-get update -y && \
+		apt-get install -y dvipng && \
+		pip install BondGraphTools && \
+		python3 /opt/bondgraphs/test_bondgraphs.py
+
+# Copy local files to the remote notebooks
+RUN mkdir /opt/notebooks
+
+COPY 1-NewtonsLaws /opt/notebooks/1-NewtonsLaws
+COPY 2-StationaryAction /opt/notebooks/2-StationaryAction
+COPY 3-BondGraphs /opt/notebooks/3-BondGraphs
+
+WORKDIR /opt/notebooks/
+
+# Port
+EXPOSE 8888
+
+# Run Jupyter Notebook
+CMD ["/opt/conda/bin/jupyter", "notebook", "--notebook-dir=/opt/notebooks", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]
+
+# Uncomment to access command line on the docker container
+# CMD ["bash"]
+# to start jupyter run: /opt/conda/bin/jupyter notebook --notebook-dir=/opt/notebooks --ip=0.0.0.0 --port=8888 --no-browser --allow-root

+ 33 - 0
materials/README.md

@@ -0,0 +1,33 @@
+# Objective
+
+This repository contains the materials that are used in the MoDELS tutorial of physical systems modelling for software engineers, in 2019.
+
+# Running the Examples
+
+1. Install [Docker](https://www.docker.com/).
+
+1. Using docker's console, navigate to the root of this repository.
+
+1. Build the docker image: `docker build -t jupyter .` This will download all dependencies you need to run the examples. You might need root access.
+
+1. Note the host's ip address by running: `docker-machine ip`. Let us denote it by `MACHINE_IP`
+
+1. Run the docker container: `docker run --name jupyterrun -p 8888:8888 -t jupyter`. This will start a container with name `jupyterrun` of the image tagged with `jupyter` and will forward any traffic going into port 8888 (in the host machine) to the same port in the virtual machine. Let `TOKEN` denote the token given.
+
+1. Open your browser and navigate to `http://MACHINE_IP:8888/?token=TOKEN`
+
+1. Explore the examples.
+
+1. Any changes made in the notebooks affect only the files inside the container. To retrieve them, you need to detach from the `jupyterrun` container (typing `Ctrl+C` on docker's console), and use the following command on docker's console: 
+
+1. ```bash
+   docker cp jupyterrun:/opt/notebooks/tutorial mytutorial
+   ```
+
+   Which will copy all files under the `tutorial ` folder to the `mytutorial` folder in the repository.
+
+1. To terminate and clean up, run the following commands
+
+1. `docker stop jupyterrun`
+
+1.  `docker rm jupyterrun`

+ 21 - 0
materials/test_bondgraphs.py

@@ -0,0 +1,21 @@
+#!/usr/bin/python
+import BondGraphTools as bgt
+
+model = bgt.new(name="RC")
+
+C = bgt.new("C", value=1)
+R = bgt.new("R", value=1)
+zero_law = bgt.new("0")
+
+bgt.add(model, R, C, zero_law)
+
+bgt.connect(R, zero_law)
+bgt.connect(zero_law, C)
+
+timespan = [0, 5]
+x0 = [1]
+t, x = bgt.simulate(model, timespan=timespan, x0=x0)
+
+assert len(x)>0
+
+exit(0)