libMesh
direct_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 // C++ includes
21 #include "libmesh/direct_solution_transfer.h"
22 
23 #include "libmesh/system.h"
24 #include "libmesh/numeric_vector.h"
25 
26 namespace libMesh {
27 
29  SolutionTransfer(comm_in)
30 {}
31 
33 {}
34 
35 void
37  const Variable & to_var)
38 {
39  libmesh_experimental();
40 
41  System * from_sys = from_var.system();
42  System * to_sys = to_var.system();
43 
44  // Just a couple of (not completely thorough)
46  libmesh_assert(from_var.type() == to_var.type());
47 
48  // get dof indices for source variable
49  unsigned int from_vn = from_var.number();
50  std::set<dof_id_type> from_var_indices;
51  from_sys->local_dof_indices(from_vn, from_var_indices);
52 
53  // get dof indices for dest variable
54  unsigned int to_vn = to_var.number();
55  std::set<dof_id_type> to_var_indices;
56  to_sys->local_dof_indices(to_vn, to_var_indices);
57 
58  // copy the values from from solution vector to to solution vector
59  std::set<dof_id_type>::iterator from_it = from_var_indices.begin();
60  std::set<dof_id_type>::iterator from_it_end = from_var_indices.end();
61  std::set<dof_id_type>::iterator to_it = to_var_indices.begin();
62 
63  NumericVector<Number> & from_solution = *from_sys->solution;
64 
65  for (; from_it != from_it_end; ++from_it, ++to_it)
66  to_sys->solution->set(*to_it, from_solution(*from_it));
67 
68  to_sys->solution->close();
69  to_sys->update();
70 }
71 
72 } // namespace libMesh
const FEType & type() const
Definition: variable.h:119
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
DirectSolutionTransfer(const Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(j)
unsigned int number() const
Definition: variable.h:106
This class defines the notion of a variable in the system.
Definition: variable.h:49
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
virtual void transfer(const Variable &from_var, const Variable &to_var) libmesh_override
Transfer the values of a variable to another.
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
Fills the std::set with the degrees of freedom on the local processor corresponding the the variable ...
Definition: system.C:1297
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
System * system() const
Definition: variable.h:92
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...
virtual dof_id_type n_nodes() const =0