Przeglądaj źródła

=nothing

binary_fuel
Weiye Wang 6 miesięcy temu
rodzic
commit
9207179246
17 zmienionych plików z 15914 dodań i 349 usunięć
  1. +179
    -0
      .gitignore
  2. +29
    -21
      CMakeLists.txt
  3. BIN
      bin/DLTORC_0.5C3_EP
  4. BIN
      bin/DLTORC_2.0C3_EP
  5. BIN
      bin/DLTORC_C7_EP
  6. BIN
      bin/DLTORC_UNIFAC
  7. +5
    -2
      include/UserData.h
  8. +2
    -2
      include/parse.hpp
  9. +21
    -11
      include/residue.h
  10. +136
    -0
      input_folder/initDropTwoPhase.py
  11. +147
    -0
      input_folder/initDropTwoPhase_ver2.py
  12. +4600
    -0
      input_folder/redKaust-C3.cti
  13. +8147
    -0
      input_folder/redKaust-C3.xml
  14. +2372
    -0
      input_folder/redKaust-C3.yaml
  15. +72
    -52
      src/UserData.cpp
  16. +2
    -3
      src/main.cpp
  17. +202
    -258
      src/residue.cpp

+ 179
- 0
.gitignore Wyświetl plik

@@ -0,0 +1,179 @@
# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Common credential files
**/credentials.json
**/client_secrets.json
**/client_secret.json
*creds*
*.dat
*password*
*.httr-oauth*
# Private Node Modules
node_modules/
creds.js
# Private Files
*.json
*.csv
*.csv.gz
*.tsv
*.tsv.gz
*.xlsx
# Mac/OSX
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/

# clion
cmake-build-*/
.idea/
bin/

+ 29
- 21
CMakeLists.txt Wyświetl plik

@@ -1,42 +1,50 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.12.0)
project(demo)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR} CACHE PATH "Installing prefix of the project" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()

set(CMAKE_CXX_STANDARD 11)
find_package(OpenMP REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(fmt REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GSL REQUIRED IMPORTED_TARGET gsl)
pkg_check_modules(CANTERA REQUIRED IMPORTED_TARGET cantera)

# Define path to header files and libraries
#set(HOME /opt/scientific)
set(CANTERA_DIR /usr/local)
set(IDA_DIR /usr/local)
set(GSL_DIR /usr/local)
set(COOLPROP_DIR /opt/CoolProp/shared_library/Linux)
set(FMT_DIR /usr/local)

set(CANTERA_INCLUDES ${CANTERA_DIR}/include)
set(IDA_INCLUDES ${IDA_DIR}/include)
set(GSL_INCLUDES ${GSL_DIR}/include/gsl)
set(COOLPROP_INCLUDES ${COOLPROP_DIR}/include)
set(FMT_INCLUDES ${FMT_DIR}/include)
set(EIGEN_INCLUDES /opt/eigen-3.4.0)

# Search for source files
aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_LIST)
add_executable(DropletCombustion ${SRC_LIST})

