Example #1
0
std::string* alltihop(int* kassa, std::string katalogisering) {
  if (*kassa > 4 || katalogisering == "kedja")
    return new std::string("kinesiska");
  int kattunge = *kassa + 1;
  std::string* kista = new std::string("klack");
  int* kjol = anpassning(kattunge, kista);
  std::string* kladd = new std::string("klappning");
  int* klapp = anslagstavla(kattunge, kladd);
  std::string* klase = new std::string("klick");
  int* klassificering = alldeles(kattunge, klase);
  std::string klippa("klokera");
  std::string* klocka = alm(&kattunge, klippa);
  std::string* klubb = new std::string("klump");
  int* klubba = algebra(kattunge, klubb);
  std::string* klunga = new std::string("klut");
  int* klunk = anspelning(kattunge, klunga);
  std::string* klyfta = new std::string("klyscha");
  return klyfta;
} // alltihop
Example #2
0
int allteftersom(int* initiering, std::string inklusive) {
  if (*initiering > 6 || inklusive == "inkopiering")
    return 24979;
  int inkommande = *initiering + 1;
  std::string inkoppling("inledning");
  std::string* inlandsis = anledning(&inkommande, inkoppling);
  std::string inmatning("innantill");
  int innan = anknytning(&inkommande, inmatning);
  std::string* inne = new std::string("innerst");
  int* inneha = aj(inkommande, inne);
  std::string* inom = new std::string("inriktning");
  int* inomhus = algebra(inkommande, inom);
  std::string* insamling = new std::string("inskjutning");
  int* insida = anhopning(inkommande, insamling);
  std::string inskrivning("instantiering");
  int inspelning = annars(&inkommande, inskrivning);
  std::string* inte = new std::string("internationalisering");
  int* integrering = anpassning(inkommande, inte);
  int intet(24833);
  return intet;
} // allteftersom
Example #3
0
int main() {

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

  simu.read();

  create();
  
  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 particles " << endl;

    number(Tp);
    number(Tm);
  }

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

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

  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 );
  
  // every step
  areas(Tp);
  quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );

  // 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 is, 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);
  
  cout << "Assigning velocities to 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

// #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 );
  move_info( Tp );

  draw(Tm, mesh_file     , true);
  draw(Tp, particle_file , true);

  // return 1;
  
  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);
    move_info(Tp);
    
    // iter loop
    for( ; ; iter++) {
      
      // comment for no move.-
      cout << "Moving half step " << endl;
      FT d0;

      displ = move( Tp , dt2 , d0 );

      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 );

// Search "FLIPincr" in CH_FFT.cpp to change accordingly!
// 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

    move_info( Tm );
    move_info( Tp );

    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() );
    }

    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;

}
Example #4
0
int main() {

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

  simu.read();

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

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

    cout << "Creating alpha field " << endl;
    
    set_alpha_random(  Tm ) ;
    //set_alpha_cos( Tm );
    
    cout << "Numbering particles " << endl;

    number(Tp);
    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_alpha_on_fft( Tm , fft );

  fft.all_fields();

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

  fft.draw( "mu", 0, fft.field_mu() );

  fft.draw( "grad_mu_x", 0, fft.field_grad_mu_x() );

  fft.draw( "grad_mu_y", 0, fft.field_grad_mu_y() );

  fft.draw( "force_x", 0, fft.field_force_x() );

  fft.draw( "force_y", 0, fft.field_force_y() );

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

  fft.draw( "vel_y", 0, fft.field_vel_y() );
  
  load_fields_from_fft( fft, Tm );
  
  // every step
  areas(Tp);
  quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );

  // 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 is, 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);
  
  cout << "Assigning alpha to particles " << endl;


#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

