From 87b26906e995e1c17e51734d648ca53de3de2580 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Tue, 16 Nov 2021 21:50:21 +0100
Subject: [PATCH] better explanation of
 sameMatrixWithArtificialAndPhysicalSources

---
 examples/maxwell/main.cpp   | 20 ++++++++++++++------
 src/problem/Formulation.cpp |  7 ++++---
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/examples/maxwell/main.cpp b/examples/maxwell/main.cpp
index 0b8ad676..89b65a87 100644
--- a/examples/maxwell/main.cpp
+++ b/examples/maxwell/main.cpp
@@ -140,6 +140,10 @@ int main(int argc, char **argv)
     im * beta * kz / (kc * kc) *
       cos< std::complex< double > >(kz * z< std::complex< double > >()) *
       sin< std::complex< double > >(ky * y< std::complex< double > >()));
+
+  VectorFunction< std::complex< double > > functionZero =
+    vector< std::complex< double > >(0., 0., 0.);
+
   /****
      * FEM
      ****/
@@ -209,8 +213,8 @@ int main(int argc, char **argv)
     // VectorFunction<std::complex<double>> n = normal<std::complex<double>>();
     // VOLUME TERMS
 
-    E.addConstraint(border, vector< std::complex< double > >(0., 0., 0.));
-    lambda.addConstraint(border, vector< std::complex< double > >(0., 0., 0.));
+    E.addConstraint(border, functionZero);
+    lambda.addConstraint(border, functionZero);
 
     formulation.integral(curl(dof(E)), curl(tf(E)), omega, gauss);
     formulation.integral(-k * k * dof(E), tf(E), omega, gauss);
@@ -294,8 +298,7 @@ int main(int argc, char **argv)
     // subdomains
     formulation.addInterfaceField(g);
     VectorFunction< std::complex< double > > n = normal< std::complex< double > >();
-    VectorFunction< std::complex< double > > functionZero =
-      vector< std::complex< double > >(0., 0., 0.);
+
     for(unsigned int i = 0; i < unsigned(nDom); ++i) {
       E(i).addConstraint(border(i), functionZero);
       lambda(i).addConstraint(border(i), functionZero);
@@ -346,9 +349,14 @@ int main(int argc, char **argv)
                                    sigma(i, j), gauss);*/
       }
     }
+
     formulation.pre();
-    // Solve the DDM formulation
-    formulation.solve("gmres", 1e-4, 100, false); // FIXME: last argument should be autodetected!
+    // Solve the DDM formulation; the last argument tells the solver that the
+    // subdomain matrices will be identical with physical and artificial sources
+    // (no bilinear terms involving the sources and no non-homogeneous Dirichlet
+    // BCs) - this saves 2 factorizations per subdomain
+    formulation.solve("gmres", 1e-4, 100, true);
+
     //save field E
     for(int i = 0; i < nDom; ++i) {
       save(E(i), omega(i), "E" + std::to_string(i));
diff --git a/src/problem/Formulation.cpp b/src/problem/Formulation.cpp
index 5b2a5618..c3b59205 100644
--- a/src/problem/Formulation.cpp
+++ b/src/problem/Formulation.cpp
@@ -664,9 +664,10 @@ namespace gmshddm
     template< class T_Scalar >
     gmshfem::common::Timer Formulation< T_Scalar >::solve(const std::string &solver, const double tolerance, const int iterMax, const bool sameMatrixWithArtificialAndPhysicalSources)
     {
-      // TODO: sameMatrixWithArtificialAndPhysicalSources could be automatically
-      // detected by examining if bilinear terms of volume formulations use the
-      // physical/artifical communicator
+      // sameMatrixWithArtificialAndPhysicalSources could be automatically set
+      // to true if bilinear terms of volume formulations do not use the
+      // physical/artifical communicator and if there are no non-homogeneous
+      // Dirichlet BCs
 
       gmshfem::common::Timer time;
       time.tick();
-- 
GitLab