tchange VERSION to double - slidergrid - grid of elastic sliders on a frictional surface
(HTM) git clone git://src.adamsgaard.dk/slidergrid
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit faff3bde365e55629dc9c2414e30d2dcbf96d3ef
(DIR) parent d5eaf125740490f062884823edb1fead98f8efbb
(HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Mon, 4 Apr 2016 15:16:42 -0700
change VERSION to double
Diffstat:
M postprocessing.py | 50 +++++++++++++++++--------------
M slidergrid/constants.h | 2 +-
M slidergrid/simulation.c | 17 ++++++++++++++++-
3 files changed, 45 insertions(+), 24 deletions(-)
---
(DIR) diff --git a/postprocessing.py b/postprocessing.py
t@@ -2,10 +2,11 @@
import sys
import getopt
import os
+import csv
import numpy as np
import matplotlib.pyplot as plt
-VERSION = '0.1-beta'
+VERSION = '0.01'
SCRIPTNAME = sys.argv[0]
t@@ -47,16 +48,18 @@ class sgvis:
def read_general(self, filename):
self.general_filename = filename
- raw = np.loadtxt(self.folder + '/' + self.general_filename)
- self.version = raw[0]
- self.id = raw[1]
- self.N = raw[2]
- self.time = raw[3]
- self.time_end = raw[4]
- self.dt = raw[5]
- self.file_interval = raw[6]
- self.iteration = raw[7]
- self.bond_length_limit = raw[8]
+ with open(self.folder + '/' + self.general_filename, 'r') as f:
+ reader = csv.reader(f, delimiter='\t')
+ for raw in reader:
+ self.version = float(raw[0])
+ self.sid = raw[1]
+ self.N = int(raw[2])
+ self.time = float(raw[3])
+ self.time_end = float(raw[4])
+ self.dt = float(raw[5])
+ self.file_interval = float(raw[6])
+ self.iteration = int(raw[7])
+ self.bond_length_limit = float(raw[8])
def plot_sliders(self):
plt.plot(self.pos[:, 0], self.pos[:, 1], '+')
t@@ -75,7 +78,7 @@ class sgvis:
self.plot_sliders()
def current_time(self):
- return 0.0
+ return self.time
def current_kinetic_energy(self):
E_t = 0.0
t@@ -94,23 +97,26 @@ class sgvis:
* np.sqrt(np.dot(self.angvel[idx, :], self.angvel[idx, :]))**2
def plot_kinetic_energy(self):
- t = []
- E_t_series = []
- E_r_series = []
+ self.t_series = []
+ self.E_t_series = []
+ self.E_r_series = []
for filename in os.listdir(self.folder):
if 'sliders' in filename \
and '.txt' in filename \
- and '.pdf' in filename \
+ and '.pdf' not in filename \
and '.png' not in filename:
self.read_sliders(filename)
self.read_general(filename.replace('sliders', 'general'))
- t.append(self.current_time)
+ self.t_series.append(self.time)
E_t, E_r = self.current_kinetic_energy()
- E_t_series.append(E_t)
- E_r_series.append(E_r)
-
- plt.plot(t, E_t_series)
- plt.plot(t, E_r_series)
+ self.E_t_series.append(E_t)
+ self.E_r_series.append(E_r)
+
+ sorted_idx = np.argsort(self.t_series)
+ print(sorted_idx)
+ t_sorted = np.sort(self.t_series, order=sorted_idx)
+ plt.plot(t_sorted, self.E_t_series)
+ plt.plot(self.t_series[sorted_idx], self.E_r_series[sorted_idx])
outfile = self.folder + '/E_kin.pdf'
print(outfile)
plt.savefig(outfile)
(DIR) diff --git a/slidergrid/constants.h b/slidergrid/constants.h
t@@ -1,6 +1,6 @@
#ifndef CONSTANTS_H_
#define CONSTANTS_H_
-static const char* VERSION = "beta-0.1";
+static const double VERSION = 0.01;
#endif
(DIR) diff --git a/slidergrid/simulation.c b/slidergrid/simulation.c
t@@ -152,7 +152,7 @@ int save_general_state_to_file(const simulation* sim, const char* filename)
}
fprintf(f,
- "%s\t" // VERSION
+ "%f\t" // VERSION
"%s\t" // sim->id
"%d\t" // sim->N
"%f\t" // sim->time
t@@ -177,6 +177,21 @@ int save_general_state_to_file(const simulation* sim, const char* filename)
return 0;
}
+/* save all simulation information to binary format */
+int save_binary_file(const simulation* sim, const char* filename)
+{
+ FILE* f = fopen(filename, "wb");
+ if (f == NULL) {
+ fprintf(stderr, "Error: Could not open output file %s.", filename);
+ return 1;
+ }
+
+
+
+ fclose(f);
+ return 0;
+}
+
/* save slider information as an unstructured grid to a VTK xml file. The
* filename extension should be '.vtu' in order for Paraview to correctly handle
* the file upon import. See VTK-file-formats.pdf for documentation on the file