https://mooseframework.inl.gov
ContactRelationshipManagerTest.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 
10 #include "gtest/gtest.h"
11 
12 #include "ActionFactory.h"
13 #include "ContactAction.h"
14 #include "Factory.h"
15 #include "MeshGeneratorMesh.h"
16 #include "Moose.h"
17 #include "MooseApp.h"
18 #include "MooseMain.h"
19 #include "MooseUnitUtils.h"
20 #include "RelationshipManager.h"
21 
22 class ContactRelationshipManagerTest : public ::testing::Test
23 {
24 protected:
26  {
27  Default,
28  False,
29  True
30  };
31 
32  void SetUp() override
33  {
34  const char * argv[2] = {"foo", "\0"};
35  _app = Moose::createMooseApp("ContactApp", 1, (char **)argv);
36  _factory = &_app->getFactory();
38  }
39 
41  {
42  auto params = _factory->getValidParams("MeshGeneratorMesh");
43  auto moose_mesh =
44  _factory->create<MeshGeneratorMesh>("MeshGeneratorMesh", "moose_mesh", params);
45  moose_mesh->setMeshBase(moose_mesh->buildMeshBaseObject(2));
46  moose_mesh->buildMesh();
47  _app->actionWarehouse().mesh() = moose_mesh;
48  }
49 
50  std::shared_ptr<ContactAction> buildContactAction(
51  const GhostWholeInterfaceInput ghost_whole_interface = GhostWholeInterfaceInput::Default,
52  const std::string & formulation = "kinematic")
53  {
54  auto params = _app->getActionFactory().getValidParams("ContactAction");
55  params.set<std::string>("task") = "add_constraint";
56  params.set<std::string>("registered_identifier") = "Contact/*";
57  params.set<std::vector<BoundaryName>>("primary") = {"primary"};
58  params.set<std::vector<BoundaryName>>("secondary") = {"secondary"};
59  // Mark this programmatic assignment as user-set so the action sees the
60  // same parameter metadata it would get from parsed input.
61  params.set_attributes("formulation", false);
62  params.set<MooseEnum>("formulation") = formulation;
63  // The mortar validation specifically checks isParamSetByUser(), so only
64  // explicit test inputs should be marked as user-set.
65  switch (ghost_whole_interface)
66  {
68  break;
70  params.set_attributes("ghost_whole_interface", false);
71  params.set<bool>("ghost_whole_interface") = false;
72  break;
74  params.set_attributes("ghost_whole_interface", false);
75  params.set<bool>("ghost_whole_interface") = true;
76  break;
77  }
78 
79  auto action = _app->getActionFactory().create("ContactAction", "Contact/test", params);
80  return std::dynamic_pointer_cast<ContactAction>(action);
81  }
82 
83  void testContactActionRelationshipManager(const bool enabled)
84  {
85  const auto action = buildContactAction(enabled ? GhostWholeInterfaceInput::True
87  ASSERT_TRUE(action);
88 
89  action->addRelationshipManagers(Moose::RelationshipManagerType::GEOMETRIC);
90 
91  const auto & relationship_managers = _app->relationshipManagers();
92  ASSERT_EQ(relationship_managers.size(), 1);
93 
94  auto & rm = **relationship_managers.begin();
95  EXPECT_EQ(rm.type(), "GhostPrimaryFace");
96  EXPECT_TRUE(rm.isType(Moose::RelationshipManagerType::GEOMETRIC));
97  EXPECT_TRUE(rm.isType(Moose::RelationshipManagerType::ALGEBRAIC));
98  EXPECT_EQ(rm.attachGeometricEarly(), !enabled);
99  EXPECT_EQ(rm.getInfo(), enabled ? "GhostPrimaryFace" : "GhostPrimaryFace (disabled)");
100  }
101 
102  void testMortarContactActionRejectsGhostWholeInterface(const std::string & formulation)
103  {
104  const std::string error =
105  "Mortar contact always geometrically and algebraically ghosts the interface.";
106  EXPECT_THROW_MSG_CONTAINS(
107  buildContactAction(GhostWholeInterfaceInput::True, formulation), std::runtime_error, error);
108  EXPECT_THROW_MSG_CONTAINS(buildContactAction(GhostWholeInterfaceInput::False, formulation),
109  std::runtime_error,
110  error);
111  }
112 
113  std::shared_ptr<MooseApp> _app;
115 };
116 
117 TEST_F(ContactRelationshipManagerTest, contactActionAddsDisabledRMByDefault)
118 {
119  testContactActionRelationshipManager(false);
120 }
121 
122 TEST_F(ContactRelationshipManagerTest, contactActionCanEnableWholeInterfaceRM)
123 {
124  testContactActionRelationshipManager(true);
125 }
126 
127 TEST_F(ContactRelationshipManagerTest, mortarContactActionRejectsGhostWholeInterface)
128 {
129  testMortarContactActionRejectsGhostWholeInterface("mortar");
130 }
131 
132 TEST_F(ContactRelationshipManagerTest, mortarPenaltyContactActionRejectsGhostWholeInterface)
133 {
134  testMortarContactActionRejectsGhostWholeInterface("mortar_penalty");
135 }
Action class for creating constraints, kernels, and user objects necessary for mechanical contact...
Definition: ContactAction.h:32
void testMortarContactActionRejectsGhostWholeInterface(const std::string &formulation)
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
InputParameters getValidParams(const std::string &name) const
std::shared_ptr< ContactAction > buildContactAction(const GhostWholeInterfaceInput ghost_whole_interface=GhostWholeInterfaceInput::Default, const std::string &formulation="kinematic")
TEST_F(ContactRelationshipManagerTest, contactActionAddsDisabledRMByDefault)
void testContactActionRelationshipManager(const bool enabled)
void setMeshBase(std::unique_ptr< MeshBase > mesh_base)
std::unique_ptr< MooseApp > createMooseApp(const std::string &default_app_type, int argc, char *argv[])