Skip to content

Commit bd7eac0

Browse files
dylan-copelandandersonw1
authored andcommitted
Sample mesh manager bug fix (#258)
* Bug fix. * Cleaning up a few things.
1 parent 208c292 commit bd7eac0

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

examples/prom/dg_advection_global_rom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ int main(int argc, char *argv[])
704704
if (merge)
705705
{
706706
mergeTimer.Start();
707-
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
708707
options = new CAROM::Options(U->Size(), max_num_snapshots, 1, update_right_SV);
709708
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);
710709
for (int paramID=0; paramID<nsets; ++paramID)

examples/prom/linear_elasticity_global_rom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ int main(int argc, char* argv[])
244244
if (merge)
245245
{
246246
mergeTimer.Start();
247-
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
248247
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
249248
update_right_SV);
250249
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);

examples/prom/maxwell_global_rom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ int main(int argc, char *argv[])
238238
if (merge)
239239
{
240240
mergeTimer.Start();
241-
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
242241
options = new CAROM::Options(fespace->GetTrueVSize(), max_num_snapshots, 1,
243242
update_right_SV);
244243
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);

examples/prom/poisson_global_rom.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ int main(int argc, char *argv[])
247247
if (merge)
248248
{
249249
mergeTimer.Start();
250-
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
251250
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots, 1,
252251
update_right_SV);
253252
generator = new CAROM::BasisGenerator(*options, isIncremental, basisName);

