CppNoddy  0.92
Loading...
Searching...
No Matches
FortranData.h
Go to the documentation of this file.
1/// \file FortranData.h
2
3#ifndef FORTRANDATA_H
4#define FORTRANDATA_H
5
6#include <Types.h>
7#include <Uncopyable.h>
8#include <Exceptions.h>
9
10namespace CppNoddy {
11 /// A little (legacy) utility class for passing CppNoddy containers to
12 /// Fortran library routines.
13 class FortranData : private Uncopyable {
14
15 public:
16
17 /// Make an empty FortranData object that is not constructed
18 /// from a CppNoddy container
19 explicit FortranData(std::size_t size) {
20 p_DATA = new DenseVector<double>(size, 0.0);
21 }
22
23 /// Make a FortranData object from a double dense matrix (with potential)
24 /// for padding the data to avoid cache contention. The transpose flag
25 /// defaults to true in order to return data in column-major format.
26 /// \param matrix A double dense matrix to convert to Lapack/Fortran format
27 /// \param transpose Transpose the matrix to be in column major format
28 /// \param padding The number of additional elements to pad the matrix
29 FortranData(DenseMatrix<double>& matrix, bool transpose = true, int padding = 0) {
30 p_DATA = new DenseVector<double>;
31 if(transpose) {
32 matrix.transpose();
33 }
34 matrix.matrix_to_vector(*p_DATA, padding);
35 }
36
37 /// Make a FortranData object from a complex dense matrix (with potential)
38 /// for padding the data to avoid cache contention. The transpose flag
39 /// defaults to true in order to return data in column-major format.
40 /// \param matrix A complex dense matrix to convert to Lapack/Fortran format
41 /// \param transpose Transpose the matrix to be in column major format
42 /// \param padding The number of additional elements to pad the matrix
43 FortranData(DenseMatrix<D_complex>& matrix, bool transpose = true, int padding = 0) {
44 p_DATA = new DenseVector<double>;
45 if(transpose) {
46 matrix.transpose();
47 }
48 matrix.matrix_to_vector(*p_DATA, padding);
49 }
50
51 FortranData(BandedMatrix<double>& matrix, bool transpose = true) {
52 std::string problem;
53 problem = "The default storage format for a banded matrix is now\n";
54 problem += "a contiguous column-major vector. You should not need to \n";
55 problem += "the FortranData method anymore.\n";
56 throw ExceptionRuntime(problem);
57 }
58
59 FortranData(BandedMatrix<D_complex>& matrix, bool transpose = true) {
60 std::string problem;
61 problem = "The default storage format for a banded matrix is now\n";
62 problem += "a contiguous column-major vector. You should not need to \n";
63 problem += "the FortranData method anymore.\n";
64 throw ExceptionRuntime(problem);
65 }
66
68 std::string problem;
69 problem = "This method is not required. Just use the base address of \n";
70 problem += "the first element and treat it as a vector of doubles.\n";
71 throw ExceptionRuntime(problem);
72 }
73
75 delete p_DATA;
76 }
77
78 /// Get the pointer to the first element.
79 /// \return The pointer to the base address.
80 double* base() {
81 return & (p_DATA -> operator[](0));
82 }
83
84 /// Get the reference to the first element.
85 /// \return The the i-th element in the vector
86 double& operator[](const std::size_t& i) {
87 return p_DATA -> operator[](i);
88 }
89
90 /// Find the number of stored elements.
91 /// \return The number of elements.
92 std::size_t size() const {
93 return p_DATA -> size();
94 }
95
96 /// Convert the data to a double dense format.
97 /// \param rows The number of required rows
98 /// \param cols The number of required columns
99 /// \return The DenseMatrix<double> of the data
100 DenseMatrix<double> to_dense_matrix(std::size_t rows, std::size_t cols) {
101 DenseMatrix<double> matrix(rows, cols, &(p_DATA->operator[](0)));
102 return matrix;
103 }
104
105 /// Dump the data to standard out.
106 void dump() {
107 p_DATA -> dump();
108 }
109
110 private:
111
112 // pointer to the base address of the data
113 DenseVector<double>* p_DATA;
114 };
115}
116
117#endif /*FORTRANDATA_H*/
The collection of CppNoddy exceptions.
Some standard typedefs.
A matrix class that constructs a BANDED matrix.
Definition: BandedMatrix.h:16
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
DenseVector< double > matrix_to_vector(const std::size_t &padding=0) const
Conversion to contiguous data in row major format Inefficient ... the void method is preferred.
void transpose()
Transpose the matrix.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A generic runtime exception.
Definition: Exceptions.h:158
A little (legacy) utility class for passing CppNoddy containers to Fortran library routines.
Definition: FortranData.h:13
FortranData(std::size_t size)
Make an empty FortranData object that is not constructed from a CppNoddy container.
Definition: FortranData.h:19
DenseMatrix< double > to_dense_matrix(std::size_t rows, std::size_t cols)
Convert the data to a double dense format.
Definition: FortranData.h:100
FortranData(DenseVector< D_complex > &vector)
Definition: FortranData.h:67
FortranData(BandedMatrix< D_complex > &matrix, bool transpose=true)
Definition: FortranData.h:59
FortranData(DenseMatrix< D_complex > &matrix, bool transpose=true, int padding=0)
Make a FortranData object from a complex dense matrix (with potential) for padding the data to avoid ...
Definition: FortranData.h:43
double & operator[](const std::size_t &i)
Get the reference to the first element.
Definition: FortranData.h:86
std::size_t size() const
Find the number of stored elements.
Definition: FortranData.h:92
FortranData(DenseMatrix< double > &matrix, bool transpose=true, int padding=0)
Make a FortranData object from a double dense matrix (with potential) for padding the data to avoid c...
Definition: FortranData.h:29
double * base()
Get the pointer to the first element.
Definition: FortranData.h:80
void dump()
Dump the data to standard out.
Definition: FortranData.h:106
FortranData(BandedMatrix< double > &matrix, bool transpose=true)
Definition: FortranData.h:51
An object to block copying.
Definition: Uncopyable.h:8
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt