From f658fe817ed0ba7a118f4ec8ba6745d0aad6f68c Mon Sep 17 00:00:00 2001
From: Dmitry Yurov <d.yurov@fz-juelich.de>
Date: Fri, 27 Oct 2017 17:41:14 +0200
Subject: [PATCH] Default (vacuum) material factories

Redmine: #1858
---
 Core/Material/MaterialFactoryFuncs.cpp        | 14 ++++++++++++++
 Core/Material/MaterialFactoryFuncs.h          | 16 ++++++++++++++++
 Core/Material/RefractiveCoefMaterial.h        |  2 ++
 Core/Material/WavelengthIndependentMaterial.h |  2 ++
 Tests/UnitTests/Core/Other/MaterialTest.h     |  5 +++++
 5 files changed, 39 insertions(+)

diff --git a/Core/Material/MaterialFactoryFuncs.cpp b/Core/Material/MaterialFactoryFuncs.cpp
index eff5cf790e7..9f10cc4eea4 100644
--- a/Core/Material/MaterialFactoryFuncs.cpp
+++ b/Core/Material/MaterialFactoryFuncs.cpp
@@ -20,6 +20,13 @@ Material HomogeneousMaterial(const std::string& name, double delta, double beta,
     return Material(std::move(mat_impl));
 }
 
+Material HomogeneousMaterial()
+{
+    std::unique_ptr<RefractiveCoefMaterial> mat_impl(
+        new RefractiveCoefMaterial("vacuum", 0.0, 0.0, kvector_t{}));
+    return Material(std::move(mat_impl));
+}
+
 Material MaterialBySLD(const std::string& name, double sld, double abs_term,
                        kvector_t magnetization)
 {
@@ -36,3 +43,10 @@ Material MaterialByAbsCX(const std::string& name, double sld, double abs_cx,
         new WavelengthIndependentMaterial(name, sld, abs_cx / basic_wavelength, magnetization));
     return Material(std::move(mat_impl));
 }
+
+Material MaterialBySLD()
+{
+    std::unique_ptr<WavelengthIndependentMaterial> mat_impl(
+        new WavelengthIndependentMaterial("vacuum", 0.0, 0.0, kvector_t{}));
+    return Material(std::move(mat_impl));
+}
diff --git a/Core/Material/MaterialFactoryFuncs.h b/Core/Material/MaterialFactoryFuncs.h
index 88912df502e..70507d2db0c 100644
--- a/Core/Material/MaterialFactoryFuncs.h
+++ b/Core/Material/MaterialFactoryFuncs.h
@@ -35,6 +35,14 @@ BA_CORE_API_ Material HomogeneousMaterial(const std::string& name, double delta,
 
 //! @ingroup materials
 
+//! Constructs vacuum material based on refractive coefficients.
+//! Though in practice there is no difference between vacuum materials
+//! produced with MaterialBySLD() and HomogeneousMaterial(), they are not equal because of
+//! the difference in the type of underlying data
+BA_CORE_API_ Material HomogeneousMaterial();
+
+//! @ingroup materials
+
 //! Constructs a wavelength-independent material with given sld and absorptive term
 //! Absorptive term is wavelength-independent (normalized to a wavelength)
 //! and can be considered as inverse of imaginary part of complex scattering length density:
@@ -60,4 +68,12 @@ BA_CORE_API_ Material MaterialBySLD(const std::string& name, double sld, double
 BA_CORE_API_ Material MaterialByAbsCX(const std::string& name, double sld, double abs_cx,
                                       kvector_t magnetization = kvector_t());
 
+//! @ingroup materials
+
+//! Constructs wavelength-independent vacuum material.
+//! Though in practice there is no difference between vacuum materials
+//! produced with MaterialBySLD() and HomogeneousMaterial(), they are not equal because of
+//! the difference in the type of underlying data
+BA_CORE_API_ Material MaterialBySLD();
+
 #endif /* MATERIALFACTORYFUNCS_H_ */
diff --git a/Core/Material/RefractiveCoefMaterial.h b/Core/Material/RefractiveCoefMaterial.h
index dcbb7f276a7..1cda87d0298 100644
--- a/Core/Material/RefractiveCoefMaterial.h
+++ b/Core/Material/RefractiveCoefMaterial.h
@@ -30,6 +30,8 @@ public:
     friend BA_CORE_API_ Material HomogeneousMaterial(const std::string&, double, double,
                                                          kvector_t);
 
+    friend BA_CORE_API_ Material HomogeneousMaterial();
+
     virtual ~RefractiveCoefMaterial();
 
     //! Returns pointer to a copy of material
diff --git a/Core/Material/WavelengthIndependentMaterial.h b/Core/Material/WavelengthIndependentMaterial.h
index bd3f0f59ddc..dff7c2259cd 100644
--- a/Core/Material/WavelengthIndependentMaterial.h
+++ b/Core/Material/WavelengthIndependentMaterial.h
@@ -29,6 +29,8 @@ public:
 
     friend BA_CORE_API_ Material MaterialByAbsCX(const std::string&, double, double, kvector_t);
 
+    friend BA_CORE_API_ Material MaterialBySLD();
+
     virtual ~WavelengthIndependentMaterial();
 
     //! Returns pointer to a copy of material
diff --git a/Tests/UnitTests/Core/Other/MaterialTest.h b/Tests/UnitTests/Core/Other/MaterialTest.h
index bb0636417b2..0c5e9527050 100644
--- a/Tests/UnitTests/Core/Other/MaterialTest.h
+++ b/Tests/UnitTests/Core/Other/MaterialTest.h
@@ -131,6 +131,11 @@ TEST_F(MaterialTest, EqualityTest)
     EXPECT_DOUBLE_EQ(material.materialData().real(), material3.materialData().real());
     EXPECT_DOUBLE_EQ(material.materialData().imag(), material3.materialData().imag());
     EXPECT_TRUE(material.dataType() == material3.dataType());
+
+    EXPECT_EQ(HomogeneousMaterial().getName(), MaterialBySLD().getName());
+    EXPECT_EQ(HomogeneousMaterial().materialData(), MaterialBySLD().materialData());
+    EXPECT_EQ(HomogeneousMaterial().magnetization(), MaterialBySLD().magnetization());
+    EXPECT_FALSE(HomogeneousMaterial() == MaterialBySLD());
 }
 
 TEST_F(MaterialTest, MaterialCopy)
-- 
GitLab