LCOV - code coverage report
Current view: top level - src/transfers - NekFieldVariable.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 46 54 85.2 %
Date: 2025-07-15 20:50:38 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /********************************************************************/
       2             : /*                  SOFTWARE COPYRIGHT NOTIFICATION                 */
       3             : /*                             Cardinal                             */
       4             : /*                                                                  */
       5             : /*                  (c) 2021 UChicago Argonne, LLC                  */
       6             : /*                        ALL RIGHTS RESERVED                       */
       7             : /*                                                                  */
       8             : /*                 Prepared by UChicago Argonne, LLC                */
       9             : /*               Under Contract No. DE-AC02-06CH11357               */
      10             : /*                With the U. S. Department of Energy               */
      11             : /*                                                                  */
      12             : /*             Prepared by Battelle Energy Alliance, LLC            */
      13             : /*               Under Contract No. DE-AC07-05ID14517               */
      14             : /*                With the U. S. Department of Energy               */
      15             : /*                                                                  */
      16             : /*                 See LICENSE for full restrictions                */
      17             : /********************************************************************/
      18             : 
      19             : #ifdef ENABLE_NEK_COUPLING
      20             : 
      21             : #include "NekFieldVariable.h"
      22             : 
      23             : registerMooseObject("CardinalApp", NekFieldVariable);
      24             : 
      25             : InputParameters
      26        1544 : NekFieldVariable::validParams()
      27             : {
      28        1544 :   auto params = FieldTransferBase::validParams();
      29        3088 :   params.addParam<MooseEnum>(
      30             :       "field",
      31        3088 :       getNekFieldEnum(),
      32             :       "NekRS field variable to read/write; defaults to the name of the object");
      33        1544 :   params.addClassDescription("Reads/writes volumetric field data between NekRS and MOOSE.");
      34        1544 :   return params;
      35           0 : }
      36             : 
      37         772 : NekFieldVariable::NekFieldVariable(const InputParameters & parameters)
      38         772 :   : FieldTransferBase(parameters)
      39             : {
      40         772 :   if (_direction == "from_nek")
      41        1542 :     addExternalVariable(_variable);
      42             : 
      43         770 :   if (_direction == "to_nek")
      44           0 :     paramError("direction",
      45             :                "The NekFieldVariable currently only supports transfers 'from_nek'; contact the "
      46             :                "Cardinal developer team if you require writing of NekRS field variables.");
      47             : 
      48        1540 :   if (isParamValid("field"))
      49        1286 :     _field = getParam<MooseEnum>("field").getEnum<field::NekFieldEnum>();
      50             :   else
      51             :   {
      52             :     // try a reasonable default by seeing if the object name matches a valid enumeration
      53         127 :     auto enums = getNekFieldEnum().getNames();
      54         127 :     auto obj_name = name();
      55             :     std::transform(obj_name.begin(), obj_name.end(), obj_name.begin(), ::toupper);
      56         127 :     bool found_name = std::find(enums.begin(), enums.end(), obj_name) != enums.end();
      57         127 :     if (found_name)
      58         126 :       _field = convertToFieldEnum(obj_name);
      59             :     else
      60           1 :       paramError("field",
      61           1 :                  "We tried to choose a default 'field' as '" + name() +
      62             :                      "', but this value is not an option in the 'field' enumeration. Please "
      63             :                      "provide the 'field' parameter.");
      64         126 :   }
      65             : 
      66         769 :   if (_field == field::velocity_component)
      67           0 :     paramError("field",
      68             :                "'velocity_component' is not yet supported; if you need velocity dotted with a "
      69             :                "specific direction, extract the three components of velocity and perform the "
      70             :                "postprocessing operation using a ParsedAux. If this is hindering your workflow, "
      71             :                "please contact the Cardinal developer team.");
      72             : 
      73         769 :   _external_data = (double *)calloc(_nek_problem.nPoints(), sizeof(double));
      74         769 : }
      75             : 
      76        1528 : NekFieldVariable::~NekFieldVariable() { freePointer(_external_data); }
      77             : 
      78             : field::NekFieldEnum
      79         126 : NekFieldVariable::convertToFieldEnum(const std::string name) const
      80             : {
      81         126 :   auto lowercase = name;
      82             :   std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), ::tolower);
      83         126 :   if (lowercase == "velocity_x")
      84             :     return field::velocity_x;
      85         110 :   if (lowercase == "velocity_y")
      86             :     return field::velocity_y;
      87          94 :   if (lowercase == "velocity_z")
      88             :     return field::velocity_z;
      89          86 :   if (lowercase == "velocity")
      90             :     return field::velocity;
      91          82 :   if (lowercase == "velocity_component")
      92             :     return field::velocity_component;
      93          82 :   if (lowercase == "velocity_x_squared")
      94             :     return field::velocity_x_squared;
      95          82 :   if (lowercase == "velocity_y_squared")
      96             :     return field::velocity_y_squared;
      97          82 :   if (lowercase == "velocity_z_squared")
      98             :     return field::velocity_z_squared;
      99          78 :   if (lowercase == "temperature")
     100             :     return field::temperature;
     101          54 :   if (lowercase == "pressure")
     102             :     return field::pressure;
     103          46 :   if (lowercase == "scalar01")
     104             :     return field::scalar01;
     105          34 :   if (lowercase == "scalar02")
     106             :     return field::scalar02;
     107           8 :   if (lowercase == "scalar03")
     108             :     return field::scalar03;
     109           0 :   if (lowercase == "unity")
     110             :     return field::unity;
     111           0 :   if (lowercase == "usrwrk00")
     112             :     return field::usrwrk00;
     113           0 :   if (lowercase == "usrwrk01")
     114             :     return field::usrwrk01;
     115           0 :   if (lowercase == "usrwrk02")
     116             :     return field::usrwrk02;
     117             : 
     118           0 :   mooseError("Unhandled NekFieldEnum in NekFieldVariable!");
     119             : }
     120             : 
     121             : void
     122       88432 : NekFieldVariable::readDataFromNek()
     123             : {
     124       88432 :   if (!_nek_mesh->volume())
     125       20410 :     _nek_problem.boundarySolution(_field, _external_data);
     126             :   else
     127       68022 :     _nek_problem.volumeSolution(_field, _external_data);
     128             : 
     129       88432 :   fillAuxVariable(_variable_number[_variable], _external_data);
     130       88432 : }
     131             : 
     132             : #endif

Generated by: LCOV version 1.14