merge membrane into test_poisson
This commit is contained in:
commit
86be316977
@ -5,22 +5,17 @@
|
||||
|
||||
Membrane::Membrane(std::shared_ptr <Domain> Dm, int *dvcNeighborList, int Nsites) {
|
||||
|
||||
Np = Nsites;
|
||||
initialNeighborList = new int[18*Np];
|
||||
ScaLBL_AllocateDeviceMemory((void **)&NeighborList, 18*Np*sizeof(int));
|
||||
Lock=false; // unlock the communicator
|
||||
//......................................................................................
|
||||
// Create a separate copy of the communicator for the device
|
||||
MPI_COMM_SCALBL = Dm->Comm.dup();
|
||||
Np = Nsites;
|
||||
if (Dm->rank() == 0){
|
||||
printf("**** Creating membrane data structure ****** \n");
|
||||
printf(" Number of active lattice sites (rank = %i): %i \n",Dm->rank(), Np);
|
||||
}
|
||||
|
||||
initialNeighborList = new int[18*Np];
|
||||
ScaLBL_AllocateDeviceMemory((void **)&NeighborList, 18*Np*sizeof(int));
|
||||
Lock=false; // unlock the communicator
|
||||
MPI_COMM_SCALBL = Dm->Comm.dup();
|
||||
|
||||
ScaLBL_CopyToHost(initialNeighborList, dvcNeighborList, 18*Np*sizeof(int));
|
||||
Dm->Comm.barrier();
|
||||
ScaLBL_CopyToDevice(NeighborList, initialNeighborList, 18*Np*sizeof(int));
|
||||
ScaLBL_CopyToHost(initialNeighborList, dvcNeighborList, 18*Np*sizeof(int));
|
||||
Dm->Comm.barrier();
|
||||
ScaLBL_CopyToDevice(NeighborList, initialNeighborList, 18*Np*sizeof(int));
|
||||
|
||||
/* Copy communication lists */
|
||||
//......................................................................................
|
||||
@ -91,6 +86,11 @@ Membrane::Membrane(std::shared_ptr <Domain> Dm, int *dvcNeighborList, int Nsites
|
||||
recvCount_YZ=Dm->recvCount("YZ");
|
||||
recvCount_XZ=Dm->recvCount("XZ");
|
||||
|
||||
if (rank == 0){
|
||||
printf("**** Creating membrane data structure ****** \n");
|
||||
printf(" Number of active lattice sites (rank = %i): %i \n",rank, Np);
|
||||
}
|
||||
|
||||
iproc = Dm->iproc();
|
||||
jproc = Dm->jproc();
|
||||
kproc = Dm->kproc();
|
||||
@ -99,7 +99,7 @@ Membrane::Membrane(std::shared_ptr <Domain> Dm, int *dvcNeighborList, int Nsites
|
||||
nprocz = Dm->nprocz();
|
||||
//BoundaryCondition = Dm->BoundaryCondition;
|
||||
//......................................................................................
|
||||
if (rank==0) printf(" Create Membrane: copying communication structures...\n");
|
||||
|
||||
ScaLBL_AllocateZeroCopy((void **) &sendbuf_x, 2*5*sendCount_x*sizeof(double)); // Allocate device memory
|
||||
ScaLBL_AllocateZeroCopy((void **) &sendbuf_X, 2*5*sendCount_X*sizeof(double)); // Allocate device memory
|
||||
ScaLBL_AllocateZeroCopy((void **) &sendbuf_y, 2*5*sendCount_y*sizeof(double)); // Allocate device memory
|
||||
@ -1323,7 +1323,7 @@ void Membrane::RecvD3Q7AA(double *dist){
|
||||
// Unpack the distributions on the device
|
||||
//...................................................................................
|
||||
//...Unpacking for x face(q=2)................................
|
||||
/* ScaLBL_D3Q7_Membrane_Unpack(2,dvcRecvDist_x, dvcRecvLinks_x,0,linkCount_x[0],recvCount_x,recvbuf_x,dist,Np,coefficient_x);
|
||||
ScaLBL_D3Q7_Membrane_Unpack(2,dvcRecvDist_x, dvcRecvLinks_x,0,linkCount_x[0],recvCount_x,recvbuf_x,dist,Np,coefficient_x);
|
||||
//...................................................................................
|
||||
//...Packing for X face(q=1)................................
|
||||
ScaLBL_D3Q7_Membrane_Unpack(1,dvcRecvDist_X, dvcRecvLinks_X,0,linkCount_X[0],recvCount_X,recvbuf_X,dist,Np,coefficient_X);
|
||||
@ -1339,7 +1339,7 @@ void Membrane::RecvD3Q7AA(double *dist){
|
||||
//...Packing for Z face(q=5)................................
|
||||
ScaLBL_D3Q7_Membrane_Unpack(5,dvcRecvDist_Z, dvcRecvLinks_Z,0,linkCount_Z[0],recvCount_Z,recvbuf_Z,dist,Np,coefficient_Z);
|
||||
//..................................................................................
|
||||
*/
|
||||
|
||||
//...................................................................................
|
||||
Lock=false; // unlock the communicator after communications complete
|
||||
//...................................................................................
|
||||
@ -1351,46 +1351,11 @@ void Membrane::IonTransport(double *dist, double *den){
|
||||
}
|
||||
|
||||
// std::shared_ptr<Database> db){
|
||||
void Membrane::AssignCoefficients(int *Map, double *Psi, string method){
|
||||
void Membrane::AssignCoefficients(int *Map, double *Psi, double Threshold,
|
||||
double MassFractionIn, double MassFractionOut, double ThresholdMassFractionIn,
|
||||
double ThresholdMassFractionOut){
|
||||
/* Assign mass transfer coefficients to the membrane data structure */
|
||||
|
||||
double Threshold;
|
||||
double MassFractionIn,MassFractionOut,ThresholdMassFractionIn,ThresholdMassFractionOut;
|
||||
|
||||
Threshold = -55.0;
|
||||
MassFractionIn = 0.0;
|
||||
MassFractionOut = 0.0;
|
||||
ThresholdMassFractionOut = 0.0;
|
||||
ThresholdMassFractionIn = 0.0;
|
||||
|
||||
if (method == "ones"){
|
||||
/* Initializing */
|
||||
//printf(".... initialize permeable membrane \n");
|
||||
MassFractionIn = 1.0;
|
||||
MassFractionOut = 1.0;
|
||||
ThresholdMassFractionOut = 1.0;
|
||||
ThresholdMassFractionIn = 1.0;
|
||||
}
|
||||
if (method == "Voltage Gated Potassium"){
|
||||
MassFractionIn = 0.0;
|
||||
MassFractionOut = 0.0;
|
||||
ThresholdMassFractionOut = 0.0;
|
||||
ThresholdMassFractionIn = 1.0;
|
||||
}
|
||||
if (method == "impermeable"){
|
||||
//printf(".... impermeable membrane \n");
|
||||
MassFractionIn = 0.001;
|
||||
MassFractionOut = 0.001;
|
||||
ThresholdMassFractionOut = 0.001;
|
||||
ThresholdMassFractionIn = 0.0001;
|
||||
}
|
||||
if (method == "Na+"){
|
||||
//printf(".... Na+ permeable membrane \n");
|
||||
MassFractionIn = 0.05;
|
||||
MassFractionOut = 0.05;
|
||||
ThresholdMassFractionOut = 0.05;
|
||||
ThresholdMassFractionIn = 0.05;
|
||||
}
|
||||
|
||||
ScaLBL_D3Q7_Membrane_AssignLinkCoef(MembraneLinks, Map, MembraneDistance, Psi, MembraneCoef,
|
||||
Threshold, MassFractionIn, MassFractionOut, ThresholdMassFractionIn, ThresholdMassFractionOut,
|
||||
|
@ -97,7 +97,9 @@ public:
|
||||
void RecvD3Q19AA(double *dist);
|
||||
void SendD3Q7AA(double *dist);
|
||||
void RecvD3Q7AA(double *dist);
|
||||
void AssignCoefficients(int *Map, double *Psi, std::string method);
|
||||
void AssignCoefficients(int *Map, double *Psi, double Threshold,
|
||||
double MassFractionIn, double MassFractionOut, double ThresholdMassFractionIn,
|
||||
double ThresholdMassFractionOut);
|
||||
void IonTransport(double *dist, double *den);
|
||||
//......................................................................................
|
||||
// Buffers to store data sent and recieved by this MPI process
|
||||
|
@ -482,7 +482,7 @@ extern "C" void ScaLBL_D3Q7_Ion_Init_FromFile(double *dist, double *Den,
|
||||
|
||||
extern "C" void ScaLBL_D3Q7_Ion_ChargeDensity(double *Den,
|
||||
double *ChargeDensity,
|
||||
int IonValence, int ion_component,
|
||||
double IonValence, int ion_component,
|
||||
int start, int finish, int Np) {
|
||||
|
||||
int n;
|
||||
|
@ -71,4 +71,10 @@ Visualization {
|
||||
}
|
||||
Membrane {
|
||||
MembraneLabels = 2
|
||||
VoltageThreshold = 0.0, 0.0
|
||||
MassFractionIn = 1e-2, 1e-8
|
||||
MassFractionOut = 1e-2, 1e-8
|
||||
ThresholdMassFractionIn = 1e-2, 1e-8
|
||||
ThresholdMassFractionOut = 1e-2, 1e-8
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ ScaLBL_IonModel::~ScaLBL_IonModel() {}
|
||||
|
||||
void ScaLBL_IonModel::ReadParams(string filename, vector<int> &num_iter) {
|
||||
|
||||
USE_MEMBRANE = true;
|
||||
// read the input database
|
||||
db = std::make_shared<Database>(filename);
|
||||
domain_db = db->getDatabase("Domain");
|
||||
@ -283,7 +282,7 @@ void ScaLBL_IonModel::ReadParams(string filename, vector<int> &num_iter) {
|
||||
void ScaLBL_IonModel::ReadParams(string filename) {
|
||||
//NOTE: the maximum iteration timesteps for ions are left unspecified
|
||||
// it relies on the multiphys controller to compute the max timestep
|
||||
|
||||
USE_MEMBRANE = true;
|
||||
// read the input database
|
||||
db = std::make_shared<Database>(filename);
|
||||
domain_db = db->getDatabase("Domain");
|
||||
@ -321,7 +320,9 @@ void ScaLBL_IonModel::ReadParams(string filename) {
|
||||
if (domain_db->keyExists("voxel_length")) { //default unit: um/lu
|
||||
h = domain_db->getScalar<double>("voxel_length");
|
||||
}
|
||||
|
||||
if (ion_db->keyExists("use_membrane")) {
|
||||
USE_MEMBRANE = ion_db->getScalar<bool>("use_membrane");
|
||||
}
|
||||
// LB-Ion Model parameters
|
||||
//if (ion_db->keyExists( "timestepMax" )){
|
||||
// timestepMax = ion_db->getScalar<int>( "timestepMax" );
|
||||
@ -423,23 +424,104 @@ void ScaLBL_IonModel::ReadParams(string filename) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ion_db->keyExists("MembraneIonConcentrationList")) {
|
||||
if (rank == 0) printf(".... Read MembraneIonConcentrationList \n");
|
||||
MembraneIonConcentration.clear();
|
||||
MembraneIonConcentration = ion_db->getVector<double>("MembraneIonConcentrationList");
|
||||
if (MembraneIonConcentration.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and MembraneIonConcentrationList must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < MembraneIonConcentration.size(); i++) {
|
||||
MembraneIonConcentration[i] =
|
||||
MembraneIonConcentration[i] *
|
||||
(h * h * h *
|
||||
1.0e-18); //LB ion concentration has unit [mol/lu^3]
|
||||
if (USE_MEMBRANE){
|
||||
membrane_db = db->getDatabase("Membrane");
|
||||
|
||||
/* get membrane permeability parameters*/
|
||||
if (membrane_db->keyExists("MassFractionIn")) {
|
||||
if (rank == 0) printf(".... Read membrane permeability (MassFractionIn) \n");
|
||||
MassFractionIn.clear();
|
||||
MassFractionIn = membrane_db->getVector<double>("MassFractionIn");
|
||||
if (MassFractionIn.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and membrane permeability (MassFractionIn) must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
MassFractionIn.resize(IonConcentration.size());
|
||||
for (size_t i = 0; i < IonConcentration.size(); i++) {
|
||||
MassFractionIn[i] = 0.0;
|
||||
}
|
||||
}
|
||||
if (membrane_db->keyExists("MassFractionOut")) {
|
||||
if (rank == 0) printf(".... Read membrane permeability (MassFractionOut) \n");
|
||||
MassFractionOut.clear();
|
||||
MassFractionOut = membrane_db->getVector<double>("MassFractionOut");
|
||||
if (MassFractionIn.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and membrane permeability (MassFractionOut) must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
MassFractionOut.resize(IonConcentration.size());
|
||||
for (size_t i = 0; i < IonConcentration.size(); i++) {
|
||||
MassFractionOut[i] = 0.0;
|
||||
}
|
||||
}
|
||||
if (membrane_db->keyExists("ThresholdMassFractionIn")) {
|
||||
if (rank == 0) printf(".... Read membrane permeability (ThresholdMassFractionIn) \n");
|
||||
ThresholdMassFractionIn.clear();
|
||||
ThresholdMassFractionIn = membrane_db->getVector<double>("ThresholdMassFractionIn");
|
||||
if (ThresholdMassFractionIn.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and membrane permeability (ThresholdMassFractionIn) must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
ThresholdMassFractionIn.resize(IonConcentration.size());
|
||||
for (size_t i = 0; i < IonConcentration.size(); i++) {
|
||||
ThresholdMassFractionIn[i] = 0.0;
|
||||
}
|
||||
}
|
||||
if (membrane_db->keyExists("ThresholdMassFractionOut")) {
|
||||
if (rank == 0) printf(".... Read membrane permeability (ThresholdMassFractionOut) \n");
|
||||
ThresholdMassFractionOut.clear();
|
||||
ThresholdMassFractionOut = membrane_db->getVector<double>("ThresholdMassFractionOut");
|
||||
if (ThresholdMassFractionOut.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and membrane permeability (ThresholdMassFractionOut) must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
ThresholdMassFractionOut.resize(IonConcentration.size());
|
||||
for (size_t i = 0; i < IonConcentration.size(); i++) {
|
||||
ThresholdMassFractionOut[i] = 0.0;
|
||||
}
|
||||
}
|
||||
if (membrane_db->keyExists("ThresholdVoltage")) {
|
||||
if (rank == 0) printf(".... Read membrane threshold (ThresholdVoltage) \n");
|
||||
ThresholdVoltage.clear();
|
||||
ThresholdVoltage = membrane_db->getVector<double>("ThresholdVoltage");
|
||||
if (ThresholdVoltage.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and membrane voltage threshold (ThresholdVoltage) must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
ThresholdVoltage.resize(IonConcentration.size());
|
||||
for (size_t i = 0; i < IonConcentration.size(); i++) {
|
||||
ThresholdVoltage[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ion_db->keyExists("MembraneIonConcentrationList")) {
|
||||
if (rank == 0) printf(".... Read MembraneIonConcentrationList \n");
|
||||
MembraneIonConcentration.clear();
|
||||
MembraneIonConcentration = ion_db->getVector<double>("MembraneIonConcentrationList");
|
||||
if (MembraneIonConcentration.size() != number_ion_species) {
|
||||
ERROR("Error: number_ion_species and MembraneIonConcentrationList must be "
|
||||
"the same length! \n");
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < MembraneIonConcentration.size(); i++) {
|
||||
MembraneIonConcentration[i] =
|
||||
MembraneIonConcentration[i] *
|
||||
(h * h * h *
|
||||
1.0e-18); //LB ion concentration has unit [mol/lu^3]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//Read solid boundary condition specific to Ion model
|
||||
BoundaryConditionSolid = 0;
|
||||
@ -1362,11 +1444,9 @@ void ScaLBL_IonModel::RunMembrane(double *Velocity, double *ElectricField, doubl
|
||||
|
||||
for (size_t ic = 0; ic < number_ion_species; ic++) {
|
||||
/* set the mass transfer coefficients for the membrane */
|
||||
if (ic == 0)
|
||||
IonMembrane->AssignCoefficients(dvcMap, Psi, "Na+");
|
||||
else {
|
||||
IonMembrane->AssignCoefficients(dvcMap, Psi, "impermeable");
|
||||
}
|
||||
IonMembrane->AssignCoefficients(dvcMap, Psi, ThresholdVoltage[ic],MassFractionIn[ic],
|
||||
MassFractionOut[ic],ThresholdMassFractionIn[ic],ThresholdMassFractionOut[ic]);
|
||||
|
||||
timestep = 0;
|
||||
while (timestep < timestepMax[ic]) {
|
||||
//************************************************************************/
|
||||
|
@ -69,10 +69,13 @@ public:
|
||||
vector<int> IonValence;
|
||||
vector<double> IonConcentration; //unit [mol/m^3]
|
||||
vector<double> MembraneIonConcentration; //unit [mol/m^3]
|
||||
vector<double>
|
||||
Cin; //inlet boundary value, can be either concentration [mol/m^3] or flux [mol/m^2/sec]
|
||||
vector<double>
|
||||
Cout; //outlet boundary value, can be either concentration [mol/m^3] or flux [mol/m^2/sec]
|
||||
vector<double> ThresholdVoltage;
|
||||
vector<double> MassFractionIn;
|
||||
vector<double> MassFractionOut;
|
||||
vector<double> ThresholdMassFractionIn;
|
||||
vector<double> ThresholdMassFractionOut;
|
||||
vector<double> Cin; //inlet boundary value, can be either concentration [mol/m^3] or flux [mol/m^2/sec]
|
||||
vector<double> Cout; //outlet boundary value, can be either concentration [mol/m^3] or flux [mol/m^2/sec]
|
||||
vector<double> tau;
|
||||
vector<double> time_conv;
|
||||
|
||||
@ -83,7 +86,7 @@ public:
|
||||
std::shared_ptr<Domain> Dm; // this domain is for analysis
|
||||
std::shared_ptr<Domain> Mask; // this domain is for lbm
|
||||
std::shared_ptr<ScaLBL_Communicator> ScaLBL_Comm;
|
||||
// input database
|
||||
// input databaseF
|
||||
std::shared_ptr<Database> db;
|
||||
std::shared_ptr<Database> domain_db;
|
||||
std::shared_ptr<Database> ion_db;
|
||||
|
@ -200,7 +200,7 @@ int main(int argc, char **argv)
|
||||
ScaLBL_D3Q19_AAodd_Compact(M.NeighborList, gq, Np);
|
||||
|
||||
/* explicit mass transfer step with the membrane*/
|
||||
M.AssignCoefficients(dvcMap, Psi, "ones");
|
||||
M.AssignCoefficients(dvcMap, Psi, 0.0, 1.0, 1.0, 1.0, 1.0);
|
||||
M.IonTransport(gq, Cj);
|
||||
ScaLBL_CopyToHost(Ci_host, Cj, sizeof(double) * Np);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user