Updated CPU branch

This commit is contained in:
James McClure
2014-01-27 11:43:24 -05:00
parent 32cacd8afd
commit 42338802c5
16 changed files with 5921 additions and 244 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,20 @@
extern void InitDenColor(char *ID, double *Den, double *Phi, double das, double dbs, int N); extern "C" void dvc_InitDenColor(char *ID, double *Den, double *Phi, double das, double dbs, int Nx, int Ny, int Nz, int S);
extern void InitD3Q19(char *ID, double *f_even, double *f_odd, int Nx, int Ny, int Nz); extern "C" void dvc_InitDenColorDistance(char *ID, double *Den, double *Phi, double *Distance,
double das, double dbs, double beta, double xp, int Nx, int Ny, int Nz, int S);
extern void Compute_VELOCITY(char *ID, double *disteven, double *distodd, double *vel, int Nx, int Ny, int Nz); extern "C" void dvc_Compute_VELOCITY(char *ID, double *disteven, double *distodd, double *vel, int Nx, int Ny, int Nz, int S);
extern "C" void dvc_ComputePressureD3Q19(char *ID, double *disteven, double *distodd, double *Pressure,
//************************************************************************* int Nx, int Ny, int Nz, int S);
//************************************************************************* extern "C" void dvc_PressureBC_inlet(double *disteven, double *distodd, double din,
extern void PressureBC_inlet(double *disteven, double *distodd, double din, int Nx, int Ny, int Nz, int S);
int Nx, int Ny, int Nz); extern "C" void dvc_PressureBC_outlet(double *disteven, double *distodd, double dout,
extern void PressureBC_outlet(double *disteven, double *distodd, double dout, int Nx, int Ny, int Nz, int S, int outlet);
int Nx, int Ny, int Nz, int S, int outlet); extern "C" void dvc_ComputeColorGradient(char *ID, double *phi, double *ColorGrad, int Nx, int Ny, int Nz, int S);
//************************************************************************* extern "C" void dvc_ColorCollide( char *ID, double *disteven, double *distodd, double *ColorGrad,
extern void ComputeColorGradient(char *ID, double *phi, double *ColorGrad, int Nx, int Ny, int Nz); double *Velocity, int Nx, int Ny, int Nz, int S,double rlx_setA, double rlx_setB,
//************************************************************************* double alpha, double beta, double Fx, double Fy, double Fz, bool pBC);
extern void ColorCollide( char *ID, double *disteven, double *distodd, double *ColorGrad, extern "C" void dvc_ColorCollideOpt( char *ID, double *disteven, double *distodd, double *phi, double *ColorGrad,
double *Velocity, int Nx, int Ny, int Nz, double rlx_setA, double rlx_setB, double *Velocity, int Nx, int Ny, int Nz, int S,double rlx_setA, double rlx_setB,
double alpha, double beta, double Fx, double Fy, double Fz, bool pBC); double alpha, double beta, double Fx, double Fy, double Fz);
//************************************************************************* extern "C" void dvc_DensityStreamD3Q7(char *ID, double *Den, double *Copy, double *Phi, double *ColorGrad, double *Velocity,
extern void DensityStreamD3Q7(char *ID, double *Den, double *Copy, double *Phi, double *ColorGrad, double *Velocity, double beta, int Nx, int Ny, int Nz, bool pBC, int S);
double beta, int Nx, int Ny, int Nz, bool pBC); extern "C" void dvc_ComputePhi(char *ID, double *Phi, double *Copy, double *Den, int N, int S);
extern void ComputePhi(char *ID, double *Phi, double *Copy, double *Den, int N);

View File

@@ -1,4 +1,4 @@
extern void PackDist(int q, int *list, int start, int count, double *sendbuf, double *dist, int N){ extern "C" void dvc_PackDist(int q, int *list, int start, int count, double *sendbuf, double *dist, int N){
//.................................................................................... //....................................................................................
// Pack distribution q into the send buffer for the listed lattice sites // Pack distribution q into the send buffer for the listed lattice sites
// dist may be even or odd distributions stored by stream layout // dist may be even or odd distributions stored by stream layout
@@ -10,9 +10,7 @@ extern void PackDist(int q, int *list, int start, int count, double *sendbuf, do
} }
} }
extern "C" void dvc_UnpackDist(int q, int Cqx, int Cqy, int Cqz, int *list, int start, int count,
extern void MapRecvDist(int q, int Cqx, int Cqy, int Cqz, int *list, int start, int count,
double *recvbuf, double *dist, int Nx, int Ny, int Nz){ double *recvbuf, double *dist, int Nx, int Ny, int Nz){
//.................................................................................... //....................................................................................
// Unack distribution from the recv buffer // Unack distribution from the recv buffer
@@ -54,8 +52,46 @@ extern void MapRecvDist(int q, int Cqx, int Cqy, int Cqz, int *list, int start,
} }
} }
extern "C" void dvc_InitD3Q19(char *ID, double *f_even, double *f_odd, int Nx, int Ny, int Nz, int S)
{
int n,N;
N = Nx*Ny*Nz;
for (n=0; n<N; n++){
if (ID[n] > 0){
f_even[n] = 0.3333333333333333;
f_odd[n] = 0.055555555555555555; //double(100*n)+1.f;
f_even[N+n] = 0.055555555555555555; //double(100*n)+2.f;
f_odd[N+n] = 0.055555555555555555; //double(100*n)+3.f;
f_even[2*N+n] = 0.055555555555555555; //double(100*n)+4.f;
f_odd[2*N+n] = 0.055555555555555555; //double(100*n)+5.f;
f_even[3*N+n] = 0.055555555555555555; //double(100*n)+6.f;
f_odd[3*N+n] = 0.0277777777777778; //double(100*n)+7.f;
f_even[4*N+n] = 0.0277777777777778; //double(100*n)+8.f;
f_odd[4*N+n] = 0.0277777777777778; //double(100*n)+9.f;
f_even[5*N+n] = 0.0277777777777778; //double(100*n)+10.f;
f_odd[5*N+n] = 0.0277777777777778; //double(100*n)+11.f;
f_even[6*N+n] = 0.0277777777777778; //double(100*n)+12.f;
f_odd[6*N+n] = 0.0277777777777778; //double(100*n)+13.f;
f_even[7*N+n] = 0.0277777777777778; //double(100*n)+14.f;
f_odd[7*N+n] = 0.0277777777777778; //double(100*n)+15.f;
f_even[8*N+n] = 0.0277777777777778; //double(100*n)+16.f;
f_odd[8*N+n] = 0.0277777777777778; //double(100*n)+17.f;
f_even[9*N+n] = 0.0277777777777778; //double(100*n)+18.f;
}
else{
for(int q=0; q<9; q++){
f_even[q*N+n] = -1.0;
f_odd[q*N+n] = -1.0;
}
f_even[9*N+n] = -1.0;
}
}
}
//************************************************************************* //*************************************************************************
extern void SwapD3Q19(char *ID, double *disteven, double *distodd, int Nx, int Ny, int Nz) extern "C" void dvc_SwapD3Q19(char *ID, double *disteven, double *distodd, int Nx, int Ny, int Nz, int S)
{ {
int n,nn,N; int n,nn,N;
// distributions // distributions

View File

@@ -1,6 +1,6 @@
extern "C" void dvc_PackDist(int q, int *list, int start, int count, double *sendbuf, double *dist, int N);
extern void PackDist(int q, int *list, int start, int count, double *sendbuf, double *dist, int N); extern "C" void dvc_UnpackDist(int q, int Cqx, int Cqy, int Cqz, int *list, int start, int count,
extern void MapRecvDist(int q, int Cqx, int Cqy, int Cqz, int *list, int start, int count,
double *recvbuf, double *dist, int Nx, int Ny, int Nz); double *recvbuf, double *dist, int Nx, int Ny, int Nz);
//************************************************************************* //*************************************************************************
extern void SwapD3Q19(char *ID, double *disteven, double *distodd, int Nx, int Ny, int Nz); extern "C" void dvc_InitD3Q19(char *ID, double *f_even, double *f_odd, int Nx, int Ny, int Nz, int S);
extern "C" void dvc_SwapD3Q19(char *ID, double *disteven, double *distodd, int Nx, int Ny, int Nz, int S);

View File

@@ -1,6 +1,6 @@
// GPU Functions for D3Q7 Lattice Boltzmann Methods // CPU Functions for D3Q7 Lattice Boltzmann Methods
extern void PackValues(int *list, int count, double *sendbuf, double *Data, int N){ extern "C" void dvc_PackValues(int *list, int count, double *sendbuf, double *Data, int N){
//.................................................................................... //....................................................................................
// Pack distribution q into the send buffer for the listed lattice sites // Pack distribution q into the send buffer for the listed lattice sites
// dist may be even or odd distributions stored by stream layout // dist may be even or odd distributions stored by stream layout
@@ -11,7 +11,7 @@ extern void PackValues(int *list, int count, double *sendbuf, double *Data, int
sendbuf[idx] = Data[n]; sendbuf[idx] = Data[n];
} }
} }
extern void UnpackValues(int *list, int count, double *recvbuf, double *Data, int N){ extern "C" void dvc_UnpackValues(int *list, int count, double *recvbuf, double *Data, int N){
//.................................................................................... //....................................................................................
// Pack distribution q into the send buffer for the listed lattice sites // Pack distribution q into the send buffer for the listed lattice sites
// dist may be even or odd distributions stored by stream layout // dist may be even or odd distributions stored by stream layout
@@ -23,7 +23,7 @@ extern void UnpackValues(int *list, int count, double *recvbuf, double *Data, in
} }
} }
extern void PackDenD3Q7(int *list, int count, double *sendbuf, int number, double *Data, int N){ extern "C" void dvc_PackDenD3Q7(int *list, int count, double *sendbuf, int number, double *Data, int N){
//.................................................................................... //....................................................................................
// Pack distribution into the send buffer for the listed lattice sites // Pack distribution into the send buffer for the listed lattice sites
//.................................................................................... //....................................................................................
@@ -38,7 +38,7 @@ extern void PackDenD3Q7(int *list, int count, double *sendbuf, int number, doubl
} }
extern void UnpackDenD3Q7(int *list, int count, double *recvbuf, int number, double *Data, int N){ extern "C" void dvc_UnpackDenD3Q7(int *list, int count, double *recvbuf, int number, double *Data, int N){
//.................................................................................... //....................................................................................
// Unack distribution from the recv buffer // Unack distribution from the recv buffer
// Sum to the existing density value // Sum to the existing density value

View File

@@ -1,9 +1,9 @@
// CPU Functions for D3Q7 Lattice Boltzmann Methods // CPU Functions for D3Q7 Lattice Boltzmann Methods
extern void PackValues(int *list, int count, double *sendbuf, double *Data, int N); extern "C" void dvc_PackValues(int *list, int count, double *sendbuf, double *Data, int N);
extern void UnpackValues(int *list, int count, double *recvbuf, double *Data, int N); extern "C" void dvc_UnpackValues(int *list, int count, double *recvbuf, double *Data, int N);
extern void PackDenD3Q7(int *list, int count, double *sendbuf, int number, double *Data, int N); extern "C" void dvc_PackDenD3Q7(int *list, int count, double *sendbuf, int number, double *Data, int N);
extern void UnpackDenD3Q7(int *list, int count, double *recvbuf, int number, double *Data, int N); extern "C" void dvc_UnpackDenD3Q7(int *list, int count, double *recvbuf, int number, double *Data, int N);

28
cpu/Extras.cpp Normal file
View File

@@ -0,0 +1,28 @@
// Basic cuda functions callable from C/C++ code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
extern "C" void dvc_AllocateDeviceMemory(void** address, size_t size){
//cudaMalloc(address,size);
(*address) = malloc(size);
if (*address==NULL){
printf("Memory allocation failed! \n");
}
}
extern "C" void dvc_CopyToDevice(void* dest, void* source, size_t size){
// cudaMemcpy(dest,source,size,cudaMemcpyHostToDevice);
memcpy(dest, source, size);
}
extern "C" void dvc_CopyToHost(void* dest, void* source, size_t size){
// cudaMemcpy(dest,source,size,cudaMemcpyDeviceToHost);
memcpy(dest, source, size);
}
extern "C" void dvc_Barrier(){
// cudaDeviceSynchronize();
}

7
cpu/Extras.h Normal file
View File

@@ -0,0 +1,7 @@
extern "C" void dvc_AllocateDeviceMemory(void** address, size_t size);
extern "C" void dvc_CopyToDevice(void* dest, void* source, size_t size);
extern "C" void dvc_CopyToHost(void* dest, void* source, size_t size);
extern "C" void dvc_Barrier();

2447
cpu/lb2_Color_wia_mpi.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -312,14 +312,14 @@ double DoubleArray::e(int i, int j, int k)
extern DoubleArray IncreaseSize(DoubleArray &A, int addLength) extern DoubleArray IncreaseSize(DoubleArray &A, int addLength)
{ {
if (addLength<0) { if (addLength<0) {
printf("IncreaseSize(Array,Length)","Length needs to be >0."); printf("IncreaseSize(Array,Length) Length needs to be >0.");
return DoubleArray(); return DoubleArray();
} }
int newM,newN,newO; int newM,newN,newO;
if (A.o>1) { if (A.o>1) {
if (addLength%(A.m*A.n)!=0) { if (addLength%(A.m*A.n)!=0) {
printf("IncreaseSize(Array,Length)","Length needs to be a multiple of m*n"); printf("IncreaseSize(Array,Length) Length needs to be a multiple of m*n");
return DoubleArray(); return DoubleArray();
} }
newM = A.m; newM = A.m;
@@ -328,7 +328,7 @@ extern DoubleArray IncreaseSize(DoubleArray &A, int addLength)
} }
else if (A.n>1) { else if (A.n>1) {
if (addLength%(A.m)!=0) { if (addLength%(A.m)!=0) {
printf("IncreaseSize(Array,Length)","Length needs to be a multiple of m"); printf("IncreaseSize(Array,Length) Length needs to be a multiple of m");
return DoubleArray(); return DoubleArray();
} }
newM = A.m; newM = A.m;
@@ -348,14 +348,14 @@ extern DoubleArray IncreaseSize(DoubleArray &A, int addLength)
extern IntArray IncreaseSize(IntArray &A, int addLength) extern IntArray IncreaseSize(IntArray &A, int addLength)
{ {
if (addLength<0) { if (addLength<0) {
printf("IncreaseSize(Array,Length)","Length needs to be >0."); printf("IncreaseSize(Array,Length) Length needs to be >0.");
return IntArray(); return IntArray();
} }
int newM,newN,newO; int newM,newN,newO;
if (A.o>1) { if (A.o>1) {
if (addLength%(A.m*A.n)!=0) { if (addLength%(A.m*A.n)!=0) {
printf("IncreaseSize(Array,Length)","Length needs to be a multiple of m*n"); printf("IncreaseSize(Array,Length) Length needs to be a multiple of m*n");
return IntArray(); return IntArray();
} }
newM = A.m; newM = A.m;
@@ -364,7 +364,7 @@ extern IntArray IncreaseSize(IntArray &A, int addLength)
} }
else if (A.n>1) { else if (A.n>1) {
if (addLength%(A.m)!=0) { if (addLength%(A.m)!=0) {
printf("IncreaseSize(Array,Length)","Length needs to be a multiple of m"); printf("IncreaseSize(Array,Length) Length needs to be a multiple of m");
return IntArray(); return IntArray();
} }
newM = A.m; newM = A.m;

View File

@@ -399,3 +399,18 @@ inline void ReadCheckpoint(char *FILENAME, double *cDen, double *cDistEven, doub
} }
File.close(); File.close();
} }
inline void ReadBinaryFile(char *FILENAME, double *Data, int N)
{
int n;
double value;
ifstream File(FILENAME,ios::binary);
for (n=0; n<N; n++){
// Write the two density values
File.read((char*) &value, sizeof(value));
Data[n] = value;
}
File.close();
}

View File

@@ -3402,15 +3402,24 @@ inline void pmmc_MeshCurvature(DoubleArray &f, DoubleArray &MeanCurvature, Doubl
fyz = 0.25*(f(i,j+1,k+1) - f(i,j+1,k-1) - f(i,j-1,k+1) + f(i,j-1,k-1)); fyz = 0.25*(f(i,j+1,k+1) - f(i,j+1,k-1) - f(i,j-1,k+1) + f(i,j-1,k-1));
// Evaluate the Mean Curvature // Evaluate the Mean Curvature
denominator = pow(sqrt(fx*fx + fy*fy + fz*fz),3); denominator = pow(sqrt(fx*fx + fy*fy + fz*fz),3);
if (denominator == 0.0) denominator = 1.0; if (denominator == 0.0){
MeanCurvature(i,j,k)=(1.0/denominator)*((fyy+fzz)*fx*fx + (fxx+fzz)*fy*fy + (fxx+fyy)*fz*fz MeanCurvature(i,j,k) = 0.0;
-2.0*fx*fy*fxy - 2.0*fx*fz*fxz - 2.0*fy*fz*fyz); }
else{
MeanCurvature(i,j,k)=(1.0/denominator)*((fyy+fzz)*fx*fx + (fxx+fzz)*fy*fy + (fxx+fyy)*fz*fz
-2.0*fx*fy*fxy - 2.0*fx*fz*fxz - 2.0*fy*fz*fyz);
}
// Evaluate the Gaussian Curvature // Evaluate the Gaussian Curvature
denominator = pow(fx*fx + fy*fy + fz*fz,2); denominator = pow(fx*fx + fy*fy + fz*fz,2);
if (denominator == 0.0) denominator = 1.0; if (denominator == 0.0){
GaussCurvature(i,j,k) = (1.0/denominator)*(fx*fx*(fyy*fzz-fyz*fyz) + fy*fy*(fxx*fzz-fxz*fxz) + fz*fz*(fxx*fyy-fxy*fxy) GaussCurvature(i,j,k) = 0.0;
+2.0*(fx*fy*(fxz*fyz-fxy*fzz) + fy*fz*(fxy*fxz-fyz*fxx) }
+ fx*fz*(fxy*fyz-fxz*fyy))); else{
GaussCurvature(i,j,k) = (1.0/denominator)*(fx*fx*(fyy*fzz-fyz*fyz) + fy*fy*(fxx*fzz-fxz*fxz) + fz*fz*(fxx*fyy-fxy*fxy)
+2.0*(fx*fy*(fxz*fyz-fxy*fzz) + fy*fz*(fxy*fxz-fyz*fxx)
+ fx*fz*(fxy*fyz-fxz*fyy)));
}
} }
} }
} }
@@ -3831,13 +3840,14 @@ inline void pmmc_InterfaceSpeed(DoubleArray &dPdt, DoubleArray &P_x, DoubleArray
Point A,B,C; Point A,B,C;
int p; int p;
double vA,vB,vC; double vA,vB,vC;
double vAx,vBx,vCx,vAy,vBy,vCy,vAz,vBz,vCz;
double x,y,z; double x,y,z;
double s,s1,s2,s3,temp; double s,s1,s2,s3,temp;
double a,b,c,d,e,f,g,h; double a,b,c,d,e,f,g,h;
double norm, zeta; double norm, zeta;
// ................x component ............................. // ................x component .............................
// Copy the curvature values for the cube // Copy the x derivative values for the cube
CubeValues(0,0,0) = P_x(i,j,k); CubeValues(0,0,0) = P_x(i,j,k);
CubeValues(1,0,0) = P_x(i+1,j,k); CubeValues(1,0,0) = P_x(i+1,j,k);
CubeValues(0,1,0) = P_x(i,j+1,k); CubeValues(0,1,0) = P_x(i,j+1,k);
@@ -3866,7 +3876,7 @@ inline void pmmc_InterfaceSpeed(DoubleArray &dPdt, DoubleArray &P_x, DoubleArray
} }
// ................y component ............................. // ................y component .............................
// Copy the curvature values for the cube // Copy the y derivative values for the cube
CubeValues(0,0,0) = P_y(i,j,k); CubeValues(0,0,0) = P_y(i,j,k);
CubeValues(1,0,0) = P_y(i+1,j,k); CubeValues(1,0,0) = P_y(i+1,j,k);
CubeValues(0,1,0) = P_y(i,j+1,k); CubeValues(0,1,0) = P_y(i,j+1,k);
@@ -3895,7 +3905,7 @@ inline void pmmc_InterfaceSpeed(DoubleArray &dPdt, DoubleArray &P_x, DoubleArray
} }
// ................z component ............................. // ................z component .............................
// Copy the curvature values for the cube // Copy the z derivative values for the cube
CubeValues(0,0,0) = P_z(i,j,k); CubeValues(0,0,0) = P_z(i,j,k);
CubeValues(1,0,0) = P_z(i+1,j,k); CubeValues(1,0,0) = P_z(i+1,j,k);
CubeValues(0,1,0) = P_z(i,j+1,k); CubeValues(0,1,0) = P_z(i,j+1,k);
@@ -3983,22 +3993,43 @@ inline void pmmc_InterfaceSpeed(DoubleArray &dPdt, DoubleArray &P_x, DoubleArray
s = 0.5*(s1+s2+s3); s = 0.5*(s1+s2+s3);
temp = s*(s-s1)*(s-s2)*(s-s3); temp = s*(s-s1)*(s-s2)*(s-s3);
if (temp > 0.0){ if (temp > 0.0){
// Surface value (speed)
vA = SurfaceValues(Triangles(0,r));
vB = SurfaceValues(Triangles(1,r));
vC = SurfaceValues(Triangles(2,r));
// Increment the averaged values // Increment the averaged values
// x component // x component
vA = SurfaceVector(Triangles(0,r))*SurfaceValues(Triangles(0,r)); vAx = SurfaceVector(Triangles(0,r))*vA;
vB = SurfaceVector(Triangles(1,r))*SurfaceValues(Triangles(1,r)); vBx = SurfaceVector(Triangles(1,r))*vB;
vC = SurfaceVector(Triangles(2,r))*SurfaceValues(Triangles(2,r)); vCx = SurfaceVector(Triangles(2,r))*vC;
AvgVel(0) += sqrt(temp)*0.33333333333333333*(vA+vB+vC);
// y component // y component
vA = SurfaceVector(npts+Triangles(0,r))*SurfaceValues(Triangles(0,r)); vAy = SurfaceVector(npts+Triangles(0,r))*vA;
vB = SurfaceVector(npts+Triangles(1,r))*SurfaceValues(Triangles(1,r)); vBy = SurfaceVector(npts+Triangles(1,r))*vB;
vC = SurfaceVector(npts+Triangles(2,r))*SurfaceValues(Triangles(2,r)); vCy = SurfaceVector(npts+Triangles(2,r))*vC;
AvgVel(1) += sqrt(temp)*0.33333333333333333*(vA+vB+vC);
// z component // z component
vA = SurfaceVector(2*npts+Triangles(0,r))*SurfaceValues(Triangles(0,r)); vAz = SurfaceVector(2*npts+Triangles(0,r))*vA;
vB = SurfaceVector(2*npts+Triangles(1,r))*SurfaceValues(Triangles(1,r)); vBz = SurfaceVector(2*npts+Triangles(1,r))*vB;
vC = SurfaceVector(2*npts+Triangles(2,r))*SurfaceValues(Triangles(2,r)); vCz = SurfaceVector(2*npts+Triangles(2,r))*vC;
AvgVel(2) += sqrt(temp)*0.33333333333333333*(vA+vB+vC);
AvgVel(0) += sqrt(temp)*0.33333333333333333*(vAx+vBx+vCx);
AvgVel(1) += sqrt(temp)*0.33333333333333333*(vAy+vBy+vCy);
AvgVel(2) += sqrt(temp)*0.33333333333333333*(vAz+vBz+vCz);
// Update the Averages. Differentiate between advancing (0,1,2) and receding (3,4,5) interfaces
// All points on a triangle have the same orientation in the color gradient
/* if (vA > 0.0){
// Advancing interface
AvgVel(0) += sqrt(temp)*0.33333333333333333*(vAx+vBx+vCx);
AvgVel(1) += sqrt(temp)*0.33333333333333333*(vAy+vBy+vCy);
AvgVel(2) += sqrt(temp)*0.33333333333333333*(vAz+vBz+vCz);
}
else{
// Receding interface
AvgVel(3) += sqrt(temp)*0.33333333333333333*(vAx+vBx+vCx);
AvgVel(4) += sqrt(temp)*0.33333333333333333*(vAy+vBy+vCy);
AvgVel(5) += sqrt(temp)*0.33333333333333333*(vAz+vBz+vCz);
}
*/
} }
} }
//............................................................................. //.............................................................................

View File

@@ -15,12 +15,17 @@ int main(int argc, char **argv)
{ {
//....................................................................... //.......................................................................
// printf("Radius = %s \n,"RADIUS); // printf("Radius = %s \n,"RADIUS);
int Nx,Ny,Nz; int Nx,Ny,Nz,N;
int i,j,k,p,q,r,n; int i,j,k,p,q,r,n;
int nspheres; int nspheres;
double Lx,Ly,Lz; double Lx,Ly,Lz;
//....................................................................... //.......................................................................
Nx = Ny = Nz = 60; Nx = Ny = Nz = 60;
cout << "Enter Domain size " << endl;
cout << "Nx = " << endl;
cin >> Nx;
Ny = Nz = Nx;
N = Nx*Ny*Nz;
//....................................................................... //.......................................................................
// Reading the domain information file // Reading the domain information file
/* //....................................................................... /* //.......................................................................
@@ -129,6 +134,8 @@ int main(int argc, char **argv)
DoubleArray Gns(6); DoubleArray Gns(6);
DoubleArray Gws(6); DoubleArray Gws(6);
double iVol = 1.0/Nx/Ny/Nz;
int c; int c;
//........................................................................... //...........................................................................
int ncubes = (Nx-2)*(Ny-2)*(Nz-2); // Exclude the "upper" halo int ncubes = (Nx-2)*(Ny-2)*(Nz-2); // Exclude the "upper" halo
@@ -159,8 +166,8 @@ int main(int argc, char **argv)
dist1 = sqrt((i-Cx)*(i-Cx)+(j-Cy)*(j-Cy)) - RADIUS; dist1 = sqrt((i-Cx)*(i-Cx)+(j-Cy)*(j-Cy)) - RADIUS;
dist2 = sqrt((i-Cx)*(i-Cx)+(j-Cy)*(j-Cy)+(k-Cz)*(k-Cz)) - CAPRAD; dist2 = sqrt((i-Cx)*(i-Cx)+(j-Cy)*(j-Cy)+(k-Cz)*(k-Cz)) - CAPRAD;
SignDist(i,j,k) = -dist1; //SignDist(i,j,k) = -dist1;
Phase(i,j,k) = dist2; //Phase(i,j,k) = dist2;
} }
} }
} }
@@ -175,7 +182,41 @@ int main(int argc, char **argv)
} }
} }
//........................................................................... awn = aws = ans = lwns = 0.0;
nwp_volume = 0.0;
As = 0.0;
Jwn = 0.0;
efawns = 0.0;
// Compute phase averages
pan = paw = 0.0;
vaw(0) = vaw(1) = vaw(2) = 0.0;
van(0) = van(1) = van(2) = 0.0;
vawn(0) = vawn(1) = vawn(2) = 0.0;
Gwn(0) = Gwn(1) = Gwn(2) = 0.0;
Gwn(3) = Gwn(4) = Gwn(5) = 0.0;
Gws(0) = Gws(1) = Gws(2) = 0.0;
Gws(3) = Gws(4) = Gws(5) = 0.0;
Gns(0) = Gns(1) = Gns(2) = 0.0;
Gns(3) = Gns(4) = Gns(5) = 0.0;
vol_w = vol_n =0.0;
// Read the input files for the phase, distance and pressure field
char PHASEFILE[16];
sprintf(PHASEFILE,"Phase.in");
ReadBinaryFile(PHASEFILE,Phase.data,Nx*Ny*Nz);
char DISTFILE[16];
sprintf(DISTFILE,"SignDist.in");
ReadBinaryFile(DISTFILE,SignDist.data,Nx*Ny*Nz);
/* FILE *PRESS
PRESS = fopen("Pressure.in","wb");
fread(Phase.data,8,N,PRESS);
fclose(PRESS);
FILE *VEL;
VEL = fopen("Pressure.in","wb");
fread(Phase.data,8,3*N,VEL);
fclose(VEL);
*/ //...........................................................................
// Calculate the time derivative of the phase indicator field // Calculate the time derivative of the phase indicator field
for (int n=0; n<Nx*Ny*Nz; n++) dPdt(n) = 0.5*(Phase_tplus(n) - Phase_tminus(n)); for (int n=0; n<Nx*Ny*Nz; n++) dPdt(n) = 0.5*(Phase_tplus(n) - Phase_tminus(n));
@@ -237,6 +278,18 @@ int main(int argc, char **argv)
vol_w = vol_n =0.0; vol_w = vol_n =0.0;
FILE *WN_TRIS;
WN_TRIS = fopen("wn-tris.out","w");
FILE *NS_TRIS;
NS_TRIS = fopen("ns-tris.out","w");
FILE *WS_TRIS;
WS_TRIS = fopen("ws-tris.out","w");
FILE *WNS_PTS;
WNS_PTS = fopen("wns-pts.out","w");
for (c=0;c<ncubes;c++){ for (c=0;c<ncubes;c++){
// Get cube from the list // Get cube from the list
i = cubeList(0,c); i = cubeList(0,c);
@@ -262,6 +315,10 @@ int main(int argc, char **argv)
pmmc_InterfaceSpeed(dPdt, Phase_x, Phase_y, Phase_z, CubeValues, nw_pts, nw_tris, pmmc_InterfaceSpeed(dPdt, Phase_x, Phase_y, Phase_z, CubeValues, nw_pts, nw_tris,
NormalVector, InterfaceSpeed, vawn, i, j, k, n_nw_pts, n_nw_tris); NormalVector, InterfaceSpeed, vawn, i, j, k, n_nw_pts, n_nw_tris);
// pmmc_InterfaceSpeed(dPdt, Phase_x, Phase_y, Phase_z, CubeValues, nw_pts, nw_tris,
// NormalVector, InterfaceSpeed, vawn, i, j, k, n_nw_pts, n_nw_tris);
// Compute the average contact angle // Compute the average contact angle
efawns += pmmc_CubeContactAngle(CubeValues,ContactAngle,Phase_x,Phase_y,Phase_z,Sx,Sy,Sz, efawns += pmmc_CubeContactAngle(CubeValues,ContactAngle,Phase_x,Phase_y,Phase_z,Sx,Sy,Sz,
local_nws_pts,i,j,k,n_local_nws_pts); local_nws_pts,i,j,k,n_local_nws_pts);
@@ -282,8 +339,44 @@ int main(int argc, char **argv)
// aws += pmmc_CubeSurfaceArea(ws_pts,ws_tris,n_ws_tris); // aws += pmmc_CubeSurfaceArea(ws_pts,ws_tris,n_ws_tris);
As += pmmc_CubeSurfaceArea(local_sol_pts,local_sol_tris,n_local_sol_tris); As += pmmc_CubeSurfaceArea(local_sol_pts,local_sol_tris,n_local_sol_tris);
lwns += pmmc_CubeCurveLength(local_nws_pts,n_local_nws_pts); lwns += pmmc_CubeCurveLength(local_nws_pts,n_local_nws_pts);
//.......................................................................................
// Write the triangle lists to text file
for (r=0;r<n_nw_tris;r++){
A = nw_pts(nw_tris(0,r));
B = nw_pts(nw_tris(1,r));
C = nw_pts(nw_tris(2,r));
fprintf(WN_TRIS,"%f %f %f %f %f %f %f %f %f \n",A.x,A.y,A.z,B.x,B.y,B.z,C.x,C.y,C.z);
}
for (r=0;r<n_ws_tris;r++){
A = ws_pts(ws_tris(0,r));
B = ws_pts(ws_tris(1,r));
C = ws_pts(ws_tris(2,r));
fprintf(WS_TRIS,"%f %f %f %f %f %f %f %f %f \n",A.x,A.y,A.z,B.x,B.y,B.z,C.x,C.y,C.z);
}
for (r=0;r<n_ns_tris;r++){
A = ns_pts(ns_tris(0,r));
B = ns_pts(ns_tris(1,r));
C = ns_pts(ns_tris(2,r));
fprintf(NS_TRIS,"%f %f %f %f %f %f %f %f %f \n",A.x,A.y,A.z,B.x,B.y,B.z,C.x,C.y,C.z);
}
for (p=0; p < n_nws_pts; p++){
P = nws_pts(p);
fprintf(WNS_PTS,"%f %f %f \n",P.x, P.y, P.z);
}
} }
fclose(WN_TRIS);
fclose(NS_TRIS);
fclose(WS_TRIS);
fclose(WNS_PTS);
printf("Jwn = %f \n",Jwn);
printf("awn = %f \n",awn);
printf("efawns = %f \n",efawns);
printf("lwns = %f \n",lwns);
printf("efawns = %f \n",efawns/lwns);
Jwn /= awn; Jwn /= awn;
efawns /= lwns; efawns /= lwns;
for (i=0; i<3; i++) vawn(i) /= awn; for (i=0; i<3; i++) vawn(i) /= awn;
@@ -291,6 +384,11 @@ int main(int argc, char **argv)
for (i=0; i<6; i++) Gns(i) /= ans; for (i=0; i<6; i++) Gns(i) /= ans;
for (i=0; i<6; i++) Gws(i) /= aws; for (i=0; i<6; i++) Gws(i) /= aws;
awn = awn*iVol;
aws = aws*iVol;
ans = ans*iVol;
lwns = lwns*iVol;
printf("--------------------------------------------------------------------------------------\n"); printf("--------------------------------------------------------------------------------------\n");
printf("sw pw pn vw[x, y, z] vn[x, y, z] "); // Volume averages printf("sw pw pn vw[x, y, z] vn[x, y, z] "); // Volume averages
printf("awn ans aws Jwn vwn[x, y, z] lwns efawns "); // Interface and common curve averages printf("awn ans aws Jwn vwn[x, y, z] lwns efawns "); // Interface and common curve averages
@@ -303,12 +401,13 @@ int main(int argc, char **argv)
printf("%.5g %.5g %.5g ",van(0),van(1),van(2)); // average velocity of n phase printf("%.5g %.5g %.5g ",van(0),van(1),van(2)); // average velocity of n phase
printf("%.5g %.5g %.5g ",awn,ans,aws); // interfacial areas printf("%.5g %.5g %.5g ",awn,ans,aws); // interfacial areas
printf("%.5g ",Jwn); // curvature of wn interface printf("%.5g ",Jwn); // curvature of wn interface
printf("%.5g %.5g %.5g ",vawn(0),vawn(1),vawn(2)); // velocity of wn interface printf("%.5g ", lwns); // common curve length
printf("%.5g ",efawns); // average contact angle
printf("%.5g %.5g %.5g %.5g %.5g %.5g ", printf("%.5g %.5g %.5g %.5g %.5g %.5g ",
Gwn(0),Gwn(1),Gwn(2),Gwn(3),Gwn(4),Gwn(5)); // orientation of wn interface Gwn(0),Gwn(1),Gwn(2),Gwn(3),Gwn(4),Gwn(5)); // orientation of wn interface
printf("%.5g %.5g %.5g %.5g %.5g %.5g ", printf("%.5g %.5g %.5g %.5g %.5g %.5g ",
Gns(0),Gns(1),Gns(2),Gns(3),Gns(4),Gns(5)); // orientation of ns interface Gns(0),Gns(1),Gns(2),Gns(3),Gns(4),Gns(5)); // orientation of ns interface
printf("%.5g %.5g %.5g %.5g %.5g %.5g ", printf("%.5g %.5g %.5g %.5g %.5g %.5g \n",
Gws(0),Gws(1),Gws(2),Gws(3),Gws(4),Gws(5)); // orientation of ws interface Gws(0),Gws(1),Gws(2),Gws(3),Gws(4),Gws(5)); // orientation of ws interface
@@ -319,19 +418,19 @@ int main(int argc, char **argv)
printf("Area ws = %f, Analytical = %f \n", aws, 4*PI*RADIUS*HEIGHT); printf("Area ws = %f, Analytical = %f \n", aws, 4*PI*RADIUS*HEIGHT);
printf("Area s = %f, Analytical = %f \n", As, 2*PI*RADIUS*(N-2)); printf("Area s = %f, Analytical = %f \n", As, 2*PI*RADIUS*(N-2));
printf("Length wns = %f, Analytical = %f \n", lwns, 4*PI*RADIUS); printf("Length wns = %f, Analytical = %f \n", lwns, 4*PI*RADIUS);
// printf("Cos(theta_wns) = %f, Analytical = %f \n",efawns/lwns,1.0*RADIUS/CAPRAD); // printf("Cos(theta_wns) = %f, Analytical = %f \n",efawns/lwns,1.0*RADIUS/CAPRAD);
printf("Interface Velocity = %f,%f,%f \n",vawn(0)/awn,vawn(1)/awn,vawn(2)/awn); printf("Interface Velocity = %f,%f,%f \n",vawn(0)/awn,vawn(1)/awn,vawn(2)/awn);
printf("-------------------------------- \n"); printf("-------------------------------- \n");
//......................................................................... //.........................................................................
*/
FILE *PHASE; FILE *PHASE;
PHASE = fopen("Phase.in","wb"); PHASE = fopen("Phase.out","wb");
fwrite(Phase,8,SIZE,PHASE); fwrite(Phase.data,8,N,PHASE);
fclose(PHASE); fclose(PHASE);
FILE *SOLID; FILE *SOLID;
SOLID = fopen("Distance.in","wb"); SOLID = fopen("Distance.out","wb");
fwrite(Solid,8,SIZE,SOLID); fwrite(SignDist.data,8,N,SOLID);
fclose(SOLID); fclose(SOLID);
*/
} }

View File

@@ -153,10 +153,8 @@ int main (int argc, char *argv[])
aws += pmmc_CubeSurfaceArea(ws_pts,ws_tris,n_ws_tris); aws += pmmc_CubeSurfaceArea(ws_pts,ws_tris,n_ws_tris);
As += pmmc_CubeSurfaceArea(local_sol_pts,local_sol_tris,n_local_sol_tris); As += pmmc_CubeSurfaceArea(local_sol_pts,local_sol_tris,n_local_sol_tris);
lwns += pmmc_CubeCurveLength(local_nws_pts,n_local_nws_pts); lwns += pmmc_CubeCurveLength(local_nws_pts,n_local_nws_pts);
} }
printf("-------------------------------- \n"); printf("-------------------------------- \n");
printf("NWP volume = %f \n", nwp_volume); printf("NWP volume = %f \n", nwp_volume);
printf("Area wn = %f, Analytical = %f \n", awn,2*PI*RADIUS*RADIUS); printf("Area wn = %f, Analytical = %f \n", awn,2*PI*RADIUS*RADIUS);

View File

@@ -8,7 +8,7 @@
#define CAPRAD 20 #define CAPRAD 20
#define HEIGHT 15.5 #define HEIGHT 15.5
#define N 60 #define N 60
#define SPEED 1 #define SPEED -1
#define PI 3.14159 #define PI 3.14159
int main (int argc, char *argv[]) int main (int argc, char *argv[])
@@ -45,7 +45,7 @@ int main (int argc, char *argv[])
// Averaging variables // Averaging variables
//........................................................................... //...........................................................................
double awn,ans,aws,lwns,nwp_volume; double awn,ans,aws,lwns,nwp_volume;
double efawns; double efawns,Jwn;
double As; double As;
double dEs,dAwn,dAns; // Global surface energy (calculated by rank=0) double dEs,dAwn,dAns; // Global surface energy (calculated by rank=0)
double awn_global,ans_global,aws_global,lwns_global,nwp_volume_global; double awn_global,ans_global,aws_global,lwns_global,nwp_volume_global;
@@ -87,9 +87,10 @@ int main (int argc, char *argv[])
DoubleArray CubeValues(2,2,2); DoubleArray CubeValues(2,2,2);
DoubleArray ContactAngle(20); DoubleArray ContactAngle(20);
DoubleArray wn_curvature(20);
DoubleArray InterfaceSpeed(20); DoubleArray InterfaceSpeed(20);
DoubleArray NormalVector(60); DoubleArray NormalVector(60);
DoubleArray vawn(3); DoubleArray vawn(6);
int c; int c;
//........................................................................... //...........................................................................
@@ -212,9 +213,7 @@ int main (int argc, char *argv[])
Jwn /= awn; Jwn /= awn;
efawns /= lwns; efawns /= lwns;
vawn(0) /= awn; for (i=0;i<6;i++) vawn(i) /= awn;
vawn(1) /= awn;
vawn(2) /= awn;
printf("-------------------------------- \n"); printf("-------------------------------- \n");
printf("NWP volume = %f \n", nwp_volume); printf("NWP volume = %f \n", nwp_volume);
@@ -224,7 +223,8 @@ int main (int argc, char *argv[])
printf("Area s = %f, Analytical = %f \n", As, 2*PI*RADIUS*(N-2)); printf("Area s = %f, Analytical = %f \n", As, 2*PI*RADIUS*(N-2));
printf("Length wns = %f, Analytical = %f \n", lwns, 4*PI*RADIUS); printf("Length wns = %f, Analytical = %f \n", lwns, 4*PI*RADIUS);
// printf("Cos(theta_wns) = %f, Analytical = %f \n",efawns/lwns,1.0*RADIUS/CAPRAD); // printf("Cos(theta_wns) = %f, Analytical = %f \n",efawns/lwns,1.0*RADIUS/CAPRAD);
printf("Interface Velocity = %f,%f,%f \n",vawn(0)/awn,vawn(1)/awn,vawn(2)/awn); printf("Advancing Interface Velocity = %f,%f,%f \n",vawn(0),vawn(1),vawn(2));
printf("Receding Interface Velocity = %f,%f,%f \n",vawn(3),vawn(4),vawn(5));
printf("-------------------------------- \n"); printf("-------------------------------- \n");
//......................................................................... //.........................................................................