Exemple #1
0
int main(int argc, char **argv)
{
  
  DataCube dc(2); // datacube of dimension 2

  Vector<int> size(2); 
  size[1] = 5; // range of datacube in x-direction
  size[2] = 5; // range of datacube in y-direction

  Vector<double> spaceing(2);
  spaceing[1]=1.0;
  spaceing[2]=1.0;

  dc.SetCubeSizeAndSpaceing(size,spaceing); 
  dc.MallocCube();

  // define the dataarray
  for ( int i = 0; i < size[1]; i++ ){
    for ( int j = 0; j < size[2]; j++ ){

      if (  ( i == 2 ) || ( ( i > 1 ) && ( j == 2 ) ) )
	dc(i,j) = 1.0;

    } 
  }

  // test the calculation of moments

  //define volume
  Volume vol(0, 0, 0, 5, 5, spaceing[1], spaceing[2]);

  Moments mom(&dc);

  Vector<double> fp(2);
  int code = mom.focal_point( fp, vol );
  if ( code ) cout << errorCode(code);

  cout << "focal point: ( " << fp[1] << " " << fp[2] << " )" << endl;

  // caluclulate inertian tensor
  Vector<double> i_t(4);
  code = mom.inertian_tensor(i_t, vol );
  if ( code ) cout << errorCode(code);

  cout << "inertian tensor: ( " << i_t[1] << " " << i_t[2] << " )" << endl;
  cout << "                 ( " << i_t[3] << " " << i_t[4] << " )" << endl;

   // calculate inertian values

  Vector<double> ew(2);
  Vector<double> ev(4);
  code = mom.inertian_values(ew,ev,vol);
  if ( code ) cout << errorCode(code);

  cout << "eigenvektor: ( " << ev[1] << " " << ev[2] << " )" << endl;
  cout << "dazu eigenwert: " << ew[1] << endl;
  cout << "eigenvektor: ( " << ev[3] << " " << ev[4] << " )" << endl;
  cout << "dazu eigenwert: " << ew[2] << endl;
 
}
Exemple #2
0
void CFDDataPack::reinitViscous()
{
	grad_rho = duh[0];
	grad_mom = RealTensor(duh[1], duh[2], duh[3]);

	for (int a = 0; a < 3; ++a)
		for (int b = 0; b < 3; ++b)
			grad_vel(a, b) = (grad_mom(a, b) - vel(a)*grad_rho(b))/r;

	tau = grad_vel + grad_vel.transpose();
	vel_div =  grad_vel.tr();
	tau(0, 0) -= 2./3*vel_div; tau(1, 1) -= 2./3*vel_div; tau(2, 2) -= 2./3*vel_div;

	if(_cfd_problem._vis_type == 0) vis = 0.0;
	else if(_cfd_problem._vis_type == 1) vis = 1.0;
	else if(_cfd_problem._vis_type == 2)
	{
		Real t_ref(288), t_s(110.4);
		vis = pow(t/t_ref, 1.5)*(t_ref+t_s)/(t+t_s);
	}
	else mooseError("不可知的粘性模型");
	tau *= vis/_reynolds;

	grad_enthalpy = (duh[4]-uh[4]/uh[0] * duh[0])/r - grad_vel.transpose() * vel;
	grad_enthalpy *= (vis/_reynolds)*(_gamma/_prandtl);

	invis_flux[0] = r*vel;

	invis_flux[1] = mom(0)*vel;
	invis_flux[1](0) += p;

	invis_flux[2] = mom(1)*vel;
	invis_flux[2](1) += p;

	invis_flux[3] = mom(2)*vel;
	invis_flux[3](2) += p;

	invis_flux[4] = r*h*vel;

	vis_flux[0].zero();
	vis_flux[1] = tau.row(0);
	vis_flux[2] = tau.row(1);
	vis_flux[3] = tau.row(2);
	vis_flux[4] = tau * vel + grad_enthalpy;
}
Particle::Particle(const std::string& name, const double px, const double py, const double pz)
  : pdg_code_(ParticleInfo::Instance().getPDGCode(name)),
    name_(name),
    mass_(ParticleInfo::Instance().getMassGeV(pdg_code_)),
    charge_(ParticleInfo::Instance().getCharge(pdg_code_)),
    momentum_(mass_, ThreeVector())
{
  ThreeVector mom(px, py, pz);
  this->setThreeMomentum(mom);
}
Exemple #4
0
TEST(Individual, Insert){
  Individual mom("07243165");

  Individual Child1 = mom; Child1.insert(0, 7);
  Individual Child2 = mom; Child2.insert(7, 0);
  Individual Child3 = mom; Child3.insert(2, 5);

  ASSERT_EQ(Individual("72431650"), Child1);
  ASSERT_EQ(Individual("50724316"), Child2);
  ASSERT_EQ(Individual("07431265"), Child3);
}
Exemple #5
0
void CFDDataPack::reinitInviscous()
{
	r = uh[0];
	mom(0) = uh[1]; mom(1) = uh[2]; mom(2) = uh[3]; mom_size = mom.size();
	re = uh[4];
	vel = mom/r; vel_size = vel.size();

	p = (_gamma-1) * (fabs(uh[4]) - 0.5*(uh[1]*uh[1] + uh[2]*uh[2] + uh[3]*uh[3])/uh[0]);
	t = _gamma*_mach*_mach*p/uh[0];
	h = (fabs(uh[4]) + p)/uh[0];
	s = p/pow(r, _gamma);
	c = sqrt(fabs(_gamma*p/r));
	m = vel_size/c;

	invis_flux[0] = r*vel;

	invis_flux[1] = mom(0)*vel;
	invis_flux[1](0) += p;

	invis_flux[2] = mom(1)*vel;
	invis_flux[2](1) += p;

	invis_flux[3] = mom(2)*vel;
	invis_flux[3](2) += p;

	invis_flux[4] = r*h*vel;
}
Exemple #6
0
TEST(UX, Crossover){
  Individual mom("02134");
  Individual dad("41302");

  std::vector<int> indices;
  indices.push_back(1);
  indices.push_back(3);

  UX ux(2);
  Individual child = ux.cross(indices, &dad, &mom);
  
  ASSERT_EQ(Individual("31204"), child);
  ASSERT_EQ(&dad, child.parent(0));
  ASSERT_EQ(&mom, child.parent(1));
}
Exemple #7
0
int main(int argc, char **argv)
{

  DataCube dc(3); // datacube of dimension 2
  Vector<int> size(3); 
  size[1]= 33; // range of datacube in x-direction
  size[2]= 33; // range of datacube in y-direction
  size[3]= 33; // range of datacube in z-direction
  Vector<double> spaceing(3);
  spaceing[1]=1.0;
  spaceing[2]=1.0;
  spaceing[3]=1.0;

  dc.SetCubeSizeAndSpaceing(size,spaceing); 
  dc.MallocCube();

  // define the dataarray
  for ( int k = 0; k < size[3]; k++ ){
    for ( int j = 0; j < size[2]; j++ ){
      for ( int i = 0; i < size[1]; i++ ){

	 if (  
	     ( j == 16 ) 
	     && 
	        ( k == i )
	     && ( ( i < 16 ) || ( i > 18 ) )
	     
	     )
	dc(i,j,k) = 1.0;
	 else dc(i,j,k) = 0.0;
	
      } 
    } 
  }

 // test the calculation of moments

  Moments mom(&dc);
 
  int intsize = 5;
  //define volume
  Volume vol(1, 3, intsize,intsize,intsize );
  cout << "Integration auf Kugel" << endl;
  cout << "Radius = " << intsize << endl;

  int code;

 //  // calculate mass 

 //  cout << "calculate mass" << endl;

//   MassIntegrant mass;
//   Integration m(&dc,&mass);

//   double mass_res = 0.0;
//   code = m.execute(mass_res, vol );
//   if ( code ) cout << errorCode(code);

//   cout << "mass: " << mass_res << endl;

//   //calculate focal point

//   cout << "calculate focal point" << endl;

//   Vector<double> fp(3);
 
//   code = mom.focal_point(fp, vol );
//   if ( code ) cout << errorCode(code);

//   cout << "focal point: ( " << fp[1] << ", " << fp[2] << ", " << fp[3] <<" )" << endl;


// //   // caluclulate inertian tensor

//   cout << "calculate inertian tensor" << endl;

//   Vector<double> i_t(9);
//   code = mom.inertian_tensor(i_t, vol );
//   if ( code ) cout << errorCode(code);

//   cout << "inertian tensor: ( " << i_t[1] << " " << i_t[2] << " " << i_t[3] << " )" << endl;
//   cout << "                 ( " << i_t[4] << " " << i_t[5] << " " << i_t[6] << " )" << endl;
//   cout << "                 ( " << i_t[7] << " " << i_t[8] << " " << i_t[9] << " )" << endl;


//   // calculate inertian values

//   cout << "calculate inertian values" << endl;

//   Vector<double> ew(3);
//   Vector<double> ev(9);

//   code = mom.inertian_values(ew,ev,vol);
//   if ( code ) cout << errorCode(code);

//   cout << "Traegheitswerte am Punkt (3,3,3): " << endl;

//   cout << "eigenvektor: ( " << ev[1] << " " << ev[2] << " " << ev[3] << " )" << endl;
//   cout << "dazu eigenwert: " << ew[1] << endl;
//   cout << "eigenvektor: ( " << ev[4] << " " << ev[5] << " " << ev[6] << " )" << endl;
//   cout << "dazu eigenwert: " << ew[2] << endl;
//   cout << "eigenvektor: ( " << ev[7] << " " << ev[8] << " " << ev[9] << " )" << endl;
//   cout << "dazu eigenwert: " << ew[3] << endl;


  // calculate inertian values all over the datacube

  cout << "calculate inertian values all over the datacube" << endl;

  int DataSize = dc.GetSize()[1]*dc.GetSize()[2]*dc.GetSize()[3];

  Vector<double> *vals = new Vector<double>[DataSize](3);
 
  Vector<double> *vects = new Vector<double>[DataSize](9);
 
  code = mom.all_inertian_values(vals,vects,vol);
  if ( code ) cout << errorCode(code);
  
  int pos;
  double swap, sumew, cl, cp, ci;
  for ( int k = 0; k < size[3]; k++ ){
    for ( int j = 0; j < size[2]; j++ ){
      for ( int i = 0; i < size[1]; i++ ){
	
	pos = i+j*size[1]+k*size[1]*size[2];
	
	if ( 
	    ( j == 16 ) &&  
	      ( i >= 14 ) && ( i <= 17 ) && ( ( k == i ) || ( k == i+1) )
	    ) 
	     {
	
	  cout << "Traegheitswerte am Punkt ( " << i << ", " << j << ", " << k <<" ): " << endl;
	  
	  cout << "eigenvektor: ( " << vects[pos][1] << " " << vects[pos][2] << " " << vects[pos][3] << " )" << endl;
	  cout << "dazu eigenwert: " << vals[pos][1] << endl;
	  cout << "eigenvektor: ( " << vects[pos][4] << " " << vects[pos][5] << " " << vects[pos][6] << " )" << endl;
	  cout << "dazu eigenwert: " << vals[pos][2] << endl;
	  cout << "eigenvektor: ( " << vects[pos][7] << " " << vects[pos][8] << " " << vects[pos][9] << " )" << endl;
	  cout << "dazu eigenwert: " << vals[pos][3] << endl;

	  // sort eigenvalues 
	  if ( vals[pos][1] < vals[pos][2] ){ 
	    swap = vals[pos][1]; vals[pos][1] = vals[pos][2]; vals[pos][2] = swap;
	  }
	  if ( vals[pos][1] < vals[pos][3] ){ 
	    swap = vals[pos][1]; vals[pos][1] = vals[pos][3]; vals[pos][3] = swap;
	  }
	  if ( vals[pos][2] < vals[pos][3] ){ 
	    swap = vals[pos][2]; vals[pos][2] = vals[pos][3]; vals[pos][3] = swap;  
	  }
	  
	  sumew = vals[pos][1]+vals[pos][2]+vals[pos][3];
	  cl = (vals[pos][1]-vals[pos][2])/sumew;
	  cp = 2*(vals[pos][2]-vals[pos][3])/sumew;
	  ci = 3*vals[pos][3]/sumew;

	  cout << "Anisotropie-Koeffizienten: "<< endl;
	  cout << " cl = " << cl << endl;
	  cout << " cp = " << cp << endl;
	  cout << " ci = " << ci << endl;
	}

      }
    }
  }

}
Exemple #8
0
  DecayChain* TrackAttach::calculateFor(DecayChain* MyDecayChain) const
  {
    double distance = 0;
    double Theta = 0; 
    double Phi = 0;
    Vector3 VertexPos;
    SymMatrix5x5 dummy;
    dummy.clear();
    double closeapproach;
    double LoD;
    int numberoftracks = 0;
    int  vertexcounter = 0;
    int tempvertex =0;
    DecayChain* DecaywithAtTracks = new DecayChain(*MyDecayChain);
    MemoryManager<DecayChain> ::Event()->registerObject(DecaywithAtTracks);
    std::vector<vertex_lcfi::Track > AttachedTracks;
    std::vector<Track*> Innertracks;
    
    for (std::vector<Vertex*>::const_iterator iVertex = (MyDecayChain->vertices().begin()); iVertex != MyDecayChain->vertices().end() ;++iVertex)
      {

	numberoftracks = (*iVertex)->tracks( ).size();

	if ( numberoftracks > 1 || vertexcounter > 0 )
	  {
	    tempvertex = vertexcounter;
	  }
	vertexcounter++;
      }
    
    tempvertex = (MyDecayChain->vertices().size()-1);
    
    if (MyDecayChain->vertices().empty())
	    std::cerr << "Empty Decay Chain - trackattach.cpp:119" << std::endl;


    VertexPos = (MyDecayChain->vertices()[tempvertex]->position()).subtract( (MyDecayChain->vertices()[0])->position() );

    distance =  VertexPos.mag();

    //effectively if distance bigger than 0 within rounding errors hence not a parameter
    if (distance > 0.00001)
      {   

	//Make a straight track from IP to vertex so then we can use swimmer	


	Theta = acos( VertexPos.unit().z() );
	Phi = acos( VertexPos.unit().x()/sin(Theta));
	if (VertexPos.unit().y()<0.0) Phi = (2*3.141592654) - Phi;
	
	HelixRep LinearHelix;
	
	LinearHelix.d0() = 0;
	
	LinearHelix.z0() = 0.0;
	LinearHelix.invR() = 0.0;
	LinearHelix.phi() = Phi;
	LinearHelix.tanLambda() = tan((3.141592654/2.0)-Theta);

	Vector3 mom(cos(Phi)*sin(Theta),sin(Phi)*sin(Theta),cos(Theta));
	
	Track LinearTrack(0,LinearHelix,mom,0.0,dummy,std::vector<int>());	
	
	TrackState* TSLin = LinearTrack.makeState();
	TrackState* TSHel;


	for (std::vector<Track*>::const_iterator iTrack = (MyDecayChain->jet()->tracks().begin()); iTrack != MyDecayChain->jet()->tracks().end() ;++iTrack)
	  {


	    //new addition to find tracks not from primary but associated with a vertex

	    if (_AddAllTracksFromSecondary == true )
	      {
		for (std::vector<Vertex*>::const_iterator iVertex = (++MyDecayChain->vertices().begin()); iVertex != MyDecayChain->vertices().end() ;++iVertex)
		  {	
		    
		    if((*iVertex)->hasTrack(*iTrack))
		      {

			Innertracks.push_back(*iTrack);
		      }
		  }
	      }

	    TSHel = (**iTrack).makeState();  

	    //this is a smart way of solving many problems
	    // we swim near to the vertex since the cut is then perfomed at the vertex.
	    //so if we have too many iterations we can cut the track

	    TSLin->swimToStateNearest( MyDecayChain->vertices()[tempvertex]->position() );

       	    TSLin->swimToStateNearest( TSHel );
	    TSHel->swimToStateNearest( TSLin );

	    closeapproach = ((*TSHel).position().subtract((*TSLin).position())).mag();

	    LoD = (TSLin->position().subtract((MyDecayChain->vertices()[0])->position())).mag();
	    
	    if( 0 > TSLin->position().subtract(MyDecayChain->vertices()[0]->position()).dot( VertexPos ) )
	    {
	      LoD = LoD * (-1);
	    }

	    if ( (LoD/distance)> _LoDCutmin && (LoD/distance)< _LoDCutmax && (closeapproach < _CloseapproachCut) )
	      {

		if(  DecaywithAtTracks->hasTrack(*iTrack) == 0 )
		  {
		    
		    DecaywithAtTracks->addTrack(*iTrack);
		  }
	      }
	    else
	      {
		if (_AddAllTracksFromSecondary == true )
		  {
		    std::vector<Track*>::const_iterator Inner = find(Innertracks.begin(),Innertracks.end(),*iTrack );
		    if(Inner == Innertracks.end())
		      {
			if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
			  {
			    DecaywithAtTracks->removeTrack(*iTrack);
			  }
		      }
		  }
		else
		  {
		    if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
		      {
			DecaywithAtTracks->removeTrack(*iTrack);
		      }
		  }
	      }
	   
	  }
      }
    else
      {
	for (std::vector<Track*>::const_iterator iTrack = (MyDecayChain->jet()->tracks().begin()); iTrack != MyDecayChain->jet()->tracks().end() ;++iTrack)
	  {
	    if(DecaywithAtTracks->hasTrack(*iTrack) == 1)
	      {
		DecaywithAtTracks->removeTrack(*iTrack);
	      }
	  }
      }
    
    //    std::cout<<"I AM FINISHED"<<std::endl;    
    return DecaywithAtTracks;
    
  }
