#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 CONNECTOR_POS 1.5
#define CONNECTOR_RADIUS .2
#define WIRE_RADIUS .1
#define RESISTANCE_RADIUS .2
#define NB_V_CONTOURS 20
#define VOLTAGE 10000
#define CONNECTION_STEP_1 20
#define CONNECTION_STEP_2 700
#define WIRE_RESISTIVITY .01
#define RESISTANCE 3
#define ANGLE_AMPL 20
#define DTHETA .15
void dt(double& theta) {
theta += DTHETA;
if(theta > 180)
theta -= 360;
}
double to_rad(double theta) {
return theta*M_PI/180;
}
double azimuth(double theta, double angle_init) {
return angle_init + ANGLE_AMPL*std::sin(to_rad(theta));
}
int main(int argc, char* argv[]) {
if(argc != 3) {
std::cout << "Usage : " << argv[0] << " <particle|field|both> <a|b|c...> | elec-plot.py" << std::endl
<< " " << argv[0] << " <particle|field|both> <a|b|c...> | elec-plotV.py" << std::endl;
return 0;
}
bool part = true;
bool field = true;
std::string mode(argv[1]);
std::string cond(argv[2]);
double vmin = -(1.5)*VOLTAGE;
double vmax = .5*VOLTAGE;
double alpha_0 = 0;
double elevation = 0;
if(mode == "particle") {
part = true;
field = false;
}
else if(mode == "field") {
part = false;
field = true;
}
double bound = CONNECTOR_POS - .08;
world.
set_generator({-CONNECTOR_POS,0},{CONNECTOR_POS,0},CONNECTOR_RADIUS,VOLTAGE);
if(cond == "a") {}
else if(cond == "b") {
world += rb3;
world += rb1;
world += rb2;
alpha_0 = 90;
elevation = 20;
}
else if(cond == "c") {
alpha_0 = 0;
elevation = 50;
world += rc7;
world += rc8;
world += rc9;
world += rc1;
world += rc2;
world += rc3;
world += rc4;
world += rc5;
world += rc6;
}
elec::Point min(-CONNECTOR_POS - CONNECTOR_RADIUS, -1);
std::vector<elec::Point>
mesh;
std::vector<elec::Point> Efield;
std::vector<double> Vfield;
elec::mesh(min,max,MESH_SIZE,MESH_SIZE,std::back_inserter(mesh));
Efield.clear(); Vfield.clear();
if(field) {
if(cond == "a")
}
unsigned int nb_steps = 0;
double theta = 0;
if(cond == "a")
nb_steps = 400;
else if(cond == "b")
nb_steps = 1100;
else if(cond == "c")
nb_steps = 1700;
for(unsigned int step = 0; step < nb_steps; ++step, dt(theta)) {
if(step == CONNECTION_STEP_1 && cond == "a") {
world += ra1;
}
if(step == CONNECTION_STEP_2 && cond == "b") {
world += rb4;
}
plot.begin_frame("frame","jpg");
plot.set_view(elevation,azimuth(theta,alpha_0));
if(part)
if(field) {
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), vmin, vmax, NB_V_CONTOURS);
if(cond == "a")
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
}
plot.end_frame();
world.
sim(SIM_DT,SIM_SPLIT);
if(field) {
Efield.clear(); Vfield.clear();
if(cond == "a")
}
}
}