LCOV - code coverage report
Current view: top level - src/base - SwiftApp.C (source / functions) Hit Total Coverage
Test: idaholab/swift: #92 (25e020) with base b3cd84 Lines: 71 81 87.7 %
Date: 2025-09-10 17:10:32 Functions: 12 15 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**********************************************************************/
       2             : /*                    DO NOT MODIFY THIS HEADER                       */
       3             : /*             Swift, a Fourier spectral solver for MOOSE             */
       4             : /*                                                                    */
       5             : /*            Copyright 2024 Battelle Energy Alliance, LLC            */
       6             : /*                        ALL RIGHTS RESERVED                         */
       7             : /**********************************************************************/
       8             : 
       9             : #include "SwiftApp.h"
      10             : #include "Moose.h"
      11             : #include "AppFactory.h"
      12             : #include "ModulesApp.h"
      13             : #include "MooseSyntax.h"
      14             : #include "DomainAction.h"
      15             : #include "SwiftUtils.h"
      16             : 
      17             : #include <cstdlib>
      18             : 
      19             : namespace MooseTensor
      20             : {
      21             : static struct SwiftGlobalSettings
      22             : {
      23         138 :   SwiftGlobalSettings()
      24         138 :   {
      25         138 :     const auto env = std::getenv("SWIFT_TORCH_DEVICE");
      26         138 :     if (env)
      27           0 :       _torch_device = std::string(env);
      28             :     else
      29         138 :       _torch_device = "";
      30         138 :   }
      31             :   std::string _torch_device;
      32             :   std::string _floating_precision;
      33             : } swift_global_settings;
      34             : 
      35             : std::string
      36         514 : torchDevice()
      37             : {
      38         514 :   return swift_global_settings._torch_device;
      39             : }
      40             : 
      41             : std::string
      42         298 : precision()
      43             : {
      44         298 :   return swift_global_settings._floating_precision;
      45             : }
      46             : }
      47             : 
      48             : InputParameters
      49         136 : SwiftApp::validParams()
      50             : {
      51         136 :   InputParameters params = MooseApp::validParams();
      52         136 :   params.set<bool>("use_legacy_material_output") = false;
      53         136 :   params.set<bool>("use_legacy_initial_residual_evaluation_behavior") = false;
      54         136 :   return params;
      55           0 : }
      56             : 
      57         136 : SwiftApp::SwiftApp(const InputParameters & parameters) : MooseApp(parameters)
      58             : {
      59         136 :   SwiftApp::registerAll(_factory, _action_factory, _syntax);
      60             :   MooseTensor::swift_global_settings._torch_device =
      61         272 :       std::string(parameters.get<MooseEnum>("compute_device"));
      62         136 : }
      63             : 
      64         260 : SwiftApp::~SwiftApp() {}
      65             : 
      66             : void
      67          20 : SwiftApp::setTorchDevice(std::string device, const MooseTensor::Key<DomainAction> &)
      68             : {
      69             :   MooseTensor::swift_global_settings._torch_device = device;
      70          20 : }
      71             : 
      72             : void
      73           0 : SwiftApp::setTorchDeviceStatic(std::string device, const MooseTensor::Key<SwiftInit> &)
      74             : {
      75             :   MooseTensor::swift_global_settings._torch_device = device;
      76           0 : }
      77             : 
      78             : void
      79          20 : SwiftApp::setTorchPrecision(std::string precision, const MooseTensor::Key<DomainAction> &)
      80             : {
      81             :   MooseTensor::swift_global_settings._floating_precision = precision;
      82          20 : }
      83             : 
      84             : void
      85         136 : SwiftApp::registerAll(Factory & f, ActionFactory & af, Syntax & syntax)
      86             : {
      87             :   ModulesApp::registerAllObjects<SwiftApp>(f, af, syntax);
      88         136 :   Registry::registerObjectsTo(f, {"SwiftApp"});
      89         136 :   Registry::registerActionsTo(af, {"SwiftApp"});
      90             : 
      91         408 :   auto registerDeep = [&](const std::string & base_path, const std::string & task)
      92             :   {
      93         408 :     registerMooseObjectTask(task, TensorOperator, false);
      94         408 :     std::string path = base_path;
      95             :     // register five levels deep
      96        2448 :     for (unsigned int i = 0; i < 5; ++i)
      97             :     {
      98             :       path += "/*";
      99        2040 :       syntax.registerSyntaxType(path, "TensorComputeName");
     100        4080 :       registerSyntaxTask("AddTensorComputeAction", path, task);
     101             :     }
     102         408 :   };
     103             : 
     104             :   // ComputeDevice Action
     105         272 :   registerSyntax("DomainAction", "Domain");
     106             : 
     107             :   // LBM Stencil Actions
     108         272 :   registerSyntaxTask("AddLBMStencilAction", "Stencil/*", "add_stencil");
     109         272 :   syntax.registerSyntaxType("Stencil/*", "StencilName");
     110         272 :   registerMooseObjectTask("add_stencil", LBStencil, false);
     111         272 :   addTaskDependency("add_stencil", "add_aux_variable");
     112             : 
     113             :   // TensorBuffer Actions
     114         272 :   registerSyntaxTask("AddTensorBufferAction", "TensorBuffers/*", "add_tensor_buffer");
     115         272 :   syntax.registerSyntaxType("TensorBuffers/*", "TensorInputBufferName");
     116         272 :   syntax.registerSyntaxType("TensorBuffers/*", "TensorOutputBufferName");
     117         272 :   registerMooseObjectTask("add_tensor_buffer", TensorBuffer, false);
     118         272 :   addTaskDependency("add_tensor_buffer", "add_stencil");
     119             : 
     120             :   // TensorComputes/Initial Actions
     121         272 :   registerDeep("TensorComputes/Initialize", "add_tensor_ic");
     122         272 :   addTaskDependency("add_tensor_ic", "add_tensor_buffer");
     123             : 
     124             :   // TensorComputes/Boundary Actions
     125         272 :   registerSyntaxTask("AddLBMBCAction", "TensorComputes/Boundary/*", "add_tensor_bc");
     126         272 :   syntax.registerSyntaxType("TensorComputes/Boundary/*", "TensorComputeName");
     127         272 :   registerMooseObjectTask("add_tensor_bc", TensorOperator, false);
     128         272 :   addTaskDependency("add_tensor_bc", "add_tensor_buffer");
     129             : 
     130             :   // TensorComputes/Solve Action
     131         272 :   registerDeep("TensorComputes/Solve", "add_tensor_compute");
     132         272 :   addTaskDependency("add_tensor_compute", "add_tensor_ic");
     133             : 
     134             :   // TensorComputes/Postprocess Action
     135         272 :   registerDeep("TensorComputes/Postprocess", "add_tensor_postprocessor");
     136         272 :   addTaskDependency("add_tensor_postprocessor", "add_tensor_compute");
     137             : 
     138         272 :   registerSyntaxTask("EmptyAction", "TensorComputes", "no_action"); // placeholder
     139             : 
     140             :   // TensorOutputs Action
     141         272 :   registerSyntaxTask("AddTensorOutputAction", "TensorOutputs/*", "add_tensor_output");
     142         272 :   syntax.registerSyntaxType("TensorOutputs/*", "TensorOutputName");
     143         272 :   registerMooseObjectTask("add_tensor_output", TensorOutput, false);
     144         272 :   addTaskDependency("add_tensor_output", "add_tensor_postprocessor");
     145             : 
     146             :   // Create TensorSolver
     147         272 :   registerSyntaxTask("CreateTensorSolverAction", "TensorSolver", "create_tensor_solver");
     148         272 :   registerMooseObjectTask("create_tensor_solver", TensorSolver, false);
     149         272 :   addTaskDependency("create_tensor_solver", "add_tensor_output");
     150             : 
     151             :   // Add predictors to the solver
     152         272 :   registerSyntaxTask(
     153             :       "AddTensorPredictorAction", "TensorSolver/Predictors/*", "add_tensor_predictor");
     154         272 :   syntax.registerSyntaxType("TensorSolver/Predictors/*", "TensorPredictorName");
     155         272 :   registerMooseObjectTask("add_tensor_predictor", TensorPredictor, false);
     156         272 :   addTaskDependency("add_tensor_predictor", "create_tensor_solver");
     157             : 
     158             :   // make sure all this gets run before `add_mortar_variable`
     159         272 :   addTaskDependency("add_mortar_variable", "add_tensor_predictor");
     160         136 : }
     161             : 
     162             : void
     163         136 : SwiftApp::registerApps()
     164             : {
     165         136 :   registerApp(SwiftApp);
     166         136 : }
     167             : 
     168             : /***************************************************************************************************
     169             :  *********************** Dynamic Library Entry Points - DO NOT MODIFY ******************************
     170             :  **************************************************************************************************/
     171             : extern "C" void
     172           0 : SwiftApp__registerAll(Factory & f, ActionFactory & af, Syntax & s)
     173             : {
     174           0 :   SwiftApp::registerAll(f, af, s);
     175           0 : }
     176             : extern "C" void
     177           0 : SwiftApp__registerApps()
     178             : {
     179           0 :   SwiftApp::registerApps();
     180           0 : }

Generated by: LCOV version 1.14