From 7ccdf7633e9f0aaca177977680b89dfe725bce6b Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de> Date: Tue, 6 Aug 2024 19:28:18 +0200 Subject: [PATCH] LayerInterface always has non-nullptr roughness --- Sample/Interface/LayerInterface.cpp | 35 +++++++---------------------- Sample/Interface/LayerInterface.h | 14 +++--------- Sample/Multilayer/MultiLayer.cpp | 6 ++--- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/Sample/Interface/LayerInterface.cpp b/Sample/Interface/LayerInterface.cpp index 5b9e217f302..48cc3bb1732 100644 --- a/Sample/Interface/LayerInterface.cpp +++ b/Sample/Interface/LayerInterface.cpp @@ -16,10 +16,15 @@ #include "Base/Util/Assert.h" #include "Sample/Interface/LayerRoughness.h" -LayerInterface::LayerInterface() - : m_top_layer(nullptr) - , m_bottom_layer(nullptr) +LayerInterface::LayerInterface(const Layer* top_layer, const Layer* bottom_layer, + const LayerRoughness* layerRoughness) + : m_top_layer(top_layer) + , m_bottom_layer(bottom_layer) + , m_roughness(layerRoughness) { + ASSERT(top_layer); + ASSERT(bottom_layer); + ASSERT(layerRoughness); } LayerInterface::~LayerInterface() = default; @@ -29,35 +34,11 @@ LayerInterface* LayerInterface::clone() const throw std::runtime_error("LayerInterface::clone -> Not allowed to clone."); } -LayerInterface* LayerInterface::createInterface(const Layer* top_layer, const Layer* bottom_layer, - const LayerRoughness* roughness) -{ - auto* result = new LayerInterface(); - result->setLayersTopBottom(top_layer, bottom_layer); - if (roughness) - result->setRoughness(roughness); - return result; -} - -void LayerInterface::setRoughness(const LayerRoughness* roughness) -{ - m_roughness.reset(roughness); -} - std::vector<const INode*> LayerInterface::nodeChildren() const { return std::vector<const INode*>() << m_roughness; } -//! Sets links to the layers above and below the interface. - -void LayerInterface::setLayersTopBottom(const Layer* top_layer, const Layer* bottom_layer) -{ - ASSERT(top_layer && bottom_layer); - m_top_layer = top_layer; - m_bottom_layer = bottom_layer; -} - std::string LayerInterface::validate() const { return ""; diff --git a/Sample/Interface/LayerInterface.h b/Sample/Interface/LayerInterface.h index c598a428096..37c933c543f 100644 --- a/Sample/Interface/LayerInterface.h +++ b/Sample/Interface/LayerInterface.h @@ -24,22 +24,17 @@ class Layer; class LayerRoughness; -//! Interface between two layers, possibly with roughness. +//! Interface between two layers, always with roughness. class LayerInterface : public ISampleNode { public: + LayerInterface(const Layer* top_layer, const Layer* bottom_layer, + const LayerRoughness* layerRoughness); ~LayerInterface() override; LayerInterface* clone() const override; std::string className() const final { return "LayerInterface"; } - //! Creates rough interface between two layers - static LayerInterface* createInterface(const Layer* top_layer, const Layer* bottom_layer, - const LayerRoughness* roughness); - - //! Sets roughness of the interface. - void setRoughness(const LayerRoughness* roughness); - //! Returns roughness of the interface. const LayerRoughness* roughness() const; @@ -52,9 +47,6 @@ public: std::string validate() const override; private: - void setLayersTopBottom(const Layer* top_layer, const Layer* bottom_layer); - LayerInterface(); - const Layer* m_top_layer; //!< pointer to the layer above interface const Layer* m_bottom_layer; //!< pointer to the layer below interface std::unique_ptr<const LayerRoughness> m_roughness; //!< roughness of the interface diff --git a/Sample/Multilayer/MultiLayer.cpp b/Sample/Multilayer/MultiLayer.cpp index 38f5239b478..5b928298309 100644 --- a/Sample/Multilayer/MultiLayer.cpp +++ b/Sample/Multilayer/MultiLayer.cpp @@ -70,10 +70,8 @@ void MultiLayer::addLayerExec(const Layer& layer, const LayerRoughness* roughnes if (numberOfLayers()) { // not the top layer const Layer* last_layer = m_layers.back(); - const LayerRoughness* new_roughness = - roughness && roughness->sigma() != 0.0 ? roughness->clone() : nullptr; - m_interfaces.push_back( - LayerInterface::createInterface(last_layer, new_layer, new_roughness)); + const LayerRoughness* new_roughness = roughness ? roughness->clone() : new LayerRoughness; + m_interfaces.push_back(new LayerInterface(last_layer, new_layer, new_roughness)); } else { // the top layer if (new_layer->thickness() != 0.0) -- GitLab