@@ -227,6 +227,9 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_Hs(
227227 this ->energy = this ->post_2D .cal_energy (
228228 this ->post_2D .saves [" Ds_" +save_names_suffix[2 ]],
229229 this ->post_2D .set_tensors_map2 (this ->Hs ) );
230+
231+ if (!this ->flag_save_result .Hs )
232+ this ->Hs .clear ();
230233}
231234
232235template <typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
@@ -247,7 +250,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
247250 std::map<TA,Tdata> force_ipos;
248251
249252 {
250- std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs;
253+ this -> dHs [ipos][ 0 ]. clear () ;
251254
252255 this ->lri .data_ab_name [Label::ab::a ] = " dCs_" +std::to_string (ipos)+" _" +save_names_suffix[3 ];
253256 this ->lri .data_ab_name [Label::ab::a0b0] = " Vs_" +save_names_suffix[1 ];
@@ -256,13 +259,13 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
256259 this ->lri .cal_loop3 (
257260 {Label::ab_ab::a0b0_a1b1,
258261 Label::ab_ab::a0b0_a1b2,},
259- dHs,
262+ this -> dHs [ipos][ 0 ] ,
260263 -1.0 );
261264
262265 this ->lri .cal_loop3 (
263266 {Label::ab_ab::a0b0_a2b1,
264267 Label::ab_ab::a0b0_a2b2},
265- dHs,
268+ this -> dHs [ipos][ 0 ] ,
266269 1.0 );
267270
268271 this ->lri .data_ab_name [Label::ab::a ] = " Cs_" +save_names_suffix[0 ];
@@ -271,55 +274,61 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_force(
271274 this ->lri .cal_loop3 (
272275 {Label::ab_ab::a0b0_a2b2,
273276 Label::ab_ab::a0b0_a2b1},
274- dHs,
277+ this -> dHs [ipos][ 0 ] ,
275278 1.0 );
276279
277280 this ->post_2D .cal_force (
278281 this ->post_2D .saves [" Ds_" +save_names_suffix[2 ]],
279- this ->post_2D .set_tensors_map2 (std::move ( dHs) ),
282+ this ->post_2D .set_tensors_map2 (this -> dHs [ipos][ 0 ] ),
280283 true ,
281284 force_ipos );
282285
283- // mul(D)
284- // this->Fs[ipos] = this->post_2D.cal_F(dHs);
285- // this->stress[ipos] = this->post_2D.cal_sttress(dHs);
286- // this->Fs[ipos][I] = \sum_J \sum_{i,j} dHs(i,j) * D(i,j)
286+ // mul(D)
287+ // this->Fs[ipos] = this->post_2D.cal_F(dHs);
288+ // this->stress[ipos] = this->post_2D.cal_sttress(dHs);
289+ // this->Fs[ipos][I] = \sum_J \sum_{i,j} dHs(i,j) * D(i,j)
290+
291+ if (!this ->flag_save_result .dHs )
292+ this ->dHs [ipos][0 ].clear ();
287293 }
288294
289295 {
290- std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs;
296+ this -> dHs [ipos][ 1 ]. clear () ;
291297
292298 this ->lri .cal_loop3 (
293299 {Label::ab_ab::a0b0_a2b2,
294300 Label::ab_ab::a0b0_a1b2},
295- dHs,
296- 1.0 );
301+ this -> dHs [ipos][ 1 ] ,
302+ - 1.0 );
297303
298304 this ->lri .data_ab_name [Label::ab::a0b0] = " Vs_" +save_names_suffix[1 ];
299305 this ->lri .data_ab_name [Label::ab::b ] = " dCs_" +std::to_string (ipos)+" _" +save_names_suffix[3 ];
300306
301307 this ->lri .cal_loop3 (
302308 {Label::ab_ab::a0b0_a1b1,
303309 Label::ab_ab::a0b0_a2b1},
304- dHs,
305- 1.0 );
310+ this -> dHs [ipos][ 1 ] ,
311+ - 1.0 );
306312
307313 this ->lri .cal_loop3 (
308314 {Label::ab_ab::a0b0_a1b2,
309315 Label::ab_ab::a0b0_a2b2},
310- dHs,
311- - 1.0 );
316+ this -> dHs [ipos][ 1 ] ,
317+ 1.0 );
312318
313319 this ->post_2D .cal_force (
314320 this ->post_2D .saves [" Ds_" +save_names_suffix[2 ]],
315- this ->post_2D .set_tensors_map2 (std::move ( dHs) ),
321+ this ->post_2D .set_tensors_map2 (this -> dHs [ipos][ 1 ] ),
316322 false ,
317323 force_ipos );
318324
319- // mul(D)
320- // this->Fs[ipos] -= this->post_2D.cal_F(dHs);
321- // this->stress[ipos] -= this->post_2D.cal_sttress(dHs);
322- // this->Fs[ipos][J] = \sum_I \sum_{i,j} dHs(i,j) * D(i,j)
325+ // mul(D)
326+ // this->Fs[ipos] -= this->post_2D.cal_F(dHs);
327+ // this->stress[ipos] -= this->post_2D.cal_sttress(dHs);
328+ // this->Fs[ipos][J] = \sum_I \sum_{i,j} dHs(i,j) * D(i,j)
329+
330+ if (!this ->flag_save_result .dHs )
331+ this ->dHs [ipos][1 ].clear ();
323332 }
324333 this ->force [ipos] = this ->post_2D .reduce_force (force_ipos);
325334 } // end for(ipos)
@@ -344,7 +353,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
344353 for (std::size_t ipos0=0 ; ipos0<Npos; ++ipos0)
345354 for (std::size_t ipos1=0 ; ipos1<Npos; ++ipos1)
346355 {
347- std::map<TA,std::map<TAC,Tensor<Tdata>>> dHs ;
356+ this -> dHRs [ipos0][ipos1]. clear () ;
348357
349358 this ->lri .data_ab_name [Label::ab::a ] = " dCRs_" +std::to_string (ipos0)+" _" +std::to_string (ipos1)+" _" +save_names_suffix[3 ];
350359 this ->lri .data_ab_name [Label::ab::a0b0] = " Vs_" +save_names_suffix[1 ];
@@ -353,7 +362,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
353362 this ->lri .cal_loop3 (
354363 {Label::ab_ab::a0b0_a1b1,
355364 Label::ab_ab::a0b0_a2b1},
356- dHs ,
365+ this -> dHRs [ipos0][ipos1] ,
357366 1.0 );
358367
359368 this ->lri .data_ab_name [Label::ab::a ] = " Cs_" +save_names_suffix[0 ];
@@ -362,7 +371,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
362371 this ->lri .cal_loop3 (
363372 {Label::ab_ab::a0b0_a1b1,
364373 Label::ab_ab::a0b0_a2b1},
365- dHs ,
374+ this -> dHRs [ipos0][ipos1] ,
366375 1.0 );
367376
368377 this ->lri .data_ab_name [Label::ab::a0b0] = " Vs_" +save_names_suffix[1 ];
@@ -371,12 +380,15 @@ void Exx<TA,Tcell,Ndim,Tdata>::cal_stress(
371380 this ->lri .cal_loop3 (
372381 {Label::ab_ab::a0b0_a1b1,
373382 Label::ab_ab::a0b0_a2b1},
374- dHs ,
383+ this -> dHRs [ipos0][ipos1] ,
375384 1.0 );
376385
377- this ->stress (ipos0,ipos1) = post_2D.cal_energy (
378- this ->post_2D .saves [" Ds_" +save_names_suffix[2 ]],
379- this ->post_2D .set_tensors_map2 (dHs));
386+ this ->stress (ipos0,ipos1) = post_2D.cal_energy (
387+ this ->post_2D .saves [" Ds_" +save_names_suffix[2 ]],
388+ this ->post_2D .set_tensors_map2 (this ->dHRs [ipos0][ipos1]));
389+
390+ if (!this ->flag_save_result .dHRs )
391+ this ->dHRs [ipos0][ipos1].clear ();
380392 }
381393}
382394
0 commit comments