00001
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include "tetmesh.h"
00009 #include "bbox.h"
00010 #include "charm.h"
00011
00012 #if OSL_TETMESH_DEBUG
00013 void TetMesh::ct(int t) const {
00014 if (t<0 || t>=tet.size())
00015 CkAbort("TetMesh::ct> Tet index out of bounds");
00016 }
00017 void TetMesh::cp(int p) const {
00018 if (p<0 || p>=pts.size())
00019 CkAbort("TetMesh::cp> Point index out of bounds");
00020
00021 }
00022
00023 #endif
00024
00026 TetMesh::TetMesh() {
00027 }
00029 TetMesh::TetMesh(int nt,int np) {
00030 allocate(nt,np);
00031 }
00032 TetMesh::~TetMesh() {
00033 }
00034
00037 void TetMesh::allocate(int nt,int np) {
00038 tet.resize(nt);
00039 pts.resize(np);
00040 }
00041
00042
00043 CkVector3d *TetMesh::getPointArray(void) {
00044 return &(pts[0]);
00045 }
00046 const CkVector3d *TetMesh::getPointArray(void) const {
00047 return &(pts[0]);
00048 }
00049
00053 double tetVolume(const CkVector3d &A,const CkVector3d &B,
00054 const CkVector3d &C,const CkVector3d &D)
00055 {
00056 const static double oneSixth=1.0/6.0;
00057 return oneSixth*(B-A).dot((D-A).cross(C-A));
00058 }
00059
00060
00061 double TetMesh::getTetVolume(int s) const {
00062 const int *sc=getTet(s);
00063 return fabs(tetVolume(getPoint(sc[0]),getPoint(sc[1]),
00064 getPoint(sc[2]),getPoint(sc[3])));
00065 }
00066
00067
00068 double averageEdgeLength(const TetMesh &m) {
00069 double edgeSum=0;
00070 int nEdge=0;
00071 for (int t=0;t<m.getTets();t++) {
00072 const int *conn=m.getTet(t);
00073 typedef int edgeID[2];
00074 const int nID=6;
00075 const static edgeID edgeIDs[nID]={
00076 {0,1},{0,2},{0,3},{1,2},{2,3},{1,3}
00077 };
00078 for (int i=0;i<nID;i++)
00079 edgeSum+=m.getPoint(conn[edgeIDs[i][0]]).
00080 dist(m.getPoint(conn[edgeIDs[i][1]]));
00081 nEdge+=nID;
00082 }
00083 return edgeSum/nEdge;
00084 }
00085
00087 void print(const TetMesh &tet) {
00088 printSize(tet);
00089
00090 int maxT=20;
00091 int nTp=tet.getTets(); if (nTp>maxT) nTp=maxT;
00092 for (int t=0;t<nTp;t++) {
00093 const int *c=tet.getTet(t);
00094 printf(" tet %d: %d %d %d %d\n",t,
00095 c[0],c[1],c[2],c[3]);
00096 }
00097 if (nTp<tet.getTets()) printf(" <more tets>\n");
00098
00099 int maxP=20;
00100 int nPp=tet.getPoints(); if (nPp>maxP) nPp=maxP;
00101 for (int p=0;p<nPp;p++) {
00102 printf(" point %d: ",p);
00103 print(tet.getPoint(p));
00104 printf("\n");
00105 }
00106 if (nPp<tet.getPoints()) printf(" <more points>\n");
00107 }
00108
00110 void printSize(const TetMesh &tet) {
00111 printf("Tetrahedral mesh: %d tets, %d points\n",
00112 tet.getTets(),tet.getPoints());
00113 bbox3d box;box.empty();
00114 for (int p=0;p<tet.getPoints();p++)
00115 box.add(tet.getPoint(p));
00116 printf("Coordinate range: ");
00117
00118 printf("\n");
00119 }
00120
00122 void printTet(const TetMesh &m,int t) {
00123 const int *c=m.getTet(t);
00124 printf(" tet %d: %d %d %d %d\n",t,
00125 c[0],c[1],c[2],c[3]);
00126 for (int i=0;i<4;i++) print(m.getPoint(c[i]));
00127 printf("\n");
00128 }
00129
00130 void print(const CkVector3d &p) {
00131 printf(" (%.3f, %.3f, %.3f)",p.x,p.y,p.z);
00132 }