33#include "b2ppconfig.h"
35#if HAVE_GCC_ABI_DEMANGLE
57 StringList(
const std::string& a1) { push_back(a1); }
58 StringList(
const std::string& a1,
const std::string& a2) {
62 StringList(
const std::string& a1,
const std::string& a2,
const std::string& a3) {
68 const std::string& a1,
const std::string& a2,
const std::string& a3,
69 const std::string& a4) {
76 const std::string& a1,
const std::string& a2,
const std::string& a3,
77 const std::string& a4,
const std::string& a5) {
85 const std::string& a1,
const std::string& a2,
const std::string& a3,
86 const std::string& a4,
const std::string& a5,
const std::string& a6) {
95 const std::string& a1,
const std::string& a2,
const std::string& a3,
96 const std::string& a4,
const std::string& a5,
const std::string& a6,
97 const std::string& a7) {
107 const std::string& a1,
const std::string& a2,
const std::string& a3,
108 const std::string& a4,
const std::string& a5,
const std::string& a6,
109 const std::string& a7,
const std::string& a8) {
120 const std::string& a1,
const std::string& a2,
const std::string& a3,
121 const std::string& a4,
const std::string& a5,
const std::string& a6,
122 const std::string& a7,
const std::string& a8,
const std::string& a9) {
134 const std::string& a1,
const std::string& a2,
const std::string& a3,
135 const std::string& a4,
const std::string& a5,
const std::string& a6,
136 const std::string& a7,
const std::string& a8,
const std::string& a9,
137 const std::string& a10) {
150 const std::string& a1,
const std::string& a2,
const std::string& a3,
151 const std::string& a4,
const std::string& a5,
const std::string& a6,
152 const std::string& a7,
const std::string& a8,
const std::string& a9,
153 const std::string& a10,
const std::string& a11) {
167 const std::string& a1,
const std::string& a2,
const std::string& a3,
168 const std::string& a4,
const std::string& a5,
const std::string& a6,
169 const std::string& a7,
const std::string& a8,
const std::string& a9,
170 const std::string& a10,
const std::string& a11,
const std::string& a12) {
185 const std::string& a1,
const std::string& a2,
const std::string& a3,
186 const std::string& a4,
const std::string& a5,
const std::string& a6,
187 const std::string& a7,
const std::string& a8,
const std::string& a9,
188 const std::string& a10,
const std::string& a11,
const std::string& a12,
189 const std::string& a13) {
205 const std::string& a1,
const std::string& a2,
const std::string& a3,
206 const std::string& a4,
const std::string& a5,
const std::string& a6,
207 const std::string& a7,
const std::string& a8,
const std::string& a9,
208 const std::string& a10,
const std::string& a11,
const std::string& a12,
209 const std::string& a13,
const std::string& a14) {
226 const std::string& a1,
const std::string& a2,
const std::string& a3,
227 const std::string& a4,
const std::string& a5,
const std::string& a6,
228 const std::string& a7,
const std::string& a8,
const std::string& a9,
229 const std::string& a10,
const std::string& a11,
const std::string& a12,
230 const std::string& a13,
const std::string& a14,
const std::string& a15) {
248 const std::string& a1,
const std::string& a2,
const std::string& a3,
249 const std::string& a4,
const std::string& a5,
const std::string& a6,
250 const std::string& a7,
const std::string& a8,
const std::string& a9,
251 const std::string& a10,
const std::string& a11,
const std::string& a12,
252 const std::string& a13,
const std::string& a14,
const std::string& a15,
253 const std::string& a16) {
272 const std::string& a1,
const std::string& a2,
const std::string& a3,
273 const std::string& a4,
const std::string& a5,
const std::string& a6,
274 const std::string& a7,
const std::string& a8,
const std::string& a9,
275 const std::string& a10,
const std::string& a11,
const std::string& a12,
276 const std::string& a13,
const std::string& a14,
const std::string& a15,
277 const std::string& a16,
const std::string& a17) {
297 const std::string& a1,
const std::string& a2,
const std::string& a3,
298 const std::string& a4,
const std::string& a5,
const std::string& a6,
299 const std::string& a7,
const std::string& a8,
const std::string& a9,
300 const std::string& a10,
const std::string& a11,
const std::string& a12,
301 const std::string& a13,
const std::string& a14,
const std::string& a15,
302 const std::string& a16,
const std::string& a17,
const std::string& a18) {
323 const std::string& a1,
const std::string& a2,
const std::string& a3,
324 const std::string& a4,
const std::string& a5,
const std::string& a6,
325 const std::string& a7,
const std::string& a8,
const std::string& a9,
326 const std::string& a10,
const std::string& a11,
const std::string& a12,
327 const std::string& a13,
const std::string& a14,
const std::string& a15,
328 const std::string& a16,
const std::string& a17,
const std::string& a18,
329 const std::string& a19) {
351 const std::string& a1,
const std::string& a2,
const std::string& a3,
352 const std::string& a4,
const std::string& a5,
const std::string& a6,
353 const std::string& a7,
const std::string& a8,
const std::string& a9,
354 const std::string& a10,
const std::string& a11,
const std::string& a12,
355 const std::string& a13,
const std::string& a14,
const std::string& a15,
356 const std::string& a16,
const std::string& a17,
const std::string& a18,
357 const std::string& a19,
const std::string& a20) {
381inline std::string demangle(
const std::type_info& t) {
382#if HAVE_GCC_ABI_DEMANGLE
384 char* c_name = abi::__cxa_demangle(t.name(), 0, 0, &status);
385 std::string res(c_name);
393inline std::ostream& operator<<(std::ostream& out,
const std::type_info& t) {
394#if HAVE_GCC_ABI_DEMANGLE
396 char* c_name = abi::__cxa_demangle(t.name(), 0, 0, &status);
406inline std::string strerror(
const int error) {
407 std::array<char, 256> buf{};
410 if (!strerror_s(buf.data(), buf.size(), error)) {
return buf.data(); }
411#elif (_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE && !__ve
412 if(!strerror_r(error, buf.data(), buf.size())
417 return std::string{
"unknown error " + std::to_string(error)};
419 const char* msg = strerror_r(error, buf.data(), buf.size());
420 if (msg !=
nullptr) {
return msg; }
423 return std::string{
"unknown error " + std::to_string(error)};
426struct CompareFirstOfPair {
427 template <
typename T1,
typename T2>
428 bool operator()(
const T1& a,
const T2& b)
const {
429 return a.first < b.first;
433template <
typename T1,
typename T2,
typename T3,
typename T4>
434std::pair<T1, T2>& operator+=(std::pair<T1, T2>& i,
const std::pair<T3, T4>& j) {
436 i.second += j.second;
440inline double norm(
const float& v) {
return std::abs(v); }
442inline double norm(
const double& v) {
return std::abs(v); }
445inline b2000::csda<T>
norm(
const b2000::csda<T>& v) {
450inline T
norm(
const std::complex<T>& v) {
451 return std::abs(v.real()) + std::abs(v.imag());
455inline T max_abs(
const T& a,
const T& b) {
456 return std::max(b2000::norm(a), b2000::norm(b));
460inline b2000::csda<T> max_abs(
const b2000::csda<T>& a,
const b2000::csda<T>& b) {
461 return std::max(b2000::norm(a), b2000::norm(b));
465inline std::complex<T> max_abs(
const std::complex<T>& a,
const std::complex<T>& b) {
466 const T m = std::max(b2000::norm(a), b2000::norm(b));
467 return std::complex<T>(m);
470inline double real(
double v) {
return v; }
472inline double imag(
double v) {
return 0; }
475inline T real(b2000::csda<T> v) {
480inline T imag(b2000::csda<T> v) {
485inline T real(std::complex<T> v) {
490inline T imag(std::complex<T> v) {
494inline bool is_invalid_sqrt(
const float v) {
return v < 0; }
496inline bool is_invalid_sqrt(
const double v) {
return v < 0; }
499inline bool is_invalid_sqrt(
const b2000::csda<T> v) {
504inline bool is_invalid_sqrt(
const std::complex<T> v) {
508template <
typename _Tp1>
509struct auto_ptr_array_ref {
512 explicit auto_ptr_array_ref(_Tp1* __p) : _M_ptr(__p) {}
519template <
typename _Tp>
525 typedef _Tp element_type;
527 explicit auto_ptr_array(element_type* __p = 0) noexcept : _M_ptr(__p) {}
531 template <
typename _Tp1>
535 reset(__a.release());
539 template <
typename _Tp1>
541 reset(__a.release());
547 element_type& operator*()
const noexcept {
return *_M_ptr; }
549 element_type* operator->()
const noexcept {
return _M_ptr; }
551 element_type& operator[](
size_t i)
const noexcept {
return _M_ptr[i]; }
553 element_type* get()
const noexcept {
return _M_ptr; }
555 element_type* release()
noexcept {
556 element_type* __tmp = _M_ptr;
561 void reset(element_type* __p = 0)
noexcept {
568 auto_ptr_array(auto_ptr_array_ref<element_type> __ref) noexcept : _M_ptr(__ref._M_ptr) {}
570 auto_ptr_array& operator=(auto_ptr_array_ref<element_type> __ref)
noexcept {
571 if (__ref._M_ptr != this->get()) {
573 _M_ptr = __ref._M_ptr;
578 template <
typename _Tp1>
579 operator auto_ptr_array_ref<_Tp1>()
noexcept {
580 return auto_ptr_array_ref<_Tp1>(this->release());
583 template <
typename _Tp1>
589template <
class T1,
class T2>
590struct pair_iterator_reference {
594 pair_iterator_reference() : first(), second() {}
596 pair_iterator_reference(T1& a, T2& b) : first(a), second(b) {}
598 operator std::pair<T1, T2>()
const {
return std::pair<T1, T2>(first, second); }
600 pair_iterator_reference operator=(
const pair_iterator_reference& p) {
606 pair_iterator_reference operator=(
const std::pair<T1, T2>& p) {
611 friend void swap(pair_iterator_reference a, pair_iterator_reference b) {
613 swap(a.first, b.first);
614 swap(a.second, b.second);
618template <
typename Iterator1,
typename Iterator2>
619struct pair_iterator {
620 using iterator_category =
typename Iterator1::iterator_category;
621 using value_type = std::pair<typename Iterator1::value_type, typename Iterator2::value_type>;
622 using difference_type =
typename Iterator1::difference_type;
623 using pointer = std::pair<typename Iterator1::pointer, typename Iterator2::pointer>;
624 using reference = pair_iterator_reference<typename Iterator1::value_type, typename Iterator2::value_type>;
628 pair_iterator() : first(), second() {}
629 pair_iterator(
const Iterator1& a,
const Iterator2& b) : first(a), second(b) {}
630 pair_iterator(
const pair_iterator& i) : first(i.first), second(i.second) {}
631 pair_iterator& operator=(
const pair_iterator& i) {
636 reference operator*() {
return reference(*first, *second); }
637 value_type operator*()
const {
return value_type(*first, *second); }
638 reference operator->() {
return reference(*first, *second); }
639 pair_iterator& operator++() {
644 pair_iterator& operator--() {
649 pair_iterator operator++(
int) {
650 pair_iterator tmp(*
this);
655 pair_iterator operator--(
int) {
656 pair_iterator tmp(*
this);
661 pair_iterator& operator+=(
const difference_type n) {
666 pair_iterator& operator-=(
const difference_type n) {
671 pair_iterator operator+(
const difference_type n)
const {
672 return pair_iterator(first + n, second + n);
674 friend pair_iterator operator+(
const difference_type n,
const pair_iterator i) {
675 return pair_iterator(i.first + n, i.second + n);
677 pair_iterator operator-(
const difference_type n)
const {
678 return pair_iterator(first - n, second - n);
680 difference_type operator-(
const pair_iterator i)
const {
return first - i.first; }
681 reference operator[](
const difference_type n) {
return reference(first[n], second[n]); }
682 bool operator==(
const pair_iterator i)
const {
return first == i.first; }
683 bool operator!=(
const pair_iterator i)
const {
return first != i.first; }
684 bool operator<(
const pair_iterator i)
const {
return first < i.first; }
685 bool operator>(
const pair_iterator i)
const {
return first > i.first; }
686 bool operator<=(
const pair_iterator i)
const {
return first <= i.first; }
687 bool operator>=(
const pair_iterator i)
const {
return first >= i.first; }
690template <
class Key,
class Compare = std::less<Key> >
691class vector_set :
public std::vector<Key> {
693 vector_set(
const Compare& comp = Compare()) : comp_o(comp), set_o(Comp(*this, comp_o)) {
694 current = set_o.end();
697 size_t insert(
const Key& key) {
698 if (current != set_o.end()) {
699 if (comp_o.equal(key, (*
this)[*current])) {
705 const size_t pos = std::vector<Key>::size();
706 std::vector<Key>::push_back(key);
707 current = set_o.insert(current, pos);
708 if (*current != pos) { std::vector<Key>::pop_back(); }
712 size_t insert_cycle(
const Key& key) {
713 if (current != set_o.end()) {
714 if (comp_o.equal(key, (*
this)[*current])) {
return *current; }
716 if (current == set_o.end()) { current = set_o.begin(); }
717 if (comp_o.equal(key, (*
this)[*current])) {
return *current; }
719 const size_t pos = std::vector<Key>::size();
720 std::vector<Key>::push_back(key);
721 current = set_o.insert(current, pos);
722 if (*current != pos) { std::vector<Key>::pop_back(); }
726 size_t insert_equal_or_upper_to_top(
const Key& key) {
727 if (!std::vector<Key>::empty() && comp_o.equal(key, std::vector<Key>::back())) {
728 return std::vector<Key>::size() - 1;
730 std::vector<Key>::push_back(key);
731 return std::vector<Key>::size() - 1;
736 struct Comp :
public std::function<bool(size_t, size_t)> {
737 Comp(
const std::vector<Key>& vect_,
const Compare& comp_o_)
738 : vect(vect_), comp_o(comp_o_) {}
739 const std::vector<Key>& vect;
741 constexpr bool operator()(
const size_t& a,
const size_t& b)
const {
742 return comp_o(vect[a], vect[b]);
745 typedef std::set<size_t, Comp> set_t;
747 typename set_t::iterator current;
776 T& x1, T& x2, T& x3) {
791 T delta = c * c - 4 * b * d;
796 delta = std::sqrt(delta);
797 x1 = (-c + delta) / (2 * b);
801 x2 = (-c - delta) / (2 * b);
809 const T Q = (a1 * a1 - 3.0 * a2) / 9.0;
810 const T R = (2.0 * a1 * a1 * a1 - 9.0 * a1 * a2 + 27.0 * a3) / 54.0;
811 const T R2_Q3 = R * R - Q * Q * Q;
815 const T theta = std::acos(R / std::sqrt(Q * Q * Q));
816 const T pi = std::acos(T(-1));
817 x1 = -2.0 * std::sqrt(Q) * std::cos(theta / 3.0) - a1 / 3.0;
818 x2 = -2.0 * std::sqrt(Q) * std::cos((theta + 2.0 * pi) / 3.0) - a1 / 3.0;
819 x3 = -2.0 * std::sqrt(Q) * std::cos((theta + 4.0 * pi) / 3.0) - a1 / 3.0;
822 x1 = std::pow(std::sqrt(R2_Q3) + std::abs(R), 1 / 3.0);
824 x1 *= (R < 0.0) ? 1.0 : -1.0;
834 shared_ptr() : ptr_(0), ref_count_(nullptr) {}
836 shared_ptr(T* p) : ptr_(p), ref_count_(p ? new int : 0) { inc_ref(); }
838 shared_ptr(
const shared_ptr& rhs) : ptr_(rhs.ptr_), ref_count_(rhs.ref_count_) { inc_ref(); }
841 if (ref_count_ && dec_ref() == 0) {
847 T* get() {
return ptr_; }
849 const T* get()
const {
return ptr_; }
851 void swap(shared_ptr& rhs) {
852 std::swap(ptr_, rhs.ptr_);
853 std::swap(ref_count_, rhs.ref_count_);
856 shared_ptr& operator=(
const shared_ptr& rhs) {
862 T* operator->()
const {
return ptr_; }
864 T* operator*()
const {
return ptr_; }
868 if (ref_count_) { ++(*ref_count_); }
871 int dec_ref() {
return --(*ref_count_); }
877template <
typename T,
int i1>
878inline void fill_array(T (&t)[i1],
const T& v) {
879 std::fill_n(&t[0], i1, v);
882template <
typename T,
int i1,
int i2>
883inline void fill_array(T (&t)[i1][i2],
const T& v) {
884 std::fill_n(&t[0][0], i1 * i2, v);
887template <
typename T,
int i1,
int i2,
int i3>
888inline void fill_array(T (&t)[i1][i2][i3],
const T& v) {
889 std::fill_n(&t[0][0][0], i1 * i2 * i3, v);
892template <
typename T,
int i1,
int i2,
int i3,
int i4>
893inline void fill_array(T (&t)[i1][i2][i3][i4],
const T& v) {
894 std::fill_n(&t[0][0][0][0], i1 * i2 * i3 * i4, v);
897template <
typename T,
int i1>
898inline void copy_array(
const T (&t)[i1], T (&d)[i1]) {
899 std::copy(&t[0], &t[0] + i1, &d[0]);
902template <
typename T,
int i1,
int i2>
903inline void copy_array(
const T (&t)[i1][i2], T (&d)[i1][i2]) {
904 std::copy(&t[0][0], &t[0][0] + i1 * i2, &d[0][0]);
907template <
typename T,
int i1,
int i2,
int i3>
908inline void copy_array(
const T (&t)[i1][i2][i3], T (&d)[i1][i2][i3]) {
909 std::copy(&t[0][0][0], &t[0][0][0] + i1 * i2 * i3, &d[0][0][0]);
912template <
typename T,
int i1,
int i2,
int i3,
int i4>
913inline void copy_array(
const T (&t)[i1][i2][i3][i4], T (&d)[i1][i2][i3][i4]) {
914 std::copy(&t[0][0][0][0], &t[0][0][0][0] + i1 * i2 * i3 * i4, &d[0][0][0][0]);
bool operator>=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:316
bool operator<=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:298
csda< T > norm(const csda< T > &a)
Definition b2csda.H:343
bool operator==(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:226
bool operator>(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:280
bool operator!=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:244
bool operator<(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:262
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32
void solve_cubic_equation(const T a, const T b, const T c, const T d, int &nsol, T &x1, T &x2, T &x3)
Definition b2util.H:770