Exemplo n.º 1
0
int main(int argc, char* argv[])
{
  // Check command line count.
  if( argc < 2 )
    {
      // TODO: Need more consistent error handling.
      std::cerr << "Error: Must specify input file." << std::endl;
      exit(1);
    }

  GetPot input( argv[1] );

  GRINS::CanteraMixture mixture( input, GRINS::MaterialsParsing::material_name(input,GRINS::PhysicsNaming::reacting_low_mach_navier_stokes()) );

  GRINS::CanteraKinetics kinetics( mixture );

  libMesh::Real T0 = input( "Conditions/T0", 300.0 );
  libMesh::Real T1 = input( "Conditions/T1", 300.0 );
  libMesh::Real T_inc = input( "Conditions/T_increment", 100.0 );

  libMesh::Real rho = input( "Conditions/density", 1.0e-3 );

  const unsigned int n_species = mixture.n_species();

  std::vector<double> Y(n_species,0.0);
  for( unsigned int s = 0; s < n_species; s++ )
    {
      Y[s] = input( "Conditions/mass_fractions", 0.0, s );
    }

  std::vector<double> omega_dot(n_species,0.0);

  libMesh::Real T = T0;

  std::ofstream output;
  output.open( "omega_dot.dat", std::ios::trunc );

  output << "# Species names" << std::endl;
  for( unsigned int s = 0; s < n_species; s++ )
    {
      output << mixture.species_name( s ) << " ";
    }
  output << std::endl;
  output << "# T [K]                  omega_dot [kg/m^3-s]" << std::endl;

  output.close();

  while( T < T1 )
    {
      kinetics.omega_dot( T, rho, Y, omega_dot );

      output.open( "omega_dot.dat", std::ios::app );
      output << T << " ";

      for( unsigned int i = 0; i < n_species; i++ )
        {
          output << std::scientific << std::setprecision(16)
                 << omega_dot[i] << " ";
        }

      output << std::endl;

      output.close();

      T += T_inc;
    }


  return 0;
}
int test_evaluator( const GetPot& input )
{
  GRINS::AntiochWilkeTransportMixture<Thermo,Viscosity,Conductivity,Diffusivity> mixture(input);

  GRINS::AntiochWilkeTransportEvaluator<Thermo,Viscosity,Conductivity,Diffusivity> evaluator(mixture);

  const libMesh::Real T = 1000;

  const libMesh::Real rho = 1.0e-3;

  const unsigned int n_species = 5;

  std::vector<libMesh::Real> Y(n_species,0.2);

  GRINS::CachedValues cache;

  cache.add_quantity(GRINS::Cache::TEMPERATURE);
  std::vector<double> Tqp(1,T);
  cache.set_values(GRINS::Cache::TEMPERATURE, Tqp);

  cache.add_quantity(GRINS::Cache::MIXTURE_DENSITY);
  std::vector<double> rhoqp(1,rho);
  cache.set_values(GRINS::Cache::MIXTURE_DENSITY, rhoqp);

  cache.add_quantity(GRINS::Cache::MASS_FRACTIONS);
  std::vector<std::vector<double> > Yqp(1,Y);
  cache.set_vector_values(GRINS::Cache::MASS_FRACTIONS, Yqp);

  libMesh::Real mu = evaluator.mu( cache, 0 );

  libMesh::Real k = evaluator.k( cache, 0 );

  libMesh::Real mu2 = 0.0;
  libMesh::Real k2 = 0.0;

  evaluator.mu_and_k( cache, 0, mu2, k2 );

  std::vector<libMesh::Real> D(n_species,0.0);

  evaluator.D( cache, 0, D );

  std::cout << std::scientific << std::setprecision(16)
            << "mu = " << mu << std::endl;

  std::cout << std::scientific << std::setprecision(16)
            << "k = " << k << std::endl;

  for( unsigned int i = 0; i < n_species; i++ )
    {
      std::cout << std::scientific << std::setprecision(16) 
                << "D(" << mixture.species_name(i) << ") = " << D [i] << std::endl;
    }

  int return_flag = 0;

  int return_flag_temp = 0;

  return_flag_temp = test_mu<Viscosity>( mu );
  if( return_flag_temp != 0 ) return_flag = 1;

  return_flag_temp = test_k<Thermo,Conductivity>( k );
  if( return_flag_temp != 0 ) return_flag = 1;

  return_flag_temp = test_mu<Viscosity>( mu2 );
  if( return_flag_temp != 0 ) return_flag = 1;

  return_flag_temp = test_k<Thermo,Conductivity>( k2 );
  if( return_flag_temp != 0 ) return_flag = 1;
  
  return_flag_temp = test_D<Thermo,Viscosity,Conductivity,Diffusivity>( D );
  if( return_flag_temp != 0 ) return_flag = 1;
 
  return return_flag;
}
int main(int argc, char *argv[])
{
    timeSelector::addOptions();
#   include "addRegionOption.H"
    argList::validArgs.append("patchName");
#   include "setRootCase.H"
#   include "createTime.H"
    instantList timeDirs = timeSelector::select0(runTime, args);
#   include "createNamedMesh.H"

    word patchName = args[1];

    const label patchI = mesh.boundaryMesh().findPatchID(patchName);	

    if (patchI < 0)
    {
            FatalError
            << "Unable to find patch " << patchName << nl
            << exit(FatalError);
    }else
    {
    	Info << "Patch name: " << patchName << endl;
    	Info << " " << endl;
    }
    
    Info<< "Reading field U\n" << endl;
    volVectorField U
    (
	IOobject
	(
            "U",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
	),
	mesh
    );

    #include "createPhi.H"

    Info<< "Reading transportProperties\n" << endl;
    immiscibleIncompressibleTwoPhaseMixture mixture(U, phi);

    const dimensionedScalar& rho1 = mixture.rho1();
    const dimensionedScalar& rho2 = mixture.rho2();

    #include "readGravitationalAcceleration.H"

    // Create output folder	
    OFstream* outputFile;
    outputFile =  new OFstream(mesh.time().path()/"massFlowRateAtPatch"+patchName+".dat");
    Info<< "\nWriting mass flow rates into the file " << mesh.time().path()/"massFlowRateAtPatch"+patchName+".dat" << endl;
    *outputFile  << "#Time \t liquidFlowRate \t gasFlowRate \t totalPatchArea" << endl;	

    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);

        Info<< "Time = " << runTime.timeName() << endl;

        mesh.readUpdate();
	
	// Read color function
	IOobject alphaheader
	(
		"alpha.water",
		runTime.timeName(),
		mesh,
		IOobject::MUST_READ	
	);

	Info<< " Reading alpha" << endl;
	volScalarField alpha(alphaheader,mesh);	

	// Read velocity
	IOobject Umheader
	(
		"U",
		runTime.timeName(),
		mesh,
		IOobject::MUST_READ	
	);

	Info<< " Reading U" << endl;
	volVectorField Um(Umheader,mesh);
	U = Um;	
	
	// Liquid mass flux
	vector totalLiqMassFlux(0,0,0);

	// Gas mass flux
	vector totalGasMassFlux(0,0,0);
	
	// Total patch area
	scalar totalPatchArea(0);
	
	// Velocity aligned with the gravity direction
	volScalarField UHat((U & g)/mag(g));
	
	totalLiqMassFlux = gSum(     alpha.boundaryField()[patchI]*rho1.value()*UHat.boundaryField()[patchI]*mesh.Sf().boundaryField()[patchI]);
	totalGasMassFlux = gSum((1.-alpha.boundaryField()[patchI])*rho2.value()*UHat.boundaryField()[patchI]*mesh.Sf().boundaryField()[patchI]);
	
	totalPatchArea = gSum(mesh.magSf().boundaryField()[patchI]);		

	*outputFile	<< mesh.time().value() 
			<< tab << " " 
                        << totalLiqMassFlux[0] << " " << totalLiqMassFlux[1] << " " << totalLiqMassFlux[2] 
			<< tab << " " 
			<< totalGasMassFlux[0] << " " << totalGasMassFlux[1] << " " << totalGasMassFlux[2] 
			<< tab << "" 
			<< totalPatchArea
                	<< endl;
        
	Info << " " << endl;
    }
