libMesh
meshfree_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 #include "libmesh/meshfree_solution_transfer.h"
21 
22 #include "libmesh/mesh.h"
23 #include "libmesh/system.h"
24 #include "libmesh/numeric_vector.h"
25 #include "libmesh/threads.h"
26 #include "libmesh/meshfree_interpolation.h"
27 #include "libmesh/function_base.h"
28 #include "libmesh/node.h"
29 
30 // C++ includes
31 #include <cstddef>
32 
33 namespace libMesh
34 {
35 
36 // Forward Declarations
37 template <typename T>
38 class DenseVector;
39 
40 void
42  const Variable & to_var)
43 {
44  libmesh_experimental();
45 
46  System * from_sys = from_var.system();
47  System * to_sys = to_var.system();
48 
49  EquationSystems & from_es = from_sys->get_equation_systems();
50 
51  MeshBase & from_mesh = from_es.get_mesh();
52 
54  (from_mesh.comm(), 4, 2);
55 
56  std::vector<Point> & src_pts (idi.get_source_points());
57  std::vector<Number> & src_vals (idi.get_source_vals());
58 
59  std::vector<std::string> field_vars;
60  field_vars.push_back(from_var.name());
61  idi.set_field_variables(field_vars);
62 
63  // We now will loop over every node in the source mesh
64  // and add it to a source point list, along with the solution
65  for (const auto & node : from_mesh.local_node_ptr_range())
66  {
67  src_pts.push_back(*node);
68  src_vals.push_back((*from_sys->solution)(node->dof_number(from_sys->number(),from_var.number(),0)));
69  }
70 
71  // We have only set local values - prepare for use by gathering remote data
72  idi.prepare_for_use();
73 
74  // Create a MeshfreeInterpolationFunction that uses our
75  // InverseDistanceInterpolation object. Since each
76  // MeshfreeInterpolationFunction shares the same
77  // InverseDistanceInterpolation object in a threaded environment we
78  // must also provide a locking mechanism.
79  Threads::spin_mutex mutex;
80  MeshfreeInterpolationFunction mif(idi, mutex);
81 
82  // project the solution
83  to_sys->project_solution(&mif);
84 }
85 
86 } // namespace libMesh
This is the EquationSystems class.
Inverse distance interpolation.
const EquationSystems & get_equation_systems() const
Definition: system.h:721
const Parallel::Communicator & comm() const
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:75
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
unsigned int number() const
Definition: system.h:2350
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
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
System * system() const
Definition: variable.h:114
void set_field_variables(std::vector< std::string > names)
Defines the field variable(s) we are responsible for, and importantly their assumed ordering...
const MeshBase & get_mesh() const
const std::string & name() const
Definition: variable.h:122
unsigned int number() const
Definition: variable.h:128