https://mooseframework.inl.gov
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 
17 registerMooseAction("MooseApp", CombineComponentsMeshes, "append_mesh_generator");
18 
21 {
23  params.addClassDescription("Combines meshes generated by disjoined components.");
24  return params;
25 }
26 
28 
29 void
31 {
32  // Create the mesh generator to combine them
33  if (_current_task == "append_mesh_generator")
34  {
35  // Get the list of components meshes (from their last mesh generators)
36  std::vector<MeshGeneratorName> all_components_mgs;
37  std::vector<MeshGeneratorName> mgs_to_combine;
38  std::vector<const ActionComponent *> components = _awh.getActions<ActionComponent>();
39  for (const auto comp : components)
40  {
41  // Keep track of all mesh generators used in components
42  for (const auto & mg_name : comp->meshGeneratorNames())
43  all_components_mgs.push_back(mg_name);
44  if (comp->meshGeneratorNames().size())
45  mgs_to_combine.push_back(comp->meshGeneratorNames().back());
46  }
47 
48  // TODO once we have junctions
49  // - Get the list of disconnected components
50  // - Find the disjoint groups
51  // - Use a combiner generators on the vector of disjoint groups
52 
53  // Add the main mesh from the Mesh block, only if it was not already used in
54  // making component meshes
55  bool all_mgs_from_components = true;
56  const auto final_mg = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName();
58  {
59  // Check whether there are mesh generators that do not come from Components
60  for (const auto & mg : _app.getMeshGeneratorSystem().getMeshGeneratorNames())
61  if (std::find(all_components_mgs.begin(), all_components_mgs.end(), mg) ==
62  all_components_mgs.end())
63  all_mgs_from_components = false;
64 
65  // If a component is already defined on the final mesh MG, no need to add it
66  if (final_mg != "" &&
67  std::find(all_components_mgs.begin(), all_components_mgs.end(), final_mg) ==
68  all_components_mgs.end())
69  mgs_to_combine.push_back(final_mg);
70  if (final_mg == "" && !all_mgs_from_components)
71  mooseError("Final mesh generator should be set for [Mesh] and [ActionComponents] to work "
72  "together");
73  }
74 
75  // Combine everyone into a combiner
76  InputParameters params = _factory.getValidParams("CombinerGenerator");
77  params.set<std::vector<MeshGeneratorName>>("inputs") = mgs_to_combine;
78  params.set<bool>("avoid_merging_subdomains") = true;
79  params.set<bool>("avoid_merging_boundaries") = true;
80  params.set<bool>("output") = true;
81 
82  // Single component case
83  if (mgs_to_combine.size() == 1)
84  params.set<std::vector<Point>>("positions") = {Point(0, 0, 0)};
85 
86  // Replace the current final MG if there are mesh generators
87  if (!all_mgs_from_components)
89  "CombinerGenerator", "component_combiner", params);
90  else
91  // No mesh generators somehow
92  {
94  "CombinerGenerator", "component_combiner", params);
95  }
96  }
97  else
98  mooseAssert(false, "Registered to a task but not doing anything on that task");
99 }
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:159
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshGeneratorName getFinalMeshGeneratorName() const
Get the name of the final mesh generator.
std::vector< std::string > getMeshGeneratorNames() const
Get names of all mesh generators Note: This function should be called after all mesh generators are a...
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...
Base class for components that are defined using an action.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Base class for actions.
Definition: Action.h:33
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.
Factory & _factory
The Factory associated with the MooseApp.
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.
static InputParameters validParams()
Definition: Action.C:24
registerMooseAction("MooseApp", CombineComponentsMeshes, "append_mesh_generator")
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:162
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
static InputParameters validParams()
CombineComponentsMeshes(const InputParameters &params)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition: MooseApp.h:863
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
Action to combine the meshes of disjoined components.