Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clang format #92

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BasedOnStyle: LLVM
---
Language: Cpp
AlwaysBreakTemplateDeclarations: true
BreakBeforeBraces: Allman
BinPackParameters: true
IndentWidth: 4
SpacesInParentheses: true
BreakConstructorInitializersBeforeComma: true
PointerAlignment: Left
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ env: #maybe add mpich later
script:
- mkdir build && cd build &&
PATH="$HOME/bin:/usr/lib/ccache:$PATH" CC=gcc-${GVER} CXX=g++-${GVER} cmake -DENABLE_INTEGRATED_TESTS=ON -DENABLE_UNIT_TESTS=ON ${USE_V4_SSE:+-DUSE_V4_SSE=ON} ${USE_V4_PORTABLE:+-DUSE_V4_PORTABLE=ON} ${LONG_TESTS:+-DENABLE_LONG_TESTS=ON} ${COVERAGE:+-DENABLE_COVERAGE_BUILD=ON} .. &&
make -j4 VERBOSE=1 && make test CTEST_OUTPUT_ON_FAILURE=1 && make install DESTDIR=$PWD
#make -j4 VERBOSE=1 && make test CTEST_OUTPUT_ON_FAILURE=1 && make install DESTDIR=$PWD
make -j4 VERBOSE=1 && make test CTEST_OUTPUT_ON_FAILURE=1 && make format && git diff --exit-code && make install DESTDIR=$PWD

after_success:
- if [[ ${COVERAGE} ]]; then cd .. && codecov --gcov-exec gcov-${GVER}; fi
Expand Down
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

#------------------------------------------------------------------------------#
# Set C flags
#------------------------------------------------------------------------------#
Expand Down Expand Up @@ -361,6 +363,7 @@ file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vpic
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VPIC_CXX_FLAGS}")

