コード例 #1
0
void LaserSource<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  // current time
 const RealType t = workset.current_time;
  
  AMP::LaserCenter Val;
  Val.t = t;
  
  RealType x, y, power_fraction;
  int power;
  LaserData_.getLaserPosition(t,Val,x,y,power,power_fraction);
  ScalarT Laser_center_x = x;
  ScalarT Laser_center_y = y;
  ScalarT Laser_power_fraction = power_fraction;

  // source function
  ScalarT pi = 3.1415926535897932;
  ScalarT LaserFlux_Max;
  // laser on or off
  if ( power == 1 )
    {
      LaserFlux_Max =(3.0/(pi*laser_beam_radius*laser_beam_radius))*laser_power*Laser_power_fraction;
    }
  else
    {
      LaserFlux_Max = 0.0;
    }
  ScalarT beta = 1.5*(1.0 - porosity)/(porosity*particle_dia);

//  Parameters for the depth profile of the laser heat source:
  ScalarT lambda = 2.50;
  ScalarT a = sqrt(1.0 - powder_hemispherical_reflectivity);
  ScalarT A = (1.0 - pow(powder_hemispherical_reflectivity,2))*exp(-lambda);
  ScalarT B = 3.0 + powder_hemispherical_reflectivity*exp(-2*lambda);
  ScalarT b1 = 1 - a;
  ScalarT b2 = 1 + a;
  ScalarT c1 = b2 - powder_hemispherical_reflectivity*b1;
  ScalarT c2 = b1 - powder_hemispherical_reflectivity*b2;
  ScalarT C = b1*c2*exp(-2*a*lambda) - b2*c1*exp(2*a*lambda);
//  Following are few factors defined by the coder to be included while defining the depth profile
  ScalarT f1 = 1.0/(3.0 - 4.0*powder_hemispherical_reflectivity);
  ScalarT f2 = 2*powder_hemispherical_reflectivity*a*a/C;
  ScalarT f3 = 3.0*(1.0 - powder_hemispherical_reflectivity);

//-----------------------------------------------------------------------------------------------
  for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
    for (std::size_t qp = 0; qp < num_qps_; ++qp) {
	  MeshScalarT X = coord_(cell,qp,0);
	  MeshScalarT Y = coord_(cell,qp,1);
	  MeshScalarT Z = coord_(cell,qp,2);

    ScalarT depth_profile = f1*(f2*(A*(b2*exp(2.0*a*beta*Z)-b1*exp(-2.0*a*beta*Z)) - B*(c2*exp(-2.0*a*(lambda - beta*Z))-c1*exp(2.0*a*(lambda-beta*Z)))) + f3*(exp(-beta*Z)+powder_hemispherical_reflectivity*exp(beta*Z - 2.0*lambda)));
    MeshScalarT* XX = &coord_(cell,qp,0);
    ScalarT radius = sqrt((X - Laser_center_x)*(X - Laser_center_x) + (Y - Laser_center_y)*(Y - Laser_center_y));
     if (radius < laser_beam_radius && beta*Z <= lambda)
            laser_source_(cell,qp) = beta*LaserFlux_Max*pow((1.0-(radius*radius)/(laser_beam_radius*laser_beam_radius)),2)*depth_profile;
     else   laser_source_(cell,qp) = 0.0;
	
    }
  }
}
コード例 #2
0
ファイル: PhaseResidual_Def.hpp プロジェクト: gahansen/Albany
  void PhaseResidual<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    // time step
    ScalarT dt = deltaTime(0);
    typedef Intrepid2::FunctionSpaceTools<PHX::Device> FST;

    if (dt == 0.0) dt = 1.0e-15;
    //grab old temperature
    Albany::MDArray T_old = (*workset.stateArrayPtr)[Temperature_Name_];
    
    // Compute Temp rate
    for (std::size_t cell = 0; cell < workset.numCells; ++cell)
      {
        for (std::size_t qp = 0; qp < num_qps_; ++qp)
	  {
            T_dot_(cell, qp) = (T_(cell, qp) - T_old(cell, qp)) / dt;
	  }
      }

    // diffusive term
    FST::scalarMultiplyDataData<ScalarT> (term1_, k_.get_view(), T_grad_.get_view());
    // FST::integrate(residual_, term1_, w_grad_bf_, false);
    //Using for loop to calculate the residual 

    
    // zero out residual
    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int node = 0; node < num_nodes_; ++node) {
        residual_(cell,node) = 0.0;
      }
    }

    //    for (int cell = 0; cell < workset.numCells; ++cell) {
    //      for (int qp = 0; qp < num_qps_; ++qp) {
    //        for (int node = 0; node < num_nodes_; ++node) {
    //          for (int i = 0; i < num_dims_; ++i) {
    //             residual_(cell,node) += w_grad_bf_(cell,node,qp,i) * term1_(cell,qp,i);
    //          }
    //        }
    //      }
    //    }

    //THESE ARE HARD CODED NOW. NEEDS TO BE CHANGED TO USER INPUT LATER
    ScalarT Coeff_volExp = 65.2e-6; //per kelvins
    ScalarT Ini_temp = 300; //kelvins
   
    if (hasConsolidation_) {
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    //Use if consolidation and expansion is considered
	    //  porosity_function1 = pow(	((1.0 - porosity_(cell, qp)) / ((1+Coeff_volExp*(T_(cell,qp) -Ini_temp))*(1.0 - Initial_porosity))), 2);
	    //  porosity_function2 = (1+Coeff_volExp*(T_(cell,qp) -Ini_temp))*(1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
	                    
	    //Use if only consolidation is considered
	    porosity_function1 = pow(	((1.0 - porosity_(cell, qp)) / (1.0 - Initial_porosity)), 2);
	    porosity_function2 = (1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));					
												
	    //In the model that is currently used, the Z-axis corresponds to the depth direction. Hence the term porosity
	    //function1 is multiplied with the second term. 
	    residual_(cell, node) += porosity_function2 * (
							   w_grad_bf_(cell, node, qp, 0) * term1_(cell, qp, 0)
							   + w_grad_bf_(cell, node, qp, 1) * term1_(cell, qp, 1)
							   + porosity_function1 * w_grad_bf_(cell, node, qp, 2) * term1_(cell, qp, 2));
	  }
	}
      }

      // heat source from laser 
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    //Use if consolidation and expansion is considered
	    //  porosity_function2 = (1+Coeff_volExp*(T_(cell,qp) -Ini_temp))*(1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
						
	    //Use if only consolidation is considered
	    porosity_function2 = (1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));

	    residual_(cell, node) -= porosity_function2 * (w_bf_(cell, node, qp) * laser_source_(cell, qp));
	  }
	}
      }

      // all other problem sources
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    //Use if consolidation and expansion is considered
	    //  porosity_function2 = (1+Coeff_volExp*(T_(cell,qp) -Ini_temp))*(1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
						
	    //Use if only consolidation is considered
	    porosity_function2 = (1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
						
	    residual_(cell, node) -= porosity_function2 * (w_bf_(cell, node, qp) * source_(cell, qp));
	  }
	}
      }

      // transient term
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    //Use if consolidation and expansion is considered
	    //  porosity_function2 = (1+Coeff_volExp*(T_(cell,qp) -Ini_temp))*(1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
						
	    //Use if only consolidation is considered
	    porosity_function2 = (1.0 - Initial_porosity) / (1.0 - porosity_(cell, qp));
						
	    residual_(cell, node) += porosity_function2 * (w_bf_(cell, node, qp) * energyDot_(cell, qp));
	  }
	}
      }
    } else { // does not have consolidation
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    residual_(cell, node) += (
				      w_grad_bf_(cell, node, qp, 0) * term1_(cell, qp, 0)
				      + w_grad_bf_(cell, node, qp, 1) * term1_(cell, qp, 1)
				      + w_grad_bf_(cell, node, qp, 2) * term1_(cell, qp, 2));
	  }
	}
      }
      // heat source from laser 
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    residual_(cell, node) -= (w_bf_(cell, node, qp) * laser_source_(cell, qp));
	  }
	}
      }
      // all other problem sources
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    residual_(cell, node) -= (w_bf_(cell, node, qp) * source_(cell, qp));
	  }
	}
      }
      // transient term
      for (int cell = 0; cell < workset.numCells; ++cell) {
	for (int qp = 0; qp < num_qps_; ++qp) {
	  for (int node = 0; node < num_nodes_; ++node) {
	    residual_(cell, node) += (w_bf_(cell, node, qp) * energyDot_(cell, qp));
	  }
	}
      }
    }
         
    // heat source from laser 
    //PHAL::scale(laser_source_, -1.0);
    //FST::integrate(residual_, laser_source_, w_bf_, true);

    // all other problem sources
    //PHAL::scale(source_, -1.0);
    //FST::integrate(residual_, source_, w_bf_, true);

    // transient term
    //FST::integrate(residual_, energyDot_, w_bf_, true);
  }