17 #pragma warning(disable:4503)
28#include "viennagrid/config/default_configs.hpp"
32template <
typename ValueType>
35 typedef ValueType value_type;
37 field_container(std::size_t size, value_type default_value = value_type()) : data_(size, default_value) {}
39 template <
typename ElementType>
40 value_type operator()(ElementType
const & elem)
const
42 return data_.at(std::size_t(elem.id().get()));
45 template <
typename ElementType>
46 void operator()(ElementType
const & elem, value_type val)
48 data_.at(std::size_t(elem.id().get())) = val;
51 std::vector<value_type>
const & container()
const {
return data_; }
53 std::vector<value_type> data_;
59template <
typename DeviceType>
60int test(DeviceType
const & device, std::string output_filename)
62 typedef typename DeviceType::mesh_type MeshType;
64 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
65 typedef typename viennagrid::result_of::facet<MeshType>::type FacetType;
66 typedef typename viennagrid::result_of::cell<MeshType>::type CellType;
68 typedef typename viennagrid::result_of::const_facet_range<MeshType>::type FacetContainer;
69 typedef typename viennagrid::result_of::iterator<FacetContainer>::type FacetIterator;
70 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
71 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
73 typedef typename viennagrid::result_of::const_facet_range<CellType>::type FacetOnCellContainer;
75 std::vector<double> reference_field(3);
76 reference_field[0] = 1.0;
77 reference_field[1] = 2.0;
78 reference_field[2] = 3.0;
80 MeshType
const & mesh = device.mesh();
85 std::cout <<
"Writing normal projections on box interfaces to facets..." << std::endl;
86 FacetContainer facets(mesh);
87 field_container<double> field_component_on_edge_container(facets.size());
89 for (FacetIterator fit = facets.begin();
93 typedef typename viennagrid::result_of::const_coboundary_range<MeshType, FacetType, CellType>::type CellOnFacetContainer;
96 CellOnFacetContainer cells_on_facet(mesh, viennagrid::handle(mesh, *fit));
103 double field_in_n = reference_field[0] * n[0];
104 if (PointType::dim >= 2)
105 field_in_n += reference_field[1] * n[1];
106 if (PointType::dim >= 3)
107 field_in_n += reference_field[2] * n[2];
108 field_component_on_edge_container(*fit, field_in_n);
115 std::cout <<
"Transferring from edges to vertices..." << std::endl;
116 CellContainer cells(mesh);
117 field_container<std::vector<double> > my_cell_field_container(cells.size(), std::vector<double>(PointType::dim));
119 for (CellIterator cit = cells.begin();
123 FacetOnCellContainer facets_on_cell(*cit);
126 *cit, facets_on_cell,
127 my_cell_field_container, field_component_on_edge_container);
129 std::vector<double> e_field(3);
130 e_field[0] = my_cell_field_container(*cit)[0];
131 if (PointType::dim >= 2)
132 e_field[1] = my_cell_field_container(*cit)[1];
133 if (PointType::dim >= 3)
134 e_field[2] = my_cell_field_container(*cit)[2];
139 double diff = (e_field[0] - reference_field[0]) * (e_field[0] - reference_field[0]);
140 if (PointType::dim >= 2)
141 diff += (e_field[1] - reference_field[1]) * (e_field[1] - reference_field[1]);
142 if (PointType::dim >= 3)
143 diff += (e_field[2] - reference_field[2]) * (e_field[2] - reference_field[2]);
144 if (std::abs(diff) > 1e-10)
146 std::cerr <<
"Test failed at cell " << *cit << std::endl;
147 std::cerr <<
"Diff: " << diff <<
", computed vector: (" << e_field[0] <<
", " << e_field[1] <<
", " << e_field[2] <<
")" << std::endl;
157 std::cout <<
"Writing to VTK..." << std::endl;
158 viennagrid::io::vtk_writer<MeshType> my_vtk_writer;
159 my_vtk_writer.add_vector_data_on_cells(viennagrid::make_accessor<CellType>(my_cell_field_container.container()),
"flux");
160 my_vtk_writer(mesh, output_filename);
173 typedef viennagrid::line_1d_mesh MeshType1d;
176 typedef viennagrid::triangular_2d_mesh MeshType2d;
179 typedef viennagrid::tetrahedral_3d_mesh MeshType3d;
182 std::cout <<
"* main(): Testing mesh in 1d..." << std::endl;
183 DeviceType1d device1d;
186 device1d.generate_mesh(generator_params);
188 if (test(device1d,
"quantity_transfer_1d") != EXIT_SUCCESS)
193 std::cout <<
"* main(): Testing mesh in 2d..." << std::endl;
194 DeviceType2d device2d;
195 device2d.load_mesh(
"../../examples/data/nin2d.mesh");
197 if (test(device2d,
"quantity_transfer_2d") != EXIT_SUCCESS)
201 std::cout <<
"* main(): Testing mesh in 3d..." << std::endl;
202 DeviceType3d device3d;
203 device3d.load_mesh(
"../../examples/data/half-trigate57656.mesh");
205 if (test(device3d,
"quantity_transfer_3d") != EXIT_SUCCESS)
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)
Convenience header, which includes all core functionality available in ViennaSHE.
VectorType::value_type norm_2(VectorType const &v)
void dual_box_flux_to_cell(DeviceT const &device, CellT const &cell, FacetContainerT const &facets, CellSetterT &cell_setter, FacetAccessorT const &facet_access)
Interpolates normal components of the flux defined on each facet to cells. Mostly used for visualizat...
viennagrid::result_of::point< viennagrid::element< CellTagT, WrappedConfigT > >::type outer_cell_normal_at_facet(viennagrid::element< CellTagT, WrappedConfigT > const &cell, viennagrid::element< FacetTagT, WrappedConfigT > const &facet)
Returns the unit outer normal of a facet with respect to the provided cell.