Commit 0d00eee4 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#723 ThirdParty/Solver: isolate lines of code that are relevant only for Mumps solver.

parent f1645dcc
......@@ -659,8 +659,8 @@ Petsc2 = {
-- List of solver: { chebychev cg gmres preonly bicg python };
-- Expected format: {"VALUE1", "VALUE2", ...}
-- Constraint: ops_in(v, {'Mumps', 'Umfpack'})
solver = 'Mumps',
-- Constraint: ops_in(v, {'Mumps', 'Umfpack', 'Gmres'})
solver = 'Gmres',
} -- Petsc
......
......@@ -559,6 +559,12 @@
BE8553AC1BBD77BF00DB109E /* None.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE8553A61BBD77BF00DB109E /* None.cpp */; };
BE8553AD1BBD77BF00DB109E /* None.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE8553A71BBD77BF00DB109E /* None.hpp */; };
BE8553AE1BBD77BF00DB109E /* None.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE8553A81BBD77BF00DB109E /* None.hxx */; };
BE863E3B1BE7AB6700EE3338 /* Snes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE863E381BE7AB6700EE3338 /* Snes.cpp */; };
BE863E3C1BE7AB6700EE3338 /* Snes.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE863E391BE7AB6700EE3338 /* Snes.hpp */; };
BE863E3D1BE7AB6700EE3338 /* Snes.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE863E3A1BE7AB6700EE3338 /* Snes.hxx */; };
BE863E421BE7ABA900EE3338 /* Mumps.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE863E3F1BE7ABA900EE3338 /* Mumps.cpp */; };
BE863E431BE7ABA900EE3338 /* Mumps.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE863E401BE7ABA900EE3338 /* Mumps.hpp */; };
BE863E441BE7ABA900EE3338 /* Mumps.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE863E411BE7ABA900EE3338 /* Mumps.hxx */; };
BE86A9EE1A385C9B003B211D /* SegmentP2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE86A9EC1A385C9B003B211D /* SegmentP2.cpp */; };
BE86A9EF1A385C9B003B211D /* SegmentP2.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE86A9ED1A385C9B003B211D /* SegmentP2.hpp */; };
BE86B21D1AE90F6B00406F5B /* GlobalVectorStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE86B21A1AE90F6B00406F5B /* GlobalVectorStorage.cpp */; };
......@@ -950,9 +956,6 @@
BE90E1B71A24929A00CCAFDE /* Petsc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE82F18CE0A6900177F79 /* Petsc.cpp */; };
BE90E1B81A24929A00CCAFDE /* Petsc.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83018CE0A6900177F79 /* Petsc.hpp */; };
BE90E1B91A24929A00CCAFDE /* Print.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83418CE0A6900177F79 /* Print.hpp */; };
BE90E1BA1A24929A00CCAFDE /* Snes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE83918CE0A6900177F79 /* Snes.cpp */; };
BE90E1BB1A24929A00CCAFDE /* Snes.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83A18CE0A6900177F79 /* Snes.hpp */; };
BE90E1BC1A24929A00CCAFDE /* Snes.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE83B18CE0A6900177F79 /* Snes.hxx */; };
BE90E1BD1A24929A00CCAFDE /* Viewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE83F18CE0A6900177F79 /* Viewer.cpp */; };
BE90E1BE1A24929A00CCAFDE /* Viewer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE9FE84018CE0A6900177F79 /* Viewer.hpp */; };
BE90E1C01A2492AA00CCAFDE /* SeldonFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE9FE84218CE0A6900177F79 /* SeldonFunctions.cpp */; };
......@@ -4028,6 +4031,12 @@
BE8553A61BBD77BF00DB109E /* None.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = None.cpp; sourceTree = "<group>"; };
BE8553A71BBD77BF00DB109E /* None.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = None.hpp; sourceTree = "<group>"; };
BE8553A81BBD77BF00DB109E /* None.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = None.hxx; sourceTree = "<group>"; };
BE863E381BE7AB6700EE3338 /* Snes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Snes.cpp; path = Solver/Snes.cpp; sourceTree = "<group>"; };
BE863E391BE7AB6700EE3338 /* Snes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Snes.hpp; path = Solver/Snes.hpp; sourceTree = "<group>"; };
BE863E3A1BE7AB6700EE3338 /* Snes.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Snes.hxx; path = Solver/Snes.hxx; sourceTree = "<group>"; };
BE863E3F1BE7ABA900EE3338 /* Mumps.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mumps.cpp; path = Solver/Private/Mumps.cpp; sourceTree = "<group>"; };
BE863E401BE7ABA900EE3338 /* Mumps.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mumps.hpp; path = Solver/Private/Mumps.hpp; sourceTree = "<group>"; };
BE863E411BE7ABA900EE3338 /* Mumps.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mumps.hxx; path = Solver/Private/Mumps.hxx; sourceTree = "<group>"; };
BE86A9EC1A385C9B003B211D /* SegmentP2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SegmentP2.cpp; sourceTree = "<group>"; };
BE86A9ED1A385C9B003B211D /* SegmentP2.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SegmentP2.hpp; sourceTree = "<group>"; };
BE86B21A1AE90F6B00406F5B /* GlobalVectorStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GlobalVectorStorage.cpp; sourceTree = "<group>"; };
......@@ -4090,9 +4099,6 @@
BE9FE82F18CE0A6900177F79 /* Petsc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Petsc.cpp; sourceTree = "<group>"; };
BE9FE83018CE0A6900177F79 /* Petsc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Petsc.hpp; sourceTree = "<group>"; };
BE9FE83418CE0A6900177F79 /* Print.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Print.hpp; sourceTree = "<group>"; };
BE9FE83918CE0A6900177F79 /* Snes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Snes.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
BE9FE83A18CE0A6900177F79 /* Snes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = Snes.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
BE9FE83B18CE0A6900177F79 /* Snes.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Snes.hxx; sourceTree = "<group>"; };
BE9FE83F18CE0A6900177F79 /* Viewer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Viewer.cpp; sourceTree = "<group>"; };
BE9FE84018CE0A6900177F79 /* Viewer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Viewer.hpp; sourceTree = "<group>"; };
BE9FE84218CE0A6900177F79 /* SeldonFunctions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SeldonFunctions.cpp; sourceTree = "<group>"; };
......@@ -6620,6 +6626,27 @@
path = DofSourcePolicy;
sourceTree = "<group>";
};
BE863E371BE7AAF700EE3338 /* Solver */ = {
isa = PBXGroup;
children = (
BE863E381BE7AB6700EE3338 /* Snes.cpp */,
BE863E391BE7AB6700EE3338 /* Snes.hpp */,
BE863E3A1BE7AB6700EE3338 /* Snes.hxx */,
BE863E3E1BE7AB8200EE3338 /* Private */,
);
name = Solver;
sourceTree = "<group>";
};
BE863E3E1BE7AB8200EE3338 /* Private */ = {
isa = PBXGroup;
children = (
BE863E3F1BE7ABA900EE3338 /* Mumps.cpp */,
BE863E401BE7ABA900EE3338 /* Mumps.hpp */,
BE863E411BE7ABA900EE3338 /* Mumps.hxx */,
);
name = Private;
sourceTree = "<group>";
};
BE8F0E381A8110EE00D81C9F /* GlobalVariationalOperator.xctemplate */ = {
isa = PBXGroup;
children = (
......@@ -6805,14 +6832,12 @@
children = (
BEEFEF71196ECCC000C80FF1 /* Matrix */,
BEEFEF78196ECCC000C80FF1 /* Vector */,
BE863E371BE7AAF700EE3338 /* Solver */,
BE9FE82F18CE0A6900177F79 /* Petsc.cpp */,
BE9FE83018CE0A6900177F79 /* Petsc.hpp */,
BE4B17D21AA5B20D0073516A /* Print.cpp */,
BE9FE83418CE0A6900177F79 /* Print.hpp */,
BE4B17CF1AA5AB0E0073516A /* Print.hxx */,
BE9FE83918CE0A6900177F79 /* Snes.cpp */,
BE9FE83A18CE0A6900177F79 /* Snes.hpp */,
BE9FE83B18CE0A6900177F79 /* Snes.hxx */,
BE9FE83F18CE0A6900177F79 /* Viewer.cpp */,
BE9FE84018CE0A6900177F79 /* Viewer.hpp */,
BE9FE82318CE0A6900177F79 /* Exceptions */,
......@@ -8636,6 +8661,7 @@
BE768E9F1B8331AE009B24CB /* Traits.hxx in Headers */,
BE90E1AA1A24929A00CCAFDE /* Matrix.hpp in Headers */,
BE90E1C81A2492AA00CCAFDE /* Mpi.hpp in Headers */,
BE863E3D1BE7AB6700EE3338 /* Snes.hxx in Headers */,
BE90E1AE1A24929A00CCAFDE /* MatrixPattern.hxx in Headers */,
BE90E1C21A2492AA00CCAFDE /* SeldonFunctions.hxx in Headers */,
BE90E1A81A24929A00CCAFDE /* Parmetis.hpp in Headers */,
......@@ -8648,6 +8674,7 @@
BE90E1A61A24929A00CCAFDE /* Helper.hxx in Headers */,
BE56978F1BE383AD00B2EC67 /* MatrixOperations.hxx in Headers */,
BE90E18F1A24929A00CCAFDE /* File.hpp in Headers */,
BE863E3C1BE7AB6700EE3338 /* Snes.hpp in Headers */,
BE44C05B1AA463DF0030FA26 /* Pragma.hpp in Headers */,
BE4ED31D1A2CBAC400DE374E /* MatrixOperations.hpp in Headers */,
BE90E1B11A24929A00CCAFDE /* Vector.hxx in Headers */,
......@@ -8665,7 +8692,8 @@
BE1E873D1B8DBF460002EE64 /* Definitions.hpp in Headers */,
BE41A8CA1A24AA46004E4312 /* Mpi.hpp in Headers */,
BE768E851B832795009B24CB /* Subtuple.hpp in Headers */,
BE90E1BB1A24929A00CCAFDE /* Snes.hpp in Headers */,
BE863E431BE7ABA900EE3338 /* Mumps.hpp in Headers */,
BE863E441BE7ABA900EE3338 /* Mumps.hxx in Headers */,
BE41A8CF1A24AA46004E4312 /* Mpi.hxx in Headers */,
BE1E87641B8DFB710002EE64 /* PrepareDefaultEntry.hxx in Headers */,
BE56978E1BE383AD00B2EC67 /* MatrixOperations.hpp in Headers */,
......@@ -8709,7 +8737,6 @@
BE41A8D01A24AA59004E4312 /* Petsc.hxx in Headers */,
BE90E1C31A2492AA00CCAFDE /* SubVector.hpp in Headers */,
BE90E1781A24926E00CCAFDE /* Singleton.hpp in Headers */,
BE90E1BC1A24929A00CCAFDE /* Snes.hxx in Headers */,
BE768EC01B836022009B24CB /* Section.hpp in Headers */,
BE90E16B1A24926E00CCAFDE /* Vector.hpp in Headers */,
BE90E1661A24926E00CCAFDE /* Tuple.hpp in Headers */,
......@@ -10391,6 +10418,7 @@
BE768E7E1B8325BB009B24CB /* ManualParsing.cpp in Sources */,
BE90E17A1A24926E00CCAFDE /* Singleton.cpp in Sources */,
BE90E1C01A2492AA00CCAFDE /* SeldonFunctions.cpp in Sources */,
BE863E421BE7ABA900EE3338 /* Mumps.cpp in Sources */,
BE90E1A01A24929A00CCAFDE /* Comm.cpp in Sources */,
BE1E87401B8DBF670002EE64 /* Definitions.cpp in Sources */,
BE6E4EE11B2ABE8B0049BB2D /* AccessGhostContent.cpp in Sources */,
......@@ -10398,9 +10426,9 @@
BE90E1981A24929A00CCAFDE /* Lm5.cpp in Sources */,
BE41A8D11A24AA7F004E4312 /* Petsc.cpp in Sources */,
BE90E1AF1A24929A00CCAFDE /* Vector.cpp in Sources */,
BE90E1BA1A24929A00CCAFDE /* Snes.cpp in Sources */,
BE90E1711A24926E00CCAFDE /* String.cpp in Sources */,
BEEABA631A49CB5A00A875C6 /* CommandLineOptions.cpp in Sources */,
BE863E3B1BE7AB6700EE3338 /* Snes.cpp in Sources */,
BE90E1961A24929A00CCAFDE /* libmesh5.c in Sources */,
BE90E1941A24929A00CCAFDE /* TimeKeep.cpp in Sources */,
BE90E1611A24926E00CCAFDE /* Exception.cpp in Sources */,
......
......@@ -40,7 +40,7 @@ namespace HappyHeart
const std::string& Solver::Constraint()
{
static std::string ret("ops_in(v, { 'Mumps', 'Umfpack' })"); // 'chebychev', 'umfpack', 'cg', 'gmres', 'preonly', 'bicg', 'python'})");
static std::string ret("ops_in(v, { 'Mumps', 'Umfpack', 'Gmres' })"); // 'chebychev', 'umfpack', 'cg', 'gmres', 'preonly', 'bicg', 'python'})");
return ret;
}
......
......@@ -12,7 +12,7 @@
# include <memory>
# include <vector>
# include "ThirdParty/Wrappers/Petsc/Snes.hpp"
# include "ThirdParty/Wrappers/Petsc/Solver/Snes.hpp"
# include "Core/InputParameter/Solver/Petsc.hpp"
# include "Core/InputParameterList.hpp"
......
......@@ -5,7 +5,7 @@
# include <vector>
# include "ThirdParty/Wrappers/Petsc/Matrix/MatrixOperations.hpp"
# include "ThirdParty/Wrappers/Petsc/Snes.hpp"
# include "ThirdParty/Wrappers/Petsc/Solver/Snes.hpp"
# include "ThirdParty/Wrappers/Petsc/Print.hpp"
# include "ThirdParty/Wrappers/Petsc/Vector/AccessVectorContent.hpp"
......
......@@ -71,7 +71,7 @@ namespace HappyHeart
template<IsFactorized IsFactorizedT>
inline void VariationalFormulation<DerivedT, SolverIndexT>
::SolveLinear(const NumberingSubset& row_numbering_subset,
const NumberingSubset& col_numbering_subset)
const NumberingSubset& col_numbering_subset)
{
return SolveLinear<IsFactorizedT>(GetSystemMatrix(row_numbering_subset, col_numbering_subset),
GetSystemRhs(col_numbering_subset),
......
......@@ -16,7 +16,8 @@ Wrappers/Petsc/Matrix/Matrix.cpp
Wrappers/Petsc/Matrix/MatrixPattern.cpp
Wrappers/Petsc/Petsc.cpp
Wrappers/Petsc/Print.cpp
Wrappers/Petsc/Snes.cpp
Wrappers/Petsc/Solver/Snes.cpp
Wrappers/Petsc/Solver/Private/Mumps.cpp
Wrappers/Petsc/Vector/AccessVectorContent.cpp
Wrappers/Petsc/Vector/AccessGhostContent.cpp
Wrappers/Petsc/Vector/Private/VectorHelper.cpp
......
//
// Mumps.cpp
// HappyHeart
//
// Created by Sebastien Gilles on 02/11/15.
// Copyright © 2015 Inria. All rights reserved.
//
#include "ThirdParty/Wrappers/Petsc/Solver/Private/Mumps.hpp"
#include "ThirdParty/Wrappers/Petsc/Solver/Snes.hpp"
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
namespace Private
{
void Mumps::SetOptions(Snes& snes,
const char* invoking_file, int invoking_line)
{
auto pc = snes.GetPreconditioner(invoking_file, invoking_line);
auto error_code = PCFactorSetUpMatSolverPackage(pc); /* call MatGetFactor() to create F */
if (error_code)
throw ExceptionNS::Exception(error_code, "PCFactorSetUpMatSolverPackage",
invoking_file, invoking_line);
Mat F;
error_code = PCFactorGetMatrix(pc, &F);
if (error_code)
throw ExceptionNS::Exception(error_code, "PCFactorGetMatrix",
invoking_file, invoking_line);
// /* sequential ordering */
PetscInt icntl = 7, ival = 2;
PetscScalar val;
error_code = MatMumpsSetIcntl(F, icntl, ival);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatMumpsSetIcntl",
invoking_file, invoking_line);
/* threshhold for row pivot detection */
error_code = MatMumpsSetIcntl(F,24,1);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatMumpsSetIcntl",
invoking_file, invoking_line);
icntl = 3; val = 1.e-6;
error_code = MatMumpsSetCntl(F,icntl,val);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatMumpsSetIcntl",
invoking_file, invoking_line);
/* compute determinant of A */
error_code = MatMumpsSetIcntl(F,33,1);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatMumpsSetIcntl",
invoking_file, invoking_line);
TimeKeep::GetInstance().PrintTimeElapsed("AfterMUMPSSet");
}
} //namespace Private
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
//
// Mumps.hpp
// HappyHeart
//
// Created by Sebastien Gilles on 02/11/15.
// Copyright © 2015 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HPP_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HPP_
# include <memory>
# include <vector>
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
// ============================
// Forward declarations.
// ============================
class Snes;
// ============================
// End of forward declarations.
// ============================
namespace Private
{
struct Mumps
{
static void SetOptions(Snes& snes,
const char* invoking_file, int invoking_line);
};
} //namespace Private
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
# include "ThirdParty/Wrappers/Petsc/Solver/Private/Mumps.hxx"
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HPP_
//
// Mumps.hxx
// HappyHeart
//
// Created by Sebastien Gilles on 02/11/15.
// Copyright © 2015 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HXX_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HXX_
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
namespace Private
{
} //namespace Private
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_PRIVATE_x_MUMPS_HXX_
......@@ -9,7 +9,7 @@
//
#include <cassert>
#include "ThirdParty/Wrappers/Petsc/Snes.hpp"
#include "ThirdParty/Wrappers/Petsc/Solver/Snes.hpp"
#include "ThirdParty/Wrappers/Petsc/Print.hpp"
#include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"
......@@ -27,6 +27,26 @@ namespace HappyHeart
{
namespace // anonymous
{
Solver SolverFromName(const std::string& solver_name)
{
if (solver_name == "Gmres")
return Solver::Gmres;
if (solver_name == "Umfpack")
return Solver::Umfpack;
if (solver_name == "Mumps")
return Solver::Mumps;
assert(false && "Any other choice should have been trapped by InputParameterList!");
return Solver::none;
}
}
Snes::Snes(const Mpi& mpi,
const std::string& solver,
......@@ -42,7 +62,8 @@ namespace HappyHeart
: mpi_(mpi),
snes_function_(snes_function),
snes_jacobian_(snes_jacobian),
snes_viewer_(snes_viewer)
snes_viewer_(snes_viewer),
solver_(SolverFromName(solver))
{
auto communicator = mpi.GetCommunicator();
......@@ -53,6 +74,21 @@ namespace HappyHeart
throw ExceptionNS::Exception(error_code, "SNESCreate", invoking_file, invoking_line);
auto ksp = GetKsp(invoking_file, invoking_line);
std::string solver_id;
if (solver == "Mumps")
solver_id = MATSOLVERMUMPS;
else if (solver == "Umfpack")
solver_id = MATSOLVERUMFPACK;
else if (solver == "Gmres")
solver_id = KSPGMRES;
else
{
assert(false && "Any other choice should have been trapped by InputParameterList!");
}
assert(!solver_id.empty());
// If the solver is a direct one, type must be 'preonly' and preconditioner 'lu'; actual solver
......@@ -71,13 +107,6 @@ namespace HappyHeart
throw Exception(oconv.str(), invoking_file, invoking_line);
}
std::string solver_id;
if (solver == "Mumps")
solver_id = MATSOLVERMUMPS;
else if (solver == "Umfpack")
solver_id = MATSOLVERUMFPACK;
assert(!solver_id.empty());
auto pc = GetPreconditioner(invoking_file, invoking_line);
......@@ -93,7 +122,7 @@ namespace HappyHeart
}
else
{
error_code = KSPSetType(ksp, solver.c_str());
error_code = KSPSetType(ksp, solver_id.c_str());
if (error_code)
throw ExceptionNS::Exception(error_code, "KSPSetType", invoking_file, invoking_line);
......
......@@ -6,8 +6,8 @@
// Copyright (c) 2013 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SNES_HPP_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SNES_HPP_
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_SNES_HPP_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_SNES_HPP_
# include <memory>
......@@ -17,9 +17,9 @@
# include "ThirdParty/Wrappers/Petsc/Vector/Vector.hpp"
# include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
#include "ThirdParty/Wrappers/Petsc/Snes.hpp"
#include "ThirdParty/Wrappers/Petsc/Print.hpp"
#include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"
#include "ThirdParty/Wrappers/Petsc/Solver/Private/Mumps.hpp"
#include "Utilities/TimeKeep/TimeKeep.hpp"
......@@ -36,6 +36,15 @@ namespace HappyHeart
{
enum class Solver
{
none,
Mumps,
Umfpack,
Gmres
};
/*!
* \brief This class wraps all the Petsc objects related to solver.
*
......@@ -61,7 +70,8 @@ namespace HappyHeart
//! Alias for SNESJacobian (which seemed to have been deprecated in Petsc 3.4...).
using SNESJacobian = PetscErrorCode(*)(SNES, Vec, Mat, Mat, void*);
//! Friendship to helper class.
friend Private::Mumps;
public:
......@@ -232,8 +242,11 @@ namespace HappyHeart
* an illegal call.
*/
SNESViewer GetSnesViewer() const;
//! Get the solver used.
Solver GetSolver() const noexcept;
private:
//! Petsc's underlying object.
......@@ -251,6 +264,9 @@ namespace HappyHeart
//! Snes viewer function. Might be nullptr for linear solve.
SNESViewer snes_viewer_;
//! Solver used.
const Solver solver_;
};
......@@ -263,7 +279,7 @@ namespace HappyHeart
} // namespace HappyHeart
# include "ThirdParty/Wrappers/Petsc/Snes.hxx"
# include "ThirdParty/Wrappers/Petsc/Solver/Snes.hxx"
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SNES_HPP_
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_SNES_HPP_
......@@ -6,8 +6,8 @@
// Copyright (c) 2013 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SNES_HXX_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SNES_HXX_
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_SNES_HXX_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_SOLVER_x_SNES_HXX_
......@@ -43,6 +43,12 @@ namespace HappyHeart
assert(!(!snes_viewer_));
return snes_viewer_;
}
inline Solver Snes::GetSolver() const noexcept
{
return solver_;
}
template<class MatrixT>
......@@ -69,54 +75,8 @@ namespace HappyHeart
TimeKeep::GetInstance().PrintTimeElapsed("AfterSetOperator");
auto pc = GetPreconditioner(__FILE__, __LINE__);
error_code = PCFactorSetUpMatSolverPackage(pc); /* call MatGetFactor() to create F */
if (error_code)
throw ExceptionNS::Exception(error_code, "PCFactorSetUpMatSolverPackage",
invoking_file, invoking_line);
Mat F;
error_code = PCFactorGetMatrix(pc, &F);
if (error_code)
throw ExceptionNS::Exception(error_code, "PCFactorGetMatrix",
invoking_file, invoking_line);
// /* sequential ordering */
PetscInt icntl = 7, ival = 2;
PetscScalar val;
error_code = MatMumpsSetIcntl(F, icntl, ival);