Skip to content

Commit 7fcac1b

Browse files
committed
Use single definition of FieldMetric
1 parent 1b3b372 commit 7fcac1b

5 files changed

Lines changed: 57 additions & 67 deletions

File tree

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
21
#ifndef BOUT_CHRISTOFFELSYMBOLS_HXX
32
#define BOUT_CHRISTOFFELSYMBOLS_HXX
43

5-
#include "bout/field2d.hxx"
6-
#include "bout/field3d.hxx"
7-
#include "bout/metric_tensor.hxx"
8-
#include <bout/bout_types.hxx>
9-
10-
using FieldMetric = MetricTensor::FieldMetric;
4+
#include <bout/metric_tensor.hxx>
115

126
class Coordinates;
137

@@ -16,26 +10,26 @@ class ChristoffelSymbols {
1610
public:
1711
explicit ChristoffelSymbols(Coordinates& coordinates);
1812

19-
const FieldMetric& G1_11() const { return G1_11_m; }
20-
const FieldMetric& G1_22() const { return G1_22_m; }
21-
const FieldMetric& G1_33() const { return G1_33_m; }
22-
const FieldMetric& G1_12() const { return G1_12_m; }
23-
const FieldMetric& G1_13() const { return G1_13_m; }
24-
const FieldMetric& G1_23() const { return G1_23_m; }
25-
26-
const FieldMetric& G2_11() const { return G2_11_m; }
27-
const FieldMetric& G2_22() const { return G2_22_m; }
28-
const FieldMetric& G2_33() const { return G2_33_m; }
29-
const FieldMetric& G2_12() const { return G2_12_m; }
30-
const FieldMetric& G2_13() const { return G2_13_m; }
31-
const FieldMetric& G2_23() const { return G2_23_m; }
32-
33-
const FieldMetric& G3_11() const { return G3_11_m; }
34-
const FieldMetric& G3_22() const { return G3_22_m; }
35-
const FieldMetric& G3_33() const { return G3_33_m; }
36-
const FieldMetric& G3_12() const { return G3_12_m; }
37-
const FieldMetric& G3_13() const { return G3_13_m; }
38-
const FieldMetric& G3_23() const { return G3_23_m; }
13+
const bout::FieldMetric& G1_11() const { return G1_11_m; }
14+
const bout::FieldMetric& G1_22() const { return G1_22_m; }
15+
const bout::FieldMetric& G1_33() const { return G1_33_m; }
16+
const bout::FieldMetric& G1_12() const { return G1_12_m; }
17+
const bout::FieldMetric& G1_13() const { return G1_13_m; }
18+
const bout::FieldMetric& G1_23() const { return G1_23_m; }
19+
20+
const bout::FieldMetric& G2_11() const { return G2_11_m; }
21+
const bout::FieldMetric& G2_22() const { return G2_22_m; }
22+
const bout::FieldMetric& G2_33() const { return G2_33_m; }
23+
const bout::FieldMetric& G2_12() const { return G2_12_m; }
24+
const bout::FieldMetric& G2_13() const { return G2_13_m; }
25+
const bout::FieldMetric& G2_23() const { return G2_23_m; }
26+
27+
const bout::FieldMetric& G3_11() const { return G3_11_m; }
28+
const bout::FieldMetric& G3_22() const { return G3_22_m; }
29+
const bout::FieldMetric& G3_33() const { return G3_33_m; }
30+
const bout::FieldMetric& G3_12() const { return G3_12_m; }
31+
const bout::FieldMetric& G3_13() const { return G3_13_m; }
32+
const bout::FieldMetric& G3_23() const { return G3_23_m; }
3933

4034
// Transforms the ChristoffelSymbols by applying the given function to every element
4135
template <class F>
@@ -61,9 +55,9 @@ public:
6155
}
6256

6357
private:
64-
FieldMetric G1_11_m, G1_22_m, G1_33_m, G1_12_m, G1_13_m, G1_23_m;
65-
FieldMetric G2_11_m, G2_22_m, G2_33_m, G2_12_m, G2_13_m, G2_23_m;
66-
FieldMetric G3_11_m, G3_22_m, G3_33_m, G3_12_m, G3_13_m, G3_23_m;
58+
bout::FieldMetric G1_11_m, G1_22_m, G1_33_m, G1_12_m, G1_13_m, G1_23_m;
59+
bout::FieldMetric G2_11_m, G2_22_m, G2_33_m, G2_12_m, G2_13_m, G2_23_m;
60+
bout::FieldMetric G3_11_m, G3_22_m, G3_33_m, G3_12_m, G3_13_m, G3_23_m;
6761
};
6862

6963
#endif //BOUT_CHRISTOFFELSYMBOLS_HXX

