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 2242 : 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 5044 : ADFParser::JITCompile() 28 : { 29 : #if LIBMESH_HAVE_FPARSER_JIT 30 5044 : std::string includes; 31 5044 : const auto type_hash = typeid(ADReal).hash_code(); 32 : bool result; 33 : 34 5044 : std::string fopenmp; 35 : #if defined(_OPENMP) 36 : #if defined(__INTEL_LLVM_COMPILER) 37 : fopenmp = "-qopenmp"; 38 : #else 39 5044 : fopenmp = "-fopenmp"; 40 : #endif 41 : #endif 42 : 43 5044 : const auto include_path_env = std::getenv("MOOSE_ADFPARSER_JIT_INCLUDE"); 44 5044 : if (include_path_env) 45 0 : result = JITCompileHelper( 46 0 : "ADReal", fopenmp, "#include \"" + std::string(include_path_env) + "\"\n", type_hash); 47 : else 48 : { 49 : // check if we can find an installed version of the monolithic include 50 : const std::string include_path = 51 5044 : MooseUtils::pathjoin(Moose::getExecutablePath(), "../include/moose/ADRealMonolithic.h"); 52 5044 : if (MooseUtils::checkFileReadable(include_path, false, false, false)) 53 : result = 54 0 : JITCompileHelper("ADReal", fopenmp, "#include \"" + include_path + "\"\n", type_hash); 55 : else 56 : // otherwise use the compiled in location from the source tree 57 20176 : result = JITCompileHelper("ADReal", 58 10088 : fopenmp + " " + ADFPARSER_INCLUDES, 59 : "#include \"MooseConfig.h\"\n#include \"ADReal.h\"\n", 60 : type_hash); 61 5044 : } 62 : 63 5044 : if (!result) 64 : #endif 65 0 : mooseError("ADFParser::JITCompile() failed. Evaluation not possible."); 66 : 67 5044 : return true; 68 5044 : } 69 : 70 : ADReal 71 6588445 : ADFParser::Eval(const ADReal * vars) 72 : { 73 : mooseAssert(compiledFunction, "ADFParser objects must be JIT compiled before evaluation!"); 74 6588445 : ADReal ret; 75 6588445 : (*reinterpret_cast<CompiledFunctionPtr<ADReal>>(compiledFunction))(&ret, vars, pImmed, _epsilon); 76 6588445 : return ret; 77 0 : }