#include <vector>
#include <iterator>
#include <cmath>
#include <cstdlib>
#define SIM_SPLIT 10
#define SIM_DT 1
#define MAX_PLOT_FIELD_NORM 100000
#define PLOT_FIELD_SCALE 5e-6
#define MESH_SIZE 40
#define NB_V_CONTOURS 20
#define RESISTIVITY 1 // Good conductor
#define ROTATION_VIEW .1
int main(int argc, char* argv[]) {
if(argc != 4) {
std::cout << "Usage : " << argv[0] << " <particle|field|both> <a|b|..> <nb-frames> | elec-plot.py" << std::endl
<< " " << argv[0] << " <particle|field|both> <a|b|..> <nb-frames> | elec-plotV.py" << std::endl;
return 0;
}
bool part = true;
bool field = true;
std::string mode(argv[1]);
std::string cond(argv[2]);
unsigned int nb_steps = (unsigned int)(atoi(argv[3]));
double vmin,vmax;
double a = 20;
if(mode == "particle") {
part = true;
field = false;
}
else if(mode == "field") {
part = false;
field = true;
}
bool uniform_electron_init = false;
double electron_ratio = 1;
if(cond == "a") {
world += da1;
world += da2;
world += ra1;
rand_min = {-.05,-.05};
rand_max = { .05, .05};
electron_ratio = 3;
vmin = -10000;
vmax = 0;
}
else if(cond == "b") {
world += db1;
world += rb1;
world += rb2;
uniform_electron_init = true;
electron_ratio = 3;
vmin = -10000;
vmax = 0;
}
else if(cond == "c") {
world += da1;
world += da2;
world += ra1;
rand_min = {-.05,-.05};
rand_max = { .05, .05};
electron_ratio = .33;
vmin = -1000;
vmax = 2000;
}
else {
rand_min = {-.05,-.05};
rand_max = { .05, .05};
electron_ratio = 3;
vmin = -10000;
vmax = 0;
}
unsigned int nb_electrons = (
unsigned int)(world.
nb_protons()*electron_ratio);
if(!uniform_electron_init)
for(unsigned int i = 0; i < nb_electrons; ++i)
else
std::vector<elec::Point>
mesh;
std::vector<elec::Point> Efield;
std::vector<double> Vfield;
double max_norm;
std::pair<double,double> vbound;
elec::mesh(min,max,MESH_SIZE,MESH_SIZE,std::back_inserter(mesh));
Efield.clear();
Vfield.clear();
if(field) {
}
for(unsigned int step = 0; step < nb_steps; ++step, a+=ROTATION_VIEW) {
if(field)
std::cerr << "max |E| = " << max_norm << std::endl
<< "V in [" << vbound.first << ", " << vbound.second << ']' << std::endl;
plot.begin_frame("frame","jpg");
plot.set_view(50,a);
if(field) {
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), vmin, vmax, NB_V_CONTOURS);
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
}
if(part)
plot.end_frame();
world.
sim(SIM_DT,SIM_SPLIT);
if(field) {
Efield.clear();
Vfield.clear();
}
}
return 0;
}