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