void three_body_system::calc_structure_factors_channels() { if (cont->sf_channels.size() == 0) return; cout << "Calculating structure factors: "; for (auto & ch : cont->sf_channels) { sf_results.push_back(vector<double>()); cout << ch << " "; } cout << endl; double sf_grad = (cont->sf_maximum - cont->sf_minimum) / double(cont->sf_n_points); for (int sf_point_index = 0; sf_point_index < cont->sf_n_points; sf_point_index++) { cout << double(sf_point_index) / double(cont->sf_n_points) << " " << flush; double rP = sf_point_index * sf_grad + cont->sf_minimum; sf_radii.push_back(rP); int sf_ch_index = 0; for (auto & ch : cont->sf_channels) { double oscillator_length = 1.0; if (ch != 0) { int cind = channel_index(ch); oscillator_length = pow(trapping[cind][0][0] / kinetic[cind][0][0], -0.25) / sqrt(2.0); } //else oscillator_length = length_hyperspherical; else oscillator_length = pow(trapping[channel_index(3)][0][0] / kinetic[channel_index(3)][0][0], -0.25); //else oscillator_length = 1.0; vector<double> sf_matrix_elements; for (auto & s1 : states) { for (auto & s2 : states) { sf_matrix_elements.push_back( calc_sf_channel_element(oscillator_length*rP, s1, s2, ch) ); } } double res = 0.0; for (int i=0; i<basis_size; i++) { for (int j=0; j<basis_size; j++) { res += evecs[i] * evecs[j] * sf_matrix_elements[i + basis_size * j]; } } sf_results[sf_ch_index++].push_back(res); if (test_structure_factors) { sf_test_matrices.push_back(vector<double>()); for (int i=0; i<basis_size; i++) { for (int j=0; j<basis_size; j++) { sf_test_matrices.back().push_back(sf_matrix_elements[i + basis_size * j]); } } } } } cout << "... " << endl; compute_sf_test_results(); print_structure_factors(); }
void three_body_system::print_structure_factors() { if (cont->sf_channels.size() == 0) return; int sf_index = 0; for (auto & ch : cont->sf_channels) { cout << "Calculating sf " << ch << endl; double oscillator_length = 1.0; //if (ch != 0){ if (0) { int cind = channel_index(ch); oscillator_length = pow(trapping[cind][0][0] / kinetic[cind][0][0], -0.25) / sqrt(2.0); } //else oscillator_length = length_hyperspherical; else oscillator_length = pow(trapping[channel_index(3)][0][0] / kinetic[channel_index(3)][0][0], -0.25) / sqrt(2.0); ofstream sf_output(name + ".sf" + to_string(ch)); for (unsigned int i = 0; i < sf_radii.size(); i++) { //double temp1 = (ch == 0) ? oscillator_length : 1.0; double temp1 = 1.0; sf_output << temp1 * sf_radii[i] << " " << sf_results[sf_index][i] * oscillator_length / double(cont->permutation_number) << endl; } cout << endl; sf_index++; } }
state_full three_body_system::generate_random_state(double min_r, double max_r, double min_rho, double max_rho, double min_com, double max_com, int angular_index, int channel){ int quiet = 1; int cind = channel_index(channel); double random_log_r = random_double( log(min_r), log(max_r) ); double alpha_r = scale_factor_r[cind] * exp(random_log_r); double random_log_rho = random_double( log(min_rho), log(max_rho) ); double alpha_rho = scale_factor_rho[cind] * exp(random_log_rho); double alpha_com = scale_factor_com[cind] * random_double(min_com, max_com); return state_full(states.size(), &ang->states[angular_index], pow(alpha_r,-2), pow(alpha_rho,-2), pow(alpha_com,-2), channel); }
void three_body_system::generate_states_geometric(){ vector<double> alphas_r, alphas_rho, alphas_com; int channel = 3; int cind = channel_index(channel); double minimum = cont->scale_min_to_r0_r ? cont->basis_min_r * r0_unlike : cont->basis_min_r; double maximum = cont->basis_max_r * pow(trapping[cind][0][0] / kinetic[cind][0][0], -0.125); cout << cont->basis_max_r << " " << pow(trapping[cind][0][0] / kinetic[cind][0][0], -0.125) << endl; geometric_series(alphas_r, minimum, maximum, 2); minimum = cont->scale_min_to_r0_rho ? cont->basis_min_rho * r0_unlike : cont->basis_min_rho; maximum = cont->basis_max_rho * pow(trapping[cind][1][1] / kinetic[cind][1][1], -0.125); geometric_series(alphas_rho, minimum, maximum, 2); if (1 == 1){ //alphas_com.push_back(pow(trapping[2][2] / kinetic[2][2], 0.25)); alphas_com.push_back(1.0/kinetic[cind][2][2]); } else{ minimum = cont->scale_min_to_r0_com ? cont->basis_min_com * r0_unlike : cont->basis_min_com; maximum = cont->basis_max_com * pow(trapping[cind][2][2] / kinetic[cind][2][2], -0.125); geometric_series(alphas_com, minimum, maximum, 1); } states = vector<state_full>(); int index = 0; for (auto & alpha_com : alphas_com){ for (auto & alpha_rho : alphas_rho){ for (auto & alpha_r : alphas_r){ for (auto & angular: ang->states){ states.push_back( state_full(index++, &angular, alpha_r, alpha_rho, alpha_com, 3)); } } } } cout << "Generated geometric series states, total: " << alphas_r.size() << " x " << alphas_rho.size() << " x " << alphas_com.size() << " x " << ang->states.size() << " = " << states.size() << endl; if (true){ print_vector_to_file(alphas_r, name + ".info.alphas_r"); print_vector_to_file(alphas_rho, name + ".info.alphas_rho"); print_vector_to_file(alphas_com, name + ".info.alphas_com"); } }
state_full three_body_system::generate_random_state(int state_generation_mode){ int quiet = 1; int channel = 0; while (abs(channel) == 0){ channel = random_int(-3, 3); } channel = 3; int cind = channel_index(channel); double random_log_r = random_double( log(basis_min_r_scaled), log(basis_max_r) ); if (true){ int randomiser = random_int(0,3); if (randomiser != 0){ random_log_r = random_double( log(0.9*basis_min_r_scaled), log(1000.0 * basis_min_r_scaled) ); } } double alpha_r = scale_factor_r[cind] * exp(random_log_r); double random_log_rho = random_double( log(basis_min_rho_scaled), log(basis_max_rho) ); double alpha_rho = scale_factor_rho[cind] * exp(random_log_rho); double alpha_com = scale_factor_com[cind] * random_double(basis_min_com_scaled, basis_max_com); int temp_int = -1 + ang->generation_modes.size(); int temp_mode = min(state_generation_mode, temp_int); int temp_mode_max = ang->generation_modes[temp_mode].size() - 1; int angular_index = ang->generation_modes[temp_mode][random_int(0, temp_mode_max)]; if (only_2body){ while (true){ angular_index = ang->generation_modes[temp_mode][random_int(0, temp_mode_max)]; if (&ang->states[angular_index].lcom == 0 && ang->states[angular_index].lcoup == ang->ltotal){ break; } } } if (!quiet){ cout << "Generated random state: " << state_full(-1, &ang->states[angular_index], alpha_r, alpha_rho, alpha_com, channel); } return state_full(states.size(), &ang->states[angular_index], pow(alpha_r,-2), pow(alpha_rho,-2), pow(alpha_com,-2), channel); }
int cmd_nick(Channel *channel, User *speaker, const char *text) { int i; Channel *ch; char buf[256]; if(!user_name_is_valid(text)) return 0; if(user_lookup(text) != NULL) /* Refuse if nick is in use. */ return 0; /* Before doing the change, go through all channels and notify. */ snprintf(buf, sizeof buf, "%s is now known as %s\n", user_get_name(speaker), text); for(i = 0; (ch = channel_index(i)) != NULL; i++) { if(channel_user_is_member(ch, speaker)) channel_hear(ch, NULL, buf); } user_set_name(speaker, text); return 1; }
double three_body_system::calc_sf_channel_contribution(double rP, state_full &s1, state_full &s2, int transformation_index1, int transformation_index2, int channel_working, double prefactor) { double res = 0.0; int c = (channel_working == 0) ? 3 : channel_working; state_angular *a1 = &ang->states_transformed[s1.ang->allowed_transformations[transformation_index1]]; state_angular *a2 = &ang->states_transformed[s2.ang->allowed_transformations[transformation_index2]]; if (a1->lcom != a2->lcom) return 0.0; int cind = channel_index(c); prefactor *= 4.0 * Pi / s1.norm / s2.norm * sqrt(Pi / 2.0); for (int kappa=0; kappa < get_kappa_limit(a1, a2); kappa++) { double E = ang->E(kappa, kappa, 0, a2->lr, a2->lrho, a2->lcoup, a1->lr, a1->lrho, a1->lcoup); if (E == 0.0) continue; vector<double> transformed_state; calc_transformed_state(transformed_state, s1, s2, c); double nr_double = a1->nr + a2->nr + (a1->lr + a2->lr - kappa) / 2.0 + 0.01; double nrho_double = a1->nrho + a2->nrho + (a1->lrho + a2->lrho - kappa) / 2.0 + 0.01; int nr = floor(nr_double); int nrho = floor(nrho_double); double com0 = gaussian_integral(s1.alpha_com + s2.alpha_com, a1->lcom + a2->lcom); if (channel_working != 0) res += com0 * E * calc_sf_channel_summand(kappa, nr, nrho, transformed_state, rP); else res += com0 * E * calc_sf_hyper_summand(kappa, nr, a1->lr, nrho, a1->lrho, transformed_state, rP); } res *= prefactor; return res; }
void three_body_system::stochastic_loop(){ // start with a sigle state, the QHO ground state int channel_0 = 3; int cind = channel_index(channel_0); states.push_back( state_full(0, &ang->states[0], scale_factor_r[cind], scale_factor_rho[cind], scale_factor_com[cind], channel_0) ); if (true){ states.push_back( state_full(1, &ang->states[0], 0.8*scale_factor_r[cind], 0.8*scale_factor_rho[cind], scale_factor_com[cind], channel_0) ); } // create initial matrix and "diagonalise" regenerate_matrices(); diagonalise(); select_new_state_competitive(10, 0); /*state_full new_state = generate_random_state(); cout << "New state... " << new_state; double eval; vector<double> S_new_column, H_new_column; test_state(new_state, S_new_column, H_new_column, eval); cout << "New eigenvalue = " << eval << endl;*/ }
void three_body_system::competitive_loop(){ int channel_0 = 3; int cind = channel_index(channel_0); if (cont->use_saved_states){ string state_input_name = name + ".states"; if (only_2body) state_input_name += "_2body"; ifstream state_input(state_input_name); string line; while (getline(state_input, line)){ string line_temp = line; if (line_temp.find("Fin") == std::string::npos) states.push_back(state_full(line, ang)); } cout << "Successfully read states from file." << endl; } if (states.size() == 0){ states.push_back( state_full(0, &ang->states[0], scale_factor_r[cind], scale_factor_rho[cind], scale_factor_com[cind], channel_0) ); string state_output_name = name + ".states"; if (only_2body) state_output_name += "_2body"; ofstream state_output(state_output_name, ios_base::app); state_output << states.back(); } regenerate_matrices(); diagonalise(); // determine what mode we're in initially... int current_mode = 0; int state_counter = states.size(); for (auto mode_size : cont->max_states){ if (state_counter >= mode_size){ current_mode++; state_counter -= mode_size; } else{ break; } } int end_test_counter = 0; int fail_counter = 0; int fail_limit = 2; double energy_old = evals[0]; double convtol = 1E-6; string energy_output_name = name + ".energies"; if (only_2body){ energy_output_name = name + ".2body"; } ofstream energy_output(energy_output_name, ios_base::app); for (; current_mode < int(cont->max_states.size()); current_mode++){ int mode_size = cont->max_states[current_mode]; int fail_counter = 0; cout << "sc = " << state_counter << endl; while (state_counter++ <= mode_size){ if (select_new_state_competitive(1000, current_mode)){ if (relative_difference(energy_old, evals[0]) < convtol){ fail_counter++; } else{ cout << energy_old << " " << evals[0] << " " << relative_difference(energy_old, evals[0]) << endl; energy_old = evals[0]; fail_counter = 0; energy_output << states.size() << ": " << flush; for (unsigned int i=0; i<10; i++){ if (i < evals.size()){ energy_output << evals[i] << " "; } } energy_output << endl; //break; } } else fail_counter++; if (fail_counter != 0) cout << "fails = " << fail_counter << endl; if (fail_counter >= fail_limit){ cout << "Cannot find new states, ending simulation..." << endl; break; } } state_counter = 0; cout << "Completed mode " << current_mode << endl; cout << "state_counter = " << state_counter << endl; cout << "mode_size = " << mode_size << endl; } //print_matrix_to_file(&S[0], basis_size, name + ".S"); //print_matrix_to_file(&H[0], basis_size, name + ".H"); }