Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
jit.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_LIBS_JUST_IN_TIME_INFORMATIONS_HXX__
22#define __ANTARES_LIBS_JUST_IN_TIME_INFORMATIONS_HXX__
23
24#include <antares/logs/logs.h>
25
26using namespace Antares;
27
29{
30 return (!j or j->alreadyLoaded);
31}
32
34{
35 modified = true;
36 alreadyLoaded = true;
37}
38
39using namespace Antares;
40
41template<class T, class ReadWriteT>
42void JIT::just_in_time_manager::clear_matrix(const Matrix<T, ReadWriteT>* mtx)
43{
45
46 // Ugly const_cast but it is to preserve a good public Matrix class API :
47 auto* mtx_not_const = const_cast<Matrix<T, ReadWriteT>*>(mtx);
48 mtx_not_const->clear();
49}
50
51template<class T, class ReadWriteT>
52void JIT::just_in_time_manager::unload_matrix_properly_from_memory(const Matrix<T, ReadWriteT>* mtx)
53{
54 using namespace Antares;
55
56 auto* mtx_not_const = const_cast<Matrix<T, ReadWriteT>*>(mtx);
57
58 // - jit activated :
59 // If JIT (Just-In-Time) is activated, we have to unload data to keep the memory for
60 // the solver. The old width must only be kept when the matrix has fixed dimension.
61 //
62 // - JIT::enabled and jit not activated :
63 // If the matrix is not ready for just-in-time (not activated), but JIT is enabled,
64 // like it would be the case from the GUI, we have to activate jit. 2
65 // reasons
66 // for this :
67 // - To reserve the memory for the study
68 // - To reload data in case of preprocessor data have been written to
69 // the input folder
70
71 if (jit_ or JIT::enabled)
72 {
73 Yuni::String buffer = file_name_;
74 jit_ = JIT::Reset(jit_, buffer);
75 mtx->jit = jit_;
77 jit_->minWidth = (0
78 != (jit_recorded_state()->options & Matrix<T, ReadWriteT>::optFixedSize))
79 ? jit_recorded_state()->minWidth
80 : 1;
81 jit_->maxHeight = jit_recorded_state()->maxHeight;
82 jit_->options = jit_recorded_state()->options;
83 mtx_not_const->clear();
84 }
85}
86
87template<class T, class ReadWriteT>
88void JIT::just_in_time_manager::load_matrix(const Matrix<T, ReadWriteT>* mtx)
89{
90 if (not jit_->alreadyLoaded)
91 {
92 auto* mtx_not_const = const_cast<Matrix<T, ReadWriteT>*>(mtx);
93
94 logs.debug() << " Force loading of " << jit_->sourceFilename;
95 const bool modi = jit_->modified;
96
97 mtx_not_const->loadFromCSVFile(jit_->sourceFilename,
98 jit_->minWidth,
99 jit_->maxHeight,
101
102 jit_->modified = modi;
103 }
104 jit_->loadDataIfNotAlreadyDone = false;
105}
106
107#endif // __ANTARES_LIBS_JUST_IN_TIME_INFORMATIONS_HXX__
A n-by-n matrix.
Definition jit.h:30
JIT::Informations * jit
Just-in-time informations.
Definition matrix.h:447
void clear()
Empty the matrix.
Definition matrix.hxx:532
Definition jit.h:118
bool modified
Flag to determine wheter if the associated data have already been modified.
Definition jit.h:144
bool alreadyLoaded
Flag to determine wheter if the associated data have already been loaded.
Definition jit.h:142
void markAsModified()
Mark the associated data as modified.
Definition jit.hxx:33
static Informations * Reset(Informations *jit, const AnyString &filename)
Reset the source filename.
Definition jit.cpp:80
static bool IsReady(Informations *j)
Get if the data has been loaded.
Definition jit.hxx:28
static bool enabled
Flag to enable/disable JIT informations.
Definition jit.h:179
static void MarkAsNotLoaded(Informations *j)
Mark the attached object as not loaded.
Definition jit.cpp:101