OGS
ApplicationsLib::LinearSolverLibrarySetup Struct Reference

Detailed Description

The LinearSolverLibrarySetup takes care of proper initialization and shutting down of an external linear solver library. The concrete implementation is chosen by the build system. An object of this class must be created at the beginning of the scope where it is used. When the scope closes (or the object is destroyed explicitly) library shutting down functions are automatically called. The default implementation is empty providing polymorphic behaviour when using this class.

Definition at line 20 of file LinearSolverLibrarySetup.h.

#include <LinearSolverLibrarySetup.h>

Inheritance diagram for ApplicationsLib::LinearSolverLibrarySetup:
[legend]

Static Public Member Functions

OGS_EXPORT_SYMBOL static std::shared_ptr< LinearSolverLibrarySetupcreate (int argc, char *argv[])

Protected Member Functions

 LinearSolverLibrarySetup ()=default
virtual ~LinearSolverLibrarySetup ()

Private Member Functions

 LinearSolverLibrarySetup (const LinearSolverLibrarySetup &)=delete
LinearSolverLibrarySetupoperator= (const LinearSolverLibrarySetup &)=delete

Constructor & Destructor Documentation

◆ LinearSolverLibrarySetup() [1/2]

ApplicationsLib::LinearSolverLibrarySetup::LinearSolverLibrarySetup ( )
protecteddefault

◆ ~LinearSolverLibrarySetup()

ApplicationsLib::LinearSolverLibrarySetup::~LinearSolverLibrarySetup ( )
protectedvirtual

Definition at line 95 of file LinearSolverLibrarySetup.cpp.

96{
97 DBUG("Tearing down linear solver library setup.");
98}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22

References DBUG().

◆ LinearSolverLibrarySetup() [2/2]

ApplicationsLib::LinearSolverLibrarySetup::LinearSolverLibrarySetup ( const LinearSolverLibrarySetup & )
privatedelete

Member Function Documentation

◆ create()

std::shared_ptr< LinearSolverLibrarySetup > ApplicationsLib::LinearSolverLibrarySetup::create ( int argc,
char * argv[] )
static

Definition at line 100 of file LinearSolverLibrarySetup.cpp.

102{
103 static std::weak_ptr<LinearSolverLibrarySetup> instance;
104 static std::mutex mutex;
105
106 // Lock to avoid multiple initializations.
107 std::lock_guard lock{mutex};
108
109 std::shared_ptr lsls = instance.lock();
110
111 if (!lsls)
112 {
113 DBUG("Initializing linear solver library for the first time");
114 lsls =
115 std::make_shared<detail::LinearSolverLibrarySetupImpl>(argc, argv);
116
117 // Necessary such that the internally cached ptr and the returned ptr
118 // both point to the same object, which might be returned from
119 // subsequent create() calls.
120 instance = lsls;
121 }
122 else
123 {
124 DBUG("Initializing linear solver library for the {}th time",
125 lsls.use_count());
126#if defined(USE_PETSC) || defined(USE_LIS)
127 // PETSc and Lis parse commandline arguments. Therefore, we exclude them
128 // for the time being such that nobody can accidentally pass
129 // different arguments to different linear solver library setups.
130 OGS_FATAL(
131 "Reusing a LinearSolverLibrarySetup has not been defined for "
132 "PETSc or LIS. In the present build configuration you cannot run "
133 "two separate OGS simulations in the same process.");
134#else
135 // No initialization needed for Eigen, just return the internally cached
136 // ptr.
137#endif
138 }
139
140 // Consistency check that the internally cached ptr and the returned ptr
141 // both point to the same object.
142 // C++26 will have owner_equal()
143 assert(!instance.owner_before(lsls) && !lsls.owner_before(instance));
144
145 return lsls;
146}
#define OGS_FATAL(...)
Definition Error.h:19

References DBUG(), and OGS_FATAL.

◆ operator=()

LinearSolverLibrarySetup & ApplicationsLib::LinearSolverLibrarySetup::operator= ( const LinearSolverLibrarySetup & )
privatedelete

The documentation for this struct was generated from the following files: