From 5d185799d8d30b051c50201ec337c76bb4bddb65 Mon Sep 17 00:00:00 2001
From: Richard Comblen <richard.comblen@uclouvain.be>
Date: Tue, 16 Feb 2010 14:31:11 +0000
Subject: [PATCH] New bindings for RK, see RayleighTaylor.lua for examples

---
 Solver/CMakeLists.txt                        |  2 +-
 Solver/TESTCASES/RayleighTaylor.lua          | 13 +++++++------
 Solver/{dgSlopeLimiter.cpp => dgLimiter.cpp} | 19 ++++++++++++++++++-
 Solver/dgLimiter.h                           |  6 ++++--
 Solver/dgRungeKutta.cpp                      |  8 ++++++--
 Solver/dgSystemOfEquations.cpp               |  2 +-
 6 files changed, 37 insertions(+), 13 deletions(-)
 rename Solver/{dgSlopeLimiter.cpp => dgLimiter.cpp} (87%)

diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt
index 80c9b312e0..b41c976146 100644
--- a/Solver/CMakeLists.txt
+++ b/Solver/CMakeLists.txt
@@ -20,7 +20,7 @@ set(SRC
   dgConservationLawShallowWater2d.cpp
   dgConservationLawWaveEquation.cpp
   dgConservationLawPerfectGas.cpp
-  dgSlopeLimiter.cpp
+  dgLimiter.cpp
   dgDofContainer.cpp
   function.cpp
   functionDerivator.cpp
diff --git a/Solver/TESTCASES/RayleighTaylor.lua b/Solver/TESTCASES/RayleighTaylor.lua
index 4fa27208d5..2f6db81ee9 100644
--- a/Solver/TESTCASES/RayleighTaylor.lua
+++ b/Solver/TESTCASES/RayleighTaylor.lua
@@ -72,29 +72,30 @@ law:addBoundaryCondition('Top',law:newOutsideValueBoundary(FS))
 GC=dgGroupCollection(myModel,2,order)
 solution=dgDofContainer(GC,4)
 solution:L2Projection(FS)
-DG:limitSolution()
-GC:splitGroupsForMultirate(0.0003,law)
+-- limiter=dgSlopeLimiter()
+-- limiter:apply(solution)
 GC:buildGroupsOfInterfaces(myModel,2,order)
 
 print'*** setting the initial solution ***'
 --print'*** export ***'
 
-DG:exportSolution('output/rt_0')
+solution:exportMsh(string.format("output/rt-%06d", 0)) 
 
 print'*** solve ***'
 
 LC = 0.1*.1
 dt = .0003;
 print('DT=',dt)
-
+RK=dgRungeKutta()
+-- RK:setLimiter(limiter)
 for i=1,10000 do
 --    norm = DG:RK44_limiter(dt)
-    norm = DG:RK44(dt)
+    norm = RK:iterate44(law,dt,solution)
     if (i % 10 == 0) then 
        print('*** ITER ***',i,norm)
     end
     if (i % 100 == 0) then 
-       DG:exportSolution(string.format("output/rt-%06d", i)) 
+       solution:exportMsh(string.format("output/rt-%06d", i)) 
     end
 end
 
diff --git a/Solver/dgSlopeLimiter.cpp b/Solver/dgLimiter.cpp
similarity index 87%
rename from Solver/dgSlopeLimiter.cpp
rename to Solver/dgLimiter.cpp
index cdef092477..8ff6173446 100644
--- a/Solver/dgSlopeLimiter.cpp
+++ b/Solver/dgLimiter.cpp
@@ -4,8 +4,9 @@
 #include "function.h"
 
 //----------------------------------------------------------------------------------   
-bool dgSlopeLimiter::apply ( dgDofContainer &solution, dgGroupCollection &groups)
+bool dgSlopeLimiter::apply ( dgDofContainer &solution)
 {    
+  dgGroupCollection &groups=*solution.getGroups();
   solution.scatter();
   int nbFields =_claw->getNbFields();    
 	
@@ -120,3 +121,19 @@ bool dgSlopeLimiter::apply ( dgDofContainer &solution, dgGroupCollection &groups
   return true; 
 }
 
+/*
+#include "Bindings.h"
+
+void dgSlopeLimiter::registerBindings(binding *b) {
+  classBinding *cb = b->addClass<dgSlopeLimiter>("dgSlopeLimiter");
+  cb->setDescription("The usual DG slope limiter: keep the mean, reduces uniformly the slope until it does not overshoot the neighbors' mean");
+  methodBinding *cm;
+  cm = cb->setConstructor<dgSlopeLimiter,dgConservationLaw *>();
+  cm->setDescription("A new explicit slope limiter");
+  cm->setArgNames("law",NULL);
+//  cm = cb->addMethod("apply",&dgLimiter::apply);
+//  cm->setArgNames("solution",NULL);
+//  cm->setDescription("apply the limiter on the solution");
+}
+
+*/
diff --git a/Solver/dgLimiter.h b/Solver/dgLimiter.h
index 93951c62a2..d22d2cf37e 100644
--- a/Solver/dgLimiter.h
+++ b/Solver/dgLimiter.h
@@ -6,19 +6,21 @@
 struct dgDofContainer;
 class dgGroupCollection;
 class dgConservationLaw;
+class binding;
 
 class dgLimiter{
 protected:
   dgConservationLaw *_claw;
 public:
   dgLimiter (dgConservationLaw *claw) : _claw(claw) {}
-  virtual bool apply ( dgDofContainer &sol, dgGroupCollection &groups)=0;
+  virtual bool apply ( dgDofContainer &sol)=0;
 };
 
 class dgSlopeLimiter : public dgLimiter{
 public :
   dgSlopeLimiter (dgConservationLaw *claw) : dgLimiter (claw) {}
-  virtual bool apply ( dgDofContainer &solution, dgGroupCollection &groups);
+  virtual bool apply ( dgDofContainer &solution);
+  //static void registerBindings(binding *b);
 };
 
 #endif
diff --git a/Solver/dgRungeKutta.cpp b/Solver/dgRungeKutta.cpp
index 94e7db089f..b6f7069c07 100644
--- a/Solver/dgRungeKutta.cpp
+++ b/Solver/dgRungeKutta.cpp
@@ -49,7 +49,7 @@ double dgRungeKutta::diagonalRK (const dgConservationLaw *claw,
       K.axpy(*sol);
     }
 
-    if (_limiter) _limiter->apply(K, *groups);
+    if (_limiter) _limiter->apply(K);
     dgAlgorithm::residual(*claw,*groups,K,resd);
     K.scale(0.);
     for(int k=0; k < groups->getNbElementGroups(); k++) {
@@ -64,9 +64,10 @@ double dgRungeKutta::diagonalRK (const dgConservationLaw *claw,
     }
     Unp.axpy(K,b[j]*dt);
   }
-  if (_limiter) _limiter->apply(Unp, *groups);
+  if (_limiter) _limiter->apply(Unp);
   sol->scale(0.);
   sol->axpy(Unp);
+  return sol->norm();
 }
 
 dgRungeKutta::dgRungeKutta():_limiter(NULL) {}
@@ -89,4 +90,7 @@ void dgRungeKutta::registerBindings(binding *b) {
   cm = cb->addMethod("iterate44",&dgRungeKutta::iterate44);
   cm->setArgNames("law","dt","solution",NULL);
   cm->setDescription("update solution by doing classical fourth order runge-kutta step of time step dt for the conservation law");
+//  cm = cb->addMethod("setLimiter",&dgRungeKutta::setLimiter);
+//  cm->setArgNames("limiter",NULL);
+//  cm->setDescription("if a limiter is set, it is applied after each RK stage");
 }
diff --git a/Solver/dgSystemOfEquations.cpp b/Solver/dgSystemOfEquations.cpp
index e9fa0c2e58..56c0b9a3b9 100644
--- a/Solver/dgSystemOfEquations.cpp
+++ b/Solver/dgSystemOfEquations.cpp
@@ -142,7 +142,7 @@ void dgSystemOfEquations::exportSolution(std::string outputFile){
 
 void dgSystemOfEquations::limitSolution(){
   dgLimiter *sl = new dgSlopeLimiter(_claw);
-  sl->apply(*_solution,_groups);
+  sl->apply(*_solution);
 
   delete sl;
 }
-- 
GitLab