00001
00002 #include "mpi.h"
00003 #include "petsc.h"
00004 #include "sys.h"
00005 #include "TreeNode.h"
00006 #include "parUtils.h"
00007 #include "omg.h"
00008 #include "oda.h"
00009 #include "omgJac.h"
00010 #include "handleStencils.h"
00011 #include <cstdlib>
00012 #include "colors.h"
00013 #include "externVars.h"
00014 #include "dendro.h"
00015
00016 static char help[] = "FBM";
00017
00018
00019 #ifdef MPI_WTIME_IS_GLOBAL
00020 #undef MPI_WTIME_IS_GLOBAL
00021 #endif
00022
00023 #ifdef PETSC_USE_LOG
00024
00025 int Jac1DiagEvent;
00026 int Jac1MultEvent;
00027 int Jac1FinestDiagEvent;
00028 int Jac1FinestMultEvent;
00029
00030 int Jac2DiagEvent;
00031 int Jac2MultEvent;
00032 int Jac2FinestDiagEvent;
00033 int Jac2FinestMultEvent;
00034
00035 int Jac3DiagEvent;
00036 int Jac3MultEvent;
00037 int Jac3FinestDiagEvent;
00038 int Jac3FinestMultEvent;
00039 #endif
00040
00041 double***** LaplacianType1Stencil;
00042 double**** LaplacianType2Stencil;
00043 double***** MassType1Stencil;
00044 double**** MassType2Stencil;
00045 double****** ShapeFnStencil;
00046
00047 int main(int argc, char ** argv ) {
00048 int npes, rank;
00049 unsigned int maxNumPts= 1;
00050 unsigned int dim=3;
00051 unsigned int maxDepth=30;
00052 bool compressLut=false;
00053 double mgLoadFac = 2.0;
00054 bool incCorner = 1;
00055
00056 PetscInitialize(&argc,&argv,"optionsFBM",help);
00057 ot::RegisterEvents();
00058
00059 ot::DAMG_Initialize(MPI_COMM_WORLD);
00060
00061 MPI_Comm_size(MPI_COMM_WORLD,&npes);
00062 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00063
00064 char pFile[256];
00065 sprintf(pFile, "fbmInp%d_%d.pts",rank, npes);
00066
00067 std::vector<double> pts;
00068 ot::readPtsFromFile(pFile, pts);
00069
00070 double gSize[3];
00071 gSize[0] = 1.0;
00072 gSize[1] = 1.0;
00073 gSize[2] = 1.0;
00074
00075
00076 std::vector<ot::TreeNode> linOct;
00077 ot::points2Octree(pts, gSize, linOct, dim, maxDepth, maxNumPts, MPI_COMM_WORLD);
00078 pts.clear();
00079
00080
00081 std::vector<ot::TreeNode> balOct;
00082 ot::balanceOctree(linOct, balOct, dim, maxDepth, incCorner, MPI_COMM_WORLD, NULL, NULL);
00083 linOct.clear();
00084
00085 PetscInt numRefinements = 0;
00086
00087 PetscOptionsGetInt(0,"-numRefinements",&numRefinements,0);
00088 for(int i = 0; i < numRefinements; i++) {
00089 std::vector<ot::TreeNode> tmpOct = balOct;
00090 balOct.clear();
00091 ot::refineOctree(tmpOct, balOct);
00092 }
00093
00094
00095
00096 ot::DAMG *damg;
00097 int nlevels = 1;
00098 unsigned int dof =1;
00099
00100 PetscInt nlevelsPetscInt = nlevels;
00101 PetscOptionsGetInt(0, "-nlevels", &nlevelsPetscInt, 0);
00102 nlevels = nlevelsPetscInt;
00103
00104 if(!rank) {
00105 std::cout<<"nlevels initial: "<<nlevels<<std::endl;
00106 }
00107
00108 MPI_Barrier(MPI_COMM_WORLD);
00109 double setupStartTime = MPI_Wtime();
00110
00111
00112 ot::DAMGCreateAndSetDA(PETSC_COMM_WORLD, nlevels, NULL, &damg,
00113 balOct, dof, mgLoadFac, compressLut, incCorner);
00114
00115 MPI_Barrier(MPI_COMM_WORLD);
00116 double setupEndTime = MPI_Wtime();
00117
00118 if(!rank) {
00119 std::cout<<"nlevels final: "<<nlevels<<std::endl;
00120 }
00121
00122 if(!rank) {
00123 std::cout << "Created DA for all levels."<< std::endl;
00124 }
00125
00126 ot::PrintDAMG(damg);
00127
00128 createLmatType2(LaplacianType2Stencil);
00129 createMmatType2(MassType2Stencil);
00130 createShFnMat(ShapeFnStencil);
00131
00132 ot::DAMGCreateSuppressedDOFs(damg);
00133
00134 SetDirichletJacContexts(damg);
00135
00136
00137
00138 ot::getPrivateMatricesForKSP_Shell = getPrivateMatricesForKSP_Shell_DirichletJac;
00139
00140 ot::DAMGSetKSP(damg, CreateDirichletJacobian, ComputeDirichletJacobian, ComputeFBM_RHS);
00141
00142 MPI_Barrier(MPI_COMM_WORLD);
00143 double solveStartTime = MPI_Wtime();
00144
00145 ot::DAMGSolve(damg);
00146
00147 MPI_Barrier(MPI_COMM_WORLD);
00148 double solveEndTime = MPI_Wtime();
00149
00150 Vec solTrue;
00151 VecDuplicate(DAMGGetx(damg), &solTrue);
00152 SetSolutionFBM(damg[nlevels - 1], solTrue);
00153 EnforceZeroFBM(damg[nlevels - 1], DAMGGetx(damg));
00154
00155 VecAXPY(solTrue, -1.0, DAMGGetx(damg));
00156
00157 PetscReal maxNormErr;
00158 VecNorm(solTrue, NORM_INFINITY, &maxNormErr);
00159
00160 VecDestroy(solTrue);
00161
00162 if(!rank) {
00163 std::cout<<" Total Setup Time: "<<(setupEndTime - setupStartTime)<<std::endl;
00164 std::cout<<" Total Solve Time: "<<(solveEndTime - solveStartTime)<<std::endl;
00165 std::cout<<" maxNormErr (Pointwise): "<<maxNormErr<<std::endl;
00166 }
00167
00168 destroyLmatType2(LaplacianType2Stencil);
00169 destroyMmatType2(MassType2Stencil);
00170 destroyShFnMat(ShapeFnStencil);
00171
00172 DestroyDirichletJacContexts(damg);
00173
00174 DAMGDestroy(damg);
00175
00176 balOct.clear();
00177
00178 ot::DAMG_Finalize();
00179
00180 PetscFinalize();
00181 }
00182