From cb0cf10edc6dac5c3aa807ca8d581cd53080e5a9 Mon Sep 17 00:00:00 2001 From: Kenneth Assogba Date: Tue, 26 Nov 2024 00:34:15 +0100 Subject: [PATCH] Add Lattice class for assemblies and core --- examples/main.cpp | 7 ++++++ src/demeter/model.hpp | 3 ++- src/demeter/model/cell.cpp | 7 +++--- src/demeter/model/cell.hpp | 4 ++-- src/demeter/model/lattice.cpp | 12 ++++++++++ src/demeter/model/lattice.hpp | 42 ++++++++++++++++++++++++++++++++++ src/demeter/model/material.hpp | 10 ++++---- 7 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 src/demeter/model/lattice.cpp create mode 100644 src/demeter/model/lattice.hpp diff --git a/examples/main.cpp b/examples/main.cpp index 1a2ad85..32095df 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -23,5 +23,12 @@ int main() { Cell uo2_cell(1.0, uo2, "UO2"); std::cout << uo2_cell << std::endl; + // Lattice assm00{{uo2_cell, uo2_cell}}; + // Lattice assm01{{uo2_cell, uo2_cell}}; + // Lattice assm10{{uo2_cell, uo2_cell}}; + // Lattice assm11{{uo2_cell, uo2_cell}}; + + // Lattice core{{assm00, assm01, assm10, assm11}}; + return 0; } \ No newline at end of file diff --git a/src/demeter/model.hpp b/src/demeter/model.hpp index b700f29..fe31217 100644 --- a/src/demeter/model.hpp +++ b/src/demeter/model.hpp @@ -1,4 +1,5 @@ #pragma once #include "model/cell.hpp" -#include "model/material.hpp" \ No newline at end of file +#include "model/material.hpp" +#include "model/lattice.hpp" \ No newline at end of file diff --git a/src/demeter/model/cell.cpp b/src/demeter/model/cell.cpp index dad71dd..edb3a94 100644 --- a/src/demeter/model/cell.cpp +++ b/src/demeter/model/cell.cpp @@ -6,13 +6,12 @@ void Cell::check() const { assert(materials_.size() == radii_.size() + 1); } -std::string Cell::print() const { +std::string Cell::print(bool full) const { std::ostringstream ss; ss << "Cell " << name_ << " has " << radii_.size() << " rings and " << materials_.size() << " materials:\n"; - for (const auto& m : materials_) { - ss << " * " << m.get().print(); - } + if (full) + for (const auto& m : materials_) ss << " * " << m.get().print(); return ss.str(); } } // namespace Demeter \ No newline at end of file diff --git a/src/demeter/model/cell.hpp b/src/demeter/model/cell.hpp index baa45c7..51933ac 100644 --- a/src/demeter/model/cell.hpp +++ b/src/demeter/model/cell.hpp @@ -27,9 +27,9 @@ class Cell { check(); } - std::string print() const; + std::string print(bool full = false) const; friend std::ostream& operator<<(std::ostream& os, const Cell& c) { - return os << c.print(); + return os << c.print(true); } private: diff --git a/src/demeter/model/lattice.cpp b/src/demeter/model/lattice.cpp new file mode 100644 index 0000000..e9eb824 --- /dev/null +++ b/src/demeter/model/lattice.cpp @@ -0,0 +1,12 @@ +#include "lattice.hpp" + +namespace Demeter { +std::string Lattice::print() const { + std::string s = "Lattice:\n"; + for (const auto& c : cells_) { + s += c.get().print(false); + } + return s; +} + +} // namespace Demeter \ No newline at end of file diff --git a/src/demeter/model/lattice.hpp b/src/demeter/model/lattice.hpp new file mode 100644 index 0000000..64a58c7 --- /dev/null +++ b/src/demeter/model/lattice.hpp @@ -0,0 +1,42 @@ +/** + * @file lattice.hpp + * @author Kenneth Assogba + * @brief Lattice class + */ + +#pragma once + +#include +#include +#include + +#include "demeter/model/cell.hpp" + +namespace Demeter { + +class Lattice { + public: + Lattice(std::vector>& cells, + std::string name = "") + : cells_(cells), name_(name) {} + Lattice(std::initializer_list>& cells, + std::string name = "") + : cells_(cells), name_(name) {} + + std::vector>& cells() { return cells_; } + const std::vector>& cells() const { + return cells_; + } + + friend std::ostream& operator<<(std::ostream& os, const Lattice& l) { + return os << l.print(); + } + std::string print() const; + + private: + std::vector> cells_; + + std::string name_; +}; + +} // namespace Demeter \ No newline at end of file diff --git a/src/demeter/model/material.hpp b/src/demeter/model/material.hpp index e3c2839..07d5fb5 100644 --- a/src/demeter/model/material.hpp +++ b/src/demeter/model/material.hpp @@ -46,6 +46,8 @@ class Material { auto name() const { return name_; } auto NumEnergyGroups() const { return num_groups_; } + bool fissile() const { return fissile_; } + const auto& SigmaT() const { return sigma_t_; } auto MaxSigmaT() const { return sigma_t_.maxCoeff(); }; const auto& SigmaS() const { return sigma_s_; } @@ -53,15 +55,15 @@ class Material { const auto& SigmaF() const { return sigma_f_; } const auto& NuSigmaF() const { return nu_sigma_f_; } const auto& Chi() const { return chi_; } + auto SigmaT(Index group) const { return sigma_t_(check(group)); } - auto SigmaS(Index from, Index to) const { - return sigma_s_(check(from), check(to)); - }; auto SigmaA(Index group) const { return sigma_a_(check(group)); } auto SigmaF(Index group) const { return sigma_f_(check(group)); }; auto NuSigmaF(Index group) const { return nu_sigma_f_(check(group)); }; auto Chi(Index group) const { return chi_(check(group)); }; - bool fissile() const { return fissile_; } + auto SigmaS(Index from, Index to) const { + return sigma_s_(check(from), check(to)); + }; friend void swap(Material& a, Material& b) { using std::swap;