GCBM
dynamicgrowthcurvetransform.h
Go to the documentation of this file.
1 #ifndef MOJA_MODULES_CBM_DYNAMICGROWTHCURVETRANSFORM_H_
2 #define MOJA_MODULES_CBM_DYNAMICGROWTHCURVETRANSFORM_H_
3 
4 #include "moja/datarepository/iproviderrelationalinterface.h"
5 #include "moja/flint/ilandunitcontroller.h"
6 #include "moja/flint/itransform.h"
7 
8 #include <Poco/LRUCache.h>
9 #include <Poco/ThreadLocal.h>
10 
11 #include <atomic>
12 #include <map>
13 
14 namespace moja {
15 namespace modules {
16 namespace cbm {
17 
18 class DynamicGrowthCurveTransform : public flint::ITransform {
19 public:
21  std::shared_ptr<std::map<std::tuple<std::string, double, double>, DynamicVar>> gcIdCache,
22  std::shared_ptr<std::map<int, std::map<std::string, DynamicVar>>> gcCache,
23  std::shared_ptr<Poco::Mutex> cacheLock,
24  std::shared_ptr<std::atomic<int>> nextGcId
25  ) : _gcIdCache(gcIdCache), _gcCache(gcCache), _cacheLock(cacheLock), _nextGcId(nextGcId) { }
26 
27  void configure(DynamicObject config,
28  const flint::ILandUnitController& landUnitController,
29  datarepository::DataRepository& dataRepository) override;
30 
31  void controllerChanged(const flint::ILandUnitController& controller) override;
32  const DynamicVar& value() const override;
33 
34 private:
35  mutable int _maxAge = 300;
36  mutable int _incrementLength = 10;
37  mutable bool _debug = false;
38 
39  const flint::ILandUnitController* _landUnitController;
40  mutable const flint::IVariable* _csetVar;
41  mutable const flint::IVariable* _precipitationVar;
42  mutable const flint::IVariable* _growingDaysVar;
43  mutable const flint::IVariable* _volToBioVar;
44  mutable const flint::IVariable* _growthAndYieldParamsVar;
45  mutable DynamicVar _value;
46 
47  // Key: <species, mean annual precipitation, growing days>
48  std::shared_ptr<std::map<std::tuple<std::string, double, double>, DynamicVar>> _gcIdCache;
49  std::shared_ptr<std::map<int, std::map<std::string, DynamicVar>>> _gcCache;
50  std::shared_ptr<Poco::Mutex> _cacheLock;
51  std::shared_ptr<std::atomic<int>> _nextGcId;
52 };
53 
54 }}}
55 
56 #endif // MOJA_MODULES_CBM_DYNAMICGROWTHCURVETRANSFORM_H_
moja::modules::cbm
Definition: ageclasshelper.cpp:12
moja::modules::cbm::DynamicGrowthCurveTransform
Definition: dynamicgrowthcurvetransform.h:18
moja::modules::cbm::DynamicGrowthCurveTransform::_growthAndYieldParamsVar
const flint::IVariable * _growthAndYieldParamsVar
Definition: dynamicgrowthcurvetransform.h:44
moja::modules::cbm::DynamicGrowthCurveTransform::_debug
bool _debug
Definition: dynamicgrowthcurvetransform.h:37
moja::modules::cbm::DynamicGrowthCurveTransform::_gcCache
std::shared_ptr< std::map< int, std::map< std::string, DynamicVar > > > _gcCache
Definition: dynamicgrowthcurvetransform.h:49
moja::modules::cbm::DynamicGrowthCurveTransform::controllerChanged
void controllerChanged(const flint::ILandUnitController &controller) override
Definition: dynamicgrowthcurvetransform.cpp:69
moja::modules::cbm::DynamicGrowthCurveTransform::_nextGcId
std::shared_ptr< std::atomic< int > > _nextGcId
Definition: dynamicgrowthcurvetransform.h:51
moja::modules::cbm::DynamicGrowthCurveTransform::_gcIdCache
std::shared_ptr< std::map< std::tuple< std::string, double, double >, DynamicVar > > _gcIdCache
Definition: dynamicgrowthcurvetransform.h:48
moja::modules::cbm::DynamicGrowthCurveTransform::_landUnitController
const flint::ILandUnitController * _landUnitController
Definition: dynamicgrowthcurvetransform.h:39
moja::modules::cbm::DynamicGrowthCurveTransform::_maxAge
int _maxAge
Definition: dynamicgrowthcurvetransform.h:35
moja::modules::cbm::DynamicGrowthCurveTransform::_precipitationVar
const flint::IVariable * _precipitationVar
Definition: dynamicgrowthcurvetransform.h:41
moja::modules::cbm::DynamicGrowthCurveTransform::_volToBioVar
const flint::IVariable * _volToBioVar
Definition: dynamicgrowthcurvetransform.h:43
moja::modules::cbm::DynamicGrowthCurveTransform::_cacheLock
std::shared_ptr< Poco::Mutex > _cacheLock
Definition: dynamicgrowthcurvetransform.h:50
moja::modules::cbm::DynamicGrowthCurveTransform::DynamicGrowthCurveTransform
DynamicGrowthCurveTransform(std::shared_ptr< std::map< std::tuple< std::string, double, double >, DynamicVar >> gcIdCache, std::shared_ptr< std::map< int, std::map< std::string, DynamicVar >>> gcCache, std::shared_ptr< Poco::Mutex > cacheLock, std::shared_ptr< std::atomic< int >> nextGcId)
Definition: dynamicgrowthcurvetransform.h:20
moja::modules::cbm::DynamicGrowthCurveTransform::_value
DynamicVar _value
Definition: dynamicgrowthcurvetransform.h:45
moja::modules::cbm::DynamicGrowthCurveTransform::_incrementLength
int _incrementLength
Definition: dynamicgrowthcurvetransform.h:36
moja
Definition: ageclasshelper.cpp:10
moja::modules::cbm::DynamicGrowthCurveTransform::_csetVar
const flint::IVariable * _csetVar
Definition: dynamicgrowthcurvetransform.h:40
moja::modules::cbm::DynamicGrowthCurveTransform::_growingDaysVar
const flint::IVariable * _growingDaysVar
Definition: dynamicgrowthcurvetransform.h:42
moja::modules::cbm::DynamicGrowthCurveTransform::configure
void configure(DynamicObject config, const flint::ILandUnitController &landUnitController, datarepository::DataRepository &dataRepository) override
Definition: dynamicgrowthcurvetransform.cpp:38
moja::modules::cbm::DynamicGrowthCurveTransform::value
const DynamicVar & value() const override
Definition: dynamicgrowthcurvetransform.cpp:86