Debian Codegraph @

packages/panzer/adapters-stk/test/panzer_workset_builder/apply_orientations.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10
11 #include <Teuchos_ConfigDefs.hpp>
12 #include <Teuchos_UnitTestHarness.hpp>
13 #include <Teuchos_RCP.hpp>
14 #include <Teuchos_TimeMonitor.hpp>
15
16 #include "Teuchos_DefaultComm.hpp"
17 #include "Teuchos_GlobalMPISession.hpp"
18
19 #include "Panzer_STK_Version.hpp"
20 #include "PanzerAdaptersSTK_config.hpp"
21
22 #include "Panzer_WorksetContainer.hpp"
23 #include "Panzer_IntrepidBasisFactory.hpp"
24 #include "Panzer_DOFManager.hpp"
25 #include "Panzer_OrientationsInterface.hpp"
26
27 #include "Panzer_STK_Interface.hpp"
28 #include "Panzer_STK_SquareQuadMeshFactory.hpp"
29 #include "Panzer_STKConnManager.hpp"
30 #include "Panzer_STK_WorksetFactory.hpp"
31
32 namespace panzer {
33 namespace {
34
35 void
36 testApplyOrientations(const bool by_container,
37 const bool by_factory,
38 const bool use_needs,
39 const bool should_fail,
40 Teuchos::FancyOStream & out,
41 bool & success)
42 {
43 // In this test we want to create a simple 2 cell 2D mesh
44 // of quads which share a center face.
45 // If orientations are not applied, then the HDiv 1 basis will have an orientation (vector)
46 // on the interface that points outward from the cell center.
47 // If orientations are applied, then both vectors will point in the same direction.
48
49 // So that I don't spell the name wrong later
50 const std::string element_block = "eblock-0_0";
51
52 // Basis has a single vector per face
53 const panzer::BasisDescriptor basis(1, "HDiv");
54
55 // Integrator has a single point per face
56 const panzer::IntegrationDescriptor integrator(0, panzer::IntegrationDescriptor::SURFACE);
57
58 // Create mesh
59 Teuchos::RCP<panzer_stk::STK_Interface> mesh;
60 {
61 // Each cell is 2x2 (same as reference cell)
62 auto pl = Teuchos::rcp(new Teuchos::ParameterList);
63 pl->set("X Elements",2);
64 pl->set("Y Elements",1);
65 pl->set("X0",-2.0);
66 pl->set("Xf", 2.0);
67 pl->set("Y0",-1.0);
68 pl->set("Yf", 1.0);
69
70 panzer_stk::SquareQuadMeshFactory factory;
71 factory.setParameterList(pl);
72 mesh = factory.buildMesh(MPI_COMM_WORLD);
73 }
74
75 // Need a dof manager to act as a global indexer
76 Teuchos::RCP<panzer::DOFManager> dof_manager;
77 {
78
79 // Build a connectivity manager for the given mesh
80 const auto conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh));
81
82 // Initialize the dof manager with the conn manager
83 dof_manager = Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD));
84
85 // Build an intrepid basis and a related field pattern for seeding the DOFManager
86 {
87 const auto & cell_topology = *mesh->getCellTopology(element_block);
88 auto intrepid_basis = panzer::createIntrepid2Basis<PHX::Device::execution_space,double,double>(basis.getType(),basis.getOrder(), cell_topology);
89 auto field_pattern = Teuchos::rcp(new panzer::Intrepid2FieldPattern(intrepid_basis));
90
91 // Add arbitrary field to dof manager to lock in the field pattern
92 dof_manager->addField(element_block, "B", field_pattern);
93 }
94
95 // Finalize the dof manager
96 dof_manager->buildGlobalUnknowns();
97 }
98
99 // Create a needs map
100 std::map<std::string, WorksetNeeds> needs_map;
101 needs_map[element_block].addBasis(basis);
102 needs_map[element_block].addIntegrator(integrator);
103
104 // Build a workset container
105 Teuchos::RCP<WorksetContainer> workset_container;
106 {
107 // Build workset factory
108 auto factory = Teuchos::rcp(new panzer_stk::WorksetFactory(mesh));
109
110 if(by_factory)
111 factory->setOrientationsInterface(Teuchos::rcp(new OrientationsInterface(dof_manager)));
112
113 if(use_needs)
114 workset_container = Teuchos::rcp(new WorksetContainer(factory, needs_map));
115 else
116 workset_container = Teuchos::rcp(new WorksetContainer(factory, {}));
117
118 if(by_container)
119 workset_container->setGlobalIndexer(dof_manager);
120 }
121
122 // Grab the one and only workset
123 auto worksets = workset_container->getWorksets(WorksetDescriptor(element_block, WorksetSizeType::ALL_ELEMENTS, true, by_container));
124 TEST_EQUALITY(worksets->size(), 1);
125
126 const auto & workset = (*worksets)[0];
127 const auto & basis_values = workset.getBasisValues(basis,integrator);
128
129 // Check to see if the basis values actually has orientations applied
130 if(by_factory or by_container){
131 TEST_ASSERT(basis_values.orientationsApplied());
132 } else {
133 TEST_ASSERT(not basis_values.orientationsApplied());
134 }
135
136 // Grab the basis values vector for the given integration points
137 const auto basis_vector_device = basis_values.getVectorBasisValues(false).get_static_view();
138 //(by_factory or by_container) ? basis_values.getVectorBasisValues(false).get_static_view() : basis_values.basis_vector.get_static_view();
139 auto basis_vector = Kokkos::create_mirror_view(basis_vector_device);
140 Kokkos::deep_copy(basis_vector,basis_vector_device);
141
142 // Note that this is for a partitioned workset, which will have 2 owned cells and 6 virtual cells for a total of 8 cells
143 TEST_EQUALITY(basis_vector.extent_int(0),8); // cells
144 TEST_EQUALITY(basis_vector.extent_int(1),4); // basis
145 TEST_EQUALITY(basis_vector.extent_int(2),4); // points
146 TEST_EQUALITY(basis_vector.extent_int(3),2); // vector dim
147
148 // Print out the vector values to see what they are
149 out << "Basis Values:\n";
150 for(int c=0; c<2; ++c)
151 for(int b=0; b<4; ++b)
152 for(int p=0; p<4; ++p)
153 out << c << ", " << b << ", " << p << ": ["<<basis_vector(c,b,p,0)<<", "<<basis_vector(c,b,p,1)<<"]\n";
154
155 // We are going to make the interface between cell 0 and 1
156 // The basis function associated with that interface is (cell,basis) (0,1) and (1,3)
157 // Points are aligned with basis, so (cell,point) are also (0,1) and (1,3)
158
159 const double normal_0[2] = {basis_vector(0,1,1,0), basis_vector(0,1,1,1)};
160 const double normal_1[2] = {basis_vector(1,3,3,0), basis_vector(1,3,3,1)};
161
162 const double vec[2] = {normal_0[0]+normal_1[0], normal_0[1]+normal_1[1]};
163
164 if(should_fail){
165 // The vectors oppose each other (1,0)+(-1,0), so the magnitude should be 0
166 TEUCHOS_ASSERT(vec[0]*vec[0]+vec[1]*vec[1] < 1.e-8);
167 } else {
168 // The vectors are the same (1,0)+(1,0), so the magnitude should be 2
169 TEUCHOS_ASSERT(vec[0]*vec[0]+vec[1]*vec[1] - 4 < 1.e-8);
170 }
171
172 }
173
174 }
175 }
176
177 TEUCHOS_UNIT_TEST(apply_orientations, none)
178 {
179 panzer::testApplyOrientations(false, false, true, true, out, success);
180 }
181
182 TEUCHOS_UNIT_TEST(apply_orientations, by_container)
183 {
184 panzer::testApplyOrientations(true, false, true, false, out, success);
185 }
186
187 TEUCHOS_UNIT_TEST(apply_orientations, by_factory)
188 {
189 panzer::testApplyOrientations(false, true, false, false, out, success);
190 }
191
192 TEUCHOS_UNIT_TEST(apply_orientations, by_both)
193 {
194 panzer::testApplyOrientations(true, true, false, false, out, success);
195 }