Пример #1
0
bool CalibrationData::saveSLCALIB(const QString& filename){


    FILE * fp = fopen(qPrintable(filename), "w");
    if (!fp)
        return false;

    fprintf(fp, "#V1.0 SLStudio calibration\n");
    fprintf(fp, "#Calibration time: %s\n\n", calibrationDateTime.c_str());
    fprintf(fp, "Kc\n%f %f %f\n%f %f %f\n%f %f %f\n\n", Kc(0,0), Kc(0,1), Kc(0,2), Kc(1,0), Kc(1,1), Kc(1,2), Kc(2,0), Kc(2,1), Kc(2,2));
    fprintf(fp, "kc\n%f %f %f %f %f\n\n", kc(0), kc(1), kc(2), kc(3), kc(4));
    fprintf(fp, "Kp\n%f %f %f\n%f %f %f\n%f %f %f\n\n", Kp(0,0), Kp(0,1), Kp(0,2), Kp(1,0), Kp(1,1), Kp(1,2), Kp(2,0), Kp(2,1), Kp(2,2));
    fprintf(fp, "kp\n%f %f %f %f %f\n\n", kp(0), kp(1), kp(2), kp(3), kp(4));
    fprintf(fp, "Rp\n%f %f %f\n%f %f %f\n%f %f %f\n\n", Rp(0,0), Rp(0,1), Rp(0,2), Rp(1,0), Rp(1,1), Rp(1,2), Rp(2,0), Rp(2,1), Rp(2,2));
    fprintf(fp, "Tp\n%f %f %f\n\n", Tp(0), Tp(1), Tp(2));

    fprintf(fp, "cam_error: %f\n\n", cam_error);
    fprintf(fp, "proj_error: %f\n\n", proj_error);
    fprintf(fp, "stereo_error: %f\n\n", stereo_error);

    fclose(fp);

    return true;

}
Пример #2
0
int Tp(){
	int node = NODE++;

	if(lookahead == TOKEN_ASTERISK){
		// 4:  Tp -> * F Tp",
		int asterisk, f, tp;

		printf("\tnode%d [ label = \"<f0> * | <f1> F | <f2> Tp\"];\n", node);
		asterisk = NODE++;
		printf("\tnode%d [ label = \"*\", shape = oval, fillcolor=green, style=filled];\n", asterisk);
		printf("\tnode%d:f0 -> node%d\n", node, asterisk);
		nextToken();
		f = F();
		printf("\tnode%d:f1 -> node%d\n", node, f);
		tp = Tp();
		printf("\tnode%d:f2 -> node%d\n", node, tp);
		return node;
	} else if(lookahead == TOKEN_PLUS || lookahead == TOKEN_CLOSEPAREN || lookahead == TOKEN_EOF){
		// 5:  Tp -> {}",
		printf("\tnode%d [ label = \"<f0> \\{\\}\"]\n", node);
		return node;
	} else {
		die();
	}
}
Пример #3
0
  void
  test_polylog_dilog(Tp proto = Tp{})
  {
    std::cout.precision(__gnu_cxx::__digits10(proto));
    std::cout << std::scientific;

    std::cout << '\n';
    for (int i = -200; i <= 10; ++i)
      {
	auto x = Tp(0.1Q) * i;
	auto Ls_ceph = __gnu_cxx::dilog(x);
	auto Ls_gnu = __gnu_cxx::polylog(Tp(2), x);
	std::cout << ' ' << x
		  << ' ' << Ls_ceph
		  << ' ' << Ls_gnu
		  << '\n';
      }
    std::cout << std::endl;
  }
Пример #4
0
 inline typename enable_if<import::is_arithmetic<Tp> >::type
 check_positive_distance(Tp x)
 {
   if (x < Tp()) // Tp() == 0 by convention
     {
       std::stringstream out;
       out << x << " is negative";
       throw invalid_distance(out.str());
     }
 }
