@@ -54,6 +54,34 @@ TEST_F(BFGSTest, TestAllocate)
5454 EXPECT_EQ (bfgs.largest_grad ,0.0 );
5555}
5656
57+ // Test that relax_step will auto-initialize if not already initialized
58+ TEST_F (BFGSTest, RelaxStepAutoInitialize)
59+ {
60+ bfgs.is_initialized = false ;
61+
62+ UnitCell ucell;
63+ ucell.nat = 2 ;
64+ ucell.ntype = 1 ;
65+ ucell.atoms = new Atom[ucell.ntype ];
66+ ucell.atoms [0 ].na = 2 ;
67+ ucell.atoms [0 ].tau = std::vector<ModuleBase::Vector3<double >>(2 );
68+ ucell.atoms [0 ].taud = std::vector<ModuleBase::Vector3<double >>(2 );
69+ ucell.atoms [0 ].mbl = std::vector<ModuleBase::Vector3<int >>(2 , {1 , 1 , 1 });
70+ ucell.atoms [0 ].tau [0 ].x = 0.0 ; ucell.atoms [0 ].tau [0 ].y = 0.0 ; ucell.atoms [0 ].tau [0 ].z = 0.0 ;
71+ ucell.atoms [0 ].tau [1 ].x = 1.0 ; ucell.atoms [0 ].tau [1 ].y = 0.0 ; ucell.atoms [0 ].tau [1 ].z = 0.0 ;
72+ ucell.lat0 = 1.0 ;
73+
74+ ModuleBase::matrix force (2 , 3 );
75+ force (0 , 0 ) = 0.1 ; force (0 , 1 ) = 0.0 ; force (0 , 2 ) = 0.0 ;
76+ force (1 , 0 ) = -0.1 ; force (1 , 1 ) = 0.0 ; force (1 , 2 ) = 0.0 ;
77+
78+ // Before relax_step, is_initialized should be false
79+ EXPECT_FALSE (bfgs.is_initialized );
80+ bfgs.relax_step (force, ucell);
81+ // After relax_step, is_initialized should be true
82+ EXPECT_TRUE (bfgs.is_initialized );
83+ }
84+
5785// Test if a dimension less than or equal to 0 results in an assertion error
5886TEST_F (BFGSTest, TestAllocateWithZeroDimension)
5987{
@@ -103,10 +131,8 @@ TEST_F(BFGSTest, GetPosAndPostaud)
103131 ucell.atoms [0 ].mbl = std::vector<ModuleBase::Vector3<int >>(2 , {1 , 1 , 1 });
104132
105133 // set coordinates
106- ucell.atoms [0 ].tau [0 ].x = 1.0 ; ucell.atoms [0 ].tau [0 ].y = 2.0 ; ucell.atoms [0 ].tau [0 ].z = 3.0 ;
107- ucell.atoms [0 ].tau [1 ].x = 2.0 ; ucell.atoms [0 ].tau [1 ].y = 3.0 ; ucell.atoms [0 ].tau [1 ].z = 4.0 ;
108- ucell.atoms [0 ].taud [0 ].x = 0.1 ; ucell.atoms [0 ].taud [0 ].y = 0.2 ; ucell.atoms [0 ].taud [0 ].z = 0.3 ;
109- ucell.atoms [0 ].taud [1 ].x = 0.4 ; ucell.atoms [0 ].taud [1 ].y = 0.5 ; ucell.atoms [0 ].taud [1 ].z = 0.6 ;
134+ ucell.atoms [0 ].tau [0 ].x = 0.0 ; ucell.atoms [0 ].tau [0 ].y = 0.0 ; ucell.atoms [0 ].tau [0 ].z = 0.0 ;
135+ ucell.atoms [0 ].tau [1 ].x = 1.0 ; ucell.atoms [0 ].tau [1 ].y = 0.0 ; ucell.atoms [0 ].tau [1 ].z = 0.0 ;
110136
111137 // allocate mapping arrays
112138 ucell.iat2it = new int [ucell.nat ];
0 commit comments