adding more comprehensive labeling tool
This commit is contained in:
@@ -13,6 +13,94 @@
|
||||
#include "common/Array.h"
|
||||
#include "common/Domain.h"
|
||||
|
||||
|
||||
void AssignComponentLabels(double *phase)
|
||||
{
|
||||
int NLABELS=0;
|
||||
char VALUE=0;
|
||||
double AFFINITY=0.f;
|
||||
|
||||
vector <char> Label;
|
||||
vector <double> Affinity;
|
||||
// Read the labels
|
||||
if (rank==0){
|
||||
printf("Component labels:\n");
|
||||
ifstream iFILE("ComponentLabels.csv");
|
||||
if (iFILE.good()){
|
||||
int value;
|
||||
while (!iFILE.eof()){
|
||||
iFILE>>value;
|
||||
iFILE>>AFFINITY;
|
||||
VALUE=char(value);
|
||||
Label.push_back(value);
|
||||
Affinity.push_back(AFFINITY);
|
||||
NLABELS++;
|
||||
printf("%i %f\n",VALUE,AFFINITY);
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("Using default labels: Solid (0 --> -1.0), NWP (1 --> 1.0), WP (2 --> -1.0)\n");
|
||||
// Set default values
|
||||
VALUE=0; AFFINITY=-1.0;
|
||||
Label.push_back(VALUE);
|
||||
Affinity.push_back(AFFINITY);
|
||||
NLABELS++;
|
||||
VALUE=1; AFFINITY=1.0;
|
||||
Label.push_back(VALUE);
|
||||
Affinity.push_back(AFFINITY);
|
||||
NLABELS++;
|
||||
VALUE=2; AFFINITY=-1.0;
|
||||
Label.push_back(VALUE);
|
||||
Affinity.push_back(AFFINITY);
|
||||
NLABELS++;
|
||||
}
|
||||
}
|
||||
MPI_Barrier(Comm);
|
||||
|
||||
// Broadcast the list
|
||||
MPI_Bcast(&NLABELS,1,MPI_INT,0,Comm);
|
||||
//printf("rank=%i, NLABELS=%i \n ",rank,NLABELS);
|
||||
|
||||
// Copy into contiguous buffers
|
||||
char *LabelList;
|
||||
double * AffinityList;
|
||||
LabelList=new char[NLABELS];
|
||||
AffinityList=new double[NLABELS];
|
||||
|
||||
if (rank==0){
|
||||
for (int idx=0; idx < NLABELS; idx++){
|
||||
VALUE=Label[idx];
|
||||
AFFINITY=Affinity[idx];
|
||||
printf("rank=%i, idx=%i, value=%d, affinity=%f \n",rank,idx,VALUE,AFFINITY);
|
||||
LabelList[idx]=VALUE;
|
||||
AffinityList[idx]=AFFINITY;
|
||||
}
|
||||
}
|
||||
MPI_Barrier(Comm);
|
||||
|
||||
MPI_Bcast(LabelList,NLABELS,MPI_CHAR,0,Comm);
|
||||
MPI_Bcast(AffinityList,NLABELS,MPI_DOUBLE,0,Comm);
|
||||
|
||||
// Assign the labels
|
||||
for (int k=0;k<Nz;k++){
|
||||
for (int j=0;j<Ny;j++){
|
||||
for (int i=0;i<Nx;i++){
|
||||
int n = k*Nx*Ny+j*Nx+i;
|
||||
VALUE=id[n];
|
||||
// Assign the affinity from the paired list
|
||||
for (int idx=0; idx < NLABELS; idx++){
|
||||
//printf("rank=%i, idx=%i, value=%i, %i, \n",rank,idx, VALUE,LabelList[idx]);
|
||||
if (VALUE == LabelList[idx]){
|
||||
AFFINITY=AffinityList[idx];
|
||||
idx = NLABELS;
|
||||
}
|
||||
}
|
||||
phase[n] = AFFINITY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Initialize MPI
|
||||
@@ -28,16 +116,14 @@ int main(int argc, char **argv)
|
||||
bool MULTINPUT=false;
|
||||
|
||||
int NWP,SOLID,rank_offset;
|
||||
SOLID=atoi(argv[1]);
|
||||
NWP=atoi(argv[2]);
|
||||
//char NWP,SOLID;
|
||||
//SOLID=argv[1][0];
|
||||
//NWP=argv[2][0];
|
||||
int NLABELS=atoi(argv[1]);
|
||||
//SOLID=atoi(argv[1]);
|
||||
//NWP=atoi(argv[2]);
|
||||
if (rank==0){
|
||||
printf("Solid Label: %i \n",SOLID);
|
||||
printf("NWP Label: %i \n",NWP);
|
||||
//printf("Solid Label: %i \n",SOLID);
|
||||
//printf("NWP Label: %i \n",NWP);
|
||||
}
|
||||
if (argc > 3){
|
||||
if (argc > 2){
|
||||
MULTINPUT=true;
|
||||
rank_offset = atoi(argv[3]);
|
||||
}
|
||||
@@ -208,16 +294,55 @@ int main(int argc, char **argv)
|
||||
|
||||
nx+=2; ny+=2; nz+=2;
|
||||
N=nx*ny*nz;
|
||||
|
||||
if (rank==0) printf("All sub-domains recieved \n");
|
||||
|
||||
// Assign New Labels
|
||||
char *LabelList;
|
||||
LabelList=new char[2*NLABELS];
|
||||
if (rank==0){
|
||||
printf("Assigning new lablels \n");
|
||||
if (rank==0){
|
||||
printf("Component labels:\n");
|
||||
ifstream iFILE("ComponentLabels.csv");
|
||||
if (iFILE.good()){
|
||||
int oldlabel, newlabel;
|
||||
int label=0;
|
||||
while (!iFILE.eof()){
|
||||
iFILE>>oldlabel;
|
||||
iFILE>>newlabel;
|
||||
LabelList[2*label] = char(oldlabel);
|
||||
LabelList[2*label+1] = char(newlabel);
|
||||
label++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("Using default labels: Solid (0 --> -1), NWP (1 --> 1), WP (2 --> 2)\n");
|
||||
// Set default values
|
||||
NLABELS=3;
|
||||
for (int label=0; label<NLABELS; label++){
|
||||
LabelList[2*label] = char(label);
|
||||
LabelList[2*label+1] = char(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int label=0; label<NLABELS; label++){
|
||||
int oldlabel=atoi(LabelList[2*label]);
|
||||
int newlabel=atoi(LabelList[2*label]+1);
|
||||
printf("Original label=%i, New label=%i \n");
|
||||
}
|
||||
}
|
||||
MPI_Barrier(Comm);
|
||||
MPI_Bcast(LabelList,2*NLABELS,MPI_CHAR,0,MPI_COMM_WORLD);
|
||||
|
||||
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;
|
||||
if (Dm.id[n]==char(SOLID)) Dm.id[n] = 0;
|
||||
else if (Dm.id[n]==char(NWP)) Dm.id[n] = 1;
|
||||
else Dm.id[n] = 2;
|
||||
|
||||
for (int label=0; label<NLABELS; label++){
|
||||
char oldlabel=LabelList[2*label];
|
||||
char newlabel=LabelList[2*label+1];
|
||||
if (Dm.id[n]==oldlabel) Dm.id[n] = newlabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user