Пример #5
0
inline Tv hermite(Tp f,
	const Tv& w, const Tv& x, const Tv& y, const Tv& z,
	Tp tension, Tp bias)
{
	tension = (Tp(1) - tension)*Tp(0.5);

	// compute endpoint tangents
	//Tv m0 = ((x-w)*(1+bias) + (y-x)*(1-bias))*tension;
	//Tv m1 = ((y-x)*(1+bias) + (z-y)*(1-bias))*tension;
	Tv m0 = ((x*Tv(2) - w - y)*bias + y - w)*tension;
	Tv m1 = ((y*Tv(2) - x - z)*bias + z - x)*tension;
	
//	x - w + x b - w b + y - x - y b + x b
//	-w + 2x b - w b + y - y b
//	b(2x - w - y) + y - w			
//	
//	y - x + y b - x b + z - y - z b + y b
//	-x + 2y b - x b + z - z b
//	b(2y - x - z) + z - x

	Tp f2 = f  * f;
	Tp f3 = f2 * f;

	// compute hermite basis functions
	Tp a3 = Tp(-2)*f3 + Tp(3)*f2;
	Tp a0 = Tp(1) - a3;
	Tp a2 = f3 - f2;
	Tp a1 = f3 - Tp(2)*f2 + f;

	return x*a0 + m0*a1 + m1*a2 + y*a3;
}
Пример #6
0
  void
  test_polylog_cephes(Tp proto = Tp{})
  {
    std::cout.precision(__gnu_cxx::__digits10(proto));
    std::cout << std::scientific;

    for (auto n : {0, 1, 2, 3, 4, 5})
      {
	std::cout << '\n';
	for (int i = -200; i <= 10; ++i)
	  {
	    auto x = Tp(0.1Q) * i;
	    auto Ls_ceph = pheces::polylog(n, x);
	    auto Ls_gnu = __gnu_cxx::polylog(Tp(n), x);
	    std::cout << ' ' << n
		      << ' ' << x
		      << ' ' << Ls_ceph
		      << ' ' << Ls_gnu
		      << '\n';
	  }
      }
    std::cout << std::endl;
  }
Пример #7
0
 inline typename enable_if<import::is_arithmetic<Tp>, Tp>::type
 check_positive_mul(Tp x, Tp y)
 {
   Tp zero = Tp(); // get 0
   if (x != zero)
     {
       if (((std::numeric_limits<Tp>::max)() / x) < y)
         {
           std::stringstream out;
           out << x << " * " << y << " caused overflow";
           throw arithmetic_error(out.str());
         }
       return x * y;
     }
   return zero;
 }
