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

Protocol buffer implementation #105

Merged
merged 41 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
46dcd84
removed platform specific things from gitignore
jsrehak Jun 29, 2018
909e7c3
added multiple badges to the README file
jsrehak Jun 29, 2018
7ba3bc2
added material protocol buffer, updated CMakeLists to compile it
jsrehak Jul 5, 2018
094bc1c
skeleton for new verion of MaterialProperties
AlexanderBlank Jul 11, 2018
7c964b1
work so far on tests and implementation of MaterialProperties
AlexanderBlank Aug 15, 2018
81ffff3
implementation of MaterialProperties and MaterialPropertiesTest
AlexanderBlank Aug 17, 2018
86164a9
a couple extra test assersions, minor changes
AlexanderBlank Aug 21, 2018
7f038eb
slightly cleaned up formatting and comments
AlexanderBlank Aug 24, 2018
4ff3184
removed out of date comment for chi_
AlexanderBlank Sep 2, 2018
01ed696
added material protobuf files
jsrehak Sep 18, 2018
8b68653
added complied protobuf directory to CMakeLists
jsrehak Sep 18, 2018
fa49125
added build target to CMakeLists to move material test data
jsrehak Sep 18, 2018
ee0da40
fixed FailedtoParseMaterialFile tests
jsrehak Sep 18, 2018
cc17462
fixed ParseFromFile test for new test file I/O scheme
jsrehak Sep 18, 2018
94e50c8
added std::hash<int> sepecification to MaterialProperties when using …
jsrehak Sep 19, 2018
f5ee96d
added std::hash<int> to some unordered_set's
jsrehak Sep 19, 2018
8eaae15
added MaterialPropertiesI
jsrehak Sep 20, 2018
b9728e1
added MockMaterialProperties class
jsrehak Sep 20, 2018
28d7479
added lines for INPUT section of doxygen config
jsrehak Sep 20, 2018
3b4dbee
added more documentation to transfer matrix
jsrehak Sep 20, 2018
f21032c
added constructor of XSection that takes a MaterialPropertiesI
jsrehak Sep 21, 2018
40dd11d
fixed unordered_map typedefs in MockMaterialProperties
jsrehak Sep 21, 2018
9ce5316
fixed include guard in MaterialPropertiesI
jsrehak Sep 21, 2018
ad4bed4
added helper functions to generate random unordered_map from int to v…
jsrehak Sep 24, 2018
0e0f8da
added initial testing for XSection using Mock MaterialProperties class
jsrehak Sep 24, 2018
4199d31
added random matrix generator to helper_functions
jsrehak Sep 24, 2018
61f448c
added XSection constructor tests for matrix properties
jsrehak Sep 24, 2018
a0efab3
added tests for helper functions, various fixes to helper functions
jsrehak Sep 24, 2018
f7f3649
added test for btest::RandomMatrix helper function
jsrehak Sep 25, 2018
213e306
added RandomIntMatrixMap tests and fixes
jsrehak Sep 25, 2018
395d9d6
added commandline argument to coverage.sh -r that genrates html repor…
jsrehak Sep 25, 2018
9d4b14a
commented out Material class, changed FundamentData to use MaterialPr…
jsrehak Sep 25, 2018
26ccd7e
removed Materials class, removed functions from BartBuilder that inst…
jsrehak Sep 25, 2018
cabc973
removed all uses of Materials class
jsrehak Sep 25, 2018
a5ca82c
moved declarations of test helper functions to .h file
jsrehak Sep 26, 2018
7f4bba8
initial commit of PreciseSum function with tests
jsrehak Sep 26, 2018
bf21f2f
updated PreciseSum to use Neumaier variation
jsrehak Sep 26, 2018
ac3ba35
removed MaterialProperties::PreciseSum, replaced with butil::PreciseSum
jsrehak Sep 27, 2018
763f432
replaced implicit bool conversions with comparisons
jsrehak Oct 8, 2018
fa86820
renamed material interface class to MaterialBase, renamed protocol bu…
jsrehak Oct 8, 2018
6bdd161
formatting updates to test_helper class
jsrehak Oct 8, 2018
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
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,3 @@ html/
latex/
build/
test_data/

