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