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