Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Initialization of LOBPCG solver in parametric case #299

Merged
merged 53 commits into from
Sep 26, 2024
Merged
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ff004a4
Add boundary condition switch
siuwuncheung Apr 4, 2024
af1f38d
Output eigenvalue absolute error
siuwuncheung Apr 4, 2024
861bcdb
Make eigenfunction sign in FOM and ROM consistent
siuwuncheung Apr 4, 2024
e60ca5d
Clean up problems
siuwuncheung Apr 23, 2024
c523237
Change Gaussian radius
siuwuncheung Apr 23, 2024
333103d
Change calculation of Gaussian width
siuwuncheung Apr 24, 2024
0e1f903
Slight changes in example command lines
siuwuncheung May 22, 2024
8239b14
Change filenames
siuwuncheung May 22, 2024
157a2e9
Remove TODO
siuwuncheung May 22, 2024
6c7a0f8
Astyle
siuwuncheung May 22, 2024
8ab3481
Change filenames. Change calculation of Gaussian width
siuwuncheung May 30, 2024
e2add1b
Slight changes to filenames
siuwuncheung May 30, 2024
8e17778
Consistent sign over parameters and eigenvector ordering
siuwuncheung May 30, 2024
69812cf
Astyle
siuwuncheung May 30, 2024
958bd25
Fix visualization signs
siuwuncheung May 30, 2024
ec0d4c1
Fix stream names
siuwuncheung Jun 13, 2024
9e78052
Reset stream name
siuwuncheung Jun 13, 2024
1e864d6
Reorganize reference mode sign logic
siuwuncheung Jun 13, 2024
95d9533
Clean up
siuwuncheung Jun 13, 2024
8760daf
Change variable names
siuwuncheung Jun 13, 2024
1ebd1f2
Warning meesages
siuwuncheung Jun 13, 2024
91fba19
Astyle
siuwuncheung Jun 13, 2024
11d63b0
Normalize
siuwuncheung Jun 13, 2024
a819f82
Adjust Gaussian
siuwuncheung Jun 19, 2024
b4fc1fd
Rename variables
siuwuncheung Jun 19, 2024
88a9368
Remove verbose
siuwuncheung Jun 20, 2024
60f0013
Update example in header
siuwuncheung Jun 20, 2024
4d0abab
Fix failing CI
siuwuncheung Jun 20, 2024
16fc913
Updates
siuwuncheung Jul 9, 2024
a199925
Fix verbose
siuwuncheung Jul 9, 2024
2505aaa
Minor changes to verbose
siuwuncheung Jul 10, 2024
83fdd31
Merge branch 'master' into 3d_schrodinger
siuwuncheung Jul 10, 2024
825b330
Astyle
siuwuncheung Jul 11, 2024
42d09b7
Clean up
siuwuncheung Jul 11, 2024
b42ab46
Make muber of LOBPCG iterations an option
siuwuncheung Jul 18, 2024
4742344
Set up the Gaussians for the Li2 example
siuwuncheung Aug 8, 2024
f600575
Add variables
siuwuncheung Aug 19, 2024
4384d13
Add GTH potential
siuwuncheung Aug 19, 2024
de2e22c
Merge branch 'master' into Li2_example
siuwuncheung Aug 19, 2024
7d494bd
Slight modification
siuwuncheung Aug 22, 2024
f466b6f
Slight updates
siuwuncheung Aug 22, 2024
7441b0f
superposing gaussians
siuwuncheung Aug 22, 2024
77516d4
Minor changes to parameters
siuwuncheung Aug 29, 2024
6726436
Minor changes
siuwuncheung Aug 29, 2024
29631ce
Add loading
siuwuncheung Sep 5, 2024
6de0d5a
Use HypreParVector I/O instead of libROM I/O for this task
siuwuncheung Sep 5, 2024
407227b
Astyle
siuwuncheung Sep 5, 2024
7adae58
Add option to compare initialization
siuwuncheung Sep 12, 2024
38af1ba
Merge branch 'master' into lobpcg_initial
siuwuncheung Sep 12, 2024
f75855e
Minor change to example
siuwuncheung Sep 12, 2024
cd9dda8
Abort if no files found
siuwuncheung Sep 12, 2024
1222a80
Minor change
siuwuncheung Sep 19, 2024
32d545f
Make tolerences user-defined options
siuwuncheung Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions examples/prom/elliptic_eigenproblem_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int main(int argc, char *argv[])
double ef = 1.0;
int rdim = -1;
int verbose_level = 0;
bool prescribe_init = false;

int precision = 8;
cout.precision(precision);
Expand Down Expand Up @@ -163,6 +164,8 @@ int main(int argc, char *argv[])
"Reduced dimension.");
args.AddOption(&verbose_level, "-v", "--verbose",
"Set the verbosity level of the LOBPCG solver and preconditioner. 0 is off.");
args.AddOption(&prescribe_init, "-init", "--init", "-no-init", "--no-init",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a sample run with -init to illustrate the new feature?

"Prescribe custom Initialization of LOBPCG.");
args.AddOption(&lobpcg_niter, "-fi", "--fom-iter",
"Number of iterations for the LOBPCG solver.");
#ifdef MFEM_USE_SUPERLU
Expand Down Expand Up @@ -458,6 +461,32 @@ int main(int argc, char *argv[])
lobpcg->SetMassMatrix(*M);
lobpcg->SetOperator(*A);

