libMesh
Functions
miscellaneous_ex8.C File Reference

Go to the source code of this file.

Functions

void create_random_point_cloud (const unsigned int Npts, std::vector< Point > &pts, const Real max_range=10)
 
Real exact_solution_u (const Point &p)
 
Real exact_solution_v (const Point &p)
 
Number exact_value (const Point &p, const Parameters &, const std::string &, const std::string &)
 
void init_sys (EquationSystems &es, const std::string &system_name)
 
int main (int argc, char **argv)
 

Function Documentation

◆ create_random_point_cloud()

void create_random_point_cloud ( const unsigned int  Npts,
std::vector< Point > &  pts,
const Real  max_range = 10 
)

Definition at line 47 of file miscellaneous_ex8.C.

50 {
51  libMesh::out << "Generating "<< Npts << " point cloud...";
52  pts.resize(Npts);
53 
54  for (size_t i=0;i<Npts;i++)
55  {
56  pts[i](0) = max_range * (std::rand() % 1000) / Real(1000);
57  pts[i](1) = max_range * (std::rand() % 1000) / Real(1000);
58  pts[i](2) = max_range * (std::rand() % 1000) / Real(1000);
59  }
60  libMesh::out << "done\n";
61 }

References libMesh::out, and libMesh::Real.

Referenced by main().

◆ exact_solution_u()

Real exact_solution_u ( const Point p)

Definition at line 65 of file miscellaneous_ex8.C.

66 {
67  const Real
68  x = p(0),
69  y = p(1),
70  z = p(2);
71 
72  return (x*x*x +
73  y*y*y*y +
74  z*z*z*z*z);
75 }

References libMesh::Real.

Referenced by main().

◆ exact_solution_v()

Real exact_solution_v ( const Point p)

Definition at line 79 of file miscellaneous_ex8.C.

80 {
81  const Real
82  x = p(0),
83  y = p(1),
84  z = p(2);
85 
86  return (x*x +
87  y*y +
88  z*z*z);
89 }

References libMesh::Real.

Referenced by exact_value(), and main().

◆ exact_value()

Number exact_value ( const Point p,
const Parameters ,
const std::string &  ,
const std::string &   
)

Definition at line 91 of file miscellaneous_ex8.C.

95 {
96  return exact_solution_v(p);
97 }

References exact_solution_v().

Referenced by init_sys().

◆ init_sys()

void init_sys ( EquationSystems es,
const std::string &  system_name 
)

Definition at line 103 of file miscellaneous_ex8.C.

105 {
106  // Get a reference to the Convection-Diffusion system object.
107  System & system =
108  es.get_system<System>(system_name);
109 
110  system.project_solution(exact_value, nullptr, es.parameters);
111 }

References exact_value(), libMesh::EquationSystems::get_system(), libMesh::EquationSystems::parameters, and libMesh::System::project_solution().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 116 of file miscellaneous_ex8.C.

