00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define _DECLARE_MRC_
00021 #include <MatrixManagement.hpp>
00022 static MemoryRepository MR;
00023 MemoryRepository * memoryRepository = &MR;
00024
00025 #include <TinyVector.hpp>
00026 #include <TinyMatrix.hpp>
00027
00028 #include <Vector.hpp>
00029 #include <SparseMatrix.hpp>
00030
00031 #include <DoubleHashedMatrix.hpp>
00032 #include <UnAssembledMatrix.hpp>
00033
00034 void MemoryRepository::store(int i,ReferenceCounting<BaseMatrix>& matrix)
00035 {
00036 __matrices[i] = matrix;
00037 }
00038
00039 ReferenceCounting<BaseMatrix>& MemoryRepository::getMatrix(int i)
00040 {
00041 if (__matrices.count(i) != 0)
00042 return __matrices[i];
00043 else {
00044 throw ErrorHandler(__FILE__,__LINE__,
00045 "tying to access to a none stored matrix ("
00046 +stringify(i)+")",
00047 ErrorHandler::unexpected);
00048 }
00049 return __matrices[0];
00050 }
00051
00052 bool MemoryRepository::stored(int i) const
00053 {
00054 return (__matrices.count(i) != 0);
00055 }
00056
00060 bool MemoryManager::ReserveMatrix(ReferenceCounting<BaseMatrix>& A,
00061 const size_t dimension,
00062 const size_t nbDegreeOfFreefom)
00063 {
00064 int keepMatrix = -1;
00066 if ((keepMatrix == -1) || (!__mr.stored(keepMatrix))) {
00067 switch (__options.value().matrixType()) {
00068 case (MemoryManagerOptions::none): {
00069 A = new UnAssembledMatrix(nbDegreeOfFreefom);
00070 break;
00071 }
00072 case (MemoryManagerOptions::sparse): {
00073 A = new DoubleHashedMatrix(nbDegreeOfFreefom, nbDegreeOfFreefom);
00074 break;
00075 }
00076 default: {
00077 A = new DoubleHashedMatrix(nbDegreeOfFreefom, nbDegreeOfFreefom);
00078 break;
00079 }
00080 }
00081 return true;
00082 } else {
00083 A = __mr.getMatrix(keepMatrix);
00084 return false;
00085 }
00086 }
00087
00088
00089 void MemoryManager::ReserveVector(ReferenceCounting<BaseVector>& b,
00090 size_t dimension,
00091 size_t nbDegreeOfFreefom)
00092 {
00093 b = new Vector<real_t>(nbDegreeOfFreefom);
00094 static_cast<Vector<real_t>&>(*b) = 0;
00095 }