69#include "ramCanvas.hpp"
71typedef mjr::ramCanvas3c8b rcT;
75 std::random_device rd;
76 std::minstd_rand0 rEng(rd());
77 std::uniform_real_distribution<double> uniform_dist_double(1.0e-5, 1.0);
81 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
82 rcT theRamCanvas(width, height);
84 std::vector<mjr::ramCanvas1c64F> imgu1{mjr::ramCanvas1c64F(width, height), mjr::ramCanvas1c64F(width, height)};
85 std::vector<mjr::ramCanvas1c64F> imgu2{mjr::ramCanvas1c64F(width, height), mjr::ramCanvas1c64F(width, height)};
87 mjr::ramCanvas1c64F::pointIntVecType st { {0,-1}, {0,1}, {-1,0}, {1,0}};
96 for(rcT::coordIntType y=0;y<theRamCanvas.getNumPixY();y++)
97 for(rcT::coordIntType x=0;x<theRamCanvas.getNumPixX();x++) {
98 imgu1[0].drawPoint(x, y, uniform_dist_double(rEng));
99 imgu2[0].drawPoint(x, y, uniform_dist_double(rEng));
104 for(
int step=0; step<N; step++) {
108 std::cout <<
"STEP: " << step << std::endl;
109# pragma omp parallel for schedule(static,1)
110 for(rcT::coordIntType y=0;y<theRamCanvas.getNumPixY();y++) {
111 for(rcT::coordIntType x=0;x<theRamCanvas.getNumPixX();x++) {
115 for(mjr::ramCanvas1c64F::pointIntType
const &p: st) {
116 u1_sum += imgu1[i_in].getPxColorChanWrap<0>(x+p.x, y+p.y);
117 u2_sum += imgu2[i_in].getPxColorChanWrap<0>(x+p.x, y+p.y);
120 double u1_c = imgu1[i_in].getPxColor(x, y).getC0();
121 double u2_c = imgu2[i_in].getPxColor(x, y).getC0();
123 double du1_c = t*(1.0-(b+1)*u1_c+a*u1_c*u1_c*u2_c+(u1_sum-4*u1_c)/(h*h));
124 double du2_c = t*(b*u1_c-a*u1_c*u1_c*u2_c+d*(u2_sum-4*u2_c)/(h*h));
126 double u1 = u1_c + du1_c;
127 double u2 = u2_c + du2_c;
129 maxv = std::max(maxv, std::max(u1, u2));
131 imgu1[i_ou].drawPoint(x, y, u1);
132 imgu2[i_ou].drawPoint(x, y, u2);
136 std::cout <<
"Solution Failure at step " << step << std::endl;
138 }
else if (maxv < 0.0001) {
139 std::cout <<
"Zero Solution at step " << step << std::endl;
144 imgu1[i_ou].autoHistStrech();
145 imgu2[i_ou].autoHistStrech();
146 for(
int y=0;y<theRamCanvas.getNumPixY();y++)
147 for(
int x=0;x<theRamCanvas.getNumPixX();x++) {
148 rcT::colorChanType r =
static_cast<rcT::colorChanType
>(255*imgu1[i_ou].getPxColorNC(x, y).getC0());
149 rcT::colorChanType b =
static_cast<rcT::colorChanType
>(255*imgu2[i_ou].getPxColorNC(x, y).getC0());
150 theRamCanvas.drawPoint(x, y, mjr::color3c8b(r, 0, b));
152 theRamCanvas.writeTIFFfile(
"brusselator.tiff");
154 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
155 std::cout <<
"Total Runtime " << runTime.count() <<
" sec" << std::endl;
int main(int argc, char *argv[])