https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMVectorUtils.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#include "MFEMVectorUtils.h"
13#include "libmesh/int_range.h"
14
15namespace Moose::MFEM
16{
18libMeshPointFromMFEMVector(const mfem::Vector & vec)
19{
20 return libMesh::Point(vec(0), vec.Size() > 1 ? vec(1) : 0., vec.Size() > 2 ? vec(2) : 0.);
21}
22
23mfem::Vector
24libMeshPointsToMFEMVector(const std::vector<libMesh::Point> & points,
25 const unsigned int num_dims,
26 const mfem::Ordering::Type ordering)
27{
28 const unsigned int num_points = points.size();
29 mfem::Vector mfem_points(num_points * num_dims);
30 for (const auto i_point : libMesh::make_range(num_points))
31 for (const auto i_dim : libMesh::make_range(num_dims))
32 mfem_points(MFEMIndex(i_dim, i_point, num_dims, num_points, ordering)) =
33 points[i_point](i_dim);
34
35 return mfem_points;
36}
37}
38
39#endif
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
std::size_t MFEMIndex(const std::size_t i_dim, const std::size_t i_point, const std::size_t num_dims, const std::size_t num_points, const mfem::Ordering::Type ordering)
Convert an index of a vector of libMesh::Points to an MFEM vector index, given an MFEM ordering.
mfem::Vector libMeshPointsToMFEMVector(const std::vector< libMesh::Point > &points, const unsigned int num_dims, const mfem::Ordering::Type ordering)
Convert a vector of libMesh::Point objects to an mfem::Vector containing all points,...
libMesh::Point libMeshPointFromMFEMVector(const mfem::Vector &vec)
Convert an MFEM position vector to a libMesh::Point.
IntRange< T > make_range(T beg, T end)