void MixtureFugacityTP::setState_TR(doublereal T, doublereal rho)
{
    getMoleFractions(DATA_PTR(moleFractions_));
    Phase::setTemperature(T);
    _updateReferenceStateThermo();
    Phase::setDensity(rho);
    doublereal mv = molarVolume();
    // depends on mole fraction and temperature
    updateMixingExpressions();

    m_Pcurrent = pressureCalc(T, mv);
    iState_ = phaseState(true);
}
Esempio n. 2
0
/****************************************************************/

void initializeFluid(int Lz, int Ly, int Lx, 
		     double ****R, double ****B){
  
  int x, y, z, k;
  double ux,uy,uz;

 for(z = 0; z < Lz; z++) {
    for(y = 0; y < Ly; y++) {
      for(x = 0; x < Lx; x++) {
	Solid[z][y][x] = 1;
	

	  if(y < Ly - 1 && y > 0 && z < Lz - 1 && z > 0) {
	    Solid[z][y][x] = 0;
	  }

	
      }
    }
  }
  // According to bubble in the middle of a tube
  for(z = 0; z < Lz; z++) {
    for(y = 0; y < Ly; y++) {
      for(x = 0; x < Lx; x++) {
	if(Solid[z][y][x] != b) {
	  if(x < Lx/4 || x > 3*Lx/4) {
	    ux=0.0;
	    uy=0.0;
	    uz=0.0;
	    
	    for(k = 0; k < b; k++) {
	      
	      B[z][y][x][k] = feq(RHO,z,y,x,k,ux,uy,uz);
	      R[z][y][x][k] = 0.0;
	      
	    }
	  }
	  
	  else{
	    ux=0.0;
	    uy=0.0;
	    uz=0.0;
	    
	    for(k = 0; k < b; k++) {
	      R[z][y][x][k]= feq(RHO,z,y,x,k,ux,uy,uz);
	      B[z][y][x][k] = 0.0;
	      
	      
	    }
	  }
	}
      }
    }
  }
  

}//end initializeFluid()_________________________________________________

double feq(double density, int z, int i, 
		  int j, int k, double ux, double uy, double uz){
  double distribution, uc, u2;
  
  uc = ux*c_x[k] + uy*c_y[k] + uz*c_z[k];
  u2 = ux*ux + uy*uy + uz*uz;
  
  distribution = density*w[k]*(1.0 + 3*uc + 4.5*uc*uc - 1.5*u2);

  return distribution;

}//end feq()__________________________________________________

