2626 *
2727 **********************************************************************************************************************************************/
2828#include < map>
29+ #include < memory>
2930#include " definitions.hpp"
3031#include " vel/FIVel.hpp"
3132#include " vel/BFVel.hpp"
5657
5758namespace ePhotosynthesis {
5859
60+ #ifdef SUNDIALS_CONTEXT_REQUIRED
61+ extern std::shared_ptr<SUNContext> global_context; // !< Global context
62+
63+ /* *
64+ Initialize the global SUNContext.
65+ */
66+ void init_global_sundials_context ();
67+
68+ /* *
69+ Destroy the global SUNContext.
70+ */
71+ void cleanup_global_sundials_context ();
72+
73+ #endif // SUNDIALS_CONTEXT_REQUIRED
74+
5975/* *
6076 Structure to hold global variables
6177 */
6278class Variables {
6379public:
6480#ifdef SUNDIALS_CONTEXT_REQUIRED
81+
82+ private:
83+ std::shared_ptr<SUNContext> _context; /* *< Sundials context */
84+ int _context_flags = 0 ; /* *< Flags describing the context */
85+ /* * Flags describing context traits */
86+ enum CONTEXT_FLAGS : int {
87+ CONTEXT_FLAG_GLOBAL = 0x00000001 , // < The context is global
88+ };
89+ public:
6590 /* *
6691 Construct a new variables instance for a given sundials context
6792 \param[in, out] ctx Sundials context.
6893 */
69- Variables (SUNContext* ctx) : context(ctx) {}
94+ Variables (SUNContext* ctx = nullptr );
95+ /* *
96+ Get the shared pointer to the Sundials context.
97+ \return Sundials context shared pointer.
98+ */
99+ std::shared_ptr<SUNContext> context_ptr () {
100+ return _context;
101+ }
102+ /* *
103+ Get the Sundials context.
104+ \return Sundials context.
105+ */
106+ SUNContext& context () {
107+ return *(_context.get ());
108+ }
70109#else // SUNDIALS_CONTEXT_REQUIRED
71110 /* *
72111 Construct a new variables instance for a given sundials context
@@ -86,9 +125,6 @@ class Variables {
86125 Variables& operator =(const Variables& other);
87126 friend std::ostream& operator <<(std::ostream &out, const Variables *in);
88127
89- #ifdef SUNDIALS_CONTEXT_REQUIRED
90- SUNContext* context = NULL ; /* *< Sundials context */
91- #endif // SUNDIALS_CONTEXT_REQUIRED
92128 bool record = false ;
93129 bool BF_FI_com = false ;
94130 bool EPS_SUCS_com = false ;
0 commit comments