Chi-Tech
assemble_utils_plwd.cc
Go to the documentation of this file.
1#include "diffusion_solver.h"
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7
8/**Still searching for a reference for this.
9 *
10 * For Polygons:
11 * Defined from paper \n
12 * Turcksin B, Ragusa J, "Discontinuous diffusion synthetic acceleration
13 * for S_n transport on 2D arbitrary polygonal meshes", Journal of
14 * Computational Physics 274, pg 356-369, 2014.\n
15 * \n
16 * Nv = Number of vertices. If Nv <= 4 then the perimeter parameter
17 * should be replaced by edge length.*/
20 const UnitIntegralContainer& fe_intgrl_values,
21 unsigned int f)
22{
23 double hp=1.0;
24
25 size_t Nf = cell.faces_.size();
26 size_t Nv = cell.vertex_ids_.size();
27
28 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLAB
29 if (cell.Type() == chi_mesh::CellType::SLAB)
30 {
31 const auto& v0 = grid_ptr_->vertices[cell.vertex_ids_[0]];
32 const auto& v1 = grid_ptr_->vertices[cell.vertex_ids_[1]];
33
34 hp = (v1-v0).Norm()/2.0;
35 }
36 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% POLYGON
37 else if (cell.Type() == chi_mesh::CellType::POLYGON)
38 {
39// Nv = 4;
40 const chi_mesh::CellFace& face = cell.faces_[f];
41
42 uint64_t v0i = face.vertex_ids_[0];
43 uint64_t v1i = face.vertex_ids_[1];
44
45 const auto& v0 = grid_ptr_->vertices[v0i];
46 const auto& v1 = grid_ptr_->vertices[v1i];
47
48 double perimeter = (v1 - v0).Norm();
49
50 double area = 0.0;
51 for (int i=0; i<fe_intgrl_values.NumNodes(); i++)
52 area += fe_intgrl_values.IntV_shapeI(i);
53
54 hp = area/perimeter;
55
56// if (Nv == 3)
57// hp = 2*area/perimeter;
58// else if (Nv == 4)
59// hp = area/perimeter;
60// else //Nv > 4
61// {
62// if (Nv%2 == 0)
63// hp = 4*area/perimeter;
64// else
65// {
66// hp = 2*area/perimeter;
67// hp += sqrt(2*area / Nv*sin(2*M_PI/Nv));
68// }
69// }
70 }
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% POLYHEDRON
72 else if (cell.Type() == chi_mesh::CellType::POLYHEDRON)
73 {
74 double volume = 0.0;
75 for (int i=0; i<fe_intgrl_values.NumNodes(); i++)
76 volume += fe_intgrl_values.IntV_shapeI(i);
77
78 double area = 0.0;
79 for (int fr=0; fr<Nf; fr++)
80 for (int i=0; i<Nv; i++)
81 area += fe_intgrl_values.IntS_shapeI(fr, i);
82
83 if (Nf == 4) //Tet
84 hp = 3*volume/area;
85 else if (Nf == 6 && Nv == 8) //Hex
86 hp = volume/area;
87 else //Polyhedron
88 hp = 6*volume/area;
89 }//Polyhedron
90 else
91 {
93 << "Unsupported cell type in call to HPerpendicular";
94 Chi::Exit(EXIT_FAILURE);
95 }
96
97
98 return hp;
99}
100
101/**Given a global node index, returns the local cell-node it's associated on the
102 * referenced cell.*/
105 uint64_t node_global_id)
106{
107 size_t imap = 0;
108 bool map_found = false;
109 for (size_t ai=0; ai < cell.vertex_ids_.size(); ai++)
110 {
111 if (node_global_id == cell.vertex_ids_[ai])
112 {
113 imap = ai;
114 map_found = true;
115 break;
116 }
117 }
118
119 if (not map_found)
120 throw std::logic_error(std::string(__FUNCTION__)+": Mapping failure.");
121
122 return imap;
123}
124
125
126/**Given the face index on the current cell, finds the
127 * corresponding face index on the adjacent cell.*/
128unsigned int
130 const chi_mesh::Cell& adj_cell,
131 unsigned int f)
132{
133 const auto& ccface = cur_cell.faces_[f]; //current cell face
134 std::set<uint64_t> ccface_vids;
135 for (auto vid : ccface.vertex_ids_) ccface_vids.insert(vid);
136
137 size_t fmap;
138 bool map_found = false;
139 for (size_t af=0; af < adj_cell.faces_.size(); af++)
140 {
141 const auto& acface = adj_cell.faces_[af]; //adjacent cell face
142
143 std::set<uint64_t> acface_vids;
144 for (auto vid : acface.vertex_ids_) acface_vids.insert(vid);
145
146 if (acface_vids == ccface_vids)
147 {
148 fmap = af;
149 map_found = true;
150 break;
151 }
152 }//for adj faces
153
154 if (not map_found)
155 throw std::logic_error(std::string(__FUNCTION__)+": Mapping failure.");
156
157 return (unsigned int)fmap;
158}
159
160
static void Exit(int error_code)
Definition: chi_runtime.cc:342
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream LogAllError()
Definition: chi_log.h:239
static uint64_t MapCellLocalNodeIDFromGlobalID(const chi_mesh::Cell &cell, uint64_t node_global_id)
static unsigned int MapCellFace(const chi_mesh::Cell &cur_cell, const chi_mesh::Cell &adj_cell, unsigned int f)
chi_mesh::MeshContinuumPtr grid_ptr_
double HPerpendicular(const chi_mesh::Cell &cell, const UnitIntegralContainer &fe_intgrl_values, unsigned int f)
double IntV_shapeI(unsigned int i) const
double IntS_shapeI(unsigned int face, unsigned int i) const
std::vector< uint64_t > vertex_ids_
Definition: cell.h:38
std::vector< CellFace > faces_
Definition: cell.h:82
CellType Type() const
Definition: cell.h:98
std::vector< uint64_t > vertex_ids_
Definition: cell.h:81