Skip to content

Commit

Permalink
Merge pull request #297 from gsb76/gab_add_brick
Browse files Browse the repository at this point in the history
Add Brick and test
  • Loading branch information
kidder committed Oct 27, 2017
2 parents 2938035 + 9b38b08 commit adca70b
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 10 deletions.
74 changes: 74 additions & 0 deletions src/Domain/DomainCreators/Brick.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Domain/DomainCreators/Brick.hpp"

#include <array>
#include <unordered_set>
#include <vector>

#include "Domain/Block.hpp"
#include "Domain/BlockNeighbor.hpp"
#include "Domain/CoordinateMaps/AffineMap.hpp"
#include "Domain/CoordinateMaps/ProductMaps.hpp"
#include "Domain/Direction.hpp"
#include "Domain/Domain.hpp"
#include "Options/Options.hpp"
#include "Utilities/MakeVector.hpp"

namespace DomainCreators {

Brick::Brick(
typename LowerBound::type lower_xyz, typename UpperBound::type upper_xyz,
typename IsPeriodicIn::type is_periodic_in_xyz,
typename InitialRefinement::type initial_refinement_level_xyz,
typename InitialGridPoints::type initial_number_of_grid_points_in_xyz,
const OptionContext& /*context*/) noexcept
// clang-tidy: trivially copyable
: lower_xyz_(std::move(lower_xyz)), // NOLINT
upper_xyz_(std::move(upper_xyz)), // NOLINT
is_periodic_in_xyz_(std::move(is_periodic_in_xyz)), // NOLINT
initial_refinement_level_xyz_( // NOLINT
std::move(initial_refinement_level_xyz)), // NOLINT
initial_number_of_grid_points_in_xyz_( // NOLINT
std::move(initial_number_of_grid_points_in_xyz)) {} // NOLINT

Domain<3, Frame::Inertial> Brick::create_domain() const noexcept {
using AffineMap = CoordinateMaps::AffineMap;
using AffineMap3D =
CoordinateMaps::ProductOf3Maps<AffineMap, AffineMap, AffineMap>;
std::vector<PairOfFaces> identifications{};
if (is_periodic_in_xyz_[0]) {
identifications.push_back({{0, 4, 2, 6}, {1, 5, 3, 7}});
}
if (is_periodic_in_xyz_[1]) {
identifications.push_back({{0, 1, 4, 5}, {2, 3, 6, 7}});
}
if (is_periodic_in_xyz_[2]) {
identifications.push_back({{0, 1, 2, 3}, {4, 5, 6, 7}});
}

return Domain<3, Frame::Inertial>{
make_vector<std::unique_ptr<
CoordinateMapBase<Frame::Logical, Frame::Inertial, 3>>>(
std::make_unique<
CoordinateMap<Frame::Logical, Frame::Inertial, AffineMap3D>>(
AffineMap3D{AffineMap{-1., 1., lower_xyz_[0], upper_xyz_[0]},
AffineMap{-1., 1., lower_xyz_[1], upper_xyz_[1]},
AffineMap{-1., 1., lower_xyz_[2], upper_xyz_[2]}})),
std::vector<std::array<size_t, 8>>{{{0, 1, 2, 3, 4, 5, 6, 7}}},
identifications};
}

std::array<size_t, 3> Brick::initial_extents(const size_t block_index) const
noexcept {
ASSERT(0 == block_index, "index = " << block_index);
return initial_number_of_grid_points_in_xyz_;
}

std::array<size_t, 3> Brick::initial_refinement_levels(
const size_t block_index) const noexcept {
ASSERT(0 == block_index, "index = " << block_index);
return initial_refinement_level_xyz_;
}
} // namespace DomainCreators
81 changes: 81 additions & 0 deletions src/Domain/DomainCreators/Brick.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

/// \file
/// Defines class Brick.

#pragma once

#include "Domain/DomainCreators/DomainCreator.hpp"
#include "Options/Options.hpp"

