@@ -14,13 +14,13 @@ Magnetism::~Magnetism()
1414}
1515
1616void Magnetism::compute_mag (const double & omega,
17- const int & nrxx,
18- const int & nxyz,
19- const double * const * rho,
20- const int & nspin,
21- const bool & two_fermi,
22- const double & nelec,
23- double * nelec_spin)
17+ const int & nrxx,
18+ const int & nxyz,
19+ const double * const * rho,
20+ const int & nspin,
21+ const bool & two_fermi,
22+ const double & nelec,
23+ double * nelec_spin)
2424{
2525 assert (omega>0.0 );
2626 assert (nxyz>0 );
@@ -45,61 +45,61 @@ void Magnetism::compute_mag(const double& omega,
4545 this ->tot_mag *= fac;
4646 this ->abs_mag *= fac;
4747
48- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Total magnetism (Bohr mag/cell)" ,this ->tot_mag );
49- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Absolute magnetism (Bohr mag/cell)" ,this ->abs_mag );
50-
51- // update number of electrons for each spin
52- // if TWO_EFERMI, no need to update
53- if (!two_fermi)
54- {
55- nelec_spin[0 ] = (nelec + this ->tot_mag ) / 2 ;
56- nelec_spin[1 ] = (nelec - this ->tot_mag ) / 2 ;
57- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Electron number for spin up" , nelec_spin[0 ]);
58- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Electron number for spin down" , nelec_spin[1 ]);
59- }
48+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Total magnetism (Bohr mag/cell)" ,this ->tot_mag );
49+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Absolute magnetism (Bohr mag/cell)" ,this ->abs_mag );
50+
51+ // update number of electrons for each spin
52+ // if TWO_EFERMI, no need to update
53+ if (!two_fermi)
54+ {
55+ nelec_spin[0 ] = (nelec + this ->tot_mag ) / 2 ;
56+ nelec_spin[1 ] = (nelec - this ->tot_mag ) / 2 ;
57+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Electron number for spin up" , nelec_spin[0 ]);
58+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Electron number for spin down" , nelec_spin[1 ]);
59+ }
6060 }
6161
62- // noncolliear :
63- else if (nspin==4 )
64- {
65- for (int i=0 ;i<3 ;i++)
66- {
67- this ->tot_mag_nc [i] = 0.00 ;
68- }
69-
70- this ->abs_mag = 0.00 ;
71- for (int ir=0 ; ir<nrxx; ir++)
72- {
73- double diff = sqrt (pow (rho[1 ][ir], 2 ) + pow (rho[2 ][ir], 2 ) +pow (rho[3 ][ir], 2 ));
62+ // noncolliear :
63+ else if (nspin==4 )
64+ {
65+ for (int i=0 ;i<3 ;i++)
66+ {
67+ this ->tot_mag_nc [i] = 0.00 ;
68+ }
69+
70+ this ->abs_mag = 0.00 ;
71+ for (int ir=0 ; ir<nrxx; ir++)
72+ {
73+ double diff = sqrt (pow (rho[1 ][ir], 2 ) + pow (rho[2 ][ir], 2 ) +pow (rho[3 ][ir], 2 ));
7474
75- for (int i=0 ;i<3 ;i++)
76- {
77- this ->tot_mag_nc [i] += rho[i+1 ][ir];
78- }
79- this ->abs_mag += std::abs (diff);
80- }
75+ for (int i=0 ;i<3 ;i++)
76+ {
77+ this ->tot_mag_nc [i] += rho[i+1 ][ir];
78+ }
79+ this ->abs_mag += std::abs (diff);
80+ }
8181#ifdef __MPI
8282 Parallel_Reduce::reduce_pool (this ->tot_mag_nc , 3 );
8383 Parallel_Reduce::reduce_pool (this ->abs_mag );
8484#endif
85- for (int i=0 ;i<3 ;i++)
86- {
87- this ->tot_mag_nc [i] *= fac;
85+ for (int i=0 ;i<3 ;i++)
86+ {
87+ this ->tot_mag_nc [i] *= fac;
8888 // mohan add 2025-06-21
89- if ( std::abs (this ->tot_mag_nc [i]) < 1.0e-16 )
90- {
91- this ->tot_mag_nc [i] = 0.0 ;
92- }
93- }
89+ if ( std::abs (this ->tot_mag_nc [i]) < 1.0e-16 )
90+ {
91+ this ->tot_mag_nc [i] = 0.0 ;
92+ }
93+ }
9494
95- this ->abs_mag *= fac;
95+ this ->abs_mag *= fac;
9696
9797 // mohan update 2025-06-21
98- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Total magnetism (Bohr mag/cell)" ,
98+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Total magnetism (Bohr mag/cell)" ,
9999 this ->tot_mag_nc [0 ], this ->tot_mag_nc [1 ], this ->tot_mag_nc [2 ]);
100100
101- ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Absolute magnetism (Bohr mag/cell)" ,this ->abs_mag );
102- }
101+ ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Absolute magnetism (Bohr mag/cell)" ,this ->abs_mag );
102+ }
103103
104104 return ;
105105}
@@ -112,8 +112,8 @@ bool Magnetism::judge_parallel(const double a[3], const ModuleBase::Vector3<doub
112112 double cross=0.0 ;
113113
114114 cross = pow ((a[1 ]*b.z -a[2 ]*b.y ),2 )
115- + pow ((a[2 ]*b.x -a[0 ]*b.z ),2 )
116- + pow ((a[0 ]*b.y -a[1 ]*b.x ),2 );
115+ + pow ((a[2 ]*b.x -a[0 ]*b.z ),2 )
116+ + pow ((a[0 ]*b.y -a[1 ]*b.x ),2 );
117117
118118 jp = (fabs (cross)<1e-6 );
119119 return jp;
0 commit comments