Skip to content

Commit

Permalink
Material
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethassogba committed Nov 24, 2024
1 parent 2727280 commit 94f52f2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
2 changes: 2 additions & 0 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ int main() {
Demeter::Material uo2(sigma_t, sigma_s, sigma_a, sigma_f, nu_sigma_f, chi,
"UO2");

std::cout << uo2 << std::endl;

return 0;
}
38 changes: 23 additions & 15 deletions examples/t1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.12.3' requires the ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/bin/python3 -m pip install ipykernel -U --user --force-reinstall'"
]
}
],
"outputs": [],
"source": [
"from demeter import *\n",
"import numpy as np\n",
Expand All @@ -27,17 +16,36 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Create materials\n",
"sigma_t = np.array([0.222222, 0.833333])\n",
"sigma_s = np.array([[0.00, 0.02],\n",
" [0.00, 0.00]])\n",
"sigma_a = np.array([0.010120, 0.080032])\n",
"sigma_f = np.array([0., 0.135])\n",
"nu_sigma_f = np.array([0., 0.135])\n",
"chi = np.array([1., 0.])\n",
"\n",
"uO2 = Material(sigma_t, sigma_s, sigma_a, sigma_f, nu_sigma_f, chi, name= 'uO2') # type: ignore"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "pyenv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/demeter/model/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ Material::Material(Material&& other)
fissile_(other.fissile_),
name_(other.name_) {}

std::string Material::print() const {
std::ostringstream ss;
ss << PRINTER(name_) << "; " << PRINTER(num_groups_) << "; "
<< "fissile_" << (fissile_ ? "True" : "False") << '\n';
return ss.str();
}

// TODO change assert since we also want to check in release
void Material::check() const { // TODO use fmt and a logger
if (not(num_groups_ > 0)) {
Expand Down
8 changes: 8 additions & 0 deletions src/demeter/model/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string_view>
#include <Eigen/Core>

#define PRINTER(x) #x << " = " << x

// TODO add optional xs and name
// TODO some material maybe not need all xs, make them optional
namespace Demeter {
Expand Down Expand Up @@ -38,6 +40,12 @@ class Material {
return *this;
}

std::string print() const;

friend std::ostream& operator<<(std::ostream& os, const Material& m) {
return os << m.print();
}

auto name() const { return name_; }
auto NumEnergyGroups() const { return num_groups_; }
const auto& SigmaT() const { return sigma_t_; }
Expand Down

0 comments on commit 94f52f2

Please sign in to comment.