LCOV - code coverage report
Current view: top level - src/transfers - ScalarTransferBase.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 25 27 92.6 %
Date: 2025-07-15 20:50:38 Functions: 2 2 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 "ScalarTransferBase.h"
      22             : 
      23             : std::map<unsigned int, unsigned int> ScalarTransferBase::_counter;
      24             : 
      25             : InputParameters
      26         104 : ScalarTransferBase::validParams()
      27             : {
      28         104 :   auto params = NekTransferBase::validParams();
      29         208 :   params.addParam<unsigned int>(
      30             :       "usrwrk_slot",
      31             :       "When 'direction = to_nek', the slot in the usrwrk array to write the incoming data");
      32         208 :   params.addParam<Real>("scaling", 1.0, "Multiplier on the value passed into NekRS");
      33         104 :   params.addClassDescription(
      34             :       "Base class for defining input parameters for passing single values (scalars) into NekRS");
      35         104 :   return params;
      36           0 : }
      37             : 
      38          51 : ScalarTransferBase::ScalarTransferBase(const InputParameters & parameters)
      39         102 :   : NekTransferBase(parameters), _scaling(getParam<Real>("scaling"))
      40             : {
      41          51 :   if (_direction == "to_nek")
      42             :   {
      43         102 :     checkRequiredParam(parameters, "usrwrk_slot", "writing data 'to_nek'");
      44         102 :     _usrwrk_slot = getParam<unsigned int>("usrwrk_slot");
      45             : 
      46             :     // slot should not be greater than the amount allocated
      47          51 :     checkAllocatedUsrwrkSlot(_usrwrk_slot);
      48             : 
      49             :     // check that we're not writing into space that's used for field transfers
      50             :     auto field_usrwrk_map = FieldTransferBase::usrwrkMap();
      51          50 :     if (field_usrwrk_map.find(_usrwrk_slot) != field_usrwrk_map.end())
      52             :     {
      53           1 :       std::string unavailable_slots = "";
      54           3 :       for (const auto & f : field_usrwrk_map)
      55           4 :         unavailable_slots += Moose::stringify(f.first) + " ";
      56             : 
      57           1 :       paramError("usrwrk_slot",
      58           1 :                  "The usrwrk slot " + Moose::stringify(_usrwrk_slot) +
      59             :                      " is already used by the FieldTransfers for writing field data into NekRS. "
      60           1 :                      "You cannot set 'usrwrk_slot' to any of: " +
      61             :                      unavailable_slots);
      62             :     }
      63             : 
      64             :     // we do allow duplicates now within the scalar transfers; we simply shift
      65             :     // each by an offset; first, find what the previous filled offset was for this
      66             :     // slot, then save that value for usage
      67          49 :     if (_counter.find(_usrwrk_slot) == _counter.end())
      68          41 :       _counter[_usrwrk_slot] = 0;
      69             :     else
      70           8 :       _counter[_usrwrk_slot] += 1;
      71             : 
      72          49 :     _offset = _counter[_usrwrk_slot];
      73             :   }
      74             : 
      75          49 :   if (_direction == "from_nek")
      76           0 :     paramError("direction",
      77             :                "Reading scalar values from NekRS can be performed using the Postprocessing system. "
      78             :                "Alternatively, if you want to pull out individual scalars from nrs->usrwrk, "
      79             :                "contact the Cardinal developer team to request this feature.");
      80          49 : }
      81             : 
      82             : #endif

Generated by: LCOV version 1.14