|
7 | 7 | problem-specific SprayParticlesInitInsert.cpp file, when necessary.
|
8 | 8 | */
|
9 | 9 |
|
| 10 | +std::ifstream& |
| 11 | +GotoLine(std::ifstream& file, long int num) |
| 12 | +{ |
| 13 | + file.seekg(std::ios::beg); |
| 14 | + for (int i = 0; i < num - 1; ++i) { |
| 15 | + file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); |
| 16 | + } |
| 17 | + return file; |
| 18 | +} |
| 19 | + |
| 20 | +void |
| 21 | +SprayParticleContainer::sprayInjectionfromDPMFile( |
| 22 | + const amrex::Real time, |
| 23 | + SprayJet* spray_jet, |
| 24 | + const amrex::Real sim_dt, |
| 25 | + const int level) |
| 26 | +{ |
| 27 | + |
| 28 | + if (!spray_jet->jet_active(time) || sim_dt <= 0.) { |
| 29 | + if (m_verbose > 0) { |
| 30 | + amrex::Print() << "Warning! Spray jet " << spray_jet->jet_name() |
| 31 | + << " is inactive and hence 0 particles are injected.\n"; |
| 32 | + } |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + if (amrex::ParallelDescriptor::IOProcessor()) { |
| 37 | + amrex::Real dt = sim_dt; |
| 38 | + const amrex::Real smallnum = 1e-15; |
| 39 | + |
| 40 | + while ((std::fabs(time - spray_jet->m_nxt_inj_flw_time) < smallnum || |
| 41 | + time >= spray_jet->m_nxt_inj_flw_time) && |
| 42 | + spray_jet->jet_active(time)) { |
| 43 | + // Line numbers in the dpm file |
| 44 | + long int lineno_current_dpm_time_begin = 0; |
| 45 | + long int lineno_current_dpm_time_end = 0; |
| 46 | + long int lineno_next_dpm_time_begin = 0; |
| 47 | + long int lineno_first_dpm_time_begin; |
| 48 | + long int lineno_last_dpm_time_end = 0; |
| 49 | + |
| 50 | + long int ln; // iterating index |
| 51 | + amrex::Real dummy_time = -1; |
| 52 | + amrex::Real part_loc[3]; |
| 53 | + amrex::Real part_vel[3]; |
| 54 | + amrex::Real dia, temperature, parcel_mass, particle_mass, nppp; |
| 55 | + const amrex::Real verysmallnum = 1.e-15; |
| 56 | + |
| 57 | + long int dummy_line_no; |
| 58 | + std::ifstream is_dpm(spray_jet->m_FluentDPMFile, std::ios::in); |
| 59 | + is_dpm >> dummy_line_no; // Reading total number of time instants to a |
| 60 | + // dummy variable |
| 61 | + |
| 62 | + long int ctr = 0; |
| 63 | + |
| 64 | + // Locate the current injection dpm time in the dpm file |
| 65 | + while (std::fabs(dummy_time - spray_jet->m_cur_inj_dpm_time) > |
| 66 | + verysmallnum && |
| 67 | + ctr <= spray_jet->m_dpm_num_of_time_instants) { |
| 68 | + if (ctr == 0) { |
| 69 | + is_dpm >> dummy_time >> lineno_first_dpm_time_begin; |
| 70 | + dummy_line_no = lineno_first_dpm_time_begin; |
| 71 | + } else { |
| 72 | + is_dpm >> dummy_time >> dummy_line_no; |
| 73 | + } |
| 74 | + ctr++; |
| 75 | + } |
| 76 | + // If after one sweep, current injection dpm time is not found |
| 77 | + if (ctr > spray_jet->m_dpm_num_of_time_instants) { |
| 78 | + amrex::Abort( |
| 79 | + "Error! Unable to find the current injection dpm time in file.\n"); |
| 80 | + } |
| 81 | + |
| 82 | + // If at the last dpm time |
| 83 | + if (m_verbose > 0) { |
| 84 | + amrex::Print() << "\nCollecting particle data at DPM time " |
| 85 | + << dummy_time << std::endl; |
| 86 | + } |
| 87 | + if ( |
| 88 | + dummy_time == spray_jet->m_cur_inj_dpm_time && |
| 89 | + spray_jet->m_cur_inj_dpm_time == |
| 90 | + spray_jet->dpm_final_time()) // The last time in the dpm file |
| 91 | + { |
| 92 | + if (m_verbose > 0) { |
| 93 | + amrex::Print() << " (last dpm time) \n"; |
| 94 | + } |
| 95 | + is_dpm >> lineno_last_dpm_time_end; // includes the last line no |
| 96 | + lineno_current_dpm_time_begin = dummy_line_no; |
| 97 | + lineno_current_dpm_time_end = lineno_last_dpm_time_end; |
| 98 | + |
| 99 | + // if dpm file is periodic, the next time instant is time=0 |
| 100 | + if (spray_jet->is_dpm_periodic) { |
| 101 | + |
| 102 | + spray_jet->m_nxt_inj_dpm_time = spray_jet->dpm_intial_time(); |
| 103 | + // lineno_next_dpm_time_begin = lineno_first_dpm_time_begin; |
| 104 | + } else { |
| 105 | + amrex::Print() << "\nWARNING! No more injection time found in DPM " |
| 106 | + "file. To continue the same injection again, set " |
| 107 | + "'is_dpm_periodic' to true.\n "; |
| 108 | + spray_jet->m_nxt_inj_dpm_time = -1; |
| 109 | + spray_jet->set_end_time(time - verysmallnum); |
| 110 | + } |
| 111 | + } else if ( |
| 112 | + dummy_time == spray_jet->m_cur_inj_dpm_time && |
| 113 | + spray_jet->m_cur_inj_dpm_time != spray_jet->dpm_final_time()) { |
| 114 | + lineno_current_dpm_time_begin = dummy_line_no; |
| 115 | + is_dpm >> spray_jet->m_nxt_inj_dpm_time >> lineno_next_dpm_time_begin; |
| 116 | + lineno_current_dpm_time_end = lineno_next_dpm_time_begin - 1; |
| 117 | + spray_jet->dt_dpm = |
| 118 | + spray_jet->m_nxt_inj_dpm_time - spray_jet->m_cur_inj_dpm_time; |
| 119 | + } else { |
| 120 | + amrex::Abort("Error! Unable to find the current injection dpm time in " |
| 121 | + "the dpm file"); |
| 122 | + } |
| 123 | + is_dpm.close(); |
| 124 | + |
| 125 | + // Now reading the particle data |
| 126 | + std::ifstream is_dpm1(spray_jet->m_FluentDPMFile, std::ios::in); |
| 127 | + GotoLine( |
| 128 | + is_dpm1, lineno_current_dpm_time_begin); // Skip lines in dpm file till |
| 129 | + // the current injection time |
| 130 | + for (ln = 0; |
| 131 | + ln <= lineno_current_dpm_time_end - lineno_current_dpm_time_begin; |
| 132 | + ln++) { |
| 133 | + amrex::Real pmov1 = |
| 134 | + amrex::Random(); // Random number to make sure particle is advanced a |
| 135 | + // little bit downstream |
| 136 | + amrex::Real pmov = amrex::Random(); |
| 137 | + amrex::Real Y_part[SPRAY_FUEL_NUM]; // Spray fuel mass fraction |
| 138 | + bool set_part_Y = false; |
| 139 | + |
| 140 | + // Reading parcel/particle details from dpm input file |
| 141 | + is_dpm1 >> dummy_time >> part_loc[0] >> part_loc[1] >> part_loc[2] >> |
| 142 | + part_vel[0] >> part_vel[1] >> part_vel[2] >> dia >> temperature >> |
| 143 | + parcel_mass >> particle_mass >> nppp; |
| 144 | + |
| 145 | + amrex::ParticleLocData pld; |
| 146 | + std::map<std::pair<int, int>, amrex::Gpu::HostVector<ParticleType>> |
| 147 | + host_particles; |
| 148 | + ParticleType p; |
| 149 | + p.id() = ParticleType::NextID(); |
| 150 | + p.cpu() = amrex::ParallelDescriptor::MyProc(); |
| 151 | + |
| 152 | + // Setting particle properties |
| 153 | + // Transforming the particle coordinates to user-specified coordinate |
| 154 | + // system |
| 155 | + spray_jet->transform_to_new_cs(part_loc); |
| 156 | + |
| 157 | + if ( |
| 158 | + spray_jet->get_override_injection_plane_dir() != |
| 159 | + -1) // Overriding dpm input file particle location on a plane with |
| 160 | + // user specified location |
| 161 | + { |
| 162 | + part_loc[spray_jet->get_override_injection_plane_dir()] = |
| 163 | + spray_jet->get_override_injection_plane_loc(); |
| 164 | + } |
| 165 | + |
| 166 | + spray_jet->transform_to_new_cs( |
| 167 | + part_vel); // Transforming the particle velocity to user-specified |
| 168 | + // coordinate system |
| 169 | + AMREX_D_TERM(p.rdata(SprayComps::pstateVel) = (part_vel[0] + pmov1); |
| 170 | + , // Setting the particle velocities |
| 171 | + p.rdata(SprayComps::pstateVel + 1) = (part_vel[1] + pmov1); |
| 172 | + , p.rdata(SprayComps::pstateVel + 2) = |
| 173 | + (part_vel[2] + pmov1);); |
| 174 | + |
| 175 | + for (int dir = 0; dir < AMREX_SPACEDIM; |
| 176 | + ++dir) // Setting the particle coordinates |
| 177 | + { |
| 178 | + p.pos(dir) = |
| 179 | + part_loc[dir] + pmov * dt * p.rdata(SprayComps::pstateVel + dir); |
| 180 | + } |
| 181 | + |
| 182 | + p.rdata(SprayComps::pstateDia) = dia; // Setting the particle density |
| 183 | + p.rdata(SprayComps::pstateT) = |
| 184 | + temperature; // Setting the particle temperature |
| 185 | + set_part_Y = // NOLINT(clang-analyzer-deadcode.DeadStores) |
| 186 | + spray_jet // NOLINT(clang-analyzer-deadcode.DeadStores) |
| 187 | + ->get_new_particle( // NOLINT(clang-analyzer-deadcode.DeadStores) |
| 188 | + Y_part); // NOLINT(clang-analyzer-deadcode.DeadStores) |
| 189 | + |
| 190 | + if (SPRAY_FUEL_NUM > 1 && set_part_Y) // Setting particle mass fractions |
| 191 | + { |
| 192 | + for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { |
| 193 | + p.rdata(SprayComps::pstateY + spf) = Y_part[spf]; |
| 194 | + } |
| 195 | + } else { |
| 196 | + p.rdata(SprayComps::pstateY) = 1.; |
| 197 | + } |
| 198 | + |
| 199 | + spray_jet->m_totalInjMass += parcel_mass; |
| 200 | + |
| 201 | + // If KHRT is used, BM1 is shed mass |
| 202 | + // If TAB is used, BM1 is y |
| 203 | + p.rdata(SprayComps::pstateBM1) = 0.; |
| 204 | + p.rdata(SprayComps::pstateBM2) = 0; |
| 205 | + p.rdata(SprayComps::pstateFilmHght) = 0.; |
| 206 | + p.rdata(SprayComps::pstateN0) = 2; |
| 207 | + p.rdata(SprayComps::pstateNumDens) = nppp; |
| 208 | + |
| 209 | + bool where = Where(p, pld); |
| 210 | + if (!where) { |
| 211 | + amrex::Print() << "\n Problematic particle = " << p.pos(0) << " " |
| 212 | + << p.pos(1) << " " << p.pos(2); |
| 213 | + // amrex::Abort("Bad injection particle"); |
| 214 | + } |
| 215 | + |
| 216 | + std::pair<int, int> ind(pld.m_grid, pld.m_tile); |
| 217 | + host_particles[ind].push_back(p); |
| 218 | + |
| 219 | + for (auto& kv : host_particles) { |
| 220 | + auto grid = kv.first.first; |
| 221 | + auto tile = kv.first.second; |
| 222 | + const auto& src_tile = kv.second; |
| 223 | + auto& dst_tile = GetParticles(level)[std::make_pair(grid, tile)]; |
| 224 | + auto old_size = dst_tile.GetArrayOfStructs().size(); |
| 225 | + auto new_size = old_size + src_tile.size(); |
| 226 | + dst_tile.resize(new_size); |
| 227 | + // Copy the AoS part of the host particles to the GPU |
| 228 | + amrex::Gpu::copy( |
| 229 | + amrex::Gpu::hostToDevice, src_tile.begin(), src_tile.end(), |
| 230 | + dst_tile.GetArrayOfStructs().begin() + old_size); |
| 231 | + } |
| 232 | + } |
| 233 | + is_dpm1.close(); |
| 234 | + |
| 235 | + if (m_verbose > 0) { |
| 236 | + amrex::Print() << "Injected " << ln << " particles through " |
| 237 | + << spray_jet->jet_name() |
| 238 | + << " at flow time = " << spray_jet->m_nxt_inj_flw_time |
| 239 | + << "\n"; |
| 240 | + } |
| 241 | + spray_jet->m_nxt_inj_flw_time += spray_jet->dt_dpm; |
| 242 | + spray_jet->m_cur_inj_dpm_time = spray_jet->m_nxt_inj_dpm_time; |
| 243 | + |
| 244 | + if (m_verbose > 0) { |
| 245 | + amrex::Print() << "\tNext injection flow time = " |
| 246 | + << spray_jet->m_nxt_inj_flw_time << "\n"; |
| 247 | + amrex::Print() << "\tNext injection DPM time = " |
| 248 | + << spray_jet->m_cur_inj_dpm_time << "\n\n"; |
| 249 | + } |
| 250 | + } |
| 251 | + } |
| 252 | + Redistribute(); |
| 253 | +} |
| 254 | + |
10 | 255 | void
|
11 | 256 | SprayParticleContainer::sprayInjection(
|
12 | 257 | const amrex::Real time,
|
|
0 commit comments