# Set the RPATH parameter
set(CMAKE_INSTALL_RPATH "${IDA_DIR}/lib;${CANTERA_DIR}/lib;${GSL_DIR}/lib;${COOLPROP_DIR}/lib;${FMT_DIR}/lib")
file(GLOB SRC ${PROJECT_SOURCE_DIR}/src/*.cpp)
add_executable(DropletCombustion ${SRC})

# Link libraries
target_link_directories(DropletCombustion PRIVATE ${CANTERA_DIR}/lib ${IDA_DIR}/lib ${GSL_DIR}/lib ${COOLPROP_DIR}/64bit ${FMT_DIR}/lib )
target_link_directories(DropletCombustion PRIVATE ${IDA_DIR}/lib ${COOLPROP_DIR}/64bit)
target_link_libraries(DropletCombustion
PRIVATE cantera_shared sundials_nvecopenmp sundials_ida sundials_sunlinsollapackband gsl gslcblas CoolProp fmt)
PRIVATE
PkgConfig::CANTERA
PkgConfig::GSL
fmt::fmt
Eigen3::Eigen
sundials_nvecopenmp sundials_ida sundials_sunlinsollapackband CoolProp)
target_link_libraries(DropletCombustion PRIVATE OpenMP::OpenMP_CXX)

# Include directories
target_include_directories(DropletCombustion
PRIVATE ${PROJECT_SOURCE_DIR}/include ${CANTERA_INCLUDES} ${IDA_INCLUDES} ${GSL_INCLUDES} ${COOLPROP_INCLUDES} ${FMT_INCLUDES} ${EIGEN_INCLUDES} )
PRIVATE ${PROJECT_SOURCE_DIR}/include ${IDA_INCLUDES} ${COOLPROP_INCLUDES})

# Set the output path
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)



install(TARGETS DropletCombustion
DESTINATION bin)

BIN
bin/DLTORC_0.5C3_EP Wyświetl plik


BIN
bin/DLTORC_2.0C3_EP Wyświetl plik


BIN
bin/DLTORC_C7_EP Wyświetl plik


BIN
bin/DLTORC_UNIFAC Wyświetl plik


+ 5
- 2
include/UserData.h Wyświetl plik

@@ -34,7 +34,7 @@ typedef struct UserDataTag{
/* Current version only support single and binary component(s) droplet */
int dropType;
/* Droplet species gamma using UNIFAC method */
std::vector<double> gamma;
// std::vector<double> gamma;
/* Droplet species composition, C3H8,n-C7H16,etc.*/
std::vector<std::string> dropSpec;
/*droplet initial species mole fractions*/
@@ -188,6 +188,8 @@ typedef struct UserDataTag{
int nSaves;
/*Flag to set write for every regrid:*/
int writeEveryRegrid;
/*Flag to turn on chemistry/reactions*/
int rxns;
/*Solution output file:*/
FILE* output;
/*Flag to write the rates (ydot) of solution components into the
@@ -264,5 +266,6 @@ void setSaneDefaults(UserData data);
void freeUserData(UserData data);
#endif

void getGamma(const std::vector<double>& mole,std::vector<double>& gamma) ;
//void getGamma(const double *mole, std::vector<double>& gamma) ;
void getGamma(const double mole[],double gamma[]);


+ 2
- 2
include/parse.hpp Wyświetl plik

@@ -99,7 +99,7 @@ int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const in
/* Second argument in the strncpy function is the address !!! */
/* Note: current version of code can only take dropType =0 or 1 */
strncpy(buf1, buf+strlen(keyword)+1, bufLen);
printf("%10s: ",keyword);
printf("%30s: ",keyword);
if(*dropType ==0){
getFromString(buf1,&n);
dropPara.push_back(n);
@@ -142,7 +142,7 @@ inline int parseDropSpec<std::string>(FILE* input, const char* keyword, const si
/* Second argument in the strncpy function is the address !!! */
/* Note: current version of code can only take dropType =0 or 1 */
strncpy(buf1, buf+strlen(keyword)+1, bufLen);
printf("%10s: ",keyword);
printf("%30s: ",keyword);
if(*dropType ==0){
/* Convert from char* to string */
//printf("buf1 is %s!\n",buf1) ;


+ 21
- 11
include/residue.h Wyświetl plik

@@ -137,28 +137,38 @@ void getSpecies(UserData data,N_Vector* y,FILE* output);
//double getLiquidMaxT(double dropMole[],double pres);

double getLiquidDensity(const double temp,const double pres, const std::vector<std::string>& composition);
double getLiquidDensity(const double temp,const double pres, std::vector<std::string>& composition,const std::vector<double>& mole);
double getLiquidDensity(const double temp,const double pres, const std::vector<std::string>& composition,const double mole_[]);

double getLiquidCond(const double temp,const double pres, const std::vector<std::string>& composition);
double getLiquidCond(const double temp,const double pres, std::vector<std::string>& composition,const std::vector<double>& mole);
double getLiquidCond(const double temp,const double pres, std::vector<std::string>& composition,const double mole_[]);
double getGasCond(UserData data, double *ydata, size_t gridPoint);

double getLiquidCpb(const double temp,const double pres, const std::vector<std::string>& composition);
double getLiquidCpb(const double temp,const double pres, const std::vector<std::string>& composition,const std::vector<double>& mole);
double getLiquidCpb(const double temp,const double pres, const std::vector<std::string>& composition,const double mole_[]);
void getLiquidCp(const double temp, const double pres, const std::vector<std::string> &composition, double liquidCp[]);

std::vector<double> getLiquidCp(const double temp, const double pres, const std::vector<std::string> &composition);
double getGasCond(UserData data, double *ydata, size_t gridPoint);
std::vector<double> getLiquidVH(const double pres,const int dropType);

void mass2mole(const std::vector<double>& mass,std::vector<double>& mole, UserData data);
void getLiquidMoleVec(UserData data,double* ydata,int gridPoint,double mole_[]);
void getLiquidVH(const double pres, const int dropType, double vapheat[2]);
//void mass2mole(const double mass_[], double mole_[], UserData data);

double getLiquidmassdiff(UserData data, double* ydata, size_t gridPoint,const double temp);
std::vector<double> getLiquidmassvec(UserData data,double* ydata,int gridPoint);
std::vector<double> getLiquidmolevec(UserData data,double* ydata,int gridPoint);

//void getLiquidmassvec(UserData data,double* ydata,int gridPoint, double mass_[]);
//void getLiquidmolevec(UserData data,double* ydata,int gridPoint, double mole_[]);
std::vector<std::string> components(int dropType);

std::vector<double> getVapPressure(UserData data, double* ydata,int gridPoint,const std::vector<double> mole_);
void getVapPressure(UserData data, double* ydata,int gridPoint,const double mole_[],double vapPres[]);

double dropletmass(UserData data,double* ydata);
double dropletmass(UserData data, double *ydata, const std::vector<std::string>& composition);

void printIddata(UserData data, double* iddata);
void printPsidata(UserData data,double* psidata);

void setLiquidTransport(UserData data,
double *ydata,
int gridPoint,
const std::vector<std::string> &composition,
double *rho,
double *lambda,
double *YV);

+ 136
- 0
input_folder/initDropTwoPhase.py Wyświetl plik

@@ -0,0 +1,136 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 14:39:59 2024

@author: wangweiye
"""

import numpy as np
from numpy import power
import cantera as ct
import matplotlib.pyplot as plt
from scipy.interpolate import CubicHermiteSpline

font = {'family':'times',
'color':'darkred',
'weight':'normal',
'size':16}
def calVaporPressure(T:float) ->float :
# return 1e5*np.power(10,4.6543 - (1435.264/(T - 64.84))) # returns Pa, where T is in K
#P = 1e3*np.exp(16.7 - (4060.0/(T - 37.0))) # returns Pa, where T is in K,FOR WATER
#P = 1e5*np.power(10,4.02832-(1268.636/(T-56.199))) ; #FOR N-HEPTANE
P = 0.00 #NO FUEL @ t0
return P

# return 1D numpy array for liquid phase mass fraction
def genLiquidMassFracArr(gas,dropTemp:float,P:float,dropSpec:str) :
gas.TPX = dropTemp,P,dropSpec
massArr_ = gas.Y
# print(gas.Y)
return massArr_

# return 1D numpy array for gas phase mass fraction
def genGasMassFracArr(gas,gasTemp:float,P:float,gasSpec:str):
gas.TPX = gasTemp,P,gasSpec
massArr_ = gas.Y
return massArr_

# return 1D numpy array for gas phase spatial coordinate and temperature
def genGasTempAndRadiusArr(Rd,L,shift,Wmix,nPts,dropTemp,gasTemp):
dX = L/(nPts-1)
r_ = np.zeros(nPts)
r_[0] = Rd
#DEBUG
#print("r_[0] = %15.6e\n"%(r_[0]))
for ii in range(1, nPts-1):
r_[ii] = r_[ii-1] + dX
r_[nPts-1] = Rd+L
x = [Rd+shift, Rd+shift+Wmix] ;
y = [dropTemp, gasTemp] ;
m = [0,0] ;
spline = CubicHermiteSpline(x, y, m)
T_ = np.zeros(nPts)
for i in range(nPts):
if r_[i] < Rd + shift :
T_[i] = dropTemp ;
if r_[i] >= (Rd + shift) and (r_[i] <= Rd + shift + Wmix) :
T_[i] = spline(r_[i]) ;
if r_[i] > (Rd + shift +Wmix) and r_[i] <= (Rd+L) :
T_[i] = gasTemp ;
return r_,T_

# return 2D numpy array with size of (nvar*nPts)
def writeGlobalArr(Rd,L,shift,Wmix,dropTemp,gasTemp,P,dropSpec,gasSpec,gas,lnPts,gnPts,fileName):
liquidMassFracArr_ = genLiquidMassFracArr(gas, dropTemp, P, dropSpec)
gasMassFracArr_ = genGasMassFracArr(gas, gasTemp, P, gasSpec)
# assign spatial coordinate value
rG_,TG_ = genGasTempAndRadiusArr(Rd, L, shift, Wmix, gnPts, dropTemp, gasTemp)
rL_ = np.zeros(lnPts)
dXL = Rd/(lnPts-1)
rL_[0] = 0.0
for ii in range(1, lnPts-1):
rL_[ii] = rL_[ii-1] + dXL
rL_[lnPts-1] = Rd
#DEBUG
# print("last element of rL_ is :%15.6e"%(rL_[lnPts-1]))
# print("first element of rG_ is :%15.6e"%(rG_[0]))
r_ = np.concatenate((rL_,rG_))
# assign temperature values
TL_ = np.ones(lnPts)*dropTemp
T_ = np.concatenate((TL_,TG_))
# assign pressure values
P_ = np.ones(gnPts+lnPts) * P
mdot_ = np.ones(gnPts+lnPts) * 0.0
# write global arr to output file
out=open(fileName,"w")
for i in range(lnPts):
out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
for j in range(gas.n_species):
out.write("%15.6e\t"%(liquidMassFracArr_[j]))
out.write("%15.6e\t"%(P_[i]))
out.write("%15.6e\n"%(mdot_[i]))
for i in range(lnPts,lnPts+gnPts):
out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
for j in range(gas.n_species):
out.write("%15.6e\t"%(gasMassFracArr_[j]))
out.write("%15.6e\t"%(P_[i]))
out.write("%15.6e\n"%(mdot_[i]))
out.close()
# =============================================================================
# Following block defines the user defined parameters
# =============================================================================
if __name__ == "__main__" :
fileName = "initialConditionTest.dat" #This script output the initial conditions
#mech='sdMechMergedVer2.cti'
mech='redKaust-C3.xml' #Mechanism name
#mech='chem171.cti'
gas = ct.Solution(mech)
Rd = 200.0e-6 #droplet radius, Unit:[m]
domainLength = Rd*50.0 #domain length, Unit:[m]
shift = Rd * 3.0e0 #shift of mixing region from droplet surface
Wmix = Rd * 5.0e0 #thickness of mixing layer for heptane mass fraction & Temperature distribution, Unit:[m]
gNpts = 5000 #Number of grid points in gas phase
lNpts = 500 #Number of grid points in liquid phase
Tamb = 1400.00 #Temperature of ambient air, Unit : [K]
Pamb = 20.0*ct.one_atm #Pressure of ambient air, Unit :[Pa]
Td = 310.00 #Temperature of droplet surface, Unit: [K]
#RH = 0.0 #relative humidity
dropName = "C3H8:0.20,NC7H16:0.80" #Name of droplet species
# dropName ="NC7H16:1.00"
gasComposition = "O2:0.21,N2:0.79"
writeGlobalArr(Rd, domainLength, shift, Wmix, Td, Tamb, Pamb, dropName, gasComposition, gas, lNpts, gNpts, fileName)
# writeGlobalArr(Rd, L, shift, Wmix, dropTemp, gasTemp, P, dropSpec, gasSpec, gas, lnPts, gnPts, fileName)
#writeInitCond(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName, fileName)
# genTotalMassfracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName)
# genTemArr(Rd, domainLength, shift, Wmix, nGrid, Tdrop, Tamb)
# genMolefracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH)

+ 147
- 0
input_folder/initDropTwoPhase_ver2.py Wyświetl plik

@@ -0,0 +1,147 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 25 14:37:01 2024

@author: david
"""

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 14:39:59 2024

@author: wangweiye
"""

import numpy as np
from numpy import power
import cantera as ct
import matplotlib.pyplot as plt
from scipy.interpolate import CubicHermiteSpline

font = {'family':'times',
'color':'darkred',
'weight':'normal',
'size':16}
def calVaporPressure(T:float) ->float :
# return 1e5*np.power(10,4.6543 - (1435.264/(T - 64.84))) # returns Pa, where T is in K
#P = 1e3*np.exp(16.7 - (4060.0/(T - 37.0))) # returns Pa, where T is in K,FOR WATER
#P = 1e5*np.power(10,4.02832-(1268.636/(T-56.199))) ; #FOR N-HEPTANE
P = 0.00 #NO FUEL @ t0
return P

# return 1D numpy array for liquid phase mass fraction
def genLiquidMassFracArr(gas,dropTemp:float,P:float,dropSpec:str) :
gas.TPX = dropTemp,P,dropSpec
massArr_ = gas.Y
# print(gas.Y)
return massArr_

# return 1D numpy array for gas phase mass fraction
def genGasMassFracArr(gas,gasTemp:float,P:float,gasSpec:str):
gas.TPX = gasTemp,P,gasSpec
massArr_ = gas.Y
return massArr_

# return 1D numpy array for gas phase spatial coordinate and temperature
def genGasTempAndRadiusArr(Rd,L,shift,Wmix,nPts,dropTemp,gasTemp,deltaT):
dX = L/(nPts-1)
r_ = np.zeros(nPts)
r_[0] = Rd
#DEBUG
#print("r_[0] = %15.6e\n"%(r_[0]))
for ii in range(1, nPts-1):
r_[ii] = r_[ii-1] + dX
r_[nPts-1] = Rd+L
x = [Rd+shift, Rd+shift+Wmix] ;
y = [dropTemp+deltaT, gasTemp] ;
m = [0,0] ;
spline = CubicHermiteSpline(x, y, m)
T_ = np.zeros(nPts)
for i in range(nPts):
if r_[i] <= Rd :
T_[i] = dropTemp ;
if r_[i] > Rd and r_[i] < (Rd+shift):
T_[i] = dropTemp + deltaT ;
if r_[i] >= (Rd + shift) and (r_[i] <= Rd + shift + Wmix) :
T_[i] = spline(r_[i]) ;
if r_[i] > (Rd + shift +Wmix) and r_[i] <= (Rd+L) :
T_[i] = gasTemp ;
return r_,T_

# return 2D numpy array with size of (nvar*nPts)
def writeGlobalArr(Rd,L,shift,Wmix,dropTemp,gasTemp,deltaT,P,dropSpec,gasSpec,gas,lnPts,gnPts,fileName):
liquidMassFracArr_ = genLiquidMassFracArr(gas, dropTemp, P, dropSpec)
gasMassFracArr_ = genGasMassFracArr(gas, gasTemp, P, gasSpec)
# assign spatial coordinate value
rG_,TG_ = genGasTempAndRadiusArr(Rd, L, shift, Wmix, gnPts, dropTemp, gasTemp,deltaT)
rL_ = np.zeros(lnPts)
dXL = Rd/(lnPts-1)
rL_[0] = 0.0
for ii in range(1, lnPts-1):
rL_[ii] = rL_[ii-1] + dXL
rL_[lnPts-1] = Rd
#DEBUG
# print("last element of rL_ is :%15.6e"%(rL_[lnPts-1]))
# print("first element of rG_ is :%15.6e"%(rG_[0]))
r_ = np.concatenate((rL_,rG_))
# assign temperature values
TL_ = np.ones(lnPts)*dropTemp
T_ = np.concatenate((TL_,TG_))
# assign pressure values
P_ = np.ones(gnPts+lnPts) * P
mdot_ = np.ones(gnPts+lnPts) * 0.0
# write global arr to output file
out=open(fileName,"w")
for i in range(lnPts):
out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
for j in range(gas.n_species):
out.write("%15.6e\t"%(liquidMassFracArr_[j]))
out.write("%15.6e\t"%(P_[i]))
out.write("%15.6e\n"%(mdot_[i]))
for i in range(lnPts,lnPts+gnPts):
out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
for j in range(gas.n_species):
out.write("%15.6e\t"%(gasMassFracArr_[j]))
out.write("%15.6e\t"%(P_[i]))
out.write("%15.6e\n"%(mdot_[i]))
out.close()
# =============================================================================
# Following block defines the user defined parameters
# =============================================================================
if __name__ == "__main__" :
fileName = "initialConditionTest.dat" #This script output the initial conditions
#mech='sdMechMergedVer2.cti'
mech='redKaust-C3.xml' #Mechanism name
#mech='chem171.cti'
gas = ct.Solution(mech)
Rd = 200.0e-6 #droplet radius, Unit:[m]
domainLength = Rd*50.0 #domain length, Unit:[m]
shift = Rd * 3.0e0 #shift of mixing region from droplet surface
Wmix = Rd * 5.0e0 #thickness of mixing layer for heptane mass fraction & Temperature distribution, Unit:[m]
gNpts = 5000 #Number of grid points in gas phase
lNpts = 500 #Number of grid points in liquid phase
Tamb = 1400.00 #Temperature of ambient air, Unit : [K]
Pamb = 20.0*ct.one_atm #Pressure of ambient air, Unit :[Pa]
Td = 310.00 #Temperature of droplet surface, Unit: [K]
deltaT = 20.0
#RH = 0.0 #relative humidity
#dropName = "NC7H16:0.80,C3H8:0.20" #Name of droplet species
dropName ="NC7H16:1.00"
gasComposition = "O2:0.21,N2:0.79"
writeGlobalArr(Rd, domainLength, shift, Wmix, Td, Tamb,deltaT, Pamb, dropName, gasComposition, gas, lNpts, gNpts, fileName)
# writeGlobalArr(Rd, L, shift, Wmix, dropTemp, gasTemp, P, dropSpec, gasSpec, gas, lnPts, gnPts, fileName)
#writeInitCond(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName, fileName)
# genTotalMassfracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName)
# genTemArr(Rd, domainLength, shift, Wmix, nGrid, Tdrop, Tamb)
# genMolefracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH)

+ 4600
- 0
input_folder/redKaust-C3.cti
Plik diff jest za duży
Wyświetl plik


+ 8147
- 0
input_folder/redKaust-C3.xml
Plik diff jest za duży
Wyświetl plik


+ 2372
- 0
input_folder/redKaust-C3.yaml
Plik diff jest za duży
Wyświetl plik


+ 72
- 52
src/UserData.cpp Wyświetl plik

@@ -10,7 +10,7 @@ void freeUserData(UserData data){
using Tt = std::vector<size_t>;
data->dropMole.~Td();
data->dropSpec.~Ts();
data->gamma.~Td();
// data->gamma.~Td();
data->MW.~Td();
data->k_drop.~Tt();

@@ -87,7 +87,7 @@ UserData allocateUserData(FILE *input){
data = (UserData) malloc(sizeof *data);
new(&(data->dropMole)) std::vector<double>;
new(&(data->dropSpec)) std::vector<std::string>;
new(&(data->gamma)) std::vector<double>;
// new(&(data->gamma)) std::vector<double>;
new(&(data->MW)) std::vector<double>;
new(&(data->k_drop)) std::vector<size_t>;

@@ -304,6 +304,13 @@ UserData allocateUserData(FILE *input){
return(NULL);
}

ier=parseNumber<int> (input, "rxns", MAXBUFLEN,
&data->rxns);
if(data->rxns!=0 && data->rxns!=1){
printf("rxns must either be 0 or 1!\n");
return(NULL);
}

ier=parseNumber<int> (input, "setConstraints" , MAXBUFLEN,
&data->setConstraints);
if(data->setConstraints!=0 && data->setConstraints!=1){
@@ -461,11 +468,11 @@ UserData allocateUserData(FILE *input){
// printf("Print dropSpec component :%s! \n",data->dropSpec[0].c_str());
// size_t index = 0;
for(size_t k = 1; k <= data->nsp; k++) {
printf("spcies name :%s! \t",data->gas->speciesName(k-1).c_str());
// printf("spcies name :%s! \t",data->gas->speciesName(k-1).c_str());
if(data->gas->speciesName(k - 1)==data->dropSpec[ii] ) {
// index = k;
double weight = data->gas->molecularWeight(k-1);
printf("Molecular weight is: %.3f. \n",weight) ;
// printf("Molecular weight is: %.3f. \n",weight) ;
data->MW.push_back(weight);
}
}
@@ -474,6 +481,17 @@ UserData allocateUserData(FILE *input){
for(auto & arg :data->MW){
printf("Molecular weight : %.3f. \n",arg) ;
}

for(size_t i = 0; i < data->dropMole.size(); i++) {
size_t index = 0;
for (size_t k = 1; k <= data->nsp; k++) {
if (data->gas->speciesName(k - 1) == data->dropSpec[i]) {
index = k;
}
}
// size_t index = specIndex(data, data->dropSpec[i].c_str());
data->k_drop.push_back(index);
}
// double massSum = 0.0;
// for(int i=0;i<=1;i++){
// massSum = massSum + data->dropMole[i] * MW[i];
@@ -492,15 +510,16 @@ UserData allocateUserData(FILE *input){

/* Update the gamma using UNIFAC method for propane and n-heptane */
/*Note: gamma only need to be calculated when droplet type = 1, i.e. bi-component*/
getGamma(data->dropMole,data->gamma);
// getGamma(data->dropMole,data->gamma);

// printf("Gamma of Propane and n-heptane are %.3f and %.3f .\n",data->gamma[0],data->gamma[1]) ;
if(data->dropType == 0){
printf("Single component droplet problem, activity coeffcient is 1. \n");
}else{
for(auto & arg : data->gamma) {
printf("Initial activity coeffcient %.3f .\n",arg);
}
}
// if(data->dropType == 0){
// printf("Single component droplet problem, activity coeffcient is 1. \n");
// }else{
// for(auto & arg : data->gamma) {
// printf("Initial activity coeffcient %.3f .\n",arg);
// }
// }

if(!data->adaptiveGrid){
data->uniformGrid = new double [data->npts];
@@ -561,6 +580,7 @@ void setSaneDefaults(UserData data){
data->wallTemperature=298.0e0;
data->dirichletInner=0;
data->dirichletOuter=0;
data->rxns=0;
data->adaptiveGrid=0;
data->moveGrid=0;
data->gridOffset=0.0e0;
@@ -632,43 +652,43 @@ void getGamma(const double mole[],double gamma[]){
}


void getGamma(const std::vector<double>& mole,std::vector<double>& gamma){
size_t sz = mole.size();
if (sz == 1){
gamma.push_back(1);
}else{
gamma.reserve(mole.size());
/* define relevant matrix */
Eigen::Matrix2d nu_ ;
nu_ << 2,1,2,5;
/* define relevant vectors */
Eigen::Vector2d R_(0.9011,0.6744),Q_(0.8480,0.5400);
Eigen::Vector2d r_,q_,x_,l_,ones_(1.0,1.0),v_,ksi_,gammaC_;
double sum_q, sum_r,sum_l;
r_ = nu_ * R_ ;
q_ = nu_ * Q_ ;
x_ << mole[0], mole[1] ;
sum_q = x_.dot(q_) ;
sum_r = x_.dot(r_) ;
for(size_t i=0; i<v_.size() ; i++){
v_[i] = q_[i] * x_[i] / sum_q;
ksi_[i] = r_[i] * x_[i] / sum_r ;
}
l_ = 5 * (r_ - q_) - (r_ - ones_) ;
sum_l = l_.dot(x_) ;
/* calculate the gamma_c */
for(size_t i=0; i<v_.size() ; i++){
gammaC_[i] =std::exp( std::log(ksi_[i]/x_[i]) + 5*q_[i]*std::log(v_[i]/ksi_[i]) + l_[i] - ksi_[i]/x_[i]*sum_l );
}
/******* gamma_R for both propane and n-heptane are 0 **********/
/* return the gamma */
for(size_t i=0; i<v_.size(); i++){
gamma.push_back(gammaC_[i]);
}
}
}
//void getGamma(const double *mole, std::vector<double>& gamma){
// size_t sz = mole.size();
// if (sz == 1){
// gamma.push_back(1);
// }else{
// gamma.reserve(mole.size());
// /* define relevant matrix */
// Eigen::Matrix2d nu_ ;
// nu_ << 2,1,2,5;
// /* define relevant vectors */
// Eigen::Vector2d R_(0.9011,0.6744),Q_(0.8480,0.5400);
// Eigen::Vector2d r_,q_,x_,l_,ones_(1.0,1.0),v_,ksi_,gammaC_;
// double sum_q, sum_r,sum_l;
//
// r_ = nu_ * R_ ;
// q_ = nu_ * Q_ ;
// x_ << mole[0], mole[1] ;
//
// sum_q = x_.dot(q_) ;
// sum_r = x_.dot(r_) ;
//
// for(size_t i=0; i<v_.size() ; i++){
// v_[i] = q_[i] * x_[i] / sum_q;
// ksi_[i] = r_[i] * x_[i] / sum_r ;
// }
//
// l_ = 5 * (r_ - q_) - (r_ - ones_) ;
// sum_l = l_.dot(x_) ;
// /* calculate the gamma_c */
// for(size_t i=0; i<v_.size() ; i++){
// gammaC_[i] =std::exp( std::log(ksi_[i]/x_[i]) + 5*q_[i]*std::log(v_[i]/ksi_[i]) + l_[i] - ksi_[i]/x_[i]*sum_l );
// }
// /******* gamma_R for both propane and n-heptane are 0 **********/
// /* return the gamma */
// for(size_t i=0; i<v_.size(); i++){
// gamma.push_back(gammaC_[i]);
// }
// }
//
//}

+ 2
- 3
src/main.cpp Wyświetl plik

@@ -171,7 +171,7 @@ int main(){
printf("Cross your fingers...\n");

// ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-5*finalTime);
ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-7*finalTime);
ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-5*finalTime);

//If at first IDACalcIC doesn't succeed, try, try, try again:
for (int i = 0; i < 10; i++) {
@@ -203,7 +203,6 @@ int main(){

// getTimescale(data,&y) ;
// printTimescaleOutput(tNow, &y, data->timescaleOutput,data);

if(!data->dryRun){
count=0;
@@ -225,7 +224,7 @@ int main(){
//xOld=isothermPosition(ydata, data->isotherm, data->nt,
// data->nvar, data->grid->x, data->npts);
}
while (tNow<=finalTime && R(data->l_npts)>100e-9) {
while (tNow<=finalTime && R(data->l_npts)>100e-9 ) {
t1=tNow;
/*Floor small value to zero*/


+ 202
- 258
src/residue.cpp Wyświetl plik

@@ -556,19 +556,9 @@ int setAlgebraicVariables(N_Vector *id, UserData data, const double *ydata) {
// data->k_drop[0]=specIndex(data,specPtr[0]);
// data->k_drop[1]=specIndex(data,specPtr[1]);

for (size_t i = 0; i < data->dropMole.size(); i++) {
size_t index = 0;
for (size_t k = 1; k <= data->nsp; k++) {
if (data->gas->speciesName(k - 1) == data->dropSpec[i]) {
index = k;
}
}
// size_t index = specIndex(data, data->dropSpec[i].c_str());
data->k_drop.push_back(index);
}

printf("Oxidizer index: %lu\n", data->k_oxidizer);
printf("Bath gas index:%lu\n", data->k_bath);
printf("Bath gas index: %lu\n", data->k_bath);
printf("Droplet species index: ");

for(auto & arg : data->k_drop){
@@ -1031,9 +1021,10 @@ int initializePsiEtaGrid(double *ydata, double *psidata, UserData data) {
}
} else if (data->dropType == 1) {
for (size_t i = data->l_npts - 1; i >= 1; i--) {
std::vector<double> moleFrac, moleFracp;
moleFrac = getLiquidmolevec(data, ydata, i);
moleFracp = getLiquidmolevec(data, ydata, i + 1);
// std::vector<double> moleFrac, moleFracp;
double moleFrac[2] ={},moleFracp[2]={};
getLiquidMoleVec(data, ydata, i,moleFrac);
getLiquidMoleVec(data, ydata, i + 1,moleFracp);
rho = getLiquidDensity(T(i), P(i), composition, moleFrac);
rhop = getLiquidDensity(T(i + 1), P(i + 1), composition, moleFracp);
psi(i) = psi(i + 1) + (R(i + 1) - R(i)) *
@@ -1721,7 +1712,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
std::vector<size_t> k_drop = data->k_drop;
std::vector<std::string> dropSpec = data->dropSpec;
std::vector<std::string> composition = components(data->dropType);
std::vector<double> dropMole = data->dropMole;
std::vector<double> dropMole = data->dropMole; //only for size determination

ydata = N_VGetArrayPointer_OpenMP(y);
ydotdata = N_VGetArrayPointer_OpenMP(ydot);
@@ -1783,7 +1774,11 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
double mass, massDrop;
double sum, sum1, sum2, sum3;

std::vector<double> vapheat, mole_,liquidCp,vapPres;
// std::vector<double> vapheat, mole_,liquidCp,vapPres;
double vapheat[2]={};
double mole_[2]={} ;
double liquidCp[2]={};
double vapPres[2]={};

// size_t j, k;
int m;
@@ -1799,7 +1794,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
for (size_t k = 1; k <= nsp; k++) {
Yres(1, k) = Ydot(1, k);
}
} else {
} else if (dropType == 1) {
for (size_t k = 1; k <= nsp; k++) {
if (k == k_drop[0]) {
Yres(1, k) = Y(2, k) - Y(1, k);
@@ -1814,30 +1809,32 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
Mdotres(1) = Mdot(2) - Mdot(1);
Tres(1) = T(2) - T(1);

/*set governing equations at intermediate grid points */
massDrop = dropletmass(data, ydata);
/*set governing equations at internal grid points */
massDrop = dropletmass(data, ydata,composition);
if (dropType == 0) {
//#pragma omp parallel
/*Calculate values at j=2's m and mhalf****************/
aream = calc_area(R(1), &m);
rhom = getLiquidDensity(T(1), P(1), composition);
areamhalf = calc_area(HALF * (R(1) + R(2)), &m);
areamhalfsq = areamhalf * areamhalf;
setLiquidTransport(data, ydata, 1, composition, &rhomhalf, &lambdamhalf, &propYVmhalf);

/*loop over internal liquid phase grid points *********/
for (size_t j = 2; j <= l_npts - 1; j++) {
/*Mass:*/
/* ∂r/∂ψ = 1/ρA */
dpsim = - (psi(j) - psi(j - 1));
dpsip = - (psi(j + 1) - psi(j));
dpsiav = - (HALF * (psi(j + 1) - psi(j - 1)));
rho = getLiquidDensity(T(j), P(j), composition);
rhom = getLiquidDensity(T(j - 1), P(j - 1), composition);
rhophalf = getLiquidDensity(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition);
rhomhalf = getLiquidDensity(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition);
dpsim = -(psi(j) - psi(j - 1));
dpsip = -(psi(j + 1) - psi(j));
dpsiav = -(HALF * (psi(j + 1) - psi(j - 1)));

area = calc_area(R(j), &m);
Cpb = getLiquidCpb(T(j), P(j), composition);
lambdaphalf = getLiquidCond(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition);
lambdamhalf = getLiquidCond(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition);
rho = getLiquidDensity(T(j), P(j), composition);

aream = calc_area(R(j - 1), &m);
areamhalf = calc_area(HALF * (R(j) + R(j - 1)), &m);
areaphalf = calc_area(HALF * (R(j + 1) + R(j)), &m);
areamhalfsq = areamhalf * areamhalf;
areaphalfsq = areaphalf * areaphalf;
area = calc_area(R(j), &m);
setLiquidTransport(data,ydata,j,composition,&rhophalf,&lambdaphalf,&propYVphalf) ;

Rres(j) = ((R(j) - R(j - 1)) / dpsim) - massDrop * (TWO / (rhom * aream + rho * area));
Mdotres(j) = Mdot(j + 1) - Mdot(j);
@@ -1847,11 +1844,20 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
}

tranTerm = Tdot(j);
advTerm = psi(j) * (-Mdot(j)) / massDrop * (T(j) - T(j - 1)) / dpsim ;
advTerm = psi(j) * (-Mdot(j)) / massDrop * (T(j) - T(j - 1)) / dpsim;
diffTerm = 1 / (Cpb * massDrop * massDrop) *
(rhophalf * areaphalfsq * lambdaphalf * (T(j + 1) - T(j)) / dpsip -
rhomhalf * areamhalfsq * lambdamhalf * (T(j) - T(j - 1)) / dpsim) / dpsiav;
Tres(j) = tranTerm - advTerm - diffTerm;

/*Assign values evaluated at p and phalf to
* m and mhalf to save some cpu cost:********/
areamhalf = areaphalf ;
areamhalfsq = areaphalfsq ;
aream = area;
rhom = rho ;
rhomhalf = rhophalf;
lambdamhalf = lambdaphalf ;
}

/*Fill up the res at l_npts*/
@@ -1859,7 +1865,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
area = calc_area(R(l_npts), &m);
lambdamhalf = getLiquidCond(T(l_npts), P(l_npts), composition);
lambdaphalf = getGasCond(data, ydata, l_npts+1);
vapheat = getLiquidVH(P(l_npts+1), data->dropType);
getLiquidVH(P(l_npts+1), data->dropType,vapheat);

Rres(l_npts) = Mdot(l_npts) + rho * Rdot(l_npts) * area;
Mdotres(l_npts) = Mdot(l_npts + 1) - Mdot(l_npts);
@@ -1870,11 +1876,20 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
Tres(l_npts) = lambdamhalf * (T(l_npts) - T(l_npts - 1)) / (R(l_npts) - R(l_npts - 1)) * area +
Mdot(l_npts) * vapheat[0] -
lambdaphalf * (T(l_npts + 2) - T(l_npts + 1)) / (R(l_npts + 2) - R(l_npts + 1)) * area;
} else {
} else if (dropType == 1) {
/*binary component case*/

/*Calculate values at j=2's m and mhalf****************/
aream = calc_area(R(1), &m);
rhom = getLiquidDensity(T(1), P(1), composition);
areamhalf = calc_area(HALF * (R(1) + R(2)), &m);
areamhalfsq = areamhalf * areamhalf;
setLiquidTransport(data, ydata, 1, composition, &rhomhalf, &lambdamhalf, &propYVmhalf);
//#pragma omp parallel
/*implementation of liquid phase inner grid points*/
for (size_t j = 2; j <= l_npts - 1; j++) {
mole_ = getLiquidmolevec(data, ydata, j);

getLiquidMoleVec(data, ydata, j,mole_); //get mole fraction vector array

dpsim = - (psi(j) - psi(j - 1));
dpsip = - (psi(j + 1) - psi(j));
@@ -1886,36 +1901,20 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
cendfp = dpsim / (dpsip * dpsipm);
/**************************************************/

area = calc_area(R(j), &m);
rho = getLiquidDensity(T(j), P(j), composition, mole_);
rhom = getLiquidDensity(T(j - 1), P(j - 1), composition, mole_);
rhophalf = getLiquidDensity(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition, mole_);
rhomhalf = getLiquidDensity(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition, mole_);

Cpb = getLiquidCpb(T(j), P(j), composition, mole_);
liquidCp = getLiquidCp(T(j),P(j),composition);

lambdaphalf = getLiquidCond(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition, mole_);
lambdamhalf = getLiquidCond(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition, mole_);
getLiquidCp(T(j),P(j),composition,liquidCp);

aream = calc_area(R(j - 1), &m);
areamhalf = calc_area(HALF * (R(j) + R(j - 1)), &m);
setLiquidTransport(data, ydata, j, composition, &rhophalf, &lambdaphalf, &propYVphalf);
areaphalf = calc_area(HALF * (R(j + 1) + R(j)), &m);
areamhalfsq = areamhalf * areamhalf;
areaphalfsq = areaphalf * areaphalf;
area = calc_area(R(j), &m);

Diffcoeffphalf = getLiquidmassdiff(data, ydata, j, HALF * (T(j) + T(j + 1)));
Diffcoeffmhalf = getLiquidmassdiff(data, ydata, j, HALF * (T(j) + T(j - 1)));

Rres(j) = ((R(j) - R(j - 1)) / dpsim) - massDrop * (TWO / (rhom * aream + rho * area));
Mdotres(j) = Mdot(j + 1) - Mdot(j);
Pres(j) = P(j + 1) - P(j);

propYVphalf = (-Diffcoeffphalf * (Y(j + 1, k_drop[0]) - Y(j, k_drop[0])) / (R(j + 1) - R(j)));
propYVmhalf = (-Diffcoeffmhalf * (Y(j, k_drop[0]) - Y(j - 1, k_drop[0])) / (R(j) - R(j - 1)));

liquidCp = getLiquidCp(T(j),P(j),composition);
/*species equation*/
/*species equation***********/
for (size_t k = 1; k <= nsp; k++) {
if (k != k_drop[0] && k != k_drop[1]) {
Yres(j, k) = Y(j, k) - Y(j - 1, k);
@@ -1927,23 +1926,37 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
- areamhalf * rhomhalf * propYVmhalf )
/ dpsiav;
Yres(j, k) = tranTerm - advTerm + diffTerm;
} else{
} else if(k == k_drop[1]){
Yres(j,k) = ONE - Y(j,k_drop[0]);
}
}
/*energy equation*/
tranTerm = Tdot(j);
advTerm = 1/massDrop *(psi(j)*(-Mdot(j)))* (T(j)-T(j-1))/(psi(j)-psi(j-1));
double diffTerm1 = 1/(Cpb*massDrop*massDrop) * ( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/(psi(j+1)-psi(j)) )
- (rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/(psi(j)-psi(j-1)) ) ) /dpsiav;
double diffTerm2 = area/(Cpb*massDrop)*rho*(cendfp*T(j+1)+cendfc*T(j)+cendfm*T(j-1)) *
(HALF*((propYVphalf+propYVmhalf)*liquidCp[0]+(-propYVphalf-propYVmhalf)*liquidCp[1])) ;
diffTerm = diffTerm1 - diffTerm2 ;
Tres(j) = tranTerm - advTerm - diffTerm ;

/*energy equation***********/
tranTerm = Tdot(j);
advTerm = 1 / massDrop * (psi(j) * (-Mdot(j))) * (T(j) - T(j - 1)) / dpsim;
double diffTerm1 = 1 / (Cpb * massDrop * massDrop) *
((rhophalf * areaphalfsq * lambdaphalf * (T(j + 1) - T(j)) / dpsip)
- (rhomhalf * areamhalfsq * lambdamhalf * (T(j) - T(j - 1)) / dpsim )) /
dpsiav;
double diffTerm2 = area / (Cpb * massDrop) * rho * (cendfp * T(j + 1) + cendfc * T(j) + cendfm * T(j - 1)) *
(HALF * ((propYVphalf + propYVmhalf) * liquidCp[0] +
(-propYVphalf - propYVmhalf) * liquidCp[1]));
diffTerm = diffTerm1 - diffTerm2;
Tres(j) = tranTerm - advTerm - diffTerm;

/*Assign values evaluated at p and phalf to
* m and mhalf to save some cpu cost:********/
areamhalf = areaphalf ;
areamhalfsq = areaphalfsq ;
aream = area;
rhom = rho ;
rhomhalf = rhophalf;
lambdamhalf = lambdaphalf ;
propYVmhalf = propYVphalf ;
}

/*implementation of right boundary of liquid phase*/
mole_ = getLiquidmolevec(data,ydata,l_npts);
getLiquidMoleVec(data,ydata,l_npts,mole_);
rho = getLiquidDensity(T(l_npts), P(l_npts), composition,mole_);
area = calc_area(R(l_npts), &m);
lambdamhalf = getLiquidCond(T(l_npts), P(l_npts), composition,mole_);
@@ -1953,7 +1966,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
getGasMassFlux(data,ydata,l_npts+1,YVphalf);

Diffcoeffmhalf = getLiquidmassdiff(data, ydata, l_npts, HALF * (T(l_npts) + T(l_npts - 1)));
vapheat = getLiquidVH(P(l_npts), data->dropType);
getLiquidVH(P(l_npts), data->dropType,vapheat);

Rres(l_npts) = Mdot(l_npts) + rho * Rdot(l_npts) * area;
Mdotres(l_npts) = Mdot(l_npts + 1) - Mdot(l_npts);
@@ -1973,7 +1986,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
}
}

/*temperature formulation*/
/*enthalpy formulation*/
double epsilon = Y(l_npts + 1, k_drop[0]) + YVphalf[k_drop[0] - 1] * area / Mdot(l_npts);
Tres(l_npts) = lambdamhalf * (T(l_npts) - T(l_npts - 1)) / (R(l_npts) - R(l_npts - 1)) * area
+ Mdot(l_npts) * (epsilon * vapheat[0] + (1 - epsilon) * vapheat[1])
@@ -2045,11 +2058,6 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)

/*******************************************************************/
/*Calculate values at j=l_npts+2 's m and mhalf*****************************/
// getTransport(data, ydata, 1, &rhomhalf, &lambdamhalf, YVmhalf);
// areamhalf = calc_area(HALF * (R(1) + R(2)), &m);
// aream = calc_area(R(1), &m);
// areamhalfsq = areamhalf * areamhalf;

getTransport(data, ydata, l_npts+1, &rhomhalf, &lambdamhalf, YVmhalf);
areamhalf = calc_area(HALF * (R(l_npts+1) + R(l_npts+2)), &m);
aream = calc_area(R(l_npts+1), &m);
@@ -2108,10 +2116,10 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
Yres(l_npts + 1, k_bath) = ONE - sum - Y(l_npts + 1, k_bath);
}

/*binary componet case for gas phase LHS boundary*/
/*binary componet case for gas phase L.H.S. boundary*/
if(dropType == 1){
mole_ = getLiquidmolevec(data,ydata,l_npts);
vapPres = getVapPressure(data,ydata,l_npts+1,mole_);
getLiquidMoleVec(data,ydata,l_npts,mole_) ;
getVapPressure(data,ydata,l_npts+1,mole_,vapPres);

for (size_t i = 0; i < k_drop.size(); i++) {
Yres(l_npts+1, k_drop[i]) = Y(l_npts+1, k_drop[i]) - vapPres[i] * data->gas->molecularWeight(k_drop[i] - 1) /
@@ -2194,6 +2202,7 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
/*Pressure:*/
Pres(l_npts+1) = P(l_npts+2) - P(l_npts+1);
/*Fill up res with governing equations at inner points:*************/
//#pragma omp parallel
for (size_t j = l_npts+2 ; j < npts; j++) {

/*evaluate various mesh differences*///
@@ -2260,9 +2269,20 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data)
tranTerm = Tdot(j);
sum = ZERO;
sum1 = ZERO;
for (size_t k = 1; k <= nsp; k++) {
sum = sum + wdot(k) * enthalpy(k);
sum1 = sum1 + (Cp(k) / data->gas->molecularWeight(k - 1)) * HALF * (YVmhalf(k) + YVphalf(k));
// for (size_t k = 1; k <= nsp; k++) {
// sum = sum + wdot(k) * enthalpy(k);
// sum1 = sum1 + (Cp(k) / data->gas->molecularWeight(k - 1)) * HALF * (YVmhalf(k) + YVphalf(k));
// }
if (data->rxns == 0) {
for (size_t k = 1; k <= nsp; k++) {
// sum = sum;
sum1 = sum1 + (Cp(k) / data->gas->molecularWeight(k - 1)) * HALF * (YVmhalf(k) + YVphalf(k));
}
} else if (data->rxns == 1) {
for (size_t k = 1; k <= nsp; k++) {
sum = sum + wdot(k) * enthalpy(k);
sum1 = sum1 + (Cp(k) / data->gas->molecularWeight(k - 1)) * HALF * (YVmhalf(k) + YVphalf(k));
}
}
sum = sum * Cantera::GasConstant * T(j);
sum1 = sum1 * Cantera::GasConstant;
@@ -2913,82 +2933,6 @@ void getSpecies(UserData data, N_Vector *y, FILE *output) {
delete[] spArr;
}

//
////rho : density of liquid phase
//double getLiquidRho(double dropMole[],double temp,double pres){
// std::vector<std::string> fluids;
// fluids.push_back("Propane");
// fluids.push_back("n-Heptane");
//
// std::vector<double> Temperature(1,temp),Pressure(1,pres);
// std::vector<std::string> outputs;
// outputs.push_back("D");
//
// std::vector<double> moles;
// moles.push_back(dropMole[0]);
// moles.push_back(dropMole[1]);
// double density = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:kg/m^3
//
// return density;
//}

////Cp,l : specific heat capacity at constant pressure of liquid phase
//double getLiquidCp(double dropMole[],double temp,double pres){
// std::vector<std::string> fluids;
// fluids.push_back("Propane");
// fluids.push_back("n-Heptane");
//
// std::vector<double> Temperature(1,temp),Pressure(1,pres);
// std::vector<std::string> outputs;
// outputs.push_back("CPMASS");
//
// std::vector<double> moles;
// moles.push_back(dropMole[0]);
// moles.push_back(dropMole[1]);
// double cp = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:J/(kg*K)
//
// return cp;
//}

////Hv : heat of vaporization of liquid phase at constant pressure
//double getLiquidHv(double dropMole[],double temp,double pres){
// std::vector<std::string> fluids;
// fluids.push_back("Propane");
// fluids.push_back("n-Heptane");
//
// std::vector<double> Temperature(1,temp),Pressure(1,pres);
// std::vector<std::string> outputs;
// outputs.push_back("H");
//
// std::vector<double> moles;
// moles.push_back(dropMole[0]);
// moles.push_back(dropMole[1]);
//
// std::vector<double> state1(1,1.0);
// std::vector<double> state2(1,0.0);
//
// double H_V = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state1,"",fluids,moles)[0][0]; //Unit:J/kg
// double H_L = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state2,"",fluids,moles)[0][0]; //Unit:J/kg
// double delta_H = H_V - H_L;
//
// return delta_H;
//}

////MaxT : maximum allowed tempereture of liquid phase
////Also the boiling point of more volitile component
//double getLiquidMaxT(double dropMole[],double pres){
// std::vector<std::string> fluids;
// fluids.push_back("Propane");
// //fluids.push_back("n-Heptane");
//
// std::vector<double> Pressure(1,pres);
// std::vector<std::string> outputs;
// outputs.push_back("T");
//
// double temperature = CoolProp::PropsSI(outputs[0], "P", Pressure[0],"Q",1.0,fluids[0]);
//
// return temperature;
//}

/*function overloading for single and bi-component*/
/*calculate the liquid phase density based on droplet type and T,P,X(Y)*/
@@ -3001,10 +2945,12 @@ double getLiquidDensity(const double temp, const double pres, const std::vector<
}

/*binary component case*/
double getLiquidDensity(const double temp, const double pres, std::vector<std::string> &composition,
const std::vector<double> &mole) {
double getLiquidDensity(const double temp, const double pres,
const std::vector<std::string> &composition,
const double mole_[]) {
std::vector<double> Temperature(1, temp), Pressure(1, pres);
std::vector<std::string> outputs;
std::vector<double> mole ={mole_[0],mole_[1]};
outputs.push_back("D");

double density = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition,
@@ -3012,21 +2958,23 @@ double getLiquidDensity(const double temp, const double pres, std::vector<std::s
return density;
}

double getLiquidCond(const double temp, const double pres, const std::vector<std::string> &composition) {
double getLiquidCond(const double temp, const double pres,
const std::vector<std::string> &composition) {
std::vector<double> Temperature(1, temp), Pressure(1, pres);
double k = CoolProp::PropsSI("conductivity", "T", Temperature[0], "P", Pressure[0], composition[0]);
return k; //Unit:W/m/K (kg*m/s^3/K)
}

/*binary component case*/
double getLiquidCond(const double temp, const double pres, std::vector<std::string> &composition,
const std::vector<double> &mole) {
double getLiquidCond(const double temp, const double pres,
std::vector<std::string> &composition,const double mole_[]) {
std::vector<double> Temperature(1, temp), Pressure(1, pres);
std::vector<std::string> outputs;
std::vector<double> mole = {mole_[0],mole_[1]};
outputs.push_back("conductivity");

double k = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition,
mole)[0][0];
double k = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure,
"", composition,mole)[0][0];
return k; //Unit:W/m/K (kg*m/s^3/K)
}

@@ -3039,9 +2987,10 @@ double getLiquidCpb(const double temp,const double pres, const std::vector<std::

/*binary component case*/
double getLiquidCpb(const double temp, const double pres, const std::vector<std::string> &composition,
const std::vector<double> &mole) {
const double mole_[]) {
std::vector<double> Temperature(1, temp), Pressure(1, pres);
std::vector<std::string> outputs;
std::vector<double> mole = {mole_[0],mole_[1]};
outputs.push_back("Cpmass");

double k = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition,
@@ -3050,15 +2999,19 @@ double getLiquidCpb(const double temp, const double pres, const std::vector<std:
}

/*get Cp vector for binary componet droplet*/
std::vector<double> getLiquidCp(const double temp, const double pres, const std::vector<std::string> &composition){
std::vector<double> k ;
void getLiquidCp(const double temp, const double pres, const std::vector<std::string> &composition, double liquidCp[]){
// std::vector<double> k ;
double k_temp;
std::vector<double> Temperature(1, temp), Pressure(1, pres);
for(auto & species : composition){
k_temp = CoolProp::PropsSI("Cpmass", "T", Temperature[0], "P", Pressure[0], species);
k.push_back(k_temp) ;
// for(auto & species : composition){
// k_temp = CoolProp::PropsSI("Cpmass", "T", Temperature[0], "P", Pressure[0], species);
// liquidCp[] ;
// }
for(size_t i= 0;i < composition.size();i++){
k_temp = CoolProp::PropsSI("Cpmass", "T", Temperature[0], "P", Pressure[0], composition[i]);
liquidCp[i] = k_temp ;
}
return k;
// return k;
}


@@ -3072,9 +3025,9 @@ double getGasCond(UserData data, double *ydata, size_t gridPoint) {

/*latent heat of vaporizaiton*/
/*unit: J/kg*/
std::vector<double> getLiquidVH(const double pres, const int dropType) {
void getLiquidVH(const double pres, const int dropType, double vapheat[2]) {
double H, H_V, H_L;
std::vector<double> vapheat;
// double vapheat[2]={};
std::vector<std::string> fluids;
std::vector<double> Pressure(1, pres);

@@ -3085,37 +3038,24 @@ std::vector<double> getLiquidVH(const double pres, const int dropType) {
H_V = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 1, fluids[0]);
H_L = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 0, fluids[0]);
H = H_V - H_L;
vapheat.push_back(H);
vapheat[0] = H;
} else {
for (size_t i = 0; i < fluids.size(); i++) {
H_V = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 1, fluids[i]);
H_L = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 0, fluids[i]);
H = H_V - H_L;
vapheat.push_back(H);
vapheat[i]=H;
}
}
return vapheat; //unit:J/kg
// return vapheat; //unit:J/kg
}

/*convert mass fraction to mole fraction*/
/*size of both arrays should be identical*/
void mass2mole(const std::vector<double> &mass, std::vector<double> &mole, UserData data) {
mole.reserve(mass.size());
double sum = 0.0;
double x_temp;
for (size_t i = 0; i < data->dropMole.size(); i++) {
sum = sum + mass[i] / data->MW[i];
}

x_temp = mass[0] / (data->MW[0] * sum);
mole.push_back(x_temp);
mole.push_back(ONE - x_temp);
}

/*liquid mass diffusivity D for binary component case*/
double getLiquidmassdiff(UserData data, double *ydata, size_t gridPoint, const double temp) {
std::vector<double> V_ = {75.86, 162.34}; //molar volume at normal boiling point, unit: cm^3/mol
std::vector<double> visc_, mole_, mass_, D_inf_;
std::vector<double> visc_, mass_, D_inf_;
double mole_[2] ={} ;
double visc_temp, D, Dinf_temp;
std::vector<std::string> composition = components(data->dropType);

@@ -3123,13 +3063,13 @@ double getLiquidmassdiff(UserData data, double *ydata, size_t gridPoint, const d
visc_temp = 1000.0 * CoolProp::PropsSI("V", "T", temp, "Q", 0, composition[i]); //unit: mPa*s
visc_.push_back(visc_temp);
}
mole_ = getLiquidmolevec(data, ydata, gridPoint);
getLiquidMoleVec(data, ydata, gridPoint,mole_);

for (size_t i = 0; i < data->dropMole.size(); i++) {
if (i == 0) {
Dinf_temp = 9.89e-8 * temp * pow(visc_[1], -0.907) * pow(V_[0], -0.45) * pow(V_[1], 0.265);
D_inf_.push_back(Dinf_temp);
} else {
} else if (i == 1){
Dinf_temp = 9.89e-8 * temp * pow(visc_[0], -0.907) * pow(V_[1], -0.45) * pow(V_[0], 0.265);
D_inf_.push_back(Dinf_temp);
}
@@ -3139,40 +3079,6 @@ double getLiquidmassdiff(UserData data, double *ydata, size_t gridPoint, const d
return (D / 10000); //unit:m^2/s
}

//double dropletmass(UserData data,double* ydata){
// double mass = 0.0 ;
// double rho,rhop;
// if (data->dropType==0){
// for (size_t i = data->l_npts-1; i>=1 ; i--) {
// std::vector<std::string> str;
// str.push_back("nHeptane");
// rho = getLiquidDensity(T(i), P(i), str);
// rhop = getLiquidDensity(T(i + 1), P(i + 1), str);
// mass = mass + (R(i + 1) - R(i)) * (rho * calc_area(R(i), &data->metric) +
// rhop * calc_area(R(i + 1), &data->metric)) / TWO;
// }
// }else if(data->dropType==1){
// for (size_t i = data->l_npts-1; i>=1 ; i--){
// std::vector<std::string> str;
// std::vector<double> massFrac,massFracp,moleFrac,moleFracp;
// str.push_back("propane");
// str.push_back("nHeptane");
// for (size_t j = 0; j < data->dropMole.size(); j++){
// massFrac.push_back(Y(i,data->k_drop[j]));
// massFracp.push_back(Y(i+1,data->k_drop[j]));
// }
// /*convert mass fraction to mole fraction*/
// mass2mole(massFrac,moleFrac,data);
// mass2mole(massFracp,moleFracp,data);
// rho = getLiquidDensity(T(i),P(i),str,moleFrac);
// rhop = getLiquidDensity(T(i+1),P(i+1),str,moleFracp);
// mass = mass +(R(i+1)-R(i))*(rho*calc_area(R(i),&data->metric)+rhop*calc_area(R(i+1),&data->metric))/TWO;
// }
// }
// return mass ;
//}


// List of fluid components per dropType
std::vector<std::string> components(int dropType) {
if (dropType == 0) {
@@ -3184,52 +3090,56 @@ std::vector<std::string> components(int dropType) {
}

/*calculat droplet mass*/
double dropletmass(UserData data, double *ydata) {
double dropletmass(UserData data, double *ydata, const std::vector<std::string>& composition) {
double mass = 0.0;
double rho, rhop;
double areap = calc_area(R(data->l_npts),&data->metric);
double moleFracp[2] = {};
double moleFrac[2] = {};

for (size_t i = data->l_npts - 1; i >= 1; i--) {
std::vector<std::string> composition = components(data->dropType);
if (data->dropType == 0){
rhop = getLiquidDensity(T(data->l_npts), P(data->l_npts), composition) ;
}else if(data->dropType == 1){
getLiquidMoleVec(data, ydata, data->l_npts,moleFracp);
rhop = getLiquidDensity(T(data->l_npts), P(data->l_npts), composition, moleFracp);
}

/*loop over the internal grid points*/
for (size_t i = data->l_npts - 1; i >= 1; i--) {
if (data->dropType == 0) {
rho = getLiquidDensity(T(i), P(i), composition);
rhop = getLiquidDensity(T(i + 1), P(i + 1), composition);

} else if (data->dropType == 1) {
std::vector<double> moleFrac, moleFracp;
moleFrac = getLiquidmolevec(data, ydata, i);
moleFracp = getLiquidmolevec(data, ydata, i);

getLiquidMoleVec(data, ydata, i,moleFrac);
rho = getLiquidDensity(T(i), P(i), composition, moleFrac);
rhop = getLiquidDensity(T(i + 1), P(i + 1), composition, moleFracp);
}

double area = calc_area(R(i), &data->metric);
double areap = calc_area(R(i + 1), &data->metric);
mass += (R(i + 1) - R(i)) * (rho * area + rhop * areap) / TWO;

/*save the cpu time */
areap = area;
rhop = rho;
}
return mass;
}

std::vector<double> getLiquidmassvec(UserData data, double *ydata, int gridPoint) {
std::vector<double> mass_;
mass_.push_back(Y(gridPoint, data->k_drop[0]));
mass_.push_back(Y(gridPoint, data->k_drop[1]));
return mass_;
}

std::vector<double> getLiquidmolevec(UserData data, double *ydata, int gridPoint) {
std::vector<double> mass_, mole_;
mass_ = getLiquidmassvec(data, ydata, gridPoint);
mass2mole(mass_, mole_, data);
return mole_;
void getLiquidMoleVec(UserData data,double* ydata,int gridPoint,double mole_[]){
double sum=ZERO;
double x_temp = ZERO;
double mass[2] = {};
for (size_t i = 0; i < data->dropMole.size(); i++) {
mass[i] = Y(gridPoint,data->k_drop[i]);
}
for (size_t i = 0; i < data->dropMole.size(); i++) {
sum = sum + mass[i] / data->MW[i];
}
x_temp = mass[0] / (data->MW[0] * sum);
mole_[0] = x_temp;
mole_[1] = (ONE - x_temp) ;
}

/*return droplet species vapor pressure at interface, unit:Pa*/
std::vector<double> getVapPressure(UserData data, double* ydata,int gridPoint,const std::vector<double> mole_){
std::vector<double> vapPres;
vapPres.reserve(mole_.size()) ;
std::vector<double> gamma_;
void getVapPressure(UserData data, double* ydata,int gridPoint,const double mole_[], double vapPres[]){
double gamma_[2] = {};
getGamma(mole_,gamma_) ;
//propane
double p1 = 1.0e5 * pow(10, 4.53678 - (1149.36 / (T(gridPoint) + 24.906))) * mole_[0] *
@@ -3237,9 +3147,43 @@ std::vector<double> getVapPressure(UserData data, double* ydata,int gridPoint,co
//heptane
double p2 = 1.0e5 * pow(10, 4.02832 - (1268.636 / (T(gridPoint) - 56.199))) * mole_[1] *
gamma_[1];
vapPres.push_back(p1);
vapPres.push_back(p2);
return vapPres;
vapPres[0] = p1 ;
vapPres[1] = p2 ;
}

void setLiquidTransport(UserData data,
double *ydata,
int gridPoint,
const std::vector<std::string> &composition,
double *rho,
double *lambda,
double *YV) {
double DiffCoeff;
double molevec[2], molevecp[2], molevecAvg[2];
molevec[2] = molevecp[2] = molevecAvg[2] = {};
double TAvg = HALF * (T(gridPoint) + T(gridPoint + 1));
std::vector<std::string> outputs;
outputs.push_back("conductivity");
std::vector<double> Temperature(1, TAvg), Pressure(1, P(gridPoint));

/*Calculate the density,heat conductivity and diffusion flux ******/
if (data->dropType == 0) {
*rho = getLiquidDensity(TAvg, P(gridPoint), composition);
*lambda = CoolProp::PropsSI("conductivity", "T", TAvg, "P", P(gridPoint), composition[0]);
*YV = ZERO;
} else if (data->dropType == 1) {
getLiquidMoleVec(data, ydata, gridPoint, molevec);
getLiquidMoleVec(data, ydata, gridPoint + 1, molevecp);
for (size_t ii = 0; ii < data->dropMole.size(); ii++) {
molevecAvg[ii] = HALF * (molevec[ii] + molevecp[ii]);
}
*rho = getLiquidDensity(TAvg, P(gridPoint), composition, molevecAvg);
std::vector<double> mole = {molevecAvg[0], molevecAvg[1]};
*lambda = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition, mole)[0][0];
DiffCoeff = getLiquidmassdiff(data, ydata, gridPoint, TAvg);
*YV = -DiffCoeff * (Y(gridPoint + 1, data->k_drop[0]) - Y(gridPoint, data->k_drop[0]))
/ (R(gridPoint + 1) - R(gridPoint));
}
}

void printIddata(UserData data, double *iddata) {
@@ -3270,7 +3214,7 @@ void printPsidata(UserData data, double* psidata) {
file = fopen("psi.dat", "w");
// fprintf(file, "%15s\t%15s\t", "Rid", "Tid");
for (size_t j = 1; j <= data->npts; j++) {
fprintf(file, "%lu\t", j);
fprintf(file, "%15.5e\t", (double)j);
}
fprintf(file, "\n");



Ładowanie…
Anuluj
Zapisz