Skip to content

Commit 671d02c

Browse files
committed
...EJB
1 parent 93bba15 commit 671d02c

3 files changed

Lines changed: 67 additions & 60 deletions

File tree

Nwpw/driver/optimize/combined_optimizer.cpp renamed to Nwpw/driver/optimize/alternating_optimizer.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// combined_optimizer.cpp
1+
// alternating_optimizer.cpp
22
//
33
// Alternating atom + lattice optimizer.
44
//
@@ -12,7 +12,7 @@
1212
// the atom phase from the current RTDB each call, so a cell change in
1313
// phase 2 is picked up correctly by the next atom phase.
1414

15-
#include "combined_optimizer.hpp"
15+
#include "alternating_optimizer.hpp"
1616
#include "lattice_common.hpp" // for compute_egs_values
1717

1818
#include <cmath>
@@ -41,19 +41,19 @@ double evaluate_energy(MPI_Comm comm,
4141

4242
} // namespace
4343

44-
int combined_optimizer(MPI_Comm comm,
45-
std::string& rtdbstring,
46-
std::ostream& coutput,
47-
electronic_minimizer minimizer,
48-
const AtomContext& atom_ctx,
49-
const LatticeContext& lattice_ctx,
50-
lattice_minimizer lm,
51-
int max_outer,
52-
double energy_tol)
44+
int alternating_optimizer(MPI_Comm comm,
45+
std::string& rtdbstring,
46+
std::ostream& coutput,
47+
electronic_minimizer minimizer,
48+
const AtomContext& atom_ctx,
49+
const LatticeContext& lattice_ctx,
50+
lattice_minimizer lm,
51+
int max_outer,
52+
double energy_tol)
5353
{
5454
if (lm == nullptr)
5555
{
56-
coutput << "combined_optimizer: null lattice minimizer\n";
56+
coutput << "alternating_optimizer: null lattice minimizer\n";
5757
return 1;
5858
}
5959

@@ -64,7 +64,7 @@ int combined_optimizer(MPI_Comm comm,
6464
{
6565
coutput << '\n'
6666
<< tag << "==============================================\n"
67-
<< tag << " PWDFT combined geometry + lattice optimization\n"
67+
<< tag << " PWDFT alternating geometry + lattice optimization\n"
6868
<< tag << " Alternating atom and cell phases\n"
6969
<< tag << " outer max = " << max_outer
7070
<< " E tol = " << energy_tol << '\n'
@@ -151,7 +151,7 @@ int combined_optimizer(MPI_Comm comm,
151151
{
152152
coutput << '\n'
153153
<< tag << "==============================================\n"
154-
<< tag << " PWDFT combined optimization COMPLETE\n"
154+
<< tag << " PWDFT alternating optimization COMPLETE\n"
155155
<< tag << "==============================================\n"
156156
<< tag << " Outer iterations : "
157157
<< (converged ? outer : outer + 1) << '\n'

Nwpw/driver/optimize/combined_optimizer.hpp renamed to Nwpw/driver/optimize/alternating_optimizer.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// combined_optimizer.hpp
1+
// alternating_optimizer.hpp
22
#pragma once
33

44
#include <mpi.h>
@@ -24,14 +24,14 @@ namespace pwdft {
2424
// Returns 0 on successful completion (including non-converged runs that
2525
// hit max_outer), non-zero if either phase reports a fatal error.
2626

27-
int combined_optimizer(MPI_Comm comm,
28-
std::string& rtdbstring,
29-
std::ostream& coutput,
30-
electronic_minimizer minimizer,
31-
const AtomContext& atom_ctx,
32-
const LatticeContext& lattice_ctx,
33-
lattice_minimizer lm,
34-
int max_outer = 10,
35-
double energy_tol = 1.0e-5);
27+
int alternating_optimizer(MPI_Comm comm,
28+
std::string& rtdbstring,
29+
std::ostream& coutput,
30+
electronic_minimizer minimizer,
31+
const AtomContext& atom_ctx,
32+
const LatticeContext& lattice_ctx,
33+
lattice_minimizer lm,
34+
int max_outer = 10,
35+
double energy_tol = 1.0e-5);
3636

3737
} // namespace pwdft

‎Nwpw/driver/optimize/driver_optimize.cpp‎

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
//#include "lattice_minimizer.hpp"
1818
#include "lattice_common.hpp"
1919
#include "atom_minimizer.hpp"
20-
#include "combined_optimizer.hpp"
20+
#include "alternating_optimizer.hpp"
21+
//#include "combined_optimizer.hpp"
2122

2223
//#include "gdevice.hpp"
2324

@@ -39,7 +40,8 @@ enum class RelaxCombinedTask {
3940
// --- 1. Classical Ground State Structural Modes ---
4041
GeometryOnly = 0, // Frozen cell box; adjust inner coordinates
4142
LatticeOnly = 1, // Frozen atom coordinates; scale bounding box
42-
Both = 2, // Co-optimize atoms and bounding box in tandem
43+
Alternating = 2, // Co-optimize atoms and bounding box in tandem
44+
Combined = 3, // Co-optimize atoms and bounding box in tandem
4345

4446
};
4547

@@ -335,7 +337,8 @@ int driver_optimizer(MPI_Comm comm_world0, std::string &rtdbstring, std::ostream
335337
//coutput << tag << " Cell optimization : RTDB unita_frozen reference lattice\n";
336338
if (driver_relax_type == RelaxCombinedTask::GeometryOnly) coutput << tag << " Geometry only optimization : RTDB unita_frozen reference lattice\n";
337339
if (driver_relax_type == RelaxCombinedTask::LatticeOnly) coutput << tag << " Lattice only optimization : RTDB unita_frozen reference lattice\n";
338-
if (driver_relax_type == RelaxCombinedTask::Both) coutput << tag << " Geometry and Cell optimization : RTDB unita_frozen reference lattice\n";
340+
if (driver_relax_type == RelaxCombinedTask::Alternating) coutput << tag << " Alternating Geometry and Cell optimization : RTDB unita_frozen reference lattice\n";
341+
if (driver_relax_type == RelaxCombinedTask::Combined) coutput << tag << " Combined Geometry and Cell optimization : RTDB unita_frozen reference lattice\n";
339342

340343
coutput << tag << " Numerical grid : fixed during optimization stage\n"
341344
<< tag << " Lattice tolerance : " << lattice_tolerance << '\n'
@@ -497,40 +500,44 @@ int driver_optimizer(MPI_Comm comm_world0, std::string &rtdbstring, std::ostream
497500
}
498501

499502
// Dispatch to the crystal-system-specific geometry and lattice minimizer.
500-
if (driver_relax_type == RelaxCombinedTask::Both)
503+
if (driver_relax_type == RelaxCombinedTask::Alternating)
504+
{
505+
// --- atom context ---
506+
AtomContext atom_ctx;
507+
atom_ctx.oprint = oprint;
508+
atom_ctx.tag = tag;
509+
atom_ctx.max_steps = control.driver_maxiter();
510+
atom_ctx.minimum_gradient = control.driver_gmax();
511+
atom_ctx.initial_step = control.driver_step();
512+
atom_ctx.use_symmetry = true;
513+
atom_ctx.ops = symmetry_info.ops;
514+
515+
// --- lattice context ---
516+
LatticeContext lat_ctx;
517+
lat_ctx.oprint = oprint;
518+
lat_ctx.tag = tag;
519+
lat_ctx.max_steps = control.driver_lattice_maxiter();
520+
lat_ctx.minimum_gradient = control.driver_lattice_gmax();
521+
lat_ctx.initial_step = control.driver_lattice_step();
522+
lat_ctx.minimum_step = control.driver_lattice_xmin();
523+
524+
// --- dispatched lattice minimizer ---
525+
lattice_minimizer lm = pick_lattice_minimizer(symmetry_info.system);
526+
527+
const int ierr = alternating_optimizer(comm_world0, rtdbstring, coutput,
528+
minimizer,
529+
atom_ctx, lat_ctx, lm,
530+
10, // max_outer
531+
1.0e-5); // energy_tol
532+
if (ierr != 0)
533+
{
534+
coutput << tag << " combined minimizer returned " << ierr << '\n';
535+
return ierr;
536+
}
537+
}
538+
539+
if (driver_relax_type == RelaxCombinedTask::Combined)
501540
{
502-
// --- atom context ---
503-
AtomContext atom_ctx;
504-
atom_ctx.oprint = oprint;
505-
atom_ctx.tag = tag;
506-
atom_ctx.max_steps = control.driver_maxiter();
507-
atom_ctx.minimum_gradient = control.driver_gmax();
508-
atom_ctx.initial_step = control.driver_step();
509-
atom_ctx.use_symmetry = true;
510-
atom_ctx.ops = symmetry_info.ops;
511-
512-
// --- lattice context ---
513-
LatticeContext lat_ctx;
514-
lat_ctx.oprint = oprint;
515-
lat_ctx.tag = tag;
516-
lat_ctx.max_steps = control.driver_lattice_maxiter();
517-
lat_ctx.minimum_gradient = control.driver_lattice_gmax();
518-
lat_ctx.initial_step = control.driver_lattice_step();
519-
lat_ctx.minimum_step = control.driver_lattice_xmin();
520-
521-
// --- dispatched lattice minimizer ---
522-
lattice_minimizer lm = pick_lattice_minimizer(symmetry_info.system);
523-
524-
const int ierr = combined_optimizer(comm_world0, rtdbstring, coutput,
525-
minimizer,
526-
atom_ctx, lat_ctx, lm,
527-
10, // max_outer
528-
1.0e-5); // energy_tol
529-
if (ierr != 0)
530-
{
531-
coutput << tag << " combined minimizer returned " << ierr << '\n';
532-
return ierr;
533-
}
534541
}
535542

536543
return 0;

0 commit comments

Comments
 (0)