libMesh
meshfree_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 #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 // Helper function for doing the projection
41 class MeshlessInterpolationFunction : public FunctionBase<Number>
42 {
43 public:
45  Threads::spin_mutex & mutex) :
46  _mfi(mfi),
47  _mutex(mutex)
48  {}
49 
55  virtual ~MeshlessInterpolationFunction () = default;
56 
62 
63  void init () {}
64  void clear () {}
65 
66  virtual std::unique_ptr<FunctionBase<Number>> clone () const
67  {
68  return libmesh_make_unique<MeshlessInterpolationFunction>(_mfi, _mutex);
69  }
70 
72  const Real /*time*/)
73  {
74  _pts.clear();
75  _pts.push_back(p);
76  _vals.resize(1);
77 
78  Threads::spin_mutex::scoped_lock lock(_mutex);
79 
81 
82  return _vals.front();
83  }
84 
85 
86  void operator() (const Point & p,
87  const Real time,
88  DenseVector<Number> & output)
89  {
90  output.resize(1);
91  output(0) = (*this)(p,time);
92  return;
93  }
94 
95 private:
97  mutable std::vector<Point> _pts;
98  mutable std::vector<Number> _vals;
100 };
101 
102 void
104  const Variable & to_var)
105 {
106  libmesh_experimental();
107 
108  System * from_sys = from_var.system();
109  System * to_sys = to_var.system();
110 
111  EquationSystems & from_es = from_sys->get_equation_systems();
112 
113  MeshBase & from_mesh = from_es.get_mesh();
114 
116  (from_mesh.comm(), 4, 2);
117 
118  std::vector<Point> & src_pts (idi.get_source_points());
119  std::vector<Number> & src_vals (idi.get_source_vals());
120 
121  std::vector<std::string> field_vars;
122  field_vars.push_back(from_var.name());
123  idi.set_field_variables(field_vars);
124 
125  // We now will loop over every node in the source mesh
126  // and add it to a source point list, along with the solution
127  for (const auto & node : from_mesh.local_node_ptr_range())
128  {
129  src_pts.push_back(*node);
130  src_vals.push_back((*from_sys->solution)(node->dof_number(from_sys->number(),from_var.number(),0)));
131  }
132 
133  // We have only set local values - prepare for use by gathering remote data
134  idi.prepare_for_use();
135 
136  // Create a MeshlessInterpolationFunction that uses our
137  // InverseDistanceInterpolation object. Since each
138  // MeshlessInterpolationFunction shares the same
139  // InverseDistanceInterpolation object in a threaded environment we
140  // must also provide a locking mechanism.
141  Threads::spin_mutex mutex;
142  MeshlessInterpolationFunction mif(idi, mutex);
143 
144  // project the solution
145  to_sys->project_solution(&mif);
146 }
147 
148 } // namespace libMesh
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::Number
Real Number
Definition: libmesh_common.h:195
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::MeshlessInterpolationFunction::operator()
Number operator()(const Point &p, const Real time=0.)
Definition: meshless_interpolation_function.h:101
libMesh::MeshlessInterpolationFunction::operator=
MeshlessInterpolationFunction & operator=(const MeshlessInterpolationFunction &)=delete
This class contains const references so it can't be assigned.
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::System::number
unsigned int number() const
Definition: system.h:2075
libMesh::MeshlessInterpolationFunction::init
void init()
The actual initialization process.
Definition: meshfree_solution_transfer.C:63
libMesh::MeshfreeInterpolation::field_variables
const std::vector< std::string > & field_variables() const
Definition: meshfree_interpolation.h:116
libMesh::Variable::name
const std::string & name() const
Definition: variable.h:100
libMesh::MeshlessInterpolationFunction::_mfi
const MeshfreeInterpolation & _mfi
Definition: meshless_interpolation_function.h:47
libMesh::MeshlessInterpolationFunction::clear
void clear()
Clears the function.
Definition: meshfree_solution_transfer.C:64
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::MeshlessInterpolationFunction::_pts
std::vector< Point > _pts
Definition: meshless_interpolation_function.h:48
libMesh::MeshlessInterpolationFunction::clone
virtual std::unique_ptr< FunctionBase< Number > > clone() const
Definition: meshfree_solution_transfer.C:66
libMesh::MeshBase::local_node_ptr_range
virtual SimpleRange< node_iterator > local_node_ptr_range()=0
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::Variable
This class defines the notion of a variable in the system.
Definition: variable.h:49
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::InverseDistanceInterpolation
Inverse distance interpolation.
Definition: meshfree_interpolation.h:179
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::MeshlessInterpolationFunction
Definition: meshless_interpolation_function.h:44
libMesh::MeshlessInterpolationFunction::_mutex
Threads::spin_mutex & _mutex
Definition: meshless_interpolation_function.h:50
libMesh::MeshfreeInterpolation::interpolate_field_data
virtual void interpolate_field_data(const std::vector< std::string > &field_names, const std::vector< Point > &tgt_pts, std::vector< Number > &tgt_vals) const =0
Interpolate source data at target points.
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::MeshfreeInterpolation::set_field_variables
void set_field_variables(const std::vector< std::string > &names)
Defines the field variable(s) we are responsible for, and importantly their assumed ordering.
Definition: meshfree_interpolation.h:110
libMesh::System::project_solution
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Definition: system_projection.C:950
libMesh::MeshlessInterpolationFunction::_vals
std::vector< Number > _vals
Definition: meshless_interpolation_function.h:49
libMesh::MeshlessInterpolationFunction::MeshlessInterpolationFunction
MeshlessInterpolationFunction(const MeshfreeInterpolation &mfi, Threads::spin_mutex &mutex)
Definition: meshfree_solution_transfer.C:44
libMesh::MeshfreeInterpolation
Base class to support various mesh-free interpolation methods.
Definition: meshfree_interpolation.h:56
libMesh::MeshfreeSolutionTransfer::transfer
virtual void transfer(const Variable &from_var, const Variable &to_var) override
Transfer the values of a variable to another.
Definition: meshfree_solution_transfer.C:103
libMesh::Threads::spin_mutex
Spin mutex.
Definition: threads_none.h:127
libMesh::MeshlessInterpolationFunction::~MeshlessInterpolationFunction
virtual ~MeshlessInterpolationFunction()=default
libMesh::DenseVector< Number >