Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boiling #163

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/microphysics/kessler94.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <snap/thermodynamics/thermodynamics.hpp>

// microphysics
#include <snap/thermodynamics/vapors/water_vapors.hpp>

#include "microphysical_schemes.hpp"

Kessler94::Kessler94(std::string name, YAML::Node const &node)
Expand Down Expand Up @@ -81,7 +83,70 @@ void Kessler94::EvolveOneStep(AirParcel *air, Real time, Real dt) {

air->c[jbuf] += sol(0);
for (int n = 1; n < Size; ++n) air->w[mySpeciesId(n)] += sol(n);

// boiling condition xiz 2024
// get indices
int iv = mySpeciesId(0);
int ic = mySpeciesId(1);
int ip = mySpeciesId(2);

AirParcel airmole = *air; // Copy the air object
airmole.ToMoleFraction(); // Modify the copy
Real tem = airmole.w[IDN]; // Extract the temperature or other property

Real xs = pthermo->svp_func1_[iv][0](airmole, iv, 0) / airmole.w[IPR];
if (xs > 1.) { // boiling
// std::cout << "boiling: " <<pthermo->svp_func1_[iv][0](airmole, iv, 0)
// <<" P:"<< airmole.w[IPR] << std::endl;
air->w[iv] += air->w[ip];
air->w[ip] = 0.;
}
}
/*
for (int n = 0; n < pthermo->cloud_index_set_[iv].size(); ++n) {
//int j = pthermo->GetCloudIndex(iv,n);
// Real xs = pthermo->getSVPFunc1(*air, iv, j, n) / air->w[IPR];
int j = pthermo->cloud_index_set_[iv][n];
Real xs = pthermo->svp_func1_[iv][0](*air, iv, j) / air->w[IPR];

//std::cout << "iv=:" << iv << " bpres=:" << pthermo->getSVPFunc1(*air, iv, 0)
<< std::endl;
//std::cout << "iv=:" << iv << "ic=:" << ic<< "ip=:" << ip<< " j= "<<j<<"
bpres=:" << pthermo->svp_func1_[iv][0](*air, iv, j) << std::endl;
//std::cout << "iv=:" << iv << " j= "<<j<<" bpres=:" <<
pthermo->svp_func1_[iv][0](*air, iv, j) << std::endl;

if (xs > 0.) { // test
//std::cout << "svp nonzero: " <<pthermo->getSVPFunc1(*air, iv, j, n)<<"
P:"<< air->w[IPR]<<" T:"<< tem << " Bsvp:" <<sat_vapor_p_H2O_BriggsS(tem) <<
std::endl;
//std::cout << "svp nonzero: " <<pthermo->svp_func1_[iv][n](*air, iv, j)<<"
P:"<< air->w[IPR]<<" T:"<< tem << " Bsvp:" <<sat_vapor_p_H2O_BriggsS(tem) <<
std::endl;
// std::cout << "iv=:" << iv << " j= "<<j<< " n= "<<n<<" bpres=:" <<
pthermo->svp_func1_[iv][0](*air, iv, j) << std::endl;
//std::cout << "svp nonzero: " <<pthermo->svp_func1_[iv][n](*air, iv, n)<<"
P:"<< air->w[IPR]<<" T:"<< tem << " Bsvp:" <<sat_vapor_p_H2O_BriggsS(tem) <<
std::endl; std::cout << "svp nonzero: " <<pthermo->svp_func1_[iv][0](airmole, 0,
0)<<" P:"<< air->w[IPR]<<" T:"<< tem << " Bsvp:" <<sat_vapor_p_H2O_BriggsS(tem)
<< std::endl;
//std::cout << "svp nonzero: " <<pthermo->svp_func1_[1][1](*air, iv, n)<<"
P:"<< air->w[IPR]<<" T:"<< tem << " Bsvp:" <<sat_vapor_p_H2O_BriggsS(tem) <<
std::endl;
}

if (xs > 1.) { // boiling
//std::cout << "boiling: " <<pthermo->getSVPFunc1(*air, iv, j, n)<<
std::endl;
// std::cout << "boiling: " <<pthermo->svp_func1_[iv][n](*air, iv, j)<<
std::endl;

air->w[iv] += air->w[ip];
air->w[ip] = 0.;
}
}
}
*/

void Kessler94::SetVsedFromConserved(AthenaArray<Real> vsed[3],
Hydro const *phydro, int kl, int ku,
Expand Down
19 changes: 10 additions & 9 deletions src/snap/thermodynamics/saturation_adjustment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ void Thermodynamics::SaturationAdjustment(AirColumn& air_column) const {

for (int i = 1; i <= NVAPOR; ++i) {
Real qv = air.w[i];
if (qv < 0) {
isNeg = true;
std::cout << "gas " << i << " is negative: " << qv << std::endl;
std::cout << "Temp is " << air.w[IDN] << std::endl;
}
// if (qv < 0) {
// isNeg = true;
// std::cout << "gas " << i << " is negative: " << qv <<
// std::endl; std::cout << "Temp is " << air.w[IDN] <<
// std::endl;
// }

#pragma omp simd reduction(+ : qv)
for (auto j : cloud_index_set_[i]) qv += air.c[j];
Expand All @@ -65,10 +66,10 @@ void Thermodynamics::SaturationAdjustment(AirColumn& air_column) const {

// vapor condensation rate
air.w[i] += rates[0];
if (isNeg && i == 1) {
std::cout << "new qv: " << air.w[i] << std::endl;
std::cout << "rate: " << rates[0] << std::endl;
}
// if (isNeg && i == 1) {
// std::cout << "new qv: " << air.w[i] << std::endl;
// std::cout << "rate: " << rates[0] << std::endl;
// }
// cloud concentration rates
for (int j = 1; j < rates.size(); ++j) {
air.c[cloud_index_set_[i][j - 1]] += rates[j];
Expand Down
11 changes: 9 additions & 2 deletions src/snap/thermodynamics/thermodynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ class Thermodynamics {
return cv_ratio_mass_[n] * cvd;
}

// xiz add svp_func1_1 and cloud_index_set_ to public 2024
//! saturation vapor pressure function: Vapor -> Cloud
SVPFunc1Container svp_func1_;

//! cloud index set
std::vector<IndexSet> cloud_index_set_;

//! Ratio of specific heat capacity [J/(kg K)] at constant pressure
//! \return $c_{p,i}/c_{p,d}$
Real GetCpRatioMass(int n) const { return cp_ratio_mass_[n]; }
Expand Down Expand Up @@ -438,10 +445,10 @@ class Thermodynamics {
std::array<Real, 1 + NVAPOR> p3_;

//! saturation vapor pressure function: Vapor -> Cloud
SVPFunc1Container svp_func1_;
// SVPFunc1Container svp_func1_;

//! cloud index set
std::vector<IndexSet> cloud_index_set_;
// std::vector<IndexSet> cloud_index_set_;

//! saturation vapor pressure function: Vapor + Vapor -> Cloud
SVPFunc2Container svp_func2_;
Expand Down
Loading