Chi-Tech
chi_ffinter_volume_execute.cc
Go to the documentation of this file.
2
8
9//###################################################################
10/**Executes the volume interpolation.*/
12{
13 const auto& ref_ff = *field_functions_.front();
14 const auto& sdm = ref_ff.GetSpatialDiscretization();
15 const auto& grid = sdm.Grid();
16
17 const auto& uk_man = ref_ff.GetUnknownManager();
18 const auto uid = 0;
19 const auto cid = ref_component_;
20
21 using namespace chi_mesh::ff_interpolation;
22 const auto field_data = ref_ff.GetGhostedFieldVector();
23
24 double local_volume = 0.0;
25 double local_sum = 0.0;
26 double local_max = 0.0;
27 double local_min = 0.0;
28 for (const uint64_t cell_local_id : cell_local_ids_inside_logvol_)
29 {
30 const auto& cell = grid.local_cells[cell_local_id];
31 const auto& cell_mapping = sdm.GetCellMapping(cell);
32 const size_t num_nodes = cell_mapping.NumNodes();
33 const auto qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
34
35 std::vector<double> node_dof_values(num_nodes, 0.0);
36 for (size_t i=0; i<num_nodes; ++i)
37 {
38 const int64_t imap = sdm.MapDOFLocal(cell,i,uk_man,uid,cid);
39 node_dof_values[i] = field_data[imap];
40 }//for i
41
42 if (cell_local_id == cell_local_ids_inside_logvol_.front())
43 {
44 local_max = node_dof_values.front();
45 local_min = node_dof_values.front();
46 }
47
48 for (size_t i=0; i<num_nodes; ++i)
49 {
50 local_max = std::fmax(node_dof_values[i], local_max);
51 local_min = std::fmin(node_dof_values[i], local_min);
52 }
53
54 for (const size_t qp : qp_data.QuadraturePointIndices())
55 {
56 double ff_value = 0.0;
57 for (size_t j=0; j<num_nodes; ++j)
58 ff_value += qp_data.ShapeValue(j,qp) * node_dof_values[j];
59
60 double function_value = ff_value;
61 if (op_type_ >= Operation::OP_SUM_LUA and
62 op_type_ <= Operation::OP_MAX_LUA)
63 function_value = CallLuaFunction(ff_value, cell.material_id_);
64
65 local_volume += qp_data.JxW(qp);
66 local_sum += function_value * qp_data.JxW(qp);
67 local_max = std::fmax(ff_value, local_max);
68 local_min = std::fmin(ff_value, local_min);
69 }//for qp
70 }//for cell-id
71
72 if (op_type_ == Operation::OP_SUM or op_type_ == Operation::OP_SUM_LUA)
73 {
74 double global_sum;
75 MPI_Allreduce(&local_sum,&global_sum,1,MPI_DOUBLE,MPI_SUM,Chi::mpi.comm);
76 op_value_ = global_sum;
77 }
78 if (op_type_ == Operation::OP_AVG or op_type_ == Operation::OP_AVG_LUA)
79 {
80 double local_data[] = {local_volume, local_sum};
81 double global_data[] = {0.0,0.0};
82
83 MPI_Allreduce(&local_data,&global_data,2,MPI_DOUBLE,MPI_SUM,Chi::mpi.comm);
84 double global_volume = global_data[0];
85 double global_sum = global_data[1];
86 op_value_ = global_sum / global_volume;
87 }
88 if (op_type_ == Operation::OP_MAX or op_type_ == Operation::OP_MAX_LUA)
89 {
90 double global_value;
91 MPI_Allreduce(&local_max,&global_value,1,MPI_DOUBLE,MPI_MAX,Chi::mpi.comm);
92 op_value_ = global_value;
93 }
94}
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
std::vector< chi_physics::FieldFunctionGridBasedPtr > field_functions_
double CallLuaFunction(double ff_value, int mat_id) const
std::vector< uint64_t > cell_local_ids_inside_logvol_