tmain.cpp - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
HTML git clone git://src.adamsgaard.dk/sphere
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tmain.cpp (7280B)
---
1 #include <iostream>
2 #include <cstdio>
3 #include <string>
4 #include <cstdlib>
5
6 #include "constants.h"
7 #include "datatypes.h"
8 #include "sphere.h"
9
10 int main(const int argc, const char *argv[])
11 {
12 // Default values
13 int verbose = 1;
14 int checkVals = 1;
15 int dry = 0;
16 int render = 0; // whether to render an image
17 int method = 0; // visualization method
18 int nfiles = 0; // number of input files
19 float max_val = 0.0f; // max value of colorbar
20 float lower_cutoff = 0.0f;// lower cutoff, particles below won't be rendered
21 int fluid = 0;
22 int device = -1; // -1 run on device with most cores, 0+ run on specified device
23 int print_contacts = 0;
24
25 // Process input parameters
26 int i;
27 for (i=1; i<argc; ++i) { // skip argv[0]
28
29 std::string argvi = std::string(argv[i]);
30
31 // Display help if requested
32 if (argvi == "-h" || argvi == "--help") {
33 std::cout << argv[0] << ": particle dynamics simulator\n"
34 << "Usage: " << argv[0] << " [OPTION[S]]... [FILE1 ...]\n"
35 "Options:\n"
36 "-h, --help\t\tprint help\n"
37 "-V, --version\t\tprint version information and exit\n"
38 "-q, --quiet\t\tsuppress status messages to stdout\n"
39 "-d <device>\t\texecute on device with specified id\n"
40 "-n, --dry\t\tshow key experiment parameters and quit\n"
41 "-f, --fluid\t\tsimulate fluid between particles\n"
42 "-r, --render\t\trender input files to images instead of\n"
43 " \t\tsimulating the temporal evolution\n"
44 "-dc, --dont-check\tdon't check values before running\n"
45 "\nRaytracer (-r) specific options:\n"
46 "-m <method> <maxval> [-l <lower cutoff val>], or\n"
47 "--method <method> <maxval> [-l <lower cutoff val>]\n"
48 "\tcolor visualization method, possible values:\n"
49 "\tnormal, pres, vel, angvel, xdisp, angpos\n"
50 "\t'normal' is the default mode\n"
51 "\tif -l is appended, don't render particles with value below\n"
52 "-c, --contacts\t\tPrint a list of particle-particle contacts\n"
53 << std::endl;
54 return 0; // Exit with success
55 }
56
57 // Display version with fancy ASCII art
58 else if (argvi == "-V" || argvi == "--version") {
59 printf(
60 ".-------------------------------------.\n"
61 "| _ |\n"
62 "| | | |\n"
63 "| ___ _ __ | |__ ___ _ __ ___ |\n"
64 "| / __| '_ \\| '_ \\ / _ \\ '__/ _ \\ |\n"
65 "| \\__ \\ |_) | | | | __/ | | __/ |\n"
66 "| |___/ .__/|_| |_|\\___|_| \\___| |\n"
67 "| | | |\n"
68 "| |_| Version: %.2f |\n"
69 "`-------------------------------------ยด\n"
70 " A discrete-element method particle dynamics simulator.\n"
71 " Written by Anders Damsgaard, ISC license.\n"
72 " https://adamsgaard.dk\n", VERSION);
73 return 0;
74 }
75
76 else if (argvi == "-q" || argvi == "--quiet")
77 verbose = 0;
78
79 else if (argvi == "-n" || argvi == "--dry")
80 dry = 1;
81
82 else if (argvi == "-r" || argvi == "--render") {
83 render = 1;
84 checkVals = 0;
85 }
86
87 else if (argvi == "-dc" || argvi == "--dont-check")
88 checkVals = 0;
89
90 else if (argvi == "-f" || argvi == "--fluid")
91 fluid = 1;
92
93 else if (argvi == "-c" || argvi == "--contacts") {
94 verbose = 0;
95 print_contacts = 1;
96 }
97
98 else if (argvi == "-d") {
99 device = atoi(argv[i+1]);
100 if (device < -1) {
101 std::cerr << "Error: The device id must be 0 or larger."
102 << std::endl;
103 exit(1);
104 }
105 i++; // skip ahead
106 }
107
108 else if (argvi == "-m" || argvi == "--method") {
109
110 render = 1;
111
112 // Find out which
113 if (std::string(argv[i+1]) == "normal")
114 method = 0;
115 else if (std::string(argv[i+1]) == "pres")
116 method = 1;
117 else if (std::string(argv[i+1]) == "vel")
118 method = 2;
119 else if (std::string(argv[i+1]) == "angvel")
120 method = 3;
121 else if (std::string(argv[i+1]) == "xdisp")
122 method = 4;
123 else if (std::string(argv[i+1]) == "angpos")
124 method = 5;
125 else {
126 std::cerr << "Visualization method not understood. See `"
127 << argv[0] << " --help` for more information." << std::endl;
128 exit(1);
129 }
130
131 // Read max. value of colorbar as next argument
132 if (method != 0) {
133 max_val = atof(argv[i+2]);
134
135 // Check if a lower cutoff value was specified
136 if (std::string(argv[i+3]) == "-l") {
137 lower_cutoff = atof(argv[i+4]);
138 i += 4; // skip ahead
139 } else {
140 i += 2; // skip ahead
141 }
142 } else {
143 i++;
144 }
145 }
146
147
148 // The rest of the values must be input binary files
149 else {
150 nfiles++;
151
152 if (verbose == 1)
153 std::cout << argv[0] << ": processing input file: " << argvi <<
154 std::endl;
155
156 if (print_contacts == 1) {
157 DEM dem(argvi, verbose, 0, 0, 0, 0, fluid, device);
158 dem.printContacts();
159 exit(0);
160 }
161
162 if (nfiles == 1) {
163
164 // Create DEM class, read data from input binary, check values,
165 // init cuda, transfer const mem
166 DEM dem(argvi, verbose, checkVals, dry, 1, 1, fluid, device);
167
168 // Render image if requested
169 if (render == 1)
170 dem.render(method, max_val, lower_cutoff);
171
172 // Otherwise, start iterating through time
173 else
174 dem.startTime();
175
176 } else {
177
178 // Do not transfer to const. mem after the first file
179 DEM dem(argvi, verbose, checkVals, dry, 1, 0, fluid, device);
180
181 if (print_contacts == 1)
182 dem.printContacts();
183
184 // Render image if requested
185 else if (render == 1)
186 dem.render(method, max_val, lower_cutoff);
187
188 // Otherwise, start iterating through time
189 else
190 dem.startTime();
191 }
192
193 }
194 }
195
196 // Check whether there are input files specified
197 if (!argv[0] || argc == 1 || nfiles == 0) {
198 std::cerr << argv[0] << ": missing input binary file\n"
199 << "See `" << argv[0] << " --help` for more information"
200 << std::endl;
201 return 1;
202 }
203
204 return 0;
205 }