|
33 | 33 | void ExternalPIVAlign::compute()
|
34 | 34 | {
|
35 | 35 | int N = m_system->size();
|
36 |
| - double hx = m_hx, hy = m_hy, hz = m_hz; |
37 |
| - |
38 |
| - for (int i = 0; i < N; i++) |
| 36 | + double gamma = m_gamma; |
| 37 | + double dx = (m_xhi - m_xlow)/(m_nx-1), dy = (m_yhi - m_ylow)/(m_ny - 1); |
| 38 | + |
| 39 | + double t = static_cast<double>(m_step_counter) / static_cast<double>(m_n_piv_steps); |
| 40 | + for (int i = 0; i < N; i++) |
39 | 41 | {
|
40 | 42 | Particle& pi = m_system->get_particle(i);
|
41 | 43 | if (m_has_params)
|
| 44 | + gamma = m_type_params[pi.get_type()-1].gamma; |
| 45 | + if (pi.x > m_xhi || pi.x < m_xlow || pi.y > m_yhi || pi.y < m_ylow) |
| 46 | + throw runtime_error("One of the cells is outside the PIV mesh range. Please confien the system or make a larger PIV mesh"); |
| 47 | + |
| 48 | + int I = int((pi.x - m_xlow) / dx); |
| 49 | + int J = int((pi.y - m_ylow) / dy); |
| 50 | + |
| 51 | + double u_c = m_u[m_piv_frame_counter].piv_data[I][J], u_n = m_u[m_piv_frame_counter + 1].piv_data[I][J]; |
| 52 | + double v_c = m_v[m_piv_frame_counter].piv_data[I][J], v_n = m_v[m_piv_frame_counter + 1].piv_data[I][J]; |
| 53 | + |
| 54 | + double u = t * u_c + (1.0 - t) * u_n; |
| 55 | + double v = t * v_c + (1.0 - t) * v_n; |
| 56 | + |
| 57 | + double vel = sqrt(u * u + v * v); |
| 58 | + if (vel > 0.0) |
42 | 59 | {
|
43 |
| - hx = m_type_params[pi.get_type()-1].hx; |
44 |
| - hy = m_type_params[pi.get_type()-1].hy; |
45 |
| - hz = m_type_params[pi.get_type()-1].hz; |
| 60 | + u *= gamma/vel; |
| 61 | + v *= gamma/vel; |
46 | 62 | }
|
47 |
| - pi.tau_x += hy*pi.nz - hz*pi.ny; |
48 |
| - pi.tau_y += hz*pi.nx - hx*pi.nz; |
49 |
| - pi.tau_z += hx*pi.ny - hy*pi.nx; |
| 63 | + pi.tau_z += u*pi.ny - v*pi.nx; |
| 64 | + |
50 | 65 | }
|
| 66 | + m_step_counter++; |
| 67 | + if (m_step_counter % m_n_piv_steps == 0) |
| 68 | + { |
| 69 | + m_piv_frame_counter++; |
| 70 | + m_step_counter = 0; |
| 71 | + } |
| 72 | + if (m_piv_frame_counter >= m_u.size()) |
| 73 | + throw runtime_error("Simulation time exceeded avaliable PIV snapshots."); |
51 | 74 | }
|
52 | 75 |
|
53 | 76 | // Private member function
|
54 |
| -void ExternalPIVAlign::__read_csv(const string & fame, PIVData & data) |
| 77 | +void ExternalPIVAlign::__read_csv(const string & fname, PIVData & data) |
55 | 78 | {
|
56 |
| - ifstream f(fname.c_str()); |
57 |
| - while (f.good()) |
| 79 | + std::ifstream f(fname.c_str()); |
| 80 | + if (f) |
58 | 81 | {
|
59 |
| - string line; |
60 |
| - getline(f, line); |
61 |
| - if (line.length() > 0) |
| 82 | + while (f.good()) |
62 | 83 | {
|
63 |
| - istringstream buffer(line); |
64 |
| - string sval; |
65 |
| - vector<double> fline; |
66 |
| - while (getline(buffer, sval, ',')) |
67 |
| - fline.push_back(stod(sval)); |
68 |
| - data.piv_data.push_back(fline); |
| 84 | + string line; |
| 85 | + std::getline(f, line); |
| 86 | + if (line.length() > 0) |
| 87 | + { |
| 88 | + std::istringstream buffer(line); |
| 89 | + string sval; |
| 90 | + vector<double> fline; |
| 91 | + while (getline(buffer, sval, ',')) |
| 92 | + fline.push_back(stod(sval)); |
| 93 | + data.piv_data.push_back(fline); |
| 94 | + } |
69 | 95 | }
|
70 | 96 | }
|
| 97 | + else |
| 98 | + { |
| 99 | + throw runtime_error("Could not open file " + fname + "."); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Get a list of all files matching base name |
| 104 | +void ExternalPIVAlign::__get_file_list(const string & base_name, vector<string> & all_matching_files) |
| 105 | +{ |
| 106 | + const boost::regex filter(base_name + ".*\\."+m_ext); |
| 107 | + directory_iterator end_itr; |
| 108 | + for(directory_iterator i(m_path); i != end_itr; ++i) |
| 109 | + { |
| 110 | + if( !is_regular_file(i->status()) ) continue; |
| 111 | + boost::smatch what; |
| 112 | + if( !boost::regex_match(i->path().filename().string(), what, filter) ) continue; |
| 113 | + all_matching_files.push_back(m_path+i->path().filename().string()); |
| 114 | + } |
| 115 | + sort(all_matching_files.begin(), all_matching_files.end()); |
71 | 116 | }
|
0 commit comments