Пример #8
0
Foam::phaseModel::phaseModel
(
    const word& phaseName,
    const volScalarField& p,
    const volScalarField& T
)
:
    volScalarField
    (
        IOobject
        (
            IOobject::groupName("alpha", phaseName),
            p.mesh().time().timeName(),
            p.mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        p.mesh()
    ),
    name_(phaseName),
    p_(p),
    T_(T),
    thermo_(NULL),
    dgdt_
    (
        IOobject
        (
            IOobject::groupName("dgdt", phaseName),
            p.mesh().time().timeName(),
            p.mesh(),
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        p.mesh(),
        dimensionedScalar("0", dimless/dimTime, 0)
    )
{
    {
        volScalarField Tp(IOobject::groupName("T", phaseName), T);
        Tp.write();
    }

    thermo_ = rhoThermo::New(p.mesh(), phaseName);
    thermo_->validate(phaseName, "e");

    correct();
}
Пример #9
0
int T(){
	int node = NODE++;

	if(lookahead == TOKEN_ID || lookahead == TOKEN_OPENPAREN){
		// 3:  T  -> F Tp",
		int f, tp;

		printf("\tnode%d [ label = \"<f0> F | <f1> Tp\"];\n", node);
		f = F();
		printf("\tnode%d:f0 -> node%d\n", node, f);
		tp = Tp();
		printf("\tnode%d:f1 -> node%d\n", node, tp);
		return node;
	} else {
		die();
	}
}
Пример #10
0
 inline typename enable_if<import::is_arithmetic<Tp>, Tp>::type
 check_square(Tp x)
 {
   Tp zero = Tp(); // get 0
   if (x != zero)
     {
       Tp abs = check_abs(x);
       if (((std::numeric_limits<Tp>::max)() / abs) < abs)
         {
           std::stringstream out;
           out << "square(" << x << ") caused overflow";
           throw arithmetic_error(out.str());
         }
       return x * x;
     }
   return zero;
 }
Пример #11
0
int main() {

//  CGAL::Timer time;
//
//  time.start();
  
  cout << "Creating point cloud" << endl;

  simu.read();

  create(Tm);
  
  if(simu.create_points()) {

    //    set_alpha_circle( Tp , 2);
    //    set_alpha_under_cos(  Tp ) ;


    
    cout << "Creating velocity field " << endl;

    set_fields_TG( Tm ) ;
    //set_fields_cos( Tm ) ;
        
    cout << "Numbering mesh " << endl;

    number(Tm);
  }

  int Nb=sqrt( simu.no_of_particles() + 1e-12);

  // Set up fft, and calculate initial velocities:
  
  move_info( Tm );

  CH_FFT fft( LL , Nb );

  load_fields_on_fft( Tm , fft );

  FT dt=simu.dt();
  FT mu=simu.mu();
  
  fft.all_fields_NS( dt * mu );

  fft.draw( "phi", 0, fft.field_f() );

  fft.draw( "press", 0, fft.field_p() );

  fft.draw( "vel_x", 0, fft.field_vel_x() );

  fft.draw( "vel_y", 0, fft.field_vel_y() );
  
  load_fields_from_fft( fft, Tm );
  
  // just once!
  linear algebra(Tm);

  areas(Tm);
  quad_coeffs(Tm , simu.FEMm() ); volumes(Tm, simu.FEMm() );

  cout << "Setting up diff ops " << endl;

  // TODO: Are these two needed at all?
  //  if(simu.create_points()) {
  //  nabla(Tm);
  // TODO, they are, not too clear why
  Delta(Tm);
    //  }

  const std::string mesh_file("mesh.dat");
  const std::string particle_file("particles.dat");

  // // step 0 draw.-
  //   draw(Tm, mesh_file     , true);
  //   draw(Tp, particle_file , true);
  

// #if defined FULL_FULL
//   {
//     Delta(Tp);
//     linear algebra_p(Tp);
//     from_mesh_full( Tm , Tp ,  algebra_p,kind::ALPHA);
//   }
// #elif defined FULL_LUMPED
//   from_mesh_lumped( Tm , Tp , kind::ALPHA);
//  #elif defined FLIP
//   from_mesh(Tm , Tp , kind::ALPHA);
//  #else
//   from_mesh(Tm , Tp , kind::ALPHA);
// #endif

  cout << "Moving info" << endl;
  move_info( Tm );

  draw(Tm, mesh_file     , true);

  simu.advance_time();
  simu.next_step();

  //  bool first_iter=true;

  CGAL::Timer time;

  time.start();

  std::ofstream log_file;

  log_file.open("main.log");

  bool is_overdamped = ( simu.mu() > 1 ) ; // high or low Re

  for(;
      simu.current_step() <= simu.Nsteps();
      simu.next_step()) {

    cout
      << "Step " << simu.current_step() 
      << " . Time " <<  simu.time()
      << " ; t step " << simu.dt()
      << endl;

    FT dt=simu.dt();

    FT dt2 = dt / 2.0 ;

    int iter=0;
    FT displ=1e10;

    FT min_displ=1e10;
    int min_iter=0;

    const int max_iter=8; //10;
    const FT  max_displ=  1e-8; // < 0 : disable

//  leapfrog, special first step.-
//    if(simu.current_step() == 1) dt2 *= 0.5;

//    dt2 *= 0.5;

    move_info(Tm);

  // TODO: map Tm onto Tp
  // every step
    Triangulation Tp(domain); // particles
    clone(Tm,Tp);

    //    number(Tp);
    //    areas(Tp);
    //quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );

    //cout << "Assigning velocities to particles " << endl;

    //from_mesh_v(Tm , Tp , kind::U);

    //move_info(Tp);


    // iter loop
    for( ; ; iter++) {
      
      // comment for no move.-
      cout << "Moving half step " << endl;
      FT d0;

      displ = move( Tp , dt2 , d0 );

      //      cout << "Moved half step " << endl;

      areas(Tp);
      quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
       
      cout
	<< "Iter " << iter
	<< " , moved avg " << d0 << " to half point, "
	<< displ << " from previous"
	<< endl;

      if( displ < min_displ) {
	min_displ=displ;
	min_iter=iter;
      }

      if( (displ < max_displ) && (iter !=0) )  {
	cout << "Convergence in  " << iter << " iterations " << endl;
	break;
      }

      if(  iter == max_iter-1 )  {
	cout << "Exceeded  " << iter-1 << " iterations " << endl;
	break;
      }

      cout << "Proj advected U0 velocities onto mesh " << endl;

#if defined FULL
      onto_mesh_full_v(Tp,Tm,algebra,kind::UOLD);
#elif defined FLIP
      flip_volumes   (Tp , Tm , simu.FEMm() );
      onto_mesh_flip_v(Tp,Tm,simu.FEMm(),kind::UOLD);
#else
      onto_mesh_delta_v(Tp,Tm,kind::UOLD);
#endif

      load_fields_on_fft( Tm , fft );

      FT b = mu * dt2;
     
      fft.all_fields_NS( b );
  
//      fft.evolve( b );
      
      load_fields_from_fft( fft , Tm );

// It used to be: search "FLIPincr" in CH_FFT.cpp to change accordingly!
// That's NOT needed anymore in latest versions
// EITHER:
// FLIP idea: project only increments
      
       cout << "Proj Delta U from mesh onto particles" << endl;
      
 #if defined FULL_FULL
       {
 	Delta(Tp);
 	linear algebra_p(Tp);
 	from_mesh_full_v(Tm, Tp, algebra_p , kind::DELTAU);
       }
 #elif defined FULL_LUMPED
       from_mesh_lumped_v(Tm, Tp, kind::DELTAU);
 #elif defined FLIP
       from_mesh_v(Tm, Tp, kind::DELTAU);
 #else
       from_mesh_v(Tm, Tp, kind::DELTAU);
 #endif

       incr_v( Tp ,  kind::UOLD , kind::DELTAU , kind::U );


// OR:
// project the whole velocity
      
//      cout << "Proj U from mesh onto particles" << endl;
//      
//#if defined FULL_FULL
//      {
//	Delta(Tp);
//	linear algebra_p(Tp);
//	from_mesh_full_v(Tm, Tp, algebra_p , kind::U);
//      }
//#elif defined FULL_LUMPED
//      from_mesh_lumped_v(Tm, Tp, kind::U);
//#elif defined FLIP
//      from_mesh_v(Tm, Tp, kind::U);
//#else
//      from_mesh_v(Tm, Tp, kind::U);
//#endif

      

      
      // // substract spurious overall movement.-      

      //      zero_mean_v( Tm , kind::FORCE);

    } // iter loop


    cout << "Moving whole step: relative ";

    FT d0;
    
    displ=move( Tp , dt , d0 );

    cout
      <<  displ << " from half point, "
      <<  d0    << " from previous point"
      << endl;
    
      // comment for no move.-

    update_half_velocity( Tp , is_overdamped ); 

    update_half_alpha( Tp );

    areas(Tp);
    quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );

    // this, for the looks basically .-
    
    cout << "Proj U_t+1 , alpha_t+1 onto mesh " << endl;

#if defined FULL
    onto_mesh_full_v(Tp,Tm,algebra,kind::U);
    onto_mesh_full  (Tp,Tm,algebra,kind::ALPHA);
#elif defined FLIP
    flip_volumes(Tp , Tm , simu.FEMm() );
    onto_mesh_flip_v(Tp,Tm,simu.FEMm(),kind::U);
    onto_mesh_flip  (Tp,Tm,simu.FEMm(),kind::ALPHA);
#else
    onto_mesh_delta_v(Tp,Tm,kind::U);
    onto_mesh_delta  (Tp,Tm,kind::ALPHA);
#endif

    if(simu.current_step()%simu.every()==0) {
      draw(Tm, mesh_file     , true);
      draw(Tp, particle_file , true);
      //      fft.histogram( "phi", simu.current_step() , fft.field_fq() );
    }

    move_info( Tm );
    move_info( Tp );
    
    log_file
      << simu.current_step() << "  "
      << simu.time() << "  " ;

    // integrals( Tp , log_file);     log_file << "  ";
    // fidelity(  Tp , log_file );    log_file << endl;

    simu.advance_time();

  } // time loop

  time.stop();

  log_file.close();
  
  cout << "Total runtime: " << time.time() << endl;
  return 0;

}
tmp<scalarField>
alphatPhaseChangeJayatillekeWallFunctionFvPatchScalarField::calcAlphat
(
    const scalarField& prevAlphat
) const
{

    // Lookup the fluid model
    const phaseSystem& fluid =
        db().lookupObject<phaseSystem>("phaseProperties");

    const phaseModel& phase
    (
        fluid.phases()[internalField().group()]
    );

    const label patchi = patch().index();

    // Retrieve turbulence properties from model
    const phaseCompressibleTurbulenceModel& turbModel =
        db().lookupObject<phaseCompressibleTurbulenceModel>
        (
            IOobject::groupName(turbulenceModel::propertiesName, phase.name())
        );

    const scalar Cmu25 = pow025(Cmu_);

    const scalarField& y = turbModel.y()[patchi];

    const tmp<scalarField> tmuw = turbModel.mu(patchi);
    const scalarField& muw = tmuw();

    const tmp<scalarField> talphaw = phase.thermo().alpha(patchi);
    const scalarField& alphaw = talphaw();

    const tmp<volScalarField> tk = turbModel.k();
    const volScalarField& k = tk();
    const fvPatchScalarField& kw = k.boundaryField()[patchi];

    const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
    const scalarField magUp(mag(Uw.patchInternalField() - Uw));
    const scalarField magGradUw(mag(Uw.snGrad()));

    const fvPatchScalarField& rhow = turbModel.rho().boundaryField()[patchi];
    const fvPatchScalarField& hew =
        phase.thermo().he().boundaryField()[patchi];

    const fvPatchScalarField& Tw =
        phase.thermo().T().boundaryField()[patchi];

    scalarField Tp(Tw.patchInternalField());

    // Heat flux [W/m2] - lagging alphatw
    const scalarField qDot
    (
        (prevAlphat + alphaw)*hew.snGrad()
    );

    scalarField uTau(Cmu25*sqrt(kw));

    scalarField yPlus(uTau*y/(muw/rhow));

    scalarField Pr(muw/alphaw);

    // Molecular-to-turbulent Prandtl number ratio
    scalarField Prat(Pr/Prt_);

    // Thermal sublayer thickness
    scalarField P(this->Psmooth(Prat));

    scalarField yPlusTherm(this->yPlusTherm(P, Prat));

    tmp<scalarField> talphatConv(new scalarField(this->size()));
    scalarField& alphatConv = talphatConv.ref();

    // Populate boundary values
    forAll(alphatConv, facei)
    {
        // Evaluate new effective thermal diffusivity
        scalar alphaEff = 0.0;
        if (yPlus[facei] < yPlusTherm[facei])
        {
            scalar A = qDot[facei]*rhow[facei]*uTau[facei]*y[facei];
            scalar B = qDot[facei]*Pr[facei]*yPlus[facei];
            scalar C = Pr[facei]*0.5*rhow[facei]*uTau[facei]*sqr(magUp[facei]);
            alphaEff = A/(B + C + vSmall);
        }
        else
        {
            scalar A = qDot[facei]*rhow[facei]*uTau[facei]*y[facei];
            scalar B =
                qDot[facei]*Prt_*(1.0/kappa_*log(E_*yPlus[facei]) + P[facei]);
            scalar magUc =
                uTau[facei]/kappa_*log(E_*yPlusTherm[facei]) - mag(Uw[facei]);
            scalar C =
                0.5*rhow[facei]*uTau[facei]
               *(Prt_*sqr(magUp[facei]) + (Pr[facei] - Prt_)*sqr(magUc));
            alphaEff = A/(B + C + vSmall);
        }

        // Update convective heat transfer turbulent thermal diffusivity
        alphatConv[facei] = max(0.0, alphaEff - alphaw[facei]);
    }
Пример #13
0
void POS::UndoMove(int move, UNDO *u) {

  int sd  = Opp(side);
  int op  = side;
  int fsq = Fsq(move);
  int tsq = Tsq(move);
  int ftp = Tp(pc[tsq]);    // moving piece
  int ttp = u->ttp;

  castle_flags = u->castle_flags;
  ep_sq = u->ep_sq;
  rev_moves = u->rev_moves;
  pawn_key = u->pawn_key;
  hash_key = u->hash_key;
  head--;
  pc[fsq] = Pc(sd, ftp);
  pc[tsq] = NO_PC;
  cl_bb[sd] ^= SqBb(fsq) | SqBb(tsq);
  tp_bb[ftp] ^= SqBb(fsq) | SqBb(tsq);
#ifndef LEAF_PST
  mg_pst[sd] += Param.mg_pst_data[sd][ftp][fsq] - Param.mg_pst_data[sd][ftp][tsq];
  eg_pst[sd] += Param.eg_pst_data[sd][ftp][fsq] - Param.eg_pst_data[sd][ftp][tsq];
#endif

  // Update king location

  if (ftp == K) king_sq[sd] = fsq;

  // Undo capture

  if (ttp != NO_TP) {
    pc[tsq] = Pc(op, ttp);
    cl_bb[op] ^= SqBb(tsq);
    tp_bb[ttp] ^= SqBb(tsq);
    phase += phase_value[ttp];
#ifndef LEAF_PST
    mg_pst[op] += Param.mg_pst_data[op][ttp][tsq];
    eg_pst[op] += Param.eg_pst_data[op][ttp][tsq];
#endif
    cnt[op][ttp]++;
  }

  switch (MoveType(move)) {

  case NORMAL:
    break;

  case CASTLE:

    // define complementary rook move

    switch (tsq) {
      case C1: { fsq = A1; tsq = D1; break; }
      case G1: { fsq = H1; tsq = F1; break; }
      case C8: { fsq = A8; tsq = D8; break; }
      case G8: { fsq = H8; tsq = F8; break; }
    }

    pc[tsq] = NO_PC;
    pc[fsq] = Pc(sd, R);
    cl_bb[sd] ^= SqBb(fsq) | SqBb(tsq);
    tp_bb[R] ^= SqBb(fsq) | SqBb(tsq);
#ifndef LEAF_PST
    mg_pst[sd] += Param.mg_pst_data[sd][R][fsq] - Param.mg_pst_data[sd][R][tsq];
    eg_pst[sd] += Param.eg_pst_data[sd][R][fsq] - Param.eg_pst_data[sd][R][tsq];
#endif
    break;

  case EP_CAP:
    tsq ^= 8;
    pc[tsq] = Pc(op, P);
    cl_bb[op] ^= SqBb(tsq);
    tp_bb[P] ^= SqBb(tsq);
    phase += phase_value[P];
#ifndef LEAF_PST
    mg_pst[op] += Param.mg_pst_data[op][P][tsq];
    eg_pst[op] += Param.eg_pst_data[op][P][tsq];
#endif
    cnt[op][P]++;
    break;

  case EP_SET:
    break;

  case N_PROM: case B_PROM: case R_PROM: case Q_PROM:
    pc[fsq] = Pc(sd, P);
    tp_bb[P] ^= SqBb(fsq);
    tp_bb[ftp] ^= SqBb(fsq);
    phase += phase_value[P] - phase_value[ftp];
#ifndef LEAF_PST
    mg_pst[sd] += Param.mg_pst_data[sd][P][fsq] - Param.mg_pst_data[sd][ftp][fsq];
    eg_pst[sd] += Param.eg_pst_data[sd][P][fsq] - Param.eg_pst_data[sd][ftp][fsq];
#endif
    cnt[sd][P]++;
    cnt[sd][ftp]--;
    break;
  }
  side ^= 1;
}
void alphatFixedDmdtWallBoilingWallFunctionFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    // Lookup the fluid model
    const ThermalPhaseChangePhaseSystem
    <
        MomentumTransferPhaseSystem<twoPhaseSystem>
    >& fluid =
        refCast
        <
            const ThermalPhaseChangePhaseSystem
            <
                MomentumTransferPhaseSystem<twoPhaseSystem>
            >
        >
        (
            db().lookupObject<phaseSystem>("phaseProperties")
        );

    const phaseModel& liquid
    (
        fluid.phase1().name() == dimensionedInternalField().group()
      ? fluid.phase1()
      : fluid.phase2()
    );

    const label patchi = patch().index();

    // Retrieve turbulence properties from model
    const compressibleTurbulenceModel& turbModel =
        db().lookupObject<compressibleTurbulenceModel>
        (
            IOobject::groupName
            (
                compressibleTurbulenceModel::propertiesName,
                dimensionedInternalField().group()
            )
        );

    const scalar Cmu25 = pow025(Cmu_);

    const scalarField& y = turbModel.y()[patchi];

    const tmp<scalarField> tmuw = turbModel.mu(patchi);
    const scalarField& muw = tmuw();

    const tmp<scalarField> talphaw = liquid.thermo().alpha(patchi);
    const scalarField& alphaw = talphaw();

    scalarField& alphatw = *this;

    const tmp<volScalarField> tk = turbModel.k();
    const volScalarField& k = tk();
    const fvPatchScalarField& kw = k.boundaryField()[patchi];

    const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
    const scalarField magUp(mag(Uw.patchInternalField() - Uw));
    const scalarField magGradUw(mag(Uw.snGrad()));

    const fvPatchScalarField& rhow = turbModel.rho().boundaryField()[patchi];
    const fvPatchScalarField& hew =
        liquid.thermo().he().boundaryField()[patchi];

    const fvPatchScalarField& Tw =
        liquid.thermo().T().boundaryField()[patchi];

    scalarField Tp(Tw.patchInternalField());

    // Heat flux [W/m2] - lagging alphatw
    const scalarField qDot
    (
        (alphatw + alphaw)*hew.snGrad()
    );

    scalarField uTau(Cmu25*sqrt(kw));

    scalarField yPlus(uTau*y/(muw/rhow));

    scalarField Pr(muw/alphaw);

    // Molecular-to-turbulent Prandtl number ratio
    scalarField Prat(Pr/Prt_);

    // Thermal sublayer thickness
    scalarField P(this->Psmooth(Prat));

    scalarField yPlusTherm(this->yPlusTherm(P, Prat));

    scalarField alphatConv(this->size(), 0.0);

    // Populate boundary values
    forAll(alphatw, faceI)
    {
        // Evaluate new effective thermal diffusivity
        scalar alphaEff = 0.0;
        if (yPlus[faceI] < yPlusTherm[faceI])
        {
            scalar A = qDot[faceI]*rhow[faceI]*uTau[faceI]*y[faceI];
            scalar B = qDot[faceI]*Pr[faceI]*yPlus[faceI];
            scalar C = Pr[faceI]*0.5*rhow[faceI]*uTau[faceI]*sqr(magUp[faceI]);
            alphaEff = A/(B + C + VSMALL);
        }
        else
        {
            scalar A = qDot[faceI]*rhow[faceI]*uTau[faceI]*y[faceI];
            scalar B =
                qDot[faceI]*Prt_*(1.0/kappa_*log(E_*yPlus[faceI]) + P[faceI]);
            scalar magUc =
                uTau[faceI]/kappa_*log(E_*yPlusTherm[faceI]) - mag(Uw[faceI]);
            scalar C =
                0.5*rhow[faceI]*uTau[faceI]
               *(Prt_*sqr(magUp[faceI]) + (Pr[faceI] - Prt_)*sqr(magUc));
            alphaEff = A/(B + C + VSMALL);
        }

        // Update convective heat transfer turbulent thermal diffusivity
        alphatConv[faceI] = max(0.0, alphaEff - alphaw[faceI]);
    }
Пример #15
0
void TpSDF(double Psi[], double p[], double filling, double newPsi [], int domain[]) 
{
     Tp(Psi, p, filling, newPsi, domain);
     scaleLevelSetFunction(newPsi, p[3]);
}
Пример #16
0
      Tp operator()(const Tp& x) const
      {
	return std::min(std::max(x, Tp(0)), Tp(50));
      }
void PiersonMoskowitz::set( Ostream& os )
{
    // Get the input parameters
    scalar Hs(readScalar(dict_.lookup("Hs")));

    scalar Tp(readScalar(dict_.lookup("Tp")));

    scalar depth(readScalar(dict_.lookup("depth")));

    vector direction(vector(dict_.lookup("direction")));

    label N = readLabel(dict_.lookup("N"));

    // Calculate the frequency axis
    autoPtr<Foam::frequencyAxis> fA = Foam::frequencyAxis::New(rT_, dict_);
    scalarField nodeFrequency(N + 1, 0);

    // An intermediate step needed for certain discretisation types
    // Placed in scopes such that the temporary variables to not 'survive'
    {
        equidistantFrequencyAxis equiFA(rT_, dict_);

        scalarField tempFreqAxis = equiFA.freqAxis(10000);
        scalarField tempSpectrum
            = this->spectralValue(Hs, Tp, tempFreqAxis);

        nodeFrequency = fA->freqAxis(tempFreqAxis, tempSpectrum, N);
    }

    // Prepare variables
    freq_.setSize(N);
    amp_.setSize(N);
    phi_.setSize(N);
    k_.setSize(N);

    // Compute spectrum
    scalarField S = this->spectralValue(Hs, Tp, nodeFrequency);

    // Prepare stokesFirst to compute wave numbers
    Foam::stokesFirstProperties stp( rT_, dict_ );

    // Compute return variables
    for (int i = 1; i < N + 1; i++)
    {
        // The frequency is the mid-point between two nodes
        freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]);

        // Amplitude is the square root of the trapezoidal integral
        amp_[i - 1] =
            Foam::sqrt
            (
                (S[i-1] + S[i])
               *(nodeFrequency[i] - nodeFrequency[i - 1])
            );

        // Wave number based on linear wave theory
        k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]);

        // The phase is computed based on the phase-function
        phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]);
    }

    writeSpectrum(os, nodeFrequency, S);
}
Пример #18
0
 /**
  * A constructor.
  *
  * @param value an optional value of type POD to be given at initialization.
  */
 ipod(Tp value = Tp()) :
     _M_value(value)
 {}