Exemple #9
0
EXPORT void g_verbose_fprint_state(
	FILE	   *file,
	const char *name,
	Locstate   state)
{
	bool		bin_out;
	int		i, dim;
	float		p, c, S, v[SMAXD], speed;
	static	char	vname[3][3] = { "vx", "vy", "vz"};
	static	char	mname[3][3] = { "mx", "my", "mz"};

	if (name == NULL)
	    name = "";
	(void) fprintf(file,"\n%s:\n",name);
	(void) fprintf(file,"address %p\n",state);
	if (state == NULL || is_obstacle_state(state))
	{
	    (void) fprintf(file,"(OBSTACLE STATE)\n\n");
	    return;
	}
	dim = Params(state)->dim;

	p = pressure(state);
	c = sound_speed(state);
	S = entropy(state);

	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
		       "density",Dens(state),
		       "specific internal energy",
		       specific_internal_energy(state));
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","pressure",p,
		       "sound speed",c);
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","temperature",
		       temperature(state),"specific entropy",S);

	speed = 0.0;
	for (i = 0; i < dim; i++)
	{
	    v[i] = vel(i,state);	speed += sqr(v[i]);
	    (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
			   mname[i],mom(i,state),vname[i],v[i]);
	}
	speed = sqrt(speed);

	(void) fprintf(file,"%-24s = %-"FFMT"","total energy",energy(state));
	if (c > 0. && Dens(state) > 0.)
	   (void) fprintf(file," %-24s = %-"FFMT"\n","Mach number",speed / c);
	else
	   (void) fprintf(file,"\n");

