https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGOnlyAction.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "MooseApp.h"
11#include "CSGOnlyAction.h"
12#include "CSGBase.h"
13#include "MeshGenerator.h"
14
15registerMooseAction("MooseApp", CSGOnlyAction, "csg_only");
16registerMooseAction("MooseApp", CSGOnlyAction, "setup_mesh");
17registerMooseAction("MooseApp", CSGOnlyAction, "execute_csg_generators");
18
24
26
27void
29{
30 if (_current_task == "setup_mesh")
31 {
32 if (!_mesh)
33 mooseError("Cannot generate CSG object without a [Mesh] block in the input file");
35 }
36 else if (_current_task == "execute_csg_generators")
37 {
38 const auto final_mg_name = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName();
39 const auto ordered_mg = _app.getMeshGeneratorSystem().getOrderedMeshGenerators();
40
41 for (const auto & generator_set : ordered_mg)
42 for (const auto & generator : generator_set)
43 {
44 auto csg_obj = generator->generateInternalCSG();
45 const auto & name = generator->name();
46 // If we are running generateCSG for final generator, store CSG object for use in csg_only
47 // task
48 if (name == final_mg_name)
49 {
50 _csg_obj = std::move(csg_obj);
51 return;
52 }
53 else
54 {
55 // Store CSG object created by mesh generator for use by downstream MG's
57 }
58 }
59 }
60 else if (_current_task == "csg_only")
61 {
62 const auto final_mg_name = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName();
63 if (!_csg_obj)
64 mooseError("Expecting final generator with name " + final_mg_name +
65 " but not found in mesh generator tree");
66
67 Moose::out << "Outputting CSGBase object for " + final_mg_name + "\n";
68
69 auto csg_json = _csg_obj->generateOutput();
70
71 // write generated json to file. Filename will be based on optional argument to
72 // --csg-only. If not provided, the output name will be based on the filename
73 std::string json_out = _app.parameters().get<std::string>("csg_only");
74 if (json_out.empty())
75 json_out = _app.getOutputFileBase() + "_csg.json";
76
77 std::ofstream csg_file;
78 csg_file.open(json_out);
79 csg_file << csg_json.dump(/*indent=*/2);
80 csg_file.close();
81 }
82}
registerMooseAction("MooseApp", CSGOnlyAction, "csg_only")
Base class for actions.
Definition Action.h:38
std::shared_ptr< MooseMesh > & _mesh
Definition Action.h:174
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
Outputs the Constructive Solid Geometry to file then exits.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
static InputParameters validParams()
std::unique_ptr< CSG::CSGBase > _csg_obj
CSGOnlyAction(const InputParameters &params)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void saveOutputCSGBase(const MeshGeneratorName generator_name, std::unique_ptr< CSG::CSGBase > &csg_base)
Saves the CSGBase object to the global map storage, _csg_base_output, for a particular mesh generator...
const std::vector< std::vector< MeshGenerator * > > & getOrderedMeshGenerators() const
void setCSGOnly()
Set whether mesh generator system is running in CSG-only mode to true.
MeshGeneratorName getFinalMeshGeneratorName() const
Get the name of the final mesh generator.
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
Get the output file base name.
Definition MooseApp.C:1532
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition MooseApp.h:886
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271