From cfaf3020ec1779710a93cc326a95b98993c29796 Mon Sep 17 00:00:00 2001
From: Dmitry Yurov <d.yurov@fz-juelich.de>
Date: Sun, 29 Oct 2017 21:38:38 +0100
Subject: [PATCH] Creating averaged homogeneous material in MainComputation

Redmine: #1858

For now works only for wavelength-dependent material
---
 Core/Computation/MainComputation.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/Core/Computation/MainComputation.cpp b/Core/Computation/MainComputation.cpp
index f2004ccb7b4..d3f6085c324 100644
--- a/Core/Computation/MainComputation.cpp
+++ b/Core/Computation/MainComputation.cpp
@@ -25,12 +25,12 @@
 #include "ScalarFresnelMap.h"
 #include "ProgressHandler.h"
 #include "SimulationElement.h"
+#include "MaterialFactoryFuncs.h"
 
 namespace
 {
-Material CalculateAverageMaterial(const Material& layer_mat,
-                                             double wavelength,
-                                             const std::vector<HomogeneousRegion>& regions);
+Material CalculateAverageMaterial(const Material& layer_mat, double wavelength,
+                                  const std::vector<HomogeneousRegion>& regions);
 }
 
 MainComputation::MainComputation(
@@ -161,9 +161,9 @@ bool MainComputation::checkRegions(const std::vector<HomogeneousRegion>& regions
 
 namespace
 {
-Material CalculateAverageMaterial(const Material& layer_mat,
-                                             double wavelength,
-                                             const std::vector<HomogeneousRegion>& regions)
+// TODO: make this procedure correct for all types of materials
+Material CalculateAverageMaterial(const Material& layer_mat, double wavelength,
+                                  const std::vector<HomogeneousRegion>& regions)
 {
     kvector_t magnetization_layer = layer_mat.magnetization();
     complex_t refr_index2_layer = layer_mat.refractiveIndex2(wavelength);
@@ -177,7 +177,6 @@ Material CalculateAverageMaterial(const Material& layer_mat,
         refr_index2_avg += region.m_volume*(refr_index2_region - refr_index2_layer);
     }
     complex_t refr_index_avg = std::sqrt(refr_index2_avg);
-    Material result(layer_mat.getName()+"_avg", refr_index_avg, magnetization_avg);
-    return result;
+    return HomogeneousMaterial(layer_mat.getName() + "_avg", refr_index_avg, magnetization_avg);
 }
 }
-- 
GitLab