Skip to content

Commit

Permalink
H1 seems to work. Additive immediately stagnates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrillh committed Oct 8, 2024
1 parent 62cf730 commit 933eee1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void CoarseNonLinearSchwarzOperator<SC, LO, GO, NO>::apply(const BlockMultiVecto
if (nlIts == 0) {
if (absResidual < absNewtonTol_) {
std::cout
<< "==> Exiting local Newton solver immediately: absolute residual is already below the tolerance."
<< "==> Exiting coarse Newton solver immediately: absolute residual is already below the tolerance."
<< std::endl;
break; // We are already done
} else {
Expand Down Expand Up @@ -441,7 +441,8 @@ void CoarseNonLinearSchwarzOperator<SC, LO, GO, NO>::apply(const BlockMultiVecto
"step. Still we cancel here.");
}

y->getBlockNonConst(0)->update(alpha, problem_->getSolution()->getBlock(0), beta);
// y->getBlockNonConst(0)->update(alpha, problem_->getSolution()->getBlock(0), beta);
y->update(alpha, problem_->getSolution(), beta);
// Restore problem state
problem_->initializeProblem();
problem_->system_ = systemTmp_;
Expand Down
15 changes: 10 additions & 5 deletions feddlib/problems/Solver/NonLinearSolver_def.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef NONLINEARSOLVER_DEF_hpp

Check notice on line 1 in feddlib/problems/Solver/NonLinearSolver_def.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on feddlib/problems/Solver/NonLinearSolver_def.hpp

File feddlib/problems/Solver/NonLinearSolver_def.hpp does not conform to Custom style guidelines. (lines 3, 32, 35, 36, 37, 38, 41, 42, 43, 46, 47, 51, 52, 56, 57, 59, 60, 66, 70, 71, 74, 75, 76, 77, 78, 79, 83, 84, 90, 91, 94, 95, 96, 100, 102, 105, 106, 109, 110, 111, 112, 113, 114, 115, 123, 124, 126, 127, 129, 130, 132, 133, 135, 137, 139, 140, 142, 144, 146, 148, 151, 152, 153, 155, 162, 166, 171, 172, 174, 176, 178, 179, 180, 181, 183, 185, 186, 190, 192, 194, 195, 197, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 220, 224, 225, 227, 228, 230, 231, 233, 234, 236, 238, 240, 241, 243, 245, 247, 249, 252, 253, 254, 256, 260, 263, 266, 268, 271, 273, 274, 276, 278, 280, 281, 282, 285, 293, 294, 297, 301, 303, 305, 306, 307, 310, 312, 316, 318, 319, 321, 322, 324, 325, 327, 328, 330, 333, 335, 338, 344, 347, 348, 349, 353, 354, 358, 362, 365, 366, 367, 369, 371, 372, 376, 383, 384, 386, 387, 389, 390, 394, 396, 399, 406, 409, 410, 414, 415, 419, 424, 427, 428, 429, 431, 433, 437, 440, 441, 445, 447, 449, 450, 452, 453, 457, 460, 463, 467, 469, 472, 473, 475, 479, 480, 483, 486, 491, 494, 495, 496, 498, 499, 501, 506, 507, 509, 510, 512, 513, 516, 517, 522, 526, 529, 530, 533, 534, 536, 540, 541, 544, 551, 554, 555, 558, 561, 564, 566, 569, 570, 576, 578, 841)
#define NONLINEARSOLVER_DEF_hpp
#include "NonLinearSolver_decl.hpp"
#include "feddlib/core/LinearAlgebra/Map_decl.hpp"
#include "feddlib/core/LinearAlgebra/MultiVector_decl.hpp"
#include "feddlib/core/Utils/FEDDUtils.hpp"
#include "feddlib/problems/Solver/NonLinearSchwarzSolver/CoarseNonLinearSchwarzOperator_decl.hpp"
#include "feddlib/problems/Solver/NonLinearSchwarzSolver/H1Operator_decl.hpp"
Expand Down Expand Up @@ -630,6 +632,10 @@ void NonLinearSolver<SC, LO, GO, NO>::solveNonLinearSchwarz(NonLinearProblem_Typ
auto mapUniqueMerged = mapUnique->getMergedMap();

// The coarse space is built using this Jacobian
// Calling these first two lines does have an affect on the Jacobian that is used to build the coarse space.
// Depending on the particular problem implementation a different set of these calls to assemble should be used.
problem.assemble();
problem.assemble("FixedPoint");
problem.assemble("Newton");
problem.setBoundariesSystem();

Expand Down Expand Up @@ -663,11 +669,10 @@ void NonLinearSolver<SC, LO, GO, NO>::solveNonLinearSchwarz(NonLinearProblem_Typ
if (numLevels == 2) {
coarseOperator->initialize();
coarseOperator->compute();
// For plotting the coarse basis functions

if (problem.getParameterList()->sublist("Exporter").get("Export coarse functions", false)){
coarseOperator->exportCoarseBasis();
}

if (problem.getParameterList()->sublist("Exporter").get("Export coarse functions", false)) {
coarseOperator->exportCoarseBasis();
}
rhsCombineOperator->addOperator(
Teuchos::rcp_implicit_cast<FROSch::NonLinearOperator<SC, LO, GO, NO>>(coarseOperator));
}
Expand Down
7 changes: 7 additions & 0 deletions feddlib/problems/tests/steadyLDC/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ int main(int argc, char *argv[]) {

double length = 4.;
myCLP.setOption("length", &length, "length of domain.");
bool debug = false;
myCLP.setOption("debug", "", &debug, "bool option for debugging");

myCLP.recogniseAllOptions(true);
myCLP.throwExceptions(false);
Expand All @@ -182,6 +184,11 @@ int main(int argc, char *argv[]) {
MPI_Finalize();
return 0;
}
if (comm->getRank() == 1 && debug) {
waitForGdbAttach<LO>();
}
comm->barrier();
comm->barrier();
Teuchos::RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("Steady Navier-Stokes", true));
TimeMonitor::setStackedTimer(stackedTimer);
{
Expand Down
14 changes: 7 additions & 7 deletions feddlib/problems/tests/steadyLDC/parametersPrec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
<Parameter name="FROSch Preconditioner Type" type="string" value="TwoLevelBlockPreconditioner"/>

<Parameter name="Recycling" type="bool" value="true"/>
<Parameter name="DofsPerNode1" type="int" value="1"/>
<Parameter name="DofsPerNode1" type="int" value="2"/>
<Parameter name="DofsPerNode2" type="int" value="1"/>
<Parameter name="DofOrdering1" type="string" value="NodeWise"/>
<Parameter name="DofOrdering2" type="string" value="NodeWise"/>

<Parameter name="Overlap" type="int" value="5"/>
<Parameter name="Overlap" type="int" value="2"/>
<Parameter name="TwoLevel" type="bool" value="true"/>

<Parameter name="Level Combination" type="string" value="Additive"/><!--Multiplicative,Additive-->
<Parameter name="OverlappingOperator Type" type="string" value="AlgebraicOverlappingOperator"/>

<Parameter name="CoarseOperator Type" type="string" value="RGDSWCoarseOperator"/><!--GDSWCoarseOperator,IPOUHarmonicCoarseOperator-->
<Parameter name="Null Space Type" type="string" value="Stokes"/>
<Parameter name="Null Space Type" type="string" value="Laplace"/>

<ParameterList name="AlgebraicOverlappingOperator">
<Parameter name="Reuse: Symbolic Factorization" type="bool" value="false"/>
Expand Down Expand Up @@ -63,8 +63,8 @@
<ParameterList name="1">
<Parameter name="Use For Coarse Space" type="bool" value="true"/>
<ParameterList name="InterfacePartitionOfUnity">
<Parameter name="Type" type="string" value="GDSW"/>
<ParameterList name="GDSW">
<Parameter name="Type" type="string" value="RGDSW"/>
<ParameterList name="RGDSW">
<Parameter name="Interface Communication Strategy" type="string" value="CrsGraph"/><!-- CreateOneToOneMap, CrsGraph, CrsMatrix -->

<Parameter name="Type" type="string" value="Full"/>
Expand All @@ -81,8 +81,8 @@
<ParameterList name="2">
<Parameter name="Use For Coarse Space" type="bool" value="true"/>
<ParameterList name="InterfacePartitionOfUnity">
<Parameter name="Type" type="string" value="GDSW"/>
<ParameterList name="GDSW">
<Parameter name="Type" type="string" value="RGDSW"/>
<ParameterList name="RGDSW">
<Parameter name="Interface Communication Strategy" type="string" value="CrsGraph"/>

<Parameter name="Type" type="string" value="Full"/>
Expand Down
12 changes: 6 additions & 6 deletions feddlib/problems/tests/steadyLDC/parametersProblem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<Parameter name="Mesh Type" type="string" value="structured_ldc"/> <!--structured, structured_bfs, structured_ldc, unstructured -->
<Parameter name="BC Type" type="string" value="LDC"/><!-- parabolic, parabolic_benchmark, partialCFD, LDC-->
<Parameter name="Mesh Delimiter" type="string" value=" "/>
<Parameter name="H/h" type="int" value="50"/>
<Parameter name="H/h" type="int" value="5"/>
<Parameter name="Symmetric gradient" type="bool" value="false"/>
<Parameter name="Viscosity" type="double" value="1.0e-03"/>
<Parameter name="Viscosity" type="double" value="1.0e-02"/>
<Parameter name="Density" type="double" value="1.0"/>
<Parameter name="MaxVelocity" type="double" value="1.0"/>
<Parameter name="MeanVelocity" type="double" value="1.0"/>
<Parameter name="relNonLinTol" type="double" value="1.0e-6"/>
<Parameter name="absNonLinTol" type="double" value="1.0e-6"/>
<Parameter name="MaxNonLinIts" type="int" value="20"/>
<Parameter name="MaxNonLinIts" type="int" value="5"/>
<Parameter name="Set Zeros" type="bool" value="false"/>
<Parameter name="Myeps" type="double" value="1.0e-14"/>
<Parameter name="Combo" type="string" value="OR"/>
Expand All @@ -29,13 +29,13 @@
</ParameterList>
<ParameterList name="Exporter">

<Parameter name="Export coarse functions" type="bool" value="false"/>
<Parameter name="Export coarse functions" type="bool" value="true"/>

<Parameter name="Name coarse functions block1" type="string" value="phiU"/>
<Parameter name="Exclude coarse functions block1" type="bool" value="false"/>

<Parameter name="Name coarse functions block1" type="string" value="phiP"/>
<Parameter name="Exclude coarse functions block1" type="bool" value="false"/>
<Parameter name="Name coarse functions block2" type="string" value="phiP"/>
<Parameter name="Exclude coarse functions block2" type="bool" value="false"/>

</ParameterList>

Expand Down
6 changes: 4 additions & 2 deletions feddlib/problems/tests/steadyLDCSchwarz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

using namespace std;

void initialValue2D(double *x, double *res, double *parameters) { res[0] = 1;res[1] = 1; }
void initialValue2D(double *x, double *res, double *parameters) {res[0] = 0; res[1] = 0;}
// void initialValue2D(double *x, double *res, double *parameters) { res[0] = x[0] * x[1] * (1 - x[0]) * (1 - x[1]); }
// Required for setting the Dirichlet BC on the ghost points to the current global solution in nonlinear Schwarz
void currentSolutionDirichlet2D(double *x, double *res, double t, const double *parameters) { res[0] = x[0]; res[1] = x[1];}
void currentSolutionDirichlet1D(double *x, double *res, double t, const double *parameters) { res[0] = x[0]; }
Expand Down Expand Up @@ -222,11 +223,12 @@ int main(int argc, char *argv[]) {
navierStokes.addRhsFunction(dummyFunc);

navierStokes.initializeProblem();
navierStokes.initSolutionWithFunction(initialValue2D, 0, std::vector<double>{0});
navierStokes.initSolutionWithFunction(initialValue2D, 1, std::vector<double>{0});
navierStokes.assemble();

navierStokes.setBoundariesRHS();

// navierStokes.getSystem()->getBlock(1,1)->print();
std::string nlSolverType = parameterListProblem->sublist("General").get("Linearization", "NonlinearSchwarz");
NonLinearSolver<SC, LO, GO, NO> nlSolver(nlSolverType);
nlSolver.solve(navierStokes);
Expand Down
12 changes: 6 additions & 6 deletions feddlib/problems/tests/steadyLDCSchwarz/parametersProblem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<Parameter name="Mesh Type" type="string" value="structured_ldc"/> <!--structured, structured_bfs, structured_ldc, unstructured -->
<Parameter name="BC Type" type="string" value="LDC"/><!-- parabolic, parabolic_benchmark, partialCFD, LDC-->
<Parameter name="Mesh Delimiter" type="string" value=" "/>
<Parameter name="H/h" type="int" value="10"/>
<Parameter name="H/h" type="int" value="5"/>
<Parameter name="Symmetric gradient" type="bool" value="false"/>
<Parameter name="Viscosity" type="double" value="1.0e-02"/>
<Parameter name="Viscosity" type="double" value="1.0e-03"/>
<Parameter name="Density" type="double" value="1.0"/>
<Parameter name="MaxVelocity" type="double" value="1.0"/>
<Parameter name="MeanVelocity" type="double" value="1.0"/>
<Parameter name="relNonLinTol" type="double" value="1.0e-5"/>
<Parameter name="absNonLinTol" type="double" value="1.0e-5"/>
<Parameter name="MaxNonLinIts" type="int" value="10"/>
<Parameter name="relNonLinTol" type="double" value="1.0e-6"/>
<Parameter name="absNonLinTol" type="double" value="1.0e-6"/>
<Parameter name="MaxNonLinIts" type="int" value="20"/>
<Parameter name="Set Zeros" type="bool" value="false"/>

</ParameterList>
Expand All @@ -32,7 +32,7 @@
<Parameter name="Exclude coarse functions block1" type="bool" value="false"/>

<Parameter name="Name coarse functions block2" type="string" value="phiP"/>
<Parameter name="Exclude coarse functions block1" type="bool" value="false"/>
<Parameter name="Exclude coarse functions block2" type="bool" value="false"/>

</ParameterList>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<ParameterList name="solver">

<Parameter name="Nonlin Schwarz Variant" type="string" value="Additive" /><!-- Additive, H1 -->
<Parameter name="Nonlin Schwarz Variant" type="string" value="H1" /><!-- Additive, H1 -->
<Parameter name="Use ASPEN" type="bool" value="true" />
<Parameter name="Levels" type="int" value="1" />
<Parameter name="Overlap" type="int" value="3" />
<Parameter name="Combine Mode" type="string" value="Averaging" /> <!-- Averaging, Full, Restricted -->
<Parameter name="Levels" type="int" value="2" />
<Parameter name="Overlap" type="int" value="1" />
<Parameter name="Combine Mode" type="string" value="Restricted" /> <!-- Averaging, Full, Restricted -->
<Parameter name="Zero Initial Guess" type="bool" value="false" />

<ParameterList name="ThyraSolver"> <!-- Solver used by the FEDD::Problem object in the inner Newton -->
Expand All @@ -24,8 +24,8 @@
<Parameter name="Solver Type" type="string" value="Block GMRES" />
<ParameterList name="Solver Types">
<ParameterList name="Block GMRES">
<Parameter name="Convergence Tolerance" type="double" value="1e-6" />
<Parameter name="Maximum Iterations" type="int" value="100" />
<Parameter name="Convergence Tolerance" type="double" value="1e-8" />
<Parameter name="Maximum Iterations" type="int" value="1000" />
<Parameter name="Num Blocks" type="int" value="100" />
<Parameter name="Block Size" type="int" value="1" />
<Parameter name="Output Frequency" type="int" value="1" />
Expand All @@ -42,9 +42,9 @@
</ParameterList>

<ParameterList name="Inner Newton Nonlinear Schwarz">
<Parameter name="Relative Tolerance" type="double" value="1.0e-6" />
<Parameter name="Relative Tolerance" type="double" value="1.0e-3" />
<Parameter name="Absolute Tolerance" type="double" value="1.0e-9" />
<Parameter name="Max Iterations" type="int" value="15" />
<Parameter name="Max Iterations" type="int" value="10" />
</ParameterList>

<ParameterList name="Coarse Nonlinear Schwarz"> <!-- Same list as passed to
Expand All @@ -61,6 +61,8 @@
<ParameterList name="Blocks"> <!-- Probably so that different types of coarse space can be
applied to each block -->
<ParameterList name="1">
<!-- In this block exclude the dofs from the following blocks -->
<Parameter name="Exclude" type="string" value="2"/>
<Parameter name="Use For Coarse Space" type="bool" value="true" />
<ParameterList name="InterfacePartitionOfUnity">
<Parameter name="Type" type="string" value="RGDSW" />
Expand All @@ -82,6 +84,7 @@
</ParameterList>
</ParameterList>
<ParameterList name="2">
<Parameter name="Exclude" type="string" value="1"/>
<Parameter name="Use For Coarse Space" type="bool" value="true" />
<ParameterList name="InterfacePartitionOfUnity">
<Parameter name="Type" type="string" value="RGDSW" />
Expand Down

0 comments on commit 933eee1

Please sign in to comment.