Files
LBPM/tests/TestTorus.cpp

187 lines
5.9 KiB
C++
Raw Normal View History

2015-09-04 19:59:07 -04:00
// Sequential blob analysis
// Reads parallel simulation data and performs connectivity analysis
// and averaging on a blob-by-blob basis
// James E. McClure 2014
#include <iostream>
#include <math.h>
#include "common/Communication.h"
#include "analysis/analysis.h"
#include "analysis/TwoPhase.h"
2015-09-04 19:59:07 -04:00
2018-05-15 10:01:14 -04:00
std::shared_ptr<Database> loadInputs( int nprocs )
{
2018-05-16 21:32:30 -04:00
//auto db = std::make_shared<Database>( "Domain.in" );
auto db = std::make_shared<Database>();
2018-05-15 10:01:14 -04:00
db->putScalar<int>( "BC", 0 );
db->putVector<int>( "nproc", { 1, 1, 1 } );
db->putVector<int>( "n", { 100, 100, 100 } );
db->putScalar<int>( "nspheres", 1 );
db->putVector<double>( "L", { 1, 1, 1 } );
return db;
}
2015-09-04 19:59:07 -04:00
int main(int argc, char **argv)
{
// Initialize MPI
2020-10-08 11:03:42 -04:00
Utilities::startup( argc, argv );
2020-01-28 08:51:32 -05:00
Utilities::MPI comm( MPI_COMM_WORLD );
int rank = comm.getRank();
int nprocs = comm.getSize();
2015-09-04 19:59:07 -04:00
{ // Limit scope so variables that contain communicators will free before MPI_Finialize
if ( rank==0 ) {
printf("-----------------------------------------------------------\n");
2015-11-22 14:39:19 -05:00
printf("Unit test for torus (Euler-Poincarie characteristic) \n");
2015-09-04 19:59:07 -04:00
printf("-----------------------------------------------------------\n");
}
//.......................................................................
// Reading the domain information file
//.......................................................................
int i,j,k,n;
2018-05-16 21:46:29 -04:00
// Load inputs
auto db = loadInputs( nprocs );
int Nx = db->getVector<int>( "n" )[0];
int Ny = db->getVector<int>( "n" )[1];
int Nz = db->getVector<int>( "n" )[2];
int nprocx = db->getVector<int>( "nproc" )[0];
int nprocy = db->getVector<int>( "nproc" )[1];
int nprocz = db->getVector<int>( "nproc" )[2];
2015-09-04 19:59:07 -04:00
2018-05-16 21:46:29 -04:00
if (rank==0){
printf("********************************************************\n");
printf("Sub-domain size = %i x %i x %i\n",Nx,Ny,Nz);
printf("********************************************************\n");
}
2015-09-04 19:59:07 -04:00
// Get the rank info
2020-01-22 12:01:29 -05:00
auto Dm = std::make_shared<Domain>(db,comm);
2015-09-04 19:59:07 -04:00
// const RankInfoStruct rank_info(rank,nprocx,nprocy,nprocz);
2020-01-22 12:01:29 -05:00
auto Averages = std::make_shared<TwoPhase>(Dm);
2020-06-24 13:48:53 -04:00
auto Object = std::make_shared<Minkowski>(Dm);
2018-05-15 10:01:14 -04:00
Nx += 2;
Ny += 2;
Nz += 2;
2015-09-04 19:59:07 -04:00
//.......................................................................
for ( k=1;k<Nz-1;k++){
for ( j=1;j<Ny-1;j++){
for ( i=1;i<Nx-1;i++){
n = k*Nx*Ny+j*Nx+i;
2018-05-17 21:03:11 -04:00
Dm->id[n] = 1;
2015-09-04 19:59:07 -04:00
}
}
}
//.......................................................................
2018-05-19 07:49:32 -04:00
Dm->CommInit(); // Initialize communications for domains
2015-09-04 19:59:07 -04:00
//.......................................................................
//.......................................................................
// Assign the phase ID field based and the signed distance
//.......................................................................
double R1,R2;
2016-01-10 11:30:13 -05:00
double CX,CY,CZ; //CY1,CY2;
2015-09-04 19:59:07 -04:00
CX=Nx*nprocx*0.5;
CY=Ny*nprocy*0.5;
CZ=Nz*nprocz*0.5;
2015-09-04 20:15:21 -04:00
R1 = Nx*nprocx*0.2; // middle radius
2015-09-04 19:59:07 -04:00
R2 = Nx*nprocx*0.1; // donut thickness
2015-09-04 20:09:49 -04:00
//
//CY1=Nx*nprocx*0.5+R1;
//CY2=Ny*nprocy*0.5-R1;
2015-09-04 20:09:49 -04:00
2015-09-04 19:59:07 -04:00
double x,y,z;
if (rank==0) printf("Initializing the system \n");
for ( k=1;k<Nz-1;k++){
for ( j=1;j<Ny-1;j++){
for ( i=1;i<Nx-1;i++){
n = k*Nx*Ny+j*Nx+i;
// global position relative to center
2018-05-17 21:03:11 -04:00
x = Dm->iproc()*Nx+i - CX;
y = Dm->jproc()*Ny+j - CY;
z = Dm->kproc()*Nz+k - CZ;
2015-09-04 19:59:07 -04:00
// Shrink the sphere sizes by two voxels to make sure they don't touch
2018-05-17 21:03:11 -04:00
Averages->SDs(i,j,k) = 100.0;
2015-09-04 20:09:49 -04:00
//..............................................................................
// Single torus
2018-05-17 21:03:11 -04:00
Averages->Phase(i,j,k) = sqrt((sqrt(x*x+y*y) - R1)*(sqrt(x*x+y*y) - R1) + z*z) - R2;
2015-09-04 20:09:49 -04:00
// Double torus
2018-05-17 21:03:11 -04:00
/* y = Dm->jproc()*Ny+j - CY1;
//z = Dm->kproc()*Nz+k - CZ +R1;
Averages->Phase(i,j,k) = sqrt((sqrt(x*x+y*y) - R1)*(sqrt(x*x+y*y) - R1) + z*z) - R2;
2018-05-17 21:03:11 -04:00
y = Dm->jproc()*Ny+j - CY2;
//z = Dm->kproc()*Nz+k - CZ-R1;
Averages->Phase(i,j,k) = min(Averages->Phase(i,j,k),
2015-09-04 20:09:49 -04:00
sqrt((sqrt(x*x+y*y) - R1)*(sqrt(x*x+y*y) - R1) + z*z) - R2);
*///..............................................................................
2015-09-04 19:59:07 -04:00
2018-05-17 21:03:11 -04:00
//Averages->Phase(i,j,k) = - Averages->Phase(i,j,k);
if (Averages->Phase(i,j,k) > 0.0){
Dm->id[n] = 2;
2020-06-24 13:48:53 -04:00
Object->id(i,j,k) = 1;
2015-09-04 19:59:07 -04:00
}
else{
2018-05-17 21:03:11 -04:00
Dm->id[n] = 1;
2020-06-24 13:48:53 -04:00
Object->id(i,j,k) = 0;
2015-09-04 19:59:07 -04:00
}
2018-05-17 21:03:11 -04:00
Averages->SDn(i,j,k) = Averages->Phase(i,j,k);
Averages->Phase(i,j,k) = Averages->SDn(i,j,k);
Averages->Phase_tplus(i,j,k) = Averages->SDn(i,j,k);
Averages->Phase_tminus(i,j,k) = Averages->SDn(i,j,k);
Averages->DelPhi(i,j,k) = 0.0;
Averages->Press(i,j,k) = 0.0;
Averages->Vel_x(i,j,k) = 0.0;
Averages->Vel_y(i,j,k) = 0.0;
Averages->Vel_z(i,j,k) = 0.0;
2015-09-04 19:59:07 -04:00
}
}
}
2020-01-22 12:01:29 -05:00
//double beta = 0.95;
2015-09-04 19:59:07 -04:00
if (rank==0) printf("initializing the system \n");
2018-05-17 21:03:11 -04:00
Averages->UpdateSolid();
Dm->CommunicateMeshHalo(Averages->Phase);
Dm->CommunicateMeshHalo(Averages->SDn);
2015-09-04 19:59:07 -04:00
2018-05-17 21:03:11 -04:00
Averages->Initialize();
Averages->UpdateMeshValues();
2015-09-04 19:59:07 -04:00
if (rank==0) printf("computing local averages \n");
2018-05-17 21:03:11 -04:00
Averages->AssignComponentLabels();
Averages->ComponentAverages();
Averages->PrintComponents(int(5));
2015-09-04 19:59:07 -04:00
if (rank==0) printf("reducing averages \n");
2018-05-17 21:03:11 -04:00
Averages->Initialize();
Averages->ComputeLocal();
Averages->Reduce();
Averages->PrintAll(int(5));
// Averages->Reduce();
2020-06-24 13:48:53 -04:00
Object->MeasureObject();
2022-03-08 22:13:48 -05:00
//Object->MeasureConnectedPathway();
2020-06-24 14:01:10 -04:00
double Vi = Object->V();
double Ai = Object->A();
double Hi = Object->H();
double Xi = Object->X();
2021-01-05 16:08:03 -05:00
Vi=Dm->Comm.sumReduce( Vi);
Ai=Dm->Comm.sumReduce( Ai);
Hi=Dm->Comm.sumReduce( Hi);
Xi=Dm->Comm.sumReduce( Xi);
2020-06-24 13:48:53 -04:00
printf("Vi=%f, Ai=%f, Hi=%f, Xi=%f \n", Vi,Ai,Hi,Xi);
2015-09-04 19:59:07 -04:00
} // Limit scope so variables that contain communicators will free before MPI_Finialize
2020-10-08 11:03:42 -04:00
Utilities::shutdown();
2015-09-04 19:59:07 -04:00
return 0;
}