void massMomentumCalc(double ****R, double ****B, int ***Solid, char *directory1, char *directory2, char *filename1, char *filename2){
  
  int z, y, x, k, dir1, dir2;
  double mass = 0.0, redmass = 0.0, bluemass = 0.0, maxabsvelocity = -10.0;
  double uxtemp, uytemp, uztemp, densitytemp, temp1, temp2, val;
  int xmaxvel = -10, ymaxvel = -10, zmaxvel = -10;
  char dataFilename[255];
  FILE *dataFile1, *dataFile2;
  
  for(z = 0; z < Lz; z++) {
    for(y = 0; y < Ly; y++) {
      for(x = 0; x < Lx; x++) {
	uxtemp=0.0;
	uytemp=0.0;
	uztemp=0.0;
	densitytemp=0.0;
	
	for(k = 0; k < b; k++) {
	  mass += R[z][y][x][k] + B[z][y][x][k];
	  redmass += R[z][y][x][k];	  
	  bluemass += B[z][y][x][k];
	}

	if(Solid[z][y][x] == 0) {
	  for(k = 0; k < b; k++) {

	    densitytemp += R[z][y][x][k] + B[z][y][x][k];
	    uxtemp += (R[z][y][x][k] + B[z][y][x][k])*c_x[k];
	    uytemp += (R[z][y][x][k] + B[z][y][x][k])*c_y[k];
	    uztemp += (R[z][y][x][k] + B[z][y][x][k])*c_z[k];
	    
	  }
	  
	  uxtemp/=densitytemp;
	  uytemp/=densitytemp;
	  uztemp/=densitytemp;
	
	  if(sqrt(uxtemp*uxtemp+uytemp*uytemp+uztemp*uztemp) > maxabsvelocity){
	    
	    maxabsvelocity = sqrt(uxtemp*uxtemp+uytemp*uytemp+uztemp*uztemp);
	    xmaxvel = x;
	    ymaxvel = y;
	    zmaxvel = z;
	  }
	}
      }	 
    } 
  }
  
  
  ////////////////////////////
  //Dumping graphics to file//
  ////////////////////////////
  if(ite%10  == 0) {

#ifdef WIN32
    dir1 = mkdir(directory1);
    dir2 = mkdir(directory2);
#else
  //  dir = mkdir(directory,0777);
    dir1 = mkdir(directory1, 0777);
    dir2 = mkdir(directory2, 0777);
#endif
   if (dir1==0) printf("Error: Can't create output directory!\n");
    sprintf(dataFilename,"%s/%s_%07d.vti",directory1,filename1,ite);
    dataFile1 = fopen(dataFilename,"w");
    fprintf(dataFile1, "<?xml version=\"1.0\"?>\n");
    fprintf(dataFile1, "<!-- LBMflow v1.0.1, www.lbmflow.com -->\n");
    fprintf(dataFile1, "<VTKFile type=\"ImageData\" version=\"0.1\" byte_order=\"LittleEndian\">\n");
    fprintf(dataFile1, "  <ImageData WholeExtent=\"0 %d 0 %d 0 %d\" Origin=\"0 0 0\" Spacing=\"1 1 1\">\n",Lx-1,Ly-1,Lz-1);
    fprintf(dataFile1, "  <Piece Extent=\"0 %d 0 %d 0 %d\">\n",Lx-1,Ly-1,Lz-1);
    fprintf(dataFile1, "    <PointData Scalars=\"scalars\">\n");
    fprintf(dataFile1, "       <DataArray type=\"Float32\" Name=\"Density\" NumberOfComponents=\"1\" format=\"ascii\">\n");
    
    for(z = 0; z < Lz; z++) {
      for(y = 0; y < Ly; y++) {
	for(x = 0; x < Lx; x++) {
	  temp1 = 0.0;
	  for(k = 0; k < b; k++) {
	    temp1 += R[z][y][x][k];
	    
	  }

	  val = temp1 / (RHO + 1.0);
       std::cout << "val: " << std::endl;
	  if(Solid[z][y][x] != 0) val = 0.;

	fprintf(dataFile1, "%f ", val);

	}
	fprintf(dataFile1, "\n");
      }
    }
fprintf(dataFile1, "      </DataArray>\n");
exit(1);
    //write pressure

    fprintf(dataFile1, "    </PointData>\n");

    fprintf(dataFile1, "    <CellData>\n");
    fprintf(dataFile1, "    </CellData>\n");
    fprintf(dataFile1, "  </Piece>\n");
    fprintf(dataFile1, "  </ImageData>\n");

    fprintf(dataFile1, "</VTKFile>\n");
    fclose(dataFile1);

if (dir2==0) printf("Error: Can't create output directory!\n");
    sprintf(dataFilename,"%s/%s_%07d.vti",directory2,filename2,ite);
    dataFile2 = fopen(dataFilename,"w");
    fprintf(dataFile2, "<?xml version=\"1.0\"?>\n");
    fprintf(dataFile2, "<!-- LBMflow v1.0.1, www.lbmflow.com -->\n");
    fprintf(dataFile2, "<VTKFile type=\"ImageData\" version=\"0.1\" byte_order=\"LittleEndian\">\n");
    fprintf(dataFile2, "  <ImageData WholeExtent=\"0 %d 0 %d 0 %d\" Origin=\"0 0 0\" Spacing=\"1 1 1\">\n",Lx-1,Ly-1,Lz-1);
    fprintf(dataFile2, "  <Piece Extent=\"0 %d 0 %d 0 %d\">\n",Lx-1,Ly-1,Lz-1);
    fprintf(dataFile2, "    <PointData Scalars=\"scalars\">\n");
    fprintf(dataFile2, "       <DataArray type=\"Float32\" Name=\"Density\" NumberOfComponents=\"1\" format=\"ascii\">\n");
    for(z = 0; z < Lz; z++) {
      for(y = 0; y < Ly; y++) {
	for(x = 0; x < Lx; x++) {
	  temp2 = 0.0;
	  for(k = 0; k < b; k++) {
	    temp2 += B[z][y][x][k];
	    
	  }
	  val = temp2 / (RHO + 1.0);
	  if(Solid[z][y][x] != 0) val = 0.;
	fprintf(dataFile2, "%f ", val);

	}
	fprintf(dataFile2, "\n");
      }
    }
fprintf(dataFile2, "      </DataArray>\n");

    //write pressure

    fprintf(dataFile2, "    </PointData>\n");

    fprintf(dataFile2, "    <CellData>\n");
    fprintf(dataFile2, "    </CellData>\n");
    fprintf(dataFile2, "  </Piece>\n");
    fprintf(dataFile2, "  </ImageData>\n");

    fprintf(dataFile2, "</VTKFile>\n");
    fclose(dataFile2);
  }




  printf("Total mass = %f\n", mass);  
  printf("Red mass = %f\n", redmass);
  printf("Blue mass = %f\n", bluemass);
  printf("F0 = %f\n", FluxForce);
  printf("Maximal abs. velocity = %f, (%f, %f %f)\n", maxabsvelocity,  
	 uxtemp, uztemp, uytemp); 
    
}/* end massMomentumCalc()____________________________________________ */
void takeStep(double ****R, double ****B) {

  while(ite < T) {

    // updates phase populations
    update(Lz, Ly, Lx, R, B);

    // Writes to file
    if(ite%100 == 0) {
      massMomentumCalc(R, B, Solid,"outputh", "outputl", "LBMflow", "LBMflow");
      pressureCalc(R, B, Solid);
    }
    
    ite++;  /* Updates total timesteps ellapsed ****************/
    
  }

}