# For ggtags
GPATH
GRTAGS
GTAGS

# For emacs users
.dir-locals.el
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
set(GTEST_ROOT "/usr")
find_package(GTest REQUIRED 1.8.0)
find_package(GMock REQUIRED)
#set(GTEST_INCLUDE_DIRS "/usr/include")
#set(GTEST_BOTH_LIBRARIES "/usr/lib/libgtest_main.so;/usr/lib/libgtest.so")
#set(GMOCK_BOTH_LIBRARIES "/usr/lib/libgmock.a;/usr/lib/libgmock_main.a")

### PROTOCOL BUFFERS #################################################

#include(FindProtobuf)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
"${CMAKE_SOURCE_DIR}/protobuf/material.proto")
get_filename_component(PROTO_INC_DIR ${PROTO_HDRS} DIRECTORY)
### COMPILE AND LINKER FLAGS #########################################

SET(DEAL_II_CXX_FLAGS_DEBUG "${DEAL_II_CXX_FLAGS_DEBUG} -g -O0 --coverage")
Expand All @@ -73,6 +77,7 @@ ENABLE_TESTING()
# Recursively find source files

file(GLOB_RECURSE sources "src/*.cpp" "src/*.cc")
list(APPEND sources ${PROTO_SRCS} ${PROTO_HDRS})
set(testing_sources ${sources})
list(FILTER sources EXCLUDE REGEX ".*/tests/.*")
list(FILTER sources EXCLUDE REGEX ".*/test_helpers/.*")
Expand All @@ -81,7 +86,8 @@ list(FILTER testing_sources EXCLUDE REGEX ".*/main.cc$")

# Include directories
include_directories(${GTEST_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/inc)
${CMAKE_SOURCE_DIR}/inc
${PROTO_INC_DIR})

# Add xtrans executables
ADD_EXECUTABLE(xtrans ${sources})
Expand All @@ -90,8 +96,10 @@ ADD_EXECUTABLE(xtrans_test ${testing_sources})
# Add testing definition and library to xtrans_test
target_compile_definitions(xtrans_test PUBLIC -DTEST)


target_link_libraries(xtrans ${Protobuf_LIBRARIES})
target_link_libraries(xtrans_test ${GTEST_BOTH_LIBRARIES}
${GMOCK_BOTH_LIBRARIES})
${GMOCK_BOTH_LIBRARIES} ${Protobuf_LIBRARIES})

# Add subdirectory builds to build libraries for CTEST
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src/mesh)
Expand Down Expand Up @@ -133,3 +141,8 @@ foreach(test_file ${ctest_files})
COMMAND ${CMAKE_COMMAND} -E copy ${test_file} ${file_name})
endforeach()
add_dependencies(xtrans_test copy_ctest_output_files)

