outputMatlab.hh

Go to the documentation of this file.
1 
6 #ifndef OutputMatlabSpace_hh
7 #define OutputMatlabSpace_hh
8 
9 #include <iostream>
10 #include "basics/outputMatlab.hh"
11 
12 using namespace std;
13 
14 namespace concepts {
15 
16  // ********************************************************** outputMatlab **
17 
22  inline std::ostream& outputMatlab(std::ostream& os, const TMatrix<Real>& T)
23  {
24  typedef pair<int, Real> PID;
25  typedef vector<PID> VPID;
26  typedef map<int, VPID> M_I_VPID;
27 
28  M_I_VPID local_to_global;
29 
30  os << "[";
31 
32  uint cnt = 0;
33  for(uint i=0; i < T.n(); ++i) {
34  const TMatrix<Real>::Control* ctrl = T.control(i);
35  uint size = ctrl->sz;
36  int global_idx = ctrl->idx;
37 
38  for(uint j=0; j < size; ++j) {
39  const TMatrix<Real>::Data* d = T.data(cnt);
40  int local_idx = d->idx;
41  Real weight = d->data;
42 
43  local_to_global[local_idx].push_back(PID(global_idx, weight));
44 
45  ++cnt;
46  }
47  }
48 
49  for(M_I_VPID::const_iterator it = local_to_global.begin();
50  it != local_to_global.end(); ++it)
51  {
52 
53 
54  const VPID& targets = it->second;
55  for(uint i=0; i < targets.size(); ++i)
56  {
57  os << it->first << " " << targets[i].first << " "
58  << targets[i].second << "; ";
59  if (i % 3 == 2)
60  os << std::endl;
61  }
62  }
63 
64  os << "]";
65 
66  return os;
67  }
68 
73  inline std::ostream& outputMatlab(std::ostream& os, const TMatrixBase<Real>& T)
74  {
75  const TMatrix<Real>* Tm = dynamic_cast<const TMatrix<Real>*>(&T);
76  if (Tm)
77  outputMatlab(os, *Tm);
78  else
79  os << T;
80  return os;
81  }
82 
87  template<class F>
88  inline std::ostream& outputMatlab(std::ostream& os,
89  const ElementMatrix<F>& em)
90  {
91  const int N = em.n();
92  const int M = em.m();
93  os << "[" << std::endl;
94  for (int i = 0; i < M; ++i) {
95  for (int j = 0; j < N; ++j) {
96  outputMatlab(os << std::setw(2), em(i,j));
97  os << ((j == N-1) ? "" : " ");
98  } // for j
99  os << ((i == M-1) ? "" : "\n");
100  } // for i
101  return os << "]";
102  }
103 
104 } // namespace concepts
105 
106 #endif // OutputMatlabSpace_hh
std::ostream & outputMatlab(std::ostream &os, const ElementMatrix< F > &em)
Function for output of ElementMatrix to Matlab.
Definition: outputMatlab.hh:88
const TMatrix::Data * data(uint i) const
Returns the ith entry of the data array.
Definition: tmatrix.hh:604
const TMatrix::Control * control(uint i) const
Returns the ith entry of the control data array.
Definition: tmatrix.hh:601
Element matrix.
Definition: linearForm.hh:18
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich