std::unique_ptr<OpenALSoundSource> SoundManager::intern_create_sound_source(const std::string& filename) { assert(sound_enabled); std::unique_ptr<OpenALSoundSource> source(new OpenALSoundSource); ALuint buffer; // reuse an existing static sound buffer SoundBuffers::iterator i = buffers.find(filename); if(i != buffers.end()) { buffer = i->second; } else { // Load sound file std::unique_ptr<SoundFile> file(load_sound_file(filename)); if(file->size < 100000) { buffer = load_file_into_buffer(*file); buffers.insert(std::make_pair(filename, buffer)); } else { std::unique_ptr<StreamSoundSource> source_(new StreamSoundSource); source_->set_sound_file(std::move(file)); return std::move(source_); } log_debug << "Uncached sound \"" << filename << "\" requested to be played" << std::endl; } alSourcei(source->source, AL_BUFFER, buffer); return std::move(source); }
void NonlinearPoissonResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // u residual for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) = 0.0; } for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { for (std::size_t i = 0; i < num_dims_; ++i) { residual_(cell,node) += (1.0 + u_(cell,qp)*u_(cell,qp)) * u_grad_(cell,qp,i) * w_grad_bf_(cell,node,qp,i); } } } } // source function for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) -= w_bf_(cell,node,qp) * source_(cell,qp); } } } }
void NonlinearPoissonSource<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // source function 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); source_(cell,qp) = -2.0 * X[0]; } } }
KOKKOS_INLINE_FUNCTION void J2MiniKernel<EvalT, Traits>::operator()(int cell, int pt) const { constexpr minitensor::Index MAX_DIM{3}; using Tensor = minitensor::Tensor<ScalarT, MAX_DIM>; Tensor F(num_dims_); Tensor const I(minitensor::eye<ScalarT, MAX_DIM>(num_dims_)); Tensor sigma(num_dims_); ScalarT const E = elastic_modulus_(cell, pt); ScalarT const nu = poissons_ratio_(cell, pt); ScalarT const kappa = E / (3.0 * (1.0 - 2.0 * nu)); ScalarT const mu = E / (2.0 * (1.0 + nu)); ScalarT const K = hardening_modulus_(cell, pt); ScalarT const Y = yield_strength_(cell, pt); ScalarT const J1 = J_(cell, pt); ScalarT const Jm23 = 1.0 / std::cbrt(J1 * J1); // fill local tensors F.fill(def_grad_, cell, pt, 0, 0); // Mechanical deformation gradient auto Fm = Tensor(F); if (have_temperature_) { // Compute the mechanical deformation gradient Fm based on the // multiplicative decomposition of the deformation gradient // // F = Fm.Ft => Fm = F.inv(Ft) // // where Ft is the thermal part of F, given as // // Ft = Le * I = exp(alpha * dtemp) * I // // Le = exp(alpha*dtemp) is the thermal stretch and alpha the // coefficient of thermal expansion. ScalarT dtemp = temperature_(cell, pt) - ref_temperature_; ScalarT thermal_stretch = std::exp(expansion_coeff_ * dtemp); Fm /= thermal_stretch; } Tensor Fpn(num_dims_); for (int i{0}; i < num_dims_; ++i) { for (int j{0}; j < num_dims_; ++j) { Fpn(i, j) = ScalarT(Fp_old_(cell, pt, i, j)); } } // compute trial state Tensor const Fpinv = minitensor::inverse(Fpn); Tensor const Cpinv = Fpinv * minitensor::transpose(Fpinv); Tensor const be = Jm23 * Fm * Cpinv * minitensor::transpose(Fm); Tensor s = mu * minitensor::dev(be); ScalarT const mubar = minitensor::trace(be) * mu / (num_dims_); // check yield condition ScalarT const smag = minitensor::norm(s); ScalarT const f = smag - SQ23 * (Y + K * eqps_old_(cell, pt) + sat_mod_ * (1.0 - std::exp(-sat_exp_ * eqps_old_(cell, pt)))); RealType constexpr yield_tolerance = 1.0e-12; if (f > yield_tolerance) { // Use minimization equivalent to return mapping using ValueT = typename Sacado::ValueType<ScalarT>::type; using NLS = J2NLS<EvalT>; constexpr minitensor::Index nls_dim{NLS::DIMENSION}; using MIN = minitensor::Minimizer<ValueT, nls_dim>; using STEP = minitensor::NewtonStep<NLS, ValueT, nls_dim>; MIN minimizer; STEP step; NLS j2nls(sat_mod_, sat_exp_, eqps_old_(cell, pt), K, smag, mubar, Y); minitensor::Vector<ScalarT, nls_dim> x; x(0) = 0.0; LCM::MiniSolver<MIN, STEP, NLS, EvalT, nls_dim> mini_solver( minimizer, step, j2nls, x); ScalarT const alpha = eqps_old_(cell, pt) + SQ23 * x(0); ScalarT const H = K * alpha + sat_mod_ * (1.0 - exp(-sat_exp_ * alpha)); ScalarT const dgam = x(0); // plastic direction Tensor const N = (1 / smag) * s; // update s s -= 2 * mubar * dgam * N; // update eqps eqps_(cell, pt) = alpha; // mechanical source if (have_temperature_ == true && delta_time_(0) > 0) { source_(cell, pt) = (SQ23 * dgam / delta_time_(0) * (Y + H + temperature_(cell, pt))) / (density_ * heat_capacity_); } // exponential map to get Fpnew Tensor const A = dgam * N; Tensor const expA = minitensor::exp(A); Tensor const Fpnew = expA * Fpn; for (int i{0}; i < num_dims_; ++i) { for (int j{0}; j < num_dims_; ++j) { Fp_(cell, pt, i, j) = Fpnew(i, j); } } } else { eqps_(cell, pt) = eqps_old_(cell, pt); if (have_temperature_ == true) source_(cell, pt) = 0.0; for (int i{0}; i < num_dims_; ++i) { for (int j{0}; j < num_dims_; ++j) { Fp_(cell, pt, i, j) = Fpn(i, j); } } } // update yield surface yield_surf_(cell, pt) = Y + K * eqps_(cell, pt) + sat_mod_ * (1. - std::exp(-sat_exp_ * eqps_(cell, pt))); // compute pressure ScalarT const p = 0.5 * kappa * (J_(cell, pt) - 1. / (J_(cell, pt))); // compute stress sigma = p * I + s / J_(cell, pt); for (int i(0); i < num_dims_; ++i) { for (int j(0); j < num_dims_; ++j) { stress_(cell, pt, i, j) = sigma(i, j); } } }
void PhaseResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { typedef Intrepid::FunctionSpaceTools FST; FST::scalarMultiplyDataData<ScalarT> (term1_,k_,T_grad_); FST::integrate<ScalarT>(residual_,term1_,w_grad_bf_,Intrepid::COMP_CPP,false); FST::scalarMultiplyDataData<ScalarT> (term2_,rho_cp_,T_dot_); FST::integrate<ScalarT>(residual_,term2_,w_bf_,Intrepid::COMP_CPP,true); for (int i=0; i<source_.size(); ++i) source_[i] *= -1.0; FST::integrate<ScalarT>(residual_,source_,w_bf_,Intrepid::COMP_CPP,true); for (int i=0; i<laser_source_.size(); ++i) laser_source_[i] *= -1.0; FST::integrate<ScalarT>(residual_,laser_source_,w_bf_,Intrepid::COMP_CPP,true); /* std::cout<<"rho Cp values"<<std::endl; for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { std::cout<<rho_cp_(cell,qp)<<" "; } std::cout<<std::endl; } std::cout<<"Thermal cond values"<<std::endl; for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { std::cout<<k_(cell,qp)<<" "; } std::cout<<std::endl; } */ //---------------------------- #if 0 for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { term2_(cell,qp) = rho_cp_(cell,qp)*T_dot_(cell,qp); } } #endif // no rho_cp_ term - equivalent to heat problem // FST::integrate<ScalarT>(residual_,T_dot_,w_bf_,Intrepid::COMP_CPP,true); #if 0 // temperature residual for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) = 0.0; } for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { for (std::size_t i = 0; i < num_dims_; ++i) { residual_(cell,node) += k_(cell,qp) * T_grad_(cell,qp,i) * w_grad_bf_(cell,node,qp,i) + rho_cp_(cell,qp) * T_dot_(cell,qp) * w_bf_(cell,node,qp); } } } } // source function for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) -= source_(cell,qp) * w_bf_(cell,node,qp); } } } #endif }
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); }
void PhaseSource<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // current time const RealType time = workset.current_time; //source function ScalarT laser_beam_radius = 60.0e-6; ScalarT porosity = 0.60; ScalarT particle_dia = 20.0e-6; ScalarT powder_hemispherical_reflectivity = 0.70; ScalarT lambda =2.50; ScalarT pi = 3.1415926535897932; // ScalarT laser_power = 30; ScalarT LaserFlux_Max =(3.0/(pi*laser_beam_radius*laser_beam_radius))*laser_power; ScalarT beta = 1.5*(1.0 - porosity)/(porosity*particle_dia); // Few parameters: 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); // Code for heat into substrate ScalarT Absorptivity_substrate = 0.77; ScalarT S1 = 1.0/(3.0-4.0*powder_hemispherical_reflectivity); ScalarT S2 = powder_hemispherical_reflectivity*a/C; ScalarT S3 = (A*b2 + B*c1)*(exp(2.0*a*lambda) - 1.0); ScalarT S4 = (A*b1 + B*c2)*(exp(-2.0*a*lambda) - 1.0); ScalarT S5 = 3.0*(1.0 - powder_hemispherical_reflectivity)*(1.0 - exp(-lambda))*(1.0 + powder_hemispherical_reflectivity*exp(-lambda)); ScalarT I_value = S1*(S2*(S3 + S4) + S5); ScalarT Substrate_Top = 0.00005; ScalarT Substrate_Bot = 0.00012; // source function 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); // Code for moving laser point ScalarT LaserVelocity_x = 1.0; ScalarT LaserVelocity_z = 0.0; ScalarT Laser_Init_position_x = 0.0; ScalarT Laser_Init_position_z = 0.0; ScalarT Laser_center_x = Laser_Init_position_x + LaserVelocity_x*time; ScalarT Laser_center_z = Laser_Init_position_z + LaserVelocity_z*time; // Note:(0.0003 -Y) is because of the Y axis for the depth_profile is in the negative direction as per the Gusarov's equation. ScalarT radius = sqrt((X - Laser_center_x)*(X - Laser_center_x) + (Z - Laser_center_z)*(Z - Laser_center_z)); if (radius < laser_beam_radius && (0.0003 - Y) >= Substrate_Top && (0.0003 - Y) <= Substrate_Bot) source_(cell,qp) = beta*LaserFlux_Max*pow((1.0-(radius*radius)/(laser_beam_radius*laser_beam_radius)),2)*(Absorptivity_substrate - I_value); else source_(cell,qp) =0.0; } } }