MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
particles_extras.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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; // optional edge mesh to visualize along with particles
50 Mesh *mesh_bb = nullptr; // optional bounding box mesh for visualization
51
53 /// Track particle IDs that exist at the segment start.
54 std::list<Array<ParticleSet::IDType>> segment_ids;
55 /// Each segment is stored as a Mesh snapshot
56 std::list<Mesh> segment_meshes;
57
59 int x, y, w, h;
60 const char *title, *keys;
61 const char *vishost;
63
64#ifdef MFEM_USE_MPI
65 MPI_Comm comm;
66#endif // MFEM_USE_MPI
67
68 // Mark the start of a new segment for all particles.
69 void AddSegmentStart();
70
71 // Mark the end of the current segment for all particles.
72 void SetSegmentEnd();
73
74public:
75 /** @brief Setup up the particle trajectory for visualization.
76 *
77 * @details Visualize particle trajectory by connecting their positions at
78 * each timestep with line segments. The trajectory "tail" length is
79 * controlled by \p tail_size_. If tail_size_ = 0, entire particle
80 * trajectory is visualized. Optionally, the mesh can also be visualized
81 * along the particles by calling AddMeshForVisualization().
82 *
83 * Note this is a helper utility for quick visualization with GLVis and
84 * not necessarily optimized for large number of particles or long tails.
85 * Consider using the output from ParticleSet::PrintCSV() with ParaView for
86 * more complex visualization needs.
87 */
88 ParticleTrajectories(const ParticleSet &particles, int tail_size_,
89 const char *vishost_, int visport_, const char *title_,
90 int x_=0, int y_=0, int w_=400, int h_=400,
91 const char *keys_=nullptr);
92
93 /// Add a mesh to be visualized along with the particle trajectories.
95 {
96 MFEM_VERIFY(mesh_->Dimension() == 1,
97 "Mesh dimension must be 1 to match the particle trajectory.");
98 mesh = mesh_;
99 }
100
101 /// Visualize the particle trajectories (and mesh if provided).
102 void Visualize();
103
104 /// Set the bounding box for visualization.
105 void SetVisualizationBoundingBox(const Vector &xmin, const Vector &xmax);
106
107 /// Destructor
109 {
110 delete mesh_bb;
111 }
112};
113
114
115} // namespace common
116} // namespace mfem
117
118
119#endif // MFEM_PARTICLES_EXTRAS
Mesh data type.
Definition mesh.hpp:67
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1314
ParticleSet initializes and manages data associated with particles.
Vector data type.
Definition vector.hpp:82
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.
void SetVisualizationBoundingBox(const Vector &xmin, const Vector &xmax)
Set the bounding box for visualization.
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[]