MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
MAST::Numerics::Utility Namespace Reference

Functions

template<typename ScalarType >
void add (std::vector< ScalarType > &v, uint_t i, ScalarType s)
 
void add (libMesh::NumericVector< real_t > &v, uint_t i, real_t s)
 
template<typename ScalarType >
void add (Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &v, uint_t i, ScalarType s)
 
template<typename ValType >
std::unique_ptr< ValType > build (const libMesh::System &sys)
 
template<>
std::unique_ptr< libMesh::NumericVector< real_t > > build (const libMesh::System &sys)
 
real_t comm_max (const libMesh::Parallel::Communicator &comm, const std::vector< real_t > &v)
 
real_t comm_max (const libMesh::Parallel::Communicator &comm, real_t v)
 
complex_t comm_max (const libMesh::Parallel::Communicator &comm, const std::vector< complex_t > &v)
 
complex_t comm_max (const libMesh::Parallel::Communicator &comm, complex_t v)
 
real_t comm_min (const libMesh::Parallel::Communicator &comm, const std::vector< real_t > &v)
 
real_t comm_min (const libMesh::Parallel::Communicator &comm, real_t v)
 
complex_t comm_min (const libMesh::Parallel::Communicator &comm, const std::vector< complex_t > &v)
 
complex_t comm_min (const libMesh::Parallel::Communicator &comm, complex_t v)
 
void comm_sum (const libMesh::Parallel::Communicator &comm, real_t &v)
 
void comm_sum (const libMesh::Parallel::Communicator &comm, complex_t &v)
 
void comm_sum (const libMesh::Parallel::Communicator &comm, std::vector< real_t > &v)
 
void comm_sum (const libMesh::Parallel::Communicator &comm, std::vector< complex_t > &v)
 
template<typename ScalarType , typename VecType >
void copy (const VecType &v_from, libMesh::DenseVector< ScalarType > &v_to)
 
template<typename ScalarType , typename MatType >
void copy (const MatType &m_from, libMesh::DenseMatrix< ScalarType > &m_to)
 
template<typename ValType >
void finalize (ValType &m)
 
void finalize (libMesh::NumericVector< real_t > &v)
 
void finalize (libMesh::SparseMatrix< real_t > &m)
 
template<typename P1 , int P2, typename P3 >
void finalize (Eigen::SparseMatrix< P1, P2, P3 > &m)
 
template<typename ScalarType >
ScalarType get (const std::vector< ScalarType > &v, uint_t i)
 
real_t get (const libMesh::NumericVector< real_t > &v, uint_t i)
 
template<typename ScalarType >
ScalarType get (const Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &v, uint_t i)
 
real_t real_maximum (const std::vector< real_t > &vec)
 computes maximum of vector More...
 
complex_t real_maximum (const std::vector< complex_t > &vec)
 computes maximum based on real-part of complex numbers More...
 
real_t real_minimum (const std::vector< real_t > &vec)
 computes minimum of vector More...
 
complex_t real_minimum (const std::vector< complex_t > &vec)
 computes minimum based on real-part of complex numbers More...
 
template<typename VecType >
std::enable_if< std::is_same< typename Eigen::internal::traits< VecType >::Scalar, real_t >::value, real_t >::type real_norm (const VecType &v)
 
template<typename VecType >
std::enable_if< std::is_same< typename Eigen::internal::traits< VecType >::Scalar, complex_t >::value, real_t >::type real_norm (const VecType &v)
 
template<typename ScalarType >
void resize (std::vector< ScalarType > &v, uint_t n)
 
template<typename ScalarType >
void resize (Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &v, uint_t n)
 
template<typename ScalarType >
void set (std::vector< ScalarType > &v, uint_t i, ScalarType s)
 
void set (libMesh::NumericVector< real_t > &v, uint_t i, real_t s)
 
template<typename ScalarType >
void set (Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &v, uint_t i, ScalarType s)
 
template<typename ValType >
void setZero (ValType &m)
 
void setZero (libMesh::NumericVector< real_t > &v)
 
void setZero (libMesh::SparseMatrix< real_t > &m)
 
template<typename ScalarType >
void setZero (std::vector< ScalarType > &v)
 

Function Documentation

◆ add() [1/3]

template<typename ScalarType >
void MAST::Numerics::Utility::add ( std::vector< ScalarType > &  v,
uint_t  i,
ScalarType  s 
)
inline

Definition at line 188 of file utility.hpp.

188  {
189  v[i] += s;
190 }

◆ add() [2/3]

