Introduction
Introduction Statistics Contact Development Disclaimer Help
tadd simulation constructor, fix neighbor construction - slidergrid - grid of e…
git clone git://src.adamsgaard.dk/slidergrid
Log
Files
Refs
README
LICENSE
---
commit 3f412993d74c736d82c909dbc66e0848fad84dc2
parent 6fba7f184af58122623eadbe40e902759fef2a25
Author: Anders Damsgaard <[email protected]>
Date: Wed, 16 Mar 2016 14:25:21 -0700
add simulation constructor, fix neighbor construction
Diffstat:
M debug.h | 2 +-
M grid.c | 24 ++----------------------
M grid.h | 4 ----
M simulation.c | 41 +++++++++++++++++++++++++++++…
M simulation.h | 14 +++++++++++++-
M test.c | 6 +++---
6 files changed, 60 insertions(+), 31 deletions(-)
---
diff --git a/debug.h b/debug.h
t@@ -3,6 +3,6 @@
// if defined, verbose information to stdout will be shown during the
// slider-bond initialization function
-#define DEBUG_FIND_AND_BOND_TO_NEIGHBORS
+//#define DEBUG_FIND_AND_BOND_TO_NEIGHBORS
#endif
diff --git a/grid.c b/grid.c
t@@ -40,11 +40,11 @@ void find_and_bond_to_neighbors_n2(
const int N,
const Float cutoff)
{
- int i, j;
- int n_neighbors = 0;
+ int i, j, n_neighbors;
Float3 dist;
Float dist_norm;
for (i=0; i<N; i++) {
+ n_neighbors = 0;
for (j=0; j<N; j++) {
if (i != j) {
dist = subtract_float3(sliders[i].pos, sliders[j].pos);
t@@ -69,23 +69,3 @@ void find_and_bond_to_neighbors_n2(
}
}
}
-
-int save_slider_positions_to_file(
- const slider* sliders,
- const int N,
- const char* filename)
-{
- FILE* f = fopen(filename, "w");
- if (f == NULL) {
- fprintf(stderr, "Could not open output file %s.", filename);
- return 1;
- }
-
- int i;
- for (i=0; i<N; i++)
- printf("%f\t%f\t%f\n",
- sliders[i].pos.x, sliders[i].pos.y, sliders[i].pos.z);
-
- fclose(f);
- return 0;
-}
diff --git a/grid.h b/grid.h
t@@ -15,8 +15,4 @@ void find_and_bond_to_neighbors_n2(
const int N,
const Float cutoff);
-int save_slider_positions_to_file(
- const slider* sliders,
- const int N,
- const char* filename);
#endif
diff --git a/simulation.c b/simulation.c
t@@ -52,10 +52,31 @@ int check_simulation_values(const simulation sim)
return_status = 1;
}
+ if (sim.file_interval < 0.0) {
+ fprintf(stderr, "Error: The output file interval"
+ "(file_interval = %f) must be a zero or positive value.\n",
+ sim.file_interval);
+ return_status = 1;
+ }
+
return return_status;
}
+simulation create_simulation()
+{
+ simulation sim;
+ sim.N = 0;
+ sim.time = 0.0;
+ sim.time_end = 0.0;
+ sim.dt = 0.1;
+ sim.iteration = 0;
+ sim.bond_length_limit = 0;
+ sim.id = "unnamed";
+ sim.file_interval = 0.0;
+ return sim;
+}
+
Float find_time_step(const slider* sliders, const int N, const Float safety)
{
Float smallest_mass = 1.0e20;
t@@ -71,3 +92,23 @@ Float find_time_step(const slider* sliders, const int N, co…
return safety/sqrt(largest_stiffness/smallest_mass);
}
+
+int save_slider_positions_to_file(
+ const slider* sliders,
+ const int N,
+ const char* filename)
+{
+ FILE* f = fopen(filename, "w");
+ if (f == NULL) {
+ fprintf(stderr, "Could not open output file %s.", filename);
+ return 1;
+ }
+
+ int i;
+ for (i=0; i<N; i++)
+ printf("%f\t%f\t%f\n",
+ sliders[i].pos.x, sliders[i].pos.y, sliders[i].pos.z);
+
+ fclose(f);
+ return 0;
+}
diff --git a/simulation.h b/simulation.h
t@@ -11,13 +11,25 @@ typedef struct {
Float dt;
long int iteration;
Float bond_length_limit;
-
+ char* id;
+ Float file_interval;
} simulation;
+// create simulation with default values
+simulation create_simulation();
+
+// calculate the longest stable time step
Float find_time_step(const slider* sliders, const int N, const Float safety);
+// check if simulation parameters have reasonable values
int check_simulation_values(const simulation sim);
+// save slider positions to a file on the disk
+int save_slider_positions_to_file(
+ const slider* sliders,
+ const int N,
+ const char* filename);
+
// user-defined function which sets up the simulation
simulation setup_simulation();
diff --git a/test.c b/test.c
t@@ -5,13 +5,13 @@
// test a regular, 2d, orthogonal grid of sliders
simulation setup_simulation()
{
- // create empty simulation structure
- simulation sim;
+ // create empty simulation structure with default values
+ simulation sim = new_simulation();
// initialize grid of sliders
int nx = 4;
int ny = 4;
- int nz = 4;
+ int nz = 1;
sim.N = nx*ny*nz;
sim.sliders = create_regular_slider_grid(nx, ny, nz, 1.0, 1.0, 1.0);
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.