Chi-Tech
ff_gridbased_05_values.cc
Go to the documentation of this file.
2
4
6
7#include "chi_runtime.h"
8
9namespace chi_physics
10{
11
12// ##################################################################
13/**Not necessarily an optimal routine to use when repeatedly querying
14 * a field function.*/
15std::vector<double>
17{
18 typedef const int64_t cint64_t;
19 const auto& uk_man = GetUnknownManager();
20 const size_t num_components = uk_man.GetTotalUnknownStructureSize();
21
22 size_t local_num_point_hits = 0;
23 std::vector<double> local_point_value(num_components, 0.0);
24
25 const auto& xyz_min = local_grid_bounding_box_.first;
26 const auto& xyz_max = local_grid_bounding_box_.second;
27
28 const double xmin = xyz_min.x;
29 const double ymin = xyz_min.y;
30 const double zmin = xyz_min.z;
31
32 const double xmax = xyz_max.x;
33 const double ymax = xyz_max.y;
34 const double zmax = xyz_max.z;
35
36 const auto& field_vector = *ghosted_field_vector_;
37
38 if (point.x >= xmin and point.x <= xmax and point.y >= ymin and
39 point.y <= ymax and point.z >= zmin and point.z <= zmax)
40 {
41 const auto& grid = sdm_->Grid();
42 for (const auto& cell : grid.local_cells)
43 {
44 if (grid.CheckPointInsideCell(cell, point))
45 {
46 const auto& cell_mapping = sdm_->GetCellMapping(cell);
47 std::vector<double> shape_values;
48 cell_mapping.ShapeValues(point, shape_values);
49
50 local_num_point_hits += 1;
51
52 const size_t num_nodes = cell_mapping.NumNodes();
53 for (size_t c = 0; c < num_components; ++c)
54 {
55 for (size_t j = 0; j < num_nodes; ++j)
56 {
57 cint64_t dof_map_j = sdm_->MapDOFLocal(cell, j, uk_man, 0, c);
58 const double dof_value_j = field_vector[dof_map_j];
59
60 local_point_value[c] += dof_value_j * shape_values[j];
61 } // for node i
62 } // for component c
63 } // if inside cell
64 } // for cell
65 } // if in bounding box
66
67 //============================================= Communicate number of
68 // point hits
69 size_t globl_num_point_hits;
70 MPI_Allreduce(&local_num_point_hits, // sendbuf
71 &globl_num_point_hits, // recvbuf
72 1,
73 MPIU_SIZE_T, // count + datatype
74 MPI_SUM, // operation
75 Chi::mpi.comm); // communicator
76
77 std::vector<double> globl_point_value(num_components, 0.0);
78 MPI_Allreduce(local_point_value.data(), // sendbuf
79 globl_point_value.data(), // recvbuf
80 1,
81 MPI_DOUBLE, // count + datatype
82 MPI_SUM, // operation
83 Chi::mpi.comm); // communicator
84
85 chi_math::Scale(globl_point_value,
86 1.0 / static_cast<double>(globl_num_point_hits));
87
88 return globl_point_value;
89}
90
91// ##################################################################
93 const chi_mesh::Vector3& position,
94 unsigned int component) const
95{
96 const auto& field_vector = *ghosted_field_vector_;
97
98 typedef const int64_t cint64_t;
99 const auto& cell_mapping = sdm_->GetCellMapping(cell);
100
101 std::vector<double> shape_values;
102 cell_mapping.ShapeValues(position, shape_values);
103
104 double value = 0.0;
105 const size_t num_nodes = cell_mapping.NumNodes();
106 for (size_t j=0; j<num_nodes; ++j)
107 {
108 cint64_t dof_map = sdm_->MapDOFLocal(cell, j, GetUnknownManager(), 0, component);
109
110 value += field_vector[dof_map] * shape_values[j];
111 }
112
113 return value;
114}
115
116} // namespace chi_physics
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
const MPI_Comm & comm
MPI communicator.
Definition: mpi_info.h:28
std::unique_ptr< chi_math::GhostedParallelSTLVector > ghosted_field_vector_
virtual std::vector< double > GetPointValue(const chi_mesh::Vector3 &point) const
Returns the component values at requested point.
double Evaluate(const chi_mesh::Cell &cell, const chi_mesh::Vector3 &position, unsigned int component) const override
const chi_math::UnknownManager & GetUnknownManager() const
Definition: fieldfunction.h:42
void Scale(VecDbl &x, const double &val)
double x
Element-0.
double y
Element-1.
double z
Element-2.