libMesh
Loading...
Searching...
No Matches
direct_solution_transfer.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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#include "libmesh/variable.h"
26
27namespace libMesh {
28
32
34
35void
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
DirectSolutionTransfer(const Parallel::Communicator &comm_in)
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
const MeshBase & get_mesh() const
virtual dof_id_type n_nodes() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Base class for objects that allow transferring variable values between different systems with differe...
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
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:1409
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition system.h:1655
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition system.C:498
const EquationSystems & get_equation_systems() const
Definition system.h:767
This class defines the notion of a variable in the system.
Definition variable.h:51
System * system() const
Definition variable.h:114
unsigned int number() const
Definition variable.h:128
const FEType & type() const
Definition variable.h:144
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)