void MAST::Numerics::Utility::add ( libMesh::NumericVector< real_t > &  v,
uint_t  i,
real_t  s 
)
inline

Definition at line 194 of file utility.hpp.

194  {
195  v.add(i, s);
196 }

◆ add() [3/3]

template<typename ScalarType >
void MAST::Numerics::Utility::add ( Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &  v,
uint_t  i,
ScalarType  s 
)
inline

Definition at line 201 of file utility.hpp.

203  {
204  v(i) += s;
205 }

◆ build() [1/2]

template<typename ValType >
std::unique_ptr<ValType> MAST::Numerics::Utility::build ( const libMesh::System &  sys)
inline

Definition at line 284 of file utility.hpp.

284  {
285 
286  std::unique_ptr<ValType> rval(new ValType);
287  MAST::Numerics::Utility::resize(*rval, sys.n_dofs());
288 
289  return rval;
290 }
void resize(std::vector< ScalarType > &v, uint_t n)
Definition: utility.hpp:269

◆ build() [2/2]

template<>
std::unique_ptr<libMesh::NumericVector<real_t> > MAST::Numerics::Utility::build ( const libMesh::System &  sys)
inline

Definition at line 295 of file utility.hpp.

295  {
296 
297  return std::unique_ptr<libMesh::NumericVector<real_t>>
298  (sys.solution->zero_clone().release());
299 }

◆ comm_max() [1/4]

real_t MAST::Numerics::Utility::comm_max ( const libMesh::Parallel::Communicator &  comm,
const std::vector< real_t > &  v 
)
inline

Definition at line 422 of file utility.hpp.

423  {
424 
425  real_t
426  v_max = *std::max_element(v.begin(), v.end());
427 
428  comm.max(v_max);
429 
430  return v_max;
431 }
double real_t

◆ comm_max() [2/4]

real_t MAST::Numerics::Utility::comm_max ( const libMesh::Parallel::Communicator &  comm,
real_t  v 
)
inline

Definition at line 435 of file utility.hpp.

436  {
437 
438  comm.max(v);
439 
440  return v;
441 }

◆ comm_max() [3/4]

complex_t MAST::Numerics::Utility::comm_max ( const libMesh::Parallel::Communicator &  comm,
const std::vector< complex_t > &  v 
)
inline

Definition at line 444 of file utility.hpp.

445  {
446  Error(false, "Not currently implemented for complex_t");
447  return 0.;
448 }
#define Error(cond, msg)
Definition: exceptions.hpp:166

◆ comm_max() [4/4]

complex_t MAST::Numerics::Utility::comm_max ( const libMesh::Parallel::Communicator &  comm,
complex_t  v 
)
inline

Definition at line 452 of file utility.hpp.

453  {
454  Error(false, "Not currently implemented for complex_t");
455  return 0.;
456 }
#define Error(cond, msg)
Definition: exceptions.hpp:166

◆ comm_min() [1/4]

real_t MAST::Numerics::Utility::comm_min ( const libMesh::Parallel::Communicator &  comm,
const std::vector< real_t > &  v 
)
inline

Definition at line 382 of file utility.hpp.

383  {
384 
385  real_t
386  v_min = *std::min_element(v.begin(), v.end());
387 
388  comm.min(v_min);
389 
390  return v_min;
391 }
double real_t

◆ comm_min() [2/4]

real_t MAST::Numerics::Utility::comm_min ( const libMesh::Parallel::Communicator &  comm,
real_t  v 
)
inline

Definition at line 395 of file utility.hpp.

396  {
397 
398  comm.min(v);
399 
400  return v;
401 }

◆ comm_min() [3/4]

complex_t MAST::Numerics::Utility::comm_min ( const libMesh::Parallel::Communicator &  comm,
const std::vector< complex_t > &  v 
)
inline

Definition at line 405 of file utility.hpp.

406  {
407  Error(false, "Not currently implemented for complex_t");
408  return 0.;
409 }
#define Error(cond, msg)
Definition: exceptions.hpp:166

◆ comm_min() [4/4]

complex_t MAST::Numerics::Utility::comm_min ( const libMesh::Parallel::Communicator &  comm,
complex_t  v 
)
inline

Definition at line 413 of file utility.hpp.

414  {
415 
416  Error(false, "Not currently implemented for complex_t");
417  return 0.;
418 }
#define Error(cond, msg)
Definition: exceptions.hpp:166

◆ comm_sum() [1/4]

void MAST::Numerics::Utility::comm_sum ( const libMesh::Parallel::Communicator &  comm,
real_t v 
)
inline

Definition at line 328 of file utility.hpp.

329  {
330  comm.sum(v);
331 }

◆ comm_sum() [2/4]

void MAST::Numerics::Utility::comm_sum ( const libMesh::Parallel::Communicator &  comm,
complex_t v 
)
inline

Definition at line 335 of file utility.hpp.

336  {
337  real_t
338  v_re = v.real(),
339  v_im = v.imag();
340 
341  comm.sum(v_re);
342  comm.sum(v_im);
343 
344  v.real(v_re);
345  v.imag(v_im);
346 }
double real_t

◆ comm_sum() [3/4]

void MAST::Numerics::Utility::comm_sum ( const libMesh::Parallel::Communicator &  comm,
std::vector< real_t > &  v 
)
inline

Definition at line 350 of file utility.hpp.

351  {
352  comm.sum(v);
353 }

◆ comm_sum() [4/4]

void MAST::Numerics::Utility::comm_sum ( const libMesh::Parallel::Communicator &  comm,
std::vector< complex_t > &  v 
)
inline

Definition at line 357 of file utility.hpp.

358  {
359 
360  std::vector<real_t>
361  v_re(v.size()),
362  v_im(v.size());
363 
364  for (uint_t i=0; i<v.size(); i++) {
365 
366  v_re[i] = v[i].real();
367  v_im[i] = v[i].imag();
368  }
369 
370  comm.sum(v_re);
371  comm.sum(v_im);
372 
373  for (uint_t i=0; i<v.size(); i++) {
374 
375  v[i].real(v_re[i]);
376  v[i].imag(v_im[i]);
377  }
378 }
unsigned int uint_t

◆ copy() [1/2]

template<typename ScalarType , typename VecType >
void MAST::Numerics::Utility::copy ( const VecType &  v_from,
libMesh::DenseVector< ScalarType > &  v_to 
)
inline

Definition at line 305 of file utility.hpp.

306  {
307 
308  v_to.resize(v_from.size());
309 
310  for (uint_t i=0; i<v_from.size(); i++)
311  v_to(i) = v_from(i);
312 }
unsigned int uint_t

◆ copy() [2/2]

template<typename ScalarType , typename MatType >
void MAST::Numerics::Utility::copy ( const MatType &  m_from,
libMesh::DenseMatrix< ScalarType > &  m_to 
)
inline

Definition at line 316 of file utility.hpp.

317  {
318 
319  m_to.resize(m_from.rows(), m_from.cols());
320 
321  for (uint_t i=0; i<m_from.cols(); i++)
322  for (uint_t j=0; j<m_from.cols(); j++)
323  m_to(i, j) = m_from(i, j);
324 }
unsigned int uint_t

◆ finalize() [1/4]

template<typename ValType >
void MAST::Numerics::Utility::finalize ( ValType &  m)
inline

Definition at line 252 of file utility.hpp.

252 { }

◆ finalize() [2/4]

void MAST::Numerics::Utility::finalize ( libMesh::NumericVector< real_t > &  v)
inline

Definition at line 256 of file utility.hpp.

256 { v.close();}

◆ finalize() [3/4]

void MAST::Numerics::Utility::finalize ( libMesh::SparseMatrix< real_t > &  m)
inline

Definition at line 260 of file utility.hpp.

260 { m.close();}

◆ finalize() [4/4]

template<typename P1 , int P2, typename P3 >
void MAST::Numerics::Utility::finalize ( Eigen::SparseMatrix< P1, P2, P3 > &  m)
inline

Definition at line 265 of file utility.hpp.

265 { m.makeCompressed();}

◆ get() [1/3]

template<typename ScalarType >
ScalarType MAST::Numerics::Utility::get ( const std::vector< ScalarType > &  v,
uint_t  i 
)
inline

Definition at line 232 of file utility.hpp.

232  {
233  return v[i];
234 }

◆ get() [2/3]

real_t MAST::Numerics::Utility::get ( const libMesh::NumericVector< real_t > &  v,
uint_t  i 
)
inline

Definition at line 238 of file utility.hpp.

238  {
239  return v.el(i);
240 }

◆ get() [3/3]

template<typename ScalarType >
ScalarType MAST::Numerics::Utility::get ( const Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &  v,
uint_t  i 
)
inline

Definition at line 245 of file utility.hpp.

245  {
246  return v(i);
247 }

◆ real_maximum() [1/2]

real_t MAST::Numerics::Utility::real_maximum ( const std::vector< real_t > &  vec)
inline

