MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
particles_extras.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_PARTICLES_EXTRAS
13#define MFEM_PARTICLES_EXTRAS
14
15#include "mfem.hpp"
16#include <list>
17#ifdef MFEM_USE_MPI
18#include "pfem_extras.hpp"
19#else
20#include "fem_extras.hpp"
21#endif // MFEM_USE_MPI
22
23namespace mfem
24{
25namespace common
26{
27
28/// Add a point to a given Mesh, represented as a hex sized \p scale
29void Add3DPoint(const Vector &center, Mesh &m, real_t scale=2e-3);
30
31/// Add a point to a given Mesh, represented as a quad sized \p scale
32void Add2DPoint(const Vector &center, Mesh &m, real_t scale=2e-3);
33
34/** @brief Plot particles in ParticleSet \p pset, represented as quads/hexes of
35 * size \p psize and colored by \p scalar_field .
36 */
37void VisualizeParticles(socketstream &sock, const char* vishost, int visport,
38 const ParticleSet &pset,
39 const Vector &scalar_field, real_t psize,
40 const char* title,
41 int x = 0, int y = 0, int w = 400, int h = 400,
42 const char* keys=nullptr);
43
44/// Helper class for easily visualizing particle trajectories using GLVis
46{
47protected:
49 Mesh *mesh = nullptr;
50
52 /// Track particle IDs that exist at the segment start.
53 std::list<Array<ParticleSet::IDType>> segment_ids;
54 /// Each segment is stored as a Mesh snapshot
55 std::list<Mesh> segment_meshes;
56
58 int x, y, w, h;
59 const char *title, *keys;
60 const char *vishost;
62
63#ifdef MFEM_USE_MPI
64 MPI_Comm comm;
65#endif // MFEM_USE_MPI
66
67 // Mark the start of a new segment for all particles.
68 void AddSegmentStart();
69
70 // Mark the end of the current segment for all particles.
71 void SetSegmentEnd();
72
73public:
74 /** @brief Setup up the particle trajectory for visualization.
75 *
76 * @details Visualize particle trajectory by connecting their positions at
77 * each timestep with line segments. The trajectory "tail" length is
78 * controlled by \p tail_size_. If tail_size_ = 0, entire particle
79 * trajectory is visualized. Optionally, the mesh can also be visualized
80 * along the particles by calling AddMeshForVisualization().
81 *
82 * Note this is a helper utility for quick visualization with GLVis and
83 * not necessarily optimized for large number of particles or long tails.
84 * Consider using the output from ParticleSet::PrintCSV() with ParaView for
85 * more complex visualization needs.
86 */
87 ParticleTrajectories(const ParticleSet &particles, int tail_size_,
88 const char *vishost_, int visport_, const char *title_,
89 int x_=0, int y_=0, int w_=400, int h_=400,
90 const char *keys_=nullptr);
91
92 /// Add a mesh to be visualized along with the particle trajectories.
93 void AddMeshForVisualization(Mesh *mesh_) { mesh = mesh_; }
94
95 /// Visualize the particle trajectories (and mesh if provided).
96 void Visualize();
97};
98
99
100} // namespace common
101} // namespace mfem
102
103
104#endif // MFEM_PARTICLES_EXTRAS
Mesh data type.
Definition mesh.hpp:65
ParticleSet initializes and manages data associated with particles.
Helper class for easily visualizing particle trajectories using GLVis.
void Visualize()
Visualize the particle trajectories (and mesh if provided).
void AddMeshForVisualization(Mesh *mesh_)
Add a mesh to be visualized along with the particle trajectories.
std::list< Array< ParticleSet::IDType > > segment_ids
Track particle IDs that exist at the segment start.
ParticleTrajectories(const ParticleSet &particles, int tail_size_, const char *vishost_, int visport_, const char *title_, int x_=0, int y_=0, int w_=400, int h_=400, const char *keys_=nullptr)
Setup up the particle trajectory for visualization.
std::list< Mesh > segment_meshes
Each segment is stored as a Mesh snapshot.
mfem::real_t real_t
void Add2DPoint(const Vector &center, Mesh &m, real_t scale)
Add a point to a given Mesh, represented as a quad sized scale.
void Add3DPoint(const Vector &center, Mesh &m, real_t scale)
Add a point to a given Mesh, represented as a hex sized scale.
void VisualizeParticles(socketstream &sock, const char *vishost, int visport, const ParticleSet &pset, const Vector &scalar_field, real_t psize, const char *title, int x, int y, int w, int h, const char *keys)
Plot particles in ParticleSet pset, represented as quads/hexes of size psize and colored by scalar_fi...
const char vishost[]