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  if (!app.getSystemInfo())
25  return;
26 
27  json["app_name"] = app.name();
28  json["current_time"] = app.getSystemInfo()->getTimeStamp();
29  json["executable"] = app.getSystemInfo()->getExecutable();
30  json["executable_time"] = app.getSystemInfo()->getExecutableTimeStamp(json["executable"]);
31 
32  json["moose_version"] = MOOSE_REVISION;
33  json["libmesh_version"] = LIBMESH_BUILD_VERSION;
34 #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
35  json["petsc_version"] = std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MAJOR) + "." +
36  std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MINOR) + "." +
37  std::to_string(LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR);
38 #endif
39 #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
40  json["slepc_version"] = std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MAJOR) + "." +
41  std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MINOR) + "." +
42  std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR);
43 #endif
44 }
45 // MooseDocs:to_json_end
46 
47 namespace libMesh
48 {
49 void
50 to_json(nlohmann::json & json, const libMesh::Point & p)
51 {
52  json["x"] = p(0);
53  json["y"] = p(1);
54  json["z"] = p(2);
55 }
56 
57 void
58 to_json(nlohmann::json & json, const DenseVector<Real> & vector)
59 {
60  nlohmann::to_json(json, vector.get_values());
61 }
62 
63 void
64 to_json(nlohmann::json & json, const DenseMatrix<Real> & matrix)
65 {
66  std::vector<std::vector<Real>> values(matrix.m(), std::vector<Real>(matrix.n()));
67  for (const auto i : make_range(matrix.m()))
68  for (const auto j : make_range(matrix.n()))
69  values[i][j] = matrix(i, j);
70  nlohmann::to_json(json, values);
71 }
72 
73 void
74 to_json(nlohmann::json & json, const std::unique_ptr<NumericVector<Number>> & vector)
75 {
76  mooseAssert(vector, "vector must be non-null");
77  std::vector<Number> local_values;
78  local_values.reserve(vector->local_size());
79  for (const auto i : make_range(vector->first_local_index(), vector->last_local_index()))
80  local_values.push_back((*vector)(i));
81  nlohmann::to_json(json, local_values);
82 }
83 }
std::string getExecutable() const
Definition: SystemInfo.C:138
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:65
void to_json(nlohmann::json &json, const Point &p)
Definition: JsonIO.C:50
unsigned int m() const
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
std::string getExecutableTimeStamp() const
Definition: SystemInfo.C:149
const SystemInfo * getSystemInfo() const
Get SystemInfo object.
Definition: MooseApp.h:584
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