include/bout/coordinates.hxx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ class Mesh;
5151
*/
5252
class Coordinates {
5353
public:
54-
#if BOUT_USE_METRIC_3D
55-
using FieldMetric = Field3D;
56-
#else
57-
using FieldMetric = Field2D;
58-
#endif
54+
using FieldMetric = bout::FieldMetric;
5955

6056
/// Constructor interpolating from another Coordinates object
6157
/// By default attempts to read staggered Coordinates from grid data source,
@@ -147,20 +143,20 @@ public:
147143
#endif
148144

149145
/// Covariant metric tensor
150-
const MetricTensor::FieldMetric& g_11() const { return covariantMetricTensor.g11(); }
151-
const MetricTensor::FieldMetric& g_22() const { return covariantMetricTensor.g22(); }
152-
const MetricTensor::FieldMetric& g_33() const { return covariantMetricTensor.g33(); }
153-
const MetricTensor::FieldMetric& g_12() const { return covariantMetricTensor.g12(); }
154-
const MetricTensor::FieldMetric& g_13() const { return covariantMetricTensor.g13(); }
155-
const MetricTensor::FieldMetric& g_23() const { return covariantMetricTensor.g23(); }
146+
const FieldMetric& g_11() const { return covariantMetricTensor.g11(); }
147+
const FieldMetric& g_22() const { return covariantMetricTensor.g22(); }
148+
const FieldMetric& g_33() const { return covariantMetricTensor.g33(); }
149+
const FieldMetric& g_12() const { return covariantMetricTensor.g12(); }
150+
const FieldMetric& g_13() const { return covariantMetricTensor.g13(); }
151+
const FieldMetric& g_23() const { return covariantMetricTensor.g23(); }
156152

157153
/// Contravariant metric tensor (g^{ij})
158-
const MetricTensor::FieldMetric& g11() const { return contravariantMetricTensor.g11(); }
159-
const MetricTensor::FieldMetric& g22() const { return contravariantMetricTensor.g22(); }
160-
const MetricTensor::FieldMetric& g33() const { return contravariantMetricTensor.g33(); }
161-
const MetricTensor::FieldMetric& g12() const { return contravariantMetricTensor.g12(); }
162-
const MetricTensor::FieldMetric& g13() const { return contravariantMetricTensor.g13(); }
163-
const MetricTensor::FieldMetric& g23() const { return contravariantMetricTensor.g23(); }
154+
const FieldMetric& g11() const { return contravariantMetricTensor.g11(); }
155+
const FieldMetric& g22() const { return contravariantMetricTensor.g22(); }
156+
const FieldMetric& g33() const { return contravariantMetricTensor.g33(); }
157+
const FieldMetric& g12() const { return contravariantMetricTensor.g12(); }
158+
const FieldMetric& g13() const { return contravariantMetricTensor.g13(); }
159+
const FieldMetric& g23() const { return contravariantMetricTensor.g23(); }
164160

165161
/// Covariant metric tensor
166162
const BoutReal& g_11(int x, int y, int z) const {

include/bout/g_values.hxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
21
#ifndef BOUT_GVALUES_HXX
32
#define BOUT_GVALUES_HXX
43

5-
#include "bout/metric_tensor.hxx"
4+
#include <bout/metric_tensor.hxx>
65

7-
using FieldMetric = MetricTensor::FieldMetric;
6+
class Coordinates;
87

98
/// `GValues` needs renaming, when we know what the name should be
109
class GValues {
1110
public:
1211
explicit GValues(const Coordinates& coordinates);
1312

14-
const FieldMetric& G1() const { return G1_m; }
15-
const FieldMetric& G2() const { return G2_m; }
16-
const FieldMetric& G3() const { return G3_m; }
13+
const bout::FieldMetric& G1() const { return G1_m; }
14+
const bout::FieldMetric& G2() const { return G2_m; }
15+
const bout::FieldMetric& G3() const { return G3_m; }
1716

1817
template <class F>
1918
void map(F function) {
@@ -23,7 +22,7 @@ public:
2322
}
2423

2524
private:
26-
FieldMetric G1_m, G2_m, G3_m;
25+
bout::FieldMetric G1_m, G2_m, G3_m;
2726
};
2827

2928
#endif //BOUT_GVALUES_HXX

include/bout/metric_tensor.hxx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
21
#ifndef BOUT_METRIC_TENSOR_HXX
32
#define BOUT_METRIC_TENSOR_HXX
43

5-
#include "bout/build_defines.hxx"
6-
#include "bout/field2d.hxx"
7-
#include "bout/field3d.hxx"
84
#include <bout/bout_types.hxx>
5+
#include <bout/build_defines.hxx>
6+
#include <bout/field2d.hxx>
7+
#include <bout/field3d.hxx>
98

109
#include <string>
1110
#include <utility>
1211

13-
class MetricTensor {
12+
namespace bout {
13+
#if BOUT_USE_METRIC_3D
14+
using FieldMetric = Field3D;
15+
#else
16+
using FieldMetric = Field2D;
17+
#endif
18+
} // namespace bout
1419

20+
class MetricTensor {
1521
public:
1622
#if BOUT_USE_METRIC_3D
17-
using FieldMetric = Field3D;
1823
using Metric2DSlice = const BoutReal*;
1924
#else
20-
using FieldMetric = Field2D;
2125
using Metric2DSlice = const BoutReal&;
2226
#endif
27+
using FieldMetric = bout::FieldMetric;
2328

2429
MetricTensor(FieldMetric g11, FieldMetric g22, FieldMetric g33, FieldMetric g12,
2530
FieldMetric g13, FieldMetric g23);

src/mesh/coordinates.cxx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,7 @@ void Coordinates::correctionForNonUniformMeshes(bool force_interpolate_from_cent
894894
localmesh->communicate(d1_dx_, d1_dy_, d1_dz_);
895895
}
896896

897-
MetricTensor::FieldMetric Coordinates::recalculateJacobian() const {
898-
899-
TRACE("Coordinates::jacobian");
897+
FieldMetric Coordinates::recalculateJacobian() const {
900898
try {
901899
// calculate Jacobian using g^-1 = det[g^ij], J = sqrt(g)
902900
auto g_matrix = g11() * g22() * g33() + 2.0 * g12() * g13() * g23()
@@ -912,9 +910,7 @@ MetricTensor::FieldMetric Coordinates::recalculateJacobian() const {
912910
}
913911
}
914912

915-
MetricTensor::FieldMetric Coordinates::recalculateBxy() const {
916-
return sqrt(g_22()) / J();
917-
}
913+
FieldMetric Coordinates::recalculateBxy() const { return sqrt(g_22()) / J(); }
918914

919915
void Coordinates::setParallelTransform(Options* mesh_options) {
920916

0 commit comments

Comments
 (0)