file(GLOB_RECURSE VPIC_SRC src/*.c src/*.cc)
file(GLOB_RECURSE VPIC_HEADER src/*.h)
file(GLOB_RECURSE VPIC_NOT_SRC
src/util/v4/test/v4.cc
src/util/v8/test/v8.cc
Expand Down Expand Up @@ -438,6 +441,13 @@ if(ENABLE_PERFORMANCE_TESTS)
include_directories(${CATCH_DIR})
add_subdirectory(test/performance)
endif(ENABLE_PERFORMANCE_TESTS)
#~---------------------------------------------------------------------------~-#
# vim: set tabstop=2 shiftwidth=2 expandtab :
#~---------------------------------------------------------------------------~-#

# enable "make format" and clang-format
find_package(CLANG_FORMAT)
if(CLANG_FORMAT_FOUND)
#file(GLOB_RECURSE FORMAT_SOURCES core/*.cpp core/*.hpp)
set(FORMAT_SOURCES ${VPIC_SRC} ${VPIC_HEADER})
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES}
DEPENDS ${FORMAT_SOURCES})
endif()
60 changes: 60 additions & 0 deletions cmake/FindCLANG_FORMAT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
############################################################################
# Copyright (c) 2019 by the Cabana authors #
# All rights reserved. #
# #
# This file is part of the Cabana library. Cabana is distributed under a #
# BSD 3-clause license. For the licensing terms see the LICENSE file in #
# the top-level directory. #
# #
# SPDX-License-Identifier: BSD-3-Clause #
############################################################################
#
# Find clang-format
#
# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable
# CLANG_FORMAT_FOUND - True if the clang-format executable was found.
# CLANG_FORMAT_VERSION - The version of clang-format found
#

find_program(CLANG_FORMAT_EXECUTABLE
NAMES clang-format
clang-format-7
clang-format-6.0
clang-format-5.0
clang-format-4.0
clang-format-3.9
clang-format-3.8
clang-format-3.7
clang-format-3.6
clang-format-3.5
clang-format-3.4
clang-format-3.3
DOC "clang-format executable")
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)

# Extract version from command "clang-format -version"
if(CLANG_FORMAT_EXECUTABLE)
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

if(clang_format_version MATCHES "^clang-format version .*")
# clang_format_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1
# (tags/RELEASE_391/rc2)"
string(REGEX
REPLACE "clang-format version ([.0-9]+).*"
"\\1"
CLANG_FORMAT_VERSION
"${clang_format_version}")
# CLANG_FORMAT_VERSION sample: "3.9.1"
else()
set(CLANG_FORMAT_VERSION 0.0)
endif()
else()
set(CLANG_FORMAT_VERSION 0.0)
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION)
52 changes: 20 additions & 32 deletions src/boundary/boundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,47 @@ struct particle_bc;
typedef struct particle_bc particle_bc_t;

// may have been moved by Kevin
typedef struct link_boundary {
char fbase[256]; // base of file name to contain link info
double n_out; // number of writes so far on this node (double to
// accomodate long long runs)
typedef struct link_boundary
{
char fbase[256]; // base of file name to contain link info
double n_out; // number of writes so far on this node (double to
// accomodate long long runs)
} link_boundary_t;

BEGIN_C_DECLS

/* In boundary.c */

int
num_particle_bc( const particle_bc_t * RESTRICT pbc_list );
int num_particle_bc( const particle_bc_t* RESTRICT pbc_list );

void
delete_particle_bc_list( particle_bc_t * RESTRICT pbc_list );
void delete_particle_bc_list( particle_bc_t* RESTRICT pbc_list );

particle_bc_t *
append_particle_bc( particle_bc_t * pbc,
particle_bc_t ** pbc_list );
particle_bc_t* append_particle_bc( particle_bc_t* pbc,
particle_bc_t** pbc_list );

int64_t
get_particle_bc_id( particle_bc_t * pbc );
int64_t get_particle_bc_id( particle_bc_t* pbc );

/* In boundary_p.cxx */

void
boundary_p( particle_bc_t * RESTRICT pbc_list,
species_t * RESTRICT sp_list,
field_array_t * RESTRICT fa,
accumulator_array_t * RESTRICT aa );
void boundary_p( particle_bc_t* RESTRICT pbc_list, species_t* RESTRICT sp_list,
field_array_t* RESTRICT fa, accumulator_array_t* RESTRICT aa );

/* In maxwellian_reflux.c */

particle_bc_t *
maxwellian_reflux( species_t * RESTRICT sp_list,
rng_pool_t * RESTRICT rp );
particle_bc_t* maxwellian_reflux( species_t* RESTRICT sp_list,
rng_pool_t* RESTRICT rp );

void
set_reflux_temp( /**/ particle_bc_t * RESTRICT mr,
const species_t * RESTRICT sp,
float ut_para,
float ut_perp );
void set_reflux_temp( /**/ particle_bc_t* RESTRICT mr,
const species_t* RESTRICT sp, float ut_para,
float ut_perp );

/* In absorb_tally.c */

particle_bc_t *
absorb_tally( /**/ species_t * RESTRICT sp_list,
const field_array_t * RESTRICT fa );
particle_bc_t* absorb_tally( /**/ species_t* RESTRICT sp_list,
const field_array_t* RESTRICT fa );

int *
get_absorb_tally( particle_bc_t * pbc );
int* get_absorb_tally( particle_bc_t* pbc );

END_C_DECLS

#endif /* _boundary_h_ */

68 changes: 34 additions & 34 deletions src/boundary/boundary_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,53 @@
of these handlers update rhob according to net charge added and
removed from the simulation by these functions. */

typedef int /* Number of particles injected */
(*particle_bc_func_t)( /* The boundary whose ... */
void * RESTRICT b, /* parameters are b was hit by ... */
species_t * RESTRICT sp, /* a particle from this species ... */
particle_t * RESTRICT p, /* this particle in fact
(position is hit location, momentum
is at time of the hit) ... */
particle_mover_t * RESTRICT pm, /* who had this much displacement
remaining when it hit */
particle_injector_t * RESTRICT pi, /* Injectors for particles created by
typedef int /* Number of particles injected */
( *particle_bc_func_t )( /* The boundary whose ... */
void* RESTRICT
b, /* parameters are b was hit by ... */
species_t* RESTRICT
sp, /* a particle from this species ... */
particle_t* RESTRICT
p, /* this particle in fact
(position is hit location, momentum
is at time of the hit) ... */
particle_mover_t* RESTRICT
pm, /* who had this much displacement
remaining when it hit */
particle_injector_t* RESTRICT
pi, /* Injectors for particles created by
the interaction */
int max_pi, /* Max number injections allowed */
int face ); /* CONVENIENCE: Which face of the
int max_pi, /* Max number injections allowed */
int face ); /* CONVENIENCE: Which face of the
the voxel containing the above
particle was hit */

typedef void
(*delete_particle_bc_func_t)( particle_bc_t * RESTRICT pbc );
typedef void ( *delete_particle_bc_func_t )( particle_bc_t* RESTRICT pbc );

struct particle_bc {
void * params;
particle_bc_func_t interact;
delete_particle_bc_func_t delete_pbc;
int64_t id;
particle_bc_t * next;
struct particle_bc
{
void* params;
particle_bc_func_t interact;
delete_particle_bc_func_t delete_pbc;
int64_t id;
particle_bc_t* next;
};

BEGIN_C_DECLS

void
checkpt_particle_bc_internal( const particle_bc_t * pbc );
void checkpt_particle_bc_internal( const particle_bc_t* pbc );

particle_bc_t *
restore_particle_bc_internal( void * params );
particle_bc_t* restore_particle_bc_internal( void* params );

particle_bc_t *
new_particle_bc_internal( void * params,
particle_bc_func_t interact,
delete_particle_bc_func_t delete_pbc,
checkpt_func_t checkpt,
restore_func_t restore,
reanimate_func_t reanimate );
particle_bc_t* new_particle_bc_internal( void* params,
particle_bc_func_t interact,
delete_particle_bc_func_t delete_pbc,
checkpt_func_t checkpt,
restore_func_t restore,
reanimate_func_t reanimate );

void
delete_particle_bc_internal( particle_bc_t * pbc );
void delete_particle_bc_internal( particle_bc_t* pbc );

END_C_DECLS

#endif /* _boundary_h_ */

23 changes: 11 additions & 12 deletions src/collision/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

typedef struct binary_collision_model
{
char * name;
binary_rate_constant_func_t rate_constant;
binary_collision_func_t collision;
void * params;
species_t * spi;
species_t * spj;
rng_pool_t * rp;
double sample;
int interval;
int n_large_pr[ MAX_PIPELINE ];
char* name;
binary_rate_constant_func_t rate_constant;
binary_collision_func_t collision;
void* params;
species_t* spi;
species_t* spj;
rng_pool_t* rp;
double sample;
int interval;
int n_large_pr[MAX_PIPELINE];
} binary_collision_model_t;

void
apply_binary_collision_model_pipeline( binary_collision_model_t * cm );
void apply_binary_collision_model_pipeline( binary_collision_model_t* cm );

#endif /* _binary_h_ */
Loading