Chi-Tech
lagC_04_mappings.cc
Go to the documentation of this file.
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5#include "chi_mpi.h"
6
7#define sc_int64 static_cast<int64_t>
8
10{
11
12// ###################################################################
13/**Maps a vertex id according to a developed node ordering.*/
15 const chi_mesh::Cell& cell,
16 const unsigned int node,
17 const chi_math::UnknownManager& unknown_manager,
18 const unsigned int unknown_id,
19 const unsigned int component /*=0*/) const
20{
21 const uint64_t vertex_id = cell.vertex_ids_[node];
22
23 ChiLogicalErrorIf(node_mapping_.count(vertex_id) == 0,
24 std::string("Bad trouble mapping vertex ") +
25 std::to_string(vertex_id));
26 const int64_t global_id = node_mapping_.at(vertex_id);
27
28 size_t num_unknowns = unknown_manager.GetTotalUnknownStructureSize();
29 size_t block_id = unknown_manager.MapUnknown(unknown_id, component);
30 auto storage = unknown_manager.dof_storage_type_;
31
32 int64_t address = -1;
34 {
35 for (int locJ = 0; locJ < Chi::mpi.process_count; ++locJ)
36 {
37 const int64_t local_id = global_id - sc_int64(locJ_block_address_[locJ]);
38
39 if (local_id < 0 or local_id >= locJ_block_size_[locJ]) continue;
40
41 address = sc_int64(locJ_block_address_[locJ] * num_unknowns) +
42 sc_int64(locJ_block_size_[locJ] * block_id) + local_id;
43 break;
44 }
45 }
46 else if (storage == chi_math::UnknownStorageType::NODAL)
47 address = global_id * sc_int64(num_unknowns) + sc_int64(block_id);
48
49 return address;
50}
51
52// ###################################################################
53/**Maps a vertex id according to a developed node ordering.*/
55 const chi_mesh::Cell& cell,
56 const unsigned int node,
57 const chi_math::UnknownManager& unknown_manager,
58 const unsigned int unknown_id,
59 const unsigned int component /*=0*/) const
60{
61 const uint64_t vertex_id = cell.vertex_ids_[node];
62
63 ChiLogicalErrorIf(node_mapping_.count(vertex_id) == 0, "Bad trouble");
64 const int64_t node_global_id = node_mapping_.at(vertex_id);
65
66 size_t num_unknowns = unknown_manager.GetTotalUnknownStructureSize();
67 size_t block_id = unknown_manager.MapUnknown(unknown_id, component);
68 auto storage = unknown_manager.dof_storage_type_;
69
70 const int64_t local_id = node_global_id - sc_int64(local_block_address_);
71 const bool is_local = not(local_id < 0 or local_id >= local_base_block_size_);
72
73 int64_t address = -1;
74 if (is_local)
75 {
77 {
78 address = sc_int64(local_base_block_size_ * block_id) + local_id;
79 }
80 else if (storage == chi_math::UnknownStorageType::NODAL)
81 address = local_id * sc_int64(num_unknowns) + sc_int64(block_id);
82 } // if is_local
83 else
84 {
85 const size_t num_local_dofs = GetNumLocalDOFs(unknown_manager);
86 int64_t ghost_local_node_id = -1;
87 int64_t counter = 0;
88 for (const auto& vid_gnid : ghost_node_mapping_)
89 {
90 if (node_global_id == vid_gnid.second)
91 {
92 ghost_local_node_id = counter;
93 break;
94 }
95 ++counter;
96 }
98 {
99 address =
100 sc_int64(ghost_node_mapping_.size() * block_id) + ghost_local_node_id;
101 }
102 else if (storage == chi_math::UnknownStorageType::NODAL)
103 address =
104 ghost_local_node_id * sc_int64(num_unknowns) + sc_int64(block_id);
105
106 address += sc_int64(num_local_dofs);
107 }
108
109 return address;
110}
111
112} // namespace chi_math::spatial_discretization
#define ChiLogicalErrorIf(condition, message)
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
const int & process_count
Total number of processes.
Definition: mpi_info.h:27
std::vector< uint64_t > locJ_block_size_
size_t GetNumLocalDOFs(const UnknownManager &unknown_manager) const
std::vector< uint64_t > locJ_block_address_
unsigned int MapUnknown(unsigned int unknown_id, unsigned int component=0) const
UnknownStorageType dof_storage_type_
unsigned int GetTotalUnknownStructureSize() const
int64_t MapDOFLocal(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const override
int64_t MapDOF(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const override
std::vector< uint64_t > vertex_ids_
Definition: cell.h:81
#define sc_int64