/// Function to rotate all spin around the x-axis void rotate_material_spins_around_x_axis(double ddx, int material){ std::vector< std::vector<double> > x_rotation_matrix,y_rotation_matrix,z_rotation_matrix; // determine rotational matrices for phi, theta rotation vmath::set_rotational_matrix(ddx, 0.0, 0.0, x_rotation_matrix,y_rotation_matrix,z_rotation_matrix); // loop over all spins and rotate by phi around x for(int atom =0;atom<atoms::num_atoms;atom++){ int mat=atoms::type_array[atom]; if(mat==material){ std::vector<double> Sold(3), Snew(3); // Vectors to hold spins // Load spin coordinates Sold[0]=atoms::x_spin_array[atom]; Sold[1]=atoms::y_spin_array[atom]; Sold[2]=atoms::z_spin_array[atom]; // Calculate new spin positions Snew = vmath::matmul(Sold,x_rotation_matrix); // Set new spin positions atoms::x_spin_array[atom]=Snew[0]; atoms::y_spin_array[atom]=Snew[1]; atoms::z_spin_array[atom]=Snew[2]; } } return; }
bool MarketAgent::SellTo(MarketAgent *other, Equip::Type t, bool verbose) { if (other->CanBuy(t, verbose) && CanSell(t, verbose) && other->Pay(this, GetPrice(t), verbose)) { Sold(t); other->Bought(t); return true; } else return false; }
/// @brief Monte Carlo Integrator /// /// @callgraph /// @callergraph /// /// @details Integrates the system using a Monte Carlo solver with tuned step width /// /// @section License /// Use of this code, either in source or compiled form, is subject to license from the authors. /// Copyright \htmlonly © \endhtmlonly Richard Evans, 2009-2011. All Rights Reserved. /// /// @section Information /// @author Richard Evans, [email protected] /// @version 1.0 /// @date 05/02/2011 /// /// @return EXIT_SUCCESS /// /// @internal /// Created: 05/02/2011 /// Revision: --- ///===================================================================================== /// int MonteCarlo(){ // Check for calling of function if(err::check==true) std::cout << "sim::MonteCarlo has been called" << std::endl; // calculate number of steps to calculate int nmoves = atoms::num_atoms; // Declare arrays for spin states std::valarray<double> Sold(3); std::valarray<double> Snew(3); // Temporaries int atom=0; double r=1.0; double Eold=0.0; double Enew=0.0; double DE=0.0; const int AtomExchangeType=atoms::exchange_type; // Material dependent temperature rescaling std::vector<double> rescaled_material_kBTBohr(mp::num_materials); std::vector<double> sigma_array(mp::num_materials); // range for tuned gaussian random move for(int m=0; m<mp::num_materials; ++m){ double alpha = mp::material[m].temperature_rescaling_alpha; double Tc = mp::material[m].temperature_rescaling_Tc; double rescaled_temperature = sim::temperature < Tc ? Tc*pow(sim::temperature/Tc,alpha) : sim::temperature; rescaled_material_kBTBohr[m] = 9.27400915e-24/(rescaled_temperature*1.3806503e-23); sigma_array[m] = rescaled_temperature < 1.0 ? 0.02 : pow(1.0/rescaled_material_kBTBohr[m],0.2)*0.08; } double statistics_moves = 0.0; double statistics_reject = 0.0; // loop over natoms to form a single Monte Carlo step for(int i=0;i<nmoves; i++){ // add one to number of moves counter statistics_moves+=1.0; // pick atom atom = int(nmoves*mtrandom::grnd()); // get material id const int imaterial=atoms::type_array[atom]; // Calculate range for move sim::mc_delta_angle=sigma_array[imaterial]; // Save old spin position Sold[0] = atoms::x_spin_array[atom]; Sold[1] = atoms::y_spin_array[atom]; Sold[2] = atoms::z_spin_array[atom]; // Make Monte Carlo move sim::mc_move(Sold, Snew); // Calculate current energy Eold = sim::calculate_spin_energy(atom, AtomExchangeType); // Copy new spin position atoms::x_spin_array[atom] = Snew[0]; atoms::y_spin_array[atom] = Snew[1]; atoms::z_spin_array[atom] = Snew[2]; // Calculate new energy Enew = sim::calculate_spin_energy(atom, AtomExchangeType); // Calculate difference in Joules/mu_B DE = (Enew-Eold)*mp::material[imaterial].mu_s_SI*1.07828231e23; //1/9.27400915e-24 // Check for lower energy state and accept unconditionally if(DE<0) continue; // Otherwise evaluate probability for move else{ if(exp(-DE*rescaled_material_kBTBohr[imaterial]) >= mtrandom::grnd()) continue; // If rejected reset spin coordinates and continue else{ atoms::x_spin_array[atom] = Sold[0]; atoms::y_spin_array[atom] = Sold[1]; atoms::z_spin_array[atom] = Sold[2]; // add one to rejection counter statistics_reject += 1.0; continue; } } } // Save statistics to sim namespace variable sim::mc_statistics_moves += statistics_moves; sim::mc_statistics_reject += statistics_reject; return EXIT_SUCCESS; }
/// @brief Monte Carlo Integrator /// /// @callgraph /// @callergraph /// /// @details Integrates the system using a Monte Carlo solver with tuned step width /// /// @section License /// Use of this code, either in source or compiled form, is subject to license from the authors. /// Copyright \htmlonly © \endhtmlonly Richard Evans, 2009-2011. All Rights Reserved. /// /// @section Information /// @author Richard Evans, [email protected] /// @version 1.0 /// @date 05/02/2011 /// /// @return EXIT_SUCCESS /// /// @internal /// Created: 05/02/2011 /// Revision: --- ///===================================================================================== /// int MonteCarlo(){ // Check for calling of function if(err::check==true) std::cout << "sim::MonteCarlo has been called" << std::endl; // calculate number of steps to calculate int nmoves = atoms::num_atoms; // Declare arrays for spin states std::valarray<double> Sold(3); std::valarray<double> Snew(3); // Temporaries int atom=0; double r=1.0; double Eold=0.0; double Enew=0.0; double DE=0.0; const double kBTBohr = 9.27400915e-24/(sim::temperature*1.3806503e-23); const int AtomExchangeType=atoms::exchange_type; // Calculate range for move sim::mc_delta_angle=pow(1.0/kBTBohr,0.2)*0.08; // loop over natoms to form a single Monte Carlo step for(int i=0;i<nmoves; i++){ // pick atom atom = int(nmoves*mtrandom::grnd()); // get material id const int imaterial=atoms::type_array[atom]; // Save old spin position Sold[0] = atoms::x_spin_array[atom]; Sold[1] = atoms::y_spin_array[atom]; Sold[2] = atoms::z_spin_array[atom]; // Make Monte Carlo move Snew=sim::mc_move(Sold); // Calculate current energy Eold = sim::calculate_spin_energy(atom, AtomExchangeType); // Copy new spin position atoms::x_spin_array[atom] = Snew[0]; atoms::y_spin_array[atom] = Snew[1]; atoms::z_spin_array[atom] = Snew[2]; // Calculate new energy Enew = sim::calculate_spin_energy(atom, AtomExchangeType); // Calculate difference in Joules/mu_B DE = (Enew-Eold)*mp::material[imaterial].mu_s_SI*1.07828231e23; //1/9.27400915e-24 // Check for lower energy state and accept unconditionally if(DE<0) continue; // Otherwise evaluate probability for move else{ if(exp(-DE*kBTBohr) >= mtrandom::grnd()) continue; // If rejected reset spin coordinates and continue else{ atoms::x_spin_array[atom] = Sold[0]; atoms::y_spin_array[atom] = Sold[1]; atoms::z_spin_array[atom] = Sold[2]; continue; } } } return EXIT_SUCCESS; }