#include "grid.hh" #include "turing_vtk.hh" #include #include #include class turing_problem { public: // domain const structured_grid & grid; // data const std::vector & a; const std::vector & b; private: // parameters double Da, Db; double eps0, eps1; double q, f, m; public: // constructor turing_problem(const structured_grid & _g, const std::vector & _a, const std::vector & _b, double _Da, double _Db, double _e0, double _e1, double _q, double _f, double _m) : grid(_g), a(_a), b(_b), Da(_Da), Db(_Db), eps0(_e0), eps1(_e1), q(_q), f(_f), m(_m) {} // problem description void compute_local_update(unsigned int i[3], double & da, double & db) const { unsigned int idx = grid.index(i); da = db = 0.0; // laplace with neumann boundary conditions std::vector neighbors = grid.neighbors(i); for (unsigned int n=0; n & da, std::vector & db, double & dt) { unsigned int i[3]; // parallel: nur für eigene Knoten das Update aufrufen for (i[0]=0; i[0] 0.0); dt = std::min( dt, std::abs(p.a[idx]/da[idx]) ); } if (db[idx] < 0.0) { assert(p.b[idx] > 0.0); dt = std::min( dt, std::abs(p.b[idx]/db[idx]) ); } } // parallel: global minimales dt berechnen } int main(int argc, char** argv) { // parallel: MPI starten // read parameter int dim = 2; int D = 1<<7; // diameter in cells double d = 20; // diameter in units double f = 1.1; // problem param f double vt = 1; // time interval for vtk output double max_dt = vt; // max time interval for explicit euler double T = 1000; // end time // create domain info int Z = 2*D; if (dim == 2) Z = 0; // parallel: parallele Information an das Gitter übergeben structured_grid grid(D,D,Z, d/D); std::cout << "created a grid with " << grid.size() << " vertices" << std::endl; // allocate data std::vector a(grid.size()); std::vector b(grid.size()); // initialize data srand48(42); for (unsigned int i=0; i da(grid.size()); std::vector db(grid.size()); // setup problem description turing_problem p(grid, a, b, 1.0, 10.0, 2.2, 0.02, 2e-4, f, 7e-4); // vtk writer vtk_writer vtk_a("turing_a",grid,a); vtk_writer vtk_b("turing_b",grid,b); // time loop double t = 0.0; double v = vt; vtk_a.write(); vtk_b.write(); while (t < T) { double sug_dt = T; compute_update(p, da, db, sug_dt); double dt = std::min(sug_dt * 0.3, max_dt); for(unsigned int i=0; i