Пример #19
0
  void
  test(Tp proto = Tp{})
  {
    const auto _S_max_log = __gnu_cxx::__log_max(proto);

    std::cout.precision(__gnu_cxx::__digits10(proto));
    auto w = 8 + std::cout.precision();
    __gnu_cxx::_BasicSum<Tp> BS;
    __gnu_cxx::_AitkenDeltaSquaredSum<__gnu_cxx::_BasicSum<Tp>> ABS;
    __gnu_cxx::_AitkenDeltaSquaredSum<__gnu_cxx::_KahanSum<Tp>> AKS;
    __gnu_cxx::_WinnEpsilonSum<__gnu_cxx::_BasicSum<Tp>> WBS;
    __gnu_cxx::_WinnEpsilonSum<__gnu_cxx::_KahanSum<Tp>> WKS;
    __gnu_cxx::_BrezinskiThetaSum<__gnu_cxx::_BasicSum<Tp>> BTS;
    __gnu_cxx::_LevinTSum<__gnu_cxx::_BasicSum<Tp>> LTS;
    __gnu_cxx::_WenigerDeltaSum<__gnu_cxx::_BasicSum<Tp>> WDS;
    __gnu_cxx::_WenigerDeltaSum<__gnu_cxx::_VanWijngaardenSum<Tp>> WDvW;

    auto s = Tp{1.2};
    auto zetaterm = [s, _S_max_log](std::size_t k)
		    -> Tp
		    { return (s * std::log(Tp(k + 1)) < _S_max_log ? std::pow(Tp(k + 1), -s) : Tp{0}); };

    auto VwT = __gnu_cxx::_VanWijngaardenCompressor<decltype(zetaterm)>(zetaterm);

    //auto zeta = Tp{5.591582441177750776536563193423143277642L};
    std::cout << "\n\nzeta(1.2) = 5.59158244117775077653\n";
    std::cout << std::setw(w) << "k"
	      << std::setw(w) << "Basic"
	      << std::setw(w) << "Aitken-Basic"
	      << std::setw(w) << "Aitken-Kahan"
	      << std::setw(w) << "Winn-Basic"
	      << std::setw(w) << "Winn-Kahan"
	      << std::setw(w) << "BrezinskiT-Basic"
	      << std::setw(w) << "LevinT-Basic"
	      << std::setw(w) << "WenigerD-Basic"
	      << std::setw(w) << "WenigerD-vW"
	      << '\n';
    std::cout << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << '\n';
    for (auto k = 0; k < 100; ++k)
      {
	auto term = std::pow(Tp(k + 1), -s);
	BS += term;
	ABS += term;
	AKS += term;
	WBS += term;
	WKS += term;
	BTS += term;
	LTS += term;
	WDS += term;
	WDvW += VwT[k];
	std::cout << std::setw(w) << k
		  << std::setw(w) << BS()
		  << std::setw(w) << ABS()
		  << std::setw(w) << AKS()
		  << std::setw(w) << WBS()
		  << std::setw(w) << WKS()
		  << std::setw(w) << BTS()
	  	  << std::setw(w) << LTS()
	  	  << std::setw(w) << WDS()
	  	  << std::setw(w) << WDvW()
		  << '\n';
      }

    // 2F0(1,1;;-1/3)
    std::cout << "\n\n2F0(1,1;;-1/3) = 0.78625122076596\n";
    auto a = Tp{1};
    auto b = Tp{1};
    auto z = Tp{-1} / Tp{3};
    auto term = Tp{1};
    BS.reset(term);
    ABS.reset(term);
    AKS.reset(term);
    WBS.reset(term);
    WKS.reset(term);
    BTS.reset(term);
    LTS.reset(term);
    WDS.reset(term);
    std::cout << std::setw(w) << "k"
	      << std::setw(w) << "Basic"
	      << std::setw(w) << "Aitken-Basic"
	      << std::setw(w) << "Aitken-Kahan"
	      << std::setw(w) << "Winn-Basic"
	      << std::setw(w) << "Winn-Kahan"
	      << std::setw(w) << "BrezinskiT-Basic"
	      << std::setw(w) << "LevinT-Basic"
	      << std::setw(w) << "WenigerD-Basic"
	      << '\n';
    std::cout << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << std::setw(w) << "----------------"
	      << '\n';
    for (auto k = 1; k < 100; ++k)
      {
	std::cout << std::setw(w) << (k - 1)
		  << std::setw(w) << BS()
		  << std::setw(w) << ABS()
		  << std::setw(w) << AKS()
		  << std::setw(w) << WBS()
		  << std::setw(w) << WKS()
		  << std::setw(w) << BTS()
		  << std::setw(w) << LTS()
		  << std::setw(w) << WDS()
		  << '\n';
	term *= (a + k - 1) * (b + k - 1) * z / k;
	BS += term;
	ABS += term;
	AKS += term;
	WBS += term;
	WKS += term;
	BTS += term;
	LTS += term;
	WDS += term;
      }
  }
