libMesh
direct_solution_transfer.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 void
36  const Variable & to_var)
37 {
38  libmesh_experimental();
39 
40  System * from_sys = from_var.system();
41  System * to_sys = to_var.system();
42 
43  // Just a couple of (not completely thorough)
45  libmesh_assert(from_var.type() == to_var.type());
46 
47  // get dof indices for source variable
48  unsigned int from_vn = from_var.number();
49  std::set<dof_id_type> from_var_indices;
50  from_sys->local_dof_indices(from_vn, from_var_indices);
51 
52  // get dof indices for dest variable
53  unsigned int to_vn = to_var.number();
54  std::set<dof_id_type> to_var_indices;
55  to_sys->local_dof_indices(to_vn, to_var_indices);
56 
57  // copy the values from from solution vector to to solution vector
58  std::set<dof_id_type>::iterator from_it = from_var_indices.begin();
59  std::set<dof_id_type>::iterator from_it_end = from_var_indices.end();
60  std::set<dof_id_type>::iterator to_it = to_var_indices.begin();
61 
62  NumericVector<Number> & from_solution = *from_sys->solution;
63 
64  for (; from_it != from_it_end; ++from_it, ++to_it)
65  to_sys->solution->set(*to_it, from_solution(*from_it));
66 
67  to_sys->solution->close();
68  to_sys->update();
69 }
70 
71 } // namespace libMesh
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:1627
const EquationSystems & get_equation_systems() const
Definition: system.h:721
The libMesh namespace provides an interface to certain functionality in the library.
DirectSolutionTransfer(const Parallel::Communicator &comm_in)
This class defines the notion of a variable in the system.
Definition: variable.h:50
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
libmesh_assert(ctx)
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:510
System * system() const
Definition: variable.h:114
const MeshBase & get_mesh() const
Base class for objects that allow transferring variable values between different systems with differe...
unsigned int number() const
Definition: variable.h:128
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
virtual dof_id_type n_nodes() const =0
const FEType & type() const
Definition: variable.h:144