]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Multigrid: Only call MGLevelObject::resize() if necessary 11240/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 24 Nov 2020 16:50:56 +0000 (17:50 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 24 Nov 2020 19:55:19 +0000 (20:55 +0100)
include/deal.II/multigrid/multigrid.templates.h

index 5459468171e7f0a1e2b7c28eb7cd2cf30dae4898..b8a7f3ba6ebd2456b75587324966b987dd13f918 100644 (file)
@@ -251,12 +251,17 @@ void
 Multigrid<VectorType>::cycle()
 {
   // The defect vector has been initialized by copy_to_mg. Now adjust the
-  // other vectors.
-  solution.resize(minlevel, maxlevel);
-  t.resize(minlevel, maxlevel);
-  if (cycle_type != v_cycle)
+  // other vectors. First out a check if we have the right number of levels.
+  if (solution.min_level() != minlevel || solution.max_level() != maxlevel)
+    {
+      solution.resize(minlevel, maxlevel);
+      t.resize(minlevel, maxlevel);
+    }
+  if (cycle_type != v_cycle &&
+      (defect2.min_level() != minlevel || defect2.max_level() != maxlevel))
     defect2.resize(minlevel, maxlevel);
 
+  // And now we go and reinit the vectors on the levels.
   for (unsigned int level = minlevel; level <= maxlevel; ++level)
     {
       // the vectors for level>minlevel will be overwritten by the apply()
@@ -280,10 +285,14 @@ void
 Multigrid<VectorType>::vcycle()
 {
   // The defect vector has been initialized by copy_to_mg. Now adjust the
-  // other vectors.
-  solution.resize(minlevel, maxlevel);
-  t.resize(minlevel, maxlevel);
+  // other vectors. First out a check if we have the right number of levels.
+  if (solution.min_level() != minlevel || solution.max_level() != maxlevel)
+    {
+      solution.resize(minlevel, maxlevel);
+      t.resize(minlevel, maxlevel);
+    }
 
+  // And now we go and reinit the vectors on the levels.
   for (unsigned int level = minlevel; level <= maxlevel; ++level)
     {
       solution[level].reinit(defect[level], level > minlevel);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.