LCOV - code coverage report
Current view: top level - src/outputs - JsonIO.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 909fe5 Lines: 26 36 72.2 %
Date: 2025-08-29 20:01:24 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         821 : to_json(nlohmann::json & json, const MooseApp & app)
      23             : {
      24         821 :   json["app_name"] = app.name();
      25         821 :   json["current_time"] = app.getSystemInfo().getTimeStamp();
      26         821 :   json["executable"] = app.getSystemInfo().getExecutable();
      27         821 :   json["executable_time"] = app.getSystemInfo().getExecutableTimeStamp(json["executable"]);
      28             : 
      29         821 :   json["moose_version"] = MOOSE_REVISION;
      30         821 :   json["libmesh_version"] = LIBMESH_BUILD_VERSION;
      31             : #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
      32        2463 :   json["petsc_version"] = std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MAJOR) + "." +
      33        3284 :                           std::to_string(LIBMESH_DETECTED_PETSC_VERSION_MINOR) + "." +
      34        3284 :                           std::to_string(LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR);
      35             : #endif
      36             : #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
      37        2463 :   json["slepc_version"] = std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MAJOR) + "." +
      38        3284 :                           std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_MINOR) + "." +
      39        3284 :                           std::to_string(LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR);
      40             : #endif
      41         821 : }
      42             : // MooseDocs:to_json_end
      43             : 
      44             : namespace libMesh
      45             : {
      46             : void
      47        2951 : to_json(nlohmann::json & json, const libMesh::Point & p)
      48             : {
      49        2951 :   json["x"] = p(0);
      50        2951 :   json["y"] = p(1);
      51        2951 :   json["z"] = p(2);
      52        2951 : }
      53             : 
      54             : void
      55           0 : to_json(nlohmann::json & json, const DenseVector<Real> & vector)
      56             : {
      57           0 :   nlohmann::to_json(json, vector.get_values());
      58           0 : }
      59             : 
      60             : void
      61           1 : to_json(nlohmann::json & json, const DenseMatrix<Real> & matrix)
      62             : {
      63           2 :   std::vector<std::vector<Real>> values(matrix.m(), std::vector<Real>(matrix.n()));
      64           3 :   for (const auto i : make_range(matrix.m()))
      65           8 :     for (const auto j : make_range(matrix.n()))
      66           6 :       values[i][j] = matrix(i, j);
      67           1 :   nlohmann::to_json(json, values);
      68           1 : }
      69             : 
      70             : void
      71           0 : to_json(nlohmann::json & json, const std::unique_ptr<NumericVector<Number>> & vector)
      72             : {
      73             :   mooseAssert(vector, "vector must be non-null");
      74           0 :   std::vector<Number> local_values;
      75           0 :   local_values.reserve(vector->local_size());
      76           0 :   for (const auto i : make_range(vector->first_local_index(), vector->last_local_index()))
      77           0 :     local_values.push_back((*vector)(i));
      78           0 :   nlohmann::to_json(json, local_values);
      79           0 : }
      80             : }

Generated by: LCOV version 1.14