Merge branch 'master' of github.com:JamesEMcClure/LBPM-WIA

This commit is contained in:
James E McClure
2018-09-04 22:42:49 -04:00
4 changed files with 56 additions and 36 deletions

View File

@@ -39,29 +39,34 @@ void DeleteArray( const TYPE *p )
class WriteRestartWorkItem: public ThreadPool::WorkItemRet<void>
{
public:
WriteRestartWorkItem( const char* filename_, std::shared_ptr<double> cphi_, std::shared_ptr<double> cfq_, int N_ ):
filename(filename_), cphi(cphi_), cfq(cfq_), N(N_) {}
virtual void run() {
PROFILE_START("Save Checkpoint",1);
double value;
ofstream File(filename,ios::binary);
for (int n=0; n<N; n++){
// Write the two density values
value = cphi.get()[n];
File.write((char*) &value, sizeof(value));
// Write the distributions
for (int q=0; q<19; q++){
value = cfq.get()[q*N+n];
File.write((char*) &value, sizeof(value));
}
}
File.close();
WriteRestartWorkItem( const char* filename_, std::shared_ptr<double> cDen_, std::shared_ptr<double> cfq_, int N_ ):
filename(filename_), cDen(cDen_), cfq(cfq_), N(N_) {}
virtual void run() {
PROFILE_START("Save Checkpoint",1);
double value;
ofstream File(filename,ios::binary);
for (int n=0; n<N; n++){
// Write the two density values
value = cDen.get()[n];
File.write((char*) &value, sizeof(value));
value = cDen.get()[N+n];
File.write((char*) &value, sizeof(value));
}
for (int n=0; n<N; n++){
// Write the distributions
for (int q=0; q<19; q++){
value = cfq.get()[q*N+n];
File.write((char*) &value, sizeof(value));
}
}
File.close();
PROFILE_STOP("Save Checkpoint",1);
};
};
private:
WriteRestartWorkItem();
const char* filename;
std::shared_ptr<double> cfq,cphi;
std::shared_ptr<double> cfq,cDen;
// const DoubleArray& phase;
//const DoubleArray& dist;
const int N;
@@ -323,13 +328,12 @@ runAnalysis::runAnalysis( std::shared_ptr<Database> db,
d_meshData[0].mesh = std::make_shared<IO::DomainMesh>( Dm->rank_info,Dm->Nx-2,Dm->Ny-2,Dm->Nz-2,Dm->Lx,Dm->Ly,Dm->Lz );
auto PhaseVar = std::make_shared<IO::Variable>();
auto PressVar = std::make_shared<IO::Variable>();
auto VxVar = std::make_shared<IO::Variable>();
auto VyVar = std::make_shared<IO::Variable>();
auto VzVar = std::make_shared<IO::Variable>();
auto SignDistVar = std::make_shared<IO::Variable>();
auto BlobIDVar = std::make_shared<IO::Variable>();
PhaseVar->name = "phase";
PhaseVar->type = IO::VariableType::VolumeVariable;
PhaseVar->dim = 1;
@@ -600,14 +604,14 @@ void runAnalysis::run( int timestep, TwoPhase& Averages, const double *Phi,
d_ScaLBL_Comm->RegularLayout(d_Map,&Velocity[2*d_Np],Averages.Vel_z);
PROFILE_STOP("Copy-State",1);
}
std::shared_ptr<double> cfq,cPhi;
std::shared_ptr<double> cfq,cDen;
//if ( matches(type,AnalysisType::CreateRestart) ) {
if (timestep%d_restart_interval==0){
// Copy restart data to the CPU
cPhi = std::shared_ptr<double>(new double[d_Np],DeleteArray<double>);
cDen = std::shared_ptr<double>(new double[2*d_Np],DeleteArray<double>);
cfq = std::shared_ptr<double>(new double[19*d_Np],DeleteArray<double>);
ScaLBL_CopyToHost(cfq.get(),fq,19*d_Np*sizeof(double));
ScaLBL_CopyToHost(cPhi.get(),Phi,d_Np*sizeof(double));
ScaLBL_CopyToHost(cDen.get(),Den,2*d_Np*sizeof(double));
}
PROFILE_STOP("Copy data to host",1);
@@ -615,6 +619,10 @@ void runAnalysis::run( int timestep, TwoPhase& Averages, const double *Phi,
if ( matches(type,AnalysisType::IdentifyBlobs) ) {
phase = std::shared_ptr<DoubleArray>(new DoubleArray(d_N[0],d_N[1],d_N[2]));
d_ScaLBL_Comm->RegularLayout(d_Map,Phi,*phase);
if (d_regular)
d_ScaLBL_Comm->RegularLayout(d_Map,Phi,*phase);
else
ScaLBL_CopyToHost(phase.get(),Phi,N*sizeof(double));
BlobIDstruct new_index(new std::pair<int,IntArray>(0,IntArray()));
BlobIDstruct new_ids(new std::pair<int,IntArray>(0,IntArray()));
@@ -652,7 +660,7 @@ void runAnalysis::run( int timestep, TwoPhase& Averages, const double *Phi,
fclose(Rst);
}
// Write the restart file (using a seperate thread)
auto work = new WriteRestartWorkItem(d_restartFile.c_str(),cPhi,cfq,d_Np);
auto work = new WriteRestartWorkItem(d_restartFile.c_str(),cDen,cfq,d_Np);
work->add_dependency(d_wait_restart);
d_wait_restart = d_tpool.add_work(work);
}

View File

@@ -2777,11 +2777,15 @@ extern "C" void ScaLBL_PhaseField_Init(int *Map, double *Phi, double *Den, doubl
n = Map[idx];
phi = Phi[n];
if (phi > 0.f){
nA = 1.0; nB = 0.f;
if (phi > 1.f){
nA = 1.0; nB = 0.f;
}
else if (phi < -1.f){
nB = 1.0; nA = 0.f;
}
else{
nB = 1.0; nA = 0.f;
nA=0.5*(phi+1.f);
nB=0.5*(1.f-phi);
}
Den[idx] = nA;
Den[Np+idx] = nB;

View File

@@ -3902,12 +3902,16 @@ __global__ void dvc_ScaLBL_PhaseField_Init(int *Map, double *Phi, double *Den, d
n = Map[idx];
phi = Phi[n];
if (phi > 0.f){
nA = 1.0; nB = 0.f;
}
else{
nB = 1.0; nA = 0.f;
}
if (phi > 1.f){
nA = 1.0; nB = 0.f;
}
else if (phi < -1.f){
nB = 1.0; nA = 0.f;
}
else{
nA=0.5*(phi+1.f);
nB=0.5*(1.f-phi);
}
Den[idx] = nA;
Den[Np+idx] = nB;

View File

@@ -296,10 +296,14 @@ void ScaLBL_ColorModel::Initialize(){
double *cPhi = new double[Np];
double *cDist = new double[19*Np];
ifstream File(LocalRestartFile,ios::binary);
double value;
double value,va,vb;
for (int n=0; n<Np; n++){
File.read((char*) &value, sizeof(value));
File.read((char*) &value, sizeof(va));
File.read((char*) &value, sizeof(vb));
value = (va-vb)/(va+vb);
cPhi[n] = value;
}
for (int n=0; n<Np; n++){
// Read the distributions
for (int q=0; q<19; q++){
File.read((char*) &value, sizeof(value));