Skip to content

Commit

Permalink
Lattice
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethassogba committed Nov 26, 2024
1 parent ae48597 commit a3be41c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main() {

for (const auto* c : {&UO2cell, &H2Ocell}) std::cout << *c << '\n';

// Lattice assm00{{uo2_cell, uo2_cell}};
Lattice assm00{{UO2cell, H2Ocell}, "assm00"};
// Lattice assm01{{uo2_cell, uo2_cell}};
// Lattice assm10{{uo2_cell, uo2_cell}};
// Lattice assm11{{uo2_cell, uo2_cell}};
Expand Down
2 changes: 1 addition & 1 deletion src/demeter/model/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Cell {
check();
}

Cell(double side, std::vector<double>& radii,
Cell(double side, const std::vector<double>& radii,
std::vector<std::reference_wrapper<Material>>&& materials,
std::string_view name = "")
: side_(side),
Expand Down
13 changes: 8 additions & 5 deletions src/demeter/model/lattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Demeter {
std::string Lattice::print() const {
std::string s = "Lattice:\n";
for (const auto& c : cells_) {
s += c.get().print(false);
}
return s;
std::ostringstream s;
s << "Lattice:" << name_ << "\n";
// if cell, print the cells, else print the cells inside the lattices

// for (const auto& c : components_) {
// s += c.get().print(false);
// }
return s.str();
}

} // namespace Demeter
23 changes: 10 additions & 13 deletions src/demeter/model/lattice.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
#pragma once

#include <vector>
#include <initializer_list>
#include <variant>
#include <iostream>
#include <string_view>

#include "demeter/model/cell.hpp"

namespace Demeter {

class Lattice {
public:
Lattice(std::vector<std::reference_wrapper<Cell>>&& cells,
std::string name = "")
: cells_(std::move(cells)), name_(name) {}
using FillType = std::variant<std::reference_wrapper<Cell>,
std::reference_wrapper<Lattice>>;

// Lattice(std::initializer_list<std::reference_wrapper<Cell>>& cells,
// std::string name = "")
// : cells_(cells), name_(name) {}
public:
Lattice(std::vector<FillType>&& components, std::string_view name = "")
: components_(std::move(components)), name_(name) {}

std::vector<std::reference_wrapper<Cell>>& cells() { return cells_; }
const std::vector<std::reference_wrapper<Cell>>& cells() const {
return cells_;
}
auto& components() { return components_; }
const auto& components() const { return components_; }

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::vector<FillType> components_; // TODO use matrix

std::string name_;
};
Expand Down

0 comments on commit a3be41c

Please sign in to comment.