• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-Sn / opensn / 18609682277

17 Oct 2025 04:49PM UTC coverage: 74.796% (-0.3%) from 75.124%
18609682277

push

github

web-flow
Merge pull request #800 from wdhawkins/foam_fixes

Minor clang-tidy fixes to OpenFoam mesh reader

5 of 7 new or added lines in 1 file covered. (71.43%)

20 existing lines in 3 files now uncovered.

18215 of 24353 relevant lines covered (74.8%)

53660978.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/framework/utils/utils.cc
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#include "framework/utils/utils.h"
5
#include "framework/logging/log_exceptions.h"
6
#include <fstream>
7
#include <cmath>
8
#include <iomanip>
9
#include <sstream>
10

11
namespace opensn
12
{
13

14
std::string
15
StringLTrim(const std::string& s)
488✔
16
{
17
  size_t start = s.find_first_not_of(WHITESPACE);
488✔
18
  return (start == std::string::npos) ? "" : s.substr(start);
488✔
19
}
20

21
std::string
22
StringRTrim(const std::string& s)
488✔
23
{
24
  size_t end = s.find_last_not_of(WHITESPACE);
488✔
25
  return (end == std::string::npos) ? "" : s.substr(0, end + 1);
488✔
26
}
27

28
std::string
29
StringTrim(const std::string& s)
488✔
30
{
31
  return StringRTrim(StringLTrim(s));
976✔
32
}
33

34
bool
35
StartsWith(std::string_view s, std::string_view k)
296✔
36
{
37
  return s.size() >= k.size() && std::equal(k.begin(), k.end(), s.begin());
296✔
38
}
39

40
std::vector<std::string>
41
StringSplit(const std::string& input, const std::string& delim)
×
42
{
43
  constexpr size_t NPOS = std::string::npos;
×
UNCOV
44
  std::vector<std::string> output;
×
45

46
  std::string remainder = input;
×
UNCOV
47
  size_t first_scope = remainder.find_first_of(delim);
×
48

49
  while (first_scope != NPOS)
×
50
  {
51
    if (first_scope != 0)
×
UNCOV
52
      output.push_back(remainder.substr(0, first_scope));
×
53

54
    remainder = remainder.substr(first_scope + delim.size(), NPOS);
×
UNCOV
55
    first_scope = remainder.find_first_of(delim);
×
56
  }
57
  output.push_back(remainder);
×
58

59
  return output;
×
60
}
×
61

62
std::string
63
StringUpToFirstReverse(const std::string& input, const std::string& search_string)
×
64
{
65
  constexpr size_t NPOS = std::string::npos;
×
66
  std::string output = input;
×
UNCOV
67
  const size_t last_scope = input.find_last_of(search_string);
×
UNCOV
68
  if (last_scope != NPOS)
×
UNCOV
69
    output = input.substr(last_scope + search_string.size(), NPOS);
×
70

UNCOV
71
  return output;
×
UNCOV
72
}
×
73

74
std::string
75
LowerCase(const std::string& name)
358✔
76
{
77
  std::string lower(name);
358✔
78
  std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
358✔
79
  return lower;
358✔
80
}
81

82
std::string
UNCOV
83
UpperCase(const std::string& name)
×
84
{
UNCOV
85
  std::string upper(name);
×
UNCOV
86
  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
×
UNCOV
87
  return upper;
×
88
}
89

90
void
91
AssertReadableFile(const std::string& file_name)
168✔
92
{
93
  std::ifstream file(file_name.c_str(), std::ifstream::in);
168✔
94
  OpenSnLogicalErrorIf(file.fail(),
168✔
95
                       "Failed to open file \"" + file_name +
96
                         "\"."
97
                         "Either the file does not exist or you do not have read permissions.");
98

99
  file.close();
168✔
100
}
168✔
101

102
std::string
103
PrintIterationProgress(const size_t current_iteration,
39✔
104
                       const size_t total_num_iterations,
105
                       const unsigned int num_intvls)
106
{
107
  // Creating shorthand symbols for arguments
108
  const auto& i = current_iteration;
39✔
109
  const auto& I = num_intvls;
39✔
110
  const auto& N = total_num_iterations;
39✔
111

112
  // If on the first iteration then do nothing
113
  if (i == 0)
39✔
114
    return {};
1✔
115

116
  // Prepare an output stream
117
  std::stringstream output;
38✔
118
  output << std::fixed << std::setprecision(2) << std::setw(7);
38✔
119

120
  // If at the end, just print 100 and quit
121
  if ((i + 1) == N)
38✔
122
  {
123
    output << 100.0;
1✔
124
    return output.str();
1✔
125
  }
126

127
  const double dI = std::ceil(double(N) / I); // Interval size
37✔
128

129
  // std::modf is used to get the integral part
130
  // of a real value
131
  double x1;
37✔
132
  std::modf(double(i - 1) / dI, &x1);
37✔
133
  double x2;
37✔
134
  std::modf(double(i) / dI, &x2);
37✔
135

136
  if (static_cast<unsigned int>(x2) != static_cast<unsigned int>(x1))
37✔
137
  {
138
    output << x2 * (100.0 / I);
3✔
139
    return output.str();
3✔
140
  }
141

142
  return {};
34✔
143
}
38✔
144

145
std::vector<SubSetInfo>
146
MakeSubSets(size_t num_items, size_t desired_num_subsets)
9,635✔
147
{
148
  std::vector<SubSetInfo> ss_infos;
9,635✔
149
  const std::size_t div =
9,635✔
150
    std::floor(static_cast<double>(num_items) / static_cast<double>(desired_num_subsets));
9,635✔
151
  const std::size_t rem = num_items % desired_num_subsets;
9,635✔
152

153
  ss_infos.reserve(desired_num_subsets);
9,635✔
154
  for (size_t i = 0; i < desired_num_subsets; ++i)
19,331✔
155
    ss_infos.push_back({0, 0, div});
9,696✔
156
  for (size_t j = 0; j < rem; ++j)
9,635✔
UNCOV
157
    ss_infos[j].ss_size += 1;
×
158

159
  size_t check_sum = 0;
160
  for (size_t i = 0; i < desired_num_subsets; ++i)
19,331✔
161
  {
162
    ss_infos[i].ss_begin = check_sum;
9,696✔
163
    check_sum += ss_infos[i].ss_size;
9,696✔
164
    ss_infos[i].ss_end = check_sum - 1;
9,696✔
165
  }
166

167
  return ss_infos;
9,635✔
UNCOV
168
}
×
169

170
} // namespace opensn
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc