Skip to content

Commit 82192cf

Browse files
committed
Merge branch '634-run-clang-format' into 'development'
Resolve "run `clang-format`" See merge request damask/DAMASK!1213
2 parents 28b38af + c414605 commit 82192cf

11 files changed

Lines changed: 229 additions & 154 deletions

File tree

.clang-format

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
BasedOnStyle: LLVM
3+
4+
ColumnLimit: 0
5+
IndentWidth: 2
6+
7+
DerivePointerAlignment: false
8+
PointerAlignment: Left
9+
ReferenceAlignment: Pointer
10+
11+
AccessModifierOffset: -2
12+
BreakBeforeBraces: Attach
13+
SpaceBeforeParens: ControlStatements
14+
15+
AllowShortFunctionsOnASingleLine: Empty
16+
AllowShortLambdasOnASingleLine: None
17+
AllowShortIfStatementsOnASingleLine: Never
18+
AllowShortLoopsOnASingleLine: false
19+
AllowShortCaseLabelsOnASingleLine: false
20+
BinPackArguments: false
21+
BinPackParameters: false
22+
AllowAllArgumentsOnNextLine: false
23+
AllowAllParametersOfDeclarationOnNextLine: false
24+
25+
IncludeBlocks: Preserve
26+
SortIncludes: Never
27+
28+
TypenameMacros: [CFI_CDESC_T]

.clang-tidy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ CheckOptions:
1717
- key: readability-identifier-naming.MemberCase
1818
value: lower_case
1919
- key: readability-identifier-naming.GlobalConstantCase
20-
value: CamelCase
21-
- key: readability-identifier-naming.GlobalConstantPrefix
22-
value: k
20+
value: UPPER_CASE
21+
- key: readability-identifier-naming.StaticConstantCase
22+
value: UPPER_CASE
23+
- key: readability-identifier-naming.ConstexprVariableCase
24+
value: UPPER_CASE
2325
- key: readability-identifier-naming.FunctionIgnoredRegexp
2426
value: 'F_.*|C_.*'

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ variables:
1212
GIT_SUBMODULE_STRATEGY: normal
1313
# Shortcut names
1414
MARC_VERSION: '2025.1'
15-
PETSC_GCC_LATEST: '2026.04.03'
15+
PETSC_GCC_LATEST: '2026.04.03a'
1616
PETSC_ONEAPI_LATEST: '2026.04.03'
1717
PETSC_LLVM_LATEST: '2026.04.04'
1818
PYTHON_LATEST: '2026.02.24'
@@ -259,12 +259,12 @@ c++-linter:
259259
stage: core
260260
extends: .petsc_gcc_default
261261
script:
262-
# for now only capture non-solver and test modules
263262
- BOOST_MAPPINGS=/usr/share/include-what-you-use/boost-all.imp
264263
- cmake -B build -DTEST=ON
265264
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--error;-Xiwyu;--mapping_file=${BOOST_MAPPINGS}"
266265
-DCMAKE_CXX_CLANG_TIDY="clang-tidy;--config-file=${PWD}/.clang-tidy"
267266
- cmake --build build --parallel --target install
267+
- clang-format --style=file:.clang-format --dry-run --Werror $(git ls-files -- '*.c' '*.cpp' '*.h')
268268

269269
.unittest:
270270
stage: core

PRIVATE

src/CLI.cpp

Lines changed: 87 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
#include "IO.h"
4343

4444
namespace fs = std::filesystem;
45-
constexpr int kCLIError = 610;
46-
constexpr int kInvalidWorkingDirectoryError = 640;
45+
constexpr int CLI_ERROR = 610;
46+
constexpr int INVALID_WORKING_DIRECTORY_ERROR = 640;
4747

4848
std::string add_text_color(const std::array<int, 3>& rgb) {
4949
if (isatty(STDOUT_FILENO) && !IO_redirectedSTDOUT) {
50-
return "\033[38;2;" + std::to_string(rgb.at(0)) + ";" + std::to_string(rgb.at(1)) + ";" + std::to_string(rgb.at(2)) + "m";
50+
return "\033[38;2;" + std::to_string(rgb.at(0)) + ";" + std::to_string(rgb.at(1)) + ";" +
51+
std::to_string(rgb.at(2)) + "m";
5152
}
5253
return {};
5354
}
@@ -64,19 +65,32 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
6465
init_print();
6566

