00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "PetscSetupUtils.hpp"
00037
00038 #include <petsc.h>
00039 #include <cstdlib>
00040 #include <cassert>
00041 #include <cstring>
00042 #include <iostream>
00043
00044 #include "ChasteBuildRoot.hpp"
00045 #include "ChasteSyscalls.hpp"
00046 #include "Citations.hpp"
00047 #include "CommandLineArguments.hpp"
00048 #include "Exception.hpp"
00049 #include "GetCurrentWorkingDirectory.hpp"
00050 #include "PetscException.hpp"
00051 #include "PetscTools.hpp"
00052
00053 #ifdef TEST_FOR_FPE
00054 #include <fenv.h>
00055 #include <signal.h>
00056
00057 void FpeSignalToAbort(int sig_num, siginfo_t* info, void* context )
00058 {
00059 if ( info->si_code == FPE_FLTDIV)
00060 {
00061 std::cerr << "SIGFPE: floating point exception was divide by zero.\n";
00062 }
00063 else if ( info->si_code == FPE_FLTINV)
00064 {
00065 std::cerr << "SIGFPE: floating point exception was an invalid operation (like 0.0/0.0).\n";
00066 }
00067 else
00068 {
00069 std::cerr << "SIGFPE: unexpected error code.\n";
00070 }
00071 }
00072 #endif
00073
00074 #if ( PETSC_VERSION_MAJOR<3 || PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR<5 )
00075
00076
00077
00078
00079 static PetscBool PetscCite1 = PETSC_FALSE;
00080 const char PetscCitation1[] = "@TechReport{petsc-user-ref,\n"
00081 " Author = {Satish Balay and Shrirang Abhyankar and Mark F. Adams and Jed Brown and Peter Brune\n"
00082 " and Kris Buschelman and Victor Eijkhout and William D. Gropp\n"
00083 " and Dinesh Kaushik and Matthew G. Knepley\n"
00084 " and Lois Curfman McInnes and Karl Rupp and Barry F. Smith\n"
00085 " and Hong Zhang},\n"
00086 " Title = {{PETS}c Users Manual},\n"
00087 " Number = {ANL-95/11 - Revision 3.5},\n"
00088 " Institution = {Argonne National Laboratory},\n"
00089 " Year = {2014}\n"
00090 "}\n";
00091 static PetscBool PetscCite2 = PETSC_FALSE;
00092 const char PetscCitation2[] = "@InProceedings{petsc-efficient,\n"
00093 " Author = {Satish Balay and William D. Gropp and Lois Curfman McInnes and Barry F. Smith},\n"
00094 " Title = {Efficient Management of Parallelism in Object Oriented Numerical Software Libraries},\n"
00095 " Booktitle = {Modern Software Tools in Scientific Computing},\n"
00096 " Editor = {E. Arge and A. M. Bruaset and H. P. Langtangen},\n"
00097 " Pages = {163--202},\n"
00098 " Publisher = {Birkh{\\\"{a}}user Press},\n"
00099 " Year = {1997}\n"
00100 "}\n";
00101 #endif
00102
00103
00104 static PetscBool ChasteCite = PETSC_FALSE;
00105 const char ChasteCitation[] = "@article{mirams2013chaste,\n"
00106 " author = {Mirams, G.R. and Arthurs, C.J. and Bernabeu, M.O. and Bordas, R. and Cooper, "
00107 "J. and Corrias, A. and Davit, Y. and Dunn, S-J. and Fletcher, A.G. and Harvey, D.G. and "
00108 "Marsh, M.E. and Osborne, J.M. and Pathmanathan, P. and Pitt-Francis, J. and Southern, J. "
00109 "and Zemzemi, N. and Gavaghan, D.J.},\n"
00110 " title = {Chaste: an open source C++ library for computational physiology and biology},\n"
00111 " journal = {PLoS computational biology},\n"
00112 " volume = {9},\n"
00113 " number = {3},\n"
00114 " pages = {e1002970},\n"
00115 " year = {2013},\n"
00116 " publisher = {Public Library of Science}\n"
00117 "}\n";
00118
00119 void PetscSetupUtils::InitialisePetsc()
00120 {
00121
00122 CommandLineArguments* p_args = CommandLineArguments::Instance();
00123 PETSCEXCEPT(PetscInitialize(p_args->p_argc, p_args->p_argv, PETSC_NULL, PETSC_NULL));
00124 }
00125
00126
00127 void PetscSetupUtils::CommonSetup()
00128 {
00129 InitialisePetsc();
00130
00131 #if ( PETSC_VERSION_MAJOR<3 || PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR<5 )
00132
00133 Citations::Register(PetscCitation1, &PetscCite1);
00134 Citations::Register(PetscCitation2, &PetscCite2);
00135 #endif
00136
00137 Citations::Register(ChasteCitation, &ChasteCite);
00138
00139
00140 std::string cwd = GetCurrentWorkingDirectory() + "/";
00141 if (strcmp(cwd.c_str(), ChasteBuildRootDir()) != 0)
00142 {
00143 #define COVERAGE_IGNORE
00144
00145 std::cout << std::endl << "Changing directory from '" << cwd << "' to '" << ChasteBuildRootDir() << "'." << std::endl;
00146 EXPECT0(chdir, ChasteBuildRootDir());
00147 std::cout << "CWD now: " << GetCurrentWorkingDirectory() << std::endl;
00148 #undef COVERAGE_IGNORE
00149 }
00150
00151 #ifdef TEST_FOR_FPE
00152
00153 feenableexcept(FE_DIVBYZERO | FE_INVALID );
00154
00155 struct sigaction sa;
00156 sa.sa_sigaction = FpeSignalToAbort;
00157 sa.sa_flags = SA_RESETHAND|SA_SIGINFO;
00158 sa.sa_restorer = 0;
00159 sigaction(SIGFPE, &sa, NULL);
00160 #endif
00161 }
00162
00163 void PetscSetupUtils::CommonFinalize()
00164 {
00165 Citations::Print();
00166 PETSCEXCEPT(PetscFinalize());
00167 }
00168
00169 void PetscSetupUtils::ResetStatusCache()
00170 {
00171 PetscTools::ResetCache();
00172 }