1
/* Copyright (C) 2006 Imperial College London and others.
3
Please see the AUTHORS file in the main source directory for a full list
7
Applied Modelling and Computation Group
8
Department of Earth Science and Engineering
9
Imperial College London
11
g.gorman@imperial.ac.uk
13
This library is free software; you can redistribute it and/or
14
modify it under the terms of the GNU Lesser General Public
15
License as published by the Free Software Foundation; either
16
version 2.1 of the License.
18
This library is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
Lesser General Public License for more details.
23
You should have received a copy of the GNU Lesser General Public
24
License along with this library; if not, write to the Free Software
25
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29
#ifndef METRICTENSOR_H
30
#define METRICTENSOR_H
48
#error FLT_SMALL is already defined
50
#define FLT_SMALL (1.0E-12)
52
/** Performs basic operations on metric tensors.
57
MetricTensor(int dimension);
60
MetricTensor(double m11,
61
double m12, double m22);
64
MetricTensor(double m11,
65
double m12, double m22,
66
double m13, double m23, double m33);
68
/// Constructor - T stores the bottom triangle of the tensor.
69
MetricTensor(int dim, const double *T);
72
MetricTensor(const MetricTensor&);
74
/// Overloaded assignment operator.
75
const MetricTensor& operator=(const MetricTensor &);
77
/// Overloaded write operator.
78
friend std::ostream &operator<< (std::ostream&, const MetricTensor&);
80
/// Aspect ratio between the maximum and minimum edge lengths
81
/// required by the metric.
82
double aspect_ratio() const;
84
/// Average desired edge length
85
double average_length() const;
87
/// Calculates metric tensor that circumscribes this tensor and
88
/// input, M. This limits the minimum edge lengths anisotropically.
89
int circumscribe(const MetricTensor& M);
91
/// Determinant of tensor
94
/// Calculate eivenvalue decomposition of metric tensor.
95
/// @param D Eigenvalues
96
/// @param V Eigenvectors.
97
int eigen_decomp(double *D, double *V) const;
99
/// Construct metric tensor from eigenvalue decomposition.
100
/// @param D Eigenvalues
101
/// @param V Eigenvectors.
102
int eigen_undecomp(const double *D, const double *V);
104
/// Calculate the inner product between this tensor and M2
105
/// @returns Inner product.
106
MetricTensor dot(const MetricTensor &M2);
108
/// Pass back a copy of the bottom triangle of metric tensor into M (must be allocated by caller).
109
void get_metric(double *M) const;
111
/// Pass back a copy of the full metric tensor into M (must be allocated by caller).
112
void get_metric2(double *M) const;
114
/// Calculates metric tensor that inscribes this tensor and
115
/// input, M. This limits the maximum edge lengths anisotropically.
116
int inscribe(const MetricTensor& M);
118
/// Limit the maximum edge length.
119
int limit_max_size(const double *max_d);
121
/// Limit the minimum edge length.
122
int limit_min_size(const double *min_d);
124
/// Calculate inverse of metric tensor.
125
MetricTensor inv() const;
127
/// True if metric is null.
128
bool is_null() const;
130
/// Limit the aspect ratio of the desired edge lengths.
131
int limit_aspect(double);
133
/// Scale the metric tensor.
134
/// @param s Scale factor
135
void scale(double s);
137
/// Superimposes two metrics.
138
int superimpose(const MetricTensor& M);
140
/// Disable verbose mode.
143
/// Enable verbose mode.
146
/// Dump a copy of the metric as vtkPolyData. Must be configured with VTK support.
147
int write_vtk(const char *filename) const;
151
std::vector<double> metric;
154
/// BLAS [DS]PEV abstraction
155
int blas_spev(char jobz, char uplo, int N, const double ap[],
156
double eigenvalues[], double eigenvectors[], int ldz, double work[]) const;
158
/// Cofactor of index i, j
159
double cofactor(int i, int j) const;
161
/// Calculate eivenvalue decomposition of tensor T.
163
/// @param D Eigenvalues
164
/// @param V Eigenvectors.
165
int eigen_decomp(const double *T, double *D, double *V) const;
167
/// Construct metric tensor from eigenvalue decomposition.
169
/// @param D Eigenvalues
170
/// @param V Eigenvectors.
171
int eigen_undecomp(const double *D, const double *V, double *T) const;
174
/// In-place inversion of tensor.
175
int inv(double&, double&,
176
double&, double&) const;
178
/// In-place inversion of tensor.
179
int inv(double&, double&, double&,
180
double&, double&, double&,
181
double&, double&, double&) const;
183
/// Convert i, j index into lower-triangle index
184
int lookup(size_t i, size_t j) const;
186
/// Map self to the same space where M is the unit sphere
187
int map(const MetricTensor& M);
189
int MatrixDotMatrix(double *A, bool aT, double *B, bool bT, double *C) const;
190
void print_eigen(double *, double*) const;
192
/// Unmap M back from unit metric space.
193
int unmap(const MetricTensor& M);