#include #include #include "pmmc.h" // Computes the interfacial areas according to the Porous Medium marching cubes (pmmc) // algorithm developed by McClure, Adalsteinnsson et al. (2007) for a two fluid phase // system. The common curve length is also computed. // The wn, ws, ns and solid surfaces are written to disk in the form of triangle lists int main(int argc, char * argv[]) { //........................................................................... int Nx,Ny,Nz,N; Nx = Ny = Nz = N; int i,j,k,p,q,r,n; //........................................................................... // Interfaces are defined by the F(x,y,z) = 0.0 // input data must be mapped such that this corresponds to the // desired interface double fluid_isovalue = 0.0; double solid_isovalue = 0.0; //........................................................................... cout << "Enter the domain length (x): " << endl; cin >> Nx; cout << "Enter the domain length (y): " << endl; cin >> Ny; cout << "Enter the domain length (z): " << endl; cin >> Nz; //........................................................................... //........................................................................... DoubleArray SignDist(Nx,Ny,Nz); DoubleArray Phase(Nx,Ny,Nz); //........................................................................... printf("Reading distance from a file... \n"); double readval; ifstream DISTANCE("Distance.in",ios::binary); for (int k=0;k fluid_isovalue) int cube[8][3] = {{0,0,0},{1,0,0},{0,1,0},{1,1,0},{0,0,1},{1,0,1},{0,1,1},{1,1,1}}; // cube corners // int count_in=0,count_out=0; // int nodx,nody,nodz; // initialize lists for vertices for surfaces, common line DTMutableList nw_pts(20); DTMutableList ns_pts(20); DTMutableList ws_pts(20); DTMutableList nws_pts(20); // initialize triangle lists for surfaces IntArray nw_tris(3,20); IntArray ns_tris(3,20); IntArray ws_tris(3,20); // initialize list for line segments IntArray nws_seg(2,20); DTMutableList tmp(20); // IntArray store; int n_nw_pts=0,n_ns_pts=0,n_ws_pts=0,n_nws_pts=0, map=0; int n_nw_tris=0, n_ns_tris=0, n_ws_tris=0, n_nws_seg=0; double s,s1,s2,s3; // Triangle sides (lengths) Point A,B,C,P; // double area; // Initialize arrays for local solid surface DTMutableList local_sol_pts(20); int n_local_sol_pts = 0; IntArray local_sol_tris(3,18); int n_local_sol_tris; DoubleArray values(20); DTMutableList local_nws_pts(20); int n_local_nws_pts; int n_nw_tris_beg, n_ns_tris_beg, n_ws_tris_beg; int c; int newton_steps = 0; //........................................................................... int ncubes = (Nx-2)*(Ny-2)*(Nz-2); // Exclude the "upper" halo IntArray cubeList(3,ncubes); int nc=0; //........................................................................... // Set up the cube list (very regular in this case due to lack of blob-ID) for (k=0; k 0 && SignDist(i+cube[p][0],j+cube[p][1],k+cube[p][2]) > 0 ){ nwp_volume += 0.125; } } // Run PMMC n_local_sol_tris = 0; n_local_sol_pts = 0; n_local_nws_pts = 0; n_nw_pts=0,n_ns_pts=0,n_ws_pts=0,n_nws_pts=0, map=0; n_nw_tris=0, n_ns_tris=0, n_ws_tris=0, n_nws_seg=0; n_nw_tris_beg = 0;// n_nw_tris; n_ns_tris_beg = 0;//n_ns_tris; n_ws_tris_beg = 0;//n_ws_tris; // if there is a solid phase interface in the grid cell if (Interface(SignDist,solid_isovalue,i,j,k) == 1){ ///////////////////////////////////////// /// CONSTRUCT THE LOCAL SOLID SURFACE /// ///////////////////////////////////////// // find the local solid surface // SOL_SURF(SignDist,0.0,Phase,fluid_isovalue,i,j,k, Nx,Ny,Nz,local_sol_pts,n_local_sol_pts, // local_sol_tris,n_local_sol_tris,values); // find the local solid surface using the regular Marching Cubes algorithm SolidMarchingCubes(SignDist,0.0,Phase,fluid_isovalue,i,j,k,Nx,Ny,Nz,local_sol_pts,n_local_sol_pts, local_sol_tris,n_local_sol_tris,values); ///////////////////////////////////////// //////// TRIM THE SOLID SURFACE ///////// ///////////////////////////////////////// /* TRIM(local_sol_pts, n_local_sol_pts, fluid_isovalue,local_sol_tris, n_local_sol_tris, ns_pts, n_ns_pts, ns_tris, n_ns_tris, ws_pts, n_ws_pts, ws_tris, n_ws_tris, values, local_nws_pts, n_local_nws_pts, Phase, SignDist, i, j, k, newton_steps); */ TRIM(local_sol_pts, n_local_sol_pts, fluid_isovalue,local_sol_tris, n_local_sol_tris, ns_pts, n_ns_pts, ns_tris, n_ns_tris, ws_pts, n_ws_pts, ws_tris, n_ws_tris, values, local_nws_pts, n_local_nws_pts); ///////////////////////////////////////// //////// WRITE COMMON LINE POINTS /////// //////// TO MAIN ARRAYS /////// ///////////////////////////////////////// // SORT THE LOCAL COMMON LINE POINTS ///////////////////////////////////////// // Make sure the first common line point is on a face // Common curve points are located pairwise and must // be searched and rearranged accordingly for (p=0; p 0){ n_nw_tris =0; EDGE(Phase, fluid_isovalue, SignDist, i,j,k, Nx, Ny, Nz, nw_pts, n_nw_pts, nw_tris, n_nw_tris, nws_pts, n_nws_pts); } else { MC(Phase, fluid_isovalue, SignDist, i,j,k, nw_pts, n_nw_pts, nw_tris, n_nw_tris); } } ///////////////////////////////////////// ////// CONSTRUCT THE nw SURFACE ///////// ///////////////////////////////////////// else if (Fluid_Interface(Phase,SignDist,fluid_isovalue,i,j,k) == 1){ MC(Phase, fluid_isovalue, SignDist, i,j,k, nw_pts, n_nw_pts, nw_tris, n_nw_tris); } //******END OF BLOB PMMC********************************************* //******************************************************************* // Compute the Interfacial Areas, Common Line length for blob p // nw surface double temp; for (r=0;r 0.0) awn += sqrt(temp); } for (r=0;r 0.0) ans += sqrt(temp); } for (r=0;r 0.0) aws += sqrt(temp); } for (r=0;r 0.0) As += sqrt(temp); } for (p=0; p < n_local_nws_pts-1; p++){ // Extract the line segment A = local_nws_pts(p); B = local_nws_pts(p+1); // Compute the length of the segment s = sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z)); // Add the length to the common line lwns += s; } //....................................................................................... // Write the triangle lists to text file for (r=0;r