117 {
118  // Skip this example if we do not meet certain requirements
119  libmesh_example_requires(3 <= LIBMESH_DIM, "3D support");
120 #ifndef LIBMESH_HAVE_EIGEN
121  libmesh_example_requires(false, "--enable-eigen");
122 #endif
123 #ifndef LIBMESH_HAVE_ZLIB_H
124  libmesh_example_requires(false, "--enable-zlib");
125 #endif
126  // Nanoflann is giving me trouble with extended Reals
127 #ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
128  libmesh_example_requires(false, "--disable-triple-precision");
129 #endif
130 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
131  libmesh_example_requires(false, "--disable-quadruple-precision");
132 #endif
133 
134  // Initialize libMesh.
135  LibMeshInit init (argc, argv);
136  {
137  // Demonstration case 1
138  {
139  std::vector<Point> tgt_pts;
140  std::vector<Number> tgt_data_idi, tgt_data_rbi;
141  std::vector<std::string> field_vars;
142 
143  field_vars.push_back("u");
144  field_vars.push_back("v");
145 
147  /* n_interp_pts = */ 8,
148  /* power = */ 2);
149 
150  RadialBasisInterpolation<3> rbi (init.comm());
151 
152  idi.set_field_variables (field_vars);
153  rbi.set_field_variables (field_vars);
154 
156  idi.get_source_points());
157 
158 
159  // Explicitly set the data values we will interpolate from
160  {
161  const std::vector<Point> & src_pts (idi.get_source_points());
162  std::vector<Number> & src_vals (idi.get_source_vals());
163 
164  src_vals.clear(); src_vals.reserve(2*src_pts.size());
165 
166  for (std::vector<Point>::const_iterator pt_it=src_pts.begin();
167  pt_it != src_pts.end(); ++pt_it)
168  {
169  src_vals.push_back (exact_solution_u (*pt_it));
170  src_vals.push_back (exact_solution_v (*pt_it));
171  }
172  }
173 
174  // give rbi the same info as idi
175  rbi.get_source_points() = idi.get_source_points();
176  rbi.get_source_vals() = idi.get_source_vals();
177 
178  idi.prepare_for_use();
179  rbi.prepare_for_use();
180 
181  libMesh::out << idi;
182 
183  // Interpolate to some other random points, and evaluate the result
184  {
186  tgt_pts);
187 
188  //tgt_pts = rbi.get_source_points();
189 
190  idi.interpolate_field_data (field_vars,
191  tgt_pts,
192  tgt_data_idi);
193 
194  rbi.interpolate_field_data (field_vars,
195  tgt_pts,
196  tgt_data_rbi);
197 
198  std::vector<Number>::const_iterator
199  v_idi = tgt_data_idi.begin(),
200  v_rbi = tgt_data_rbi.begin();
201 
202  for (std::vector<Point>::const_iterator p_it=tgt_pts.begin();
203  p_it!=tgt_pts.end(); ++p_it)
204  {
205  libMesh::out << "\nAt target point " << *p_it
206  << "\n u_interp_idi=" << *v_idi
207  << ", u_interp_rbi=" << *v_rbi
208  << ", u_exact=" << exact_solution_u(*p_it);
209  ++v_idi;
210  ++v_rbi;
211  libMesh::out << "\n v_interp_idi=" << *v_idi
212  << ", v_interp_rbi=" << *v_rbi
213  << ", v_exact=" << exact_solution_v(*p_it)
214  << std::endl;
215  ++v_idi;
216  ++v_rbi;
217  }
218  }
219  }
220 
221 
222  // Demonstration case 2
223  {
224  Mesh mesh_a(init.comm()), mesh_b(init.comm());
225 
226  mesh_a.read("struct.ucd.gz");
227  mesh_b.read("unstruct.ucd.gz");
228 
229  // Create equation systems objects.
231  es_a(mesh_a), es_b(mesh_b);
232 
233  System & sys_a = es_a.add_system<System>("src_system");
234  System & sys_b = es_b.add_system<System>("dest_system");
235 
236  sys_a.add_variable ("Cp", FIRST);
237  sys_b.add_variable ("Cp", FIRST);
238 
240  es_a.init();
241 
242  // Write out the initial conditions.
243  TecplotIO(mesh_a).write_equation_systems ("src.dat",
244  es_a);
245 
247  /* n_interp_pts = */ 4,
248  /* power = */ 2);
249  RadialBasisInterpolation<3> rbi (init.comm());
250 
251  std::vector<Point> & src_pts (idi.get_source_points());
252  std::vector<Number> & src_vals (idi.get_source_vals());
253  std::vector<std::string> field_vars;
254  field_vars.push_back("Cp");
255  idi.set_field_variables(field_vars);
256 
257  // We now will loop over every node in the source mesh
258  // and add it to a source point list, along with the solution
259  for (const auto & node : mesh_a.local_node_ptr_range())
260  {
261  src_pts.push_back(*node);
262  src_vals.push_back(sys_a.current_solution(node->dof_number(0, 0, 0)));
263  }
264 
265  rbi.set_field_variables(field_vars);
266  rbi.get_source_points() = idi.get_source_points();
267  rbi.get_source_vals() = idi.get_source_vals();
268 
269  // We have only set local values - prepare for use by gathering remote data
270  idi.prepare_for_use();
271  rbi.prepare_for_use();
272 
273  // Create a MeshlessInterpolationFunction that uses our InverseDistanceInterpolation
274  // object. Since each MeshlessInterpolationFunction shares the same InverseDistanceInterpolation
275  // object in a threaded environment we must also provide a locking mechanism.
276  {
277  Threads::spin_mutex mutex;
278  MeshlessInterpolationFunction mif(idi, mutex);
279 
280  // project the solution onto system b
281  es_b.init();
282  sys_b.project_solution (&mif);
283 
284  // Write the result
285  TecplotIO(mesh_b).write_equation_systems ("dest_idi.dat",
286  es_b);
287  }
288 
289  // Create a MeshlessInterpolationFunction that uses our RadialBasisInterpolation
290  // object. Since each MeshlessInterpolationFunction shares the same RadialBasisInterpolation
291  // object in a threaded environment we must also provide a locking mechanism.
292  {
293  Threads::spin_mutex mutex;
294  MeshlessInterpolationFunction mif(rbi, mutex);
295 
296  // project the solution onto system b
297  sys_b.project_solution (&mif);
298 
299  // Write the result
300  TecplotIO(mesh_b).write_equation_systems ("dest_rbi.dat",
301  es_b);
302  }
303  }
304  }
305  return 0;
306 }

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::attach_init_function(), create_random_point_cloud(), libMesh::System::current_solution(), exact_solution_u(), exact_solution_v(), libMesh::FIRST, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), init_sys(), libMesh::out, libMesh::UnstructuredMesh::read(), libMesh::MeshfreeInterpolation::set_field_variables(), and libMesh::MeshOutput< MT >::write_equation_systems().

libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
exact_solution_u
Real exact_solution_u(const Point &p)
Definition: miscellaneous_ex8.C:65
libMesh::System::current_solution
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:194
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::System::add_variable
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1069
exact_value
Number exact_value(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: miscellaneous_ex8.C:91
libMesh::UnstructuredMesh::read
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
Definition: unstructured_mesh.C:620
create_random_point_cloud
void create_random_point_cloud(const unsigned int Npts, std::vector< Point > &pts, const Real max_range=10)
Definition: miscellaneous_ex8.C:47
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshOutput::write_equation_systems
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
libMesh::InverseDistanceInterpolation
Inverse distance interpolation.
Definition: meshfree_interpolation.h:179
libMesh::TecplotIO
This class implements writing meshes in the Tecplot format.
Definition: tecplot_io.h:43
libMesh::System::attach_init_function
void attach_init_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in initializing the system.
Definition: system.C:1720
exact_solution_v
Real exact_solution_v(const Point &p)
Definition: miscellaneous_ex8.C:79
libMesh::MeshlessInterpolationFunction
Definition: meshless_interpolation_function.h:44
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::RadialBasisInterpolation
Radial Basis Function interpolation.
Definition: radial_basis_interpolation.h:43
init_sys
void init_sys(EquationSystems &es, const std::string &system_name)
Definition: miscellaneous_ex8.C:103
libMesh::out
OStreamProxy out
libMesh::FIRST
Definition: enum_order.h:42
libMesh::Threads::spin_mutex
Spin mutex.
Definition: threads_none.h:127
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557