28 template <
typename DeviceT >
29 void get_vertices_on_cell(DeviceT
const & device,
34 typedef typename DeviceT::mesh_type MeshType;
35 typedef typename viennagrid::result_of::cell<MeshType>::type CellType;
36 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
37 typedef typename viennagrid::result_of::const_vertex_range<CellType>::type VertexOnCellContainer;
38 typedef typename viennagrid::result_of::iterator<VertexOnCellContainer>::type VertexOnCellIterator;
40 CellContainer cells(device.mesh());
42 if (vertex_ids == 0)
throw std::invalid_argument(
"vertices = NULL !");
43 if ( cell_id >= cells.size())
throw std::invalid_argument(
"cell_id invalid !");
46 VertexOnCellContainer vertices_on_cell(cells[cell_id]);
48 for (VertexOnCellIterator vit = vertices_on_cell.begin(); vit != vertices_on_cell.end(); ++vit, ++j)
63 template <
typename DeviceT >
64 void initalize_device(DeviceT & device,
long * material_ids,
double * doping_n,
double * doping_p)
66 typedef typename DeviceT::mesh_type MeshType;
68 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
70 CellContainer cells = viennagrid::cells(device.mesh());
72 for (std::size_t i = 0; i < cells.size(); ++i)
74 device.set_material(material_ids[i], cells[i]);
78 viennashe::log::warn() <<
"initalize_device(): Warning! The donor doping must be greater zero. doping_n[" << i <<
"] = " << doping_n[i] << std::endl;
80 else if (doping_p[i] < 0)
82 viennashe::log::warn() <<
"initalize_device(): Warning! The acceptor doping must be greater zero. doping_p[" << i <<
"] = " << doping_p[i] << std::endl;
87 if (doping_n[i]) device.set_doping_n(doping_n[i], cells[i]);
88 if (doping_p[i]) device.set_doping_p(doping_p[i], cells[i]);
101 template <
typename DeviceT >
104 typedef typename DeviceT::mesh_type MeshType;
106 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
108 CellContainer cells(device.mesh());
110 for (std::size_t i = 0; i < len; ++i)
113 if (
id < cells.size())
114 device.set_contact_potential(values[i], cells[
id] );
116 viennashe::log::warn() <<
"WARNING! set_contact_potential(): Invalid cell id '" <<
id <<
"' ... skipping!" << std::endl;
127 template <
typename DeviceT >
130 if (segment_id < device.segmentation().size())
131 device.set_contact_potential(value, device.segment(
static_cast<int>(segment_id)));
133 viennashe::log::warn() <<
"WARNING! set_contact_potential(): Invalid segment id '" << segment_id <<
"' ... skipping!" << std::endl;
208 if (doping_n == 0 || doping_p == 0 || material_ids == 0)
210 viennashe::log::error() <<
"ERROR! initalize_device(): The arrays material_ids, doping_n and doping_p must be arrays " << std::endl;
222 switch (int_dev->
stype)
251 viennashe::log::error() <<
"ERROR! viennashe_set_material_on_segment(): The material_id needs to be greater zero. material_id = " << material_id << std::endl;
259 viennashe::log::error() <<
"ERROR! viennashe_set_material_on_segment(): The device must exist!" << std::endl;
263 switch (int_dev->
stype)
292 viennashe::log::error() <<
"ERROR! viennashe_set_doping_n_on_segment(): The doping_n needs to be greater zero. doping_n = " << doping_n << std::endl;
300 viennashe::log::error() <<
"ERROR! viennashe_set_doping_n_on_segment(): The device must exist!" << std::endl;
304 switch (int_dev->
stype)
312 viennashe::log::error() <<
"ERROR! viennashe_set_doping_n_on_segment(): UNKOWN DEVICE TYPE!" << std::endl;
334 viennashe::log::error() <<
"ERROR! viennashe_set_doping_p_on_segment(): The doping_p needs to be greater zero. doping_p = " << doping_p << std::endl;
342 viennashe::log::error() <<
"ERROR! viennashe_set_doping_p_on_segment(): The device must exist!" << std::endl;
346 switch (int_dev->
stype)
354 viennashe::log::error() <<
"ERROR! viennashe_set_doping_p_on_segment(): UNKOWN DEVICE TYPE!" << std::endl;
385 switch (int_dev->
stype)
399 viennashe::log::error() <<
"ERROR! viennashe_set_contact_potential_cells(): UNKOWN ERROR!" << std::endl;
421 switch (int_dev->
stype)
643 viennashe::log::error() <<
"ERROR! viennashe_get_num_vertices_per_cell(): UNKOWN ERROR!" << std::endl;
766 viennashe::log::error() <<
"ERROR! viennashe_create_device_flat(): Invalid topolgy id !" << std::endl;
826 viennashe::log::error() <<
"ERROR! viennashe_create_device_from_file(): Invalid topolgy id !" << std::endl;
834 catch(std::exception
const & ex)
856 viennashe::log::error() <<
"ERROR! viennashe_get_grid(): Mesh must exist (dev != NULL) "<< std::endl;
859 if (num_vertices == NULL || vertices == NULL)
861 viennashe::log::error() <<
"ERROR! viennashe_get_grid(): num_vertices must be valid. num_vertices = "
862 << num_vertices <<
" and vertices = " << vertices << std::endl;
868 <<
num_cells <<
" and cells = " << cells << std::endl;
895 viennashe::log::error() <<
"ERROR! viennashe_get_grid(): Unkown topology type or malconfigured device (dev)!" << std::endl;
922 if (
static_cast<long>(vid) < 0 || vid >= num_vertices)
924 viennashe::log::error() <<
"ERROR! viennashe_get_nth_vertex(): The given index id (vid) must not be smaller 0 or greater " << num_vertices << std::endl;
928 *x = 0; *y = 0; *z = 0;
934 typedef viennagrid::result_of::const_vertex_range<MeshType>::type VertexContainer;
936 VertexContainer vertices((
dev->device_1d)->mesh());
937 *x = viennagrid::point(vertices[vid])[0];
942 typedef viennagrid::result_of::const_vertex_range<MeshType>::type VertexContainer;
944 VertexContainer vertices((
dev->device_quad_2d)->mesh());
945 *x = viennagrid::point(vertices[vid])[0];
946 *y = viennagrid::point(vertices[vid])[1];
951 typedef viennagrid::result_of::const_vertex_range<MeshType>::type VertexContainer;
953 VertexContainer vertices((
dev->device_tri_2d)->mesh());
954 *x = viennagrid::point(vertices[vid])[0];
955 *y = viennagrid::point(vertices[vid])[1];
960 typedef viennagrid::result_of::const_vertex_range<MeshType>::type VertexContainer;
962 VertexContainer vertices((
dev->device_hex_3d)->mesh());
963 *x = viennagrid::point(vertices[vid])[0];
964 *y = viennagrid::point(vertices[vid])[1];
965 *z = viennagrid::point(vertices[vid])[2];
970 typedef viennagrid::result_of::const_vertex_range<MeshType>::type VertexContainer;
972 VertexContainer vertices((
dev->device_tet_3d)->mesh());
973 *x = viennagrid::point(vertices[vid])[0];
974 *y = viennagrid::point(vertices[vid])[1];
975 *z = viennagrid::point(vertices[vid])[2];
979 viennashe::log::error() <<
"ERROR! viennashe_get_nth_vertex(): Unkown topology type or malconfigured device (dev)!" << std::endl;
1002 if (
static_cast<long>(cid) < 0 || cid >=
num_cells)
1004 viennashe::log::error() <<
"ERROR! viennashe_get_nth_vertex(): The given index id (cid) must not be smaller 0 or greater " <<
num_cells << std::endl;
1011 libviennashe::get_vertices_on_cell(*(
dev->device_1d), cid, vertex_id_list);
1015 libviennashe::get_vertices_on_cell(*(
dev->device_quad_2d), cid, vertex_id_list);
1019 libviennashe::get_vertices_on_cell(*(
dev->device_tri_2d), cid, vertex_id_list);
1023 libviennashe::get_vertices_on_cell(*(
dev->device_hex_3d), cid, vertex_id_list);
1027 libviennashe::get_vertices_on_cell(*(
dev->device_tet_3d), cid, vertex_id_list);
1031 viennashe::log::error() <<
"ERROR! viennashe_get_nth_vertex(): Unkown topology type or malconfigured device (dev)!" << std::endl;
void generate_mesh(viennashe::util::device_generation_config const &generator_params)
void set_material(long material_id, cell_type const &elem)
Sets the material ID on a cell.
void load_mesh(std::string filename)
segmentation_type const & segmentation() const
void set_doping_p(double value, cell_type const &c)
Sets the acceptor doping (in m^-3) in the specified cell.
MeshT const & mesh() const
Returns the underlying mesh.
void set_doping_n(double value, cell_type const &c)
Sets the donator doping (in m^-3) in the specified cell.
Defines the physical properties of a device, e.g. doping. This is the implementation for 2d and highe...
Configuration class for the simple mesh generator.
void add_segment(double start_x, double start_y, double len_x, double len_y, unsigned long points_x, unsigned long points_y)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_vertices(viennashe_device dev, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_segments(viennashe_device dev, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_device_flat(viennashe_device *dev, viennashe_topology_type_id topology_id, double *vertices, viennashe_index_type num_vertices, viennashe_index_type *cells, viennashe_index_type num_cells, viennashe_index_type *segmentation)
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_device(viennashe_device dev)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_contact_potential_cells(viennashe_device dev, viennashe_index_type *cell_ids, double *values, viennashe_index_type len)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_1d_device(viennashe_device *dev, double len_x, size_t points_x)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_nth_cell(viennashe_device dev, viennashe_index_type cid, viennashe_index_type *vertex_id_list)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_grid(viennashe_device dev, double **vertices, viennashe_index_type *num_vertices, viennashe_index_type **cells, viennashe_index_type *num_cells)
viennashe_topology_type_id
Enum of available toplogical mesh configurations.
@ viennashe_quadrilateral_2d
@ viennashe_hexahedral_3d
@ viennashe_tetrahedral_3d
@ viennashe_triangular_2d
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_contact_potential_segment(viennashe_device dev, double value, viennashe_index_type segment_id)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_cells(viennashe_device dev, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_doping_p_on_segment(viennashe_device dev, double doping_p, viennashe_index_type segment_id)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_vertices_on_segment(viennashe_device dev, viennashe_index_type segment_id, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_doping_n_on_segment(viennashe_device dev, double doping_n, viennashe_index_type segment_id)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_dimension(viennashe_device dev, viennashe_index_type *dim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_initalize_device(viennashe_device dev, viennashe_material_id *material_ids, double *doping_n, double *doping_p)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_vertices_per_cell(viennashe_device dev, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_nth_vertex(viennashe_device dev, viennashe_index_type vid, double *x, double *y, double *z)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_device(viennashe_device *dev, viennashe_topology_type_id topology_id, double **vertices, viennashe_index_type num_vertices, viennashe_index_type **cells, viennashe_index_type num_cells, viennashe_index_type *segmentation)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_material_on_segment(viennashe_device dev, viennashe_material_id material_id, viennashe_index_type segment_id)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_device_from_file(viennashe_device *dev, viennashe_topology_type_id topology_id, char const *filename)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_cells_on_segment(viennashe_device dev, viennashe_index_type segment_id, viennashe_index_type *num)
Contains a very simple mesh generator (ortho-grids) for one and two spatial dimensions.
long viennashe_material_id
The internal C++ namespace of the library.
logger< true > error()
Used to log errors. The logging level is logERROR.
logger< true > warn()
Used to log warnings. The logging level is logWARNING.
void dump_mesh(DeviceT const &device, double **vertices, IndexT &num_vertices, IndexT **cells, IndexT &num_cells)
A device generator to generate a device from C-Arrays (DOES NOT TAKE OWNERSHIP)
A device generator to generate a device from flat C-Arrays (DOES NOT TAKE OWNERSHIP)
Internal C++ to C wrapper for the device. Has typedefs and destructor.
devq2d_type * device_quad_2d
devt2d_type * device_tri_2d
devh3d_type * device_hex_3d
devt3d_type * device_tet_3d
struct viennashe_device_impl viennashe_device_impl
Device implementation type.
unsigned long viennashe_index_type
Contains all viennashe includes and most of the C++/C-wrappers. Contains macros.
#define CHECK_ARGUMENT_FOR_NULL(arg, pos, name)