Files
LBPM/tests/lbpm_minkowski_scalar.cpp

131 lines
3.4 KiB
C++
Raw Normal View History

2018-08-15 14:50:53 -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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include "common/Array.h"
#include "common/Domain.h"
#include "common/Communication.h"
2020-03-17 21:44:45 -04:00
#include "common/MPI_Helpers.h"
2018-08-15 14:50:53 -04:00
#include "IO/MeshDatabase.h"
#include "IO/Mesh.h"
#include "IO/Writer.h"
#include "IO/netcdf.h"
#include "analysis/analysis.h"
#include "analysis/filters.h"
#include "analysis/distance.h"
#include "analysis/Minkowski.h"
#include "ProfilerApp.h"
int main(int argc, char **argv)
{
2020-03-17 21:44:45 -04:00
2018-08-15 14:50:53 -04:00
// Initialize MPI
2021-01-04 19:33:27 -05:00
Utilities::startup( argc, argv );
2020-01-28 08:51:32 -05:00
Utilities::MPI comm( MPI_COMM_WORLD );
2021-01-04 19:33:27 -05:00
int rank = comm.getRank();
2021-01-05 18:43:44 -05:00
//int nprocs = comm.getSize();
2018-08-15 14:50:53 -04:00
{
Utilities::setErrorHandlers();
PROFILE_START("Main");
//std::vector<std::string> filenames;
if ( argc<2 ) {
if ( rank == 0 ){
printf("At least one filename must be specified\n");
}
return 1;
}
std::string filename = std::string(argv[1]);
if ( rank == 0 ){
printf("Input data file: %s\n",filename.c_str());
}
auto db = std::make_shared<Database>( filename );
auto domain_db = db->getDatabase( "Domain" );
// Read domain parameters
auto Filename = domain_db->getScalar<std::string>( "Filename" );
auto L = domain_db->getVector<double>( "L" );
auto size = domain_db->getVector<int>( "n" );
auto SIZE = domain_db->getVector<int>( "N" );
auto nproc = domain_db->getVector<int>( "nproc" );
auto ReadValues = domain_db->getVector<char>( "ReadValues" );
auto WriteValues = domain_db->getVector<char>( "WriteValues" );
auto nx = size[0];
auto ny = size[1];
auto nz = size[2];
2021-01-05 18:43:44 -05:00
/*auto nprocx = nproc[0];
2018-08-15 14:50:53 -04:00
auto nprocy = nproc[1];
auto nprocz = nproc[2];
auto Nx = SIZE[0];
auto Ny = SIZE[1];
auto Nz = SIZE[2];
2021-01-05 18:43:44 -05:00
*/
2018-08-15 14:50:53 -04:00
int i,j,k,n;
2021-01-05 18:43:44 -05:00
std::shared_ptr<Domain> Dm = std::shared_ptr<Domain>(new Domain(domain_db,comm)); // full domain for analysis
comm.barrier();
2018-08-15 14:50:53 -04:00
Dm->CommInit();
// Compute the Minkowski functionals
2021-01-05 18:43:44 -05:00
comm.barrier();
2020-03-17 21:44:45 -04:00
std::shared_ptr<Minkowski> Averages(new Minkowski(Dm));
2018-08-15 14:50:53 -04:00
// Calculate the distance
// Initialize the domain and communication
nx+=2; ny+=2; nz+=2;
Array<char> id(nx,ny,nz);
2018-09-15 13:49:28 -04:00
DoubleArray Distance(nx,ny,nz);
2018-08-15 14:50:53 -04:00
//if (rank==0){
//printf("ID: %i, %i, %i \n",Dm->Nx, Dm->Ny, Dm->Nz);
// printf("ID: %i, %i, %i \n",id.size(0),id.size(1),id.size(2));
// printf("SDn: %i, %i, %i \n",Averages->SDn.size(0),Averages->SDn.size(1),Averages->SDn.size(2));
//}
// Solve for the position of the solid phase
for (k=0;k<nz;k++){
for (j=0;j<ny;j++){
for (i=0;i<nx;i++){
n = k*nx*ny+j*nx+i;
// Initialize the object
if (Dm->id[n] == ReadValues[0]) id(i,j,k) = 1;
else id(i,j,k) = 0;
}
}
}
for (k=0;k<nz;k++){
for (j=0;j<ny;j++){
for (i=0;i<nx;i++){
n=k*nx*ny+j*nx+i;
// Initialize distance to +/- 1
2018-09-15 13:49:28 -04:00
Distance(i,j,k) = 2.0*double(id(i,j,k))-1.0;
2018-08-15 14:50:53 -04:00
}
}
}
//std::array<bool> bc(3)={1,1,1};
if (rank==0) printf("Initialized solid phase -- Converting to Signed Distance function \n");
2018-09-15 13:49:28 -04:00
CalcDist(Distance,id,*Dm);
2018-08-15 14:50:53 -04:00
if (rank==0) printf("Computing Minkowski functionals \n");
2018-09-15 13:50:51 -04:00
Averages->ComputeScalar(Distance,0.f);
2018-08-15 14:50:53 -04:00
Averages->PrintAll();
}
PROFILE_STOP("Main");
PROFILE_SAVE("Minkowski",true);
2021-01-04 19:33:27 -05:00
Utilities::shutdown();
2018-08-15 14:50:53 -04:00
return 0;
}