#if defined(TWOD)
	if (dim == 2)
	    (void) fprintf(file,"%-24s = %-"FFMT"\n","velocity angle",
			   degrees(angle(v[0],v[1])));
#endif /* defined(TWOD) */


	fprint_state_type(file,"State type = ",state_type(state));
	(void) fprintf(file,"Params state = %llu\n",
		       gas_param_number(Params(state)));

	bin_out = is_binary_output();
	set_binary_output(NO);
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));
	set_binary_output(bin_out);

	//if(p< -2000 || p>10000)
	//{
	//    printf("#huge pressure\n");
	//    clean_up(0);
	//}
#if !defined(COMBUSTION_CODE)
	(void) fprintf(file,"\n");
#else /* !defined(COMBUSTION_CODE) */
	if (Composition_type(state) == PURE_NON_REACTIVE)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-12s   %-24s = %-"FFMT"\n","burned",
		       Burned(state) ? "BURNED" : "UNBURNED",
		       "q",Params(state)->q);
	(void) fprintf(file,"%-24s = %-"FFMT"\n","t_crit",
		       Params(state)->critical_temperature);

	if (Composition_type(state) == PTFLAME)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","product density",Prod(state));
	(void) fprintf(file,"%-24s = %-"FFMT"\n",
		       "reaction progress",React(state));

	if (Composition_type(state) == ZND)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","rho1",Dens1(state));
#endif /* !defined(COMBUSTION_CODE) */
	(void) fprintf(file,"%-24s = %-24s %-24s = %-"FFMT"\n\n","gamma_set",
		      Local_gamma_set(state)?"YES" : "NO","local_gamma",
		      Local_gamma(state));
        if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
        {
            if(Params(state) != NULL &&
               Params(state)->n_comps != 1)
            {
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"partial density[%2d] = %"FFMT"\n",
                       i,pdens(state)[i]);
                (void) fprintf(file,"\n");
                 /* TMP the following print is for the debuging display purpose */
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"[%d]Mass fraction = %-"FFMT"\n",
                             i, pdens(state)[i]/Dens(state));
                (void) fprintf(file,"\n");
            }
        }
}		/*end g_verbose_fprint_state*/
Exemple #10
0
/*!
 * discretizes 3d nonlinear anisotropic diffusion 
 * by finite volume method using a 27-point stencil
 */
