From d648e04f1d5d54422e82b9bfddf673a10cda0a53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu>
Date: Tue, 31 Mar 2020 19:00:04 +0200
Subject: [PATCH] New method HasStateBlocks::perturb()

---
 include/core/state_block/has_state_blocks.h | 5 ++++-
 src/state_block/has_state_blocks.cpp        | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/core/state_block/has_state_blocks.h b/include/core/state_block/has_state_blocks.h
index 0f7d13f99..ef55d163b 100644
--- a/include/core/state_block/has_state_blocks.h
+++ b/include/core/state_block/has_state_blocks.h
@@ -68,6 +68,10 @@ class HasStateBlocks
         unsigned int    getSize() const;
         unsigned int    getLocalSize() const;
 
+        // Perturb state
+        void            perturb(double amplitude = 0.01);
+
+
     private:
         std::string structure_;
         std::unordered_map<std::string, StateBlockPtr> state_block_map_;
@@ -251,6 +255,5 @@ inline unsigned int HasStateBlocks::getLocalSize() const
     return size;
 }
 
-
 } // namespace wolf
 #endif /* STATE_BLOCK_HAS_STATE_BLOCKS_H_ */
diff --git a/src/state_block/has_state_blocks.cpp b/src/state_block/has_state_blocks.cpp
index 8b11f1cb3..83cf44b26 100644
--- a/src/state_block/has_state_blocks.cpp
+++ b/src/state_block/has_state_blocks.cpp
@@ -44,5 +44,14 @@ void HasStateBlocks::removeStateBlocks(ProblemPtr _problem)
     }
 }
 
+void HasStateBlocks::perturb(double amplitude)
+{
+    for (const auto& pair_key_sb : state_block_map_)
+    {
+        auto& sb = pair_key_sb.second;
+        if (!sb->isFixed())
+            sb->perturb(amplitude);
+    }
+}
 
 }
-- 
GitLab