Files
LBPM/tests/TestSphereCurvature.cpp

74 lines
2.0 KiB
C++
Raw Normal View History

2013-11-25 16:08:49 -05:00
#include <iostream>
#include <math.h>
2018-09-09 23:54:45 -04:00
#include "analysis/Minkowski.h"
#include "common/Domain.h"
2018-05-16 10:16:11 -04:00
#include "common/SpherePack.h"
2013-11-25 16:08:49 -05:00
using namespace std;
/*
* Compare the measured and analytical curvature for a sphere
*
*/
int main(int argc, char **argv)
{
2013-11-27 16:41:37 -05:00
int i,j,k;
int Nx,Ny,Nz;
2013-11-25 16:08:49 -05:00
double Lx,Ly,Lz;
2013-11-27 16:41:37 -05:00
double fluid_isovalue=0.0;
double solid_isovalue=0.0;
2013-11-25 16:08:49 -05:00
Lx = Ly = Lz = 1.0;
2018-09-10 11:39:16 -04:00
Nx = Ny = Nz = 64;
2013-11-27 16:41:37 -05:00
DoubleArray Phase(Nx,Ny,Nz);
DoubleArray CubeValues(2,2,2);
2018-09-09 21:16:12 -04:00
2018-09-10 10:35:52 -04:00
printf("Set distance map \n");
2013-12-03 16:36:45 -05:00
for (k=0; k<Nz; k++){
for (j=0; j<Ny; j++){
for (i=0; i<Nx; i++){
Phase(i,j,k) = sqrt((1.0*i-0.5*Nx)*(1.0*i-0.5*Nx)+(1.0*j-0.5*Ny)*(1.0*j-0.5*Ny)+(1.0*k-0.5*Nz)*(1.0*k-0.5*Nz))-0.3*Nx;
}
}
}
2018-09-09 21:16:12 -04:00
2018-09-10 10:35:52 -04:00
printf("Construct local isosurface \n");
2018-09-09 21:16:12 -04:00
DECL sphere;
2018-09-10 17:46:03 -04:00
Point V1,V2,V3;
2018-09-10 17:43:12 -04:00
unsigned long int e1,e2,e3;
double s,s1,s2,s3;
double area = 0.f;
2018-09-09 21:16:12 -04:00
for (k=0; k<Nz-1; k++){
for (j=0; j<Ny-1; j++){
for (i=0; i<Nx-1; i++){
sphere.LocalIsosurface(Phase,0.f,i,j,k);
2018-09-10 17:29:48 -04:00
for (unsigned long int idx=0; idx<sphere.TriangleCount; idx++){
2018-09-10 17:43:12 -04:00
e1 = sphere.Face(idx);
e2 = sphere.halfedge.next(e1);
e3 = sphere.halfedge.next(e2);
2018-09-10 17:46:03 -04:00
V1 = sphere.vertex.coords(sphere.halfedge.v1(e1));
V2 = sphere.vertex.coords(sphere.halfedge.v1(e2));
V3 = sphere.vertex.coords(sphere.halfedge.v1(e3));
2018-09-10 17:43:12 -04:00
s1 = sqrt((V1.x-V2.x)*(V1.x-V2.x)+(V1.y-V2.y)*(V1.y-V2.y)+(V1.z-V2.z)*(V1.z-V2.z));
s2 = sqrt((V1.x-V3.x)*(V1.x-V3.x)+(V1.y-V3.y)*(V1.y-V3.y)+(V1.z-V3.z)*(V1.z-V3.z));
s3 = sqrt((V2.x-V3.x)*(V2.x-V3.x)+(V2.y-V3.y)*(V2.y-V3.y)+(V2.z-V3.z)*(V2.z-V3.z));
s = 0.5*(s1+s2+s3);
area += sqrt(s*(s-s1)*(s-s2)*(s-s3));
2018-09-10 17:29:48 -04:00
}
2018-09-09 21:16:12 -04:00
}
}
2013-11-27 16:41:37 -05:00
}
2013-11-25 16:08:49 -05:00
2018-09-10 17:43:12 -04:00
printf("Surface area = %f (analytical = %f) \n", area,4*3.14159*0.3*0.3*double(Nx*Nx));
// printf("Mean Curvature Average = %f, Analytical = %f \n", wn_curvature_sum/wn_area_sum, 2.0/rad[0]/101 );
2014-06-06 08:30:12 -04:00
int toReturn = 0;
2018-09-09 23:56:45 -04:00
/* if ( fabs(wn_curvature_sum/wn_area_sum -2.0/rad[0]/101)*rad[0]*101.0*0.5 > 0.01 ){
2014-06-06 08:30:12 -04:00
toReturn = 1;
printf("Mean curvature test error exceeds relative error tolerance \n ");
2014-06-06 08:30:12 -04:00
}
2018-09-09 23:56:45 -04:00
*/
2014-06-06 08:30:12 -04:00
return toReturn;
2013-11-25 16:08:49 -05:00
}