int 
FV_3d27::
discretize(DataCube &dc)
{ 
 
  int code; // errorcode
  int e,i,j,k,ewc,evc; // loop variables
  NeuraDataType insert_diff; // help variable
  NeuraDataType diff_x, diff_y, diff_z; // help variables

  int n = a->Length(1);//=dc.GetSize()[1];
  int m = a->Length(2);//=dc.GetSize()[2];
  int l = a->Length(3);//=dc.GetSize()[3];
 
  int number_of_elements = (n-1)*(m-1)*(l-1);
  int number_of_nodes = n*m*l;

  // eigenvalues and eigenvectors of inertian tensor 
  // within current integration point
  Vector<NeuraDataType> ew(3);
  Vector<NeuraDataType> ev(9); 

  Vector<NeuraDataType> tmp(3); // help vector
  Vector<NeuraDataType> t(3); // coefficients of anisotropy

  NeuraDataType cl, cp, ci; // characteristic structure coefficients
  NeuraDataType sum_ew; // sum over eigenvalues of inertian tensor
  NeuraDataType swap; // help variable 

  a->SetZero();

  // prepare moment calculation

  // for to use fastest method
  if ( gt == CUBE ){
    int warn = 0;
    if ( integration_size_x % 2 == 1 ){ integration_size_x ++; warn = 1;}
    if ( integration_size_y % 2 == 1 ){ integration_size_y ++; warn = 1;}
    if ( integration_size_z % 2 == 1 ){ integration_size_z ++; warn = 1;}
    if ( warn ) cout << "Warning: You should use even integration sizes in all directions at CUBE integration! Given values were adapted." << endl;
  }

  Volume vol(gt, 3, integration_size_x, integration_size_y, integration_size_z );

  Moments mom(&dc);
  Vector<NeuraDataType> *vals; 
  Vector<NeuraDataType> *vects;
  
  time_t time1, time2, timediff;
  // calculate moments
  cout << "calculate moments..." << endl;
  time1 = time(NULL);

  if ( 
      ( integration_size_x > n ) || 
      ( integration_size_y > m ) || 
      ( integration_size_z > l ) 
      ) 
    {
      return INTEGRATION_DOMAIN_TOO_BIG;
    } 
  
  switch ( gt )
    {
    case CUBE: // fast moments calculation and elementwise kindOfMoments
      kind_of_moments = ELEMENTWISE;
      vals = new ( Vector<NeuraDataType>[number_of_elements])(3);
      vects = new (Vector<NeuraDataType>[number_of_elements])(9);
      code = mom.elemwise_fast2_all_inertian_values(vals,vects,vol);
      if ( code ) return code;
      break;
    case BALL: // fourier moments calculation and nodewise kindOfMoments
      kind_of_moments = NODEWISE;
      vals = new ( Vector<NeuraDataType>[number_of_nodes])(3);
      vects = new (Vector<NeuraDataType>[number_of_nodes])(9);
      code = mom.fourier_all_inertian_values(vals,vects,vol,n,m,l);
      code = mom.all_inertian_values(vals,vects,vol);
      if ( code ) return code;
      break;
    default:
      return UNKNOWN_GEOMETRY_TYPE;
    }
  
  if ( code ) return code;
  time2 = time(NULL);
  cout << "...moments calculated" << endl;
  timediff = time2-time1;
  cout << "calculation of moments took " << timediff << " seconds" << endl;
 
  // discretise
  for ( e = 0; e < number_of_elements; e++ ) // elements 
    {  
      elements_nodes(e,n,m,en);
      
      for ( i = 0; i < 8; i++ ) // nodes
	{   
	  // determine moments
	  switch ( kind_of_moments )
	    {
	    case ELEMENTWISE:
	      // eigenvalues
	      for ( ewc = 1; ewc <= 3; ewc++ )
		ew[ewc] = vals[e][ewc];
	      // eigenvectors
	      for ( evc = 1; evc <= 9; evc++ )
		ev[evc] = vects[e][evc];
	      break;
	    case NODEWISE:
	      // eigenvalues
	      for ( ewc = 1; ewc <= 3; ewc++ )
		ew[ewc] = vals[en[i]-1][ewc];
	      // eigenvectors
	      for ( evc = 1; evc <= 9; evc++ )
		ev[evc] = vects[en[i]-1][evc];
	      break;
	    default: 
	      cout << "FV_3d27::RunTimeError: Unknown kindOfMoments! \n Abort " << endl;
	      exit(1);
	    }
	  
	  k = 0;
	  while ( ( ip[i][k][0] != -1 ) && ( k < 2 ) ) // ips
	    {   
	      for ( j = 0; j < 8; j++ ) // ansatzfunctions
		{  
		  diff_x = grad_phi_x(j,ip[i][k][0],ip[i][k][1],ip[i][k][2]);
		  diff_y = grad_phi_y(j,ip[i][k][0],ip[i][k][1],ip[i][k][2]);
		  diff_z = grad_phi_z(j,ip[i][k][0],ip[i][k][1],ip[i][k][2]);
		  
		  // sort eigenvalues
		  if ( ew[1] < ew[2] ){ 
		    swap = ew[1]; ew[1] = ew[2]; ew[2] = swap;
		    swap = ev[1]; ev[1] = ev[4]; ev[4] = swap;
		    swap = ev[2]; ev[2] = ev[5]; ev[5] = swap;
		    swap = ev[3]; ev[3] = ev[6]; ev[6] = swap;
		    
		  }
		  if ( ew[1] < ew[3] ){ 
		    swap = ew[1]; ew[1] = ew[3]; ew[3] = swap;
		    swap = ev[1]; ev[1] = ev[7]; ev[7] = swap;
		    swap = ev[2]; ev[2] = ev[8]; ev[8] = swap;
		    swap = ev[3]; ev[3] = ev[9]; ev[9] = swap;
		  }
		  if ( ew[2] < ew[3] ){ 
		    swap = ew[2]; ew[2] = ew[3]; ew[3] = swap;
		    swap = ev[4]; ev[4] = ev[7]; ev[7] = swap;
		    swap = ev[5]; ev[5] = ev[8]; ev[8] = swap;
		    swap = ev[6]; ev[6] = ev[9]; ev[9] = swap;
		  }
		  
		  
		  // determine coefficients of anisotropy
		 	  
		  if ( fixed_coeffs )
		    {
		      t[1] = anicoeff1;
		      t[2] = anicoeff2;
		      t[3] = anicoeff3;
		    }
		  else
		    {
		      sum_ew = ew[1]+ew[2]+ew[3];
		      if ( fabs(sum_ew) <= 0.000001 )
			{ cl = 0; cp = 0; ci = 1; }
		      else {
			cl = (ew[1]-ew[2])/sum_ew;
			cp = 2*(ew[2]-ew[3])/sum_ew;
			ci = 3*ew[3]/sum_ew;
		      }
		      
		      t[1] = 1.0;
		      switch (dependence_type)
			{
			case PERONA_MALIK:
			  t[2] = g_pm(cl);
			  t[3] = g_pm(1-ci);
			  break;
			case WEIKERT:
			  t[2] = g_w(cl);
			  t[3] = g_w(1-ci);
			  break;
			case BLACK_SAPIRO: 
			  t[2] = g_bs(cl);
			  t[3] = g_bs(1-ci);
			  break;
			default:
			  cout << "Unknown nonlinear function specified!\n Abort" << endl;
			  exit(1);	
			}
		    }

		  // multiplication with the anisotropy tensor

		  tmp[1] = ev[1]*diff_x + ev[2]*diff_y + ev[3]*diff_z;
		  tmp[2] = ev[4]*diff_x + ev[5]*diff_y + ev[6]*diff_z;
		  tmp[3] = ev[7]*diff_x + ev[8]*diff_y + ev[9]*diff_z;

		  tmp[1] *= t[1]; tmp[2] *= t[2]; tmp[3] *= t[3];

		  diff_x = ev[1]*tmp[1] + ev[4]*tmp[2] + ev[7]*tmp[3];
		  diff_y = ev[2]*tmp[1] + ev[5]*tmp[2] + ev[8]*tmp[3];
		  diff_z = ev[3]*tmp[1] + ev[6]*tmp[2] + ev[9]*tmp[3];


		  // multiplication with normal
		  insert_diff = diff_x * nip[i][k][0] +
		    diff_y * nip[i][k][1] +
		    diff_z * nip[i][k][2];
 
		
		  insert_diff *= 0.25; // surface of subcontrolvolume
		 
		      a->Add(en[i], en[j], insert_diff);
		    
		      a->Add( en[intact[i][k]], en[j], -insert_diff); 
		     	  
		}//for j
	    
	      k++;
       
	    }// while
	 
	}// for i
     	  	      
    }// for e

  delete [] vals;
  delete [] vects;


  // treatment of boundary

  int position; 
  
  // lower and upper boundary
  for ( i = 0; i < n; i++ )
    {
      for ( j = 0; j < m; j++ )
	{
	  k = 0;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	  k = l-1;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	} 
    }
  //left and right boundary
  for ( j = 0; j < m; j++ )
    {
      for ( k = 0; k < l; k++ )
	{ 
	  i = 0;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	  i = n-1;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	} 
    }
  
  // front and back boundary
  for ( i = 0; i < n; i++ )
    {
      for ( k = 0; k < l; k++ )
	{
	  j = 0;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	  j = m-1;
	  position = 1 + i + j*n + k*n*m;
	  a->MultiplyRow(position,2);
	}
    }


return OK;
}
Exemple #11
0
main()
{
	FILE *input,*out,*dataf;
	int j,ic,n,*index,*index2,k,i,ndata,dd1,dd2;
	float *x0,*y0,*x1,*y1;
	float *xmed,*ymed,*ytop,*ybot,*y2;
	float dx0[90000],dy0[90000],dpval[90000],dnval[90000];
	float mean,sdev,skew,kurt,min,max,g1,d1,l1,xi1,nvar,qval;
	int ifault,itype1;
	char instr[200],outstr[200],datstr[200];
	
	opengfsr();
	printf("data file, output file, simulated density file?:");
	scanf("%s %s %s",datstr,outstr,instr);
	dataf = fopen(datstr,"r");
	input = fopen(instr,"r");
	out = fopen(outstr,"w");
	for(j=0;;++j){
           char sdx1[200];
		//ic = fscanf(dataf,"%f %f ",&dx0[j],&dy0[j]);
		ic = fscanf(dataf,"%f %s ",&dx0[j],sdx1);
           if (sdx1[1] == 'a') {
               dy0[j] = NAN;
           }
           else {
               sscanf(sdx1, "%f", &dy0[j]);
           }
		if(ic == EOF)break;
	}
	ndata = j;
	for(j=0;;++j){
		ic = fscanf(input,"%f %f ",&dd1,&dd2);
		if(ic == EOF)break;
	}

	NMAX = n = j;
	fclose(input);

	index = (int *)malloc(NMAX*sizeof(int));
	index2 = (int *)malloc(NMAX*sizeof(int));
	x0 = (float *)malloc(NMAX*sizeof(float));
	y0 = (float *)malloc(NMAX*sizeof(float));
	x1 = (float *)malloc(NMAX*sizeof(float));
	y1 = (float *)malloc(NMAX*sizeof(float));
	xmed = (float *)malloc(NMAX*sizeof(float));
	ymed = (float *)malloc(NMAX*sizeof(float));
	ytop = (float *)malloc(NMAX*sizeof(float));
	ybot = (float *)malloc(NMAX*sizeof(float));
	y2 = (float *)malloc(NMAX*sizeof(float));
	
	input = fopen(instr,"r");

	for(j=0;j<n;++j){
		ic = fscanf(input,"%f %f ",&x0[j],&y0[j]);
	}
	
	
	
	isort(n,x0,index);
	for(j=0;j<n;++j){
		x1[j] = x0[index[j]];
		y1[j] = y0[index[j]];
	}
	for(j=0;j<ndata;++j) {
		dpval[j] = -100.0;
	}
	
	for(k=0; k+WIN-1 < n;k+=WIN){
		mom(&y1[k],WIN,&mean,&sdev,&skew,&kurt,&min,&max);
		jnsn(&mean,&sdev,&skew,&kurt,&itype1,&g1,&d1,&l1,&xi1,&ifault); 
		if(ifault!=0){
			printf(" jnsn. ifault is %d\n",ifault);
			if(ifault != 3)continue;
		}
		for(j=0;j<ndata;++j) {
			if((k==0 && dx0[j] < x1[WIN-1]) || 
			(!(k+2*WIN-1 < n) && dx0[j] >= x1[k]) || 
			(dx0[j] >= x1[k] && dx0[j] < x1[k+WIN])) {
				varn(&dy0[j],&nvar,&itype1,&g1,&d1,&l1,&xi1,&ifault);
				if(ifault == 2) {
					if(dy0[j] < mean) {
						dpval[j] = 0.0;
						dnval[j] = -5.0;
					}
					else {
						dpval[j] = 1.0;
						dnval[j] = 5.0;
					}
				}
				else {
					dpval[j] = pnorm(nvar);
					dnval[j] = nvar;
				}
				
				
			}
		}
	}
	for(j=0;j<ndata;++j) {
           if (isnan(dy0[j])) {
               fprintf(out,"%f nan nan nan\n", dx0[j]);
           }
           else {
    		    fprintf(out,"%f %f %f %f\n", dx0[j], dy0[j], dnval[j], dpval[j]);
           }
	}
	
	closegfsr();
}
Real NSMassUnspecifiedNormalFlowBC::computeQpResidual()
{
  RealVectorValue mom(_rho_u[_qp], _rho_v[_qp], _rho_w[_qp]);

  return this->qp_residual( mom * _normals[_qp] );
}
Exemple #13
0
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
void AlgWspect::run()
{
#ifdef  TIMING_ALG_W_SPECT
  int quark_b, quark_e;
  int meson_b, meson_m, meson_e, meson_bmp, meson_mmp, meson_emp;
  int nucleon_b, nucleon_m, nucleon_e;
  int total_b = clock();
  int total_e;  
#endif
	  CgArg cg = *cg_arg_p;
	  char *fname = "run()";
	  VRB.Func(d_class_name,fname);

	  // printf("in AlgWspect::run \n");

	  WspectOutput * output = (WspectOutput *)common_arg->results;
	  

	  // Set the Lattice pointer
	  //------------------------------------------------------------------------
	  Lattice& lat = AlgLattice();

	  int src_slice = d_arg_p->aots_start;
	  int src_slice_step = d_arg_p->aots_step;
	  int src_slice_end  = src_slice + src_slice_step * d_arg_p->aots_num;

	  VRB.Result(d_class_name,fname,"%d %d %d \n",src_slice,src_slice_step, src_slice_end);

	  for ( ; src_slice < src_slice_end; src_slice += src_slice_step) {


	    // Calculate quark propagator
	    //----------------------------------------------------------------------
	    // Ping:  certainly more work here to be done about the desired
	    //        combinations of non-degenerate quarks.
	    //        Presumably, more arguments will have to be passed in.
	    //        One way: for three flavors, [100] means use only q1
	    //                 to caculate spectrum.
	    //        Also some care needed to get the scope (CTOR and DTOR) 
	    //        of each quark propagator right.
	    //    const WspectQuark & q2 = q;
	    //    const WspectQuark & q3 = q;

	    // Xiaodong & Thomas:
	    // Modified to calculate also extended mesons
	    // q1 is the usual propagator(no source operator), which can be
	    // used to pass propagation direction and src_slice infomation
	    // to spectrum class

	    // there is a problem here --> check !
	    VRB.Result(d_class_name,fname,"prop_dir = %d , src_slice = %d \n",d_arg_p->prop_dir, src_slice);

	    WspectHyperRectangle hyperRect(d_arg_p->prop_dir, src_slice);    

	#ifdef  TIMING_ALG_W_SPECT
	    quark_b = clock();
	#endif

    VRB.Result(d_class_name,fname,"created quark q1 \n");
	    // create local quark propagator
	     WspectQuark q1(lat, output->cg, output->pbp,
			  output->mid_point, output->a0_p, d_arg_p[0], cg,hyperRect);
		  
      VRB.Result(d_class_name,fname,"finished quark q1 \n");
#ifdef  TIMING_ALG_W_SPECT
    quark_e = clock();
#endif

    //Note: for ExtendedMesons, do only zero momentum projection
    WspectMomenta  mom(hyperRect, q1.SourceCenter2(), d_arg_p->num_mom - 1);
    //    mom.dumpData();


    // Calculate LOCAL meson CORRELATOR
    // added control by Thomas and Xiaodong
    //----------------------------------------------------------------------
    {
#ifdef  TIMING_ALG_W_SPECT
      meson_b = clock();
#endif
     if(d_arg_p->normal_mesons_on) {
        WspectMesons mes(q1, q1, hyperRect, mom);
#if 0
	q1.dumpData("qprop.dat");
#endif

#ifdef  TIMING_ALG_W_SPECT
        meson_m = clock();
#endif
        //write data to files
        mes.print(output);
      }
#ifdef  TIMING_ALG_W_SPECT
      meson_e = clock();
#endif
    } //end of normal mesons
   

    // Calculate <\Delta J^5 \bar q1 \gamma^5 q1> with middle point sink
    // changed
    //----------------------------------------------------------------------
    if (lat.Fclass() == F_CLASS_DWF && output->mid_point)
      {
#ifdef  TIMING_ALG_W_SPECT
	meson_bmp = clock();
#endif
        WspectMesons mes(q1.Data_SP1(), q1.Data_SP2(), hyperRect, mom);
	
#ifdef  TIMING_ALG_W_SPECT
	meson_mmp = clock();
#endif
	
	mes.print_mp(output->mid_point);	
	
#ifdef  TIMING_ALG_W_SPECT
	meson_emp = clock();
#endif
      }
    
    // Calculate nucleon and delta's
    //----------------------------------------------------------------------
    if (d_arg_p->baryons_on) {
      
      {
#ifdef  TIMING_ALG_W_SPECT
	nucleon_b = clock();
#endif
	WspectBaryon nuc(q1, q1, q1, hyperRect,
			 WspectBaryon::NUCLEON_CONSTI,
			 WspectBaryon::NUCLEON_DIRAC);
#ifdef  TIMING_ALG_W_SPECT
	nucleon_m = clock();
#endif

	nuc.print(output->nucleon, output->fold);	

#ifdef  TIMING_ALG_W_SPECT
	nucleon_e = clock();
#endif   
      }

      
      {
	WspectBaryon nucPrime(q1, q1, q1, hyperRect,
			      WspectBaryon::NUCLEON_CONSTI,
			      WspectBaryon::UnitUnit);
	nucPrime.print(output->nucleon_prime, output->fold);	
      }
      
      
      {
	WspectBaryon deltaX(q1, q1, q1, hyperRect,
			    WspectBaryon::DELTA_CONSTI,
			    WspectBaryon::DELTAX_DIRAC);
	deltaX.print(output->delta_x, output->fold);	
      }
      
      
      {
	WspectBaryon deltaY(q1, q1, q1, hyperRect,
			    WspectBaryon::DELTA_CONSTI,
			    WspectBaryon::DELTAY_DIRAC);
	deltaY.print(output->delta_y, output->fold);      
      }
      
      
      {
	WspectBaryon deltaZ(q1, q1, q1, hyperRect,
			    WspectBaryon::DELTA_CONSTI,
			    WspectBaryon::DELTAZ_DIRAC);
	deltaZ.print(output->delta_z, output->fold); 
      }
      

      {
	WspectBaryon deltaT(q1, q1, q1, hyperRect,
			    WspectBaryon::DELTA_CONSTI,
			    WspectBaryon::DELTAT_DIRAC);
	deltaT.print(output->delta_t, output->fold); 
      }
    } //end if(baryons_on) 
    
    // Increment the counter
    d_counter += d_count_step;
  } // end of for(sc_slice,..)

#ifdef  TIMING_ALG_W_SPECT
  total_e = clock();
  printf("Total: %d = [%d - %d]\n", total_e - total_b, total_e, total_b);
  printf("Quark: %d = [%d - %d]\n", quark_e - quark_b, quark_e, quark_b);
  printf("Meson: \t%d = [%d - %d] = \n\tcalc %d = [%d - %d] + \n\tprint %d = [%d - %d]\n", 
	 meson_e - meson_b, meson_e, meson_b,
	 meson_m - meson_b, meson_m, meson_b,
	 meson_e - meson_m, meson_e, meson_m);
  printf("Nucleon:\t%d = [%d - %d] = \n\tcalc %d = [%d - %d] + \n\tprint %d = [%d - %d]\n", 
	 nucleon_e - nucleon_b, nucleon_e, nucleon_b,
	 nucleon_m - nucleon_b, nucleon_m, nucleon_b,
	 nucleon_e - nucleon_m, nucleon_e, nucleon_m);  
#endif 
   VRB.FuncEnd(d_class_name,fname);

}
Exemple #14
0
int main(int argc, char *argv[]) {

  Start(&argc,&argv);
  int seed = atoi(argv[1]);         //
  int SINPz_Pz   = atof(argv[2]);   // integer percentage of the tolerance of sin(p)/p at Z.
  int SINPxy_Pxy = atof(argv[3]);   // integer percentage of the tolerance of sin(p)/p at XY.
  //int t_in = atoi(argv[5]);         //

  DoArg do_arg;
  setup_do_arg(do_arg, seed); 
  GJP.Initialize(do_arg);  

  GwilsonFclover lat;
  CommonArg c_arg;

  //Declare args for Gaussian Smearing
  QPropWGaussArg g_arg_mom;
  setup_g_arg(g_arg_mom);


  int sweep_counter = 0;
  int total_updates = NTHERM + NSKIP*(NDATA-1);

  #ifdef QUENCH
  GhbArg ghb_arg;
  ghb_arg.num_iter = 1;
  AlgGheatBath hb(lat, &c_arg, &ghb_arg);
  #else
  HmdArg hmd_arg; 
  setup_hmd_arg(hmd_arg);
  AlgHmcPhi hmc(lat, &c_arg, &hmd_arg); 
  #endif

  //Declare args for source at 0.
  QPropWArg arg_0;
  setup_qpropwarg_cg(arg_0);
  arg_0.x = 0;
  arg_0.y = 0;
  arg_0.z = 0;
  arg_0.t = 0;

  //Declare args for source at z.
  QPropWArg arg_z;
  setup_qpropwarg_cg(arg_z);

  // Propagator calculation objects and memory allocation
  //
  // Using x[4] = X(x,y,z,t)
  //       y[4] = Y(x,y,z,t)
  //       z[4] = Z(x,y,z,t)
  int x[4];
  int y[4];
  int z[4];
  int x_idx4d, x_idx3d, y_idx4d, y_idx3d, z_idx4d, z_idx3d;
  int vol4d = GJP.XnodeSites()*GJP.YnodeSites()*GJP.ZnodeSites()*GJP.TnodeSites();
  int vol3d = GJP.XnodeSites()*GJP.YnodeSites()*GJP.ZnodeSites();
  int xnodes = GJP.XnodeSites();
  int ynodes = GJP.YnodeSites();
  int znodes = GJP.ZnodeSites();
  double norm = pow(vol3d, -0.5);
  
  int max_mom = NSITES_3D;
  mom3D mom(max_mom, SINPz_Pz/(1.0*100));

  int s1 = 0;
  int c1 = 0;
  int s2 = 0;
  int c2 = 0;
  int sc_idx = 0;

  //use t to represent the time slice.
  //int t = 0;

  //In these arrays, we will use the index convention [sink_index + vol3d*source_index]
  WilsonMatrix *t3_arr = (WilsonMatrix*)smalloc(vol3d*vol3d*sizeof(WilsonMatrix));
  WilsonMatrix *t2_arr = (WilsonMatrix*)smalloc(vol3d*vol3d*sizeof(WilsonMatrix));
  //Initialise
  for (int i=0; i<vol3d*vol3d; i++) {
    t3_arr[i]    *= 0.0;
    t2_arr[i]    *= 0.0;
  }

  //Arrays to store the trace data
  fftw_complex *FT_t4 = (fftw_complex*)smalloc(vol3d*sizeof(fftw_complex));
  fftw_complex *FT_t2 = (fftw_complex*)smalloc(vol3d*vol3d*sizeof(fftw_complex));
  fftw_complex *FT_t3 = (fftw_complex*)smalloc(vol3d*vol3d*sizeof(fftw_complex));
  
  //Use this array several times for 9d D0, D1, D2.
  fftw_complex *FT_9d  = (fftw_complex*)smalloc(vol3d*vol3d*vol3d*sizeof(fftw_complex));
  
  //Momentum source array.
  fftw_complex *FFTW_mom_arr  = (fftw_complex*)smalloc(vol3d*sizeof(fftw_complex));
  //Initialise
  for (int i=0; i<vol3d*vol3d*vol3d; i++) {
    for(int a=0; a<2; a++){
      FT_9d[i][a]  = 0.0;    
      if(i<vol3d*vol3d) {
	FT_t3[i][a]  = 0.0;
	FT_t2[i][a]  = 0.0;
      }
      if(i<vol3d) {
	FT_t4[i][a]  = 0.0;
	FFTW_mom_arr[i][a]  = 0.0;
      }
    }
  }
 //gaahhbage 
  FFT_F(9, NSITES_3D, FT_9d);
  FFT_B(9, NSITES_3D, FT_9d);

  FFT_F(6, NSITES_3D, FT_t2);
  FFT_B(6, NSITES_3D, FT_t2);
 
  FFT_F(3, NSITES_3D, FFTW_mom_arr);
  FFT_B(3, NSITES_3D, FFTW_mom_arr); 

  WilsonMatrix t1;
  WilsonMatrix t1c;
  WilsonMatrix t4;
  WilsonMatrix t4c;
  WilsonMatrix t4t1c;
  WilsonMatrix t2t3c;
  WilsonMatrix t3;
  WilsonMatrix t3c;
  WilsonMatrix t2;
  WilsonMatrix t2c;
		
  //Rcomplex mom_src;
  //WilsonMatrix temp;

  Rcomplex t1t1c_tr;
  Rcomplex t4t4c_tr;
  Rcomplex d2_tr;
  Rcomplex t2t2c_tr;
  Rcomplex t3t3c_tr;

  //////////////////////
  // Start simulation //
  ////////////////////// 

  Float *time = (Float*)smalloc(10*sizeof(Float));
  for(int a=0; a<10; a++) time[a] = 0.0;

  char lattice[256];
  
  while (sweep_counter < total_updates) {
    for (int n = 1; n <= NSKIP; n++) {
#ifndef READ
      #ifdef QUENCH
      hb.run(); 
      #else
      hmc.run();
      #endif
#endif
      sweep_counter++;
      if (!UniqueID()) {
        printf("step %d complete\n",sweep_counter);
        fflush(stdout);
      }
    }
    
    if (sweep_counter == NTHERM) {
      printf("thermalization complete. \n");
    }
    if (sweep_counter >= NTHERM) {
      // Use this code to specify a gauge configuration.
      #ifdef QUENCH
        sprintf(lattice, LATT_PATH"QU/lat_hb_B%.2f_%d-%d_%d.dat", BETA, NSITES_3D, NSITES_T, sweep_counter);
      #else
        sprintf(lattice, LATT_PATH"UNQ/lat_hmc_B%.2f_M%.3f_%d-%d_%d.dat", BETA, MASS, NSITES_3D, NSITES_T, sweep_counter);
      #endif
#ifdef READ
      ReadLatticeParallel(lat,lattice);
#else
      WriteLatticeParallel(lat,lattice);
#endif
      
      gaugecounter = 1;
      
      // We will compute two arrays of momentum source propagators.
      // One array is of t2 S(x,z)
      // One array is of t3 S(y,z)
      // Each array will be indexed arr[sink_index + vol*source_index].
      
      // The sources for these arrays are calculated using the backaward FT of momentum states.
      // E.G., momemtum state P_0=(0,0,0) is used to calculated the position space state
      // X_0[n] = \frac{1}{sqrt(V)} * \sum_{m} e^{(-2i*pi/N)*n*m} * P_0[m].
      // This source is then used in the inversion to calculate an propagator M_0. M_0 <P_0|  has,
      // strong overlap with the P_0 state. This is repeated for small momenta (e.g. |P| < 1) and the propagators
      // from each inversion are summed and normalised by the number of momenta used k:
      // M = 1/sqrt(k) sum_k M_k <P_k|  The resulting propagator M has strong overlap with the low momentum states.
      // N.B. One can show that using all possible momenta K, the full propagator matrix is recovered.
      
      // The 0-mom source at the origin is calculated outside the time loop.
      int P0[3] = {0,0,0};
      
      arg_0.t = 0;
      QPropWMomSrcSmeared qprop_0(lat, &arg_0, P0, &g_arg_mom, &c_arg);
      qprop_0.GaussSmearSinkProp(g_arg_mom);
      cout<<"Sink Smear 0 complete."<<endl;
      
      //////////////////////////////////
      // Begin loop over time slices. //
      //////////////////////////////////

      for (int t=0; t<GJP.TnodeSites(); t++) {
	//Reinitialise all propagator arrays.
        for (int i=0; i<vol3d*vol3d; i++) {
	  t2_arr[i]    *= 0.0;
	  t3_arr[i]    *= 0.0;
        }
	
	stopwatchStart();
	
	//Generate momentum source
	int n_mom_srcs    = 0;

	for (mom.P[2] = 0; mom.P[2] < max_mom; mom.P[2]++)
	  for (mom.P[1] = 0; mom.P[1] < max_mom; mom.P[1]++)
	    for (mom.P[0] = 0; mom.P[0] < max_mom; mom.P[0]++) {
	      
	      cout<<"MOM = "<<mom.P[0]<<" "<<mom.P[1]<<" "<<mom.P[2]<<endl;
	      
	      cout<<"NORM_MOM_SZE = "<<mom.mod()/M_PI<<endl;
	      //frac = sin(p)/p
	      Float frac = sin(mom.mod())/(mom.mod());
	      cout<<"SIN(Pz)/Pz = "<<frac<<endl;
	      
	      if(frac > mom.sin_cutoff || (mom.P[0] == 0 && mom.P[1] == 0 && mom.P[2] == 0) ){
		
		//Set momentum
		int P[3] = {mom.P[0], mom.P[1], mom.P[2]};
		
		// The CPS momentum source function uses an unnormalised
		// source, so we take the product of both normalisation
		// factors and place them here on the FFTW_mom_arr.
		// A further normalisation to perform comes from the number n_mom_srcs
		// of momentum sources. This is done later in when the trace of
		// of the propagators is caculated.
		
		
		//Get Momentum Propagator
		arg_z.t = t;
		//QPropWMomSrc qprop_mom(lat, &arg_z, P, &c_arg);
		QPropWMomSrcSmeared qprop_mom(lat, &arg_z, P, &g_arg_mom, &c_arg);
		cout<<"Inversion "<<(n_mom_srcs+1)<<" complete."<<endl;
		qprop_mom.GaussSmearSinkProp(g_arg_mom);
		cout<<"Sink Smear "<<(n_mom_srcs+1)<<" complete."<<endl;
		
		int z_idx4d, z_idx3d, x_idx4d, x_idx3d, y_idx4d, y_idx3d;
		//Loop over sources at z.
		z[3] = t;
		for (z[2]=0; z[2]<znodes; z[2]++)
		  for (z[1]=0; z[1]<ynodes; z[1]++)
		    for (z[0]=0; z[0]<xnodes; z[0]++) {
		      z_idx4d = lat.GsiteOffset(z)/4;
		      z_idx3d = z_idx4d - vol3d*z[3];
		      
		      cout<<"mom_src "<<qprop_mom.mom_src(z_idx4d)<<endl;
		      
		      //Loop over sinks at x.
		      x[3] = 0;
		      for (x[2]=0; x[2]<znodes; x[2]++)
			for (x[1]=0; x[1]<ynodes; x[1]++)
			  for (x[0]=0; x[0]<xnodes; x[0]++) {
			    x_idx4d = lat.GsiteOffset(x)/4;
			    x_idx3d = x_idx4d - vol3d*x[3];
			    
			    //Build t2 array.
			    t2_arr[x_idx3d + vol3d*z_idx3d] += qprop_mom[x_idx4d]*conj(qprop_mom.mom_src(z_idx4d));
			  }
		      
		      //Loop over sinks at y.
		      y[3] = t;
		      for (y[2]=0; y[2]<znodes; y[2]++)
			for (y[1]=0; y[1]<ynodes; y[1]++)
			  for (y[0]=0; y[0]<xnodes; y[0]++) {
			    y_idx4d = lat.GsiteOffset(y)/4;
			    y_idx3d = y_idx4d - vol3d*y[3];
			    
			    //Build t3 array.
			    t3_arr[y_idx3d + vol3d*z_idx3d] += qprop_mom[y_idx4d]*conj(qprop_mom.mom_src(z_idx4d));
			  }
		    }
		n_mom_srcs++; 
		cout << "momentum sources: "<<1+mom.P[2]*max_mom*max_mom + mom.P[1]*max_mom + mom.P[0]<<" / "<<pow(max_mom,3)<<" checked"<<endl;
	      }
	    }
	
	cout<<"FLAG 1"<<endl;
	//inversions + fill      
	time[1] = stopwatchReadSeconds();
	stopwatchStart();
	
	//////////////////////////////////////////////////////////////////
	// End momentum source propagator calculation for time slice t. //
	//////////////////////////////////////////////////////////////////
	
	
	///////////////////////////////////////////////
	// Begin summation of trace at time slice t. //
	///////////////////////////////////////////////
	      
	// The t1, t1c, t4, and t4c propagators are calculated 'on the fly'
	// within the trace summation.
      
	//Reinitialise all trace variables
	
	t1  *= 0.0;
	t1c *= 0.0;
	t2  *= 0.0;
	t2c *= 0.0;
	t3  *= 0.0;
	t3c *= 0.0;
	t4  *= 0.0;
	t4c *= 0.0;
	t4t1c *= 0.0;
	t2t3c *= 0.0;
      
	t1t1c_tr *= 0.0;
	t2t2c_tr *= 0.0;
	t3t3c_tr *= 0.0;
	t4t4c_tr *= 0.0;
	d2_tr *= 0.0;
            
	for (int i=0; i<vol3d*vol3d*vol3d; i++) 
	  for(int a=0; a<2; a++) {
	    FT_9d[i][a] = 0.0;
	    if(i<vol3d*vol3d) {
	      FT_t3[i][a] = 0.0;
	      FT_t2[i][a] = 0.0;
	    }
	    if(i<vol3d) {
	      FT_t4[i][a] = 0.0;
	    }
	  }
	//Sum over X
	x[3] = 0;
	for (x[2]=0; x[2]<znodes; x[2]++)
	  for (x[1]=0; x[1]<ynodes; x[1]++)
	    for (x[0]=0; x[0]<xnodes; x[0]++) {
	      x_idx4d = lat.GsiteOffset(x)/4;
	      x_idx3d = x_idx4d - vol3d*x[3];
	      
	      t1 = qprop_0[x_idx4d];
	      t1c = t1.conj_cp();
	      
	      //Sum over Y
	      y[3] = t;
	      for (y[2]=0; y[2]<znodes; y[2]++)
		for (y[1]=0; y[1]<ynodes; y[1]++)
		  for (y[0]=0; y[0]<xnodes; y[0]++) {
		    y_idx4d = lat.GsiteOffset(y)/4;
		    y_idx3d = y_idx4d - vol3d*y[3];
		    
		    t4 = qprop_0[y_idx4d];
		  
		    // Use this condition so that t4t4c is calculated only once
		    // over X per time slice.
		    if (x_idx3d == 0) {
		      //Perform t4t4c trace sum for D0 graph.
		      FT_t4[y_idx3d][0] = MMDag_re_tr(t4);
		      FT_t4[y_idx3d][1] = 0.0;
		    }
		    
		    //Declare new Wilson Matrix t4*t1c for D2 and compute
		    t4t1c = t4;
		    t4t1c *= t1c;
		    
		    //Sum over Z.
		    z[3] = t;
		    for (z[2]=0; z[2]<znodes; z[2]++)
		      for (z[1]=0; z[1]<ynodes; z[1]++)
			for (z[0]=0; z[0]<xnodes; z[0]++) {
			  z_idx4d = lat.GsiteOffset(z)/4;
			  z_idx3d = z_idx4d - vol3d*z[3];
			  
			  //Declare new Wilson Matrix t2*t3c and compute it.			  
			  t2t3c = t2_arr[x_idx3d + vol3d*z_idx3d];
			  t3c   = t3_arr[y_idx3d + vol3d*z_idx3d].conj_cp();
			  t2t3c *= t3c;
			  
			  //Perform t4t1c * t2t3c trace sum for D2 graph.
			  d2_tr = Trace(t4t1c, t2t3c);
			  
			  //Create 9d array for D2.			  
			  FT_9d[x_idx3d + vol3d*(y_idx3d + vol3d*z_idx3d)][0] = d2_tr.real();
			  FT_9d[x_idx3d + vol3d*(y_idx3d + vol3d*z_idx3d)][1] = d2_tr.imag();
			  
			  ///////////////////////////////////////////////////////////////////
			  // Use this condition so that t2t2c is calculated only over
			  // x1 and x3 loops per time slice. 
			  if (y_idx3d == 0) {
			    //Retrieve propagators for t2t2c trace sum.
			    FT_t2[x_idx3d + vol3d*z_idx3d][0] = MMDag_re_tr(t2_arr[x_idx3d + vol3d*z_idx3d]);
			    FT_t2[x_idx3d + vol3d*z_idx3d][1] = 0.0;
			  }
			  // Use this condition so that t3t3c is calculated only over
			  // x2 and x3 loops per time slice. 
			  if (x_idx3d == 0) {
			    
			    //Retrieve propagators for t3t3c trace sum.
			    FT_t3[y_idx3d + vol3d*z_idx3d][0] = MMDag_re_tr(t3_arr[y_idx3d + vol3d*z_idx3d]);
			    FT_t3[y_idx3d + vol3d*z_idx3d][1] = 0.0;
			  }
			  ///////////////////////////////////////////////////////////////////
			}
		  }
	    }
	
	//Fill the trace arrays
	time[2] = stopwatchReadSeconds();
	
	cout<<"FLAG 3"<<endl;

	///////////////////////////////////////////////
	// Write traces to file for post-processing. //
	///////////////////////////////////////////////
      
	char file[256];
  	FFT_F(6, NSITES_3D, FT_t2);
	FFT_F(6, NSITES_3D, FT_t3);
	FFT_F(3, NSITES_3D, FT_t4);

	// if(t==0) {    
	// sprintf(file, "%d-%d_3-0.1_msmsFT_6d_data/t1t1c_TR_%d_%d-%d_%d_%d.dat",  NSITES_3D, NSITES_T, n_mom_srcs, NSITES_3D, NSITES_T, sweep_counter, t);	  
	// FILE *qt1tr   = Fopen(file, "a");
	// for(int snk =0; snk<vol3d; snk++) {
	// Fprintf(qt1tr,  "%d %d %d %.16e %.16e\n", sweep_counter, t, snk, FT_t4[snk][0], FT_t4[snk][1]);
	// }
	// Fclose(qt1tr);
	// }
	
	sprintf(file, DATAPATH"t4t4c_TR_%d_%d-%d_%d_%d.dat",  n_mom_srcs, NSITES_3D, NSITES_T, sweep_counter, t);
	FILE *qt4tr   = Fopen(file, "a");
	for(int snk =0; snk<vol3d; snk++) {
	  Fprintf(qt4tr,  "%d %d %d %.16e %.16e\n", sweep_counter, t, snk, FT_t4[snk][0], FT_t4[snk][1]);
	}
	
	sprintf(file, DATAPATH"t2t2c_TR_%d_%d-%d_%d_%d.dat",  n_mom_srcs, NSITES_3D, NSITES_T, sweep_counter, t);
	FILE *qt2tr   = Fopen(file, "a");
	sprintf(file, DATAPATH"t3t3c_TR_%d_%d-%d_%d_%d.dat",  n_mom_srcs, NSITES_3D, NSITES_T, sweep_counter, t);
	FILE *qt3tr   = Fopen(file, "a");
	
	for(int src =0; src<vol3d; src++) {
	  for(int snk =0; snk<vol3d; snk++) {
	    Fprintf(qt2tr,"%d %d %d %d %.16e %.16e\n", sweep_counter, t, src, snk, FT_t2[snk + vol3d*src][0], FT_t2[snk + vol3d*src][1]);
	    Fprintf(qt3tr,"%d %d %d %d %.16e %.16e\n", sweep_counter, t, src, snk, FT_t3[snk + vol3d*src][0], FT_t3[snk + vol3d*src][1]);
	  }
	}
	

	Fclose(qt2tr);
	Fclose(qt3tr);
	Fclose(qt4tr);

	//////////////////////////
	// FFT the 9D D2 array. //
	//////////////////////////
      
	stopwatchStart();
	
	FFT_F(9, NSITES_3D, FT_9d);
	//time for D2 6d FFT
	time[4] = stopwatchReadSeconds();      
	//wtf == 'write to file', include/FFTW_functions.cpp
	FFT_wtf_ZYX(FT_9d, 2, SINPz_Pz, SINPxy_Pxy, n_mom_srcs, NSITES_3D, NSITES_T, sweep_counter, t);
	
	//sprintf(file, "T_data/times_%d-%d_%d_%d.dat", NSITES_3D, NSITES_T, sweep_counter, t);
	//FILE *time_fp = Fopen(file, "a");
	//Fprintf(time_fp, "%.4f %.4f %.4f %.4f\n", time[1], time[2], time[3], time[4]);
	//Fclose(time_fp); 
	
	//////////////////////////////////////////
	// End trace summation at time slice t. //
	//////////////////////////////////////////
      }
    }
  }
  ////////////////////
  // End simulation //
  ////////////////////
  
  sfree(t2_arr);
  sfree(t3_arr);

  //sfree(FT_t1);
  sfree(FT_t4);
  sfree(FT_t2);
  sfree(FT_t3);
  sfree(FT_9d);  


  sfree(time);

  //End();
  return 0;
}
Exemple #15
0
void test_matrix()
{
	struct MeshConfig *conf;
	struct MD *x[2], *x0[2];
	int i;
	double c[2];
	double z0;

	FILE *fplot;

	conf = mesh_new(
		2.4e-3, 10e-3,
		0,
		3e-3,
		0.79e-3,
		2.2
		);

	z0 = mom(conf, x0, x, c);


	printf("C0 = %le F        C1 = %le F\n", c[0], c[1]);
	printf("Z0 = %lf Ohm\n", z0);

	fplot = fopen("dielectric.plot", "w");

	if (fplot) {
		fprintf(fplot, "#!"PATH_GNUPLOT"\n");
		fprintf(fplot, "# top all charges\n");
		fprintf(fplot, "plot '-' notitle with impulse, \\\n"
				"\t'-' notitle with impulse\n");

		for (i = conf->index[ID_STRIP0_START];
			i < conf->index[ID_STRIP0_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}

		for (i = conf->index[ID_DIELECTRIC0_START];
			i < conf->index[ID_DIELECTRIC0_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}
		fprintf(fplot, "e\n");

		fprintf(fplot, "# bottom all charges\n");

		for (i = conf->index[ID_STRIP1_START];
			i < conf->index[ID_STRIP1_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}

		for (i = conf->index[ID_DIELECTRIC1_START];
			i < conf->index[ID_DIELECTRIC1_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}
		fprintf(fplot, "e\npause -1\n");
		/*****/
		fprintf(fplot, "# top free charges\n");
		fprintf(fplot, "plot '-' notitle with impulse, \\\n"
				"\t'-' notitle with impulse\n");

		for (i = conf->index[ID_STRIP0_START];
			i < conf->index[ID_STRIP0_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[0]->buf[i]);
		}

		for (i = conf->index[ID_DIELECTRIC0_START];
			i < conf->index[ID_DIELECTRIC0_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[0]->buf[i]);
		}
		fprintf(fplot, "e\n");

		fprintf(fplot, "# bottom free charges\n");

		for (i = conf->index[ID_STRIP1_START];
			i < conf->index[ID_STRIP1_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[0]->buf[i]);
		}

		for (i = conf->index[ID_DIELECTRIC1_START];
			i < conf->index[ID_DIELECTRIC1_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[0]->buf[i]);
		}
		fprintf(fplot, "e\npause -1\n");
		fclose(fplot);
	}

	fplot = fopen("freespace.plot", "w");

	if (fplot) {
		fprintf(fplot, "#!"PATH_GNUPLOT"\n");
		fprintf(fplot, "# top free charges\n");
		fprintf(fplot, "plot '-' notitle with impulse, \\\n"
				"\t'-' notitle with impulse\n");

		for (i = conf->index[ID_STRIP0_START];
			i < conf->index[ID_STRIP0_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}

		fprintf(fplot, "e\n");

		fprintf(fplot, "# bottom free charges\n");

		for (i = conf->index[ID_STRIP1_START];
			i < conf->index[ID_STRIP1_END]; ++i) {
			fprintf(fplot, "%le %le\n", conf->mesh[i].centre, x[1]->buf[i]);
		}

		fprintf(fplot, "e\npause -1\n");
		fclose(fplot);
	}
	md_free(x[0]);
	md_free(x[1]);

	mesh_free(conf);
}