Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62986849
dumper_field.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
Thu, May 16, 23:23
Size
7 KB
Mime Type
text/x-c
Expires
Sat, May 18, 23:23 (2 d)
Engine
blob
Format
Raw Data
Handle
17716579
Attached To
rAKA akantu
dumper_field.hh
View Options
/**
* @file dumper_field.hh
*
* @author Nicolas Richart <nicolas.richart@epfl.ch>
*
* @date creation: Tue Sep 02 2014
* @date last modification: Tue Jan 19 2016
*
* @brief Common interface for fields
*
* @section LICENSE
*
* Copyright (©) 2014, 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "element_type_map.hh"
#include "support.hh"
/* -------------------------------------------------------------------------- */
#include <sstream>
#include <typeindex>
/* -------------------------------------------------------------------------- */
#ifndef __AKANTU_DUMPER_FIELD_HH__
#define __AKANTU_DUMPER_FIELD_HH__
namespace
akantu
{
namespace
dumper
{
enum
class
FieldType
{
_not_defined
,
_array
,
_element_map_array
,
_connectivity
};
/// Field interface
class
FieldBase
:
public
PropertiesManager
{
public
:
virtual
~
FieldBase
()
=
default
;
FieldBase
(
const
FieldBase
&
)
=
default
;
FieldBase
(
FieldBase
&&
)
=
delete
;
FieldBase
&
operator
=
(
const
FieldBase
&
)
=
delete
;
FieldBase
&
operator
=
(
FieldBase
&&
)
=
delete
;
explicit
FieldBase
(
const
SupportBase
&
support
,
FieldType
type
)
:
support
(
support
),
field_type
(
type
)
{}
AKANTU_GET_MACRO
(
FieldType
,
field_type
,
FieldType
);
AKANTU_GET_MACRO
(
Support
,
support
,
const
SupportBase
&
);
protected
:
const
SupportBase
&
support
;
FieldType
field_type
{
FieldType
::
_not_defined
};
};
/* ------------------------------------------------------------------------ */
class
FieldArrayBase
:
public
FieldBase
{
public
:
FieldArrayBase
(
const
FieldArrayBase
&
)
=
default
;
FieldArrayBase
(
FieldArrayBase
&&
)
=
delete
;
FieldArrayBase
&
operator
=
(
const
FieldArrayBase
&
)
=
delete
;
FieldArrayBase
&
operator
=
(
FieldArrayBase
&&
)
=
delete
;
explicit
FieldArrayBase
(
const
SupportBase
&
support
)
:
FieldBase
(
support
,
FieldType
::
_array
)
{}
virtual
~
FieldArrayBase
()
=
default
;
[[
nodiscard
]]
virtual
std
::
type_index
type
()
const
=
0
;
[[
nodiscard
]]
virtual
const
void
*
data
()
const
=
0
;
[[
nodiscard
]]
virtual
void
*
data
()
=
0
;
[[
nodiscard
]]
virtual
std
::
size_t
size
()
const
=
0
;
[[
nodiscard
]]
virtual
std
::
size_t
getNbComponent
()
const
=
0
;
};
/* ------------------------------------------------------------------------ */
class
FieldElementMapArrayBase
:
public
FieldBase
{
public
:
using
ElementTypesIteratorHelper
=
ElementTypeMapArray
<
UInt
,
ElementType
>::
ElementTypesIteratorHelper
;
explicit
FieldElementMapArrayBase
(
const
SupportBase
&
support
)
:
FieldBase
(
support
,
FieldType
::
_element_map_array
)
{}
[[
nodiscard
]]
virtual
ElementTypesIteratorHelper
elementTypes
()
const
=
0
;
[[
nodiscard
]]
virtual
FieldArrayBase
&
array
(
const
Qualified
<
ElementType
>
&
type
)
const
=
0
;
};
/* ------------------------------------------------------------------------ */
template
<
typename
T
>
class
FieldArray
:
public
FieldArrayBase
{
public
:
FieldArray
(
const
Array
<
T
>
&
array
,
const
SupportBase
&
support
)
:
FieldArrayBase
(
support
),
array
(
array
)
{}
[[
nodiscard
]]
std
::
type_index
type
()
const
override
{
return
{
typeid
(
T
)};
}
[[
nodiscard
]]
const
void
*
data
()
const
override
{
return
array
.
storage
();
}
[[
nodiscard
]]
void
*
data
()
override
{
return
array
.
storage
();
}
[[
nodiscard
]]
std
::
size_t
size
()
const
override
{
return
array
.
size
();
}
[[
nodiscard
]]
std
::
size_t
getNbComponent
()
const
override
{
return
array
.
getNbComponent
();
}
[[
nodiscard
]]
const
Array
<
T
>
&
getArray
()
const
{
return
array
;
}
private
:
const
Array
<
T
>
&
array
;
};
/* ------------------------------------------------------------------------ */
template
<
typename
T
>
class
FieldElementMapArray
:
public
FieldElementMapArrayBase
{
public
:
FieldElementMapArray
(
const
ElementTypeMapArray
<
T
>
&
map_array
,
const
SupportBase
&
support
)
:
FieldElementMapArrayBase
(
support
),
support_element
(
dynamic_cast
<
const
SupportElements
&>
(
support
)),
map_array
(
map_array
)
{
for
(
auto
&&
type
:
support_element
.
elementTypes
())
{
std
::
string
name
=
std
::
to_string
(
type
.
type
);
if
(
type
.
ghost_type
!=
_not_ghost
)
name
+
":"
+
std
::
to_string
(
type
.
ghost_type
);
auto
field
=
std
::
make_unique
<
FieldArray
<
T
>>
(
map_array
(
type
),
support
);
field
->
addProperty
(
"name"
,
name
);
fields
.
emplace
(
type
,
std
::
move
(
field
));
}
}
[[
nodiscard
]]
FieldArrayBase
&
array
(
const
Qualified
<
ElementType
>
&
type
)
const
override
{
return
*
fields
.
at
(
type
);
}
[[
nodiscard
]]
decltype
(
auto
)
arrayTyped
(
const
Qualified
<
ElementType
>
&
type
)
const
{
return
(
aka
::
as_type
<
FieldArray
<
T
>>
(
*
fields
.
at
(
type
)));
}
[[
nodiscard
]]
ElementTypesIteratorHelper
elementTypes
()
const
override
{
return
support_element
.
elementTypes
();
};
std
::
pair
<
UInt
,
UInt
>
getTotalNbElements
()
{
UInt
total_element
{
0
};
UInt
total_size
{
0
};
for
(
auto
&&
type
:
this
->
elementTypes
())
{
auto
&&
array
=
this
->
array
(
type
);
total_element
+=
array
.
size
();
total_size
+=
array
.
size
()
*
array
.
getNbComponent
();
}
return
std
::
make_pair
(
total_element
,
total_size
);
}
private
:
const
SupportElements
&
support_element
;
const
ElementTypeMapArray
<
T
>
&
map_array
;
std
::
map
<
Qualified
<
ElementType
>
,
std
::
unique_ptr
<
FieldArray
<
T
>>>
fields
;
};
/* ------------------------------------------------------------------------ */
class
FieldConnectivity
:
public
FieldElementMapArray
<
UInt
>
{
public
:
FieldConnectivity
(
const
ElementTypeMapArray
<
UInt
>
&
map_array
,
const
SupportBase
&
support
)
:
FieldElementMapArray
<
UInt
>
(
map_array
,
support
)
{
field_type
=
FieldType
::
_connectivity
;
}
};
/* ------------------------------------------------------------------------ */
template
<
typename
T
>
auto
make_field
(
const
Array
<
T
>
&
array
,
const
SupportBase
&
support
)
{
return
std
::
make_unique
<
FieldArray
<
T
>>
(
array
,
support
);
}
/* ------------------------------------------------------------------------ */
template
<
typename
T
>
auto
make_field
(
const
ElementTypeMapArray
<
T
>
&
array
,
const
SupportBase
&
support
)
{
return
std
::
make_unique
<
FieldElementMapArray
<
T
>>
(
array
,
support
);
}
/* ------------------------------------------------------------------------ */
template
<
typename
T
>
auto
make_connectivity_field
(
const
ElementTypeMapArray
<
T
>
&
array
,
const
SupportBase
&
support
)
{
return
std
::
make_unique
<
FieldConnectivity
>
(
array
,
support
);
}
}
// namespace dumper
}
// namespace akantu
#endif
/* __AKANTU_DUMPER_FIELD_HH__ */
Event Timeline
Log In to Comment