1 #ifndef VERTEXCFD_EVALUATORTESTHARNESS_HPP
2 #define VERTEXCFD_EVALUATORTESTHARNESS_HPP
4 #include <Panzer_BasisIRLayout.hpp>
5 #include <Panzer_BasisValues2.hpp>
6 #include <Panzer_CellData.hpp>
7 #include <Panzer_CommonArrayFactories.hpp>
8 #include <Panzer_Dimension.hpp>
9 #include <Panzer_IntegrationRule.hpp>
10 #include <Panzer_IntegrationValues2.hpp>
11 #include <Panzer_Traits.hpp>
12 #include <Panzer_Workset.hpp>
14 #include <Phalanx_Evaluator.hpp>
15 #include <Phalanx_FieldManager.hpp>
16 #include <Phalanx_KokkosDeviceTypes.hpp>
18 #include <Shards_BasicTopologies.hpp>
19 #include <Shards_CellTopology.hpp>
20 #include <Shards_CellTopologyData.h>
21 #include <Shards_CellTopologyTraits.hpp>
23 #include <Teuchos_RCP.hpp>
25 #include <gtest/gtest.h>
27 #include <Kokkos_Core.hpp>
29 #include <Trilinos_version.h>
44 Teuchos::RCP<PHX::FieldManager<panzer::Traits>> fm;
45 Teuchos::RCP<shards::CellTopology> cell_topo;
46 Teuchos::RCP<panzer::Workset> workset;
47 Teuchos::RCP<panzer::CellData> cell_data;
48 Teuchos::RCP<panzer::IntegrationRule> ir;
49 Teuchos::RCP<panzer::IntegrationValues2<double>> int_values;
50 Teuchos::RCP<panzer::BasisIRLayout> basis_ir_layout;
51 Teuchos::RCP<panzer::BasisValues2<double>> basis_values;
52 Teuchos::RCP<std::vector<panzer::Workset>> worksets;
53 Teuchos::RCP<panzer::Traits::SD> setup_data;
55 using host_coords_view = Kokkos::View<
double***,
56 typename PHX::DevLayout<double>::type,
57 PHX::Device>::HostMirror;
63 const host_coords_view host_coords,
64 const int integration_order,
65 const int basis_order,
66 const int side_id = -1)
68 initialize(cell_topo_data,
77 const int integration_order,
78 const int basis_order,
79 const int side_id = -1)
82 const int num_cell = 1;
84 const CellTopologyData* cell_topo_data =
nullptr;
85 host_coords_view host_coords;
88 if (1 == num_space_dim)
90 cell_topo_data = shards::getCellTopologyData<shards::Line<2>>();
92 host_coords = host_coords_view(
"coords", num_cell, 2, 1);
94 host_coords(0, 0, 0) = 0.0;
95 host_coords(0, 1, 0) = 1.0;
97 else if (2 == num_space_dim)
100 = shards::getCellTopologyData<shards::Quadrilateral<4>>();
102 host_coords = host_coords_view(
"coords", num_cell, 4, 2);
104 host_coords(0, 0, 0) = 0.0;
105 host_coords(0, 0, 1) = 0.0;
107 host_coords(0, 1, 0) = 1.0;
108 host_coords(0, 1, 1) = 0.0;
110 host_coords(0, 2, 0) = 1.0;
111 host_coords(0, 2, 1) = 1.0;
113 host_coords(0, 3, 0) = 0.0;
114 host_coords(0, 3, 1) = 1.0;
116 else if (3 == num_space_dim)
119 = shards::getCellTopologyData<shards::Hexahedron<8>>();
121 host_coords = host_coords_view(
"coords", num_cell, 8, 3);
123 host_coords(0, 0, 0) = 0.0;
124 host_coords(0, 0, 1) = 0.0;
125 host_coords(0, 0, 2) = 0.0;
127 host_coords(0, 1, 0) = 1.0;
128 host_coords(0, 1, 1) = 0.0;
129 host_coords(0, 1, 2) = 0.0;
131 host_coords(0, 2, 0) = 1.0;
132 host_coords(0, 2, 1) = 1.0;
133 host_coords(0, 2, 2) = 0.0;
135 host_coords(0, 3, 0) = 0.0;
136 host_coords(0, 3, 1) = 1.0;
137 host_coords(0, 3, 2) = 0.0;
139 host_coords(0, 4, 0) = 0.0;
140 host_coords(0, 4, 1) = 0.0;
141 host_coords(0, 4, 2) = 1.0;
143 host_coords(0, 5, 0) = 1.0;
144 host_coords(0, 5, 1) = 0.0;
145 host_coords(0, 5, 2) = 1.0;
147 host_coords(0, 6, 0) = 1.0;
148 host_coords(0, 6, 1) = 1.0;
149 host_coords(0, 6, 2) = 1.0;
151 host_coords(0, 7, 0) = 0.0;
152 host_coords(0, 7, 1) = 1.0;
153 host_coords(0, 7, 2) = 1.0;
157 std::ostringstream msg;
158 msg <<
"Invalid spatial dimensions (" << num_space_dim
159 <<
"): must be 1, 2, or 3.";
160 throw std::logic_error(msg.str());
163 initialize(cell_topo_data,
171 template<
class EvalType>
173 registerEvaluator(
const Teuchos::RCP<PHX::Evaluator<panzer::Traits>>& eval)
175 fm->registerEvaluator<EvalType>(eval);
179 template<
class EvalType,
class Field>
180 void registerTestField(
const Field& field)
182 fm->requireField<EvalType>(field.fieldTag());
186 void setTime(
const double& time) { workset->time = time; }
189 void setStageNumber(
const int& stage) { workset->stage_number = stage; }
192 void setStepSize(
const double& step_size)
194 workset->step_size = step_size;
200 setup_data = Teuchos::rcp(
new panzer::Traits::SD);
201 worksets = Teuchos::rcp(
new std::vector<panzer::Workset>);
202 worksets->push_back(*workset);
203 setup_data->worksets_ = worksets;
204 std::vector<PHX::index_size_type> derivative_dimensions;
205 derivative_dimensions.push_back(4);
206 fm->setKokkosExtendedDataTypeDimensions<panzer::Traits::Jacobian>(
207 derivative_dimensions);
208 fm->postRegistrationSetup(*setup_data);
212 template<
class EvalType>
213 void evaluate(
const bool& doPostRegSetup =
true)
216 this->postRegSetup();
218 const panzer::Traits::PED ped;
219 fm->preEvaluate<EvalType>(ped);
220 fm->evaluateFields<EvalType>(*workset);
221 fm->postEvaluate<EvalType>(0);
225 template<
class EvalType,
class Field>
226 auto getTestFieldData(
const Field& field)
const
228 auto field_view = field.get_static_view();
229 auto field_mirror = Kokkos::create_mirror(field_view);
230 Kokkos::deep_copy(field_mirror, field_view);
235 int numPoint()
const {
return ir->num_points; }
238 int cardinality()
const {
return basis_ir_layout->cardinality(); }
241 void initialize(
const CellTopologyData* cell_topo_data,
242 const host_coords_view host_coords,
243 const int integration_order,
244 const int basis_order,
247 cell_topo = Teuchos::rcp(
new shards::CellTopology(cell_topo_data));
249 const int num_space_dim = cell_topo->getDimension();
251 if (num_space_dim != host_coords.extent_int(2))
253 std::ostringstream msg;
254 msg <<
"Unexpected spatial dimensions in provided coordinates: "
255 << cell_topo->getName() <<
" expects " << num_space_dim
256 <<
" dimensions, but " << host_coords.extent(2)
257 <<
" were provided.";
258 throw std::logic_error(msg.str());
261 const int nodes_per_cell = cell_topo->getNodeCount();
263 if (nodes_per_cell != host_coords.extent_int(1))
265 std::ostringstream msg;
266 msg <<
"Unexpected node count in provided coordinates: "
267 << cell_topo->getName() <<
" expects " << nodes_per_cell
268 <<
" nodes, but " << host_coords.extent(1)
269 <<
" were provided.";
270 throw std::logic_error(msg.str());
273 const int num_cell = host_coords.extent(0);
276 fm = Teuchos::rcp(
new PHX::FieldManager<panzer::Traits>);
279 workset = Teuchos::rcp(
new panzer::Workset);
280 workset->num_cells = num_cell;
284 const Kokkos::View<int*, PHX::Device> cell_local_ids_k(
285 "cell_local_ids_k", num_cell);
286 auto cell_local_ids_k_host
287 = Kokkos::create_mirror_view(cell_local_ids_k);
289 workset->cell_local_ids.resize(num_cell);
291 for (
int i = 0; i < num_cell; ++i)
293 cell_local_ids_k_host(i) = i;
294 workset->cell_local_ids[i] = i;
297 Kokkos::deep_copy(cell_local_ids_k, cell_local_ids_k_host);
298 workset->cell_local_ids_k = cell_local_ids_k;
301 workset->block_id =
"block_0";
302 workset->ir_degrees = Teuchos::rcp(
new std::vector<int>);
303 workset->basis_names = Teuchos::rcp(
new std::vector<std::string>);
305 workset->step_size = 0.0;
307 const panzer::MDFieldArrayFactory array_factory(
"",
true);
308 auto& node_coords = workset->cell_node_coordinates;
311 .buildStaticArray<double, panzer::Cell, panzer::NODE, panzer::Dim>(
312 "coords", num_cell, nodes_per_cell, num_space_dim);
314 Kokkos::deep_copy(node_coords.get_static_view(), host_coords);
318 = Teuchos::rcp(
new panzer::CellData(num_cell, side_id, cell_topo));
322 new panzer::IntegrationRule(integration_order, *cell_data));
324 = Teuchos::rcp(
new panzer::IntegrationValues2<double>(
"",
true));
325 int_values->setupArrays(ir);
326 int_values->evaluateValues(node_coords);
327 workset->ir_degrees->push_back(ir->cubature_degree);
328 workset->int_rules.push_back(int_values);
331 basis_ir_layout = panzer::basisIRLayout(
"HGrad", basis_order, *ir);
333 = Teuchos::rcp(
new panzer::BasisValues2<double>(
"",
true,
true));
334 basis_values->setupArrays(basis_ir_layout);
335 basis_values->evaluateValues(int_values->cub_points,
339 int_values->weighted_measure,
340 int_values->node_coordinates);
341 workset->bases.push_back(basis_values);
342 workset->basis_names->push_back(basis_ir_layout->getBasis()->name());
348 double accessValue(
double v)
356 template<
class Value>
357 double accessValue(Value&& v)
359 return accessValue(v.val());
364 template<
class Field,
class... Indices>
365 double fieldValue(Field f,
const Indices... i)
367 return accessValue(f(i...));
375 #endif // end VERTEXCFD_EVALUATORTESTHARNESS_HPP