libMesh
direct_solution_transfer.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
28 DirectSolutionTransfer::DirectSolutionTransfer(const libMesh::Parallel::Communicator & comm_in) :
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
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::System::get_equation_systems
const EquationSystems & get_equation_systems() const
Definition: system.h:720
libMesh::Variable::system
System * system() const
Definition: variable.h:92
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
libMesh::Variable::number
unsigned int number() const
Definition: variable.h:106
libMesh::SolutionTransfer
Base class for objects that allow transferring variable values between different systems with differe...
Definition: solution_transfer.h:40
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DirectSolutionTransfer::~DirectSolutionTransfer
virtual ~DirectSolutionTransfer()
Definition: direct_solution_transfer.C:32
libMesh::DirectSolutionTransfer::transfer
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
Definition: direct_solution_transfer.C:36
libMesh::Variable::type
const FEType & type() const
Definition: variable.h:119
libMesh::System::local_dof_indices
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:1259
libMesh::NumericVector< Number >
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::DirectSolutionTransfer::DirectSolutionTransfer
DirectSolutionTransfer(const Parallel::Communicator &comm_in)
Definition: direct_solution_transfer.C:28
libMesh::Variable
This class defines the notion of a variable in the system.
Definition: variable.h:49
libMesh::MeshBase::n_nodes
virtual dof_id_type n_nodes() const =0
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::System::update
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:408