examples/prom/poisson_local_rom_greedy.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@ int main(int argc, char *argv[])
617617
if (calc_rel_error || (offline && basisIdentifiers.size() == 1))
618618
{
619619
mergeTimer.Start();
620-
std::unique_ptr<CAROM::BasisGenerator> basis_generator;
621620
options = new CAROM::Options(fespace.GetTrueVSize(), max_num_snapshots, 1,
622621
update_right_SV);
623622
generator = new CAROM::BasisGenerator(*options, isIncremental, loadBasisName);

lib/mfem/SampleMesh.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ void FindStencilElements(const vector<int>& sample_dofs_gid,
2929
for (int i = 0; i < dofs.Size(); i++)
3030
{
3131
const int dof_i = dofs[i] >= 0 ? dofs[i] : -1 - dofs[i];
32-
//int ltdof = fespace.GetLocalTDofNumber(dof_i);
3332
int global_dof = fespace.GetGlobalTDofNumber(dof_i);
3433
if (global_dof == *it)
3534
{
@@ -115,7 +114,6 @@ void GetLocalSampleMeshElements(ParMesh& pmesh, ParFiniteElementSpace& fespace,
115114

116115
// Construct the map of local true dofs to global true dofs.
117116
map<int, int> ltdof2gtdof;
118-
//const int ndofs = fespace.GetNDofs();
119117
const int ndofs = fespace.GetVSize();
120118
for (int i = 0; i < fespace.GetVSize(); ++i) {
121119
int ltdof = fespace.GetLocalTDofNumber(i);
@@ -390,8 +388,8 @@ void BuildSampleMesh(ParMesh& pmesh, vector<ParFiniteElementSpace*> & fespace,
390388
int numElVert = elVert.Size(); // number of vertices per element
391389
MFEM_VERIFY(numElVert > 0, "");
392390

393-
vector<int> my_element_vgid(
394-
numElVert*local_num_elems); // vertex global indices, for each element
391+
// vertex global indices, for each element
392+
vector<int> my_element_vgid(numElVert*local_num_elems);
395393
vector<double> my_element_coords(d*numElVert*local_num_elems);
396394

397395
for (set<int>::iterator it = elems.begin(); it != elems.end(); ++it) {
@@ -411,7 +409,7 @@ void BuildSampleMesh(ParMesh& pmesh, vector<ParFiniteElementSpace*> & fespace,
411409
Array<int> dofs;
412410
H1DummySpace.GetElementDofs(elId, dofs);
413411
MFEM_VERIFY(numElVert == dofs.Size(),
414-
""); // Assuming a bijection between vertices and H1 dummy space DOF's.
412+
"Assuming a bijection between vertices and H1 dummy space DOF's");
415413

416414
for (int i = 0; i < numElVert; ++i) {
417415
my_element_vgid[conn_idx++] = H1DummySpace.GetGlobalTDofNumber(dofs[i]);
@@ -464,10 +462,10 @@ void BuildSampleMesh(ParMesh& pmesh, vector<ParFiniteElementSpace*> & fespace,
464462
delete [] cts;
465463
delete [] offsets;
466464

467-
// element_vgid holds vertices as global ids. Vertices may be shared
465+
// element_vgid holds vertices as global ids. Vertices may be shared
468466
// between elements so we don't know the number of unique vertices in the
469-
// sample mesh. Find all the unique vertices and construct the map of
470-
// global dof ids to local dof ids (vertices). Keep track of the number of
467+
// sample mesh. Find all the unique vertices and construct the map of
468+
// global dof ids to local dof ids (vertices). Keep track of the number of
471469
// unique vertices.
472470
set<int> unique_gdofs;
473471
map<int, int> unique_gdofs_first_appearance;
@@ -534,8 +532,12 @@ void BuildSampleMesh(ParMesh& pmesh, vector<ParFiniteElementSpace*> & fespace,
534532
}
535533

536534
void GetLocalDofsToLocalElementMap(ParFiniteElementSpace& fespace,
537-
const vector<int>& dofs, const vector<int>& localNumDofs, const set<int>& elems,
538-
vector<int>& dofToElem, vector<int>& dofToElemDof, const bool useTDof)
535+
const vector<int>& dofs,
536+
const vector<int>& localNumDofs,
537+
const set<int>& elems,
538+
vector<int>& dofToElem,
539+
vector<int>& dofToElemDof,
540+
const bool useTDof)
539541
{
540542
int myid;
541543
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
@@ -568,8 +570,9 @@ void GetLocalDofsToLocalElementMap(ParFiniteElementSpace& fespace,
568570
if (ltdof == dofs[myoffset + i]) // dofs contains true DOF's.
569571
#endif
570572
{
571-
dofToElem[i] =
572-
elId; // Possibly overwrite another element index, which is fine since we just want any element index.
573+
// Possibly overwrite another element index, which is fine
574+
// since we just want any element index.
575+
dofToElem[i] = elId;
573576
dofToElemDof[i] = j;
574577
}
575578
}
@@ -622,8 +625,8 @@ void Set_s2sp(const int myid, const int num_procs, vector<int> const& spNtrue,
622625
// Gather all the sample DOF to element and element DOF indices.
623626
vector<int> mySampleToElement(2*local_num_sample_dofs[myid]);
624627

625-
mySampleToElement.assign(mySampleToElement.size(),
626-
-1); // Initialize with invalid values, to verify later that everything was set.
628+
// Initialize with invalid values, to verify later that everything was set.
629+
mySampleToElement.assign(mySampleToElement.size(), -1);
627630

628631
for (int s=0; s<nspaces; ++s) // Loop over subspaces
629632
{
@@ -673,9 +676,8 @@ void Set_s2sp(const int myid, const int num_procs, vector<int> const& spNtrue,
673676
spaceOS[i] = spaceOS[i-1] + spfespace[i-1]->GetVSize();
674677

675678
s2sp.resize(global_num_sample_dofs);
676-
677-
s2sp.assign(s2sp.size(),
678-
-1); // Initialize with invalid values, to verify later that everything was set.
679+
// Initialize with invalid values, to verify later that everything was set.
680+
s2sp.assign(s2sp.size(), -1);
679681

680682
for (int s=0; s<nspaces; ++s)
681683
os[s] = 0;
@@ -852,8 +854,6 @@ void Finish_s2sp_augmented(const int rank, const int nprocs,
852854
MFEM_VERIFY(it->second == sp, "");
853855
}
854856
}
855-
856-
//gid[(2*i) + 1] = s2sp[dofs_sub_to_sdofs[s][os + i]];
857857
}
858858
}
859859

@@ -863,7 +863,6 @@ void Finish_s2sp_augmented(const int rank, const int nprocs,
863863
for (int i=0; i<local_num_dofs_sub[s][p]; ++i)
864864
{
865865
const int g = allgid[offsets[p] + (2*i)];
866-
//const int sp = allgid[offsets[p] + (2*i) + 1]; ?? //why isn't this used? because it already set gi2sp, which is now used.
867866

868867
map<int, int>::const_iterator it = gi2sp.find(g);
869868
MFEM_VERIFY(it != gi2sp.end() && it->first == g, "");
@@ -883,11 +882,14 @@ void Finish_s2sp_augmented(const int rank, const int nprocs,
883882
{
884883
if (s2sp_[i] == -1)
885884
s2sp_[i] = s2sp[i];
886-
887-
MFEM_VERIFY(s2sp_[i] >= 0 && s2sp_[i] == s2sp[i], "");
885+
else
886+
MFEM_VERIFY(s2sp_[i] == s2sp[i], "Consistency check");
888887
}
889888
}
890889
}
890+
891+
for (int i=0; i<s2sp_.size(); ++i)
892+
MFEM_VERIFY(s2sp_[i] >= 0 && s2sp_[i] == s2sp[i], "");
891893
}
892894
#endif
893895

@@ -1162,7 +1164,8 @@ void SampleMeshManager::SetSampleMaps()
11621164
}
11631165
}
11641166

1165-
// For each variable v and each of the num_sample_dofs_per_proc[v][p] samples, set s2sp_var[v][] to be its index in sample_dofs
1167+
// For each variable v and each of the num_sample_dofs_per_proc[v][p]
1168+
// samples, set s2sp_var[v][] to be its index in sample_dofs.
11661169
s2sp_var.resize(nvar);
11671170
for (int v=0; v<nvar; ++v)
11681171
{
@@ -1179,7 +1182,8 @@ void SampleMeshManager::SetSampleMaps()
11791182
{
11801183
const int sample = sample_dofs_var[v][os + j];
11811184

1182-
// Note: this has quadratic complexity and could be improved with a std::map<int, int>, but it should not be a bottleneck.
1185+
// Note: this has quadratic complexity and could be improved
1186+
// with a std::map<int, int>, but it should not be a bottleneck.
11831187
int k = -1;
11841188
int cnt = 0;
11851189
for (set<int>::const_iterator it = sample_dofs_proc[space][p].begin();
@@ -1440,16 +1444,16 @@ void GatherDistributedMatrixRows_aux(const CAROM::Matrix& B, const int rdim,
14401444
if (allos0[i] <= all_sprows[sti] && all_sprows[sti] < allos1[i])
14411445
{
14421446
MFEM_VERIFY(0 <= st2sp[sti] - ossp && st2sp[sti] - ossp < Bsp.numRows(), "");
1447+
// Note that this may redundantly overwrite some rows corresponding to shared DOF's.
14431448
MPI_Recv(&Bsp(st2sp[sti] - ossp, 0), rdim, MPI_DOUBLE,
1444-
i, offsets[i]+j, MPI_COMM_WORLD,
1445-
&status); // Note that this may redundantly overwrite some rows corresponding to shared DOF's.
1449+
i, offsets[i]+j, MPI_COMM_WORLD, &status);
14461450
}
14471451
#else
14481452
if (allos0[i] <= all_sprows[Bsp_row] && all_sprows[Bsp_row] < allos1[i])
14491453
{
1454+
// Note that this may redundantly overwrite some rows corresponding to shared DOF's.
14501455
MPI_Recv(&Bsp(st2sp[Bsp_row], 0), rdim, MPI_DOUBLE,
1451-
i, offsets[i]+j, MPI_COMM_WORLD,
1452-
&status); // Note that this may redundantly overwrite some rows corresponding to shared DOF's.
1456+
i, offsets[i]+j, MPI_COMM_WORLD, &status);
14531457
}
14541458
#endif
14551459
++Bsp_row;
@@ -1623,8 +1627,8 @@ void SampleMeshManager::CreateSampleMesh()
16231627
MPI_INT, &all_sprows[0], &local_num_stencil_dofs[0],
16241628
offsets, MPI_INT, MPI_COMM_WORLD);
16251629

1626-
// Note that all_stencil_dofs may contain DOF's on different processes that are identical (shared DOF's), which is fine
1627-
// (see comments in Set_s2sp).
1630+
// Note that all_stencil_dofs may contain DOF's on different processes that
1631+
// are identical (shared DOF's), which is fine (see comments in Set_s2sp).
16281632

16291633
delete [] offsets;
16301634

0 commit comments

Comments
 (0)