Пример #20
0
void SetPosition(POS *p, char *epd) {

  int j, pc;
  static const char pc_char[13] = "PpNnBbRrQqKk";

  for (int sd = 0; sd < 2; sd++) {
    p->cl_bb[sd] = 0ULL;
#ifndef LEAF_PST
    p->mg_pst[sd] = 0;
    p->eg_pst[sd] = 0;
#endif
  }

  p->phase = 0;

  for (int pc = 0; pc < 6; pc++) {
    p->tp_bb[pc] = 0ULL;
    p->cnt[WC][pc] = 0;
    p->cnt[BC][pc] = 0;
  }

  p->castle_flags = 0;
  p->rev_moves = 0;
  p->head = 0;

  for (int i = 56; i >= 0; i -= 8) {
    j = 0;
    while (j < 8) {
      if (*epd >= '1' && *epd <= '8')
        for (pc = 0; pc < *epd - '0'; pc++) {
          p->pc[i + j] = NO_PC;
          j++;
        }
      else {
        for (pc = 0; pc_char[pc] != *epd; pc++)
          ;
        p->pc[i + j] = pc;
        p->cl_bb[Cl(pc)] ^= SqBb(i + j);
        p->tp_bb[Tp(pc)] ^= SqBb(i + j);
        
        if (Tp(pc) == K)
          p->king_sq[Cl(pc)] = i + j;

        p->phase += phase_value[Tp(pc)];
#ifndef LEAF_PST
        p->mg_pst[Cl(pc)] += Param.mg_pst_data[Cl(pc)][Tp(pc)][i + j];
        p->eg_pst[Cl(pc)] += Param.eg_pst_data[Cl(pc)][Tp(pc)][i + j];
#endif
        p->cnt[Cl(pc)][Tp(pc)]++;
        j++;
      }
      epd++;
    }
    epd++;
  }

  // Setting side to move

  if (*epd++ == 'w') p->side = WC;
  else               p->side = BC;

  // Setting castling rights

  epd++;
  if (*epd == '-')
    epd++;
  else {
    if (*epd == 'K') {
      p->castle_flags |= 1;
      epd++;
    }
    if (*epd == 'Q') {
      p->castle_flags |= 2;
      epd++;
    }
    if (*epd == 'k') {
      p->castle_flags |= 4;
      epd++;
    }
    if (*epd == 'q') {
      p->castle_flags |= 8;
      epd++;
    }
  }

  // Setting en passant square (only if capture is possible)

  epd++;
  if (*epd == '-')
    p->ep_sq = NO_SQ;
  else {
    p->ep_sq = Sq(*epd - 'a', *(epd + 1) - '1');
    if (!(BB.PawnAttacks(Opp(p->side), p->ep_sq) & p->Pawns(p->side)))
      p->ep_sq = NO_SQ;
  }

  // Calculating hash keys

  p->hash_key = InitHashKey(p);
  p->pawn_key = InitPawnKey(p);
}