libMesh
dtk_solution_transfer.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #include "libmesh/libmesh_config.h"
21 
22 #ifdef LIBMESH_TRILINOS_HAVE_DTK
23 
24 #include "libmesh/dtk_solution_transfer.h"
25 #include "libmesh/system.h"
26 
27 #include "libmesh/ignore_warnings.h"
28 
29 // Trilinos Includes
30 #include <Teuchos_RCP.hpp>
31 #include <Teuchos_GlobalMPISession.hpp>
32 #include <Teuchos_Ptr.hpp>
33 #include <Teuchos_DefaultMpiComm.hpp>
34 #include <Teuchos_OpaqueWrapper.hpp>
35 
36 // DTK Includes
37 #include <DTK_MeshManager.hpp>
38 #include <DTK_MeshContainer.hpp>
39 #include <DTK_FieldManager.hpp>
40 #include <DTK_FieldContainer.hpp>
41 #include <DTK_FieldTools.hpp>
42 #include <DTK_CommTools.hpp>
43 #include <DTK_CommIndexer.hpp>
44 
45 #include "libmesh/restore_warnings.h"
46 
47 namespace libMesh
48 {
49 
51  SolutionTransfer(comm)
52 {
53  //comm_default = Teuchos::DefaultComm<int>::getComm();
54  comm_default = Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::rcp(new Teuchos::OpaqueWrapper<MPI_Comm>(comm.get()))));
55 }
56 
58 {
59  for (std::map<EquationSystems *, DTKAdapter *>::iterator it = adapters.begin();
60  it != adapters.end();
61  ++it)
62  delete it->second;
63 
64  for (std::map<std::pair<EquationSystems *, EquationSystems *>, shared_domain_map_type *>::iterator it = dtk_maps.begin();
65  it != dtk_maps.end();
66  ++it)
67  delete it->second;
68 }
69 
70 void
72  const Variable & to_var)
73 {
74  libmesh_experimental();
75 
76  EquationSystems * from_es = &from_var.system()->get_equation_systems();
77  EquationSystems * to_es = &to_var.system()->get_equation_systems();
78 
79  // Possibly make an Adapter for from_es
80  if (adapters.find(from_es) == adapters.end())
81  adapters[from_es] = new DTKAdapter(comm_default, *from_es);
82 
83  // Possibly make an Adapter for to_es
84  if (adapters.find(to_es) == adapters.end())
85  adapters[to_es] = new DTKAdapter(comm_default, *to_es);
86 
87  DTKAdapter * from_adapter = adapters[from_es];
88  DTKAdapter * to_adapter = adapters[to_es];
89 
90  std::pair<EquationSystems *, EquationSystems *> from_to(from_es, to_es);
91 
92  // If we haven't created a map for this pair of EquationSystems yet, do it now
93  if (dtk_maps.find(from_to) == dtk_maps.end())
94  {
95  libmesh_assert(from_es->get_mesh().mesh_dimension() == to_es->get_mesh().mesh_dimension());
96 
98  dtk_maps[from_to] = map;
99 
100  // The tolerance here is for the "contains_point()" implementation in DTK. Set a larger value for a looser tolerance...
101  map->setup(from_adapter->get_mesh_manager(), to_adapter->get_target_coords(), 30*Teuchos::ScalarTraits<double>::eps());
102  }
103 
104  DTKAdapter::RCP_Evaluator from_evaluator = from_adapter->get_variable_evaluator(from_var.name());
105  Teuchos::RCP<DataTransferKit::FieldManager<DTKAdapter::FieldContainerType>> to_values = to_adapter->get_values_to_fill(to_var.name());
106 
107  dtk_maps[from_to]->apply(from_evaluator, to_values);
108 
109  if (dtk_maps[from_to]->getMissedTargetPoints().size())
110  libMesh::out<<"Warning: Some points were missed in the transfer of "<<from_var.name()<<" to "<<to_var.name()<<"!"<<std::endl;
111 
112  to_adapter->update_variable_values(to_var.name());
113 }
114 
115 } // namespace libMesh
116 
117 #endif // #ifdef LIBMESH_TRILINOS_HAVE_DTK
This is the EquationSystems class.
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
Teuchos::RCP< DataTransferKit::FieldManager< MeshContainerType > > get_target_coords()
Definition: dtk_adapter.h:66
const std::string & name() const
Definition: variable.h:100
virtual void transfer(const Variable &from_var, const Variable &to_var) libmesh_override
Transfer the values of a variable to another.
void update_variable_values(std::string var_name)
After computing values for a variable in this EquationSystems we need to take those values and put th...
Definition: dtk_adapter.C:205
The DTKAdapter is used with the DTKSolutionTransfer object to adapt libmesh data to the DTK interface...
Definition: dtk_adapter.h:52
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(j)
This class defines the notion of a variable in the system.
Definition: variable.h:49
RCP_Evaluator get_variable_evaluator(std::string var_name)
Definition: dtk_adapter.C:178
Teuchos::RCP< const Teuchos::Comm< int > > comm_default
COMM_WORLD for now.
Teuchos::RCP< EvaluatorType > RCP_Evaluator
Definition: dtk_adapter.h:61
Teuchos::RCP< DataTransferKit::MeshManager< MeshContainerType > > get_mesh_manager()
Definition: dtk_adapter.h:64
OStreamProxy out
System * system() const
Definition: variable.h:92
unsigned int mesh_dimension() const
Definition: mesh_base.C:148
DataTransferKit::SharedDomainMap< DTKAdapter::MeshContainerType, DTKAdapter::MeshContainerType > shared_domain_map_type
const EquationSystems & get_equation_systems() const
Definition: system.h:712
const MeshBase & get_mesh() const
Base class for objects that allow transferring variable values between different systems with differe...
std::map< std::pair< EquationSystems *, EquationSystems * >, shared_domain_map_type * > dtk_maps
The dtk shared domain maps for pairs of EquationSystems (from, to)
DTKSolutionTransfer(const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
std::map< EquationSystems *, DTKAdapter * > adapters
The DTKAdapter associated with each EquationSystems.
Teuchos::RCP< DataTransferKit::FieldManager< FieldContainerType > > get_values_to_fill(std::string var_name)
Definition: dtk_adapter.C:192