1 // Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and
2 // other Axom Project Developers. See the top-level LICENSE file for details.
3 //
4 // SPDX-License-Identifier: (BSD-3-Clause)
5 #include "axom/mint/mesh/ParticleMesh.hpp"
6
7 #include "axom/core/Macros.hpp"
8
9 #include "axom/mint/config.hpp" // for compile-time type definitions
10 #include "axom/mint/mesh/MeshCoordinates.hpp" // for mint::MeshCoordinates class
11 #include "axom/mint/mesh/blueprint.hpp" // for mint::blueprint() functions
12
13 #include "axom/mint/mesh/internal/MeshHelpers.hpp" // for internal helpers
14
15 namespace axom
16 {
17 namespace mint
18 {
19 //------------------------------------------------------------------------------
ParticleMesh(int dimension,IndexType numParticles,IndexType capacity)20 ParticleMesh::ParticleMesh(int dimension, IndexType numParticles, IndexType capacity)
21 : Mesh(dimension, PARTICLE_MESH)
22 , m_positions(new MeshCoordinates(dimension, numParticles, capacity))
23 {
24 initialize();
25 }
26
27 //------------------------------------------------------------------------------
ParticleMesh(IndexType numParticles,double * x,double * y,double * z)28 ParticleMesh::ParticleMesh(IndexType numParticles, double* x, double* y, double* z)
29 : Mesh(internal::dim(x, y, z), PARTICLE_MESH)
30 , m_positions(new MeshCoordinates(numParticles, numParticles, x, y, z))
31 {
32 initialize();
33 }
34
35 //------------------------------------------------------------------------------
36 #ifdef AXOM_MINT_USE_SIDRE
37
ParticleMesh(sidre::Group * group,const std::string & topo)38 ParticleMesh::ParticleMesh(sidre::Group* group, const std::string& topo)
39 : Mesh(group, topo)
40 , m_positions(new MeshCoordinates(getCoordsetGroup()))
41 {
42 SLIC_ERROR_IF(m_type != PARTICLE_MESH,
43 "supplied Sidre group does not correspond to a ParticleMesh");
44
45 initialize();
46 }
47
48 //------------------------------------------------------------------------------
ParticleMesh(int dimension,IndexType numParticles,sidre::Group * group,const std::string & topo,const std::string & coordset,IndexType capacity)49 ParticleMesh::ParticleMesh(int dimension,
50 IndexType numParticles,
51 sidre::Group* group,
52 const std::string& topo,
53 const std::string& coordset,
54 IndexType capacity)
55 : Mesh(dimension, PARTICLE_MESH, group, topo, coordset)
56 , m_positions(nullptr)
57 {
58 blueprint::initializeTopologyGroup(m_group, m_topology, m_coordset, "points");
59
60 SLIC_ERROR_IF(!blueprint::isValidTopologyGroup(getTopologyGroup()),
61 "invalid topology group!");
62
63 m_positions =
64 new MeshCoordinates(getCoordsetGroup(), dimension, numParticles, capacity);
65
66 initialize();
67 }
68
69 //------------------------------------------------------------------------------
ParticleMesh(int dimension,IndexType numParticles,sidre::Group * group,IndexType capacity)70 ParticleMesh::ParticleMesh(int dimension,
71 IndexType numParticles,
72 sidre::Group* group,
73 IndexType capacity)
74 : ParticleMesh(dimension, numParticles, group, "", "", capacity)
75 { }
76
77 #endif
78
79 //------------------------------------------------------------------------------
initialize()80 void ParticleMesh::initialize()
81 {
82 SLIC_ERROR_IF(m_positions == nullptr, "null particle positions!");
83
84 m_mesh_fields[NODE_CENTERED]->reserve(getNodeCapacity());
85 m_mesh_fields[NODE_CENTERED]->resize(getNumberOfNodes());
86 m_explicit_coords = true;
87 m_explicit_connectivity = false;
88 m_has_mixed_topology = false;
89 }
90
91 //------------------------------------------------------------------------------
~ParticleMesh()92 ParticleMesh::~ParticleMesh()
93 {
94 delete m_positions;
95 m_positions = nullptr;
96 }
97
98 //------------------------------------------------------------------------------
checkConsistency()99 bool ParticleMesh::checkConsistency()
100 {
101 return m_mesh_fields[NODE_CENTERED]->checkConsistency(getNumberOfNodes(),
102 getNodeCapacity());
103 }
104
105 } /* namespace mint */
106 } /* namespace axom */
107