From edd6e5f593d30b66a25841483e91bc599d7351a8 Mon Sep 17 00:00:00 2001 From: Samuel Melchior <samuel.melchior@uclouvain.be> Date: Wed, 10 Mar 2010 11:34:56 +0000 Subject: [PATCH] First lines for projection --- Solver/CMakeLists.txt | 1 + Solver/dgDofContainer.cpp | 38 ++++++++++++++++++++++++++++++++++++ Solver/dgDofContainer.h | 4 +++- Solver/dgGroupOfElements.cpp | 1 + Solver/function.cpp | 2 +- Solver/linearSystemCSR.cpp | 25 ++++++++++++++++++++++++ Solver/linearSystemCSR.h | 5 +++++ 7 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt index e88ccd212e..83714dfa9e 100644 --- a/Solver/CMakeLists.txt +++ b/Solver/CMakeLists.txt @@ -13,6 +13,7 @@ set(SRC multiscaleLaplace.cpp dgGroupOfElements.cpp dgAlgorithm.cpp + dgMgAlgorithm.cpp dgRungeKutta.cpp dgRungeKuttaMultirate.cpp dgConservationLaw.cpp diff --git a/Solver/dgDofContainer.cpp b/Solver/dgDofContainer.cpp index cbf6afa0af..32df24e05f 100644 --- a/Solver/dgDofContainer.cpp +++ b/Solver/dgDofContainer.cpp @@ -242,6 +242,44 @@ void dgDofContainer::L2Projection(std::string functionName){ } } +void dgDofContainer::Mesh2Mesh_BuildL2Projection(linearSystemCSR<double> &projector,dgDofContainer &donor){ +// projector.allocate(); +// projector.addToMatrix(,,); +/*nt nbCoarseNodes = 0; // OLD CODE + int nbCoarseElements = 0; + int r = 0; + for (int kFine = 0;kFine < fineGroups.getNbElementGroups();kFine++) { + int nbFineNodes = fineGroups.getElementGroup(kFine)->getNbNodes(); + fineSol.getGroupProxy(kFine).scale(0); + for (int fineElement = 0 ; fineElement<fineGroups.getElementGroup(kFine)->getNbElements() ;++fineElement) { + for (int fineNodes = 0 ; fineNodes<nbFineNodes ;++fineNodes) { + int kCoarse = 0; + int c0 = 0; + for (int i = startIndex[r++]; i < startIndex[r] - 1; i++){ + int c = columns[i]; + for (;c-c0 < nbCoarseNodes*nbCoarseElements;kCoarse++) { + c0 += nbCoarseNodes*nbCoarseElements; + nbCoarseNodes = coarseGroups.getElementGroup(kCoarse)->getNbNodes(); + nbCoarseElements = coarseGroups.getElementGroup(kCoarse)->getNbElements(); + } + int coarseElement = (c-c0)/nbCoarseNodes; + int coarseNodes = c-c0-nbCoarseNodes*coarseElement; + for (int m = 0; m < nbFields; m++){ + (fineSol.getGroupProxy(kFine))(fineNodes,fineElement*nbFields+m) += values[i]*(coarseSol.getGroupProxy(kCoarse))(coarseNodes,coarseElement*nbFields+m); + } + } + } + }*/ +} + +void dgDofContainer::Mesh2Mesh_ApplyL2Projection(linearSystemCSR<double> &projector,dgDofContainer &donor){ + scale(0.); + int *startIndex; + int *columns; + double *values; + projector.getMatrix(startIndex,columns,values); +} + void dgDofContainer::exportGroupIdMsh(){ // the elementnodedata::export does not work !! diff --git a/Solver/dgDofContainer.h b/Solver/dgDofContainer.h index ad926cd1ef..29318b62f1 100644 --- a/Solver/dgDofContainer.h +++ b/Solver/dgDofContainer.h @@ -3,6 +3,7 @@ #include <vector> #include "fullMatrix.h" +#include "linearSystemCSR.h" class dgGroupCollection; class dgGroupOfElements; @@ -42,7 +43,8 @@ public: void load(const std::string name); void setAll(double v); void L2Projection(std::string functionName); - void Mesh2Mesh_L2Projection(dgDofContainer &other); + void Mesh2Mesh_BuildL2Projection(linearSystemCSR<double> &projector,dgDofContainer &donor); + void Mesh2Mesh_ApplyL2Projection(linearSystemCSR<double> &projector,dgDofContainer &donor); void exportMsh(const std::string name); void exportGroupIdMsh(); void exportMultirateGroupMsh(); diff --git a/Solver/dgGroupOfElements.cpp b/Solver/dgGroupOfElements.cpp index 7248b24dd5..192bc6a794 100644 --- a/Solver/dgGroupOfElements.cpp +++ b/Solver/dgGroupOfElements.cpp @@ -168,6 +168,7 @@ dgGroupOfElements::~dgGroupOfElements(){ delete _elementVolume; } + dgGroupOfFaces::~dgGroupOfFaces() { if (!_faces.size())return; diff --git a/Solver/function.cpp b/Solver/function.cpp index 034d025609..1bd3041b8a 100644 --- a/Solver/function.cpp +++ b/Solver/function.cpp @@ -291,7 +291,7 @@ public: for (int k=0;k<_dofContainer->getNbFields();k++){ _value(i,k) = 0.0; for (int j=0;j<fSize;j++){ - _value(i,k) += solEl(j,k)*fs[j]; + _value(i,k) += solEl(j,k)*fs[j]; } } } diff --git a/Solver/linearSystemCSR.cpp b/Solver/linearSystemCSR.cpp index fd31746723..570657b5c4 100644 --- a/Solver/linearSystemCSR.cpp +++ b/Solver/linearSystemCSR.cpp @@ -282,6 +282,31 @@ void sortColumns_(int NbLines, delete[] count; } +template<> + void linearSystemCSR<double>::getMatrix(INDEX_TYPE*& jptr,INDEX_TYPE*& ai,double*& a) + { + jptr = (INDEX_TYPE*) _jptr->array; + ai = (INDEX_TYPE*) _ai->array; + a = ( double * ) _a->array; + if (!sorted) + sortColumns_(_b->size(), + CSRList_Nbr(_a), + (INDEX_TYPE *) _ptr->array, + jptr, + ai, + a); + sorted = true; + } + +#include "Bindings.h" + +template<> + void linearSystemCSR<double>::registerBindings(binding *b) + { + classBinding *cb = b->addClass< linearSystemCSR<double> >("linearSystemCSRdouble"); +// cb->setDescription("A GModel contains a geometrycal and it's mesh."); + } + #if defined(HAVE_GMM) #include "gmm.h" diff --git a/Solver/linearSystemCSR.h b/Solver/linearSystemCSR.h index 84e4c13e4c..58e343741a 100644 --- a/Solver/linearSystemCSR.h +++ b/Solver/linearSystemCSR.h @@ -11,6 +11,8 @@ #include "GmshMessage.h" #include "linearSystem.h" +class binding; + typedef int INDEX_TYPE ; typedef struct { int nmax; @@ -83,6 +85,8 @@ class linearSystemCSR : public linearSystem<scalar> { } else ptr[position] = n; } + virtual void getMatrix(INDEX_TYPE*& jptr,INDEX_TYPE*& ai,double*& a); + virtual scalar getFromMatrix (int row, int col) const { Msg::Error("getFromMatrix not implemented for CSR"); @@ -110,6 +114,7 @@ class linearSystemCSR : public linearSystem<scalar> { { for(unsigned int i = 0; i < _b->size(); i++) (*_b)[i] = 0.; } + static void registerBindings(binding *b); }; template <class scalar> -- GitLab