From 742629ca1e86180b1e96f6f996325e75350284ce Mon Sep 17 00:00:00 2001 From: XavierAdriaens <xavier.adriaens@doct.uliege.be> Date: Tue, 27 Jul 2021 12:37:03 +0200 Subject: [PATCH] Reduce wave::operator[] cost --- common/wave/element.cpp | 8 ++++++-- common/wave/element.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/wave/element.cpp b/common/wave/element.cpp index fda4158..45d183c 100644 --- a/common/wave/element.cpp +++ b/common/wave/element.cpp @@ -18,8 +18,12 @@ void WaveMultiField<T_Physic>::initializeField(const WaveField<T_Physic>& field) template<Physic T_Physic> const WaveField<T_Physic>& WaveMultiField<T_Physic>::operator[](const unsigned int index) const { - _field.setAllVector(_dofValues[index], gmshfem::dofs::RawOrder::Hash); - return _field; + if(index!=_index) + { + _field.setAllVector(_dofValues[index], gmshfem::dofs::RawOrder::Hash); + _index=index; + } + return _field; } template<Physic T_Physic> diff --git a/common/wave/element.h b/common/wave/element.h index 26a8295..bd5f2fc 100644 --- a/common/wave/element.h +++ b/common/wave/element.h @@ -19,8 +19,9 @@ private: mutable WaveField<T_Physic> _field; bool _isInitialized; std::vector< gmshfem::algebra::Vector< std::complex< double > > > _dofValues; + mutable unsigned int _index; public: - WaveMultiField(unsigned int n, const std::string& name = "") : _field(), _isInitialized(false), _dofValues(n) {_field.name(name);}; + WaveMultiField(unsigned int n, const std::string& name = "") : _field(), _isInitialized(false), _dofValues(n), _index(n+1) {_field.name(name);}; void initializeField(const WaveField<T_Physic>& field); bool isInitialized() const {return _isInitialized;}; -- GitLab