~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/atc/PerAtomQuantityLibrary.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
719
719
    InterscaleManager & interscaleManager(atc->interscale_manager());
720
720
    if (!atomVelocities_)
721
721
      atomVelocities_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_VELOCITY,
722
 
                                                                        atomType);
 
722
                                                                    atomType);
723
723
    if (!atomMasses_)
724
724
      atomMasses_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_MASS,
725
725
                                                                    atomType);
835
835
        LammpsInterface::ATOM_VELOCITY, atomType);
836
836
    }
837
837
    if (!atomMeanVelocities_) {
838
 
      atomMeanVelocities_ = interscaleManager.per_atom_quantity("AtomicMeanVelocity");
 
838
      atomMeanVelocities_ = interscaleManager.per_atom_quantity(field_to_prolongation_name(VELOCITY));
839
839
    }
840
840
 
841
841
    atomVelocities_->register_dependence(this);
980
980
      }
981
981
    }
982
982
  }
 
983
 
983
984
  //--------------------------------------------------------
984
985
  //--------------------------------------------------------
985
986
  //  Class TwiceFluctuatingKineticEnergy
1009
1010
                                                                atomType);
1010
1011
    }
1011
1012
    if (!atomMeanVelocities_) {
1012
 
      atomMeanVelocities_ = interscaleManager.per_atom_quantity("AtomicMeanVelocity");
 
1013
      atomMeanVelocities_ = interscaleManager.per_atom_quantity(field_to_prolongation_name(VELOCITY));
1013
1014
    }
1014
1015
 
1015
1016
    atomVelocities_->register_dependence(this);
1144
1145
                                                                atomType);
1145
1146
    }
1146
1147
    if (!atomMeanVelocities_) {
1147
 
      atomMeanVelocities_ = interscaleManager.per_atom_quantity("AtomicMeanVelocity");
 
1148
      atomMeanVelocities_ = interscaleManager.per_atom_quantity(field_to_prolongation_name(VELOCITY));
1148
1149
    }
1149
1150
 
1150
1151
    atomVelocities_->register_dependence(this);
1428
1429
    InterscaleManager & interscaleManager(atc->interscale_manager());
1429
1430
    if (!atomVelocities_)
1430
1431
      atomVelocities_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_VELOCITY,
1431
 
                                                                        atomType);
 
1432
                                                                    atomType);
1432
1433
    atomVelocities_->register_dependence(this);
1433
1434
  }
1434
1435
 
1923
1924
                                                           PerAtomQuantity<double> * atomLambdas,
1924
1925
                                                           AtomType atomType) :
1925
1926
    ProtectedAtomQuantity<double>(atc,1,atomType),
1926
 
    atomMasses_(NULL),
1927
1927
    atomLambdas_(atomLambdas)
1928
1928
  {
1929
1929
    InterscaleManager & interscaleManager(atc->interscale_manager());
1930
 
    atomMasses_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_MASS,
1931
 
                                                                  atomType);
1932
1930
    if (!atomLambdas) {
1933
1931
      atomLambdas_ = interscaleManager.per_atom_quantity("AtomLambdaEnergy");
1934
1932
    }
1935
 
 
1936
 
    atomMasses_->register_dependence(this);
1937
1933
    atomLambdas_->register_dependence(this);
1938
1934
  }
1939
1935
 
1942
1938
  //--------------------------------------------------------
1943
1939
  AtomicVelocityRescaleFactor::~AtomicVelocityRescaleFactor()
1944
1940
  {
1945
 
    atomMasses_->remove_dependence(this);
1946
1941
    atomLambdas_->remove_dependence(this);
1947
1942
  }
1948
1943
 
