Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation, working locally correct #8

Merged
merged 14 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
.vscode/
.vscode/
.ipynb_checkpoints/
23 changes: 21 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
FROM ubuntu:latest

Workdir /app

# Install Python and simulation dependencies
RUN apt-get update && apt-get install -y python3 python3-pip libgl1-mesa-glx libxrender1 xvfb
Copy ./requirements.txt .
RUN pip3 install -r requirements.txt

# init data folder
COPY data ./data
# Copy the build artifacts uploaded in previous job into the Docker image
COPY ./build ./app
COPY ./build ./build

# Copy the simulation script and run script into the Docker image
COPY ./simulation/simulation.py ./run.sh ./
RUN chmod +x ./run.sh
RUN chmod +x ./build/src/gs_main

# Expose the port 5050 for serving animation
EXPOSE 5050

# Run the output executable
CMD ["./app/src/gs_main"]
CMD ["./run.sh"]
Binary file added data/animation-sample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pyvista==0.42.3
imageio==2.26.0
pillow==9.4.0
matplotlib==3.5.1
numpy==1.22.3
pooch==1.8.0
scooby==0.9.2
vtk==9.2.6
cycler==0.11.0
fonttools==4.25.0
kiwisolver==1.4.4
packaging==23.0
pyparsing==3.0.9
python-dateutil==2.8.2
six==1.16.0
platformdirs==2.5.2
requests==2.31.0
charset-normalizer==2.0.4
idna==3.4
urllib3==1.26.16
certifi==2023.7.22
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Run the C++ executable and redirect its output to a file
./build/src/gs_main

# Run the Python script and redirect its output to a file
python3 -u simulation.py
44 changes: 44 additions & 0 deletions simulation/simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pyvista as pv
import os
import http.server
import socketserver

pv.start_xvfb()

# Get a list of all files in the directory
directory = '/app/data/'
files = [f for f in os.listdir(directory) if os.path.isfile(
os.path.join(directory, f))]
files.sort(key=len)
# Create a plotter object to plot and animate
print("creating animation ...")
plotter = pv.Plotter()
# plotter.set_movie_delay(200)
mesh = pv.read('/app/data/output_0.vtk')
plotter.add_mesh(mesh)
plotter.open_gif('/app/data/animation.gif')
# Loop over all frames
for file in files:
mesh = pv.read(f'/app/data/{file}')

plotter.clear()
plotter.add_mesh(mesh)

# Write this frame to the GIF
plotter.write_frame()
plotter.close()


class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
base_dir = '/app/data/'
requested_path = path[1:] # Remove the leading '/'
return os.path.join(base_dir, requested_path)


# serving the animation and files
PORT = 5050
Handler = CustomHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("checkout the simulation animation at http://localhost:5050/animation.gif")
httpd.serve_forever()
2 changes: 1 addition & 1 deletion src/gs/gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void init() {
// Function to write the u array to a VTK file
void writeVTKFile(int iteration) {
std::stringstream ss;
ss << "output_" << iteration << ".vtk";
ss << "/app/data/output_" << iteration << ".vtk";

std::ofstream vtkFile(ss.str());
vtkFile << "# vtk DataFile Version 3.0\n";
Expand Down
Loading