diff --git a/Source/Spray/SprayIO.cpp b/Source/Spray/SprayIO.cpp index 96a4c4240..607be658d 100644 --- a/Source/Spray/SprayIO.cpp +++ b/Source/Spray/SprayIO.cpp @@ -82,20 +82,20 @@ SprayParticleContainer::SprayParticleIO( if (!file.good()) { FileOpenFailed(filename); } - if(js->m_use_Fluentdpmfile) - { - file << js->jet_name() << " " << js->num_ppp() << " " - << js->m_sumInjMass << " " << js->m_sumInjTime << " " - << js->m_minParcel << " " << js->m_totalInjMass << " " - << js->m_totalInjTime << " " << js->get_flow_time_initial_injection()<<" "<get_dpm_time_initial_injection()<<" " - << js->m_cur_inj_flw_time<<" "<< js->m_cur_inj_dpm_time<<"\n"; - } - else - { - file << js->jet_name() << " " << js->num_ppp() << " " - << js->m_sumInjMass << " " << js->m_sumInjTime << " " - << js->m_minParcel << " " << js->m_totalInjMass << " " - << js->m_totalInjTime << "\n"; + if (js->m_use_Fluentdpmfile) { + file << js->jet_name() << " " << js->num_ppp() << " " + << js->m_sumInjMass << " " << js->m_sumInjTime << " " + << js->m_minParcel << " " << js->m_totalInjMass << " " + << js->m_totalInjTime << " " + << js->get_flow_time_initial_injection() << " " + << js->get_dpm_time_initial_injection() << " " + << js->m_cur_inj_flw_time << " " << js->m_cur_inj_dpm_time + << "\n"; + } else { + file << js->jet_name() << " " << js->num_ppp() << " " + << js->m_sumInjMass << " " << js->m_sumInjTime << " " + << js->m_minParcel << " " << js->m_totalInjMass << " " + << js->m_totalInjTime << "\n"; } file.flush(); @@ -147,32 +147,31 @@ SprayParticleContainer::PostInitRestart(const std::string& dir) Vector fluentdpm_inj_init_dpm_time(in_numjets); Vector fluentdpm_inj_nxt_flw_time(in_numjets); Vector fluentdpm_inj_nxt_dpm_time(in_numjets); - for (int i = 0; i < in_numjets; ++i) - { - JetDataFile >> in_jet_names[i] >> in_inj_ppp[i] >> in_inj_mass[i] >> + for (int i = 0; i < in_numjets; ++i) { + JetDataFile >> in_jet_names[i] >> in_inj_ppp[i] >> in_inj_mass[i] >> in_inj_time[i] >> in_min_parcel[i] >> in_total_mass[i] >> in_total_time[i]; - std::string in_name = in_jet_names[i]; - - bool jet_is_fluent_dpm_based=false; - //Find if the jet is a fluentdpm based jet - for (int mjets = 0; mjets < numjets; ++mjets) - { - SprayJet* js = m_sprayJets[mjets].get(); + std::string in_name = in_jet_names[i]; - if (js->jet_name() == in_name && js->m_use_Fluentdpmfile && !js->m_rstrt_Fltdpmsim_from_nonFltDPMChckPointFile) - { - JetDataFile >> fluentdpm_inj_init_flw_time[i]>> - fluentdpm_inj_init_dpm_time[i]>>fluentdpm_inj_nxt_flw_time[i]>> - fluentdpm_inj_nxt_dpm_time[i]; - jet_is_fluent_dpm_based=true; + bool jet_is_fluent_dpm_based = false; + // Find if the jet is a fluentdpm based jet + for (int mjets = 0; mjets < numjets; ++mjets) { + SprayJet* js = m_sprayJets[mjets].get(); - } - if(jet_is_fluent_dpm_based) //Not fluent dpm based. Read the values the old way - { - break; - } - } + if ( + js->jet_name() == in_name && js->m_use_Fluentdpmfile && + !js->m_rstrt_Fltdpmsim_from_nonFltDPMChckPointFile) { + JetDataFile >> fluentdpm_inj_init_flw_time[i] >> + fluentdpm_inj_init_dpm_time[i] >> fluentdpm_inj_nxt_flw_time[i] >> + fluentdpm_inj_nxt_dpm_time[i]; + jet_is_fluent_dpm_based = true; + } + if (jet_is_fluent_dpm_based) // Not fluent dpm based. Read the values + // the old way + { + break; + } + } } for (int ijets = 0; ijets < in_numjets; ++ijets) { std::string in_name = in_jet_names[ijets]; @@ -186,17 +185,23 @@ SprayParticleContainer::PostInitRestart(const std::string& dir) js->m_totalInjMass = in_total_mass[ijets]; js->m_totalInjTime = in_total_time[ijets]; - if (js->m_use_Fluentdpmfile && !js->m_rstrt_Fltdpmsim_from_nonFltDPMChckPointFile) - { - js->set_initial_injection_flow_time(fluentdpm_inj_init_flw_time[ijets]); - js->set_initial_injection_dpm_time(fluentdpm_inj_init_dpm_time[ijets]); - js->m_cur_inj_flw_time=fluentdpm_inj_nxt_flw_time[ijets]; - js->m_cur_inj_dpm_time=fluentdpm_inj_nxt_dpm_time[ijets]; - - amrex::Print()<<" For jet "<jet_name()<<", next injection flow time = "<m_cur_inj_flw_time<<" and next injection dpm time = "<m_cur_inj_dpm_time<<"\n"; + if ( + js->m_use_Fluentdpmfile && + !js->m_rstrt_Fltdpmsim_from_nonFltDPMChckPointFile) { + js->set_initial_injection_flow_time( + fluentdpm_inj_init_flw_time[ijets]); + js->set_initial_injection_dpm_time( + fluentdpm_inj_init_dpm_time[ijets]); + js->m_cur_inj_flw_time = fluentdpm_inj_nxt_flw_time[ijets]; + js->m_cur_inj_dpm_time = fluentdpm_inj_nxt_dpm_time[ijets]; + amrex::Print() + << " For jet " << js->jet_name() + << ", next injection flow time = " << js->m_cur_inj_flw_time + << " and next injection dpm time = " << js->m_cur_inj_dpm_time + << "\n"; } - } + } } } } diff --git a/Source/Spray/SprayInjection.H b/Source/Spray/SprayInjection.H index 0ba056bc9..53592942d 100644 --- a/Source/Spray/SprayInjection.H +++ b/Source/Spray/SprayInjection.H @@ -7,219 +7,231 @@ problem-specific SprayParticlesInitInsert.cpp file, when necessary. */ -//Added by Sreejith for A74 simulation +// Added by Sreejith for A74 simulation -std::ifstream& GotoLine(std::ifstream& file, long int num){ - file.seekg(std::ios::beg); - for(int i=0; i < num - 1; ++i){ - file.ignore(std::numeric_limits::max(),'\n'); - } - return file; +std::ifstream& +GotoLine(std::ifstream& file, long int num) +{ + file.seekg(std::ios::beg); + for (int i = 0; i < num - 1; ++i) { + file.ignore(std::numeric_limits::max(), '\n'); + } + return file; } - void SprayParticleContainer::sprayInjectionfromDPMFile( - const amrex::Real time, - SprayJet* spray_jet, - const amrex::Real sim_dt, - const int level) + const amrex::Real time, + SprayJet* spray_jet, + const amrex::Real sim_dt, + const int level) { - if (!spray_jet->jet_active(time) || sim_dt <= 0.) - { - amrex::Print()<<"Warning! Spray jet "<jet_name()<<" is inactive and hence 0 particles are injected.\n"; - return; - } - - if (amrex::ParallelDescriptor::IOProcessor()) - { - amrex::Real dt = sim_dt; - - SprayUnits SPU; - const SprayData* fdat = m_sprayData; - - - - while(fabs(time-dt-spray_jet->m_cur_inj_flw_time)<1e-15 || time-dt>=spray_jet->m_cur_inj_flw_time) - { - //Line numbers in the dpm file - long int lineno_current_dpm_time_begin=0; - long int lineno_current_dpm_time_end=0; - long int lineno_next_dpm_time_begin=0; - long int lineno_first_dpm_time_begin=0; - long int lineno_last_dpm_time_end=0; - bool found_dpm_time_in_file=false; - - long int ln; //iterating index - amrex::Real dummy_time=-1; - amrex::Real part_loc[3]; - amrex::Real part_vel[3]; - amrex::Real dia,temperature,parcel_mass,particle_mass,nppp; - - long int dummy_line_no; - std::ifstream is_dpm(spray_jet->m_FluentDPMFile, std::ios::in); - is_dpm>>dummy_line_no; //Reading total number of time instants to a dummy variable - - long int ctr=0; - - //Locate the current injection dpm time in the dpm file - while(abs(dummy_time-spray_jet->m_cur_inj_dpm_time)>1e-9 && ctr<=spray_jet->m_dpm_num_of_time_instants) - { - if(ctr==0) - { - is_dpm>>dummy_time>>lineno_first_dpm_time_begin; - dummy_line_no=lineno_first_dpm_time_begin; - } - else - { - is_dpm>>dummy_time>>dummy_line_no; - } - ctr++; - } - if(ctr>spray_jet->m_dpm_num_of_time_instants) - { - amrex::Abort("Error! Unable to find the current injection dpm time in file.\n"); - } - - if(dummy_time==spray_jet->m_cur_inj_dpm_time && spray_jet->m_cur_inj_dpm_time==spray_jet->dpm_final_time()) //The last time in the dpm file - { - is_dpm>>lineno_last_dpm_time_end; //includes the last line no - lineno_current_dpm_time_begin=dummy_line_no; - lineno_current_dpm_time_end=lineno_last_dpm_time_end; - - //if dpm file is periodic, the next time instant is time=0 - if(spray_jet->is_dpm_periodic) - { - spray_jet->m_nxt_inj_dpm_time=0.0; - lineno_next_dpm_time_begin=lineno_first_dpm_time_begin; - } - else - { - spray_jet->m_nxt_inj_dpm_time=-1.0; - spray_jet->set_jet_endtime(spray_jet->m_cur_inj_flw_time); - } - } - else if(dummy_time==spray_jet->m_cur_inj_dpm_time && spray_jet->m_cur_inj_dpm_time!=spray_jet->dpm_final_time()) - { - lineno_current_dpm_time_begin=dummy_line_no; - is_dpm>>spray_jet->m_nxt_inj_dpm_time>>lineno_next_dpm_time_begin; - lineno_current_dpm_time_end=lineno_next_dpm_time_begin-1; - spray_jet->dt_dpm=spray_jet->m_nxt_inj_dpm_time-spray_jet->m_cur_inj_dpm_time; - } - else - { - amrex::Abort("Error! Unable to find the current injection dpm time in the dpm file"); - } - is_dpm.close(); - - //Now reading the particle data - std::ifstream is_dpm1(spray_jet->m_FluentDPMFile, std::ios::in); - GotoLine(is_dpm1,lineno_current_dpm_time_begin); //Skip lines in dpm file till the current injection time - for(ln=0;ln<=lineno_current_dpm_time_end-lineno_current_dpm_time_begin;ln++) - { - amrex::Real pmov1 = amrex::Random(); //Random number to make sure particle is advanced a little bit downstream - amrex::Real pmov = amrex::Random(); - int num_ppp=2; //number of particles per parcel - amrex::Real Y_part[SPRAY_FUEL_NUM]; //Spray fuel mass fraction - amrex::Real rho_part = 0.; //density of particle - amrex::Real dummy_coordinates[AMREX_SPACEDIM]; - bool set_part_Y=false; - - - //Reading parcel/particle details from dpm input file - is_dpm1>>dummy_time>>part_loc[0]>>part_loc[1]>>part_loc[2]>>part_vel[0]>>part_vel[1]>>part_vel[2]>>dia>>temperature>>parcel_mass>>particle_mass>>nppp; - - - amrex::ParticleLocData pld; - std::map, amrex::Gpu::HostVector> host_particles; - ParticleType p; - p.id() = ParticleType::NextID(); - p.cpu() = amrex::ParallelDescriptor::MyProc(); - - //Setting particle properties - //Transforming the particle coordinates to A74 coordinate system - spray_jet->transform_to_new_cs(part_loc); - - if(spray_jet->get_override_injection_plane_dir()!=-1) //Overriding dpm input file particle location on a plane with user specified location - { - part_loc[spray_jet->get_override_injection_plane_dir()]=spray_jet->get_override_injection_plane_loc(); - } - - spray_jet->transform_to_new_cs(part_vel); //Transforming the particle velocity to A74 coordinate system - AMREX_D_TERM( p.rdata(SprayComps::pstateVel) = (part_vel[0]+pmov1);, //Setting the particle velocities - p.rdata(SprayComps::pstateVel + 1) = (part_vel[1]+pmov1);, - p.rdata(SprayComps::pstateVel + 2) = (part_vel[2]+pmov1);); - - for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) //Setting the particle coordinates - { - p.pos(dir) = part_loc[dir] + pmov * dt * p.rdata(SprayComps::pstateVel + dir); - } - - p.rdata(SprayComps::pstateDia) = dia; //Setting the particle density - p.rdata(SprayComps::pstateT) = temperature; //Setting the particle temperature - set_part_Y =spray_jet->get_new_particle(Y_part); //Getting particle mass fractions - if (SPRAY_FUEL_NUM > 1) //Setting particle mass fractions - { - for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) - { - p.rdata(SprayComps::pstateY + spf) = Y_part[spf]; - rho_part += Y_part[spf] / fdat->rhoL(temperature, spf); - } - rho_part = 1. / rho_part; - } - else - { - rho_part = fdat->rhoL(temperature, 0); - p.rdata(SprayComps::pstateY) = 1.; - } - amrex::Real pmass = particle_mass; //Setting parcel mass - spray_jet->m_totalInjMass += parcel_mass; - - - // If KHRT is used, BM1 is shed mass - // If TAB is used, BM1 is y - p.rdata(SprayComps::pstateBM1) = 0.; - p.rdata(SprayComps::pstateBM2) = 0; - p.rdata(SprayComps::pstateFilmHght) = 0.; - p.rdata(SprayComps::pstateN0) = 2; - p.rdata(SprayComps::pstateNumDens) = nppp; - - - bool where = Where(p, pld); - if (!where) - { - amrex::Print()<<"\n Problematic particle = "< ind(pld.m_grid, pld.m_tile); - host_particles[ind].push_back(p); - - for (auto& kv : host_particles) - { - auto grid = kv.first.first; - auto tile = kv.first.second; - const auto& src_tile = kv.second; - auto& dst_tile = GetParticles(level)[std::make_pair(grid, tile)]; - auto old_size = dst_tile.GetArrayOfStructs().size(); - auto new_size = old_size + src_tile.size(); - dst_tile.resize(new_size); - // Copy the AoS part of the host particles to the GPU - amrex::Gpu::copy( amrex::Gpu::hostToDevice, src_tile.begin(), src_tile.end(), - dst_tile.GetArrayOfStructs().begin() + old_size); - } - } - is_dpm1.close(); - spray_jet->m_cur_inj_flw_time+=spray_jet->dt_dpm; - amrex::Print()<<"Injected "<jet_name()<<"\n"; - spray_jet->m_cur_inj_dpm_time=spray_jet->m_nxt_inj_dpm_time; - - amrex::Print()<<"\tNext injection flow time = "<m_cur_inj_flw_time<<"\n"; - amrex::Print()<<"\tNext injection DPM time = "<m_cur_inj_dpm_time<<"\n\n"; - } - } - Redistribute(); + if (!spray_jet->jet_active(time) || sim_dt <= 0.) { + amrex::Print() << "Warning! Spray jet " << spray_jet->jet_name() + << " is inactive and hence 0 particles are injected.\n"; + return; + } + + if (amrex::ParallelDescriptor::IOProcessor()) { + amrex::Real dt = sim_dt; + + SprayUnits SPU; + const SprayData* fdat = m_sprayData; + + while (fabs(time - dt - spray_jet->m_cur_inj_flw_time) < 1e-15 || + time - dt >= spray_jet->m_cur_inj_flw_time) { + // Line numbers in the dpm file + long int lineno_current_dpm_time_begin = 0; + long int lineno_current_dpm_time_end = 0; + long int lineno_next_dpm_time_begin = 0; + long int lineno_first_dpm_time_begin = 0; + long int lineno_last_dpm_time_end = 0; + bool found_dpm_time_in_file = false; + + long int ln; // iterating index + amrex::Real dummy_time = -1; + amrex::Real part_loc[3]; + amrex::Real part_vel[3]; + amrex::Real dia, temperature, parcel_mass, particle_mass, nppp; + + long int dummy_line_no; + std::ifstream is_dpm(spray_jet->m_FluentDPMFile, std::ios::in); + is_dpm >> dummy_line_no; // Reading total number of time instants to a + // dummy variable + + long int ctr = 0; + + // Locate the current injection dpm time in the dpm file + while (abs(dummy_time - spray_jet->m_cur_inj_dpm_time) > 1e-9 && + ctr <= spray_jet->m_dpm_num_of_time_instants) { + if (ctr == 0) { + is_dpm >> dummy_time >> lineno_first_dpm_time_begin; + dummy_line_no = lineno_first_dpm_time_begin; + } else { + is_dpm >> dummy_time >> dummy_line_no; + } + ctr++; + } + if (ctr > spray_jet->m_dpm_num_of_time_instants) { + amrex::Abort( + "Error! Unable to find the current injection dpm time in file.\n"); + } + + if ( + dummy_time == spray_jet->m_cur_inj_dpm_time && + spray_jet->m_cur_inj_dpm_time == + spray_jet->dpm_final_time()) // The last time in the dpm file + { + is_dpm >> lineno_last_dpm_time_end; // includes the last line no + lineno_current_dpm_time_begin = dummy_line_no; + lineno_current_dpm_time_end = lineno_last_dpm_time_end; + + // if dpm file is periodic, the next time instant is time=0 + if (spray_jet->is_dpm_periodic) { + spray_jet->m_nxt_inj_dpm_time = 0.0; + lineno_next_dpm_time_begin = lineno_first_dpm_time_begin; + } else { + spray_jet->m_nxt_inj_dpm_time = -1.0; + spray_jet->set_jet_endtime(spray_jet->m_cur_inj_flw_time); + } + } else if ( + dummy_time == spray_jet->m_cur_inj_dpm_time && + spray_jet->m_cur_inj_dpm_time != spray_jet->dpm_final_time()) { + lineno_current_dpm_time_begin = dummy_line_no; + is_dpm >> spray_jet->m_nxt_inj_dpm_time >> lineno_next_dpm_time_begin; + lineno_current_dpm_time_end = lineno_next_dpm_time_begin - 1; + spray_jet->dt_dpm = + spray_jet->m_nxt_inj_dpm_time - spray_jet->m_cur_inj_dpm_time; + } else { + amrex::Abort("Error! Unable to find the current injection dpm time in " + "the dpm file"); + } + is_dpm.close(); + + // Now reading the particle data + std::ifstream is_dpm1(spray_jet->m_FluentDPMFile, std::ios::in); + GotoLine( + is_dpm1, lineno_current_dpm_time_begin); // Skip lines in dpm file till + // the current injection time + for (ln = 0; + ln <= lineno_current_dpm_time_end - lineno_current_dpm_time_begin; + ln++) { + amrex::Real pmov1 = + amrex::Random(); // Random number to make sure particle is advanced a + // little bit downstream + amrex::Real pmov = amrex::Random(); + int num_ppp = 2; // number of particles per parcel + amrex::Real Y_part[SPRAY_FUEL_NUM]; // Spray fuel mass fraction + amrex::Real rho_part = 0.; // density of particle + amrex::Real dummy_coordinates[AMREX_SPACEDIM]; + bool set_part_Y = false; + + // Reading parcel/particle details from dpm input file + is_dpm1 >> dummy_time >> part_loc[0] >> part_loc[1] >> part_loc[2] >> + part_vel[0] >> part_vel[1] >> part_vel[2] >> dia >> temperature >> + parcel_mass >> particle_mass >> nppp; + + amrex::ParticleLocData pld; + std::map, amrex::Gpu::HostVector> + host_particles; + ParticleType p; + p.id() = ParticleType::NextID(); + p.cpu() = amrex::ParallelDescriptor::MyProc(); + + // Setting particle properties + // Transforming the particle coordinates to A74 coordinate system + spray_jet->transform_to_new_cs(part_loc); + + if ( + spray_jet->get_override_injection_plane_dir() != + -1) // Overriding dpm input file particle location on a plane with + // user specified location + { + part_loc[spray_jet->get_override_injection_plane_dir()] = + spray_jet->get_override_injection_plane_loc(); + } + + spray_jet->transform_to_new_cs( + part_vel); // Transforming the particle velocity to A74 coordinate + // system + AMREX_D_TERM(p.rdata(SprayComps::pstateVel) = (part_vel[0] + pmov1); + , // Setting the particle velocities + p.rdata(SprayComps::pstateVel + 1) = (part_vel[1] + pmov1); + , p.rdata(SprayComps::pstateVel + 2) = + (part_vel[2] + pmov1);); + + for (int dir = 0; dir < AMREX_SPACEDIM; + ++dir) // Setting the particle coordinates + { + p.pos(dir) = + part_loc[dir] + pmov * dt * p.rdata(SprayComps::pstateVel + dir); + } + + p.rdata(SprayComps::pstateDia) = dia; // Setting the particle density + p.rdata(SprayComps::pstateT) = + temperature; // Setting the particle temperature + set_part_Y = spray_jet->get_new_particle( + Y_part); // Getting particle mass fractions + if (SPRAY_FUEL_NUM > 1) // Setting particle mass fractions + { + for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { + p.rdata(SprayComps::pstateY + spf) = Y_part[spf]; + rho_part += Y_part[spf] / fdat->rhoL(temperature, spf); + } + rho_part = 1. / rho_part; + } else { + rho_part = fdat->rhoL(temperature, 0); + p.rdata(SprayComps::pstateY) = 1.; + } + amrex::Real pmass = particle_mass; // Setting parcel mass + spray_jet->m_totalInjMass += parcel_mass; + + // If KHRT is used, BM1 is shed mass + // If TAB is used, BM1 is y + p.rdata(SprayComps::pstateBM1) = 0.; + p.rdata(SprayComps::pstateBM2) = 0; + p.rdata(SprayComps::pstateFilmHght) = 0.; + p.rdata(SprayComps::pstateN0) = 2; + p.rdata(SprayComps::pstateNumDens) = nppp; + + bool where = Where(p, pld); + if (!where) { + amrex::Print() << "\n Problematic particle = " << p.pos(0) << " " + << p.pos(1) << " " << p.pos(2); + // amrex::Abort("Bad injection particle"); + } + + std::pair ind(pld.m_grid, pld.m_tile); + host_particles[ind].push_back(p); + + for (auto& kv : host_particles) { + auto grid = kv.first.first; + auto tile = kv.first.second; + const auto& src_tile = kv.second; + auto& dst_tile = GetParticles(level)[std::make_pair(grid, tile)]; + auto old_size = dst_tile.GetArrayOfStructs().size(); + auto new_size = old_size + src_tile.size(); + dst_tile.resize(new_size); + // Copy the AoS part of the host particles to the GPU + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, src_tile.begin(), src_tile.end(), + dst_tile.GetArrayOfStructs().begin() + old_size); + } + } + is_dpm1.close(); + spray_jet->m_cur_inj_flw_time += spray_jet->dt_dpm; + amrex::Print() << "Injected " << ln << " particles through " + << spray_jet->jet_name() << "\n"; + spray_jet->m_cur_inj_dpm_time = spray_jet->m_nxt_inj_dpm_time; + + amrex::Print() << "\tNext injection flow time = " + << spray_jet->m_cur_inj_flw_time << "\n"; + amrex::Print() << "\tNext injection DPM time = " + << spray_jet->m_cur_inj_dpm_time << "\n\n"; + } + } + Redistribute(); } void @@ -511,7 +523,7 @@ SprayParticleContainer::uniformSprayInit( nparticles.pop_back(); } } // if (which == MyProc) - } // for (int which ... + } // for (int which ... for (auto& kv : host_particles) { auto grid = kv.first.first; auto tile = kv.first.second; diff --git a/Source/Spray/SprayJet.H b/Source/Spray/SprayJet.H index b2f0125b7..96ec16870 100644 --- a/Source/Spray/SprayJet.H +++ b/Source/Spray/SprayJet.H @@ -70,27 +70,20 @@ public: // Call this before using spray jet bool jet_active(const amrex::Real time) const { - if(!m_use_Fluentdpmfile) - { - if (m_jetDia < 0.) - { - amrex::Abort("Jet diameter is not set"); - } - else if (m_avgDia < 0.) - { - amrex::Abort("Average droplet diameter is not set"); - } - else if (m_jetT < 0.) - { - amrex::Abort("Droplet temperature is not set"); - } - } - bool check = true; - if (time < m_startTime || time > m_endTime) - { - check = false; - } - return check; + if (!m_use_Fluentdpmfile) { + if (m_jetDia < 0.) { + amrex::Abort("Jet diameter is not set"); + } else if (m_avgDia < 0.) { + amrex::Abort("Average droplet diameter is not set"); + } else if (m_jetT < 0.) { + amrex::Abort("Droplet temperature is not set"); + } + } + bool check = true; + if (time < m_startTime || time > m_endTime) { + check = false; + } + return check; } inline bool hollow_spray() const { return m_hollowSpray; } @@ -102,29 +95,27 @@ public: amrex::Real get_avg_Y(const int spf) const { return m_jetY[spf]; } - bool use_FluentDPMFile(){return m_use_Fluentdpmfile;} + bool use_FluentDPMFile() { return m_use_Fluentdpmfile; } void set_initial_injection_flow_time(amrex::Real time) { - m_flow_time_initial_injection=time; + m_flow_time_initial_injection = time; } void set_initial_injection_dpm_time(amrex::Real time) { - m_dpm_time_initial_injection=time; + m_dpm_time_initial_injection = time; } void set_final_injection_flow_time() { - if(is_dpm_periodic) - { - m_flow_time_final_injection=1E8; - } - else - { - m_flow_time_final_injection=m_flow_time_initial_injection+m_dpm_time_final; - m_endTime=m_flow_time_final_injection; - } + if (is_dpm_periodic) { + m_flow_time_final_injection = 1E8; + } else { + m_flow_time_final_injection = + m_flow_time_initial_injection + m_dpm_time_final; + m_endTime = m_flow_time_final_injection; + } } void set_jet_vel(amrex::Real jet_vel) { m_jetVel = jet_vel; } @@ -146,10 +137,7 @@ public: } } - void set_jet_endtime(amrex::Real end_time) - { - m_endTime =end_time; - } + void set_jet_endtime(amrex::Real end_time) { m_endTime = end_time; } void set_jet_cent(amrex::RealVect jet_cent, const amrex::Geometry& geom) { @@ -178,29 +166,31 @@ public: } } - void set_override_injection_plane(int dir,amrex::Real loc) + void set_override_injection_plane(int dir, amrex::Real loc) { - m_override_inj_plane_dir=dir; - m_override_inj_plane_loc=loc; + m_override_inj_plane_dir = dir; + m_override_inj_plane_loc = loc; } - void set_dpm_periodic(bool b) + void set_dpm_periodic(bool b) { is_dpm_periodic = b; } + + amrex::Real get_flow_time_initial_injection() { - is_dpm_periodic=b; + return m_flow_time_initial_injection; + } + amrex::Real get_dpm_time_initial_injection() + { + return m_dpm_time_initial_injection; } - amrex::Real get_flow_time_initial_injection(){return m_flow_time_initial_injection;} - amrex::Real get_dpm_time_initial_injection(){return m_dpm_time_initial_injection;} - + amrex::Real dpm_final_time() { return m_dpm_time_final; } - amrex::Real dpm_final_time() + int get_override_injection_plane_dir() { return m_override_inj_plane_dir; } + amrex::Real get_override_injection_plane_loc() { - return m_dpm_time_final; + return m_override_inj_plane_loc; } - int get_override_injection_plane_dir(){return m_override_inj_plane_dir;} - amrex::Real get_override_injection_plane_loc(){return m_override_inj_plane_loc;} - void set_start_time(amrex::Real start_time) { m_startTime = start_time; } void set_end_time(amrex::Real end_time) { m_endTime = end_time; } void set_num_ppp(amrex::Real num_ppp) { m_numPPP = num_ppp; } @@ -313,22 +303,28 @@ public: inline void transform_to_new_cs(amrex::Real vec[AMREX_SPACEDIM]) { - amrex::Real x,y,z; - if(AMREX_SPACEDIM==2) - { - x=vec[0]; - y=vec[1]; - vec[0]=m_translation[0]+(m_trans_matrix[0]*x+m_trans_matrix[1]*y); - vec[1]=m_translation[1]+(m_trans_matrix[2]*x+m_trans_matrix[3]*y); - }else if(AMREX_SPACEDIM==3) - { - x=vec[0]; - y=vec[1]; - z=vec[2]; - vec[0]=m_translation[0]+(m_trans_matrix[0]*x+m_trans_matrix[1]*y+m_trans_matrix[2]*z); - vec[1]=m_translation[1]+(m_trans_matrix[3]*x+m_trans_matrix[4]*y+m_trans_matrix[5]*z); - vec[2]=m_translation[2]+(m_trans_matrix[6]*x+m_trans_matrix[7]*y+m_trans_matrix[8]*z); - } + amrex::Real x, y, z; + if (AMREX_SPACEDIM == 2) { + x = vec[0]; + y = vec[1]; + vec[0] = + m_translation[0] + (m_trans_matrix[0] * x + m_trans_matrix[1] * y); + vec[1] = + m_translation[1] + (m_trans_matrix[2] * x + m_trans_matrix[3] * y); + } else if (AMREX_SPACEDIM == 3) { + x = vec[0]; + y = vec[1]; + z = vec[2]; + vec[0] = + m_translation[0] + + (m_trans_matrix[0] * x + m_trans_matrix[1] * y + m_trans_matrix[2] * z); + vec[1] = + m_translation[1] + + (m_trans_matrix[3] * x + m_trans_matrix[4] * y + m_trans_matrix[5] * z); + vec[2] = + m_translation[2] + + (m_trans_matrix[6] * x + m_trans_matrix[7] * y + m_trans_matrix[8] * z); + } } inline amrex::Real interpolateMdot(const amrex::Real time) const { @@ -342,9 +338,12 @@ public: inline void PrintTransformationMatrix() { - amrex::Print()<<"\n Row1 = "< m_jetY = {{0.}}; - amrex::GpuArray m_trans_matrix = {AMREX_D_DECL(AMREX_D_DECL(1.0,0.0,0.0),AMREX_D_DECL(0.0,1.0,0.0),AMREX_D_DECL(0.0,0.0,1.0))}; - amrex::GpuArray m_translation = {AMREX_D_DECL(0.0,0.0,0.0)}; + amrex::GpuArray m_trans_matrix = + {AMREX_D_DECL( + AMREX_D_DECL(1.0, 0.0, 0.0), + AMREX_D_DECL(0.0, 1.0, 0.0), + AMREX_D_DECL(0.0, 0.0, 1.0))}; + amrex::GpuArray m_translation = { + AMREX_D_DECL(0.0, 0.0, 0.0)}; amrex::Real m_avgDia = -1.; std::unique_ptr m_dropDist; amrex::Real m_startTime = 0.; diff --git a/Source/Spray/SprayJet.cpp b/Source/Spray/SprayJet.cpp index 58584bd72..ed3d77d01 100644 --- a/Source/Spray/SprayJet.cpp +++ b/Source/Spray/SprayJet.cpp @@ -10,165 +10,156 @@ SprayJet::SprayJet(const std::string& jet_name, const amrex::Geometry& geom) std::string ppspray = "spray." + m_jetName; amrex::ParmParse ps(ppspray); - - ps.query("read_from_dpm_file", m_use_Fluentdpmfile); - if(m_use_Fluentdpmfile) - { - if(AMREX_SPACEDIM!=3) - { - amrex::Abort("Injection through Fluent DPM files not implemented for dimensions other than 3, \n"); - } - ps.get("dpm_filename",m_FluentDPMFile); - std::ifstream is_dpm(m_FluentDPMFile, std::ios::in); - if (!is_dpm.good()) { - amrex::FileOpenFailed(m_FluentDPMFile); - } - else - { - long int dummy_line_no; - amrex::Real dummy_dpm_time; - amrex::Print()<<"Using spray particle injection file: "<>m_dpm_num_of_time_instants; - is_dpm>>m_dpm_time_initial>>dummy_line_no; - for(long int i=0;i>dummy_dpm_time>>dummy_line_no; - } - m_dpm_time_final=dummy_dpm_time; - - amrex::Print()<<"Total number of DPM time instants = "<> m_dpm_num_of_time_instants; + is_dpm >> m_dpm_time_initial >> dummy_line_no; + for (long int i = 0; i < m_dpm_num_of_time_instants - 1; i++) { + is_dpm >> dummy_dpm_time >> dummy_line_no; + } + m_dpm_time_final = dummy_dpm_time; - std::vector tmatrix(AMREX_SPACEDIM*AMREX_SPACEDIM); - std::vector dX_translation(AMREX_SPACEDIM); - ps.getarr("trans_matrix", tmatrix); - ps.getarr("translation", dX_translation); - for (int dir = 0; dir < AMREX_SPACEDIM*AMREX_SPACEDIM; ++dir) { - m_trans_matrix[dir] = tmatrix[dir]; - } + amrex::Print() << "Total number of DPM time instants = " + << m_dpm_num_of_time_instants << "\n"; + amrex::Print() << "Spray injection initial time = " << m_dpm_time_initial + << "\n"; + amrex::Print() << "Spray injection final time = " << m_dpm_time_final + << "\n"; + } + is_dpm.close(); + ps.query("m_override_inj_plane_dir", m_override_inj_plane_dir); + if (!(m_override_inj_plane_dir == -1 || m_override_inj_plane_dir == 0 || + m_override_inj_plane_dir == 1 || m_override_inj_plane_dir == 2)) { + amrex::Abort("Override injection plane direction should be -1,0,1 or 2"); + } + ps.query(".", m_rstrt_Fltdpmsim_from_nonFltDPMChckPointFile); + ps.query("m_override_inj_plane_loc", m_override_inj_plane_loc); + ps.query("is_dpm_periodic", is_dpm_periodic); - for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { - m_translation[dir] = dX_translation[dir]; - } + std::vector tmatrix(AMREX_SPACEDIM * AMREX_SPACEDIM); + std::vector dX_translation(AMREX_SPACEDIM); + ps.getarr("trans_matrix", tmatrix); + ps.getarr("translation", dX_translation); + for (int dir = 0; dir < AMREX_SPACEDIM * AMREX_SPACEDIM; ++dir) { + m_trans_matrix[dir] = tmatrix[dir]; + } - ps.query("start_time", m_startTime); - ps.query("end_time", m_endTime); - ps.get("initial_injection_dpm_time",m_dpm_time_initial_injection); - ps.get("initial_injection_flow_time",m_flow_time_initial_injection); - m_cur_inj_dpm_time=m_dpm_time_initial_injection; - m_cur_inj_flw_time=m_flow_time_initial_injection; + for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { + m_translation[dir] = dX_translation[dir]; + } + ps.query("start_time", m_startTime); + ps.query("end_time", m_endTime); + ps.get("initial_injection_dpm_time", m_dpm_time_initial_injection); + ps.get("initial_injection_flow_time", m_flow_time_initial_injection); + m_cur_inj_dpm_time = m_dpm_time_initial_injection; + m_cur_inj_flw_time = m_flow_time_initial_injection; - if (SPRAY_FUEL_NUM == 1) - { - m_jetY[0] = 1.; - } else - { - std::vector in_Y_jet(SPRAY_FUEL_NUM, 0.); - ps.getarr("Y", in_Y_jet); - amrex::Real sumY = 0.; - for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) - { - m_jetY[spf] = in_Y_jet[spf]; - sumY += in_Y_jet[spf]; - } - if (std::abs(sumY - 1.) > 1.E-8) - { - amrex::Abort(ppspray + ".Y must sum to 1"); - } - } - } - else - { - std::string dist_type; - ps.get("dist_type", dist_type); - m_dropDist = DistBase::create(dist_type); - m_dropDist->init(ppspray); - m_avgDia = m_dropDist->get_avg_dia(); - std::vector jcent(AMREX_SPACEDIM); - ps.getarr("jet_cent", jcent); - std::vector jnorm(AMREX_SPACEDIM); - ps.getarr("jet_norm", jnorm); + if (SPRAY_FUEL_NUM == 1) { + m_jetY[0] = 1.; + } else { + std::vector in_Y_jet(SPRAY_FUEL_NUM, 0.); + ps.getarr("Y", in_Y_jet); + amrex::Real sumY = 0.; + for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { + m_jetY[spf] = in_Y_jet[spf]; + sumY += in_Y_jet[spf]; + } + if (std::abs(sumY - 1.) > 1.E-8) { + amrex::Abort(ppspray + ".Y must sum to 1"); + } + } + } else { + std::string dist_type; + ps.get("dist_type", dist_type); + m_dropDist = DistBase::create(dist_type); + m_dropDist->init(ppspray); + m_avgDia = m_dropDist->get_avg_dia(); + std::vector jcent(AMREX_SPACEDIM); + ps.getarr("jet_cent", jcent); + std::vector jnorm(AMREX_SPACEDIM); + ps.getarr("jet_norm", jnorm); - for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { - m_cent[dir] = jcent[dir]; - m_norm[dir] = jnorm[dir]; - } - amrex::Real mag = m_norm.vectorLength(); - m_norm /= mag; - check_jet_cent(geom); - ps.get("jet_dia", m_jetDia); - ps.get("spread_angle", m_spreadAngle); - if (m_spreadAngle < 0. || m_spreadAngle > 180.) { - amrex::Abort("'spread_angle' must be between 0 and 180"); - } - m_spreadAngle *= M_PI / 180.; // Assumes spread angle is in degrees - ps.query("swirl_angle", m_swirlAngle); - if (m_swirlAngle < 0. || m_swirlAngle > 90.) { - amrex::Abort("'swirl_angle' must be between 0 and 90"); - } - m_swirlAngle *= M_PI / 180.; - ps.get("T", m_jetT); - amrex::Real rho_part = 0.; - SprayData* fdat = SprayParticleContainer::getSprayData(); - if (SPRAY_FUEL_NUM == 1) { - m_jetY[0] = 1.; - rho_part = fdat->rhoL(m_jetT, 0); - } else { - std::vector in_Y_jet(SPRAY_FUEL_NUM, 0.); - ps.getarr("Y", in_Y_jet); - amrex::Real sumY = 0.; - for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { - m_jetY[spf] = in_Y_jet[spf]; - sumY += in_Y_jet[spf]; - rho_part += m_jetY[spf] / fdat->rhoL(m_jetT, spf); - } - rho_part = 1. / rho_part; - if (std::abs(sumY - 1.) > 1.E-8) { - amrex::Abort(ppspray + ".Y must sum to 1"); - } - } - ps.query("inject_ppp", m_numPPP); - // If a rate shape profile is generated at - // https://www.cmt.upv.es/#/ecn/download/InjectionRateGenerator/InjectionRateGenerator, - // it can be provided here for use - if (ps.contains("roi_file")) { - amrex::Real cd = 0.; - ps.get("discharge_coeff", cd); - std::string roi_file; - ps.get("roi_file", roi_file); - readROI(roi_file, rho_part, cd); - m_useROI = true; - } else { - ps.query("start_time", m_startTime); - ps.query("end_time", m_endTime); - ps.get("jet_vel", m_jetVel); - m_maxJetVel = m_jetVel; - ps.get("mass_flow_rate", m_massFlow); - if (m_jetVel < 0. || m_massFlow < 0.) { - amrex::Abort("Jet u, T, and mdot must be greater than 0"); - } - } - ps.query("hollow_spray", m_hollowSpray); - if (m_hollowSpray) { - ps.query("hollow_spread", m_hollowSpread); - if (m_hollowSpread < 0. || m_hollowSpread > 180.) { - amrex::Abort("'hollow_spread' must be between 0 and 180"); - } - m_hollowSpread *= M_PI / 180.; - } + for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { + m_cent[dir] = jcent[dir]; + m_norm[dir] = jnorm[dir]; + } + amrex::Real mag = m_norm.vectorLength(); + m_norm /= mag; + check_jet_cent(geom); + ps.get("jet_dia", m_jetDia); + ps.get("spread_angle", m_spreadAngle); + if (m_spreadAngle < 0. || m_spreadAngle > 180.) { + amrex::Abort("'spread_angle' must be between 0 and 180"); + } + m_spreadAngle *= M_PI / 180.; // Assumes spread angle is in degrees + ps.query("swirl_angle", m_swirlAngle); + if (m_swirlAngle < 0. || m_swirlAngle > 90.) { + amrex::Abort("'swirl_angle' must be between 0 and 90"); + } + m_swirlAngle *= M_PI / 180.; + ps.get("T", m_jetT); + amrex::Real rho_part = 0.; + SprayData* fdat = SprayParticleContainer::getSprayData(); + if (SPRAY_FUEL_NUM == 1) { + m_jetY[0] = 1.; + rho_part = fdat->rhoL(m_jetT, 0); + } else { + std::vector in_Y_jet(SPRAY_FUEL_NUM, 0.); + ps.getarr("Y", in_Y_jet); + amrex::Real sumY = 0.; + for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { + m_jetY[spf] = in_Y_jet[spf]; + sumY += in_Y_jet[spf]; + rho_part += m_jetY[spf] / fdat->rhoL(m_jetT, spf); + } + rho_part = 1. / rho_part; + if (std::abs(sumY - 1.) > 1.E-8) { + amrex::Abort(ppspray + ".Y must sum to 1"); + } + } + ps.query("inject_ppp", m_numPPP); + // If a rate shape profile is generated at + // https://www.cmt.upv.es/#/ecn/download/InjectionRateGenerator/InjectionRateGenerator, + // it can be provided here for use + if (ps.contains("roi_file")) { + amrex::Real cd = 0.; + ps.get("discharge_coeff", cd); + std::string roi_file; + ps.get("roi_file", roi_file); + readROI(roi_file, rho_part, cd); + m_useROI = true; + } else { + ps.query("start_time", m_startTime); + ps.query("end_time", m_endTime); + ps.get("jet_vel", m_jetVel); + m_maxJetVel = m_jetVel; + ps.get("mass_flow_rate", m_massFlow); + if (m_jetVel < 0. || m_massFlow < 0.) { + amrex::Abort("Jet u, T, and mdot must be greater than 0"); + } + } + ps.query("hollow_spray", m_hollowSpray); + if (m_hollowSpray) { + ps.query("hollow_spread", m_hollowSpread); + if (m_hollowSpread < 0. || m_hollowSpread > 180.) { + amrex::Abort("'hollow_spread' must be between 0 and 180"); + } + m_hollowSpread *= M_PI / 180.; + } } } @@ -232,14 +223,12 @@ SprayJet::SprayJet( bool SprayJet::get_new_particle(amrex::Real* Y_part) { - for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) - { - Y_part[spf] = m_jetY[spf]; - } - return true; + for (int spf = 0; spf < SPRAY_FUEL_NUM; ++spf) { + Y_part[spf] = m_jetY[spf]; + } + return true; } - // Default get_new_particle bool SprayJet::get_new_particle( diff --git a/Source/Spray/SprayParticles.H b/Source/Spray/SprayParticles.H index b91961d05..e8e13d46e 100644 --- a/Source/Spray/SprayParticles.H +++ b/Source/Spray/SprayParticles.H @@ -58,10 +58,10 @@ public: const int level); void sprayInjectionfromDPMFile( - const amrex::Real time, - SprayJet* spray_jet, - const amrex::Real sim_dt, - const int level); + const amrex::Real time, + SprayJet* spray_jet, + const amrex::Real sim_dt, + const int level); /// \brief General initialization routine for uniformly distributed droplets /// @param num_part Number of parcels to initialize in each direction @@ -322,7 +322,7 @@ public: bool injectParticles( amrex::Real time, amrex::Real dt, int nstep, int level, int finest_level); - void WriteSprayInjectionTemporal(amrex::Real time, int nstep, int level); + void WriteSprayInjectionTemporal(amrex::Real time, int nstep, int level); /// \brief Generalized initializer routine. Calls #InitSprayParticles and /// #PostInitRestart diff --git a/Source/Spray/SpraySetup.cpp b/Source/Spray/SpraySetup.cpp index 41f6453fa..a636f56ad 100644 --- a/Source/Spray/SpraySetup.cpp +++ b/Source/Spray/SpraySetup.cpp @@ -302,7 +302,7 @@ SprayParticleContainer::SprayInitialize(const std::string& restart_dir) bool init_sprays = false; if (restart_dir.empty() && spray_init_file.empty()) { init_sprays = true; - amrex::Print()<<"\nInit sprays = true and restart_dir is empty"; + amrex::Print() << "\nInit sprays = true and restart_dir is empty"; } InitSprayParticles(init_sprays); if (!spray_init_file.empty()) {