Line data Source code
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 : 10 : #include "CombineComponentsMeshes.h" 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 : 19 : InputParameters 20 288 : CombineComponentsMeshes::validParams() 21 : { 22 288 : InputParameters params = Action::validParams(); 23 576 : params.addClassDescription("Combines meshes generated by disjoined components."); 24 576 : params.addParam<bool>( 25 576 : "combine_component_meshes", true, "Whether to combine all component meshes"); 26 288 : return params; 27 0 : } 28 : 29 244 : CombineComponentsMeshes::CombineComponentsMeshes(const InputParameters & params) : Action(params) {} 30 : 31 : void 32 238 : CombineComponentsMeshes::act() 33 : { 34 : // Create the mesh generator to combine them 35 238 : if (_current_task == "append_mesh_generator") 36 : { 37 714 : if (!getParam<bool>("combine_component_meshes")) 38 72 : return; 39 : 40 : // Get the list of components meshes (from their last mesh generators) 41 166 : std::vector<MeshGeneratorName> all_components_mgs; 42 166 : std::vector<MeshGeneratorName> mgs_to_combine; 43 166 : std::vector<const ActionComponent *> components = _awh.getActions<ActionComponent>(); 44 398 : for (const auto comp : components) 45 : { 46 : // Keep track of all mesh generators used in components 47 1010 : for (const auto & mg_name : comp->meshGeneratorNames()) 48 778 : all_components_mgs.push_back(mg_name); 49 232 : if (comp->meshGeneratorNames().size()) 50 232 : 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 166 : if (mgs_to_combine.size() == 0) 55 0 : 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 166 : bool all_mgs_from_components = true; 65 166 : const auto final_mg = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName(); 66 166 : if (_app.getMeshGeneratorSystem().getMeshGeneratorNames().size()) 67 : { 68 : // Check whether there are mesh generators that do not come from Components 69 1046 : for (const auto & mg : _app.getMeshGeneratorSystem().getMeshGeneratorNames()) 70 880 : if (std::find(all_components_mgs.begin(), all_components_mgs.end(), mg) == 71 1760 : all_components_mgs.end()) 72 268 : all_mgs_from_components = false; 73 : 74 : // If a component is already defined on the final mesh MG, no need to add it 75 244 : if (final_mg != "" && 76 78 : std::find(all_components_mgs.begin(), all_components_mgs.end(), final_mg) == 77 244 : all_components_mgs.end()) 78 66 : mgs_to_combine.push_back(final_mg); 79 166 : if (final_mg == "" && !all_mgs_from_components) 80 0 : mooseError("Final mesh generator should be set for [Mesh] and [ActionComponents] to work " 81 : "together"); 82 : } 83 : 84 : // Combine everyone into a combiner 85 498 : InputParameters params = _factory.getValidParams("CombinerGenerator"); 86 332 : params.set<std::vector<MeshGeneratorName>>("inputs") = mgs_to_combine; 87 332 : params.set<bool>("avoid_merging_subdomains") = true; 88 498 : params.set<bool>("avoid_merging_boundaries") = true; 89 166 : params.set<bool>("output") = true; 90 : 91 : // Single component case 92 166 : if (mgs_to_combine.size() == 1) 93 264 : params.set<std::vector<Point>>("positions") = {Point(0, 0, 0)}; 94 : 95 : // Replace the current final MG if there are mesh generators 96 166 : if (!all_mgs_from_components) 97 390 : _app.getMeshGeneratorSystem().appendMeshGenerator( 98 : "CombinerGenerator", "component_combiner", params); 99 : else 100 : // No mesh generators somehow 101 : { 102 440 : _app.getMeshGeneratorSystem().addMeshGenerator( 103 : "CombinerGenerator", "component_combiner", params); 104 : } 105 166 : } 106 : else 107 : mooseAssert(false, "Registered to a task but not doing anything on that task"); 108 : }