5#include <nlohmann/json.hpp>
25int main(
int argc,
char** argv) {
27 printf(
"Usage: %s <input_file_name>\n", argv[0]);
33 std::filesystem::path working_directory(argv[1]);
34 working_directory.remove_filename();
44 fmt::print(
"Creating banks...");
46 BCBank bc_bank(user_input_json);
51 fmt::print(
"Creating quadrature sets...");
58 size_t n_ordinates = angular_quad.
get()->
n_points();
59 fmt::print(
"Done\n\n");
64 mesh.
ResolveIDs(material_bank, source_bank, bc_bank);
77 fmt::print(
"Beginning source iterations.\n\n");
80 std::valarray<double> old_scalar_flux(0.0, sem_problem.
get()->
n_dofs());
81 std::valarray<double> new_scalar_flux(0.0, sem_problem.
get()->
n_dofs());
92 for (
auto n = 0; n < n_ordinates; n++) {
97 mesh, gll_quad, material_bank, ordinate);
99 gll_quad, mesh, material_bank, source_bank, ordinate, n,
100 *angular_quad.
get());
105 sem_problem.
get()->
ApplyBCs(mesh, ordinate, bc_bank, n);
115 for (
auto i = 0; i < mesh.
n_nodes(); i++)
117 std::valarray<double> error = new_scalar_flux - old_scalar_flux;
119 double new_l2_error = 0;
120 double new_flux_l2 = 0;
121 for (
const auto& elem : mesh.
elements()) {
122 std::valarray<double> element_error(0.0, gll_quad.
n_points());
123 std::valarray<double> element_flux(0.0, gll_quad.
n_points());
124 for (
auto i = 0; i < gll_quad.
n_points(); i++) {
125 element_error[i] = error[elem->node_ids()[i]];
126 element_flux[i] = new_scalar_flux[elem->node_ids()[i]];
133 new_l2_error = std::sqrt(new_l2_error);
134 new_flux_l2 = std::sqrt(new_flux_l2);
138 ? (new_l2_error == 0.0 ? 0.0
139 : std::numeric_limits<double>::infinity())
140 : new_l2_error / new_flux_l2;
143 old_scalar_flux = new_scalar_flux;
144 new_scalar_flux = 0.0;
149 fmt::print(
"Exporting results...");
155 fmt::print(
"Done.\n\n");
Wrapper class that owns an angular QuadratureBase<Ordinate> of the type corresponding to the given An...
const QuadratureBase< Ordinate > * get() const
Get the underlying quadrature set object.
Bank holding the boundary conditions defined in the input file.
Class defining a 1D Gauss-Legendre-Lobatto quadrature set on [-1,1]. The quadrature set approximates ...
double IntegrateGridFunction(const std::valarray< double > &grid_function_vals)
Integrate a function defined on the abscissae given in the order the abscissae are stored.
Bank holding the materials defined in the input file.
const Node & GetNode(const size_t id) const
Get Node by ID.
void ResolveIDs(const MaterialBank &material_bank, const SourceBank &source_bank, const BCBank &bc_bank)
Resolve the raw gmsh Physical Group tags currently stored in material_id()/source_id()/bc_id (set fro...
size_t n_nodes() const
Get the number of nodes in the mesh.
void FindBoundaryNodes()
Populates the boundary_node_ids_ member. Must be called after ResolveIDs!
size_t n_elements() const
Get the number of Elements in the mesh.
const std::vector< Node > & nodes() const
Get the Nodes in the mesh.
void SetOutwardNormals()
Set the outward-pointing unit normal vector on each boundary node (Node::outward_normal),...
void InitializeNodeSolutions(const size_t n_ordinates, const QuadratureBase< Ordinate > &angular_quad_set, const SourceBank &source_bank)
Initialize node solution vectors to the correct lengths. Scalar and angular fluxes are set to 0 and s...
void UpdateNodeScalarFluxes(const QuadratureBase< Ordinate > &angular_quad_set)
Update the nodes' scalar flux values.
void Prepare(const GaussLobattoLegendre &gll_quadrature)
Prepare the mesh for running a simulation by generating interior nodes using the GLL quadrature set,...
void UpdateNodeAngularFluxes(const SEMProblem &sem_problem, const size_t n_ordinates)
Update the nodes' angular flux values.
unsigned int dimension() const
Get the spatial dimension of the mesh, derived from the elements it contains (e.g....
const std::vector< std::unique_ptr< Element > > & elements() const
Get the elements in the mesh.
void Solve(const size_t ordinate_index)
Solve the linear system using Armadillo's sparse matrix solver. Stores the results in the solution_ve...
virtual std::vector< GlobalForcingData > AssembleGlobalForcingData(const GaussLobattoLegendre &gll_quad, Mesh &mesh, const MaterialBank &material_bank, const SourceBank &source_bank, const Ordinate &ordinate, const size_t ordinate_index, const QuadratureBase< Ordinate > &angular_quad_set)=0
Assemble the vector of GlobalForcingData structs that will be using in AssembleGlobalForcing to creat...
virtual std::vector< GlobalMatrixData > AssembleGlobalMatrixData(const Mesh &mesh, const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank, const Ordinate &ordinate)=0
Assemble the vector of GlobalMatrixData structs that will be used in AssembleGlobalSystem to create t...
void ApplyBCs(const Mesh &mesh, const Ordinate &ordinate, const BCBank &bc_bank, const size_t ordinate_index)
Apply boundary conditions by adding in values needed at boundary nodes. Internally,...
size_t n_dofs() const
Get the number of degrees of freedom.
void AssembleGlobalSystem(const std::vector< GlobalMatrixData > &global_matrix_data, const size_t ordinate_index)
Assemble the global element system. That is, form the matrix in . This only should be called once pe...
void AssembleGlobalForcing(const std::vector< GlobalForcingData > &global_forcing_data, const size_t ordinate_index)
Assemble the global forcing vector for a given ordinate index. The global vector is sized from the n_...
T GetAbscissa(const unsigned int index) const
Get the abscissa corresponding to the index.
size_t n_points() const
Get total number of abscissas.
Exports simulation results to a file.
void Export()
Export the results in the format given by output_format_.
Wrapper class that owns a ProblemBase of the type corresponding to the given FEFormulation.
ProblemBase * get() const
Get the underlying ProblemBase object.
Bank holding the volumetric sources defined in the input file.
int main(int argc, char **argv)
void print_input_files(const std::string input, const std::string mesh)
Print the paths of the input and mesh files being used.
void print_scatter_status(const double flux_l2_error, const double relative_error, const unsigned int iter)
Print the scalar flux convergence status for the current source iteration.
void print_scatter_complete(const double final_k_eff, const RunMode sim_typ)
Print a message indicating source iterations have completed.
json JSONFromFile(const std::string filename)
Create a json object from a string. Will throw an error if the file could not be opened.
void print_header()
Print the program banner, description, and license information.
void print_mesh_info(const size_t n_nodes, const size_t n_elements, const unsigned int dimension)
Print information about the mesh.
void print_columns()
Print the column headers for the k-eff/scatter iteration status table.
AngularQuadSet angular_quad_set
Angular quadrature set to use.
unsigned int n_polar
Number of polar quadrature points.
unsigned int n_azim
Number of azimuthal quadrature points.
std::string mesh_file
Path to the gmsh .msh file.
double scalar_flux
Scalar flux on the node.
OutputFormat output_format
Format results are exported in.
RunMode run_mode
Run mode for the simulation.
std::string name
Problem name.
Tracks the running state of a simulation across source iterations.
double flux_relative_error
Relative L2 error in the scalar flux (flux_error_l2 normalized by the current iteration's flux L2 nor...
double flux_error_l2
L2 norm of the change in scalar flux between the current and previous source iteration.
double k_eff
Effective multiplication factor.
double tolerance
Convergence tolerance for source iteration.
unsigned int max_iterations
Maximum number of source iterations before giving up.
FEFormulation fe_formulation
Finite element formulation to use.
unsigned int n_points
Number of points per spectral element.