computes maximum of vector

Definition at line 141 of file utility.hpp.

141  {
142 
143  return *std::max_element(vec.begin(), vec.end());
144 }

◆ real_maximum() [2/2]

complex_t MAST::Numerics::Utility::real_maximum ( const std::vector< complex_t > &  vec)
inline

computes maximum based on real-part of complex numbers

Definition at line 151 of file utility.hpp.

151  {
152 
153  complex_t
154  v = vec[0];
155 
156  for (uint_t i=1; i<vec.size(); i++) {
157  if (v.real() < vec[i].real())
158  v = vec[i];
159  }
160 
161  return v;
162 }
std::complex< real_t > complex_t
unsigned int uint_t

◆ real_minimum() [1/2]

real_t MAST::Numerics::Utility::real_minimum ( const std::vector< real_t > &  vec)
inline

computes minimum of vector

Definition at line 92 of file utility.hpp.

92  {
93 
94  return *std::min_element(vec.begin(), vec.end());
95 }

◆ real_minimum() [2/2]

complex_t MAST::Numerics::Utility::real_minimum ( const std::vector< complex_t > &  vec)
inline

computes minimum based on real-part of complex numbers

Definition at line 102 of file utility.hpp.

102  {
103 
104  complex_t
105  v = vec[0];
106 
107  for (uint_t i=1; i<vec.size(); i++) {
108  if (vec[i].real() < v.real())
109  v = vec[i];
110  }
111 
112  return v;
113 }
std::complex< real_t > complex_t
unsigned int uint_t

◆ real_norm() [1/2]

template<typename VecType >
std::enable_if<std::is_same<typename Eigen::internal::traits<VecType>::Scalar, real_t>::value, real_t>::type MAST::Numerics::Utility::real_norm ( const VecType &  v)
inline

Definition at line 63 of file utility.hpp.

63  {
64  return v.norm();
65 }

◆ real_norm() [2/2]

template<typename VecType >
std::enable_if<std::is_same<typename Eigen::internal::traits<VecType>::Scalar, complex_t>::value, real_t>::type MAST::Numerics::Utility::real_norm ( const VecType &  v)
inline

Definition at line 72 of file utility.hpp.

72  {
73  return v.norm();
74 }

◆ resize() [1/2]

template<typename ScalarType >
void MAST::Numerics::Utility::resize ( std::vector< ScalarType > &  v,
uint_t  n 
)
inline

Definition at line 269 of file utility.hpp.

269  {
270 
271  v.resize(n, ScalarType());
272 }

◆ resize() [2/2]

template<typename ScalarType >
void MAST::Numerics::Utility::resize ( Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &  v,
uint_t  n 
)
inline

Definition at line 276 of file utility.hpp.

276  {
277 
278  v = Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>::Zero(n);
279 }

◆ set() [1/3]

template<typename ScalarType >
void MAST::Numerics::Utility::set ( std::vector< ScalarType > &  v,
uint_t  i,
ScalarType  s 
)
inline

Definition at line 210 of file utility.hpp.

210  {
211  v[i] = s;
212 }

◆ set() [2/3]

void MAST::Numerics::Utility::set ( libMesh::NumericVector< real_t > &  v,
uint_t  i,
real_t  s 
)
inline

Definition at line 216 of file utility.hpp.

216  {
217  v.set(i, s);
218 }

◆ set() [3/3]

template<typename ScalarType >
void MAST::Numerics::Utility::set ( Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > &  v,
uint_t  i,
ScalarType  s 
)
inline

Definition at line 223 of file utility.hpp.

225  {
226  v(i) = s;
227 }

◆ setZero() [1/4]

template<typename ValType >
void MAST::Numerics::Utility::setZero ( ValType &  m)
inline

Definition at line 44 of file utility.hpp.

44 { m.setZero();}

◆ setZero() [2/4]

void MAST::Numerics::Utility::setZero ( libMesh::NumericVector< real_t > &  v)
inline

Definition at line 48 of file utility.hpp.

48 { v.zero();}

◆ setZero() [3/4]

void MAST::Numerics::Utility::setZero ( libMesh::SparseMatrix< real_t > &  m)
inline

Definition at line 52 of file utility.hpp.

52 { m.zero();}

◆ setZero() [4/4]

template<typename ScalarType >
void MAST::Numerics::Utility::setZero ( std::vector< ScalarType > &  v)
inline

Definition at line 56 of file utility.hpp.

56 { std::fill(v.begin(), v.end(), ScalarType());}