6667
po::options_description flags(" Valid command line flags");
67-
flags.add_options()("help,h", "show help")(
68-
"geometry,g", po::value<std::string>(&arg_geom)->value_name("[ --geom ]")->required(), "geometry file")(
69-
"loadcase,l", po::value<std::string>(&arg_load)->value_name("[ --load ]")->required(), "load case")(
70-
"materialconfig,m", po::value<std::string>(&arg_material)->value_name("[ --material ]")->required(), "material config")(
71-
"numericsconfig,n", po::value<std::string>(&arg_numerics)->value_name("[ --numerics ]"), "numerics config")(
72-
"jobname,j", po::value<std::string>(&arg_jobname)->value_name("[ --job ]"), "job name")(
73-
"workingdirectory,w", po::value<std::string>(&arg_wd)->value_name("[ --wd ]"), "working directory")(
74-
"wd", po::value<std::string>(&arg_wd), "alias")
68+
flags.add_options()("help,h", "show help");
69+
flags.add_options()("geometry,g",
70+
po::value<std::string>(&arg_geom)->value_name("[ --geom ]")->required(),
71+
"geometry file");
72+
flags.add_options()("loadcase,l",
73+
po::value<std::string>(&arg_load)->value_name("[ --load ]")->required(),
74+
"load case");
75+
flags.add_options()("materialconfig,m",
76+
po::value<std::string>(&arg_material)->value_name("[ --material ]")->required(),
77+
"material config");
78+
flags.add_options()("numericsconfig,n",
79+
po::value<std::string>(&arg_numerics)->value_name("[ --numerics ]"),
80+
"numerics config");
81+
flags.add_options()("jobname,j",
82+
po::value<std::string>(&arg_jobname)->value_name("[ --job ]"),
83+
"job name");
84+
flags.add_options()("workingdirectory,w",
85+
po::value<std::string>(&arg_wd)->value_name("[ --wd ]"),
86+
"working directory");
87+
flags.add_options()("wd", po::value<std::string>(&arg_wd), "alias");
7588
#if defined(GRID) || defined(TEST)
76-
("restart,r", po::value<int>(&arg_rs)->value_name("[ --rs ]"), "restart increment")(
77-
"rs", po::value<int>(&arg_rs), "alias")
89+
flags.add_options()("restart,r",
90+
po::value<int>(&arg_rs)->value_name("[ --rs ]"),
91+
"restart increment");
92+
flags.add_options()("rs", po::value<int>(&arg_rs), "alias");
7893
#endif
79-
;
8094
po::variables_map vm;
8195

