Skip to content

Commit cb776e7

Browse files
committed
Test initial remapping between grids and parcels
Use quadrature points for finding the connectivity between grids and parcels instead of MLPACK library.
1 parent df75405 commit cb776e7

17 files changed

+248
-195
lines changed

external/geomtk

Submodule geomtk updated 84 files

src/AdvectionManager.cpp

Lines changed: 84 additions & 89 deletions
Large diffs are not rendered by default.

src/AdvectionManager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class AdvectionManager
1919
double radialMixing; // control the radial mixing degree
2020
double lateralMixing; // control the lateral mixing degree
2121
double restoreFactor; // control the base density restore degree
22-
23-
Tree *cellTree;
24-
mat cellCoords;
25-
vector<size_t> cellCoordsMap;
2622
public:
2723
AdvectionManager();
2824
virtual ~AdvectionManager();

src/Cartesian3DTest.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Cartesian3DTest() {
77

88
Cartesian3DTest::
99
~Cartesian3DTest() {
10-
delete _mesh;
11-
delete _domain;
1210
}
1311

1412
void Cartesian3DTest::
@@ -33,7 +31,9 @@ init(const ConfigManager &configManager, AdvectionManager &advectionManager) {
3331
// Initialize velocity field.
3432
velocityField.create(*_mesh, true, true);
3533
io.file(dataIdx).addField("double", FULL_DIMENSION,
36-
{&velocityField(0), &velocityField(1)});
34+
{&velocityField(0),
35+
&velocityField(1),
36+
&velocityField(2)});
3737
// Initialize advection manager.
3838
advectionManager.init(configManager, *_mesh);
3939
// Initialize density fields for input and output.
@@ -54,33 +54,42 @@ init(const ConfigManager &configManager, AdvectionManager &advectionManager) {
5454

5555
void Cartesian3DTest::
5656
setInitialCondition(AdvectionManager &advectionManager) {
57+
TimeLevelIndex<2> timeIdx;
5758
io.open(dataIdx);
59+
io.input<double>(dataIdx, timeIdx, {&velocityField(0),
60+
&velocityField(1),
61+
&velocityField(2)});
5862
double *q = new double[_mesh->totalNumGrid(CENTER)*densities.size()];
59-
int j = 0;\
60-
for (int t = 0; t < densities.size(); ++t) {
63+
int j = 0;
64+
for (arma::uword t = 0; t < densities.size(); ++t) {
6165
io.input<double>(dataIdx, {&densities[t]});
62-
for (int i = 0; i < _mesh->totalNumGrid(CENTER); ++i) {
66+
for (arma::uword i = 0; i < _mesh->totalNumGrid(CENTER); ++i) {
6367
q[j++] = densities[t](i);
6468
}
6569
}
66-
TimeLevelIndex<2> timeIdx;
6770
advectionManager.input(timeIdx, q);
71+
io.close(dataIdx);
6872
} // setInitialCondition
6973

7074
void Cartesian3DTest::
71-
advanceDynamics(AdvectionManager &advectionManager) {
72-
// Read in WRF-LES 3D flow.
75+
advanceDynamics(const TimeLevelIndex<2> &timeIdx,
76+
AdvectionManager &advectionManager) {
77+
io.open(dataIdx);
78+
io.input<double>(dataIdx, timeIdx, {&velocityField(0),
79+
&velocityField(1),
80+
&velocityField(2)});
81+
io.close(dataIdx);
82+
Interface::advanceDynamics(timeIdx, advectionManager);
7383
} // advanceDynamics
7484

7585
void Cartesian3DTest::
7686
output(const TimeLevelIndex<2> &timeIdx, AdvectionManager &advectionManager) {
7787
io.create(outputIdx);
78-
for (int t = 0; t < densities.size(); ++t) {
79-
for (int i = 0; i < _mesh->totalNumGrid(CENTER); ++i) {
80-
std::cout << advectionManager.density(timeIdx, t, i) << std::endl;
88+
for (arma::uword t = 0; t < densities.size(); ++t) {
89+
for (arma::uword i = 0; i < _mesh->totalNumGrid(CENTER); ++i) {
8190
densities[t](i) = advectionManager.density(timeIdx, t, i);
8291
}
83-
io.output<double>(outputIdx, timeIdx, {&densities[t]});
92+
io.output<double>(outputIdx, {&densities[t]});
8493
}
8594
io.close(outputIdx);
8695
} // output

src/Cartesian3DTest.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
class Cartesian3DTest
99
: public geomtk::AdvectionTestInterface<2, Domain, Mesh, Field<double>, VelocityField, IOManager> {
10-
int dataIdx;
10+
arma::uword dataIdx;
1111
public:
1212
typedef geomtk::AdvectionManagerInterface<2, Domain, Mesh, VelocityField> AdvectionManager;
13+
typedef geomtk::AdvectionTestInterface<2, Domain, Mesh, Field<double>, VelocityField, IOManager> Interface;
1314

1415
Cartesian3DTest();
1516
virtual ~Cartesian3DTest();
@@ -21,7 +22,8 @@ class Cartesian3DTest
2122
setInitialCondition(AdvectionManager &advectionManager);
2223

2324
virtual void
24-
advanceDynamics(AdvectionManager &advectionManager);
25+
advanceDynamics(const TimeLevelIndex<2> &timeIdx,
26+
AdvectionManager &advectionManager);
2527

2628
virtual void
2729
output(const TimeLevelIndex<2> &timeIdx,

src/MeshAdaptor.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MeshAdaptor() {
99

1010
MeshAdaptor::
1111
~MeshAdaptor() {
12-
for (int t = 0; t < _masses.size(); ++t) {
12+
for (uword t = 0; t < _masses.size(); ++t) {
1313
delete _masses[t];
1414
}
1515
}
@@ -19,6 +19,7 @@ init(const Mesh &mesh) {
1919
this->mesh = &mesh;
2020
_numConnectedParcel.resize(mesh.totalNumGrid(CENTER));
2121
_connectedParcels.resize(mesh.totalNumGrid(CENTER));
22+
_numContainedQuadraturePoint.resize(mesh.totalNumGrid(CENTER));
2223
_remapWeights.resize(mesh.totalNumGrid(CENTER));
2324
_numContainedParcel.resize(mesh.totalNumGrid(CENTER));
2425
_containedParcels.resize(mesh.totalNumGrid(CENTER));
@@ -32,43 +33,64 @@ addTracer(const string &name, const string &unit, const string &comment) {
3233

3334
void MeshAdaptor::
3435
resetTracers(const TimeLevelIndex<2> &timeIdx) {
35-
for (int t = 0; t < _masses.size(); ++t) {
36-
for (int i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
37-
(*_masses[t])(timeIdx, i);
36+
for (uword t = 0; t < _masses.size(); ++t) {
37+
for (uword i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
38+
(*_masses[t])(timeIdx, i) = 0;
3839
}
3940
}
4041
}
4142

4243
void MeshAdaptor::
4344
connectParcel(int cellIdx, Parcel *parcel, double weight) {
44-
#ifndef NDEBUG
45-
for (int i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
45+
for (uword i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
4646
if (_connectedParcels[cellIdx][i] == parcel) {
47-
REPORT_ERROR("Parcel (ID = " << parcel->ID() <<
48-
") has already been connected!");
47+
_numContainedQuadraturePoint[cellIdx][i]++;
48+
_remapWeights[cellIdx][i] += weight;
49+
return;
4950
}
5051
}
51-
#endif
5252
if (_numConnectedParcel[cellIdx] == _connectedParcels[cellIdx].size()) {
5353
_connectedParcels[cellIdx].push_back(parcel);
54+
_numContainedQuadraturePoint[cellIdx].push_back(1);
5455
_remapWeights[cellIdx].push_back(weight);
5556
} else {
5657
_connectedParcels[cellIdx][_numConnectedParcel[cellIdx]] = parcel;
58+
_numContainedQuadraturePoint[cellIdx][_numConnectedParcel[cellIdx]] = 1;
5759
_remapWeights[cellIdx][_numConnectedParcel[cellIdx]] = weight;
5860
}
5961
_numConnectedParcel[cellIdx]++;
6062
}
6163

6264
void MeshAdaptor::
6365
resetConnectedParcels() {
64-
for (int i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
66+
for (uword i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
6567
_numConnectedParcel[i] = 0;
6668
}
6769
}
6870

71+
uword MeshAdaptor::
72+
numContainedQuadraturePoint(int cellIdx, Parcel *parcel) const {
73+
for (uword i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
74+
if (_connectedParcels[cellIdx][i] == parcel) {
75+
return _numContainedQuadraturePoint[cellIdx][i];
76+
}
77+
}
78+
REPORT_ERROR("Parcel is not connected!");
79+
}
80+
6981
double MeshAdaptor::
7082
remapWeight(int cellIdx, Parcel *parcel) const {
71-
for (int i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
83+
for (uword i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
84+
if (_connectedParcels[cellIdx][i] == parcel) {
85+
return _remapWeights[cellIdx][i];
86+
}
87+
}
88+
REPORT_ERROR("Parcel is not connected!");
89+
}
90+
91+
double& MeshAdaptor::
92+
remapWeight(int cellIdx, Parcel *parcel) {
93+
for (uword i = 0; i < _numConnectedParcel[cellIdx]; ++i) {
7294
if (_connectedParcels[cellIdx][i] == parcel) {
7395
return _remapWeights[cellIdx][i];
7496
}
@@ -79,7 +101,7 @@ remapWeight(int cellIdx, Parcel *parcel) const {
79101
void MeshAdaptor::
80102
containParcel(int cellIdx, Parcel *parcel) {
81103
#ifndef NDEBUG
82-
for (int i = 0; i < _numContainedParcel[cellIdx]; ++i) {
104+
for (uword i = 0; i < _numContainedParcel[cellIdx]; ++i) {
83105
if (_containedParcels[cellIdx][i] == parcel) {
84106
REPORT_ERROR("Parcel (ID = " << parcel->ID() <<
85107
") has already been contained!");
@@ -91,13 +113,13 @@ containParcel(int cellIdx, Parcel *parcel) {
91113
} else {
92114
_containedParcels[cellIdx][_numContainedParcel[cellIdx]] = parcel;
93115
}
94-
parcel->hostCellIdx() = cellIdx;
116+
parcel->hostCellIndex() = cellIdx;
95117
_numContainedParcel[cellIdx]++;
96118
}
97119

98120
void MeshAdaptor::
99121
resetContainedParcels() {
100-
for (int i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
122+
for (uword i = 0; i < mesh->totalNumGrid(CENTER, mesh->domain().numDim()); ++i) {
101123
_numContainedParcel[i] = 0;
102124
}
103125
}

src/MeshAdaptor.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ namespace lasm {
88
class MeshAdaptor {
99
const Mesh *mesh;
1010
vector<Field<double, 2>*> _masses;
11-
vector<int> _numConnectedParcel;
11+
vector<uword> _numConnectedParcel;
1212
vector<vector<Parcel*> > _connectedParcels;
13+
vector<vector<uword> > _numContainedQuadraturePoint;
1314
vector<vector<double> > _remapWeights;
14-
vector<int> _numContainedParcel;
15+
vector<uword> _numContainedParcel;
1516
vector<vector<Parcel*> > _containedParcels;
1617
public:
1718
MeshAdaptor();
@@ -52,10 +53,16 @@ class MeshAdaptor {
5253
void
5354
resetConnectedParcels();
5455

56+
uword
57+
numContainedQuadraturePoint(int cellIdx, Parcel *parcel) const;
58+
5559
double
5660
remapWeight(int cellIdx, Parcel *parcel) const;
5761

58-
int
62+
double&
63+
remapWeight(int cellIdx, Parcel *parcel);
64+
65+
uword
5966
numConnectedParcel(int cellIdx) const {
6067
return _numConnectedParcel[cellIdx];
6168
}
@@ -70,7 +77,7 @@ class MeshAdaptor {
7077
void
7178
resetContainedParcels();
7279

73-
int
80+
uword
7481
numContainedParcel(int cellIdx) const {
7582
return _numContainedParcel[cellIdx];
7683
}

src/Parcel.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ init(int ID) {
3636
_detH.level(l) = -999.0;
3737
_invH.level(l).set_size(domain->numDim(), domain->numDim());
3838
_shapeSize.level(l).set_size(domain->numDim());
39-
_meshIdx.level(l).setNumDim(domain->numDim());
39+
_meshIndex.level(l).init(domain->numDim());
4040
}
4141
_U.set_size(domain->numDim(), domain->numDim());
4242
_V.set_size(domain->numDim(), domain->numDim());
@@ -53,7 +53,7 @@ updateDeformMatrix(const TimeLevelIndex<2> &timeIdx) {
5353
mat &H = _H.level(timeIdx);
5454
const field<BodyCoord> &y = SkeletonPoints::bodyCoords();
5555
const field<SpaceCoord> &x = _skeletonPoints->localSpaceCoords(timeIdx);
56-
const field<MeshIndex> &meshIdxs = _skeletonPoints->meshIdxs(timeIdx);
56+
const field<MeshIndex> &meshIndexs = _skeletonPoints->meshIndexs(timeIdx);
5757
if (domain->numDim() == 2) {
5858
// Calculate the elements of four matrices.
5959
double h11_1 = x[0](0)/y[0](0); double h21_1 = x[0](1)/y[0](0);
@@ -69,22 +69,22 @@ updateDeformMatrix(const TimeLevelIndex<2> &timeIdx) {
6969
double h21_1 = 0, h21_3 = 0, h22_2 = 0, h22_4 = 0, h23_5 = 0, h23_6 = 0;
7070
double h31_1 = 0, h31_3 = 0, h32_2 = 0, h32_4 = 0, h33_5 = 0, h33_6 = 0;
7171
double w1 = 0, w2 = 0, w3 = 0, w4 = 0, w5 = 0, w6 = 0;
72-
if (meshIdxs[0].isValid()) {
72+
if (meshIndexs[0].isValid()) {
7373
w1 = 1; h11_1 = x[0](0)/y[0](0); h21_1 = x[0](1)/y[0](0); h31_1 = x[0](2)/y[0](0);
7474
}
75-
if (meshIdxs[1].isValid()) {
75+
if (meshIndexs[1].isValid()) {
7676
w2 = 1; h12_2 = x[1](0)/y[1](1); h22_2 = x[1](1)/y[1](1); h32_2 = x[1](2)/y[1](1);
7777
}
78-
if (meshIdxs[2].isValid()) {
78+
if (meshIndexs[2].isValid()) {
7979
w3 = 1; h11_3 = x[2](0)/y[2](0); h21_3 = x[2](1)/y[2](0); h31_3 = x[2](2)/y[2](0);
8080
}
81-
if (meshIdxs[3].isValid()) {
81+
if (meshIndexs[3].isValid()) {
8282
w4 = 1; h12_4 = x[3](0)/y[3](1); h22_4 = x[3](1)/y[3](1); h32_4 = x[3](2)/y[3](1);
8383
}
84-
if (meshIdxs[4].isValid()) {
84+
if (meshIndexs[4].isValid()) {
8585
w5 = 1; h13_5 = x[4](0)/y[4](2); h23_5 = x[4](1)/y[4](2); h33_5 = x[4](2)/y[4](2);
8686
}
87-
if (meshIdxs[5].isValid()) {
87+
if (meshIndexs[5].isValid()) {
8888
w6 = 1; h13_6 = x[5](0)/y[5](2); h23_6 = x[5](1)/y[5](2); h33_6 = x[5](2)/y[5](2);
8989
}
9090
// The final matrix is the combination of the six.
@@ -118,30 +118,30 @@ updateDeformMatrix(const TimeLevelIndex<2> &timeIdx, const vec &S) {
118118
longAxisVertexY() = _invH.level(timeIdx)*_H.level(timeIdx)*_V.col(0);
119119
calcSpaceCoord(timeIdx, longAxisVertexY, longAxisVertexX);
120120
_filamentDegree.level(timeIdx) = _S[0]/_S.min();
121-
}
121+
} // updateDeformMatrix
122122

123123
void Parcel::
124124
resetSkeletonPoints(const TimeLevelIndex<2> &timeIdx, const Mesh &mesh) {
125125
const field<BodyCoord> &y = SkeletonPoints::bodyCoords();
126126
field<SpaceCoord> &x = _skeletonPoints->spaceCoords(timeIdx);
127-
field<MeshIndex> &meshIdxs = _skeletonPoints->meshIdxs(timeIdx);
128-
for (int i = 0; i < x.size(); ++i) {
127+
field<MeshIndex> &meshIndexs = _skeletonPoints->meshIndexs(timeIdx);
128+
for (uword i = 0; i < x.size(); ++i) {
129129
calcSpaceCoord(timeIdx, y[i], x[i]);
130-
meshIdxs[i].reset();
131-
meshIdxs[i].locate(mesh, x[i]);
130+
meshIndexs[i].reset();
131+
meshIndexs[i].locate(mesh, x[i]);
132132
}
133133
} // resetSkeletonPoints
134134

135135
void Parcel::
136136
updateVolume(const TimeLevelIndex<2> &timeIdx, double volume) {
137137
_detH.level(timeIdx) = volume;
138-
}
138+
} // updateVolume
139139

140140
void Parcel::
141141
updateShapeSize(const TimeLevelIndex<2> &timeIdx) {
142142
BodyCoord y(domain->numDim());
143143
SpaceCoord x(domain->numDim());
144-
for (int m = 0; m < domain->numDim(); ++m) {
144+
for (uword m = 0; m < domain->numDim(); ++m) {
145145
y() = _invH.level(timeIdx)*_H.level(timeIdx)*_V.col(m);
146146
calcSpaceCoord(timeIdx, y, x);
147147
_shapeSize.level(timeIdx)[m] = domain->calcDistance(x, _x.level(timeIdx));
@@ -171,10 +171,15 @@ shapeFunction(const TimeLevelIndex<2> &timeIdx,
171171

172172
void Parcel::
173173
connectCell(int cellIdx) {
174-
if (_numConnectedCell == _connectedCellIdxs.size()) {
175-
_connectedCellIdxs.push_back(cellIdx);
174+
for (uword i = 0; i < _numConnectedCell; ++i) {
175+
if (_connectedCellIndexs[i] == cellIdx) {
176+
return;
177+
}
178+
}
179+
if (_numConnectedCell == _connectedCellIndexs.size()) {
180+
_connectedCellIndexs.push_back(cellIdx);
176181
} else {
177-
_connectedCellIdxs[_numConnectedCell] = cellIdx;
182+
_connectedCellIndexs[_numConnectedCell] = cellIdx;
178183
}
179184
_numConnectedCell++;
180185
} // connectCell

0 commit comments

Comments
 (0)