1953
1948
  {
1954
1949
    if (need_reset()) {
1955
1950
      PerAtomQuantity<double>::reset();
1956
 
      const DENS_MAT & mass(atomMasses_->quantity());
1957
1951
      const DENS_MAT & lambda(atomLambdas_->quantity());
1958
1952
 
1959
1953
      for (int i = 0; i < quantity_.nRows(); i++) {
1960
 
        quantity_(i,0) = sqrt(lambda(i,0)/mass(i,0));
 
1954
        quantity_(i,0) = sqrt(lambda(i,0));
 
1955
      }
 
1956
    }
 
1957
  }
 
1958
 
 
1959
  //--------------------------------------------------------
 
1960
  //--------------------------------------------------------
 
1961
  //  Class AtomicFluctuatingVelocityRescaled
 
1962
  //--------------------------------------------------------
 
1963
  //--------------------------------------------------------
 
1964
 
 
1965
  //--------------------------------------------------------
 
1966
  //  constructor
 
1967
  //--------------------------------------------------------
 
1968
  AtomicFluctuatingVelocityRescaled::AtomicFluctuatingVelocityRescaled(ATC_Method * atc,
 
1969
                                                                       PerAtomQuantity<double> * atomRescaleFactor,
 
1970
                                                                       PerAtomQuantity<double> * atomFluctuatingVelocity,
 
1971
                                                                       AtomType atomType) :
 
1972
    ProtectedAtomQuantity<double>(atc,atc->nsd(),atomType),
 
1973
    atomRescaleFactor_(atomRescaleFactor),
 
1974
    atomFluctuatingVelocity_(atomFluctuatingVelocity)
 
1975
  {
 
1976
    InterscaleManager & interscaleManager(atc->interscale_manager());
 
1977
    if (!atomRescaleFactor_) {
 
1978
      atomRescaleFactor_ = interscaleManager.per_atom_quantity("AtomVelocityRescaling");
 
1979
    }
 
1980
    if (!atomFluctuatingVelocity_) {
 
1981
      atomFluctuatingVelocity_ = interscaleManager.per_atom_quantity("AtomicFluctuatingVelocity");
 
1982
    }
 
1983
 
 
1984
    atomRescaleFactor_->register_dependence(this);
 
1985
    atomFluctuatingVelocity_->register_dependence(this);
 
1986
  }
 
1987
 
 
1988
  //--------------------------------------------------------
 
1989
  //  destructor
 
1990
  //--------------------------------------------------------
 
1991
  AtomicFluctuatingVelocityRescaled::~AtomicFluctuatingVelocityRescaled()
 
1992
  {
 
1993
    atomRescaleFactor_->remove_dependence(this);
 
1994
    atomFluctuatingVelocity_->remove_dependence(this);
 
1995
  }
 
1996
 
 
1997
  //--------------------------------------------------------
 
1998
  //  reset
 
1999
  //--------------------------------------------------------
 
2000
  void AtomicFluctuatingVelocityRescaled::reset() const
 
2001
  {
 
2002
    if (need_reset()) {
 
2003
      PerAtomQuantity<double>::reset();
 
2004
      const DENS_MAT & factor(atomRescaleFactor_->quantity());
 
2005
      const DENS_MAT & v(atomFluctuatingVelocity_->quantity());
 
2006
 
 
2007
      for (int i = 0; i < quantity_.nRows(); i++) {
 
2008
        for (int j = 0; j < quantity_.nCols(); j++) {
 
2009
          quantity_(i,j) = factor(i,0)*v(i,j);
 
2010
        }
 
2011
      }
 
2012
    }
 
2013
  }
 
2014
 
 
2015
  //--------------------------------------------------------
 
2016
  //--------------------------------------------------------
 
2017
  //  Class AtomicCombinedRescaleThermostatError
 
2018
  //--------------------------------------------------------
 
2019
  //--------------------------------------------------------
 
2020
 
 
2021
  //--------------------------------------------------------
 
2022
  //  constructor
 
2023
  //--------------------------------------------------------
 
