https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CombineComponentsMeshes.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
11#include "MooseApp.h"
12#include "MooseMesh.h"
13#include "ActionWarehouse.h"
14#include "MeshGeneratorSystem.h"
15#include "ActionComponent.h"
16
17registerMooseAction("MooseApp", CombineComponentsMeshes, "append_mesh_generator");
18
21{
23 params.addClassDescription("Combines meshes generated by disjoined components.");
24 params.addParam<bool>(
25 "combine_component_meshes", true, "Whether to combine all component meshes");
26 return params;
27}
28
30
31void
33{
34 // Create the mesh generator to combine them
35 if (_current_task == "append_mesh_generator")
36 {
37 if (!getParam<bool>("combine_component_meshes"))
38 return;
39
40 // Get the list of components meshes (from their last mesh generators)
41 std::vector<MeshGeneratorName> all_components_mgs;
42 std::vector<MeshGeneratorName> mgs_to_combine;
43 std::vector<const ActionComponent *> components = _awh.getActions<ActionComponent>();
44 for (const auto comp : components)
45 {
46 // Keep track of all mesh generators used in components
47 for (const auto & mg_name : comp->meshGeneratorNames())
48 all_components_mgs.push_back(mg_name);
49 if (comp->meshGeneratorNames().size())
50 mgs_to_combine.push_back(comp->meshGeneratorNames().back());
51 }
52
53 // Do not create a CombinerGenerator if there are no mesh generators to combine
54 if (mgs_to_combine.size() == 0)
55 return;
56
57 // TODO once we have junctions
58 // - Get the list of disconnected components
59 // - Find the disjoint groups
60 // - Use a combiner generators on the vector of disjoint groups
61
62 // Add the main mesh from the Mesh block, only if it was not already used in
63 // making component meshes
64 bool all_mgs_from_components = true;
67 {
68 // Check whether there are mesh generators that do not come from Components
69 for (const auto & mg : _app.getMeshGeneratorSystem().getMeshGeneratorNames())
70 if (std::find(all_components_mgs.begin(), all_components_mgs.end(), mg) ==
71 all_components_mgs.end())
72 all_mgs_from_components = false;
73
74 // If a component is already defined on the final mesh MG, no need to add it
75 if (final_mg != "" &&
76 std::find(all_components_mgs.begin(), all_components_mgs.end(), final_mg) ==
77 all_components_mgs.end())
78 mgs_to_combine.push_back(final_mg);
79 if (final_mg == "" && !all_mgs_from_components)
80 mooseError("Final mesh generator should be set for [Mesh] and [ActionComponents] to work "
81 "together");
82 }
83
84 // Combine everyone into a combiner
85 InputParameters params = _factory.getValidParams("CombinerGenerator");
86 params.set<std::vector<MeshGeneratorName>>("inputs") = mgs_to_combine;
87 params.set<bool>("avoid_merging_subdomains") = true;
88 params.set<bool>("avoid_merging_boundaries") = true;
89 params.set<bool>("output") = true;
90
91 // Single component case
92 if (mgs_to_combine.size() == 1)
93 params.set<std::vector<Point>>("positions") = {Point(0, 0, 0)};
94
95 // Replace the current final MG if there are mesh generators
96 if (!all_mgs_from_components)
98 "CombinerGenerator", "component_combiner", params);
99 else
100 // No mesh generators somehow
101 {
103 "CombinerGenerator", "component_combiner", params);
104 }
105 }
106 else
107 mooseAssert(false, "Registered to a task but not doing anything on that task");
108}
registerMooseAction("MooseApp", CombineComponentsMeshes, "append_mesh_generator")
Base class for components that are defined using an action.
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
Base class for actions.
Definition Action.h:38
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
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition Action.h:169
Action to combine the meshes of disjoined components.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
CombineComponentsMeshes(const InputParameters &params)
static InputParameters validParams()
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters &params)
Add a mesh generator that will act on the meshes in the system.
std::vector< std::string > getMeshGeneratorNames() const
Get names of all mesh generators Note: This function should be called after all mesh generators are a...
const MeshGenerator & appendMeshGenerator(const std::string &type, const std::string &name, InputParameters params)
Append a mesh generator that will act on the current final mesh generator in the system.
MeshGeneratorName getFinalMeshGeneratorName() const
Get the name of the final mesh generator.
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition MooseApp.h:886
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
Factory & _factory
The Factory associated with the MooseApp.