8296
/**
@@ -127,7 +141,7 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
127141

128142
po::notify(vm);
129143
} catch (const boost::program_options::error& e) {
130-
IO::error(kCLIError, std::string("Command line error: ") + e.what());
144+
IO::error(CLI_ERROR, std::string("Command line error: ") + e.what());
131145
}
132146

133147
geom_path = remove_leading_equal(arg_geom);
@@ -150,13 +164,13 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
150164
try {
151165
fs::current_path(working_directory);
152166
} catch (const fs::filesystem_error&) {
153-
IO::error(kInvalidWorkingDirectoryError, working_directory);
167+
IO::error(INVALID_WORKING_DIRECTORY_ERROR, working_directory);
154168
}
155169
}
156170

157171
if (vm.count("restart")) {
158172
if (arg_rs < 0) {
159-
IO::error(kCLIError, std::string("invalid value for --restart: ") + std::to_string(arg_rs));
173+
IO::error(CLI_ERROR, std::string("invalid value for --restart: ") + std::to_string(arg_rs));
160174
}
161175
restart_inc = arg_rs;
162176
}
@@ -170,35 +184,35 @@ CLI::CLI(std::span<const char*> args, int* worldrank) {
170184
if (ec)
171185
throw std::runtime_error("boost hostname collection error: " + ec.message());
172186

173-
cout << " Host name: " << hostname << std::endl;
174-
cout << " User name: " << get_username() << std::endl << std::endl;
187+
cout << " Host name: " << hostname << "\n";
188+
cout << " User name: " << get_username() << "\n\n";
175189
cout << " Command line call: ";
176190
for (auto& arg : args) {
177191
cout << arg << " ";
178192
}
179-
cout << std::endl;
180-
cout << " Working directory: " << fs::current_path().string() << std::endl;
181-
cout << " Geometry: " << geom_path << std::endl;
182-
cout << " Load case: " << loadfile_path << std::endl;
183-
cout << " Material config: " << material_path << std::endl;
193+
cout << "\n";
194+
cout << " Working directory: " << fs::current_path().string() << "\n";
195+
cout << " Geometry: " << geom_path << "\n";
196+
cout << " Load case: " << loadfile_path << "\n";
197+
cout << " Material config: " << material_path << "\n";
184198
if (vm.count("numericsconfig")) {
185-
cout << " Numerics config: " << numerics_path << std::endl;
199+
cout << " Numerics config: " << numerics_path << "\n";
186200
}
187-
cout << " Job name: " << jobname << std::endl;
188-
cout << " Job ID: " << uuid << std::endl;
201+
cout << " Job name: " << jobname << "\n";
202+
cout << " Job ID: " << uuid << "\n";
189203
if (restart_inc != -1) {
190204
cout << " Restart increment: " << restart_inc << std::endl;
191205
}
192206
}
193207

194208
void CLI::init_print() {
195209
#ifdef DEBUG
196-
constexpr std::array<int, 3> red = {255, 0, 0};
197-
cout << add_text_color(red);
198-
cout << "debug version - debug version - debug version - debug version - debug version" << std::endl;
210+
constexpr std::array<int, 3> RED = {255, 0, 0};
211+
cout << add_text_color(RED);
212+
cout << "debug version - debug version - debug version - debug version - debug version\n";
199213
#else
200-
constexpr std::array<int, 3> damask_blue = {67, 128, 208};
201-
cout << add_text_color(damask_blue);
214+
constexpr std::array<int, 3> DAMASK_BLUE = {67, 128, 208};
215+
cout << add_text_color(DAMASK_BLUE);
202216
#endif
203217
cout << R"(
204218
_/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/
@@ -210,62 +224,70 @@ void CLI::init_print() {
210224
)";
211225

212226
#ifdef GRID
213-
constexpr std::array<int, 3> damask_green = {123, 207, 68};
214-
cout << add_text_color(damask_green);
215-
cout << " Grid solver" << std::endl << std::endl;
227+
constexpr std::array<int, 3> DAMASK_GREEN = {123, 207, 68};
228+
cout << add_text_color(DAMASK_GREEN);
229+
cout << " Grid solver\n\n";
216230
#elif defined(MESH)
217-
constexpr std::array<int, 3> damask_orange = {230, 150, 68};
218-
cout << add_text_color(damask_orange);
219-
cout << " Mesh solver" << std::endl << std::endl;
231+
constexpr std::array<int, 3> DAMASK_ORANGE = {230, 150, 68};
232+
cout << add_text_color(DAMASK_ORANGE);
233+
cout << " Mesh solver\n\n";
220234
#endif
221235

222236
#ifdef DEBUG
223-
cout << add_text_color(red);
224-
cout << " debug version - debug version - debug version - debug version - debug version" << std::endl << std::endl;
237+
cout << add_text_color(RED);
238+
cout << " debug version - debug version - debug version - debug version - debug version\n\n";
225239
#endif
226240

227241
cout << reset_text_color();
228-
cout << " F. Roters et al., Computational Materials Science 158:420–478, 2019" << std::endl
229-
<< " https://doi.org/10.1016/j.commatsci.2018.04.030" << std::endl
230-
<< std::endl;
231-
232-
#if PETSC_VERSION_MAJOR != 3 || PETSC_VERSION_MINOR < PETSC_MINOR_MIN || PETSC_VERSION_MINOR > PETSC_MINOR_MAX
233-
#error "-- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION ---"
242+
cout << " F. Roters et al., Computational Materials Science 158:420–478, 2019\n"
243+
<< " https://doi.org/10.1016/j.commatsci.2018.04.030\n\n";
244+
245+
#if PETSC_VERSION_MAJOR != 3
246+
#error "-- UNSUPPORTED PETSc VERSION ---"
247+
#elif PETSC_VERSION_MINOR < PETSC_MINOR_MIN
248+
#error "-- UNSUPPORTED PETSc VERSION ---"
249+
#elif PETSC_VERSION_MINOR > PETSC_MINOR_MAX
250+
#error "-- UNSUPPORTED PETSc VERSION ---"
234251
#else
235-
cout << " S. Balay et al., PETSc/TAO User Manual Revision " << PETSC_VERSION_MAJOR << "." << PETSC_VERSION_MINOR << std::endl;
252+
cout << " S. Balay et al., PETSc/TAO User Manual Revision " << PETSC_VERSION_MAJOR << "."
253+
<< PETSC_VERSION_MINOR << "\n";
236254
#if PETSC_VERSION_MINOR == 19
237-
cout << " https://doi.org/10.2172/1968587" << endl;
255+
cout << " https://doi.org/10.2172/1968587\n";
238256
#elif PETSC_VERSION_MINOR == 20
239-
cout << " https://doi.org/10.2172/2205494" << endl;
257+
cout << " https://doi.org/10.2172/2205494\n";
240258
#elif PETSC_VERSION_MINOR == 21
241-
cout << " https://doi.org/10.2172/2337606" << endl;
259+
cout << " https://doi.org/10.2172/2337606\n";
242260
#elif PETSC_VERSION_MINOR == 22
243-
cout << " https://doi.org/10.2172/2476320" << endl;
261+
cout << " https://doi.org/10.2172/2476320\n";
244262
#elif PETSC_VERSION_MINOR == 23
245-
cout << " https://doi.org/10.2172/2565610" << endl;
263+
cout << " https://doi.org/10.2172/2565610\n";
246264
#elif PETSC_VERSION_MINOR == 24
247-
cout << " https://doi.org/10.2172/2998643" << endl;
265+
cout << " https://doi.org/10.2172/2998643\n";
248266
#elif PETSC_VERSION_MINOR == 25
249-
cout << " https://doi.org/10.2172/3025790" << endl;
267+
cout << " https://doi.org/10.2172/3025790\n";
250268
#endif
251-
cout << endl;
269+
cout << "\n";
252270
#endif
253271

254-
cout << " Version: " << DAMASK_VERSION << std::endl << std::endl;
272+
cout << " Version: " << DAMASK_VERSION << "\n\n";
255273
cout << " Compiled with:";
256274
#if defined(__clang__)
257-
cout << " Clang version " << __clang_major__ << "." << __clang_minor__ << "." << __clang_patchlevel__ << std::endl;
275+
cout << " Clang version " << __clang_major__ << "." << __clang_minor__ << "."
276+
<< __clang_patchlevel__ << std::endl;
258277
#elif defined(__GNUC__)
259-
cout << " GCC version " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl;
278+
cout << " GCC version " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__
279+
<< std::endl;
260280
#elif defined(__INTEL_COMPILER)
261-
cout << " Intel Compiler version " << __INTEL_COMPILER << "." << __INTEL_COMPILER_UPDATE << std::endl;
281+
cout << " Intel Compiler version " << __INTEL_COMPILER << "." << __INTEL_COMPILER_UPDATE
282+
<< std::endl;
262283
#endif
263284
F_printCompileOptions();
264-
cout << std::endl;
265-
cout << " PETSc version: " << PETSC_VERSION_MAJOR << "." << PETSC_VERSION_MINOR << "." << PETSC_VERSION_SUBMINOR << std::endl
266-
<< std::endl;
285+
cout << "\n";
286+
cout << " PETSc version: "
287+
<< PETSC_VERSION_MAJOR << "." << PETSC_VERSION_MINOR << "." << PETSC_VERSION_SUBMINOR << "\n\n";
267288

268-
cout << " Compiled at: " << __DATE__ << " at " << __TIME__ << std::endl << std::endl;
289+
cout << " Compiled at: " << __DATE__ << " at " << __TIME__ << "\n"
290+
<< std::endl;
269291
}
270292

271293
void CLI::help_print(const po::options_description& flags) {
@@ -463,7 +485,8 @@ static void strcopy_to_fortran(const std::string& src, char* dest) {
463485
* @param[out] uuid UUID buffer
464486
* @param[out] jobname Jobname buffer
465487
* @param[out] restart Restart increment (only relevant for grid solver)
466-
* @param[out] stat Status flag: always returns 0 here, failure will be implicit from buffer error
488+
* @param[out] stat Status flag: always returns 0 here, failure will be implicit from
489+
* buffer error
467490
*/
468491
void C_CLI_getParsedArgs(CLI* cli,
469492
char geom[],

src/CLI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class options_description;
2525
}
2626
} // namespace boost
2727
namespace po = boost::program_options;
28-
using namespace std;
2928

