/*!
        @file    action_F_Standard_SF.h
        @brief
        @author  Yusuke Taniguchi (maintained by H.Matsufuru)
                 $LastChangedBy: matufuru $
        @date    $LastChangedDate:: 2026-02-05 20:40:12 #$
        @version $LastChangedRevision: 2693 $
*/

#ifndef ACTION_FSTANDARD_SF_INCLUDED
#define ACTION_FSTANDARD_SF_INCLUDED

#include "Action/action.h"

#include "Force/Fermion/force_F.h"
#include "Solver/solver.h"

#include "Field/field_SF.h"

#include "IO/bridgeIO.h"
using Bridge::vout;

//! Standard fermion action with SF BC for HMC.

/*!
    This class defines an action with SF BC used in HMC.
    <ul>
    <li>Generated by copying Action_F_Standard class.
    <li>The argument Fopr and Force of the constructor should be implemented for the SF BC.
    <li>The only modification is in Action_F_Standard_SF::langevin
    <ul>
    <li>For the calculation of the initial Hamiltonian the pre-pseudo fermion field xi is set to zero at the boundary.
    <li>A private function set_boundary_zero(Field&) is introduced for this bounadry manipulation.
    <li>A few private members are added for this function.
    </ul>
    <li>The following properties are the same as those of the Action_F_Standard class.
    <ul>
    <li>Fermion and Force operators and given at the construction.
    <li>The solver is explicitly set to CG algorithm whose object is created in set_parameters().
    </ul>
    <li>[05 Apr 2012 Y.Yusuke]
    </ul>
    selector is implemented.       [02 Feb 2013 Y.Namekawa]
    (Selectors are replaced with factories by Aoyama-san)
    unique_ptr is introduced to avoid memory leaks
                                   [21 Mar 2015 Y.Namekawa]
    Multi-threading applied.       [01 Feb 2026 H.Matsufuru]
 */

class Action_F_Standard_SF : public Action
{
 public:
  static const std::string class_name;

 private:

  int Svol;            //!< A spatial volume in a node.
  int m_Nc2;           //!< number of the doubled color elements
  int m_Nd;            //!< dimension of the spinor index
  Bridge::VerboseLevel m_vl;

  std::string m_label;

  Communicator *comm;  //!< Needed to know a node at the temporal boundary.

  Fopr *m_fopr;

  Force *m_forceF;

  Field m_psf;

  Solver *m_solver;

  Field *m_U;

 public:
  Action_F_Standard_SF(Fopr *fopr, Force *forceF)
    : m_fopr(fopr), m_forceF(forceF)
  { init(); }

  Action_F_Standard_SF(Fopr *fopr, Force *forceF, const Parameters& params)
    : m_fopr(fopr), m_forceF(forceF)
  { init(params); }

  ~Action_F_Standard_SF()
  { tidyup(); }

  void set_parameters(const Parameters&);
  void set_parameters();

  void get_parameters(Parameters&) const;

  void set_label(const std::string label)
  {
    m_label = label;
    vout.detailed(m_vl, "  label: %s\n", m_label.c_str());
  }

  std::string get_label()
  { return m_label; }

  void set_config(Field *U);

  double langevin(RandomNumbers *);

  double calcH();

  void force(Field&);

private:

  void init();

  void init(const Parameters& params);

  void tidyup();

};
#endif
