Skip to content

Commit

Permalink
Add Lattice class for assemblies and core
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethassogba committed Nov 25, 2024
1 parent 0e80e49 commit cb0cf10
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 11 deletions.
7 changes: 7 additions & 0 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion src/demeter/model.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "model/cell.hpp"
#include "model/material.hpp"
#include "model/material.hpp"
#include "model/lattice.hpp"
7 changes: 3 additions & 4 deletions src/demeter/model/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/demeter/model/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/demeter/model/lattice.cpp
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions src/demeter/model/lattice.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file lattice.hpp
* @author Kenneth Assogba
* @brief Lattice class
*/

#pragma once

#include <vector>
#include <initializer_list>
#include <iostream>

#include "demeter/model/cell.hpp"

namespace Demeter {

class Lattice {
public:
Lattice(std::vector<std::reference_wrapper<Cell>>& cells,
std::string name = "")
: cells_(cells), name_(name) {}
Lattice(std::initializer_list<std::reference_wrapper<Cell>>& cells,
std::string name = "")
: cells_(cells), name_(name) {}

std::vector<std::reference_wrapper<Cell>>& cells() { return cells_; }
const std::vector<std::reference_wrapper<Cell>>& 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<std::reference_wrapper<Cell>> cells_;

std::string name_;
};

} // namespace Demeter
10 changes: 6 additions & 4 deletions src/demeter/model/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,24 @@ 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_; }
const auto& SigmaA() const { return sigma_a_; }
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;
Expand Down

0 comments on commit cb0cf10

Please sign in to comment.