if (prescribe_init && (fom || (offline && id > 0)))
{
HypreParVector** snapshot_vecs = new HypreParVector*[nev];
for (int i = 0; i < nev; i++)
{
std::string snapshot_filename = baseName + "ref_snapshot_" + std::to_string(i);
std::ifstream snapshot_infile(snapshot_filename + ".0");
dylan-copeland marked this conversation as resolved.
Show resolved Hide resolved
if (!snapshot_infile.good())
{
if (myid == 0) std::cout << "Failed to load " << snapshot_filename << std::endl;
break;
dylan-copeland marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
snapshot_vecs[i] = new HypreParVector();
snapshot_vecs[i]->Read(MPI_COMM_WORLD, snapshot_filename.c_str());
if (myid == 0) std::cout << "Loaded " << snapshot_filename << std::endl;
if (i == nev - 1)
dylan-copeland marked this conversation as resolved.
Show resolved Hide resolved
{
lobpcg->SetInitialVectors(nev, snapshot_vecs);
if (myid == 0) std::cout << "LOBPCG initial vectors set" << std::endl;
}
}
}
}

// 13. Compute the eigenmodes and extract the array of eigenvalues. Define a
// parallel grid function to represent each of the eigenmodes returned by
// the solver.
Expand All @@ -478,6 +507,12 @@ int main(int argc, char *argv[])
eigenfunction_i = lobpcg->GetEigenvector(i);
eigenfunction_i /= sqrt(InnerProduct(eigenfunction_i, eigenfunction_i));
generator->takeSample(eigenfunction_i.GetData());
if (prescribe_init && id == 0)
{
std::string snapshot_filename = baseName + "ref_snapshot_" + std::to_string(i);
const HypreParVector snapshot_vec = lobpcg->GetEigenvector(i);
snapshot_vec.Print(snapshot_filename.c_str());
}
}
}

Expand Down Expand Up @@ -585,6 +620,9 @@ int main(int argc, char *argv[])
// Calculate errors of eigenvectors
ostringstream mode_name_fom;
Vector mode_fom(numRowRB);
double eigenvalue_threshold = max(1e-6,
dylan-copeland marked this conversation as resolved.
Show resolved Hide resolved
0.02 * (eigenvalues_fom[nev-1] - eigenvalues_fom[0]));
std::cout << "eigenvalue_threshold = " << eigenvalue_threshold << std::endl;
for (int i = 0; i < nev; i++)
{
mode_name_fom << "eigenfunction_fom_" << setfill('0') << setw(2) << i << "."
Expand All @@ -598,12 +636,12 @@ int main(int argc, char *argv[])
eigenvector_i = 0.0;
for (int j = 0; j < nev; j++)
{
if (myid == 0 && verbose_level > 0)
if (myid == 0)
{
std::cout << "correlation_matrix(" << j+1 << "," << i+1 << ") = " <<
InnerProduct(mode_fom, modes_rom[j]) << ";" << std::endl;
}
if (abs(eigenvalues_fom[j] - eigenvalues_fom[i]) < 1e-6)
if (abs(eigenvalues_fom[j] - eigenvalues_fom[i]) < eigenvalue_threshold)
{
eigenvector_i.Add(InnerProduct(mode_fom, modes_rom[j]), modes_rom[j]);
}
Expand Down Expand Up @@ -908,8 +946,7 @@ double Potential(const Vector &x)
if (potential_well_switch == 0 || potential_well_switch == 1)
{
// add well with first center
center(0) = (23 * bb_min[0] + 13 * bb_max[0]) / 36 -
0.5 * h_max * pseudo_time * (bb_min[0] + bb_max[0]);
center(0) = (23 * bb_min[0] + 13 * bb_max[0]) / 36 - h_max * pseudo_time;
d_sq = x.DistanceSquaredTo(center);
radius_sq = pow(0.28 * L, 2.0);
rho += -28.9 * std::exp(-d_sq / (2 * radius_sq));
Expand All @@ -919,8 +956,7 @@ double Potential(const Vector &x)
if (potential_well_switch == 0 || potential_well_switch == 2)
{
// add well with second center
center(0) = (13 * bb_min[0] + 23 * bb_max[0]) / 36 +
0.5 * h_max * pseudo_time * (bb_min[0] + bb_max[0]);
center(0) = (13 * bb_min[0] + 23 * bb_max[0]) / 36 + h_max * pseudo_time;
d_sq = x.DistanceSquaredTo(center);
radius_sq = pow(0.28 * L, 2.0);
rho += -28.9 * std::exp(-d_sq / (2 * radius_sq));
Expand All @@ -945,7 +981,7 @@ double Potential(const Vector &x)
if (potential_well_switch == 0 || potential_well_switch == 1)
{
// add well with first center
center(0) = (23 * bb_min[0] + 13 * bb_max[0]) / 36 - pseudo_time * h_max;
center(0) = (23 * bb_min[0] + 13 * bb_max[0]) / 36 - h_max * pseudo_time;
d_sq = x.DistanceSquaredTo(center);
alpha = d_sq / pow(L * rloc, 2.0);
rho += exp(-0.5 * alpha) * (c1 + c2 * alpha + c3 * alpha * alpha + c4 * alpha *
Expand All @@ -962,7 +998,7 @@ double Potential(const Vector &x)
if (potential_well_switch == 0 || potential_well_switch == 2)
{
// add well with second center
center(0) = (13 * bb_min[0] + 23 * bb_max[0]) / 36 + pseudo_time * h_max;
center(0) = (13 * bb_min[0] + 23 * bb_max[0]) / 36 + h_max * pseudo_time;
d_sq = x.DistanceSquaredTo(center);
alpha = d_sq / pow(L * rloc, 2.0);
rho += exp(-0.5 * alpha) * (c1 + c2 * alpha + c3 * alpha * alpha + c4 * alpha *
Expand Down
Loading