VertexCFD  0.0-dev
VertexCFD_ExternalFieldsManager_impl.hpp
1 #ifndef VERTEXCFD_EXTERNALFIELDSMANAGER_IMPL_HPP
2 #define VERTEXCFD_EXTERNALFIELDSMANAGER_IMPL_HPP
3 
4 #include "VertexCFD_InitialConditionManager.hpp"
5 #include "VertexCFD_MeshManager.hpp"
6 #include "VertexCFD_PhysicsManager.hpp"
7 #include "parameters/VertexCFD_ParameterDatabase.hpp"
8 
9 #include <Panzer_ReadOnlyVector_GlobalEvaluationData.hpp>
10 
11 #include <Thyra_DefaultSpmdVector.hpp>
12 
13 namespace VertexCFD
14 {
15 //---------------------------------------------------------------------------//
16 template<class Traits>
17 template<int NumSpaceDim>
18 ExternalFieldsManager<Traits>::ExternalFieldsManager(
19  const std::integral_constant<int, NumSpaceDim>& num_space_dim,
20  const Teuchos::RCP<const Teuchos::MpiComm<int>>& comm,
21  const std::string& filename)
22 {
23  auto parameter_db
24  = Teuchos::rcp(new Parameter::ParameterDatabase(comm, filename));
25  auto mesh_manager = Teuchos::rcp(new MeshManager(*parameter_db, comm));
26  auto physics_manager = Teuchos::rcp(
27  new PhysicsManager(num_space_dim, parameter_db, mesh_manager));
28  physics_manager->setupModel();
29 
30  _global_indexer = physics_manager->dofManager();
31 
32  auto ic_manager = Teuchos::rcp(
33  new InitialConditionManager(parameter_db, mesh_manager));
34  Teuchos::RCP<Thyra::VectorBase<double>> solution;
35  Teuchos::RCP<Thyra::VectorBase<double>> solution_dot;
36  ic_manager->applyInitialConditions(
37  num_space_dim, *physics_manager, solution, solution_dot);
38 
39  // Create a global evaluation container for the field data.
40  Teuchos::RCP<panzer::ReadOnlyVector_GlobalEvaluationData> ged;
41  ged = physics_manager->linearObjectFactory()->buildReadOnlyDomainContainer();
42  ged->setOwnedVector(solution);
43 
44  // Gather the ghosted vector of field data.
45  ged->globalToGhost(0);
46 
47  // Get the local vector data.
48  auto ghosted_vector
49  = Teuchos::rcp_dynamic_cast<const Thyra::SpmdVectorBase<double>>(
50  ged->getGhostedVector());
51  auto ghosted_data_host = ghosted_vector->getLocalSubVector();
52 
53  // Thyra only provides the ghosted data via a host-side array.
54  // We need to copy this data to a device view so that it can be accessed
55  // from the device in kernel below.
56  _ghosted_field_data = Kokkos::View<double*, PHX::Device>(
57  "ghosted_field_data", ghosted_data_host.subDim());
58  auto ghost_mirror = Kokkos::create_mirror(_ghosted_field_data);
59  for (int i = 0; i < ghosted_data_host.subDim(); ++i)
60  ghost_mirror(i) = ghosted_data_host[i];
61  Kokkos::deep_copy(_ghosted_field_data, ghost_mirror);
62 }
63 
64 //---------------------------------------------------------------------------//
65 template<class Traits>
66 Teuchos::RCP<const panzer::GlobalIndexer>
67 ExternalFieldsManager<Traits>::globalIndexer() const
68 {
69  return _global_indexer;
70 }
71 
72 //---------------------------------------------------------------------------//
73 template<class Traits>
74 Kokkos::View<double*, PHX::Device>
75 ExternalFieldsManager<Traits>::ghostedFieldData() const
76 {
77  return _ghosted_field_data;
78 }
79 
80 //---------------------------------------------------------------------------//
81 
82 } // end namespace VertexCFD
83 
84 #endif // end VERTEXCFD_EXTERNALFIELDSMANAGER_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23