https://mooseframework.inl.gov
Loading...
Searching...
No Matches
JsonIO.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#include "JsonIO.h"
11#include "MooseApp.h"
12#include "MooseRevision.h"
13#include "SystemInfo.h"
14
15#include "libmesh/bounding_box.h"
16#include "libmesh/libmesh_config.h"
17#include "libmesh/int_range.h"
18#include "libmesh/dense_vector.h"
19#include "libmesh/dense_matrix.h"
20
21// MooseDocs:to_json_start
22void
23to_json(nlohmann::json & json, const MooseApp & app)
24{
25 json["app_name"] = app.name();
26 json["current_time"] = app.getSystemInfo().getTimeStamp();
27 json["executable"] = app.getSystemInfo().getExecutable();
28 json["executable_time"] = app.getSystemInfo().getExecutableTimeStamp(json["executable"]);
29
30 json["moose_version"] = MOOSE_REVISION;
31 json["libmesh_version"] = LIBMESH_BUILD_VERSION;
32#ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
33 json["petsc_version"] = std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MAJOR) + "." +
34 std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MINOR) + "." +
35 std::to_string(LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR);
36#endif
37#ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
38 json["slepc_version"] = std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MAJOR) + "." +
39 std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MINOR) + "." +
40 std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR);
41#endif
42}
43// MooseDocs:to_json_end
44
45namespace libMesh
46{
47void
48to_json(nlohmann::json & json, const libMesh::BoundingBox & bbox)
49{
50 json = {{"max", bbox.max()}, {"min", bbox.min()}};
51}
52
53void
54to_json(nlohmann::json & json, const libMesh::Point & p)
55{
56 json = {{"x", p(0)}, {"y", p(1)}, {"z", p(2)}};
57}
58
59void
60to_json(nlohmann::json & json, const DenseVector<Real> & vector)
61{
62 nlohmann::to_json(json, vector.get_values());
63}
64
65void
66to_json(nlohmann::json & json, const DenseMatrix<Real> & matrix)
67{
68 std::vector<std::vector<Real>> values(matrix.m(), std::vector<Real>(matrix.n()));
69 for (const auto i : make_range(matrix.m()))
70 for (const auto j : make_range(matrix.n()))
71 values[i][j] = matrix(i, j);
72 nlohmann::to_json(json, values);
73}
74
75void
76to_json(nlohmann::json & json, const std::unique_ptr<NumericVector<Number>> & vector)
77{
78 mooseAssert(vector, "vector must be non-null");
79 std::vector<Number> local_values;
80 local_values.reserve(vector->local_size());
81 for (const auto i : make_range(vector->first_local_index(), vector->last_local_index()))
82 local_values.push_back((*vector)(i));
83 nlohmann::to_json(json, local_values);
84}
85}
void to_json(nlohmann::json &json, const MooseApp &app)
Definition JsonIO.C:23
std::array< Real, 2 > values
Definition MortarUtils.C:52
Base class for MOOSE-based applications.
Definition MooseApp.h:110
const SystemInfo & getSystemInfo() const
Get SystemInfo object.
Definition MooseApp.h:567
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
std::string getExecutableTimeStamp() const
Definition SystemInfo.C:145
std::string getExecutable() const
Definition SystemInfo.C:139
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition SystemInfo.C:66
const Point & max() const
const Point & min() const
unsigned int n() const
unsigned int m() const
std::vector< T > & get_values()
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void to_json(nlohmann::json &json, const BoundingBox &p)
Definition JsonIO.C:48
IntRange< T > make_range(T beg, T end)