OGS
ProcessLib::ComponentTransport::LookupTable Struct Reference

Detailed Description

Definition at line 49 of file LookupTable.h.

#include <LookupTable.h>

Public Member Functions

 LookupTable (std::vector< Field > input_fields_, std::map< std::string, std::vector< double >> tabular_data_)
 
void lookup (std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::size_t const n_nodes) const
 
std::size_t getTableEntryID (std::vector< double > const &entry_input) const
 

Public Attributes

std::vector< Field > const input_fields
 
std::map< std::string, std::vector< double > > const tabular_data
 

Constructor & Destructor Documentation

◆ LookupTable()

ProcessLib::ComponentTransport::LookupTable::LookupTable ( std::vector< Field input_fields_,
std::map< std::string, std::vector< double >>  tabular_data_ 
)
inline

Definition at line 51 of file LookupTable.h.

54  : input_fields(std::move(input_fields_)),
55  tabular_data(std::move(tabular_data_))
56  {
57  }
std::map< std::string, std::vector< double > > const tabular_data
Definition: LookupTable.h:66
std::vector< Field > const input_fields
Definition: LookupTable.h:65

Member Function Documentation

◆ getTableEntryID()

std::size_t ProcessLib::ComponentTransport::LookupTable::getTableEntryID ( std::vector< double > const &  entry_input) const

point_id_groups stores indices where the elements equal to the given value.

need to intersect point_id_groups with respect to different input fields to find out an entry id where all the field data align with the entry inputs.

Definition at line 134 of file LookupTable.cpp.

136 {
137  std::vector<std::size_t> temp_vec;
138 
139  std::vector<std::size_t> intersected_vec =
142  input_fields[0].point_id_groups[BaseLib::findIndex(
143  input_fields[0].seed_points, entry_input[0])];
144 
148  for (std::size_t i = 1; i < input_fields.size(); ++i)
149  {
150  std::vector<std::size_t> const vec =
151  input_fields[i].point_id_groups[BaseLib::findIndex(
152  input_fields[i].seed_points, entry_input[i])];
153 
154  temp_vec = intersection(intersected_vec, vec);
155 
156  std::swap(intersected_vec, temp_vec);
157  temp_vec.clear();
158  }
159 
160  return intersected_vec[0];
161 }
std::size_t findIndex(Container const &container, typename Container::value_type const &element)
Definition: Algorithm.h:287
static std::vector< std::size_t > intersection(std::vector< std::size_t > const &vec1, std::vector< std::size_t > const &vec2)
Definition: LookupTable.cpp:21

References BaseLib::findIndex(), input_fields, and ProcessLib::ComponentTransport::intersection().

Referenced by lookup().

◆ lookup()

void ProcessLib::ComponentTransport::LookupTable::lookup ( std::vector< GlobalVector * > const &  x,
std::vector< GlobalVector * > const &  x_prev,
std::size_t const  n_nodes 
) const

Definition at line 56 of file LookupTable.cpp.

59 {
60  using EntryInput = std::vector<double>;
61 
62  for (std::size_t node_id = 0; node_id < n_nodes; ++node_id)
63  {
64  std::vector<InterpolationPoint> interpolation_points;
65  EntryInput base_entry_input;
66  for (auto const& input_field : input_fields)
67  {
68  // process id and variable id are equilvalent in the case the
69  // staggered coupling scheme is adopted.
70  auto const process_id = input_field.variable_id;
71  auto const& variable_name = input_field.name;
72  double input_field_value =
73  variable_name.find("_prev") == std::string::npos
74  ? x[process_id]->get(node_id)
75  : x_prev[process_id]->get(node_id);
76  input_field_value =
77  (std::abs(input_field_value) + input_field_value) / 2;
78  auto bounding_seed_points =
79  input_field.getBoundingSeedPoints(input_field_value);
80 
81  InterpolationPoint interpolation_point{bounding_seed_points,
82  input_field_value};
83  interpolation_points.push_back(interpolation_point);
84 
85  base_entry_input.push_back(bounding_seed_points.first);
86  }
87 
88  auto const base_entry_id = getTableEntryID(base_entry_input);
89 
90  // collect bounding entry ids
91  EntryInput bounding_entry_input{base_entry_input};
92  std::vector<std::size_t> bounding_entry_ids;
93  for (std::size_t i = 0; i < interpolation_points.size(); ++i)
94  {
95  bounding_entry_input[i] =
96  interpolation_points[i].bounding_points.second;
97  bounding_entry_ids.push_back(getTableEntryID(bounding_entry_input));
98  bounding_entry_input[i] =
99  interpolation_points[i].bounding_points.first;
100  }
101 
102  for (auto const& input_field : input_fields)
103  {
104  if (input_field.name.find("_prev") != std::string::npos)
105  {
106  continue;
107  }
108 
109  auto const output_field_name = input_field.name + "_new";
110  auto const base_value =
111  tabular_data.at(output_field_name)[base_entry_id];
112  auto new_value = base_value;
113 
114  // linear interpolation
115  for (std::size_t i = 0; i < interpolation_points.size(); ++i)
116  {
117  auto const interpolation_point_value =
118  tabular_data.at(output_field_name)[bounding_entry_ids[i]];
119  auto const slope =
120  (interpolation_point_value - base_value) /
121  (interpolation_points[i].bounding_points.second -
122  interpolation_points[i].bounding_points.first);
123 
124  new_value +=
125  slope * (interpolation_points[i].value -
126  interpolation_points[i].bounding_points.first);
127  }
128 
129  x[input_field.variable_id]->set(node_id, new_value);
130  }
131  }
132 }
std::size_t getTableEntryID(std::vector< double > const &entry_input) const

References getTableEntryID(), input_fields, and tabular_data.

Member Data Documentation

◆ input_fields

std::vector<Field> const ProcessLib::ComponentTransport::LookupTable::input_fields

Definition at line 65 of file LookupTable.h.

Referenced by getTableEntryID(), and lookup().

◆ tabular_data

std::map<std::string, std::vector<double> > const ProcessLib::ComponentTransport::LookupTable::tabular_data

Definition at line 66 of file LookupTable.h.

Referenced by lookup().


The documentation for this struct was generated from the following files: