MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
MAST::Optimization::DesignParameterVector< ScalarType > Class Template Reference

Detailed Description

template<typename ScalarType>
class MAST::Optimization::DesignParameterVector< ScalarType >

Definition at line 38 of file design_parameter_vector.hpp.

#include <design_parameter_vector.hpp>

Public Types

using dv_id_param_map_t = std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * >
 

Public Member Functions

 DesignParameterVector (const libMesh::Parallel::Communicator &comm)
 
virtual ~DesignParameterVector ()
 
MAST::Base::ParameterDataadd_ghosted_topology_parameter (MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
 
MAST::Base::ParameterDataadd_parameter (MAST::Optimization::DesignParameter< ScalarType > &p)
 
MAST::Base::ParameterDataadd_topology_parameter (MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
 
const MAST::Base::ParameterDataget_data_for_parameter (const MAST::Optimization::DesignParameter< ScalarType > &p) const
 
MAST::Base::ParameterDataget_data_for_parameter (const MAST::Optimization::DesignParameter< ScalarType > &p)
 
uint_t get_dv_id_for_topology_dof (const uint_t id) const
 
const dv_id_param_map_tget_dv_map () const
 
template<typename T >
get_parameter_for_dv (uint_t i, const std::string &nm) const
 
bool is_design_parameter_dof_id (const uint_t i) const
 
bool is_design_parameter_index (const uint_t i) const
 
uint_t local_begin () const
 
uint_t local_end () const
 
MAST::Optimization::DesignParameter< ScalarType > & operator[] (uint_t i)
 
const MAST::Optimization::DesignParameter< ScalarType > & operator[] (uint_t i) const
 
uint_t size () const
 
void synchronize (const libMesh::DofMap &dof_map)
 

Private Attributes

const libMesh::Parallel::Communicator & _comm
 
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
 
std::map< uint_t, uint_t_dof_id_to_dv_id_map
 
std::set< uint_t_dv_index
 
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _ghosted_parameters
 
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _local_parameters
 
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters
 
std::vector< uint_t_rank_begin_index
 
std::vector< uint_t_rank_end_index
 

Member Typedef Documentation

◆ dv_id_param_map_t

template<typename ScalarType>
using MAST::Optimization::DesignParameterVector< ScalarType >::dv_id_param_map_t = std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*>

Definition at line 42 of file design_parameter_vector.hpp.

Constructor & Destructor Documentation

◆ DesignParameterVector()

template<typename ScalarType>
MAST::Optimization::DesignParameterVector< ScalarType >::DesignParameterVector ( const libMesh::Parallel::Communicator &  comm)
inline

Definition at line 45 of file design_parameter_vector.hpp.

45  :
46  _comm (comm)
47  { }
const libMesh::Parallel::Communicator & _comm

◆ ~DesignParameterVector()

template<typename ScalarType>
virtual MAST::Optimization::DesignParameterVector< ScalarType >::~DesignParameterVector ( )
inlinevirtual

Definition at line 50 of file design_parameter_vector.hpp.

50  {
51 
52  {
53  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
54  MAST::Base::ParameterData*>::iterator
55  it = _data.begin(),
56  end = _data.end();
57 
58  for (; it != end; it++)
59  delete it->second;
60  }
61 
62  {
63  typename std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*>::iterator
64  it = _parameters.begin(),
65  end = _parameters.end();
66 
67  for (; it != end; it++)
68  delete it->second;
69  }
70  }
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data

Member Function Documentation

◆ add_ghosted_topology_parameter()

template<typename ScalarType>
MAST::Base::ParameterData& MAST::Optimization::DesignParameterVector< ScalarType >::add_ghosted_topology_parameter ( MAST::Optimization::DesignParameter< ScalarType > &  p,
const uint_t  id 
)
inline

Definition at line 212 of file design_parameter_vector.hpp.

213  {
214 
215  // make sure this does not exist
216  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
217  MAST::Base::ParameterData*>::iterator
218  it = _data.find(&p);
219 
220  Assert0(it == _data.end(), "Parameter already exists");
221 
222  _ghosted_parameters.push_back(&p);
223 
225  _data[&p] = d;
226 
227  d->add<int>("dof_id") = id;
228  _dv_index.insert(id);
229 
230  return *d;
231  }
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _ghosted_parameters
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
T & add(const std::string &nm)
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ add_parameter()

template<typename ScalarType>
MAST::Base::ParameterData& MAST::Optimization::DesignParameterVector< ScalarType >::add_parameter ( MAST::Optimization::DesignParameter< ScalarType > &  p)
inline

Definition at line 166 of file design_parameter_vector.hpp.

166  {
167 
168  // make sure this does not exist
169  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
170  MAST::Base::ParameterData*>::iterator
171  it = _data.find(&p);
172 
173  Assert0(it == _data.end(), "Parameter already exists");
174 
175  _local_parameters.push_back(&p);
176 
178  _data[&p] = d;
179 
180  return *d;
181  }
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _local_parameters
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ add_topology_parameter()

template<typename ScalarType>
MAST::Base::ParameterData& MAST::Optimization::DesignParameterVector< ScalarType >::add_topology_parameter ( MAST::Optimization::DesignParameter< ScalarType > &  p,
const uint_t  id 
)
inline
Parameters
idis the location of the coefficient in the global vector that stores the scalar field (density or level-set) used to define the topology.

Definition at line 189 of file design_parameter_vector.hpp.

190  {
191 
192  // make sure this does not exist
193  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
194  MAST::Base::ParameterData*>::iterator
195  it = _data.find(&p);
196 
197  Assert0(it == _data.end(), "Parameter already exists");
198 
199  _local_parameters.push_back(&p);
200 
202  _data[&p] = d;
203 
204  d->add<int>("dof_id") = id;
205  _dv_index.insert(id);
206 
207  return *d;
208  }
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _local_parameters
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
T & add(const std::string &nm)
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ get_data_for_parameter() [1/2]

template<typename ScalarType>
const MAST::Base::ParameterData& MAST::Optimization::DesignParameterVector< ScalarType >::get_data_for_parameter ( const MAST::Optimization::DesignParameter< ScalarType > &  p) const
inline

Definition at line 236 of file design_parameter_vector.hpp.

236  {
237 
238  // make sure this does not exist
239  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
240  MAST::Base::ParameterData*>::const_iterator
241  it = _data.find(&p);
242 
243  Assert0(it != _data.end(), "Parameter does not exists in vector");
244 
245  return *it->second;
246  }
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ get_data_for_parameter() [2/2]

template<typename ScalarType>
MAST::Base::ParameterData& MAST::Optimization::DesignParameterVector< ScalarType >::get_data_for_parameter ( const MAST::Optimization::DesignParameter< ScalarType > &  p)
inline

Definition at line 250 of file design_parameter_vector.hpp.

250  {
251 
252  // make sure this does not exist
253  typename std::map<const MAST::Optimization::DesignParameter<ScalarType>*,
254  MAST::Base::ParameterData*>::iterator
255  it = _data.find(&p);
256 
257  Assert0(it != _data.end(), "Parameter does not exists in vector");
258 
259  return *it->second;
260  }
std::map< const MAST::Optimization::DesignParameter< ScalarType > *, MAST::Base::ParameterData * > _data
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ get_dv_id_for_topology_dof()

template<typename ScalarType>
uint_t MAST::Optimization::DesignParameterVector< ScalarType >::get_dv_id_for_topology_dof ( const uint_t  id) const
inline

Definition at line 131 of file design_parameter_vector.hpp.

131  {
132 
133  std::map<uint_t, uint_t>::const_iterator
134  it = _dof_id_to_dv_id_map.find(id);
135 
136  Assert1(it != _dof_id_to_dv_id_map.end(),
137  id, "dof ID not in this vector");
138 
139  return it->second;
140  }
#define Assert1(cond, v1, msg)
Definition: exceptions.hpp:143

◆ get_dv_map()

template<typename ScalarType>
const dv_id_param_map_t& MAST::Optimization::DesignParameterVector< ScalarType >::get_dv_map ( ) const
inline

Definition at line 125 of file design_parameter_vector.hpp.

125  {
126 
127  return _parameters;
128  }
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters

◆ get_parameter_for_dv()

template<typename ScalarType>
template<typename T >
T MAST::Optimization::DesignParameterVector< ScalarType >::get_parameter_for_dv ( uint_t  i,
const std::string &  nm 
) const
inline

Definition at line 159 of file design_parameter_vector.hpp.

159  {
160 
161  return this->get_data_for_parameter((*this)[i]).template get<T>(nm);
162  }
const MAST::Base::ParameterData & get_data_for_parameter(const MAST::Optimization::DesignParameter< ScalarType > &p) const

◆ is_design_parameter_dof_id()

template<typename ScalarType>
bool MAST::Optimization::DesignParameterVector< ScalarType >::is_design_parameter_dof_id ( const uint_t  i) const
inline

Definition at line 145 of file design_parameter_vector.hpp.

145  {
146 
147  return _dof_id_to_dv_id_map.count(i);
148  }

◆ is_design_parameter_index()

template<typename ScalarType>
bool MAST::Optimization::DesignParameterVector< ScalarType >::is_design_parameter_index ( const uint_t  i) const
inline

Definition at line 152 of file design_parameter_vector.hpp.

152  {
153 
154  return _dv_index.count(i);
155  }

◆ local_begin()

template<typename ScalarType>
uint_t MAST::Optimization::DesignParameterVector< ScalarType >::local_begin ( ) const
inline

Definition at line 82 of file design_parameter_vector.hpp.

82  {
83 
85  "Data must be synchronized before call to size()");
86 
87  return _rank_begin_index[_comm.rank()];
88  }
const libMesh::Parallel::Communicator & _comm
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ local_end()

template<typename ScalarType>
uint_t MAST::Optimization::DesignParameterVector< ScalarType >::local_end ( ) const
inline

Definition at line 91 of file design_parameter_vector.hpp.

91  {
92 
94  "Data must be synchronized before call to size()");
95 
96  return _rank_end_index[_comm.rank()];
97  }
const libMesh::Parallel::Communicator & _comm
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ operator[]() [1/2]

template<typename ScalarType>
MAST::Optimization::DesignParameter<ScalarType>& MAST::Optimization::DesignParameterVector< ScalarType >::operator[] ( uint_t  i)
inline

Definition at line 101 of file design_parameter_vector.hpp.

101  {
102 
103  typename std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*>::iterator
104  it = _parameters.find(i);
105 
106  Assert0(it != _parameters.end(), "Invalid parameter index for rank");
107 
108  return *it->second;
109  }
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ operator[]() [2/2]

template<typename ScalarType>
const MAST::Optimization::DesignParameter<ScalarType>& MAST::Optimization::DesignParameterVector< ScalarType >::operator[] ( uint_t  i) const
inline

Definition at line 114 of file design_parameter_vector.hpp.

114  {
115 
116  typename std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*>::const_iterator
117  it = _parameters.find(i);
118 
119  Assert0(it != _parameters.end(), "Invalid parameter index for rank");
120 
121  return *it->second;
122  }
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ size()

template<typename ScalarType>
uint_t MAST::Optimization::DesignParameterVector< ScalarType >::size ( ) const
inline

Definition at line 73 of file design_parameter_vector.hpp.

73  {
74 
76  "Data must be synchronized before call to size()");
77 
78  return _rank_end_index[_comm.size()-1];
79  }
const libMesh::Parallel::Communicator & _comm
#define Assert0(cond, msg)
Definition: exceptions.hpp:134

◆ synchronize()

template<typename ScalarType>
void MAST::Optimization::DesignParameterVector< ScalarType >::synchronize ( const libMesh::DofMap &  dof_map)
inline

Definition at line 262 of file design_parameter_vector.hpp.

262  {
263 
264  Assert0(!_rank_begin_index.size(), "Data already synchronized");
265  Assert0(_local_parameters.size(), "Parameters not initialized on this rank");
266 
267  std::vector<int_t>
268  rank_dvs(_comm.size(), 0);
269 
270  _rank_begin_index.resize(_comm.size());
271  _rank_end_index.resize(_comm.size());
272 
273  // initialize the number of DVs for the current rank
274  rank_dvs[_comm.rank()] = _local_parameters.size();
275 
276  // now obtain these values from each rank
277  _comm.sum(rank_dvs);
278 
279  // now identify the beginning IDs for each processor
280  _rank_begin_index[0] = 0;
281  _rank_end_index[0] = rank_dvs[0];
282 
283  for (uint_t i=1; i<_comm.size(); i++) {
284 
285  _rank_begin_index[i] = _rank_begin_index[i-1] + rank_dvs[i-1];
286  _rank_end_index[i] = _rank_end_index[i-1] + rank_dvs[i];
287  }
288 
289  // assign the DV Ids and populate the DofID map
290  uint_t
291  dof_id = 0,
292  owner = 0;
293 
294  std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*>
295  dof_to_ghost_param_map;
296 
297  for (uint_t i=0; i<_local_parameters.size(); i++) {
298 
299  dof_id = this->get_data_for_parameter(*_local_parameters[i]).template get<int>("dof_id");
300  _local_parameters[i]->set_id(_rank_begin_index[_comm.rank()]+i);
301  _dof_id_to_dv_id_map[dof_id] = _local_parameters[i]->id();
302  }
303 
304 
305  // ghosted dofs indices needed from each rank
306  std::vector<std::vector<uint_t>>
307  ghosted_indices_on_rank_send(_comm.size()),
308  ghosted_indices_on_rank_recv(_comm.size()),
309  ghosted_dv_id_on_rank_recv(_comm.size());
310 
311  // figure out the DV IDs for the ghosted parameters
312  for (uint_t i=0; i<_ghosted_parameters.size(); i++) {
313 
314  dof_id = this->get_data_for_parameter(*_ghosted_parameters[i]).template get<int>("dof_id");
315  owner = dof_map.dof_owner(dof_id);
316 
317  dof_to_ghost_param_map[dof_id] = _ghosted_parameters[i];
318  ghosted_indices_on_rank_send[owner].push_back(dof_id);
319  }
320 
321  // now ask respective processors for the indices
322  for (uint_t i=0; i<_comm.size(); i++) {
323 
324  for (uint_t j=0; j<_comm.size(); j++) {
325 
326  if ( i != j) {
327 
328  // send to the j^th processor if it is my turn,
329  // else, receive from the ith processor
330  if (i == _comm.rank())
331  _comm.send(j, ghosted_indices_on_rank_send[j]);
332  else if (j == _comm.rank())
333  _comm.receive(i, ghosted_indices_on_rank_recv[i]);
334  }
335  }
336  }
337 
338  // now that we have received all the dof indices, we are going to send
339  // back to the respective processor the DV id that corresponds to the
340  // dof indices.
341 
342 
343  for (uint_t i=0; i<_comm.size(); i++) {
344 
345  for (uint_t k=0; k<ghosted_indices_on_rank_recv[i].size(); k++) {
346 
347  // make sure that the indices are all local
348  Assert2(ghosted_indices_on_rank_recv[i][k]
349  >= dof_map.first_dof(_comm.rank()),
350  ghosted_indices_on_rank_recv[i][k],
351  dof_map.first_dof(_comm.rank()),
352  "Requested dof does not belong to this processor");
353  Assert2(ghosted_indices_on_rank_recv[i][k]
354  < dof_map.end_dof(_comm.rank()),
355  ghosted_indices_on_rank_recv[i][k],
356  dof_map.end_dof(_comm.rank()),
357  "Requested dof does not belong to this processor");
358 
359  // now identify the DV Id number for these dofs
360  std::map<uint_t, uint_t>::const_iterator
361  it = _dof_id_to_dv_id_map.find(ghosted_indices_on_rank_recv[i][k]);
362 
363  Assert0(it != _dof_id_to_dv_id_map.end(),
364  "No DV Id found for this dof id");
365 
366  ghosted_indices_on_rank_recv[i][k] = it->second;
367  }
368  }
369 
370  // now we communicate this information back to the processors
371  for (uint_t i=0; i<_comm.size(); i++) {
372 
373  for (uint_t j=0; j<_comm.size(); j++) {
374 
375  if (( i == _comm.rank() && ghosted_indices_on_rank_recv[j].size()) ||
376  ( j == _comm.rank() && ghosted_indices_on_rank_send[i].size())) {
377 
378  // send to the i^th processor if it is my turn,
379  // else, receive from the j^th processor
380  if (i == _comm.rank())
381  _comm.send(j, ghosted_indices_on_rank_recv[j]);
382  else if (j == _comm.rank()) {
383 
384  _comm.receive(i, ghosted_dv_id_on_rank_recv[i]);
385 
386  Assert2(ghosted_indices_on_rank_send[i].size() ==
387  ghosted_dv_id_on_rank_recv[i].size(),
388  ghosted_indices_on_rank_send[i].size(),
389  ghosted_dv_id_on_rank_recv[i].size(),
390  "Dof and DV ID map sizes must be same");
391 
392  uint_t
393  dof_id = 0,
394  dv_id = 0;
395 
396  for (uint_t k=0; k<ghosted_dv_id_on_rank_recv[i].size(); k++) {
397 
398  dof_id = ghosted_indices_on_rank_send[i][k];
399  dv_id = ghosted_dv_id_on_rank_recv[i][k];
400  dof_to_ghost_param_map[dof_id]->set_id(dv_id);
401 
402  // also store this information in the map
403  _dof_id_to_dv_id_map[dof_id] = dv_id;
404  }
405  }
406  }
407  }
408  }
409 
410  // now, populate the parameters map
411  for (uint_t i=0; i<_local_parameters.size(); i++)
413 
414  for (uint_t i=0; i<_ghosted_parameters.size(); i++)
416 
417 
418  // we don't need these any more, so we clear them.
419  _local_parameters.clear();
420  _ghosted_parameters.clear();
421  }
std::map< uint_t, MAST::Optimization::DesignParameter< ScalarType > * > _parameters
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _local_parameters
std::vector< MAST::Optimization::DesignParameter< ScalarType > * > _ghosted_parameters
const libMesh::Parallel::Communicator & _comm
const MAST::Base::ParameterData & get_data_for_parameter(const MAST::Optimization::DesignParameter< ScalarType > &p) const
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
unsigned int uint_t
#define Assert2(cond, v1, v2, msg)
Definition: exceptions.hpp:152

Member Data Documentation

◆ _comm

template<typename ScalarType>
const libMesh::Parallel::Communicator& MAST::Optimization::DesignParameterVector< ScalarType >::_comm
private

Definition at line 425 of file design_parameter_vector.hpp.

◆ _data

template<typename ScalarType>
std::map<const MAST::Optimization::DesignParameter<ScalarType>*, MAST::Base::ParameterData*> MAST::Optimization::DesignParameterVector< ScalarType >::_data
private

Definition at line 430 of file design_parameter_vector.hpp.

◆ _dof_id_to_dv_id_map

template<typename ScalarType>
std::map<uint_t, uint_t> MAST::Optimization::DesignParameterVector< ScalarType >::_dof_id_to_dv_id_map
private

Definition at line 432 of file design_parameter_vector.hpp.

◆ _dv_index

template<typename ScalarType>
std::set<uint_t> MAST::Optimization::DesignParameterVector< ScalarType >::_dv_index
private

Definition at line 431 of file design_parameter_vector.hpp.

◆ _ghosted_parameters

template<typename ScalarType>
std::vector<MAST::Optimization::DesignParameter<ScalarType>*> MAST::Optimization::DesignParameterVector< ScalarType >::_ghosted_parameters
private

Definition at line 428 of file design_parameter_vector.hpp.

◆ _local_parameters

template<typename ScalarType>
std::vector<MAST::Optimization::DesignParameter<ScalarType>*> MAST::Optimization::DesignParameterVector< ScalarType >::_local_parameters
private

Definition at line 427 of file design_parameter_vector.hpp.

◆ _parameters

template<typename ScalarType>
std::map<uint_t, MAST::Optimization::DesignParameter<ScalarType>*> MAST::Optimization::DesignParameterVector< ScalarType >::_parameters
private

Definition at line 426 of file design_parameter_vector.hpp.

◆ _rank_begin_index

template<typename ScalarType>
std::vector<uint_t> MAST::Optimization::DesignParameterVector< ScalarType >::_rank_begin_index
private

Definition at line 433 of file design_parameter_vector.hpp.

◆ _rank_end_index

template<typename ScalarType>
std::vector<uint_t> MAST::Optimization::DesignParameterVector< ScalarType >::_rank_end_index
private

Definition at line 434 of file design_parameter_vector.hpp.


The documentation for this class was generated from the following file: