Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84257846
model_type.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Sep 21, 16:46
Size
6 KB
Mime Type
text/x-c++
Expires
Mon, Sep 23, 16:46 (2 d)
Engine
blob
Format
Raw Data
Handle
20972244
Attached To
rTAMAAS tamaas
model_type.hh
View Options
/*
* SPDX-License-Indentifier: AGPL-3.0-or-later
*
* Copyright (©) 2016-2022 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef MODEL_TYPE_HH
#define MODEL_TYPE_HH
/* -------------------------------------------------------------------------- */
#include "grid.hh"
#include "grid_base.hh"
#include "static_types.hh"
#include "tamaas.hh"
#include <algorithm>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <memory>
/* -------------------------------------------------------------------------- */
namespace
tamaas
{
// clang-format off
/// Models types **for printing only** \cond HIDDEN_SYMBOLS
#define TAMAAS_MODEL_TYPES \
(basic_1d) \
(basic_2d) \
(surface_1d) \
(surface_2d) \
(volume_1d) \
(volume_2d)
// clang-format on
/// \endcond
/// Types for grid dimensions and number of components
enum
class
model_type
{
basic_1d
,
///< one component line
basic_2d
,
///< one component surface
surface_1d
,
///< two components line
surface_2d
,
///< three components surface
volume_1d
,
///< two components volume
volume_2d
///< three components volume
};
/// Trait class to store physical dimension of domain, of boundary and
/// number of components
template
<
model_type
type
>
struct
model_type_traits
{};
#define MODEL_TYPE_TRAITS_MACRO(type, dim, comp, bdim) \
template <> \
struct model_type_traits<model_type::type> { \
static constexpr char repr[]{#type}; \
static constexpr UInt dimension = dim; \
static constexpr UInt components = comp; \
static constexpr UInt boundary_dimension = bdim; \
static constexpr UInt voigt = voigt_size<comp>::value; \
static const std::vector<UInt> indices; \
}
MODEL_TYPE_TRAITS_MACRO
(
basic_1d
,
1
,
1
,
1
);
MODEL_TYPE_TRAITS_MACRO
(
basic_2d
,
2
,
1
,
2
);
MODEL_TYPE_TRAITS_MACRO
(
surface_1d
,
1
,
2
,
1
);
MODEL_TYPE_TRAITS_MACRO
(
surface_2d
,
2
,
3
,
2
);
MODEL_TYPE_TRAITS_MACRO
(
volume_1d
,
2
,
2
,
1
);
MODEL_TYPE_TRAITS_MACRO
(
volume_2d
,
3
,
3
,
2
);
#undef MODEL_TYPE_TRAITS_MACRO
namespace
detail
{
template
<
model_type
type
,
bool
boundary
>
struct
dim_choice
:
std
::
integral_constant
<
UInt
,
(
boundary
)
?
model_type_traits
<
type
>::
boundary_dimension
:
model_type_traits
<
type
>::
dimension
>
{};
}
// namespace detail
template
<
model_type
type
,
bool
boundary
,
typename
T
,
typename
Container
>
std
::
unique_ptr
<
Grid
<
T
,
detail
::
dim_choice
<
type
,
boundary
>::
value
>>
allocateGrid
(
Container
&&
n
,
UInt
nc
)
{
return
std
::
make_unique
<
Grid
<
T
,
detail
::
dim_choice
<
type
,
boundary
>::
value
>>
(
std
::
begin
(
n
),
std
::
end
(
n
),
nc
);
}
/// \cond HIDDEN_SYMBOLS
#define ALLOC_GRID_CASE_MACRO(a, data, type) \
case data::type: { \
ptr = allocateGrid<data::type, boundary, T>( \
n, model_type_traits<data::type>::components); \
break; \
}
/// \endcond
/// Helper function for grid allocation
template
<
bool
boundary
,
typename
T
,
typename
Container
>
std
::
unique_ptr
<
GridBase
<
T
>>
allocateGrid
(
model_type
type
,
Container
&&
n
)
{
std
::
unique_ptr
<
GridBase
<
T
>>
ptr
=
nullptr
;
switch
(
type
)
{
BOOST_PP_SEQ_FOR_EACH
(
ALLOC_GRID_CASE_MACRO
,
model_type
,
TAMAAS_MODEL_TYPES
);
}
return
ptr
;
}
#undef ALLOC_GRID_CASE_MACRO
#define ALLOC_GRID_CASE_MACRO(a, data, type) \
case data::type: { \
ptr = allocateGrid<data::type, boundary, T>(n, nc); \
break; \
}
/// Helper function for grid allocation with
/// non-standard components
template
<
bool
boundary
,
typename
T
,
typename
Container
>
std
::
unique_ptr
<
GridBase
<
T
>>
allocateGrid
(
model_type
type
,
Container
&&
n
,
UInt
nc
)
{
std
::
unique_ptr
<
GridBase
<
T
>>
ptr
=
nullptr
;
switch
(
type
)
{
BOOST_PP_SEQ_FOR_EACH
(
ALLOC_GRID_CASE_MACRO
,
model_type
,
TAMAAS_MODEL_TYPES
);
}
return
ptr
;
}
/// Print function for model_type
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
const
model_type
&
val
)
{
switch
(
val
)
{
#define PRINT_MODEL_TYPE(r, data, type) \
case data::type: \
o << model_type_traits<data::type>::repr; \
break;
BOOST_PP_SEQ_FOR_EACH
(
PRINT_MODEL_TYPE
,
model_type
,
TAMAAS_MODEL_TYPES
);
#undef PRINT_MODEL_TYPE
}
return
o
;
}
#undef ALLOC_GRID_CASE_MACRO
// clang-format off
#ifdef TAMAAS_MODEL_TYPES
#undef TAMAAS_MODEL_TYPES
#endif
#define TAMAAS_MODEL_TYPES \
(model_type::basic_1d) \
(model_type::basic_2d) \
(model_type::surface_1d) \
(model_type::surface_2d) \
(model_type::volume_1d) \
(model_type::volume_2d)
// clang-format on
}
// namespace tamaas
/* --------------------------------------------------------------------------
*/
#endif
// MODEL_TYPE_HH
Event Timeline
Log In to Comment