2024
  AtomicCombinedRescaleThermostatError::AtomicCombinedRescaleThermostatError(ATC_Method * atc,
 
2025
                                                                             PerAtomQuantity<double> * atomFluctuatingMomentumRescaled,
 
2026
                                                                             PerAtomQuantity<double> * atomMeanVelocity,
 
2027
                                                                             PerAtomQuantity<double> * atomStreamingVelocity,
 
2028
                                                                             PerAtomQuantity<double> * atomMass,
 
2029
                                                                             AtomType atomType) :
 
2030
    ProtectedAtomQuantity<double>(atc,1,atomType),
 
2031
    atomFluctuatingMomentumRescaled_(atomFluctuatingMomentumRescaled),
 
2032
    atomMeanVelocity_(atomMeanVelocity),
 
2033
    atomStreamingVelocity_(atomStreamingVelocity),
 
2034
    atomMass_(atomMass)
 
2035
  {
 
2036
    InterscaleManager & interscaleManager(atc->interscale_manager());
 
2037
    if (!atomFluctuatingMomentumRescaled_) {
 
2038
      atomFluctuatingMomentumRescaled_ = interscaleManager.per_atom_quantity("AtomFluctuatingMomentumRescaled");
 
2039
    }
 
2040
    if (!atomMeanVelocity_) {
 
2041
      atomMeanVelocity_ = interscaleManager.per_atom_quantity(field_to_prolongation_name(VELOCITY));
 
2042
    }
 
2043
    if (!atomStreamingVelocity_) {
 
2044
      atomStreamingVelocity_ = interscaleManager.per_atom_quantity("AtomLambdaMomentum");
 
2045
    }
 
2046
    if (!atomMass_) {
 
2047
      atomMass_ = interscaleManager.fundamental_atom_quantity(LammpsInterface::ATOM_MASS,
 
2048
                                                              atomType);
 
2049
    }
 
2050
 
 
2051
    atomFluctuatingMomentumRescaled_->register_dependence(this);
 
2052
    atomMeanVelocity_->register_dependence(this);
 
2053
    atomStreamingVelocity_->register_dependence(this);
 
2054
    atomMass_->register_dependence(this);
 
2055
  }
 
2056
 
 
2057
  //--------------------------------------------------------
 
2058
  //  destructor
 
2059
  //--------------------------------------------------------
 
2060
  AtomicCombinedRescaleThermostatError::~AtomicCombinedRescaleThermostatError()
 
2061
  {
 
2062
    atomFluctuatingMomentumRescaled_->remove_dependence(this);
 
2063
    atomMeanVelocity_->remove_dependence(this);
 
2064
    atomStreamingVelocity_->remove_dependence(this);
 
2065
    atomMass_->remove_dependence(this);
 
2066
  }
 
2067
 
 
2068
  //--------------------------------------------------------
 
2069
  //  reset
 
2070
  //--------------------------------------------------------
 
2071
  void AtomicCombinedRescaleThermostatError::reset() const
 
2072
  {
 
2073
    if (need_reset()) {
 
2074
      PerAtomQuantity<double>::reset();
 
2075
      const DENS_MAT & m(atomMass_->quantity());
 
2076
      const DENS_MAT & p(atomFluctuatingMomentumRescaled_->quantity());
 
2077
      const DENS_MAT & v(atomMeanVelocity_->quantity());
 
2078
      const DENS_MAT & s(atomStreamingVelocity_->quantity());
 
2079
 
 
2080
      double diff;
 
2081
      for (int i = 0; i < quantity_.nRows(); i++) {
 
2082
        diff = s(i,0)-v(i,0);
 
2083
        quantity_(i,0) = 2.*p(i,0)*diff + m(i,0)*diff*diff;
 
2084
        for (int j = 1; j < p.nCols(); j++) {
 
2085
          diff = s(i,j)-v(i,j);
 
2086
          quantity_(i,0) += 2.*p(i,j)*diff + m(i,0)*diff*diff;
 
2087
        }
1961
2088
      }
1962
2089
    }
1963
2090
  }