added historical labeling feature to morph open tool

This commit is contained in:
James E McClure committed 2018-12-09 08:05:23 -05:00
1 parent af1b99ae87
commit 3e3f6c7ec5
1 file changed
+46 -1
+46 -1
View File
@@ -126,7 +126,52 @@ int main(int argc, char **argv)
MPI_Barrier(comm);
// Run the morphological opening
MorphOpen(SignDist, id, Dm, SW);
MorphOpen(SignDist, id, Dm, SW, 0.05);
// calculate distance to non-wetting fluid
if (domain_db->keyExists( "HistoryLabels" )){
if (rank==0) printf("Relabel solid components that touch fluid 1 \n");
auto LabelList = domain_db->getVector<char>( "ComponentLabels" );
auto HistoryLabels = domain_db->getVector<char>( "HistoryLabels" );
size_t NLABELS=LabelList.size();
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;
// Initialize the solid phase
if (id[n] == 1) id_solid(i,j,k) = 1;
else id_solid(i,j,k) = 0;
}
}
}
// Initialize the signed distance function
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;
// Initialize distance to +/- 1
SignDist(i,j,k) = 2.0*double(id_solid(i,j,k))-1.0;
}
}
}
CalcDist(SignDist,id_solid,*Dm);
// re-label IDs near the non-wetting fluid
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;
char VALUE=id[n];
for (unsigned int idx=0; idx < NLABELS; idx++){
if (VALUE == LabelList[idx]){
idx = NLABELS;
char NEWVALUE=HistoryLabels[idx];
if (SignDist(i,j,k) < 2.f) id[n] = NEWVALUE;
}
}
}
}
}
}
if (rank==0) printf("Writing ID file \n");
sprintf(LocalRankFilename,"ID.%05i",rank);