Skip to content

Commit

Permalink
add clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
boulderdaze committed Jun 7, 2024
1 parent 23690d5 commit 955730a
Show file tree
Hide file tree
Showing 18 changed files with 731 additions and 507 deletions.
43 changes: 43 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: 'AlwaysBreak'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlignConsecutiveMacros: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: 'None'
AllowShortIfStatementsOnASingleLine: 'Never'
AllowShortLoopsOnASingleLine: 'false'
BreakBeforeBraces: Allman
BinPackArguments: 'false'
BinPackParameters: 'false'
Cpp11BracedListStyle: 'false'
ColumnLimit: 125
IndentWidth: 2
IndentPPDirectives: BeforeHash
NamespaceIndentation: All
PackConstructorInitializers: 'Never'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyBlock: true
Standard: 'Latest'
IncludeBlocks: Regroup
IncludeCategories:
# TUV-X project headers
- Regex: '<(tuvx)\/'
Priority: 2
# CUDA headers (in progress)
- Regex: '<(cuda)[[:alnum:].(-|_)*]+>'
Priority: 3
# External libraries headers
- Regex: '<[[:alnum:].(-|_)*]+\/'
Priority: 4
# System headers
- Regex: '<[[:alnum:].(-|_)*]+>'
Priority: 5
# Main, local, private headers
- Regex: '".*'
Priority: 1
53 changes: 53 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Clang-Format

on:
push:
branches:
- main

jobs:
format:
name: Run Clang-Format
runs-on: ubuntu-latest

steps:
- name: Install Clang-Format
run: sudo apt-get update && sudo apt-get install clang-format && clang-format --version

- name: Check out code, run clang format, push changes
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Run clang-format
run: |
find include -type f \( -name '*.hpp' -or -name '*.h' \) -exec clang-format -i --style=file --verbose {} +
find src -type f \( -name '*.cpp' -or -name '*.c' \) -exec clang-format -i --style=file --verbose {} +
- name: Check for changes
id: check-changes
run: git diff --exit-code
continue-on-error: true

- name: Commit and push changes
# a failue of this step means changes were detected
if: steps.check-changes.outcome != 'success'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git commit -am "Auto-format code using Clang-Format" || echo "No changes to commit"
- name: Push changes to main-formatting branch
if: steps.check-changes.outcome != 'success'
run: git push origin HEAD:main-formatting

- name: Create Pull Request
if: steps.check-changes.outcome != 'success'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Auto-format code using Clang-Format"
title: "Auto-format code changes"
body: "This is an automated pull request to apply code formatting using Clang-Format."
branch: main-formatting
62 changes: 37 additions & 25 deletions include/tuvx/grid.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
//
/// @file Grid dimensions
/* Copyright (C) 2023-2024 National Center for Atmospheric Research
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include <string>

#include <tuvx/util/array2d.hpp>

namespace tuvx {
#include <string>

namespace tuvx
{

/// @brief Grid dimensions
///
Expand All @@ -18,9 +19,10 @@ namespace tuvx {
///
/// When grid dimensions are constant, the size of the column
/// dimension is 1.
template <typename ArrayPolicy = Array2D<double>>
class Grid {
public:
template<typename ArrayPolicy = Array2D<double>>
class Grid
{
public:
/// Grid centers
ArrayPolicy mid_points_;
/// Grid edges
Expand All @@ -33,24 +35,29 @@ namespace tuvx {
/// @param number_of_columns Number of columns.
/// @param number_of_sections Number of grid sections per column.
Grid(const std::string& units, size_t number_of_columns, size_t number_of_sections)
: units_(units),
mid_points_(number_of_sections, number_of_columns),
edges_(number_of_sections+1, number_of_columns),
is_constant_(false) {}
: units_(units),
mid_points_(number_of_sections, number_of_columns),
edges_(number_of_sections + 1, number_of_columns),
is_constant_(false)
{
}

/// @brief Constructor for a grid with dimensions that are constant.
/// @param units Units of the grid.
/// @param number_of_sections Number of grid sections per column.
Grid(const std::string& units, size_t number_of_sections)
: units_(units),
mid_points_(number_of_sections, 1),
edges_(number_of_sections+1, 1),
is_constant_(true) {}
: units_(units),
mid_points_(number_of_sections, 1),
edges_(number_of_sections + 1, 1),
is_constant_(true)
{
}

/// @brief Number of columns
///
/// When the grid dimensions are constant, the number of columns is 1.
size_t NumberOfColumns() const {
size_t NumberOfColumns() const
{
return mid_points_.Size2();
}

Expand All @@ -60,32 +67,37 @@ namespace tuvx {
/// the grid for a single column. The total number of values stored by
/// the grid would then be the number of grid sections times the number
/// of columns.
size_t NumberOfSections() const {
size_t NumberOfSections() const
{
return mid_points_.Size1();
}

/// @brief Number of grid edges
///
/// Grid edges are the boundaries of the grid sections. The number of
/// grid edges is one more than the number of grid sections.
size_t NumberOfEdges() const {
size_t NumberOfEdges() const
{
return edges_.Size1();
}

/// @brief Units of the grid.
std::string Units() const {
std::string Units() const
{
return units_;
}

/// @brief Check if the grid dimensions are constant across columns.
bool IsConstant() const {
bool IsConstant() const
{
return is_constant_;
}
private:

private:
/// Units of the grid.
std::string units_;
/// True if the grid dimensions are constant across columns.
bool is_constant_;
};

} // namespace tuvx
} // namespace tuvx
40 changes: 22 additions & 18 deletions include/tuvx/profile.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
//
/// @file Profile of a property on a grid.
/* Copyright (C) 2023-2024 National Center for Atmospheric Research
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include <string>

#include <tuvx/util/array2d.hpp>
#include <tuvx/grid.hpp>
#include <tuvx/util/array2d.hpp>

namespace tuvx {
#include <string>

namespace tuvx
{

/// @brief Profile of a property on a grid.
template <typename ArrayPolicy = Array2D<double>>
class Profile {
public:
template<typename ArrayPolicy = Array2D<double>>
class Profile
{
public:
/// Values at grid mid-points.
ArrayPolicy mid_point_values_;
/// Values at grid edges.
Expand All @@ -28,19 +30,21 @@ namespace tuvx {
/// @param grid Grid that the profile is defined on.
template<typename GridPolicy>
Profile(const std::string& units, size_t number_of_columns, const GridPolicy& grid)
: units_(units),
mid_point_values_(grid.mid_points_.Size1(), number_of_columns),
edge_values_(grid.edges_.Size1(), number_of_columns) {}
: units_(units),
mid_point_values_(grid.mid_points_.Size1(), number_of_columns),
edge_values_(grid.edges_.Size1(), number_of_columns)
{
}

/// Units of the profile.
std::string Units() const {
std::string Units() const
{
return units_;
}

private:
private:
/// Units of the profile.
std::string units_;

};

} // namespace tuvx
} // namespace tuvx
52 changes: 27 additions & 25 deletions include/tuvx/radiative_transfer/radiation_field.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
//
/// @file Radiation field vertically and wavelength resolved.
/* Copyright (C) 2023-2024 National Center for Atmospheric Research
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include <vector>

#include <tuvx/util/array3d.hpp>
#include <tuvx/grid.hpp>
#include <tuvx/util/array3d.hpp>

#include <vector>

namespace tuvx {
namespace tuvx
{

/// @brief Radiation field components vertically and wavelength resolved.
///
/// Data structures are designed to hold the radiation field components
/// for a collection of columns in a 3D grid.
/// Arrays are indexed by wavelength, vertical edge, and column.
template <typename ArrayPolicy = Array3D<double>>
struct RadiationFieldComponents {
template<typename ArrayPolicy = Array3D<double>>
struct RadiationFieldComponents
{
/// Direct component of the radiation field.
ArrayPolicy direct_;
/// Upwelling component of the radiation field.
Expand All @@ -30,19 +32,18 @@ namespace tuvx {
/// @param vertical_grid Vertical grid.
/// @param wavelength_grid Wavelength grid.
template<typename GridPolicy>
RadiationFieldComponents(size_t number_of_columns, GridPolicy& vertical_grid,
GridPolicy& wavelength_grid)
: direct_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(),
number_of_columns),
upwelling_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(),
number_of_columns),
downwelling_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(),
number_of_columns) {}
RadiationFieldComponents(size_t number_of_columns, GridPolicy& vertical_grid, GridPolicy& wavelength_grid)
: direct_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(), number_of_columns),
upwelling_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(), number_of_columns),
downwelling_(wavelength_grid.NumberOfSections(), vertical_grid.NumberOfEdges(), number_of_columns)
{
}
};

/// @brief Radiation field vertically and wavelength resolved.
template <typename ComponentPolicy = RadiationFieldComponents<Array3D<double>>>
struct RadiationField {
template<typename ComponentPolicy = RadiationFieldComponents<Array3D<double>>>
struct RadiationField
{
/// Total spectral irradiance.
ComponentPolicy spectral_irradiance_;
/// Total actinic flux.
Expand All @@ -53,10 +54,11 @@ namespace tuvx {
/// @param vertical_grid Vertical grid.
/// @param wavelength_grid Wavelength grid.
template<typename GridPolicy>
RadiationField(size_t number_of_columns, GridPolicy& vertical_grid,
GridPolicy& wavelength_grid)
: spectral_irradiance_(number_of_columns, vertical_grid, wavelength_grid),
actinic_flux_(number_of_columns, vertical_grid, wavelength_grid) {}
RadiationField(size_t number_of_columns, GridPolicy& vertical_grid, GridPolicy& wavelength_grid)
: spectral_irradiance_(number_of_columns, vertical_grid, wavelength_grid),
actinic_flux_(number_of_columns, vertical_grid, wavelength_grid)
{
}
};

} // namespace tuvx
} // namespace tuvx
Loading

0 comments on commit 955730a

Please sign in to comment.