Exemplo n.º 4
0
int do_transport_eval( const GetPot& input )
{
  GRINS::AntiochWilkeTransportMixture<Thermo,Viscosity,Conductivity,Diffusivity> mixture(input);

  GRINS::AntiochWilkeTransportEvaluator<Thermo,Viscosity,Conductivity,Diffusivity> evaluator(mixture);

  libMesh::Real T0 = input( "Conditions/T0", 300.0 );
  libMesh::Real T1 = input( "Conditions/T1", 300.0 );
  libMesh::Real T_inc = input( "Conditions/T_increment", 100.0 );

  libMesh::Real rho = input( "Conditions/density", 1.0e-3 );

  const unsigned int n_species = mixture.n_species();

  std::vector<libMesh::Real> Y(n_species);
  if( input.vector_variable_size( "Conditions/mass_fractions" ) != n_species )
    {
      std::cerr << "Error: mass fractions size not consistent with n_species"
                << std::endl;
      libmesh_error();
    }
    
  for( unsigned int s = 0; s < n_species; s++ )
    {
      Y[s] = input( "Conditions/mass_fractions", 0.0, s );
    }

  libMesh::Real T = T0;

  std::ofstream output;
  output.open( "transport.dat", std::ios::trunc );
  
  output << "# Species names" << std::endl;
  for( unsigned int s = 0; s < n_species; s++ )
    {
      output << mixture.species_name( s ) << " ";
    }
  output << std::endl;
  output << "# T [K]    mu         k           D[s]" << std::endl;

  output.close();

  while( T < T1 )
    { 
      output.open( "transport.dat", std::ios::app );
      output << std::scientific << std::setprecision(16);
      output << T << " ";
     
      libMesh::Real mu = evaluator.mu(T,Y);
      libMesh::Real k = evaluator.k(T,Y);

      output <<  mu << " ";
      output << k << " ";
      
      std::vector<libMesh::Real> D(n_species);
      for( unsigned int s = 0; s< n_species; s++ )
        {
          evaluator.D(rho, evaluator.cp(T,Y), k, D);

          output << D[s] << " ";
        }
      output << std::endl;
      output.close();

      T += T_inc;
    }

  return 0;
}
Exemplo n.º 5
0
vector tracing(vector *rayorigin,vector *raydir,int depth){

double tn=IN;
sphere *s=NULL;
double t0=IN,t1=IN;
for(int i=0;i<6;i++){

if(sphere_ray_inter(sp[i],*rayorigin,*raydir,&t0,&t1)){

if(t0<0)t0=t1;

if(t0<tn){

tn=t0;
//if(i==2)printf("\nshan\n");
s=&sp[i];
}
}
}

vector x;
vector z;

vec(&x,2,2,2);
vec(&z,0.5,0.5,0.5);

if(s==NULL)return x;
//else return s->color;

vector color=c;
//printf("%f\n",tn);
//getchar();
vector *tee=vectmult(tn,raydir);
vector *pointhit=vectadd(rayorigin,tee); 
vector *nhit=vectsub(pointhit,&(s->centre));
nhit=normalize(nhit); 

double bias=1e-4;
bool inside=false;

if(dotproduct(raydir,nhit)>0){
nhit=negative(nhit);
inside=true;
}

if((s->transparency>0||s->reflectivity>0)&&depth<maxdepth){

//tee=negative(raydir);

double ratio=-(dotproduct(raydir,nhit));
double fresnel=mixture(pow(1-ratio,3),1,0.1);

double m=dotproduct(raydir,nhit);

//Source : http://www.cs.rpi.edu/~cutler/classes/advancedgraphics/F05/lectures/13_ray_tracing.pdf

tee=vectmult(m*2,nhit);
vector *refldir=vectsub(raydir,tee);
refldir=normalize(refldir);
tee=vectmult(bias,nhit);
tee=vectadd(pointhit,tee);
vector reflection=tracing(tee,refldir,depth+1);
//tee=vectmult(fresnel,&reflection);
//return *tee;

//Source : http://steve.hollasch.net/cgindex/render/refraction.txt

vector refraction=c;
vector *tee1;

if(s->transparency){

double io=1.1,eta=(inside)?io:1/io; 

//tee=negative(nhit);

double cosine=-(dotproduct(nhit,raydir));
double k=1-eta*eta*(1-cosine*cosine);

tee=vectmult((eta*cosine-sqrt(k)),nhit);
tee1=vectmult(eta,raydir);
vector *refrdir=vectadd(tee,tee1);
refrdir=normalize(refrdir);
tee=vectmult(bias,nhit);
tee=vectsub(pointhit,tee);
refraction=tracing(tee,refrdir,depth+1);
//return refraction;
}

tee=vectmult(fresnel,&reflection);
tee1=vectmult(((1-fresnel)*s->transparency),&refraction);
tee=vectadd(tee,tee1);
tee=crossproduct(&(s->color),tee);
color=*tee;
//return *tee;  
}
//return *tee;

else {
 
for(int i=0;i<6;i++){

if(sp[i].emcolor.x>0){
 
vector transmission;

vec(&transmission,1,1,1);
vector *lightdir=vectsub(&(sp[i].centre),pointhit);
lightdir=normalize(lightdir);

for(int j=0;j<6;j++){

if (i != j){

tee=vectmult(bias,nhit);
tee=vectadd(pointhit,tee);
if(sphere_ray_inter(sp[j],*tee,*lightdir,&t0,&t1)){
transmission=c;
break;
}
}
}

tee=crossproduct(&transmission,&(s->color));
tee=crossproduct(&(sp[i].emcolor),tee);
tee=vectmult((max(double(0),dotproduct(nhit,lightdir))),tee);
tee=vectadd(&color,tee);
color=*tee;
}
}
}
  //  return sphere->surfaceColor;

return (*(vectadd(&color,&(s->emcolor))));
}
int test_evaluator( const GetPot& input )
{
  GRINS::AntiochMixtureAveragedTransportMixture<Thermo,Viscosity,Conductivity,Diffusivity> mixture(input,"TestMaterial");

  GRINS::AntiochMixtureAveragedTransportEvaluator<Thermo,Viscosity,Conductivity,Diffusivity> evaluator(mixture);

  const libMesh::Real T = 1000;

  const libMesh::Real rho = 1.0e-3;

  const unsigned int n_species = 5;

  std::vector<libMesh::Real> Y(n_species,0.2);

  libMesh::Real mu = 0.0;
  libMesh::Real k = 0.0;
  std::vector<libMesh::Real> D(n_species,0.0);

  evaluator.mu_and_k_and_D( T, rho, evaluator.cp(T,Y), Y, mu, k, D );

  std::cout << std::scientific << std::setprecision(16)
            << "mu = " << mu << std::endl;

  std::cout << std::scientific << std::setprecision(16)
            << "k = " << k << std::endl;

  for( unsigned int i = 0; i < n_species; i++ )
    {
      std::cout << std::scientific << std::setprecision(16)
                << "D(" << mixture.species_name(i) << ") = " << D [i] << std::endl;
    }

  int return_flag = 0;

  int return_flag_temp = 0;

  return_flag_temp = test_mu<Viscosity>( mu );
  if( return_flag_temp != 0 ) return_flag = 1;

  return_flag_temp = test_k<Thermo,Conductivity>( k );
  if( return_flag_temp != 0 ) return_flag = 1;

  return_flag_temp = test_D<Thermo,Viscosity,Conductivity,Diffusivity>( D );
  if( return_flag_temp != 0 ) return_flag = 1;

  return return_flag;
}