SampleStepper.C 5.4 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19
// SampleStepper.C
//
////////////////////////////////////////////////////////////////////////////////

#include "SampleStepper.h"
20
#include "Sample.h"
Francois Gygi committed
21
#include "Species.h"
Francois Gygi committed
22 23 24 25 26 27

#include <iostream>
#include <iomanip>
using namespace std;

////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
28
SampleStepper::SampleStepper(Sample& s) : s_(s)
29 30 31 32
{
  fion.resize(s_.atoms.nsp());
  for ( int is = 0; is < fion.size(); is++ )
    fion[is].resize(3*s_.atoms.na(is));
33

34 35 36 37 38 39 40 41
  sigma_eks.resize(6);
  sigma_kin.resize(6);
  sigma_ext.resize(6);
  sigma.resize(6);
  sigma_ext = valarray<double>(s.ctrl.ext_stress,6);
  const double gpa = 29421.5;
  sigma_ext /= gpa;
}
Francois Gygi committed
42 43 44 45

////////////////////////////////////////////////////////////////////////////////
SampleStepper::~SampleStepper(void)
{
46
  // print timer map
Francois Gygi committed
47 48 49 50 51 52 53 54 55
  for ( TimerMap::iterator i = tmap.begin(); i != tmap.end(); i++ )
  {
    double time = (*i).second.real();
    double tmin = time;
    double tmax = time;
    s_.ctxt_.dmin(1,1,&tmin,1);
    s_.ctxt_.dmax(1,1,&tmax,1);
    if ( s_.ctxt_.myproc()==0 )
    {
56 57
      string s = "name=\"" + (*i).first + "\"";
      cout << "<timing " << left << setw(22) << s
58 59
           << " min=\"" << setprecision(3) << tmin << "\""
           << " max=\"" << setprecision(3) << tmax << "\"/>"
60
           << endl;
Francois Gygi committed
61 62 63 64
    }
  }
}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
////////////////////////////////////////////////////////////////////////////////
void SampleStepper::print_stress(void)
{
  const double gpa = 29421.5;
  if ( s_.ctxt_.onpe0() )
  {
    cout.setf(ios::fixed,ios::floatfield);
    cout.setf(ios::right,ios::adjustfield);
    cout << setprecision(8);
    cout << " <stress_tensor unit=\"GPa\">" << endl;

    cout << "   <sigma_eks_xx> " << setw(12) << sigma_eks[0]*gpa
         << " </sigma_eks_xx>\n"
         << "   <sigma_eks_yy> " << setw(12) << sigma_eks[1]*gpa
         << " </sigma_eks_yy>\n"
         << "   <sigma_eks_zz> " << setw(12) << sigma_eks[2]*gpa
         << " </sigma_eks_zz>\n"
         << "   <sigma_eks_xy> " << setw(12) << sigma_eks[3]*gpa
         << " </sigma_eks_xy>\n"
         << "   <sigma_eks_yz> " << setw(12) << sigma_eks[4]*gpa
         << " </sigma_eks_yz>\n"
         << "   <sigma_eks_xz> " << setw(12) << sigma_eks[5]*gpa
         << " </sigma_eks_xz>\n\n";

    cout << "   <sigma_kin_xx> " << setw(12) << sigma_kin[0]*gpa
         << " </sigma_kin_xx>\n"
         << "   <sigma_kin_yy> " << setw(12) << sigma_kin[1]*gpa
         << " </sigma_kin_yy>\n"
         << "   <sigma_kin_zz> " << setw(12) << sigma_kin[2]*gpa
         << " </sigma_kin_zz>\n"
         << "   <sigma_kin_xy> " << setw(12) << sigma_kin[3]*gpa
         << " </sigma_kin_xy>\n"
         << "   <sigma_kin_yz> " << setw(12) << sigma_kin[4]*gpa
         << " </sigma_kin_yz>\n"
         << "   <sigma_kin_xz> " << setw(12) << sigma_kin[5]*gpa
         << " </sigma_kin_xz>\n\n";

    cout << "   <sigma_ext_xx> " << setw(12) << sigma_ext[0]*gpa
         << " </sigma_ext_xx>\n"
         << "   <sigma_ext_yy> " << setw(12) << sigma_ext[1]*gpa
         << " </sigma_ext_yy>\n"
         << "   <sigma_ext_zz> " << setw(12) << sigma_ext[2]*gpa
         << " </sigma_ext_zz>\n"
         << "   <sigma_ext_xy> " << setw(12) << sigma_ext[3]*gpa
         << " </sigma_ext_xy>\n"
         << "   <sigma_ext_yz> " << setw(12) << sigma_ext[4]*gpa
         << " </sigma_ext_yz>\n"
         << "   <sigma_ext_xz> " << setw(12) << sigma_ext[5]*gpa
         << " </sigma_ext_xz>\n\n";

    cout << "   <sigma_xx> " << setw(12) << sigma[0]*gpa
         << " </sigma_xx>\n"
         << "   <sigma_yy> " << setw(12) << sigma[1]*gpa
         << " </sigma_yy>\n"
         << "   <sigma_zz> " << setw(12) << sigma[2]*gpa
         << " </sigma_zz>\n"
         << "   <sigma_xy> " << setw(12) << sigma[3]*gpa
         << " </sigma_xy>\n"
         << "   <sigma_yz> " << setw(12) << sigma[4]*gpa
         << " </sigma_yz>\n"
         << "   <sigma_xz> " << setw(12) << sigma[5]*gpa
         << " </sigma_xz>\n";

    cout << " </stress_tensor>" << endl;
  }
}

////////////////////////////////////////////////////////////////////////////////
void SampleStepper::compute_sigma(void)
{
  sigma_kin = 0.0;
  // compute kinetic contribution to stress using velocities at time t0
Francois Gygi committed
137
  for ( int is = 0; is < s_.atoms.atom_list.size(); is++ )
138 139
  {
    int i = 0;
Francois Gygi committed
140 141
    double mass = s_.atoms.species_list[is]->mass() * 1822.89;
    for ( int ia = 0; ia < s_.atoms.atom_list[is].size(); ia++ )
142
    {
Francois Gygi committed
143
      Atom* pa = s_.atoms.atom_list[is][ia];
144 145 146 147
      D3vector v = pa->velocity();
      const double vx = v.x;
      const double vy = v.y;
      const double vz = v.z;
148

149 150 151 152 153 154
      sigma_kin[0] += mass * vx * vx;
      sigma_kin[1] += mass * vy * vy;
      sigma_kin[2] += mass * vz * vz;
      sigma_kin[3] += mass * vx * vy;
      sigma_kin[4] += mass * vy * vz;
      sigma_kin[5] += mass * vx * vz;
155

156 157 158 159
      i += 3;
    }
  }
  sigma_kin /= s_.wf.cell().volume();
160

161 162
  sigma = sigma_eks + sigma_kin - sigma_ext;
}