# Create copies of material protocol buffer data
add_custom_target(copy_protoc_files ALL)
file(COPY "./src/material/tests/data/" DESTINATION "./test_data/material")
add_dependencies(xtrans_test copy_protoc_files)
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[![Build Status](https://travis-ci.org/SlaybaughLab/BART.svg?branch=master)](https://travis-ci.org/SlaybaughLab/BART)
| `master` | `dev` | `restart` |
|----------|-------|-----------|
|[![Build Status](https://travis-ci.org/SlaybaughLab/BART.svg?branch=master)](https://travis-ci.org/SlaybaughLab/BART)|[![Build Status](https://travis-ci.org/SlaybaughLab/BART.svg?branch=dev)](https://travis-ci.org/SlaybaughLab/BART)|[![Build Status](https://travis-ci.org/SlaybaughLab/BART.svg?branch=restart)](https://travis-ci.org/SlaybaughLab/BART) [![Codecov](https://codecov.io/gh/SlaybaughLab/BART/branch/restart/graph/badge.svg)](https://codecov.io/gh/SlaybaughLab/BART/branch/restart)|



# Bay Area Radiation Transport (BART)
## What is BART for?
Expand Down
5 changes: 5 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ lcov --remove coverage.info '/usr/*' \
'/home/dealii/libs/*' \
--output-file coverage.info # filter out system and includes
lcov --list coverage.info #debug info
if [ $1 = "-r" ]
then
genhtml coverage.info --branch-coverage --output-directory ./code_coverage_report/
fi
rm *.gcda *.gcno
9 changes: 8 additions & 1 deletion doxygen_config
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,14 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT=./src/aqdata ./src/equation ./src/common ./src/iteration ./src/mesh ./src/material ./src/test_helpers ./src/utility
INPUT= ./src/aqdata \
./src/equation \
./src/common \
./src/iteration \
./src/mesh \
./src/material \
./src/test_helpers \
./src/utility

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
53 changes: 53 additions & 0 deletions protobuf/material.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
syntax = "proto3";

message Material {
string full_name = 1;
string abbreviation = 2;
string id = 3;

uint32 number_of_groups = 4;
uint32 thermal_groups = 5;

repeated ScalarProperty scalar_property = 6;
repeated VectorProperty vector_property = 7;
repeated MatrixProperty matrix_property = 8;

enum ScalarId {
UNKNOWN_SCALAR = 0;
DENSITY = 1;
}

enum VectorId {
UNKNOWN_VECTOR = 0;
ENERGY_GROUPS = 1; // edges of energy groups in eV
CHI = 2;
SIGMA_T = 3; // group homogenized cross sections in 1/cm
SIGMA_A = 4;
NU_SIG_F = 5;
KAPPA_SIG_F = 6;
Q = 7;
}

enum MatrixId {
UNKNOWN_MATRIX = 0;
SIGMA_S = 1; // element r*number_of_groups + c represents scattering from group r+1 to group c+1
}


message ScalarProperty {
ScalarId id = 1;
double value = 2;
}

message VectorProperty {
VectorId id = 1;
repeated double value = 2 [packed=true];
}

message MatrixProperty {
MatrixId id = 1;
uint32 rows = 2;
uint32 cols = 3;
repeated double value = 4 [packed=true];
}
}
10 changes: 0 additions & 10 deletions src/common/bart_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ void BuildAQ (const dealii::ParameterHandler &prm,
}
}

void BuildMaterial (dealii::ParameterHandler &prm,
std::unique_ptr<Materials> &mat_ptr) {
mat_ptr = std::unique_ptr<Materials> (new Materials(prm));
}

std::unique_ptr<Materials> BuildMaterial (
dealii::ParameterHandler &prm) {
return std::unique_ptr<Materials> (new Materials(prm));
}

template <int dim>
void BuildMesh (dealii::ParameterHandler &prm,
std::unique_ptr<MeshGenerator<dim>> &msh_ptr) {
Expand Down
23 changes: 0 additions & 23 deletions src/common/bart_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "../aqdata/aq_base.h"
#include "../mesh/mesh_generator.h"
#include "../material/materials.h"
#include "../equation/equation_base.h"
#include "../iteration/eigen_base.h"
#include "../iteration/mg_base.h"
Expand Down Expand Up @@ -51,28 +50,6 @@ namespace bbuilders {
void BuildAQ (const dealii::ParameterHandler &prm,
std::unique_ptr<AQBase<dim>> &aq_ptr);

//! Function used to build material
/*!
The main functionality is to build pointer to object of Materials
based on parameters specified in prm.

\param prm dealii::ParameterHandler object.
\param mat_ptr Materials object pointer.
\return Void.
*/
void BuildMaterial (dealii::ParameterHandler &prm,
std::unique_ptr<Materials> &mat_ptr);

//! Function used to build material
/*!
The same as previous function but returning pointer to material.

\param prm dealii::ParameterHandler object.
\return Materials object pointer.
*/
std::unique_ptr<Materials> BuildMaterial (
dealii::ParameterHandler &prm);

//! Function used to build mesh
/*!
The main functionality is to build pointer to object of MeshGenerator<dim>
Expand Down
27 changes: 21 additions & 6 deletions src/common/computing_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,47 @@

#include <deal.II/fe/fe_update_flags.h>

XSections::XSections (Materials& material)
// XSections::XSections (Materials& material)
// :
// sigt(material.GetSigT()),
// inv_sigt(material.GetInvSigT()),
// q(material.GetQ()),
// q_per_ster(material.GetQPerSter()),
// is_material_fissile(material.GetFissileIDMap()),
// nu_sigf(material.GetNuSigf()),
// sigs(material.GetSigS()),
// sigs_per_ster(material.GetSigSPerSter()),
// fiss_transfer(material.GetFissTransfer()),
// fiss_transfer_per_ster(material.GetFissTransferPerSter()) {}

XSections::XSections (MaterialBase& material)
:
sigt(material.GetSigT()),
inv_sigt(material.GetInvSigT()),
q(material.GetQ()),
q_per_ster(material.GetQPerSter()),
is_material_fissile(material.GetFissileIDMap()),
nu_sigf(material.GetNuSigf()),
nu_sigf(material.GetNuSigF()),
sigs(material.GetSigS()),
sigs_per_ster(material.GetSigSPerSter()),
fiss_transfer(material.GetFissTransfer()),
fiss_transfer_per_ster(material.GetFissTransferPerSter()) {}
fiss_transfer(material.GetChiNuSigF()),
fiss_transfer_per_ster(material.GetChiNuSigFPerSter())
{}

template <int dim>
FundamentalData<dim>::FundamentalData (dealii::ParameterHandler &prm,
dealii::Triangulation<dim> &tria)
:
pcout(std::cout,
(dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD)==0)),
material(prm),
//material(prm),
mesh(prm),
mat_vec(std::shared_ptr<MatrixVector> (new MatrixVector())),
//xsec(std::shared_ptr<XSections> (new XSections(material))),
fe_data(prm),
dof_handler(tria) {
xsec = std::shared_ptr<XSections> (new XSections(material));
MaterialProtobuf material{prm};
xsec = std::make_shared<XSections>(material);
bbuilders::BuildAQ<dim>(prm, aq);
aq->MakeAQ();
}
Expand Down
8 changes: 5 additions & 3 deletions src/common/computing_data.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef BART_SRC_COMMON_COMPUTING_DATA_H_
#define BART_SRC_COMMON_COMPUTING_DATA_H_

#include "../material/materials.h"
#include "../material/material_base.h"
#include "../material/material_protobuf.h"
#include "../aqdata/aq_base.h"
#include "../mesh/mesh_generator.h"

Expand Down Expand Up @@ -36,7 +37,7 @@ struct MatrixVector {
};

struct XSections {
XSections (Materials &material);
XSections (MaterialBase &material_properties);

//! \f$\sigma_\mathrm{t}\f$ of all groups for all materials.
const std::unordered_map<int, std::vector<double>> sigt;
Expand Down Expand Up @@ -133,7 +134,8 @@ struct FundamentalData {

std::unique_ptr<AQBase<dim>> aq;//!< Pointer to aq data
MeshGenerator<dim> mesh;//!< Pointer to mesh generator
Materials material;//!< Pointer to material properties
//Materials material;//!< Pointer to material properties
//std::unique_ptr<MaterialPropertiesI> material_properties;

std::shared_ptr<MatrixVector> mat_vec;
std::shared_ptr<XSections> xsec;//!< Pointer to access all cross sections.
Expand Down
68 changes: 66 additions & 2 deletions src/common/tests/computing_data_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#include "../computing_data.h"

#include <unordered_map>
#include <vector>

#include <gtest/gtest.h>
#include <deal.II/lac/full_matrix.h>

#include "../problem_definition.h"
#include "../../material/tests/mock_material.h"
#include "../../test_helpers/bart_test_helper.h"
#include "../../test_helpers/gmock_wrapper.h"
#include "../../test_helpers/test_helper_functions.h"

class XSectionsTest : public ::testing::Test {
protected:
using id_vector_map = std::unordered_map<int, std::vector<double>>;
using id_matrix_map = std::unordered_map<int, dealii::FullMatrix<double>>;
btest::MockMaterial mock_material_properties;
};

class ComputingDataTestMPI
:
public btest::BARTParallelEnvironment {
public:
void SetUp ();

void SetUp ();
dealii::ParameterHandler prm_;
};

Expand All @@ -25,3 +41,51 @@ void ComputingDataTestMPI::SetUp() {
TEST_F (ComputingDataTestMPI, 2DFundamentalDataTest) {
dealii::parallel::distributed::Triangulation<2> tria_2d(MPI_COMM_WORLD);
}

TEST_F(XSectionsTest, XSectionsConstructor) {

id_vector_map sigma_t_map = btest::RandomIntVectorMap();
id_vector_map sigma_t_inv_map = btest::RandomIntVectorMap();
id_vector_map q_map = btest::RandomIntVectorMap();
id_vector_map q_per_ster_map = btest::RandomIntVectorMap();
id_vector_map nu_sigf_map = btest::RandomIntVectorMap();
id_matrix_map sig_s_map = btest::RandomIntMatrixMap();
id_matrix_map sig_s_per_ster_map = btest::RandomIntMatrixMap();
id_matrix_map chi_nu_sig_f_map = btest::RandomIntMatrixMap();
id_matrix_map chi_nu_sig_f_per_ster_map = btest::RandomIntMatrixMap();
std::unordered_map<int, bool> fissile_id_map{{1, true}, {2, false}};

EXPECT_CALL(mock_material_properties, GetSigT())
.WillOnce(::testing::Return(sigma_t_map));
EXPECT_CALL(mock_material_properties, GetInvSigT())
.WillOnce(::testing::Return(sigma_t_inv_map));
EXPECT_CALL(mock_material_properties, GetQ())
.WillOnce(::testing::Return(q_map));
EXPECT_CALL(mock_material_properties, GetQPerSter())
.WillOnce(::testing::Return(q_per_ster_map));
EXPECT_CALL(mock_material_properties, GetNuSigF())
.WillOnce(::testing::Return(nu_sigf_map));
EXPECT_CALL(mock_material_properties, GetSigS())
.WillOnce(::testing::Return(sig_s_map));
EXPECT_CALL(mock_material_properties, GetSigSPerSter())
.WillOnce(::testing::Return(sig_s_per_ster_map));
EXPECT_CALL(mock_material_properties, GetChiNuSigF())
.WillOnce(::testing::Return(chi_nu_sig_f_map));
EXPECT_CALL(mock_material_properties, GetChiNuSigFPerSter())
.WillOnce(::testing::Return(chi_nu_sig_f_per_ster_map));
EXPECT_CALL(mock_material_properties, GetFissileIDMap())
.WillOnce(::testing::Return(fissile_id_map));

XSections test_xsections(mock_material_properties);

EXPECT_EQ(test_xsections.sigt, sigma_t_map);
EXPECT_EQ(test_xsections.inv_sigt, sigma_t_inv_map);
EXPECT_EQ(test_xsections.q, q_map);
EXPECT_EQ(test_xsections.q_per_ster, q_per_ster_map);
EXPECT_EQ(test_xsections.nu_sigf, nu_sigf_map);
EXPECT_EQ(test_xsections.sigs, sig_s_map);
EXPECT_EQ(test_xsections.sigs_per_ster, sig_s_per_ster_map);
EXPECT_EQ(test_xsections.fiss_transfer, chi_nu_sig_f_map);
EXPECT_EQ(test_xsections.fiss_transfer_per_ster, chi_nu_sig_f_per_ster_map);
EXPECT_EQ(test_xsections.is_material_fissile, fissile_id_map);
}
Loading