示例#1
0
/* Calculate first velocity moment of psi */
void CollisionD2Q9LPMChai::getDPsi(double **retX, double **retY) {
    if (psi == NULL) {
        cerr << "Unable to compute grad(Psi), MEM ERROR!" << endl;
        return;
    }

//    double sum;
    for (int j = 0; j < lm->n.y; j++) {
        for (int i = 0; i < lm->n.x; i++) {
            //sum = 0;
            retX[j][i] = 0;
            retY[j][i] = 0;
            for (int d = 1; d < lm->UDIRS; d++) {
                //  cout<<"f: "<<f[0][j][i][d]<<endl;
                retX[j][i] += (f[0][j][i][d] - fEq(d, getPsi(f[0][j][i], j, i)))
                              * lm->ex[d];
                retY[j][i] += (f[0][j][i][d] - fEq(d, getPsi(f[0][j][i], j, i)))
                              * lm->ey[d];
//
//              if(i == 0 && j == 0){
//                  //cout<<"f"<<d<<": "<<f[0][j][i][d]<<endl;
//                  //cout<<"fEQ"<<d<<": "<<fEq(d, getPsi(f[0][j][i], j, i))<<endl;
//                  //cout<<"RETY: "<<retY[j][i]<<endl;
//              }
                //  sum += f[0][j][i][d];
            }
            //retX[j][i] += 0.01;
            //retY[j][i] += 0.01;
            retX[j][i] *= -3.0;
            retY[j][i] *= -3.0;
        }
    }

//    cout<<"RETY0: "<<retY[0][0]<<endl;
//    cout<<"RETY1: "<<retY[0][1]<<endl;
//    cout<<"RETY2: "<<retY[0][2]<<endl;
    // retY[0][0] = retY[0][1];
    // retY[0][lm->n.x-1] = retY[0][1];
    // retY[lm->n.y-1][0] = retY[lm->n.y-1][1];
    // retY[lm->n.y-1][lm->n.x-1] = retY[lm->n.y-1][1];

//    cout<<"f_eq: "<<fEq(2, psi[1][lm->n.x/2])<<endl;
//    cout<<"f: "<<f[0][1][lm->n.x/2][2]<<endl;
//    for(int j = 0; j < lm->n.y-1; j++){
//        for(int i = 0; i < lm->n.x-1; i++){
//            retX[j][i] = psi[j][i+1] - psi[j][i];
//            retY[j][i] = psi[j+1][i] - psi[j][i];
//        }
//    }
//    for(int j = 0; j < lm->n.y; j++){
//        retY[j][lm->n.x-1] = retY[j][lm->n.x-2];
//    }
//
//    for(int i = 0; i < lm->n.x; i++){
//        retY[lm->n.y-1][i] = retY[lm->n.y-2][i];
//    }
}
示例#2
0
void HeZouNodes<T>::updateNode(int i, int j, double rho, int bdr) {
  double feqDiff = fEq(DIR1(1), i, j) - fEq(DIR1(3), i, j);
  //  cout<<"updating middle node..."<<endl;
  // cout<<"f_"<<DIR1(1)<<" = f_"<<DIR1(3)<<endl;
  f[0][j][i][DIR1(1)] = f[0][j][i][DIR1(3)] + feqDiff;
  // cout<<"f_"<<DIR5(5)<<"= -f_"<<DIR5(6)<<endl;
  f[0][j][i][DIR5(5)] = -f[0][j][i][DIR1(3)] - f[0][j][i][DIR5(6)]
      - f[0][j][i][DIR1(2)] - 0.5 * feqDiff + 0.5 * rho;
  // cout<<"f_"<<DIR5(8)<<endl;
  f[0][j][i][DIR5(8)] = -f[0][j][i][DIR1(3)] - f[0][j][i][DIR1(4)]
      - f[0][j][i][DIR5(7)] - 0.5 * feqDiff + 0.5 * rho;
}
示例#3
0
void HeZouNodes<T>::updateCornerNode(int i, int j, double rho, int bdr) {
  //cout<<"updating corner node..."<<endl;
  double feqDiff1_3 = fEq(DIR1(1), i, j) - fEq(DIR1(3), i, j);
  double feqDiff2_4 = fEq(DIR1(2), i, j) - fEq(DIR1(4), i, j);
  f[0][j][i][DIR1(1)] = f[0][j][i][DIR1(3)] + feqDiff1_3;
  f[0][j][i][DIR1(2)] = f[0][j][i][DIR1(4)] + feqDiff2_4;
  f[0][j][i][DIR5(5)] = f[0][j][i][DIR5(7)] - 0.5 * (feqDiff1_3 + feqDiff2_4);
  f[0][j][i][DIR5(8)] = -f[0][j][i][DIR1(3)] - f[0][j][i][DIR1(4)]
      - f[0][j][i][DIR5(7)] - 0.5 * feqDiff1_3 + 0.5 * rho;
  f[0][j][i][DIR5(6)] = -f[0][j][i][DIR1(3)] - f[0][j][i][DIR1(4)]
      - f[0][j][i][DIR5(7)] - 0.5 * feqDiff2_4 + 0.5 * rho;

}
示例#4
0
void CollisionD2Q9LNP::reset() {
  for (int j = 0; j < lm->n.y; j++) {
    for (int i = 0; i < lm->n.x; i++) {
      for (int d = 0; d < lm->UDIRS; d++) {
        f[0][j][i][d] = fEq(d, 0, 0, ni[j][i]);
      }
    }
  }
}
void CollisionD2Q9LPMWang::init() {
    psi = allocate2DArray(n.y, n.x);
    for(int j = 0; j < n.y; j++) {
        for(int i = 0; i < n.x; i++) {
            psi[j][i] = 0.0;
            for(int d = 0; d < 9; d++) f[0][j][i][d] = fEq(d, psi[j][i]);
        }
    }
}
示例#6
0
void CollisionD2Q9LPMChai::reset() {
    for (int j = 0; j < lm->n.y; j++) {
        for (int i = 0; i < lm->n.x; i++) {
            psi[j][i] = 0.0;
            for (int d = 0; d < lm->UDIRS; d++) {
                f[0][j][i][d] = fEq(d, psi[j][i]);
            }
        }
    }
}
示例#7
0
float getAngleAroundOrigin(float x, float y){
	//Prevent divide-by-zero errors.
	if(fEq(y, 0.0f)){
		if(x > 0)
			return Math::PI / 2;
		else if(x < 0)
			return -Math::PI / 2;
		else
			return 0;
	}

	return -atan(x / y) + ((y < 0) ? 0 : Math::PI);
};
void CollisionD2Q9LNPSource::collide(){
    cout<<"D2Q9 LNP with source collision"<<endl;
    cout<<"pe:"<<Pe<<endl;
    for(int j = 0; j < n.y; j++){
        for(int i = 0; i < n.x; i++){
            for(int d = 0; d < 9; d++){
                f[0][j][i][d] += w*( fEq(d, ux[j][i], uy[j][i], ni[j][i]) - f[0][j][i][d] ) +
                                 W[d] * colPrefactor * rhs[j][i];
            }
        }
    }

    updateNi();
}
void CollisionD2Q9LPMWang::collide() {
    cout<<"WANG"<<endl;
    double dQ;

    for(int j = 0; j < n.y; j++) {
        for(int i = 0; i < n.x; i++) {
            psi[j][i] = getPsi(f[0][j][i], i, j);
            dQ = (1 - 0.5*w)*g_rhs(i, j);
            for(int d = 0; d < 9; d++) {
                f[0][j][i][d] += w*( fEq(d, psi[j][i]) - f[0][j][i][d] ) + W[d]*dQ;
            }
            psi[j][i] = getPsi(f[0][j][i], i, j);
        }
    }
}
void CollisionD2Q9BGK::collide(){
    //cout<<"D2Q9 BGK collision"<<endl;
    int j, i;
	for(j = 0; j < lm->n.y; j++){
	    for(i = 0; i < lm->n.x; i++){

	        if(skip != NULL && skip[j][i]) continue;

	        fEq(i, j, eq);
			for(int d = 0; d < lm->UDIRS; d++){
			   // cout<<"i: "<<i<<", j: "<<", d"<<d<<", thread: "<<omp_get_thread_num()<<endl;
				f[0][j][i][d] += w*( eq[d] - f[0][j][i][d] );
			}
		}
	}
}
示例#11
0
void CollisionD2Q9AD::init() {
  cout << "Initializing AD collision model...";

  rho = allocate2DArray(lm->n.y, lm->n.x);
  cout << "initC: " << initC << endl;
  for (int j = 0; j < lm->n.y; j++) {
    for (int i = 0; i < lm->n.x; i++) {
      rho[j][i] = initC;
      for (int d = 0; d < lm->UDIRS; d++) {
        f[0][j][i][d] = fEq(d, initC, 0, 0);
      }
    }
  }

  cout << " done." << endl;
}
示例#12
0
void CollisionD2Q9LNP::collide() {
  updateNi();
  // cout<<"D2Q9 LNP collision"<<endl;
  // cout<<"pe:"<<Pe<<endl;
  double pref = (PHYS_E_CHARGE * z) / (PHYS_KB * T * Pe);
//    cout<<"pref: "<<pref<<endl;
//    cout<<"dPsiY: "<<dPsiy[1][lm->n.x/2]<<endl;
//    cout<<"dPsiX: "<<dPsix[1][lm->n.x/2]<<endl;
//    cout<<"RHS: "<<rhs[1][lm->n.x/2]<<endl;
//    cout<<"F_2: "<<f[0][1][lm->n.x/2][2]<<endl;
//    cout<<"d2psi = "<<dPsiy[2][lm->n.x/2] - dPsiy[1][lm->n.x/2]<<" = "<<
//            (rhs[1][lm->n.x/2] + rhs[2][lm->n.x/2])*0.5<<endl;
//    cout<<"pref*dpsiy: "<<-dPsiy[1][lm->n.x/2]*pref<<endl;
  for (int j = 0; j < n.y; j++) {
    for (int i = 0; i < n.x; i++) {
      // cout<<"i: "<<i<<endl;
      // cout<<"j: "<<j<<endl;
      // if(skip != NULL && skip[j][i]){continue;}
      for (int d = 0; d < 9; d++) {
        f[0][j][i][d] += w
            * (fEq(d, ux[j][i] - pref * dPsix[j][i],
                uy[j][i] - pref * dPsiy[j][i], ni[j][i]) - f[0][j][i][d])
            + W[d] * colPrefactor * ni[j][i] * rhs[j][i];
        // cout<<"orig f: "<<w*( fEq(d, ux[j][i] - pref*dPsix[j][i],
        //          uy[j][i] - pref*dPsiy[j][i],
        //          ni[j][i]) - f[0][j][i][d] )<<endl;
        //  cout<<"extra f: "<<W[d] * colPrefactor *ni[j][i] * rhs[j][i]<<endl;
        //   cout<<"RHS: "<<rhs[j][i]<<endl;
      }
    }
  }
  updateNi();

  double sum = 0;
  double sumCol = 0;
  for (int j = 0; j < lm->n.y; j++) {
    sumCol += ni[j][lm->n.x / 2];
    for (int i = 0; i < lm->n.x; i++) {
      sum += ni[j][1];
    }
  }

  cout << "SUM: " << sum << ", SUMCOL: " << sumCol << ", SUM/3: " << sum / 3.0
      << endl;

}
void CollisionD2Q9LNPSource::init(){
    cout<<"init LNP with source..."<<endl;
    double initConc = 0.0;
    ni = allocate2DArray(lm->n.y, lm->n.x);
    rhs = allocate2DArray(lm->n.y, lm->n.x);
    for(int j = 0; j < lm->n.y; j++){
        for(int i = 0; i < lm->n.x; i++){
            for(int d = 0; d < lm->UDIRS; d++){
                f[0][j][i][d] = fEq(d, 0, 0, j*j);
            }
        }
    }

    double colPrefactor = ( 1 - 0.5 * w );

    updateNi();
}
示例#14
0
void CollisionD2Q9LNP::init() {
  cout << "Initializing  Nernst-Planck Collision model... ";

  ni = allocate2DArray(lm->n.y, lm->n.x);
  for (int j = 0; j < lm->n.y; j++) {
    for (int i = 0; i < lm->n.x; i++) {
      ni[j][i] = initC;
      for (int d = 0; d < lm->UDIRS; d++) {
        f[0][j][i][d] = fEq(d, 0, 0, initC);
      }
    }
  }

  colPrefactor = ((1 - 0.5 * w) * PHYS_E_CHARGE * z) / (PHYS_KB * T * Pe);

  //updateNi(); //superfluous
  cout << "done" << endl;
}
示例#15
0
void CollisionD2Q9LPMChai::collide() {
    UnitHandlerLPM *uh = dynamic_cast<UnitHandlerLPM*>(unitHandler);
    //cout<<"Chai collision"<<endl;
    for (int j = 0; j < n.y; j++) {
        for (int i = 0; i < n.x; i++) {
            psi[j][i] = getPsi(f[0][j][i], i, j);

            //if(skip != NULL && skip[j][i]) continue;
            //cout<<"psi: "<<psi[j][i]<<endl;
            for (int d = 0; d < 9; d++) {
                f[0][j][i][d] += w * (fEq(d, psi[j][i]) - f[0][j][i][d])
                                 + (0.5 - 1.0 / w) / 3.0 * Wa[d] * g_rhs(i, j) * uh->getTimeStep()
                                 * uh->getTimeStep();
            }
            psi[j][i] = getPsi(f[0][j][i], i, j);
        }
    }
}
示例#16
0
void CollisionD2Q9AD::collide() {
  // cout<<"D2Q9 AD collision"<<endl;
  updateRho();
  double gamma = PHYS_E_CHARGE * z / (Pe * PHYS_KB * T);
  //cout<<"gamma: "<<gamma<<endl;
  double jx, jy;
  for (int j = 0; j < lm->n.y; j++) {
    for (int i = 0; i < lm->n.x; i++) {
      //skip the fullway bb nodes..
      //cout << "löl" << endl;
      //if(skip != NULL && skip[j][i]) continue;
      jx = ux[j][i] - gamma * dPsix[j][i];
      jy = uy[j][i] - gamma * dPsiy[j][i];
      for (int d = 0; d < 9; d++) {
        f[0][j][i][d] += w * (fEq(d, rho[j][i], jx, jy) - f[0][j][i][d]);
      }
    }
  }
//    cout << "dpsiy" << dPsiy[2][1] << endl;
//    cout << "dpsix" << dPsix[2][1] << endl;
//    cout<<"uy: "<<uy[2][1]<<endl;
//    cout<<"ux: "<<ux[2][1]<<endl;
  updateRho();
}
示例#17
0
double CollisionD2Q9LPMChai::fEq(int d, int i, int j) {
    return fEq(d, psi[j][i]);
}
示例#18
0
double CollisionD2Q9LNP::fEq(int d, int i, int j) {
  double pref = (PHYS_E_CHARGE * z) / (PHYS_KB * T * Pe);
  return fEq(d, ux[j][i] - pref * dPsix[j][i], uy[j][i] - pref * dPsiy[j][i],
      ni[j][i]);
}
示例#19
0
LDLFileLineArray *LDLQuadLine::splitConcaveQuad(int index1, int index2,
												int index3, int index4)
{
	TCVector &p1 = m_points[index1];
	TCVector &p2 = m_points[index2];
	TCVector &p3 = m_points[index3];
	TCVector &p4 = m_points[index4];
	TCVector normal1 = (p1 - p4) * (p1 - p2);
	TCVector normal2 = (p2 - p1) * (p2 - p3);
	TCVector normal3 = (p3 - p2) * (p3 - p4);
	TCVector normal4 = (p4 - p3) * (p4 - p1);
	TCFloat length1 = normal1.length();
	TCFloat length2 = normal2.length();
	TCFloat length3 = normal3.length();
	TCFloat length4 = normal4.length();
	TCFloat dotProduct;
	LDLTriangleLine *triangle1 = NULL;
	LDLTriangleLine *triangle2 = NULL;
	LDLFileLineArray *fileLineArray = NULL;

	if (fEq(length1, 0.0) || fEq(length2, 0.0) ||
		fEq(length3, 0.0) || fEq(length4, 0.0))
	{
		// Ack!
		return NULL;
	}
	normal1 /= length1;
	normal2 /= length2;
	normal3 /= length3;
	normal4 /= length4;
	if ((dotProduct = normal1.dot(normal2)) <= 0.0)
	{
		triangle1 = newTriangleLine(0, 1, 3);
		triangle2 = newTriangleLine(1, 2, 3);
		reportQuadSplit(dotProduct < -0.9, 0, 1, 2, 3, 0, 1, 3, 1, 2, 3);
	}
	else if ((dotProduct = normal2.dot(normal3)) <= 0.0)
	{
		triangle1 = newTriangleLine(0, 1, 2);
		triangle2 = newTriangleLine(0, 2, 3);
		reportQuadSplit(dotProduct < -0.9, 0, 1, 2, 3, 0, 1, 2, 0, 2, 3);
	}
	else if ((dotProduct = normal3.dot(normal4)) <= 0.0)
	{
		triangle1 = newTriangleLine(0, 1, 3);
		triangle2 = newTriangleLine(1, 2, 3);
		reportQuadSplit(dotProduct < -0.9, 0, 1, 2, 3, 0, 1, 3, 1, 2, 3);
	}
	else if ((dotProduct = normal4.dot(normal1)) <= 0.0)
	{
		triangle1 = newTriangleLine(0, 1, 2);
		triangle2 = newTriangleLine(0, 2, 3);
		reportQuadSplit(dotProduct < -0.9, 0, 1, 2, 3, 0, 1, 2, 0, 2, 3);
	}
	if (triangle1)
	{
		fileLineArray = new LDLFileLineArray(2);
		fileLineArray->addObject(triangle1);
		fileLineArray->addObject(triangle2);
		triangle1->release();
		triangle2->release();
	}
	return fileLineArray;
}
示例#20
0
bool LDLQuadLine::swapNeeded(int index1, int index2, int index3, int index4)
{
	TCVector &p1 = m_points[index1];
	TCVector &p2 = m_points[index2];
	TCVector &p3 = m_points[index3];
	TCVector &p4 = m_points[index4];
	TCVector normal1 = (p1 - p4) * (p1 - p2);
	TCVector normal2 = (p2 - p1) * (p2 - p3);
	TCVector normal3 = (p3 - p2) * (p3 - p4);
	TCVector normal4 = (p4 - p3) * (p4 - p1);
	TCFloat length1 = normal1.length();
	TCFloat length2 = normal2.length();
	TCFloat length3 = normal3.length();
	TCFloat length4 = normal4.length();
	TCFloat dotProduct;
	bool nonFlat = false;

	if (fEq(length1, 0.0) || fEq(length2, 0.0) ||
		fEq(length3, 0.0) || fEq(length4, 0.0))
	{
		return false;
	}
	normal1 /= length1;
	normal2 /= length2;
	normal3 /= length3;
	normal4 /= length4;
	if ((dotProduct = normal1.dot(normal2)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal1.dot(normal3)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal1.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal2.dot(normal3)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal2.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal3.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if (nonFlat)
	{
		setWarning(LDLENonFlatQuad,
			TCLocalStrings::get(_UC("LDLQuadLineNonFlatError")));
	}
	return false;
}