PetscTools.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef PETSCTOOLS_HPP_
00031 #define PETSCTOOLS_HPP_
00032 
00033 
00034 #include <vector>
00035 #include <iostream>
00036 #include <cassert>
00037 #include <cstring> //For strcmp etc. Needed in gcc-4.3
00038 
00039 #ifndef SPECIAL_SERIAL
00040 #include <petsc.h>
00041 #include <petscvec.h>
00042 #include <petscmat.h>
00043 
00044 #include "DistributedVector.hpp"
00045 #include "ReplicatableVector.hpp"
00046 #endif //SPECIAL_SERIAL
00047 
00048 #define EXIT_IF_PARALLEL if(!PetscTools::IsSequential()){TS_TRACE("This test does not pass in parallel yet.");return;}
00049 #define EXIT_IF_SEQUENTIAL if(PetscTools::IsSequential()){TS_TRACE("This test is not meant to be executed in sequential.");return;}
00050 
00054 class PetscTools
00055 {
00056 private:
00058     static bool mPetscIsInitialised;
00059     
00061     static unsigned mNumProcessors;
00062     
00064     static unsigned mRank;
00065     
00066 public:
00067     
00071     static const unsigned MASTER_RANK=0;
00072     
00077     static void ResetCache();
00078     
00082     static bool IsSequential();
00083     
00087     static unsigned NumProcs();
00088     
00094     static unsigned GetMyRank();
00095     
00101     static bool AmMaster();
00102     
00107     static void Barrier();
00108 
00109 #ifndef SPECIAL_SERIAL
00110 
00115     static Vec CreateVec(int size);
00116 
00124     static Vec CreateVec(int size, double value);
00125 
00131     static Vec CreateVec(std::vector<double> data);
00132 
00147     static void SetupMat(Mat& rMat, int numRows, int numColumns,
00148                          MatType matType=(MatType) MATMPIAIJ,
00149                          int numLocalRows=PETSC_DECIDE,
00150                          int numLocalColumns=PETSC_DECIDE,
00151                          int maxColsPerRow=54);
00152 
00159     static void ReplicateException(bool flag);
00160 
00172 //    static double GetVecValue(Vec vec, unsigned index)
00173 //    {
00174 //        assert(vec);
00175 //        PetscInt size;
00176 //        VecGetSize(vec, &size);
00177 //        assert((int)index<size);
00178 //
00179 //        double* p_data;
00180 //        VecGetArray(vec, &p_data);
00181 //        double ret = p_data[(int)index];
00182 //        VecRestoreArray(vec, &p_data);
00183 //
00184 //        return ret;
00185 //    }
00186 
00193     static void DumpPetscObject(Mat& rMat, const std::string& rOutputFileFullPath);
00194 
00201     static void DumpPetscObject(Vec& rVec, const std::string& rOutputFileFullPath);
00202 
00209     static void ReadPetscObject(Mat& rMat, const std::string& rOutputFileFullPath);
00210 
00217     static void ReadPetscObject(Vec& rVec, const std::string& rOutputFileFullPath);
00218 
00219 
00220 #endif //SPECIAL_SERIAL
00221 
00222 };
00223 
00224 
00225 
00226 #endif /*PETSCTOOLS_HPP_*/

Generated on Wed Mar 18 12:51:50 2009 for Chaste by  doxygen 1.5.5