Page MenuHomec4science

field_collection_global.hh
No OneTemporary

File Metadata

Created
Wed, Nov 6, 13:40

field_collection_global.hh

/**
* file field_collection_global.hh
*
* @author Till Junge <till.junge@altermail.ch>
*
* @date 05 Nov 2017
*
* @brief FieldCollection base-class for global fields
*
* @section LICENCE
*
* Copyright (C) 2017 Till Junge
*
* µSpectre is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3, or (at
* your option) any later version.
*
* µSpectre 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef FIELD_COLLECTION_GLOBAL_H
#define FIELD_COLLECTION_GLOBAL_H
#include "common/field_collection_base.hh"
#include "common/ccoord_operations.hh"
namespace muSpectre {
/* ---------------------------------------------------------------------- */
//! DimS spatial dimension (dimension of problem)
//! DimM material_dimension (dimension of constitutive law)
template<Dim_t DimS, Dim_t DimM>
class GlobalFieldCollection:
public FieldCollectionBase<DimS, DimM, GlobalFieldCollection<DimS, DimM>>
{
public:
using Parent = FieldCollectionBase
<DimS, DimM, GlobalFieldCollection<DimS, DimM>>;
using Ccoord = typename Parent::Ccoord;
using Field_p = typename Parent::Field_p;
//! Default constructor
GlobalFieldCollection();
//! Copy constructor
GlobalFieldCollection(const GlobalFieldCollection &other) = delete;
//! Move constructor
GlobalFieldCollection
(GlobalFieldCollection &&other) noexcept = delete;
//! Destructor
virtual ~GlobalFieldCollection() noexcept = default;
//! Copy assignment operator
GlobalFieldCollection&
operator=(const GlobalFieldCollection &other) = delete;
//! Move assignment operator
GlobalFieldCollection&
operator=(GlobalFieldCollection &&other) noexcept = delete;
/** allocate memory, etc. At this point, the collection is
informed aboud the size and shape of the domain (through the
sizes parameter). The job of initialise is to make sure that
all fields are either of size 0, in which case they need to be
allocated, or are of the same size as the product of 'sizes'
any field of a different size is wrong TODO: check whether it
makes sense to put a runtime check here
**/
inline void initialise(Ccoord sizes);
//! return the pixel sizes
inline const Ccoord & get_sizes() const;
//! returns the linear index corresponding to cell coordinates
inline size_t get_index(Ccoord && ccoord) const;
//! returns the cell coordinates corresponding to a linear index
inline Ccoord get_ccoord(size_t index) const;
static constexpr inline Dim_t spatial_dim() {return DimS;}
static constexpr inline Dim_t material_dim() {return DimM;}
protected:
//! number of discretisation cells in each of the DimS spatial directions
Ccoord sizes{0};
private:
};
/* ---------------------------------------------------------------------- */
template <Dim_t DimS, Dim_t DimM>
GlobalFieldCollection<DimS, DimM>::GlobalFieldCollection()
:Parent(){}
/* ---------------------------------------------------------------------- */
template <Dim_t DimS, Dim_t DimM>
void GlobalFieldCollection<DimS, DimM>::
initialise(Ccoord sizes) {
this->size_ = std::accumulate(sizes.begin(), sizes.end(), 1,
std::multiplies<Dim_t>());
this->sizes = sizes;
std::for_each(std::begin(this->fields), std::end(this->fields),
[this](auto && item) {
auto && field = *item.second;
const auto field_size = field.size();
if (field_size == 0) {
field.resize(this->size());
} else if (field_size != this->size()) {
std::stringstream err_stream;
err_stream << "Field '" << field.get_name()
<< "' contains " << field_size
<< " entries, but the field collection "
<< "has " << this->size() << " pixels";
throw FieldCollectionError(err_stream.str());
}
});
this->is_initialised = true;
}
//----------------------------------------------------------------------------//
//! return the pixel sizes
template <Dim_t DimS, Dim_t DimM>
const typename GlobalFieldCollection<DimS, DimM>::Ccoord &
GlobalFieldCollection<DimS, DimM>::get_sizes() const {
return this->sizes;
}
//----------------------------------------------------------------------------//
//! returns the cell coordinates corresponding to a linear index
template <Dim_t DimS, Dim_t DimM>
typename GlobalFieldCollection<DimS, DimM>::Ccoord
GlobalFieldCollection<DimS, DimM>::get_ccoord(size_t index) const {
return CcoordOps::get_ccoord(this->get_sizes(), std::move(index));
}
//----------------------------------------------------------------------------//
//! returns the linear index corresponding to cell coordinates
template <Dim_t DimS, Dim_t DimM>
size_t
GlobalFieldCollection<DimS, DimM>::get_index(Ccoord && ccoord) const {
return CcoordOps::get_index(this->get_sizes(), std::move(ccoord));
}
} // muSpectre
#endif /* FIELD_COLLECTION_GLOBAL_H */

Event Timeline