1#ifndef VIENNASHE_MAPPING_HPP
2#define VIENNASHE_MAPPING_HPP
25#include "viennagrid/mesh/mesh.hpp"
52 template <
typename DeviceType,
typename VertexT>
57 typedef typename DeviceType::mesh_type MeshType;
59 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
60 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
65 long mapping_index = start_index;
68 for (CellIterator cit = cells.begin();
96 template <
typename DeviceType,
typename CellType,
typename SHEQuantity>
98 CellType
const & cell,
102 long & current_index)
104 const long expansion_order =
static_cast<long>(quan.get_expansion_order(cell, index_H));
111 && quan.get_kinetic_energy(cell, index_H) < kinetic_energy_max)
113 quan.set_unknown_index(cell, index_H, current_index);
118 quan.set_unknown_index(cell, index_H, -1);
119 quan.set_expansion_order(cell, index_H, 0);
123 && quan.get_kinetic_energy(cell, index_H) < kinetic_energy_max)
125 quan.set_unknown_index(cell, index_H, current_index);
130 quan.set_unknown_index(cell, index_H, -1);
131 quan.set_expansion_order(cell, index_H, 0);
140 template <
typename DeviceType,
typename SHEQuantity,
typename FacetType>
144 FacetType
const & facet,
146 long & current_index)
148 typedef typename DeviceType::mesh_type MeshType;
150 typedef typename viennagrid::result_of::cell<MeshType>::type CellType;
152 typedef typename viennagrid::result_of::const_coboundary_range<MeshType, FacetType, CellType>::type CellOnFacetContainer;
153 typedef typename viennagrid::result_of::iterator<CellOnFacetContainer>::type CellOnFacetIterator;
157 CellOnFacetIterator cofit = cells_on_facet.begin();
159 CellType
const & c1 = *cofit;
161 if (cofit == cells_on_facet.end())
163 quan.set_unknown_index(facet, index_H, -1);
164 quan.set_expansion_order(facet, index_H, 0);
168 CellType
const & c2 = *cofit;
173 long dof1 = quan.get_unknown_index(c1, index_H);
174 long dof2 = quan.get_unknown_index(c2, index_H);
175 if (dof1 > -1 && dof2 > -1
179 quan.set_unknown_index(facet, index_H, current_index);
180 current_index +=
static_cast<long>(quan.get_unknown_num(facet, index_H));
184 quan.set_unknown_index(facet, index_H, -1);
185 quan.set_expansion_order(facet, index_H, 0);
203 template <
typename DeviceType,
typename SHEQuantity>
207 long unknown_offset = 0)
209 typedef typename DeviceType::mesh_type MeshType;
211 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
212 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
216 CellContainer cells(mesh);
236 if(quan.get_value_H_size() == 0 )
return 0;
238 int size = 1, rank = 0;
241 MPI_Comm_size(PETSC_COMM_WORLD,&size);
242 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
244 std::size_t maxquantityfull = quan.get_value_H_size();
246 std::size_t maxquantity = rank < size-1 ? ((rank+1)*maxquantityfull)/size+1 :maxquantityfull ;
247 std::size_t init = ((rank)*maxquantityfull)/size;
248 long unknown_index = unknown_offset;
249 for (std::size_t index_H = init; index_H < maxquantity; ++index_H)
251 for (CellIterator cit = cells.begin();
255 if (quan.get_unknown_mask(*cit) == false )
258 quan.set_unknown_index(*cit, index_H, -1);
262 if ( (index_H == 0) || (index_H == quan.get_value_H_size() - 1) )
264 quan.set_unknown_index(*cit, index_H, -1);
271 return unknown_index;
283 template <
typename DeviceType,
typename SHEQuantity>
287 long unknown_offset = 0)
289 typedef typename DeviceType::mesh_type MeshType;
291 typedef typename viennagrid::result_of::const_facet_range<MeshType>::type FacetContainer;
292 typedef typename viennagrid::result_of::iterator<FacetContainer>::type FacetIterator;
296 FacetContainer facets(mesh);
300 if(quan.get_value_H_size() == 0 )
return 0;
301 int size = 1,rank = 0;
304 MPI_Comm_size(PETSC_COMM_WORLD,&size);
305 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
307 std::size_t maxquantityfull = quan.get_value_H_size();
308 std::size_t maxquantity = rank < size-1 ? ((rank+1)*maxquantityfull)/size+1:maxquantityfull ;
309 std::size_t init = ((rank)*maxquantityfull)/size;
310 long unknown_index = unknown_offset;
311 for (std::size_t index_H = init; index_H < maxquantity; ++index_H)
313 for (FacetIterator fit = facets.begin();
322 return unknown_index;
337 template<
typename DeviceT>
342 typedef typename map_info_type::value_type::second_type PairType;
346 long last_mapping_index = 0;
347 long current_mapping_index = 0;
357 map_info[quantities.
unknown_quantities()[i].get_name()] = PairType(std::size_t(current_mapping_index - last_mapping_index), 0);
359 last_mapping_index = current_mapping_index;
367 map_info[quantities.
unknown_she_quantities()[i].get_name()].first = std::size_t(current_mapping_index - last_mapping_index);
370 last_mapping_index = current_mapping_index;
373 long last_even_mapping_index = current_mapping_index;
376 map_info[quantities.
unknown_she_quantities()[i].get_name()].second = std::size_t(current_mapping_index - last_even_mapping_index);
387 map_info[quantities.
unknown_she_quantities()[i].get_name()].second = std::size_t(current_mapping_index - last_mapping_index);
388 last_mapping_index = current_mapping_index;
Common routines for the assembly of SHE equations.
The main SHE configuration class. To be adjusted by the user for his/her needs.
viennashe::physics::dispersion_proxy dispersion_relation(viennashe::carrier_type_id ctype) const
Returns the dispersion relation for electrons.
nonlinear_solver_config_type & nonlinear_solver()
Returns the configuration object for the nonlinear solver.
double max_kinetic_energy_range(viennashe::carrier_type_id ctype) const
Returns the minimum kinetic energy range for the selected carrier.
linear_solver_config_type & linear_solver()
Returns the configuration object for the linear solver.
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...
The main SHE simulator controller class. Acts as an accessor for all SHE quantities needed for the si...
UnknownSHEQuantityListType & unknown_she_quantities()
std::deque< UnknownQuantityType > & unknown_quantities()
long id() const
Returns the current linear solver ID.
long id() const
Returns the current linear solver ID.
bool get_unknown_mask(associated_type const &elem) const
boundary_type_id get_boundary_type(associated_type const &elem) const
void set_unknown_index(associated_type const &elem, long value)
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.
void map_cell(DeviceType const &device, CellType const &cell, std::size_t index_H, SHEQuantity &quan, viennashe::config const &conf, long ¤t_index)
Handles the mapping of a SHE unkown quantity on a single cell and H-space index.
void map_facet(DeviceType const &device, SHEQuantity &quan, viennashe::config const &conf, FacetType const &facet, std::size_t index_H, long ¤t_index)
Assigns an unknown index for odd SHE unknowns to a facet. Preconditions:
bool is_semiconductor(long material_id)
Convenience function for checking whether the supplied material ID refers to a semiconductor.
double averaged_density_of_states(SHEQuantity const &quan, viennashe::config::dispersion_relation_type const &dispersion, CellFacetType const &cell_facet, std::size_t index_H)
Returns the density of states around a vertex or an edge at total energy specified by index_H....
long even_unknowns_on_node(long L)
Returns the number of even spherical harmonics up to (including) order L.
The main ViennaSHE namespace. All functionality resides inside this namespace.
std::map< std::string, std::pair< std::size_t, std::size_t > > map_info_type
Information on the number of unknowns per quantity.
long create_odd_mapping(DeviceType const &device, SHEQuantity &quan, viennashe::config const &conf, long unknown_offset=0)
Distributes SHE unknown indices (dofs) over the device.
long create_even_mapping(DeviceType const &device, SHEQuantity &quan, viennashe::config const &conf, long unknown_offset=0)
Distributes SHE unknown indices (dofs) over the device.
long create_mapping(DeviceType const &device, viennashe::unknown_quantity< VertexT > &quantity, long start_index=0)
Maps unkown indices in the system matrix to the given unknown spatial quantity.
Defines a generic simulator quantity for use within the solvers of ViennaSHE.
@ petsc_parallel_linear_solver
gpu-assisted solver (block ILUT)
@ newton_nonlinear_solver
Gummel iteration.
A container of all quantities defined for a certain timestep t.