1#ifndef VIENNASHE_UTIL_TRANSLATE_QUANTITY_HPP
2#define VIENNASHE_UTIL_TRANSLATE_QUANTITY_HPP
23#include "viennagrid/forwards.hpp"
24#include "viennagrid/mesh/mesh.hpp"
25#include "viennagrid/algorithm/volume.hpp"
26#include "viennagrid/algorithm/inner_prod.hpp"
27#include "viennagrid/algorithm/centroid.hpp"
48 template <
typename WrappedConfigT>
49 typename viennagrid::result_of::point< viennagrid::element<viennagrid::line_tag,WrappedConfigT> >::type
51 viennagrid::element<viennagrid::vertex_tag, WrappedConfigT>
const & facet)
53 typedef typename viennagrid::result_of::point< viennagrid::element<viennagrid::line_tag,WrappedConfigT> >::type PointType;
55 PointType centroid_cell = viennagrid::centroid(cell);
56 PointType centroid_facet = viennagrid::centroid(facet);
58 if (centroid_cell[0] < centroid_facet[0])
59 return PointType(1.0);
60 return PointType(-1.0);
64 template <
typename CellTagT,
typename WrappedConfigT>
65 typename viennagrid::result_of::point< viennagrid::element<CellTagT, WrappedConfigT> >::type
67 viennagrid::element<viennagrid::line_tag, WrappedConfigT>
const & facet)
69 typedef viennagrid::element<viennagrid::line_tag, WrappedConfigT> FacetType;
70 typedef typename viennagrid::result_of::point<FacetType>::type PointType;
71 typedef typename viennagrid::result_of::const_vertex_range<FacetType>::type VertexRange;
73 VertexRange facet_vertices(facet);
74 PointType facet_vec = viennagrid::point(facet_vertices[1]) - viennagrid::point(facet_vertices[0]);
75 PointType facet_centroid_vec = viennagrid::centroid(cell) - viennagrid::point(facet_vertices[0]);
77 PointType edge_normal(facet_vec[1], -facet_vec[0]);
79 if (viennagrid::inner_prod(facet_centroid_vec, edge_normal) > 0)
82 return edge_normal / viennagrid::norm(edge_normal);
86 template <
typename CellTagT,
typename FacetTagT,
typename WrappedConfigT>
87 typename viennagrid::result_of::point< viennagrid::element<CellTagT, WrappedConfigT> >::type
89 viennagrid::element<FacetTagT, WrappedConfigT>
const & facet)
91 typedef viennagrid::element<FacetTagT, WrappedConfigT> FacetType;
92 typedef typename viennagrid::result_of::point<FacetType>::type PointType;
93 typedef typename viennagrid::result_of::const_vertex_range<FacetType>::type VertexRange;
95 VertexRange facet_vertices(facet);
96 PointType facet_vec1 = viennagrid::point(facet_vertices[1]) - viennagrid::point(facet_vertices[0]);
97 PointType facet_vec2 = viennagrid::point(facet_vertices[2]) - viennagrid::point(facet_vertices[0]);
98 PointType facet_centroid_vec = viennagrid::centroid(cell) - viennagrid::point(facet_vertices[0]);
100 PointType edge_normal = viennagrid::cross_prod(facet_vec1, facet_vec2);
102 if (viennagrid::inner_prod(facet_centroid_vec, edge_normal) > 0)
105 return edge_normal / viennagrid::norm(edge_normal);
109 template <
typename CellTagT,
typename WrappedConfigT>
110 typename viennagrid::result_of::point< viennagrid::element<CellTagT, WrappedConfigT> >::type
112 viennagrid::element<viennagrid::triangle_tag, WrappedConfigT>
const & facet)
118 template <
typename CellTagT,
typename WrappedConfigT>
119 typename viennagrid::result_of::point< viennagrid::element<CellTagT, WrappedConfigT> >::type
121 viennagrid::element<viennagrid::quadrilateral_tag, WrappedConfigT>
const & facet)
130 template <
typename CellTagT,
typename FacetTagT,
typename WrappedConfigT>
131 typename viennagrid::result_of::point< viennagrid::element<CellTagT,WrappedConfigT> >::type
133 viennagrid::element<FacetTagT, WrappedConfigT>
const & facet)
149 template <
typename DeviceT,
typename CellT,
typename FacetContainerT,
typename CellSetterT,
typename FacetAccessorT>
151 CellT
const & cell, FacetContainerT
const & facets,
152 CellSetterT & cell_setter, FacetAccessorT
const & facet_access)
154 typedef typename viennagrid::result_of::iterator<FacetContainerT>::type FacetOnCellIterator;
155 typedef typename DeviceT::mesh_type MeshType;
156 typedef typename FacetOnCellIterator::value_type FacetType;
157 typedef typename viennagrid::result_of::point<CellT>::type PointType;
159 typedef typename viennagrid::result_of::const_coboundary_range<MeshType, FacetType, CellT>::type CellOnFacetContainer;
160 int N = PointType::dim;
162 std::vector<double> b(N);
164 std::vector<PointType> normals(facets.size());
165 std::vector<double> flux_contributions(facets.size());
168 std::size_t facet_ctr = 0;
169 for (FacetOnCellIterator focit = facets.begin();
170 focit != facets.end();
171 ++focit, ++facet_ctr )
173 flux_contributions[facet_ctr] = facet_access(*focit);
178 if (&cells_on_facet[0] != &cell)
179 flux_contributions[facet_ctr] *= -1.0;
183 for ( std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i )
185 for ( std::size_t j = 0; j < static_cast<std::size_t>(PointType::dim); ++j )
187 for ( std::size_t k = 0; k < normals.size(); ++k )
188 M(i, j) += normals[k][i] * normals[k][j];
190 for ( std::size_t k = 0; k < normals.size(); ++k )
191 b[i] += normals[k][i] * flux_contributions[k];
194 std::vector<double> to_value(PointType::dim);
197 for (std::size_t i=0; i<result.size(); ++i)
198 to_value[i] = result[i];
200 cell_setter(cell, to_value);
211 template <
typename DeviceType,
typename CellSetter,
typename FacetAccessor>
214 typedef typename DeviceType::mesh_type MeshType;
215 typedef typename viennagrid::result_of::cell<MeshType>::type CellType;
217 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
218 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
220 typedef typename viennagrid::result_of::const_facet_range<CellType>::type FacetOnCellContainer;
223 for (CellIterator cit = cells.begin();
227 FacetOnCellContainer facets(*cit);
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...
Defines several filter functors for the device. A filter functor returns true if the supplied argumen...
Contains forward declarations and definition of small classes that must be defined at an early stage.
Implementation of various utilities related to linear algebra.
A logging facility providing fine-grained control over logging in ViennaSHE.
std::vector< double > solve(viennashe::math::sparse_matrix< double > &A, std::vector< double > const &b, linear_solver_config const &config)
Public interface for solving a system of linear equations represented using a sparse matrix.
viennagrid::result_of::point< viennagrid::element< CellTagT, WrappedConfigT > >::type outer_cell_normal_at_facet_3d(viennagrid::element< CellTagT, WrappedConfigT > const &cell, viennagrid::element< FacetTagT, WrappedConfigT > const &facet)
viennagrid::result_of::point< viennagrid::element< viennagrid::line_tag, WrappedConfigT > >::type outer_cell_normal_at_facet(viennagrid::element< viennagrid::line_tag, WrappedConfigT > const &cell, viennagrid::element< viennagrid::vertex_tag, WrappedConfigT > const &facet)
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.
The main ViennaSHE namespace. All functionality resides inside this namespace.
Provides a number of fundamental constants. All constants in SI units.
Forward declarations for a generic solver layer, providing bindings to a native Gauss solver,...