3029
extern "C" {
3130
/**

src/C_routines.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ bool isatty_stdin_c() {
8888
}
8989

9090
#ifdef GRID
91-
void inflate_c(
92-
const uLong* s_deflated, const uLong* s_inflated, const Byte deflated[*s_deflated], Byte inflated[*s_inflated], int* stat) {
91+
void inflate_c(const uLong* s_deflated,
92+
const uLong* s_inflated,
93+
const Byte deflated[*s_deflated],
94+
Byte inflated[*s_inflated],
95+
int* stat) {
9396
/* make writable copy, uncompress will write to it */
9497
uLong s_inflated_;
9598
s_inflated_ = *s_inflated;
@@ -108,9 +111,14 @@ void inflate_c(
108111
#ifdef FYAML
109112
void to_flow_c(CFI_cdesc_t* flow, const char* mixed, int* stat) {
110113
struct fy_document* fyd = NULL;
111-
enum fy_emitter_cfg_flags emit_flags = FYECF_MODE_FLOW_ONELINE | FYECF_WIDTH_INF | FYECF_STRIP_LABELS | FYECF_STRIP_TAGS |
112-
FYECF_STRIP_DOC | FYECF_DOC_START_MARK_OFF;
113-
114+
// clang-format off
115+
enum fy_emitter_cfg_flags emit_flags = FYECF_MODE_FLOW_ONELINE
116+
| FYECF_WIDTH_INF
117+
| FYECF_STRIP_LABELS
118+
| FYECF_STRIP_TAGS
119+
| FYECF_STRIP_DOC
120+
| FYECF_DOC_START_MARK_OFF;
121+
// clang-format on
114122
fyd = fy_document_build_from_string(NULL, mixed, -1);
115123
if (!fyd) {
116124
*stat = 1;

0 commit comments

Comments
 (0)