int main(){
    cout<<"Poiseuille flow..."<<endl;
    int nx = 101;
	int ny = 21;
	int tMax = 5000;
	double w = 1.0;
	double c = 1.0;

	CollisionD2Q9BGK *cm = new CollisionD2Q9BGK();
	StreamD2Q9 *sm = new StreamD2Q9();
	LatticeModel *lm = new Lattice2D(nx, ny);
	LBM *lbm = new LBM(lm, cm, sm);

    cm->setW(w);
    cm->setC(c);

	/* Add boundary nodes */
	BounceBackNodes<CollisionD2Q9BGK> *bbns =
	        new BounceBackNodes<CollisionD2Q9BGK>();
	bbns->setCollisionModel(cm);
	for(int i = 0; i < nx; i++){
		bbns->addNode(i, 0, 0);
		bbns->addNode(i, ny-1, 0);
	}
	//bbns->addNode(nx/2, ny/2, 0);
    lbm->addBoundaryNodes(bbns);

	/* Set in/outlet conditions*/
	HeZouPressureNodes *cpBdry = new HeZouPressureNodes();
	for(int j = 1; j < ny-1; j++){
		cpBdry->addNode(nx-1, j, 0, 1.0);
		cpBdry->addNode(0, j, 0, 1.1);
	}
	lbm->addBoundaryNodes(cpBdry);

	/* Initialize solver */
	lbm->init();

	/* Main loop */
	for(int t = 0; t < tMax; t++){
		cout<<t<<endl;
		lbm->collideAndStream();
	}

	//lbm->calcMacroscopicVars();
	cm->dataToFile("bench_poi/");
	cout<<"DONE!"<<endl;

	return 0;
}
Esempio n. 2
0
int main() {
  cout << "2D, NS <-> PE <-> NP" << endl;

  /* Parameter definitions */
  int nx = 201;
  int ny = 201;
  // int sd = 51;

  int tNP = 150;
  int tPE = 10000;
  int tNS = tNP; //tNP;
  int tMain = 20;

  int tMod = 1; //undersök i detalj.... ok.

  double l0 = 10e-6 / (ny - 1); //PE, NP
  double C0 = 1e-4 * PHYS_N_A; //NP
  double u0 = 1e-3; //NP, NS
  double dt = 1.0;
  double V0 = -50e-3; //PE
  double rho0 = 1e3; //NS

  double nu = 1.0e-7; //m^2/s
  double D = 1.0e-10; //m^2/s
  double u0x = 0.0;
  double T = 293;
  double eps_r = 80;
  double rho_surface = -0.5e-1; //-50e-3*eps_r*PHYS_EPS0/1e-7/V0*l0;
  rho_surface = 0.0;
  double bulk_charge = 1.0;
  double gamma = PHYS_E_CHARGE / (PHYS_KB * T);
  double dPdx = 0.005e-3; //1e3 * l0/(rho0 * u0 * u0); //lattice units
  double bulkConductivity = 1.5e-3; //conductivity [S/m]

  double Pe = u0 * l0 / D;
  double Re = u0 * 1e4 * l0 / nu;
  double wNP = 1.0 / (3.0 / Pe + 0.5);
  double wPE = 1.0;
  double wNS = 1.0 / (3.0 / Re + 0.5);

  /*print parameters*/
  printLine(20);
  cout << "DIM = (" << nx << ", " << ny << ")" << endl;
  cout << "T = " << T << endl;
  cout << "RHO_SURFACE = " << rho_surface << ", "
      << rho_surface * V0 / l0 * PHYS_EPS0 * eps_r << " C/M^2" << endl;
  cout << "BULK_CHARGE = " << bulk_charge << endl;
  cout << "PE = " << Pe << endl;
  cout << endl;
  cout << "w_np = " << wNP << endl;
  cout << "w_pe = " << wPE << endl;
  cout << "w_ns = " << wNS << endl;
  cout << endl;
  cout << "l0 = " << l0 << endl;
  cout << "V0 = " << V0 << endl;
  cout << "GAMMA: " << gamma << endl;
  cout << "l0*gamma/Pe *V0/l0 = " << l0 * gamma / Pe * V0 / l0 << endl;
  cout << "l0^2*gamma/Pe *V0/l0^2 = " << l0 * l0 * gamma / Pe * V0 / l0 / l0
      << endl;
  cout << "1/Pe = " << 1 / Pe << endl;
  cout << "dPdx = " << dPdx << endl;
  printLine(20);

  /* Allocate memory for velocity and grad. potential arrays */
  double **ux = allocate2DArray(ny, nx);
  double **uy = allocate2DArray(ny, nx);
  double **dPsix = allocate2DArray(ny, nx);
  double **dPsiy = allocate2DArray(ny, nx);
  double **rho_eps = allocate2DArray(ny, nx);
  double **fx = allocate2DArray(ny, nx);
  double **fy = allocate2DArray(ny, nx);

  for (int j = 0; j < ny; j++) {
    for (int i = 0; i < nx; i++) {
      ux[j][i] = 0;
      uy[j][i] = 0;
      fx[j][i] = 0;
      fy[j][i] = 0;
      dPsix[j][i] = 0.0;
      dPsiy[j][i] = 0.0;
      rho_eps[j][i] = 0.0; //-l0*l0/V0*2*PHYS_E_CHARGE*C0/(eps_r *PHYS_EPS0)*\
                            (cos(j*2*M_PI/(ny-1)) + 1)*0.5;
    }
  }

  /* Poisson eq. solver */
  CollisionD2Q9BGKPE *cmPE = new CollisionD2Q9BGKPE();
  StreamD2Q9Periodic *smPE = new StreamD2Q9Periodic();
  Lattice2D *lmPE = new Lattice2D(nx, ny);
  UnitHandlerLPM *uhPE = new UnitHandlerLPM();

  cmPE->setRHS(rho_eps);
  cmPE->setW(wPE);
  cmPE->setC(1.0);
  cmPE->setUnitHandler(uhPE);
  uhPE->setCharLength(l0);
  uhPE->setCharVoltage(V0);
  uhPE->setTimeStep(1.0);

  LBM *lbmPE = new LBM(lmPE, cmPE, smPE);
  lbmPE->init();

//    HeZouLPMChaiNodes *bds = new HeZouLPMChaiNodes();
//    bds->setCollisionModel(cmPE);
//    for(int i = 0; i < nx; i++){
//        bds->addNode(i, 0, 0, 1.0/1.8);
//        bds->addNode(i, ny-1, 0, 1.0/1.8);
//    }

  /* Boundary conds. for Poission solver */
  NeumannNodesPESlip *bds = new NeumannNodesPESlip();
  lbmPE->addBoundaryNodes(bds);
  bds->setCollisionModel(cmPE);

  /* Nernst Planck solver */
  CollisionD2Q9AD *cmNPneg = new CollisionD2Q9AD();
  CollisionD2Q9AD *cmNPpos = new CollisionD2Q9AD();
  StreamD2Q9Periodic *sm = new StreamD2Q9Periodic();
  LatticeModel *lm = new Lattice2D(nx, ny);
  StreamD2Q9Periodic *sm2 = new StreamD2Q9Periodic();
  LatticeModel *lm2 = new Lattice2D(nx, ny);

  cmNPneg->setW(wNP);
  cmNPneg->setC(1);
  cmNPneg->setZ(-1);
  cmNPneg->setInitC(bulk_charge);
  cmNPneg->setUx(ux);
  cmNPneg->setUy(uy);
  cmNPneg->setDPsix(dPsix);
  cmNPneg->setDPsiy(dPsiy);
  cmNPneg->setT(T);
  cmNPneg->setPe(Pe);
  //cmNPneg->setRHS(rho_eps);

  cmNPpos->setW(wNP);
  cmNPpos->setC(1);
  cmNPpos->setZ(1);
  cmNPpos->setInitC(bulk_charge);
  cmNPpos->setUx(ux);
  cmNPpos->setUy(uy);
  cmNPpos->setDPsix(dPsix);
  cmNPpos->setDPsiy(dPsiy);
  cmNPpos->setT(T);
  cmNPpos->setPe(Pe);
  //cmNPpos->setRHS(rho_eps);

  LBM *lbmNPneg = new LBM(lm, cmNPneg, sm);
  LBM *lbmNPpos = new LBM(lm2, cmNPpos, sm2);

  /* Boundary conds for NP solver*/
  SlipNodes<CollisionD2Q9AD> *bbnNeg = new SlipNodes<CollisionD2Q9AD>();
  lbmNPneg->addBoundaryNodes(bbnNeg);
  bbnNeg->setCollisionModel(cmNPneg);
//    for(int i = start + 1 ; i < nx - start - 1; i++){
//        bbnNeg->addNode(i, start, 0, 2);
//        bbnNeg->addNode(i, ny-1-start, 0, 4);
//
//        bbnNeg->addNode(start, i, 0, 1);
//        bbnNeg->addNode(nx-1-start, i, 0, 3);
//    }
//    //corner nodes
//    bbnNeg->addNode(start, start, 0, 6);
//    bbnNeg->addNode(start, ny-1-start, 0, 7);
//    bbnNeg->addNode(nx-1-start, start, 0, 5);
//    bbnNeg->addNode(nx-1-start, ny-1-start, 0, 8);

  SlipNodes<CollisionD2Q9AD> *bbnPos = new SlipNodes<CollisionD2Q9AD>();
  lbmNPpos->addBoundaryNodes(bbnPos);
  bbnPos->setCollisionModel(cmNPpos);
//    for(int i = start + 1; i < nx - start - 1; i++){
//        bbnPos->addNode(i, start, 0, 2);
//        bbnPos->addNode(i, ny-1-start, 0, 4);
//
//        bbnPos->addNode(start, i, 0, 1);
//        bbnPos->addNode(nx-1-start, i, 0, 3);
//    }
//    bbnPos->addNode(start, start, 0, 6);
//    bbnPos->addNode(start, ny-1-start, 0, 7);
//    bbnPos->addNode(nx-1-start, start, 0, 5);
//    bbnPos->addNode(nx-1-start, ny-1-start, 0, 8);

  /* Initialize solver */
  lbmNPneg->init();
  lbmNPpos->init();

  /* NS Solver */
  CollisionD2Q9BGKNSF *cmNS = new CollisionD2Q9BGKNSF();
  StreamD2Q9Periodic *smNS = new StreamD2Q9Periodic();
  Lattice2D *lmNS = new Lattice2D(nx, ny);

  cmNS->setW(wNS);
  cmNS->setC(1.0);

  LBM *lbmNS = new LBM(lmNS, cmNS, smNS);

  /* Set boundary conditions for flow */
  BounceBackNodes<CollisionD2Q9BGKNSF> *bbNS = new BounceBackNodes<
      CollisionD2Q9BGKNSF>();
  bbNS->setCollisionModel(cmNS);
  lbmNS->addBoundaryNodes(bbNS);

  //vertical rod
//    int verRod = ny/5;
//    for(int j = 0; j < verRod+1; j++){
//        bbNS->addNode(nx/2, j, 0);
//        bbNS->addNode(nx/2+10, j, 0);
//
//        bbNS->addNode(nx/2, ny - 1 -j, 0);
//        bbNS->addNode(nx/2+10, ny - 1 - j, 0);
//    }
//
//    for(int i = nx/2+1; i < nx/2 + 10; i++){
//        bbNS->addNode(i, verRod, 0);
//        bbNS->addNode(i, ny - 1 - verRod, 0);
//    }

  //small square
  addRect(nx * 3 / 4, 0, nx / 10, ny / 5, rho_surface, bbNS, bds, bbnNeg,
      bbnPos);

  addRect(nx * 3 / 4, ny - 1 - ny / 5, nx / 10, ny / 6, rho_surface, bbNS, bds,
      bbnNeg, bbnPos);

  addRect(nx / 6, ny / 4, nx / 4, ny / 4, rho_surface, bbNS, bds, bbnNeg,
      bbnPos);

  addRect(nx / 8, ny * 3 / 4, nx / 4, ny / 8, rho_surface, bbNS, bds, bbnNeg,
      bbnPos);

  addRect(nx * 3 / 6, ny / 6, nx / 6, ny / 8, rho_surface, bbNS, bds, bbnNeg,
      bbnPos);

  addRect(nx * 3 / 5 - 5, ny / 2, nx / 8, ny / 4, rho_surface, bbNS, bds,
      bbnNeg, bbnPos);

  addRect(4, ny / 2, nx / 20, ny / 3 - 1, rho_surface, bbNS, bds, bbnNeg,
      bbnPos);

  addRect(nx * 3 / 4 + 5, ny / 3, nx / 20, ny / 20, rho_surface, bbNS, bds,
      bbnNeg, bbnPos);
  //addRect(nx - nx/6, ny/2, nx/10, ny/3, rho_surface, bbNS, bds, bbnNeg, bbnPos);

  //addRect(nx/2 - 10, 2*ny/3, nx/5, ny/5, rho_surface, bbNS, bds, bbnNeg, bbnPos);
  //addRect(nx/4, ny/4, nx/2, ny/2, rho_surface, bbNS, bds, bbnNeg, bbnPos);

  bds->init();
  bbnPos->init();
  bbnNeg->init();
  lbmNS->init();

  cmNS->setForce(fx, fy);

  /* Main loops */
  for (int tt = 0; tt < tMain; tt++) {
    cout << "TT: " << tt << endl;

//        if(tt == 12){ tNP = 8; tNS = 8;}

//        /* Update net charge density */
//        updateRho(rho_eps, cmNPneg, cmNPpos, lm, eps_r, V0, l0, C0);
//        cmPE->reset();
//
//        for(int t = 0; t < tPE; t++){
//            //cout<<"tPE "<<t<<endl;
//            lbmPE->collideAndStream();
//        }
//        cmPE->getDPsi(dPsix, dPsiy);
//
//        //scale potential gradients to SI units *l0
//        rescale2DArray(dPsix, V0, ny, nx);
//        rescale2DArray(dPsiy, V0, ny, nx);
//
//        for(int t = 0; t < tNP; t++){
//            lbmNPneg->collideAndStream();
//            lbmNPpos->collideAndStream();
//        }
//
//
    updateForce(fx, fy, ux, uy, rho_eps, lmNS, eps_r, u0, l0, V0, C0,
        bulkConductivity, dPdx, cmNPpos, cmNPneg);
    for (int t = 0; t < tNS; t++) {

      lbmNS->collideAndStream();
    }

    /* update velocities */
    cmNS->getU(ux, uy);

    /*write result to file*/
    stringstream ss;
    string base = "vis_scripts/data";
    if (tt % tMod == 0) {
      //dPsiY
      ss.str("");
      ss << base << "PSI";
      ss << tt / tMod << "/";
      createDirectory(ss.str());
      ss << "dpsiy.csv";
      write2DArray(dPsiy, NULL, ss.str(), nx, ny);

      //potential
      ss.str("");
      ss << base << "PE";
      ss << tt / tMod << "/";
      createDirectory(ss.str());
      ss << "rho.csv";
      cmPE->dataToFile(ss.str());

      //C_neg
      ss.str("");
      ss << base << "NP";
      ss << tt / tMod << "/";
      createDirectory(ss.str());
      ss << "ni_neg.csv";
      cmNPneg->dataToFile(ss.str());

      //C_pos
      ss.str("");
      ss << base << "NP";
      ss << tt / tMod << "/";
      ss << "ni_pos.csv";
      cmNPpos->dataToFile(ss.str());

      //U and rho_m
      ss.str("");
      ss << base << "NS";
      ss << tt / tMod << "/";
      createDirectory(ss.str());
      cmNS->dataToFile(ss.str());

      //fx
      ss.str("");
      ss << base << "FX";
      ss << tt / tMod << "/";
      createDirectory(ss.str());
      ss << "fx.csv";
      write2DArray(fx, NULL, ss.str(), nx, ny);
    }
  }

  cout << "done LNP." << endl;

  return 0;
}
int main(){
    int nx = 65, ny = 65, tMax = 12000;
    int sd = 32;
    double w = 0.5;
    double c = 1.0;
    double dPdx = 1e-6;

    double **fx = allocate2DArray(ny, nx);
    double **fy = allocate2DArray(ny, nx);

    cout<<"Square array flow..."<<endl;
    LatticeModel *lm = new Lattice2D(nx, ny);
    StreamD2Q9Periodic *sm = new StreamD2Q9Periodic();
    CollisionD2Q9BGKShanChenForce *cm = new CollisionD2Q9BGKShanChenForce();

    cm->setW(w);
    cm->setC(c);

    LBM *lbm = new LBM(lm, cm, sm);

    /* Set boundary conditions*/
    BounceBackNodes<CollisionD2Q9BGKShanChenForce> *bbns =
            new BounceBackNodes<CollisionD2Q9BGKShanChenForce>();
    bbns->setCollisionModel(cm);

    //add square
    int start = ((nx-1) - sd)/2;
    for(int i = start; i < start + sd +1; i++){
        bbns->addNode(i, start, 0);
        bbns->addNode(i, ny-1-start, 0);
    }

    for(int i = start + 1; i < start + sd; i++){
        bbns->addNode(start, i, 0);
        bbns->addNode(nx-1-start, i, 0);
    }
    lbm->addBoundaryNodes(bbns);

    /* Set force */
    for(int i = 0; i < nx; i++){
        for(int j = 0; j < ny; j++){
            fx[j][i] = dPdx;
            fy[j][i] = 0.0;
        }
    }

    /* Initialize solver */
    lbm->init();

    cm->setForce(fx, fy);

    /* Main loop */
    for(int t = 0; t < tMax; t++){
        cout<<t<<endl;
        lbm->collideAndStream();
    }

    cm->dataToFile("vis_scripts/bench_square_array/");
    cout<<"done array."<<endl;

    return 0;
}
Esempio n. 4
0
int main() {

  omp_set_num_threads(1);

  int nx = 500, ny = 150, tMax = 50000, tMod = 100;
  double w = 1.89;
  double c = 1.0;

  double **fx = allocate2DArray(ny, nx);
  double **fy = allocate2DArray(ny, nx);

  cout << "Karman vortex street..." << endl;
  LatticeModel *lm = new Lattice2D(nx, ny);
  //StreamD2Q9Periodic *sm = new StreamD2Q9Periodic();
  StreamD2Q9 *sm = new StreamD2Q9();
  CollisionD2Q9BGKNSF *cm = new CollisionD2Q9BGKNSF();

  cm->setW(w);
  cm->setC(c);

  LBM *lbm = new LBM(lm, cm, sm);

  /* Set boundary conditions*/
  BounceBackNodes<CollisionD2Q9BGKNSF> *bbns = new BounceBackNodes<
      CollisionD2Q9BGKNSF>();
  bbns->setCollisionModel(cm);
  for (int i = 0; i < nx; i++) {
    bbns->addNode(i, 0, 0);
    bbns->addNode(i, ny - 1, 0);
  }

  // add cylindrical obstacle
  int xc = nx / 4, yc = ny / 2;
  double r = ny / 15.0;
  for (int i = 0; i < nx; i++) {
    for (int j = 0; j < ny; j++) {
      if (sqrt((double) ((i - xc) * (i - xc) + (j - yc) * (j - yc))) < r) {
        bbns->addNode(i, j, 0);
      }
    }
  }

  lbm->addBoundaryNodes(bbns);

  /* Set force */
  for (int i = 0; i < nx; i++) {
    for (int j = 0; j < ny; j++) {
      fx[j][i] = 0.000005;
      fy[j][i] = 0.0;
    }
  }
  cm->setForce(fx, fy);

  /* Initialize solver */
  lbm->init();

  stringstream ss;
  string base = "vis_scripts/bench_karman_vortex/";

  /* Main loop */
  for (int t = 0; t < tMax; t++) {
    cout << t << endl;
    lbm->collideAndStream();

    // write result to file
    if (t % tMod == 0) {
      ss.str("");
      ss << base << "KV";
      ss << t / tMod << "/";
      createDirectory(ss.str());
      cm->dataToFile(ss.str());
    }

//		if(t == 3500){
//			for(int i = 0; i < nx; i++){
//				for(int j = 0; j < ny; j++){
//				    fx[j][i] = 0.0;
//				    fy[j][i] = 0.0;
//				}
//			}
//
//		}
  }

  //cm->dataToFile("vis_scripts/bench_karman_vortex/");
  cout << "done cyl." << endl;

  return 0;
}