// #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 );
  move_info( Tp );

  draw(Tm, mesh_file     , true);
  draw(Tp, particle_file , true);

  //  return 1;
  
  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=5; //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);
    move_info(Tp);

    // iter loop
    for( ; iter<max_iter ; iter++) {

      // comment for no move.-
      displ = move( Tp , dt2 );

      cout << "Iter " << iter << " , moved avg " << displ << " to half point" << endl;

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

      if( (displ < max_displ) && (iter !=0) ) break;

      areas(Tp);
      quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
       
      cout << "Proj U0, alpha0 onto mesh " << endl;

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

      load_alpha_on_fft( Tm , fft );

      fft.all_fields();
  
      FT b = Db*dt2;

      fft.evolve( b );
      
      load_fields_from_fft( fft, Tm );

      cout << "Proj U, alpha from mesh " << endl;
      
#if defined FULL_FULL
      {
	Delta(Tp);
	linear algebra_p(Tp);
	from_mesh_full_v(Tm, Tp, algebra_p , kind::U);
	from_mesh_full( Tm , Tp ,  algebra_p,kind::ALPHA);
      }
#elif defined FULL_LUMPED
      from_mesh_lumped( Tm , Tp , kind::ALPHA);
      from_mesh_lumped_v(Tm, Tp, kind::U);
#elif defined FLIP
      from_mesh(Tm , Tp , kind::ALPHA);
      from_mesh_v(Tm, Tp, kind::U);
#else
      from_mesh(Tm , Tp , kind::ALPHA);
      from_mesh_v(Tm, Tp, kind::U);
#endif

      
      // // substract spurious overall movement.-      

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

    } // iter loop

      // comment for no move.-

    displ=move( Tp , dt );

    update_half_velocity( Tp , false );

      // 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() );
    }

    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;

}
Example #5
0
int main() {

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

  simu.read();

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

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

    cout << "Creating alpha field " << endl;
    
    set_alpha_random(  Tp ) ;

    cout << "Numbering particles " << endl;

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

  // volumes(Tp, simu.FEMp() );
  // Delta(Tp);

  // linear algebra(Tp);

  // if(simu.create_points()) {
  //   nabla(Tp);
  //   Delta(Tp);
  // }
  
  move_info( Tp );

  // /// Prev test begin
  //cout << "Calculating Lapl U" << endl;
  //algebra.laplacian_v(kind::UOLD,kind::LAPLU);

  //FT dt=simu.dt();

  //cout << "Calculating Ustar implicitely" << endl;
	  //algebra.ustar_inv(kind::USTAR,  dt , kind::UOLD, false);

  //cout << "Solving PPE" << endl;
  //algebra.PPE( kind::USTAR, dt, kind:: P );

  //cout << "Calculating grad p" << endl;
  //algebra.gradient(kind::P, kind::GRADP);
  //algebra.mass_s(kind::DIVU);

  
//draw();
//  return 1;

   /// Prev test end

#ifdef WRITE
  algebra.save_matrices();
#endif

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

      // nabla(Tp);
      // Delta(Tp);


      // linear algebra(Tp);

      // cout << "Calculating grad alpha" << endl;
      // algebra.gradient(kind::ALPHA, kind::GRADALPHA);
  
  const std::string particle_file("particles.dat");

  draw(Tp, particle_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=1; //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(Tp);

    // iter loop
    for( ; iter<max_iter ; iter++) {

      cout << "Move iteration  " << iter << " of " << max_iter << " " << endl;

      // comment for no move.-
      displ=move( Tp , dt2 );

      cout << "Iter " << iter << " , moved avg " << displ << " to half point" << endl;

      if( (displ < max_displ) && (iter !=0) ) break;

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

      nabla(Tp);
      Delta(Tp);

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

      //      set_forces_Kolmo(Tp);

//  Reynolds number discrimination



#ifdef EXPLICIT

	cout << "Calculating Ustar explicitely" << endl;

	algebra.laplacian_v(kind::UOLD,kind::LAPLU);

	u_star(Tp, dt2 , false );

#else

//	cout << "Calculating chem pot" << endl;

//	algebra.chempot(kind::ALPHA, kind::CHEMPOT);

	cout << "Calculating alpha implicitely" << endl;

	// partly explicit ( unstable ? ):
	cout << "Calculating chem pot explicitely" << endl;

        if (iter==0)
	  algebra.chempot( kind::ALPHA0, kind::CHEMPOT );
	else
	 algebra.chempot( kind::ALPHA , kind::CHEMPOT );

	// inner iter loop

	for( int alpha_it=0 ; alpha_it < 1 ; alpha_it++) { // max_iter ; alpha_it++) {

	  cout << "Alpha loop iter " << alpha_it << endl;

	  algebra.chempot( kind::ALPHA , kind::CHEMPOT );
	  algebra.alpha_inv_cp(kind::ALPHA, dt2 , kind::ALPHA0 );

	}



	//	algebra.gradient(kind::ALPHA, kind::ALPHA0); // ???
	
	// // iterative, fully implicit (does not converge):
	
	// int alpha_it=0;
	
	//     // inner iter loop
	// for( ; alpha_it < 10 ; alpha_it++) { // max_iter ; alpha_it++) {

	//   cout << "Alpha loop iter " << alpha_it << endl;
	  
	//   algebra.alpha_inv_cp2(kind::ALPHA, dt2 , kind::ALPHA0 );
    
	//   cout << "Calculating chem pot implicitely" << endl;
	//   algebra.chempot_inv(kind::ALPHA, dt2 , kind::ALPHA0 );
	// }
	// //	draw(Tp, particle_file , true);

	
	cout << "Settinf Ustar = force" << endl;

	//	algebra.ustar_is_force(kind::USTAR);

	algebra.chem_pot_force();

	// substract spurious overall movement.-
	
	zero_mean_v( Tp , kind::FORCE);

#endif

	cout << "Solving PPE" << endl;

	// comment for no move.-
	algebra.PPE( kind::FORCE , 1 , kind:: P ); // Dt set to 1

	// cout << "Calculating grad p" << endl;
	// // comment for no move.-
	// algebra.gradient(kind::P, kind::GRADP);

	algebra.u_inv_od(kind::U);
	
	cout << "Evolving U " << endl;

	// comment for no move.-
	u_new( Tp , dt2 );

	cout << "U evolved " << endl;

    } // iter loop

    // comment for no move.-
    displ=move( Tp , dt );
    
//    update_half_velocity( Tp , false ); 

    // 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() );

    if(simu.current_step()%simu.every()==0)
      draw(Tp, particle_file , true);

    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;

}
Example #6
0
int main() {

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

  simu.read();

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

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

    cout << "Creating alpha field " << endl;
    
    //    set_alpha_random(  Tp ) ; // better take it from mesh
    set_alpha_random(  Tm ) ;

    cout << "Numbering particles " << endl;

    number(Tp);
    number(Tm);
  }


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

  // just once!
  linear algebra(Tm);

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

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

  if(simu.create_points()) {
    nabla(Tm);
    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);
  
  cout << "Assigning alpha to particles " << endl;
 
#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 );
  move_info( Tp );

  // algebra.chempot( kind::ALPHA , kind::CHEMPOT );
  // algebra.alpha_inv_cp(kind::ALPHA, simu.dt()/2.0 , kind::ALPHA0 );

  // draw(Tm, mesh_file     , true);
  // draw(Tp, particle_file , true);

 
  // /// Prev test begin
  //cout << "Calculating Lapl U" << endl;
  //algebra.laplacian_v(kind::UOLD,kind::LAPLU);

  //FT dt=simu.dt();

  //cout << "Calculating Ustar implicitely" << endl;
	  //algebra.ustar_inv(kind::USTAR,  dt , kind::UOLD, false);

  //cout << "Solving PPE" << endl;
  //algebra.PPE( kind::USTAR, dt, kind:: P );

  //cout << "Calculating grad p" << endl;
  //algebra.gradient(kind::P, kind::GRADP);
  //algebra.mass_s(kind::DIVU);

  
//draw();
//  return 1;

   /// Prev test end

#ifdef WRITE
  algebra.save_matrices();
#endif

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

      // nabla(Tp);
      // Delta(Tp);


      // linear algebra(Tp);

      // cout << "Calculating grad alpha" << endl;
      // algebra.gradient(kind::ALPHA, kind::GRADALPHA);

  draw(Tm, mesh_file     , true);
  draw(Tp, particle_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  = 10; //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);
    move_info(Tp);

//     cout << "Proj alpha onto mesh " << endl;

//       //onto_mesh_lumped();
// #if defined FULL
//     onto_mesh_full( Tp , Tm , algebra, kind::ALPHA);
// #elif defined FLIP
//     flip_volumes(Tp , Tm , simu.FEMm() );
//     onto_mesh_flip(Tp,Tm,simu.FEMm(),kind::ALPHA);
// #else
//     onto_mesh_delta(Tp,Tm,kind::ALPHA);
// #endif
  
    // iter loop
    for( ; iter<max_iter ; iter++) {

      //      cout << "Projecting U from mesh " << endl;
      cout << "Projecting U , alpha0 from mesh " << endl;

#if defined FULL_FULL
      {
	Delta(Tp);
	linear algebra_p(Tp);
	from_mesh_full_v(Tm, Tp, algebra_p , kind::U);
	from_mesh_full  (Tm, Tp, algebra_p , kind::ALPHA0);
	from_mesh_full  (Tm, Tp, algebra_p , kind::ALPHA);
      }
#elif defined FULL_LUMPED
      from_mesh_lumped_v(Tm, Tp, kind::U);
      from_mesh_lumped  (Tm, Tp, kind::ALPHA0);
      from_mesh_lumped  (Tm, Tp, kind::ALPHA);
#elif defined FLIP
      from_mesh_v(Tm, Tp, kind::U);
      from_mesh  (Tm, Tp, kind::ALPHA0);
      from_mesh  (Tm, Tp, kind::ALPHA);
#else
      from_mesh_v(Tm, Tp, kind::U);
      from_mesh  (Tm, Tp, kind::ALPHA0);
      from_mesh  (Tm, Tp, kind::ALPHA);
#endif
      
      // comment for no move.-
      displ=move( Tp , dt2 );

      cout << "Iter " << iter << " , moved avg " << displ << " to half point" << endl;

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

      if( (displ < max_displ) && (iter !=0) ) break;

      areas(Tp);
      quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
      
      cout << "Proj U0, alpha0 onto mesh " << endl;

#if defined FULL
      onto_mesh_full_v(Tp,Tm,algebra,kind::UOLD);
      onto_mesh_full  (Tp,Tm,algebra,kind::ALPHA0);
      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::UOLD);
      onto_mesh_flip  (Tp,Tm,simu.FEMm(),kind::ALPHA0);
      onto_mesh_flip  (Tp,Tm,simu.FEMm(),kind::ALPHA);
#else
      onto_mesh_delta_v(Tp,Tm,kind::UOLD);
      onto_mesh_delta  (Tp,Tm,kind::ALPHA0);
      onto_mesh_delta  (Tp,Tm,kind::ALPHA);
#endif

     
//  Reynolds number discrimination

// #ifdef EXPLICIT

// 	cout << "Calculating Ustar explicitely" << endl;

// 	algebra.laplacian_v(kind::UOLD,kind::LAPLU);

// 	u_star(Tp, dt2 , false );

// #else

//	cout << "Calculating chem pot" << endl;

//	algebra.chempot(kind::ALPHA, kind::CHEMPOT);

//      cout << "Calculating alpha implicitely" << endl;
      //

      // partly explicit ( unstable ? ):
      cout << "Calculating chem pot explicitely" << endl;

      // inner iter loop

      for( int alpha_it=0 ; alpha_it < 1 ; alpha_it++) { // max_iter ; alpha_it++) {

	cout << "Alpha loop iter " << alpha_it << endl;
	if (iter==0)
	  algebra.chempot( kind::ALPHA0, kind::CHEMPOT );
	else
	  algebra.chempot( kind::ALPHA , kind::CHEMPOT );
	
      //	algebra.chempot( kind::ALPHA , kind::CHEMPOT );
	algebra.alpha_inv_cp(kind::ALPHA, dt2 , kind::ALPHA0 );

      }


	//	algebra.gradient(kind::ALPHA, kind::ALPHA0); // ???
	
	// // iterative, fully implicit (does not converge):
	
	// int alpha_it=0;
	
	//     // inner iter loop
	// for( ; alpha_it < 10 ; alpha_it++) { // max_iter ; alpha_it++) {

	//   cout << "Alpha loop iter " << alpha_it << endl;
	  
	//   algebra.alpha_inv_cp2(kind::ALPHA, dt2 , kind::ALPHA0 );
    
	//   cout << "Calculating chem pot implicitely" << endl;
	//   algebra.chempot_inv(kind::ALPHA, dt2 , kind::ALPHA0 );
	// }
	// //	draw(Tp, particle_file , true);
	
	cout << "Calculating Ustar implicitely" << endl;

	//	algebra.ustar_inv(kind::USTAR,  dt2 , kind::UOLD, false , false);

	// comment for no move.-
	algebra.ustar_inv_cp(kind::USTAR,  dt2 , kind::UOLD, is_overdamped , false);

	// substract spurious overall movement.-
	
	zero_mean_v( Tp , kind::USTAR);

	//#endif

	cout << "Solving PPE" << endl;

	// comment for no move.-
	algebra.PPE( kind::USTAR, dt2 , kind:: P );

	cout << "Calculating grad p" << endl;
	// comment for no move.-
	algebra.gradient(kind::P, kind::GRADP);

	cout << "Evolving U " << endl;

	// comment for no move.-
	u_new( Tm , dt2 );

	cout << "U evolved " << endl;

    } // iter loop

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

      // comment for no move.-
    displ=move( Tp , dt );
    
//    update_half_velocity( Tp , false ); 

    // 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() );

    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::ALPHA0);
    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::ALPHA0);
    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);
    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);
    }

    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;

}