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 319 : CombineComponentsMeshes::validParams() 21 : { 22 319 : InputParameters params = Action::validParams(); 23 319 : params.addClassDescription("Combines meshes generated by disjoined components."); 24 319 : return params; 25 0 : } 26 : 27 115 : CombineComponentsMeshes::CombineComponentsMeshes(const InputParameters & params) : Action(params) {} 28 : 29 : void 30 107 : CombineComponentsMeshes::act() 31 : { 32 : // Create the mesh generator to combine them 33 107 : if (_current_task == "append_mesh_generator") 34 : { 35 : // Get the list of components meshes (from their last mesh generators) 36 107 : std::vector<MeshGeneratorName> all_components_mgs; 37 107 : std::vector<MeshGeneratorName> mgs_to_combine; 38 107 : std::vector<const ActionComponent *> components = _awh.getActions<ActionComponent>(); 39 287 : for (const auto comp : components) 40 : { 41 : // Keep track of all mesh generators used in components 42 668 : for (const auto & mg_name : comp->meshGeneratorNames()) 43 488 : all_components_mgs.push_back(mg_name); 44 180 : if (comp->meshGeneratorNames().size()) 45 180 : 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 107 : bool all_mgs_from_components = true; 56 107 : const auto final_mg = _app.getMeshGeneratorSystem().getFinalMeshGeneratorName(); 57 107 : if (_app.getMeshGeneratorSystem().getMeshGeneratorNames().size()) 58 : { 59 : // Check whether there are mesh generators that do not come from Components 60 707 : for (const auto & mg : _app.getMeshGeneratorSystem().getMeshGeneratorNames()) 61 600 : if (std::find(all_components_mgs.begin(), all_components_mgs.end(), mg) == 62 1200 : all_components_mgs.end()) 63 219 : all_mgs_from_components = false; 64 : 65 : // If a component is already defined on the final mesh MG, no need to add it 66 193 : if (final_mg != "" && 67 86 : std::find(all_components_mgs.begin(), all_components_mgs.end(), final_mg) == 68 193 : all_components_mgs.end()) 69 73 : mgs_to_combine.push_back(final_mg); 70 107 : if (final_mg == "" && !all_mgs_from_components) 71 0 : mooseError("Final mesh generator should be set for [Mesh] and [ActionComponents] to work " 72 : "together"); 73 : } 74 : 75 : // Combine everyone into a combiner 76 107 : InputParameters params = _factory.getValidParams("CombinerGenerator"); 77 107 : params.set<std::vector<MeshGeneratorName>>("inputs") = mgs_to_combine; 78 107 : params.set<bool>("avoid_merging_subdomains") = true; 79 107 : params.set<bool>("avoid_merging_boundaries") = true; 80 107 : params.set<bool>("output") = true; 81 : 82 : // Single component case 83 107 : if (mgs_to_combine.size() == 1) 84 21 : params.set<std::vector<Point>>("positions") = {Point(0, 0, 0)}; 85 : 86 : // Replace the current final MG if there are mesh generators 87 107 : if (!all_mgs_from_components) 88 86 : _app.getMeshGeneratorSystem().appendMeshGenerator( 89 : "CombinerGenerator", "component_combiner", params); 90 : else 91 : // No mesh generators somehow 92 : { 93 21 : _app.getMeshGeneratorSystem().addMeshGenerator( 94 : "CombinerGenerator", "component_combiner", params); 95 : } 96 107 : } 97 : else 98 : mooseAssert(false, "Registered to a task but not doing anything on that task"); 99 107 : }