LCOV - code coverage report
Current view: top level - src/ics - SmoothCircleFromFileIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 39 45 86.7 %
Date: 2025-09-04 07:55:36 Functions: 4 4 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 "SmoothCircleFromFileIC.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", SmoothCircleFromFileIC);
      13             : 
      14             : InputParameters
      15           9 : SmoothCircleFromFileIC::validParams()
      16             : {
      17           9 :   InputParameters params = SmoothCircleBaseIC::validParams();
      18           9 :   params.addClassDescription("Multiple smooth circles read from a text file");
      19          18 :   params.addRequiredParam<FileName>("file_name", "File containing circle centers and radii");
      20             : 
      21           9 :   return params;
      22           0 : }
      23             : 
      24           5 : SmoothCircleFromFileIC::SmoothCircleFromFileIC(const InputParameters & parameters)
      25             :   : SmoothCircleBaseIC(parameters),
      26          10 :     _data(0),
      27           5 :     _file_name(getParam<FileName>("file_name")),
      28           5 :     _txt_reader(_file_name, &_communicator),
      29           5 :     _n_circles(0)
      30             : {
      31             :   // Read names and vectors from file
      32           5 :   _txt_reader.read();
      33           5 :   _col_names = _txt_reader.getNames();
      34           5 :   _data = _txt_reader.getData();
      35           5 :   _n_circles = _data[0].size();
      36             : 
      37             :   // Check that the file has all the correct information
      38          25 :   for (unsigned int i = 0; i < _col_names.size(); ++i)
      39             :   {
      40             :     // Check that columns have uniform lengths
      41          20 :     if (_data[i].size() != _n_circles)
      42           0 :       mooseError("Columns in ", _file_name, " do not have uniform lengths.");
      43             : 
      44             :     // Determine which columns correspond to which parameters.
      45          20 :     if (_col_names[i] == "x")
      46           5 :       _col_map[X] = i;
      47          15 :     else if (_col_names[i] == "y")
      48           5 :       _col_map[Y] = i;
      49          10 :     else if (_col_names[i] == "z")
      50           5 :       _col_map[Z] = i;
      51           5 :     else if (_col_names[i] == "r")
      52           5 :       _col_map[R] = i;
      53             :   }
      54             : 
      55             :   // Check that the required columns are present
      56           5 :   if (_col_map[X] == -1)
      57           0 :     mooseError("No column in ", _file_name, " labeled 'x'.");
      58           5 :   if (_col_map[Y] == -1)
      59           0 :     mooseError("No column in ", _file_name, " labeled 'y'.");
      60           5 :   if (_col_map[Z] == -1)
      61           0 :     mooseError("No column in ", _file_name, " labeled 'z'.");
      62           5 :   if (_col_map[R] == -1)
      63           0 :     mooseError("No column in ", _file_name, " labeled 'r'.");
      64           5 : }
      65             : 
      66             : void
      67           5 : SmoothCircleFromFileIC::computeCircleRadii()
      68             : {
      69           5 :   _radii.assign(_data[_col_map[R]].begin(), _data[_col_map[R]].end());
      70           5 : }
      71             : 
      72             : void
      73           5 : SmoothCircleFromFileIC::computeCircleCenters()
      74             : {
      75           5 :   _centers.resize(_n_circles);
      76          45 :   for (unsigned int i = 0; i < _n_circles; ++i)
      77             :   {
      78          40 :     _centers[i](0) = _data[_col_map[X]][i];
      79          40 :     _centers[i](1) = _data[_col_map[Y]][i];
      80          40 :     _centers[i](2) = _data[_col_map[Z]][i];
      81             :   }
      82           5 : }

Generated by: LCOV version 1.14