LCOV - code coverage report
Current view: top level - src/outputs - JsonIO.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 27 37 73.0 %
Date: 2025-07-17 01:28:37 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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         726 : to_json(nlohmann::json & json, const MooseApp & app)
      23             : {
      24         726 :   if (!app.getSystemInfo())
      25          48 :     return;
      26             : 
      27         678 :   json["app_name"] = app.name();
      28         678 :   json["current_time"] = app.getSystemInfo()->getTimeStamp();
      29         678 :   json["executable"] = app.getSystemInfo()->getExecutable();
      30         678 :   json["executable_time"] = app.getSystemInfo()->getExecutableTimeStamp(json["executable"]);
      31             : 
      32         678 :   json["moose_version"] = MOOSE_REVISION;
      33         678 :   json["libmesh_version"] = LIBMESH_BUILD_VERSION;
      34             : #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
      35        2034 :   json["petsc_version"] = std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MAJOR) + "." +
      36        2712 :                           std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MINOR) + "." +
      37        2712 :                           std::to_string(LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR);
      38             : #endif
      39             : #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
      40        2034 :   json["slepc_version"] = std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MAJOR) + "." +
      41        2712 :                           std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MINOR) + "." +
      42        2712 :                           std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR);
      43             : #endif
      44             : }
      45             : // MooseDocs:to_json_end
      46             : 
      47             : namespace libMesh
      48             : {
      49             : void
      50        2418 : to_json(nlohmann::json & json, const libMesh::Point & p)
      51             : {
      52        2418 :   json["x"] = p(0);
      53        2418 :   json["y"] = p(1);
      54        2418 :   json["z"] = p(2);
      55        2418 : }
      56             : 
      57             : void
      58           0 : to_json(nlohmann::json & json, const DenseVector<Real> & vector)
      59             : {
      60           0 :   nlohmann::to_json(json, vector.get_values());
      61           0 : }
      62             : 
      63             : void
      64           1 : to_json(nlohmann::json & json, const DenseMatrix<Real> & matrix)
      65             : {
      66           1 :   std::vector<std::vector<Real>> values(matrix.m(), std::vector<Real>(matrix.n()));
      67           3 :   for (const auto i : make_range(matrix.m()))
      68           8 :     for (const auto j : make_range(matrix.n()))
      69           6 :       values[i][j] = matrix(i, j);
      70           1 :   nlohmann::to_json(json, values);
      71           1 : }
      72             : 
      73             : void
      74           0 : to_json(nlohmann::json & json, const std::unique_ptr<NumericVector<Number>> & vector)
      75             : {
      76             :   mooseAssert(vector, "vector must be non-null");
      77           0 :   std::vector<Number> local_values;
      78           0 :   local_values.reserve(vector->local_size());
      79           0 :   for (const auto i : make_range(vector->first_local_index(), vector->last_local_index()))
      80           0 :     local_values.push_back((*vector)(i));
      81           0 :   nlohmann::to_json(json, local_values);
      82           0 : }
      83             : }

Generated by: LCOV version 1.14