1#ifndef VIENNASHE_DEVICE_HPP
2#define VIENNASHE_DEVICE_HPP
24#include "viennagrid/forwards.hpp"
25#include "viennagrid/mesh/mesh.hpp"
26#include "viennagrid/algorithm/norm.hpp"
27#include "viennagrid/algorithm/refine.hpp"
28#include "viennagrid/algorithm/geometric_transform.hpp"
29#include "viennagrid/io/netgen_reader.hpp"
30#include "viennagrid/io/vtk_reader.hpp"
53 template<
typename MeshT>
59 typedef typename viennagrid::result_of::vertex<MeshT>::type
vertex_type;
60 typedef typename viennagrid::result_of::point<MeshT>::type
point_type;
66 typedef typename viennagrid::result_of::facet<MeshT>::type
facet_type;
67 typedef typename viennagrid::result_of::cell<MeshT>::type
cell_type;
68 typedef typename viennagrid::result_of::accessor_container<
cell_type,
71 typedef typename viennagrid::result_of::segment_handle<segmentation_type>::type
segment_type;
72 typedef typename viennagrid::result_of::segmentation_segment_id_type<
79 typedef typename viennagrid::result_of::voronoi_cell_contribution<
86 return static_cast<std::size_t
> (cell.id ().get ());
98 if (filename.size () > 5
99 && filename.substr (filename.size () - 5) ==
".mesh")
101 viennagrid::io::netgen_reader my_reader;
104 else if (filename.size () > 4
105 && (filename.substr (filename.size () - 4) ==
".vtu"
106 || filename.substr (filename.size () - 4) ==
".pvd"))
108 viennagrid::io::vtk_reader<MeshT> mesh_reader;
113 throw std::runtime_error (
"Unknown file extension!");
116 init_datastructures ();
119 template<
typename DeviceLoaderType>
124 init_datastructures ();
132 init_datastructures ();
135 template<
typename MeshGeneratorType>
140 init_datastructures ();
175 viennagrid::scale (
mesh_, factor);
176 init_datastructures ();
182 MeshT mesh_refined,mesh_refined_temp;
185 int cellsize = viennagrid::cells (
mesh_).size ();
186 long unsigned int finalcellsize = factor * cellsize;
188 typename viennagrid::result_of::field< CellRefinementContainerType,cell_type >::type cell_refinement_field(cell_refinement_flag);
189 mesh_refined =
mesh_;
190 std::cout <<
"* Size of mesh:" <<cellsize <<std::endl;
191 std::cout <<
"* Size of mesh:" <<finalcellsize <<std::endl;
195 typename viennagrid::result_of::field< CellRefinementContainerType,cell_type >::type cell_refinement_field(cell_refinement_flag);
196 for(
int i =ibegin;i<ibegin+700;i+=2)
197 cell_refinement_field( viennagrid::cells(mesh_refined)[i] ) =
true;
198 viennagrid::cell_refine(mesh_refined,
seg_, mesh_refined_temp,seg_temp, cell_refinement_field);
199 for(
int i =ibegin;i<ibegin+700;i+=2)
200 cell_refinement_field( viennagrid::cells(mesh_refined)[i] ) =
false;
201 mesh_refined = mesh_refined_temp;
203 std::cout <<
"* Size of mesh:" <<viennagrid::cells (mesh_refined).size() <<std::endl;
205 }
while(finalcellsize > viennagrid::cells ( mesh_refined).size() );}
209 typename viennagrid::result_of::field< CellRefinementContainerType,cell_type >::type cell_refinement_field(cell_refinement_flag);
210 for(
int i =ibegin;i< cellsize;i+=2)
211 cell_refinement_field( viennagrid::cells(mesh_refined)[i] ) =
true;
212 viennagrid::cell_refine(mesh_refined,
seg_, mesh_refined_temp,seg_temp, cell_refinement_field);
213 for(
int i =ibegin;i< cellsize;i+=2)
214 cell_refinement_field( viennagrid::cells(mesh_refined)[i] ) =
false;
215 mesh_refined = mesh_refined_temp;
217 std::cout <<
"* Size of mesh:" <<viennagrid::cells (mesh_refined).size() <<std::endl;
219 }
while(finalcellsize > viennagrid::cells ( mesh_refined).size() );
222 mesh_ = mesh_refined;
224 init_datastructures ();
260 "get_lattice_temp_impl(): Accessing non-positive temperature from cell!"));
267 typedef typename viennagrid::result_of::const_coboundary_range<MeshT,
269 typedef typename viennagrid::result_of::iterator<CellOnFacetContainer>::type CellOnFacetIterator;
271 CellOnFacetContainer cells_on_facet (
274 CellOnFacetIterator cofit = cells_on_facet.begin ();
278 if (cofit == cells_on_facet.end ())
328 typedef typename viennagrid::result_of::const_coboundary_range<MeshT,
330 typedef typename viennagrid::result_of::iterator<CellOnFacetContainer>::type CellOnFacetIterator;
332 CellOnFacetContainer cells_on_facet (
335 CellOnFacetIterator cofit = cells_on_facet.begin ();
339 if (cofit == cells_on_facet.end ())
357 std::vector<double>
const&
401 typedef typename viennagrid::result_of::const_coboundary_range<MeshT,
403 typedef typename viennagrid::result_of::iterator<CellOnFacetContainer>::type CellOnFacetIterator;
405 CellOnFacetContainer cells_on_facet (
408 CellOnFacetIterator cofit = cells_on_facet.begin ();
412 if (cofit == cells_on_facet.end ())
430 std::vector<double>
const&
454 template<
typename MaterialType>
477 template<
typename MaterialType>
493 template<
typename MaterialType>
507 std::vector<material_id_type>
const&
520 init_datastructures ()
528 viennagrid::cells (
mesh_).size ());
552 typedef typename viennagrid::result_of::const_cell_range<segment_type>::type CellOnSegmentContainer;
553 typedef typename viennagrid::result_of::iterator<
554 CellOnSegmentContainer>::type CellOnSegmentIterator;
556 CellOnSegmentContainer cells_on_segment (seg);
557 for (CellOnSegmentIterator cit = cells_on_segment.begin ();
558 cit != cells_on_segment.end (); ++cit)
571 "Accessing potential from vertex for which no contact potential was set!"));
624 for (std::size_t i = 0; i <
cell_traps_.size (); ++i)
664 template<
typename MeshOrSegmentT>
668 typedef typename viennagrid::result_of::const_cell_range<
669 MeshOrSegmentT>::type CellContainer;
670 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
674 "device.set_lattice_temp*: Lattice temperatures have to be greater 0 K!",
678 CellContainer cells (meshseg);
679 for (CellIterator cit = cells.begin (); cit != cells.end (); ++cit)
695 "device.set_doping_p_impl(): Concentrations have to be greater 0 !",
707 "device.set_doping_p_impl(): Concentrations have to be greater 0 !",
713 template<
typename MeshOrSegmentT>
717 typedef typename viennagrid::result_of::const_cell_range<
718 MeshOrSegmentT>::type CellContainer;
719 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
724 "device.set_doping*: Concentrations have to be greater 0 !",
727 CellContainer cells (meshseg);
728 for (CellIterator cit = cells.begin (); cit != cells.end (); ++cit)
734 template<
typename MeshOrSegmentT>
738 typedef typename viennagrid::result_of::const_cell_range<
739 MeshOrSegmentT>::type CellContainer;
740 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
745 "device.set_doping*: Concentrations have to be greater 0 !",
748 CellContainer cells (meshseg);
749 for (CellIterator cit = cells.begin (); cit != cells.end (); ++cit)
759 template<
typename MeshOrSegmentT>
762 MeshOrSegmentT
const &meshseg)
764 typedef typename viennagrid::result_of::const_cell_range<
765 MeshOrSegmentT>::type CellContainer;
766 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
769 CellContainer cells (meshseg);
770 for (CellIterator cit = cells.begin (); cit != cells.end (); ++cit)
778 template<
typename MeshOrSegmentT>
781 MeshOrSegmentT
const &meshseg)
783 typedef typename viennagrid::result_of::const_cell_range<
784 MeshOrSegmentT>::type CellContainer;
785 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
787 CellContainer cells (meshseg);
788 for (CellIterator cit = cells.begin (); cit != cells.end (); ++cit)
816 template<
typename MeshT,
bool edges_and_cells_different >
Contains the definition of per-device accessors (read-only!) for various quantities.
Defines the physical properties of a device, e.g. doping.
double get_doping(cell_type const &c, carrier_type_id ctype) const
void generate_mesh(viennashe::util::device_generation_config const &generator_params)
std::vector< bool > cell_contact_potential_mask_
void set_material(long material_id, cell_type const &elem)
Sets the material ID on a cell.
void load_device(DeviceLoaderType &loader)
viennagrid::result_of::vertex< MeshT >::type vertex_type
void set_material(MaterialType)
Sets a uniform material type using the structs defined in viennashe::materials on the whole device.
viennagrid::result_of::segment_handle< segmentation_type >::type segment_type
double get_doping_p(facet_type const &facet) const
void add_trap_level(trap_level_type trap, cell_type const &cell)
Adds a trap (density, energy) to a cell of the device.
void load_mesh(std::string filename)
void set_doping_p_impl(double value, cell_type const &c)
void set_doping_n_impl(double value, MeshOrSegmentT const &meshseg)
segmentation_type & segmentation()
bool has_contact_potential(cell_type const &c) const
Returns true if a contact potential has been set for the respective vertex.
std::vector< double > cell_doping_n_
double get_lattice_temperature(cell_type const &c) const
Returns the lattice temperature on a cell.
void scale(double factor)
bool has_contact_potential(facet_type const &) const
void add_trap_level(trap_level_type trap)
Adds a trap (density, energy) to the whole device.
void set_material(long material_id)
Sets a uniform material ID on the whole device.
void set_material(long material_id, segment_type const &seg)
Sets the material ID on a segment.
viennagrid::result_of::segmentation< MeshT >::type segmentation_type
void set_lattice_temperature(double new_value, segment_type const &s)
Sets the lattice temperature on a segment.
void set_doping_n(double value)
Sets the donator doping (in m^-3) in the whole device.
void set_lattice_temperature(double new_value, cell_type const &c)
Sets the lattice temperature at a cell.
segmentation_type const & segmentation() const
viennagrid::result_of::point< MeshT >::type point_type
viennagrid::result_of::voronoi_cell_contribution< const_cell_handle_type >::type voronoi_contribution_container_type
std::vector< double > cell_fixed_charges_
void set_doping_p_impl(double value, MeshOrSegmentT const &meshseg)
void add_trap_level_on_complex(trap_level_type trap, MeshOrSegmentT const &meshseg)
double get_doping_p(cell_type const &c) const
Returns the donator doping (in m^-3) in the specified cell.
void set_lattice_temperature(double new_value)
Sets the homogeneous temperature of the device.
long get_material(cell_type const &elem) const
Returns the material id of the provided cell.
std::vector< double > cell_temperature_
double get_lattice_temperature(facet_type const &facet) const
void clear_traps()
Removes all traps from the device.
void set_fixed_charge(cell_type const &c, double charge)
Sets a fixed charge at a cell.
void set_contact_potential(double pot, cell_type const &c)
Sets the contact potential at a cell.
segment_type const & segment(segment_id_type id) const
std::vector< trap_level_container_type > cell_traps_
void set_material(MaterialType, cell_type const &elem)
Sets the material type using the structs defined in viennashe::materials on a cell.
std::vector< double > const & doping_p() const
void set_material_on_complex(long material_id, MeshOrSegmentT const &meshseg)
std::vector< double > cell_contact_potential_
void set_doping_p(double value, cell_type const &c)
Sets the acceptor doping (in m^-3) in the specified cell.
viennagrid::result_of::cell< MeshT >::type cell_type
viennagrid::result_of::const_cell_handle< MeshT >::type const_cell_handle_type
std::vector< material_id_type > const & material() const
void set_material(MaterialType, segment_type const &seg)
Sets the material type using the structs defined in viennashe::materials on a segment.
MeshT const & mesh() const
Returns the underlying mesh.
double get_doping_n(cell_type const &c) const
Returns the donator doping (in m^-3) in the specified cell.
void set_lattice_temp_impl(double value, cell_type const &c)
viennagrid::result_of::facet< MeshT >::type facet_type
void set_doping_n_impl(double value, cell_type const &c)
double get_contact_potential(cell_type const &c) const
Returns the contact potential at a given cell (this is the externally applied voltage not considering...
void set_material(long material_id, segment_id_type id)
Sets the material ID on a segment.
trap_level_container_type const & get_trap_levels(cell_type const &cell) const
Returns all the trap levels defined for the provided cell.
void set_doping_n(double value, cell_type const &c)
Sets the donator doping (in m^-3) in the specified cell.
void set_doping_p(double value)
Sets the acceptor doping (in m^-3) in the whole device.
trap_level trap_level_type
void set_doping_n(double value, segment_id_type const &seg_id)
Sets the donator doping (in m^-3) in the specified segment.
std::vector< double > const & doping_n() const
void generate_mesh(MeshGeneratorType const &gen)
void add_trap_level(trap_level_type trap, segment_type const &seg)
Adds a trap (density, energy) to a segment of the device.
void set_contact_potential(double pot, segment_type const &seg)
Sets a contact potential for a whole segment.
double get_doping_n(facet_type const &facet) const
void set_doping_n(double value, segment_type const &d)
Sets the donator doping (in m^-3) in the specified segment.
viennagrid::result_of::segmentation_segment_id_type< segmentation_type >::type segment_id_type
void set_lattice_temp_impl(double value, MeshOrSegmentT const &meshseg)
std::vector< double > cell_doping_p_
viennagrid::result_of::accessor_container< cell_type, bool, viennagrid::std_vector_tag >::type CellRefinementContainerType
std::vector< trap_level_type > trap_level_container_type
void set_doping_p(double value, segment_type const &d)
Sets the acceptor doping (in m^-3) in the specified segment.
std::vector< material_id_type > cell_material_
void set_doping_p(double value, segment_id_type const &seg_id)
Sets the donator doping (in m^-3) in the specified segment.
double get_fixed_charge(cell_type const &c) const
Gives the fixed charge set at a certain cell.
Defines the physical properties of a device, e.g. doping. This is the implementation for 2d and highe...
Exception for the case that an invalid value (depends on the method called) is encountered.
Configuration class for the simple mesh generator.
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.
Contains a very simple mesh generator (ortho-grids) for one and two spatial dimensions.
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.
void generate_device(MeshT &mesh, SegmentationT &seg, device_generation_config const &conf)
Public interface for mesh generation of simple one- or two-dimensional meshes. Device must be rectang...
The main ViennaSHE namespace. All functionality resides inside this namespace.
carrier_type_id
Enumeration type for selecting the carrier type.
Provides a number of fundamental constants. All constants in SI units.
Contains the definition of convenience functors for accessing device quantities (see class device)....
Contains the definition of a trap level.