namespace DomainCreators {

/// \ingroup DomainCreatorsGroup
/// Create a 3D Domain consisting of a single Block.
class Brick : public DomainCreator<3, Frame::Inertial> {
public:
struct LowerBound {
using type = std::array<double, 3>;
static constexpr OptionString_t help = {
"Sequence of [x,y,z] for lower bounds."};
};

struct UpperBound {
using type = std::array<double, 3>;
static constexpr OptionString_t help = {
"Sequence of [x,y,z] for upper bounds."};
};
struct IsPeriodicIn {
using type = std::array<bool, 3>;
static constexpr OptionString_t help = {
"Sequence for [x,y,z], true if periodic."};
static type default_value() { return make_array<3>(false); }
};

struct InitialRefinement {
using type = std::array<size_t, 3>;
static constexpr OptionString_t help = {
"Initial refinement level in [x,y,z]."};
};

struct InitialGridPoints {
using type = std::array<size_t, 3>;
static constexpr OptionString_t help = {
"Initial number of grid points in [x,y,z]."};
};
using options = tmpl::list<LowerBound, UpperBound, IsPeriodicIn,
InitialRefinement, InitialGridPoints>;

static constexpr OptionString_t help{"Creates a 3D brick."};

Brick(typename LowerBound::type lower_xyz,
typename UpperBound::type upper_xyz,
typename IsPeriodicIn::type is_periodic_in_xyz,
typename InitialRefinement::type initial_refinement_level_xyz,
typename InitialGridPoints::type initial_number_of_grid_points_in_xyz,
const OptionContext& context = {}) noexcept;

Brick() = default;
Brick(const Brick&) = delete;
Brick(Brick&&) noexcept = default;
Brick& operator=(const Brick&) = delete;
Brick& operator=(Brick&&) noexcept = default;
~Brick() noexcept override = default;

Domain<3, Frame::Inertial> create_domain() const noexcept override;

std::array<size_t, 3> initial_extents(size_t block_index) const
noexcept override;

std::array<size_t, 3> initial_refinement_levels(size_t block_index) const
noexcept override;

private:
typename LowerBound::type lower_xyz_{};
typename UpperBound::type upper_xyz_{};
typename IsPeriodicIn::type is_periodic_in_xyz_{};
typename InitialRefinement::type initial_refinement_level_xyz_{};
typename InitialGridPoints::type initial_number_of_grid_points_in_xyz_{};
};
} // namespace DomainCreators
1 change: 1 addition & 0 deletions src/Domain/DomainCreators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
set(LIBRARY DomainCreators)

set(LIBRARY_SOURCES
Brick.cpp
Interval.cpp
Rectangle.cpp
)
Expand Down
22 changes: 12 additions & 10 deletions src/Domain/DomainCreators/DomainCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Domain;

/// Defines classes that create Domains.
namespace DomainCreators {
// class Brick;
class Brick;
// class Disk;
class Interval;
class Rectangle;
Expand Down Expand Up @@ -54,14 +54,16 @@ struct domain_creators<2> {
typelist<DomainCreators::Rectangle //, DomainCreators::Disk,
// DomainCreators::RotatedRectangles
>;
// };
// template <>
// struct domain_creators<3> {
// using type =
// typelist<DomainCreators::Brick, DomainCreators::RubiksCubeWithHole,
// DomainCreators::Shell, DomainCreators::Sphere,
// DomainCreators::RotatedBricks,
// DomainCreators::UnevenBricks>;
};
template <>
struct domain_creators<3> {
using type = typelist<
DomainCreators::Brick //, DomainCreators::RubiksCubeWithHole,
// DomainCreators::Shell,
// DomainCreators::Sphere,
// DomainCreators::RotatedBricks,
// DomainCreators::UnevenBricks
>;
};
} // namespace DomainCreators_detail

Expand Down Expand Up @@ -92,7 +94,7 @@ class DomainCreator : public Factory<DomainCreator<VolumeDim, TargetFrame>> {
size_t block_index) const = 0;
};

// #include "Domain/DomainCreators/Brick.hpp"
#include "Domain/DomainCreators/Brick.hpp"
// #include "Domain/DomainCreators/Disk.hpp"
#include "Domain/DomainCreators/Interval.hpp"
#include "Domain/DomainCreators/Rectangle.hpp"
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Domain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(DOMAIN_TESTS
Domain/CoordinateMaps/Test_Rotation.cpp
Domain/CoordinateMaps/Test_Wedge2D.cpp
Domain/CoordinateMaps/Test_Wedge3D.cpp
Domain/DomainCreators/Test_Brick.cpp
Domain/DomainCreators/Test_Interval.cpp
Domain/DomainCreators/Test_Rectangle.cpp
Domain/Test_Block.cpp
Expand Down

0 comments on commit adca70b

Please sign in to comment.