LCOV - code coverage report
Current view: top level - src/utils - ADFParser.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 21 26 80.8 %
Date: 2025-08-08 20:01:16 Functions: 5 5 100.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 "ADFParser.h"
      11             : #include "MooseUtils.h"
      12             : #include "ExecutablePath.h"
      13             : 
      14        2087 : ADFParser::ADFParser() : FunctionParserAD(), _epsilon(1e-12) {}
      15             : 
      16        3039 : ADFParser::ADFParser(const ADFParser & cpy) : FunctionParserAD(cpy), _epsilon(1e-12) {}
      17             : 
      18             : #ifndef ADFPARSER_INCLUDES
      19             : #error ... \
      20             :        The ADFPARSER_INCLUDES macro is not defined. A possible reason is that you       \
      21             :        are compiling MOOSE from a custom application. Please check your application     \
      22             :        Makefile and make sure that you are appending options to ADDITIONAL_CPPFLAGS     \
      23             :        using the += operator, rather than overwriting the variable with the := operator.
      24             : #endif
      25             : 
      26             : bool
      27        4889 : ADFParser::JITCompile()
      28             : {
      29             : #if LIBMESH_HAVE_FPARSER_JIT
      30        4889 :   std::string includes;
      31        4889 :   const auto type_hash = typeid(ADReal).hash_code();
      32             :   bool result;
      33             : 
      34        4889 :   std::string fopenmp;
      35             : #if defined(_OPENMP)
      36        4889 :   fopenmp = "-fopenmp";
      37             : #endif
      38             : 
      39        4889 :   const auto include_path_env = std::getenv("MOOSE_ADFPARSER_JIT_INCLUDE");
      40        4889 :   if (include_path_env)
      41           0 :     result = JITCompileHelper(
      42           0 :         "ADReal", fopenmp, "#include \"" + std::string(include_path_env) + "\"\n", type_hash);
      43             :   else
      44             :   {
      45             :     // check if we can find an installed version of the monolithic include
      46             :     const std::string include_path =
      47        4889 :         MooseUtils::pathjoin(Moose::getExecutablePath(), "../include/moose/ADRealMonolithic.h");
      48        4889 :     if (MooseUtils::checkFileReadable(include_path, false, false, false))
      49             :       result =
      50           0 :           JITCompileHelper("ADReal", fopenmp, "#include \"" + include_path + "\"\n", type_hash);
      51             :     else
      52             :       // otherwise use the compiled in location from the source tree
      53       14667 :       result = JITCompileHelper("ADReal",
      54        9778 :                                 fopenmp + " " + ADFPARSER_INCLUDES,
      55             :                                 "#include \"MooseConfig.h\"\n#include \"ADReal.h\"\n",
      56             :                                 type_hash);
      57        4889 :   }
      58             : 
      59        4889 :   if (!result)
      60             : #endif
      61           0 :     mooseError("ADFParser::JITCompile() failed. Evaluation not possible.");
      62             : 
      63        4889 :   return true;
      64        4889 : }
      65             : 
      66             : ADReal
      67     6358892 : ADFParser::Eval(const ADReal * vars)
      68             : {
      69             :   mooseAssert(compiledFunction, "ADFParser objects must be JIT compiled before evaluation!");
      70     6358892 :   ADReal ret;
      71     6358892 :   (*reinterpret_cast<CompiledFunctionPtr<ADReal>>(compiledFunction))(&ret, vars, pImmed, _epsilon);
      72     6358892 :   return ret;
      73           0 : }

Generated by: LCOV version 1.14