1#ifndef VIENNASHE_UTIL_MISC_HPP
2#define VIENNASHE_UTIL_MISC_HPP
27#include "viennagrid/forwards.hpp"
28#include "viennagrid/algorithm/voronoi.hpp"
29#include "viennagrid/algorithm/interface.hpp"
30#include "viennagrid/algorithm/boundary.hpp"
57 template <
typename ValueType>
82 template <
typename ContainerType>
86 for (
typename ContainerType::const_iterator cit = cont.begin();
89 ret += *cit / cont.size();
102 template <
typename ContainerType>
106 for (
typename ContainerType::const_iterator cit = cont.begin();
110 ret *= std::pow(*cit, 1.0 / cont.size());
123 template <
typename ContainerType>
127 for (
typename ContainerType::const_iterator cit = cont.begin();
147 template <
typename FilterType,
typename FunctorType>
153 template <
typename T>
160 template <
typename T>
168 FilterType
const & filter_;
173 template <
typename FilterType,
typename FunctorType>
174 filtered_functor<FilterType, FunctorType>
187 template <
typename U>
195 template <
typename MeshT,
typename FacetT,
typename CellT>
198 typedef typename viennagrid::result_of::const_coboundary_range<MeshT, FacetT, CellT>::type CellOnFacetContainer;
199 typedef typename viennagrid::result_of::iterator<CellOnFacetContainer>::type CellOnFacetIterator;
201 CellOnFacetContainer cells_on_facet(mesh, viennagrid::handle(mesh, facet));
202 CellOnFacetIterator cofit = cells_on_facet.begin();
204 if ( &(*cofit) == &(cell))
207 if (cofit == cells_on_facet.end())
215 template <
typename DeviceT,
typename CellT>
218 typedef typename viennagrid::result_of::const_facet_range<CellT>::type FacetOnCellContainer;
219 typedef typename viennagrid::result_of::iterator<FacetOnCellContainer>::type FacetOnCellIterator;
221 FacetOnCellContainer facets_on_cell(cell);
222 for (FacetOnCellIterator focit = facets_on_cell.begin();
223 focit != facets_on_cell.end();
252 template <
typename T,
typename U>
258 template <
typename T>
271 template <
typename DeviceType,
typename ElementTagT,
typename ValueType =
double>
276 typedef typename DeviceType::mesh_type MeshType;
279 typedef typename viennagrid::result_of::element<MeshType, ElementTagT>::type
element_type;
283 template <
typename VectorType,
typename IndexKeyType,
typename BoundaryValueAccessor>
285 VectorType
const & quantity_values,
286 IndexKeyType
const & index_array,
287 BoundaryValueAccessor
const & bnd_accessor)
288 : values_(viennagrid::elements<ElementTagT>(
device.mesh()).size()), vec_(quantity_values.size())
291 typename VectorType::value_type>::value
294 typedef typename viennagrid::result_of::const_element_range<MeshType, ElementTagT>::type ElementContainer;
295 typedef typename viennagrid::result_of::iterator<ElementContainer>::type ElementIterator;
296 typedef typename element_type::id_type id_type;
300 for (ElementIterator it = elements.begin(); it != elements.end(); ++it)
302 id_type element_id = it->id();
303 long index = index_array.at(element_id);
306 values_.at(element_id) = quantity_values[index];
308 values_.at(element_id) = bnd_accessor(*it);
311 for (std::size_t i=0; i<quantity_values.size(); ++i)
312 vec_[i] = quantity_values[i];
318 return values_.at(t.id());
322 std::vector<double>
const &
vector()
const {
return vec_; }
325 std::vector<value_type> values_;
326 std::vector<double> vec_;
335 template <
typename DeviceType,
typename ElementTagT,
typename ValueType =
double>
340 typedef typename DeviceType::mesh_type MeshType;
343 typedef typename viennagrid::result_of::element<MeshType, ElementTagT>::type
element_type;
347 spatial_quantity(DeviceType
const &
device, ValueType default_value = ValueType()) : values_(viennagrid::cells(
device.mesh()).size(), default_value) {}
352 return values_.at(t.id());
357 values_.at(t.id()) = val;
361 std::vector<value_type> values_;
371 template <
typename T>
375 s << std::setfill(
' ') << std::setw(width) << number;
385 template <
typename VectorType>
386 typename VectorType::value_type
norm_inf(VectorType
const & v, std::size_t index_start, std::size_t index_stop)
388 typename VectorType::value_type ret = 0;
389 for (std::size_t i=index_start; i<index_stop; ++i)
390 ret = std::max(std::abs(v[i]), ret);
long get_material(cell_type const &elem) const
Returns the material id of the provided cell.
MeshT const & mesh() const
Returns the underlying mesh.
Defines the physical properties of a device, e.g. doping. This is the implementation for 2d and highe...
A compound functor which applies the provided functor only to the argument if the supplied filter eva...
filtered_functor(FilterType const &fil, FunctorType &fun)
void operator()(T const &t)
A functor-style wrapper for a spatial quantity (typically potential, electron density or hole density...
viennagrid::result_of::element< MeshType, ElementTagT >::type element_type
value_type operator()(element_type const &t) const
The functor interface.
spatial_quantity_wrapper(DeviceType const &device, VectorType const &quantity_values, IndexKeyType const &index_array, BoundaryValueAccessor const &bnd_accessor)
Copy over all values from the accessors so that this object can be easily passed around.
std::vector< double > const & vector() const
Returns the internal vector with the quantities. Allows to externally adjust the quantity.
A functor-style wrapper for a spatial quantity which is externally prescribed by the user.
value_type operator()(element_type const &t) const
The functor interface.
spatial_quantity(DeviceType const &device, ValueType default_value=ValueType())
Copy over all values from the accessors so that this object can be easily passed around.
void set(element_type const &t, ValueType val)
viennagrid::result_of::element< MeshType, ElementTagT >::type element_type
A functor which holds a single value. Used in most of the postprocessing routines.
value_type operator()() const
void operator()(T const &, value_type val) const
Provides the exceptions used in the main viennashe namespace.
Contains forward declarations and definition of small classes that must be defined at an early stage.
A very simple material database. Needs to be replaced by something more versatile soon.
bool is_semiconductor(long material_id)
Convenience function for checking whether the supplied material ID refers to a semiconductor.
VectorType::value_type norm_inf(VectorType const &v, std::size_t index_start, std::size_t index_stop)
Computes the infimum norm of a subvector.
std::string format_number_to_width(T number, int width)
Returns the formatted number as string with the given length, where spaces are used as padding charac...
filtered_functor< FilterType, FunctorType > make_filtered_functor(FilterType const &filter, FunctorType &fun)
Convenience routine for creating a filtered functor out of the provided filter- and action-functor....
CellT const * get_connected_semiconductor_cell(DeviceT const &device, CellT const &cell)
Helper function returning a const-pointer to the 'second cell' of a facet, or NULL if there is no sec...
CellT const * get_other_cell_of_facet(MeshT const &mesh, FacetT const &facet, CellT const &cell)
Helper function returning a const-pointer to the 'second cell' of a facet, or NULL if there is no sec...
The main ViennaSHE namespace. All functionality resides inside this namespace.
A functor which computes the arithmetic average of all entries in a container.
double operator()(ContainerType const &cont) const
A functor assigning unity weight to the element provided.
double operator()(U const &) const
A functor which computes the geometric average of all entries in a container.
double operator()(ContainerType const &cont) const
A functor which returns the result of a logic-or chain consisting of all elements of the supplied con...
bool operator()(ContainerType const &cont) const
Defines all exceptions used/thrown in the viennashe/util/ namespace.