From 7b2d20340426ccdd0bd9dbc73b73f5dfb6875727 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Thu, 16 Dec 2021 18:35:24 +0100 Subject: [PATCH] still broken, decouple Sample from Resample --- Resample/Particle/IReParticle.h | 4 +- Resample/Processed/Slicer.cpp | 103 ++++++++++++++++++++++++ Sample/Particle/Crystal.cpp | 1 - Sample/Particle/IParticle.cpp | 1 - Sample/Particle/IParticle.h | 5 -- Sample/Particle/MesoCrystal.cpp | 34 -------- Sample/Particle/MesoCrystal.h | 2 - Sample/Particle/Particle.cpp | 17 ---- Sample/Particle/Particle.h | 2 - Sample/Particle/ParticleComposition.cpp | 8 -- Sample/Particle/ParticleComposition.h | 2 - Sample/Particle/ParticleCoreShell.cpp | 46 ----------- Sample/Particle/ParticleCoreShell.h | 2 - Sample/Scattering/IBornFF.cpp | 1 - 14 files changed, 104 insertions(+), 124 deletions(-) diff --git a/Resample/Particle/IReParticle.h b/Resample/Particle/IReParticle.h index 6bedb92d6be..58415fa01d1 100644 --- a/Resample/Particle/IReParticle.h +++ b/Resample/Particle/IReParticle.h @@ -17,7 +17,6 @@ #define BORNAGAIN_RESAMPLE_PARTICLE_IREPARTICLE_H #include "Base/Types/ICloneable.h" -#include "Param/Node/INode.h" #include "Sample/Scattering/ZLimits.h" #include <Eigen/Core> #include <heinz/Complex.h> @@ -33,10 +32,9 @@ class WavevectorInfo; //! which depends on the incoming and outgoing wave vectors ki and kf. //! If it only depends on the scattering vector q=ki-kf, then it is a DecoratedBorn. -class IReParticle : public ICloneable, public INode { +class IReParticle : public ICloneable { protected: IReParticle() = default; - IReParticle(const NodeMeta& meta, const std::vector<double>& PValues); public: ~IReParticle() override = default; diff --git a/Resample/Processed/Slicer.cpp b/Resample/Processed/Slicer.cpp index 30dd08be2fe..e750f580e2e 100644 --- a/Resample/Processed/Slicer.cpp +++ b/Resample/Processed/Slicer.cpp @@ -15,6 +15,12 @@ #include "Sample/Processed/Slicer.h" #include "Resample/Particle/ReParticle.h" #include "Sample/HardParticle/HardParticles.h" +#include "Resample/Particle/ReCoreShell.h" +#include "Resample/Particle/ParticleInSlice.h" +#include "Resample/Particle/ReMesocrystal.h" +#include "Resample/Particle/ReCompound.h" +#include "Resample/Particle/ReParticle.h" +#include "Sample/Material/MaterialFactoryFuncs.h" namespace { @@ -267,3 +273,100 @@ ReParticle* preprocessor::createSlicedFormFactor(IBornFF& ff, throw std::runtime_error("Slicing of " + className() + " not supported for the given rotation!"); } + + +ParticleInSlice ParticleCoreShell::createParticleInSlice(const ZLimits& limits) const +{ + ASSERT(m_core && m_shell); + + // core + std::unique_ptr<Particle> P_core(m_core->clone()); + if (m_rotation) + P_core->rotate(*m_rotation); + P_core->translate(m_position); + auto sliced_core = P_core->createParticleInSlice(limits); + + // shell + std::unique_ptr<Particle> P_shell(m_shell->clone()); + if (m_rotation) + P_shell->rotate(*m_rotation); + P_shell->translate(m_position); + auto sliced_shell = P_shell->createParticleInSlice(limits); + if (!sliced_shell.sliced_ff) + return {}; + + ParticleInSlice result; + // if core out of limits, return sliced shell + if (!sliced_core.sliced_ff) { + result.sliced_ff = std::move(sliced_shell.sliced_ff); + result.admixtures.push_back(sliced_shell.admixtures.back()); + return result; + } + + // set core ambient material + if (sliced_shell.admixtures.size() != 1) + return {}; + auto shell_material = sliced_shell.admixtures[0].material; + sliced_core.sliced_ff->setAmbientMaterial(shell_material); + + // construct sliced particle + sliced_shell.admixtures.back().fraction -= sliced_core.admixtures.back().fraction; + result.sliced_ff = std::make_unique<ReCoreShell>(sliced_core.sliced_ff.release(), + sliced_shell.sliced_ff.release()); + result.admixtures.push_back(sliced_core.admixtures.back()); + result.admixtures.push_back(sliced_shell.admixtures.back()); + + return result; +} + +ParticleInSlice MesoCrystal::createParticleInSlice(const ZLimits& limits) const +{ + ASSERT(m_crystal && m_meso_formfactor); + + double unit_cell_volume = m_crystal->lattice()->unitCellVolume(); + if (unit_cell_volume <= 0) + return {}; + + ParticleInSlice result; + + std::unique_ptr<ReParticle> tem_ff( + m_meso_formfactor->createSlicedFormFactor(limits, m_rotation.get(), m_position)); + + const std::unique_ptr<Crystal> new_crystal( + m_crystal->transformed(m_rotation.get(), m_position)); + const std::unique_ptr<IReParticle> new_basis_ff(new_crystal->basis()->createFormFactor()); + + result.sliced_ff.reset(new ReMesocrystal(*new_crystal->lattice(), *new_basis_ff, *tem_ff, + new_crystal->position_variance())); + + Admixtures& regions = result.admixtures; + ASSERT(regions.empty()); + for (const auto& particle : m_crystal->basis()->decompose()) { + ParticleInSlice pis = particle->createParticleInSlice({}); + regions.insert(regions.end(), pis.admixtures.begin(), pis.admixtures.end()); + } + for (auto& region : regions) + region.fraction *= m_meso_formfactor->volume() / unit_cell_volume; + + return result; +} + +ParticleInSlice ParticleComposition::createParticleInSlice(const ZLimits&) const +{ + throw std::runtime_error("ParticleComposition does not yet support slicing"); +} + + +ParticleInSlice Particle::createParticleInSlice(const ZLimits& limits) const +{ + ASSERT(m_formfactor); + std::unique_ptr<ReParticle> sliced_ff( + m_formfactor->createSlicedFormFactor(limits, m_rotation.get(), m_position)); + if (!sliced_ff) + return {}; + double volume = sliced_ff->volume(); + Material transformed_material(m_rotation ? m_material.rotatedMaterial(m_rotation->rotMatrix()) + : m_material); + sliced_ff->setMaterial(transformed_material); + return {std::move(sliced_ff), {{{volume, transformed_material}}}}; +} diff --git a/Sample/Particle/Crystal.cpp b/Sample/Particle/Crystal.cpp index d77ee179ca0..9a0fb105b78 100644 --- a/Sample/Particle/Crystal.cpp +++ b/Sample/Particle/Crystal.cpp @@ -17,7 +17,6 @@ #include "Sample/Lattice/Lattice3D.h" #include "Sample/Particle/Particle.h" #include "Sample/Particle/ParticleComposition.h" -#include "Resample/Particle/ParticleInSlice.h" #include "Sample/Scattering/Rotations.h" Crystal::Crystal(const IParticle& basis, const Lattice3D& lattice, double position_variance) diff --git a/Sample/Particle/IParticle.cpp b/Sample/Particle/IParticle.cpp index c4774207557..2e119301984 100644 --- a/Sample/Particle/IParticle.cpp +++ b/Sample/Particle/IParticle.cpp @@ -13,7 +13,6 @@ // ************************************************************************************************ #include "Sample/Particle/IParticle.h" -#include "Resample/Particle/ParticleInSlice.h" #include "Sample/Scattering/Rotations.h" IParticle::~IParticle() = default; diff --git a/Sample/Particle/IParticle.h b/Sample/Particle/IParticle.h index b8525dd62b4..296530c67b2 100644 --- a/Sample/Particle/IParticle.h +++ b/Sample/Particle/IParticle.h @@ -21,10 +21,8 @@ #include <memory> #include <vector> -struct ParticleInSlice; class Rotations; class ZLimits; -class IReParticle; class IRotation; //! Abstract base class for Particle, ParticleComposition, ParticleCoreShell, MesoCrystal. @@ -42,9 +40,6 @@ public: //! Creates a form factor for this particle virtual IReParticle* createFormFactor() const; - //! Creates a sliced form factor for this particle - virtual ParticleInSlice createParticleInSlice(const ZLimits& limits) const = 0; - double abundance() const { return m_abundance; } //! Sets particle abundance. diff --git a/Sample/Particle/MesoCrystal.cpp b/Sample/Particle/MesoCrystal.cpp index 4822ab3cf13..cf93321ceeb 100644 --- a/Sample/Particle/MesoCrystal.cpp +++ b/Sample/Particle/MesoCrystal.cpp @@ -15,8 +15,6 @@ #include "Sample/Particle/MesoCrystal.h" #include "Base/Util/Assert.h" #include "Sample/Particle/Crystal.h" -#include "Resample/Particle/ReMesocrystal.h" -#include "Resample/Particle/ParticleInSlice.h" #include "Sample/Scattering/IBornFF.h" #include "Sample/Scattering/Rotations.h" @@ -48,38 +46,6 @@ std::vector<const INode*> MesoCrystal::nodeChildren() const << IParticle::nodeChildren() << m_crystal << m_meso_formfactor; } -ParticleInSlice MesoCrystal::createParticleInSlice(const ZLimits& limits) const -{ - ASSERT(m_crystal && m_meso_formfactor); - - double unit_cell_volume = m_crystal->lattice()->unitCellVolume(); - if (unit_cell_volume <= 0) - return {}; - - ParticleInSlice result; - - std::unique_ptr<ReParticle> tem_ff( - m_meso_formfactor->createSlicedFormFactor(limits, m_rotation.get(), m_position)); - - const std::unique_ptr<Crystal> new_crystal( - m_crystal->transformed(m_rotation.get(), m_position)); - const std::unique_ptr<IReParticle> new_basis_ff(new_crystal->basis()->createFormFactor()); - - result.sliced_ff.reset(new ReMesocrystal(*new_crystal->lattice(), *new_basis_ff, *tem_ff, - new_crystal->position_variance())); - - Admixtures& regions = result.admixtures; - ASSERT(regions.empty()); - for (const auto& particle : m_crystal->basis()->decompose()) { - ParticleInSlice pis = particle->createParticleInSlice({}); - regions.insert(regions.end(), pis.admixtures.begin(), pis.admixtures.end()); - } - for (auto& region : regions) - region.fraction *= m_meso_formfactor->volume() / unit_cell_volume; - - return result; -} - const Crystal& MesoCrystal::particleStructure() const { ASSERT(m_crystal); diff --git a/Sample/Particle/MesoCrystal.h b/Sample/Particle/MesoCrystal.h index fbda66d7ce8..da248d6620a 100644 --- a/Sample/Particle/MesoCrystal.h +++ b/Sample/Particle/MesoCrystal.h @@ -34,8 +34,6 @@ public: std::string className() const final { return "MesoCrystal"; } std::vector<const INode*> nodeChildren() const override; - ParticleInSlice createParticleInSlice(const ZLimits& limits) const override; - const IBornFF* outerShape() const { return m_meso_formfactor.get(); } const Crystal& particleStructure() const; diff --git a/Sample/Particle/Particle.cpp b/Sample/Particle/Particle.cpp index 8bd159a3c5c..eca525d210d 100644 --- a/Sample/Particle/Particle.cpp +++ b/Sample/Particle/Particle.cpp @@ -15,9 +15,6 @@ #include "Sample/Particle/Particle.h" #include "Base/Util/Assert.h" #include "Base/Vector/RotMatrix.h" -#include "Sample/Material/MaterialFactoryFuncs.h" -#include "Resample/Particle/ParticleInSlice.h" -#include "Resample/Particle/ReParticle.h" #include "Sample/Scattering/Rotations.h" Particle::Particle(Material material, const IBornFF& formfactor) @@ -49,17 +46,3 @@ std::vector<const INode*> Particle::nodeChildren() const { return std::vector<const INode*>() << IParticle::nodeChildren() << m_formfactor; } - -ParticleInSlice Particle::createParticleInSlice(const ZLimits& limits) const -{ - ASSERT(m_formfactor); - std::unique_ptr<ReParticle> sliced_ff( - m_formfactor->createSlicedFormFactor(limits, m_rotation.get(), m_position)); - if (!sliced_ff) - return {}; - double volume = sliced_ff->volume(); - Material transformed_material(m_rotation ? m_material.rotatedMaterial(m_rotation->rotMatrix()) - : m_material); - sliced_ff->setMaterial(transformed_material); - return {std::move(sliced_ff), {{{volume, transformed_material}}}}; -} diff --git a/Sample/Particle/Particle.h b/Sample/Particle/Particle.h index b25718342db..7c8a8af525d 100644 --- a/Sample/Particle/Particle.h +++ b/Sample/Particle/Particle.h @@ -32,8 +32,6 @@ public: std::string className() const override { return "Particle"; } std::vector<const INode*> nodeChildren() const override; - ParticleInSlice createParticleInSlice(const ZLimits& limits) const override; - const Material* material() const override { return &m_material; } const IBornFF* formFactor() const { return m_formfactor.get(); } diff --git a/Sample/Particle/ParticleComposition.cpp b/Sample/Particle/ParticleComposition.cpp index 05cb4fc153e..0371e326dff 100644 --- a/Sample/Particle/ParticleComposition.cpp +++ b/Sample/Particle/ParticleComposition.cpp @@ -14,8 +14,6 @@ #include "Sample/Particle/ParticleComposition.h" #include "Base/Util/Assert.h" -#include "Resample/Particle/ReCompound.h" -#include "Resample/Particle/ParticleInSlice.h" #include "Sample/Scattering/Rotations.h" ParticleComposition::ParticleComposition() {} @@ -85,12 +83,6 @@ IReParticle* ParticleComposition::createFormFactor() const return result; } -ParticleInSlice ParticleComposition::createParticleInSlice(const ZLimits&) const -{ - throw std::runtime_error("ParticleComposition does not yet support slicing"); -} - - void ParticleComposition::addParticle(const IParticle& particle) { m_particles.emplace_back(particle.clone()); diff --git a/Sample/Particle/ParticleComposition.h b/Sample/Particle/ParticleComposition.h index d53e0211e68..df63d46e342 100644 --- a/Sample/Particle/ParticleComposition.h +++ b/Sample/Particle/ParticleComposition.h @@ -37,8 +37,6 @@ public: IReParticle* createFormFactor() const override; - ParticleInSlice createParticleInSlice(const ZLimits& limits) const override; - void addParticle(const IParticle& particle); void addParticle(const IParticle& particle, R3 position); void addParticles(const IParticle& particle, std::vector<R3> positions); diff --git a/Sample/Particle/ParticleCoreShell.cpp b/Sample/Particle/ParticleCoreShell.cpp index ac8a2fcb995..9cf3d5d58e8 100644 --- a/Sample/Particle/ParticleCoreShell.cpp +++ b/Sample/Particle/ParticleCoreShell.cpp @@ -15,9 +15,7 @@ #include "Sample/Particle/ParticleCoreShell.h" #include "Base/Util/Assert.h" -#include "Resample/Particle/ReCoreShell.h" #include "Sample/Particle/Particle.h" -#include "Resample/Particle/ParticleInSlice.h" #include "Sample/Scattering/Rotations.h" #include <memory> @@ -45,47 +43,3 @@ std::vector<const INode*> ParticleCoreShell::nodeChildren() const { return std::vector<const INode*>() << IParticle::nodeChildren() << m_core << m_shell; } - -ParticleInSlice ParticleCoreShell::createParticleInSlice(const ZLimits& limits) const -{ - ASSERT(m_core && m_shell); - - // core - std::unique_ptr<Particle> P_core(m_core->clone()); - if (m_rotation) - P_core->rotate(*m_rotation); - P_core->translate(m_position); - auto sliced_core = P_core->createParticleInSlice(limits); - - // shell - std::unique_ptr<Particle> P_shell(m_shell->clone()); - if (m_rotation) - P_shell->rotate(*m_rotation); - P_shell->translate(m_position); - auto sliced_shell = P_shell->createParticleInSlice(limits); - if (!sliced_shell.sliced_ff) - return {}; - - ParticleInSlice result; - // if core out of limits, return sliced shell - if (!sliced_core.sliced_ff) { - result.sliced_ff = std::move(sliced_shell.sliced_ff); - result.admixtures.push_back(sliced_shell.admixtures.back()); - return result; - } - - // set core ambient material - if (sliced_shell.admixtures.size() != 1) - return {}; - auto shell_material = sliced_shell.admixtures[0].material; - sliced_core.sliced_ff->setAmbientMaterial(shell_material); - - // construct sliced particle - sliced_shell.admixtures.back().fraction -= sliced_core.admixtures.back().fraction; - result.sliced_ff = std::make_unique<ReCoreShell>(sliced_core.sliced_ff.release(), - sliced_shell.sliced_ff.release()); - result.admixtures.push_back(sliced_core.admixtures.back()); - result.admixtures.push_back(sliced_shell.admixtures.back()); - - return result; -} diff --git a/Sample/Particle/ParticleCoreShell.h b/Sample/Particle/ParticleCoreShell.h index 1b6ab462d71..6f24dbc90dc 100644 --- a/Sample/Particle/ParticleCoreShell.h +++ b/Sample/Particle/ParticleCoreShell.h @@ -32,8 +32,6 @@ public: std::string className() const final { return "ParticleCoreShell"; } std::vector<const INode*> nodeChildren() const override; - ParticleInSlice createParticleInSlice(const ZLimits& limits) const override; - const Particle* shellParticle() const { return m_shell.get(); } const Particle* coreParticle() const { return m_core.get(); } diff --git a/Sample/Scattering/IBornFF.cpp b/Sample/Scattering/IBornFF.cpp index 47f0e3c79f0..629d033cd2c 100644 --- a/Sample/Scattering/IBornFF.cpp +++ b/Sample/Scattering/IBornFF.cpp @@ -20,7 +20,6 @@ #include "Base/Vector/WavevectorInfo.h" #include "Sample/Scattering/Rotations.h" #include "Sample/Shapes/IShape3D.h" -#include "Resample/Processed/Slicer.h" #include <stdexcept> #include <utility> -- GitLab