testSpecies.C 3.41 KB
Newer Older
Francois Gygi committed
1 2 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
// 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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//
// testSpecies.C
//
// use: testSpecies uri
//

#include "Species.h"
#include "SpeciesReader.h"
#include <iostream>
#include <cassert>
#include <string>
using namespace std;

#ifdef USE_MPI
#include <mpi.h>
#endif
int main(int argc, char **argv)
{
#if USE_MPI
  MPI_Init(&argc,&argv);
#endif
  {
35

Francois Gygi committed
36 37 38 39 40
  if ( argc != 2 )
  {
    cerr << "use: testSpecies uri" << endl;
    return 1;
  }
41

42
  Species s("unknown_name");
43

44
  SpeciesReader rdr;
45

Francois Gygi committed
46
  string uri(argv[1]);
47

48 49 50 51
  cout << " s.uri() = " << s.uri() << endl;
  cout << " testSpecies: invoking SpeciesReader::uri_to_species:" << endl;
  rdr.uri_to_species(uri,s);
  cout << " SpeciesReader::uri_to_species done" << endl;
52

Francois Gygi committed
53
  const double rcps = 1.0;
54

Francois Gygi committed
55 56 57 58 59 60
  try
  {
    s.initialize(rcps);
  }
  catch ( SpeciesInitException& e )
  {
Francois Gygi committed
61
    cerr << " Exception in Species initialization: " << e.msg << endl;
Francois Gygi committed
62 63
    throw;
  }
64 65 66 67 68 69 70 71 72
  cout << s;

  cout << " testSpecies: output of species done" << endl;

  cout << " testSpecies: invoking s.info(cout):" << endl;
  s.info(cout);

  cout << " testSpecies: testing SpeciesReader::uri_to_string: " << endl;
  string xmlstr;
73
  rdr.uri_to_string(uri,"unknown",xmlstr);
74
  cout << xmlstr;
75

76
#if 0
77

Francois Gygi committed
78 79
  if ( ctxt.onpe0() )
  {
80

Francois Gygi committed
81 82 83 84
  double dr = 0.01;
  double dg = 0.02;
  double v,dv;

Francois Gygi committed
85
  int n = 1500;
86

Francois Gygi committed
87 88
  for ( int l = 0; l <= s.lmax(); l++ )
  {
Francois Gygi committed
89
    cout << "# " << n << " Vps(l=" << l << ",r) " << endl;
Francois Gygi committed
90 91 92 93 94 95
    for ( int i = 0; i < n; i++ )
    {
      double r = i * dr;
      s.vpsr(l,r,v);
      cout << r << " " << v << endl;
    }
Francois Gygi committed
96
    cout << endl << endl;
Francois Gygi committed
97

Francois Gygi committed
98 99 100 101 102 103 104 105 106 107 108
    cout << "# " << n << " phi(l=" << l << ",r) " << endl;
    for ( int i = 0; i < n; i++ )
    {
      double r = i * dr;
      double val;
      s.phi(l,r,val);
      cout << r << " " << val << endl;
    }
    cout << endl << endl;

    cout << "# " << n << " dVps(l=" << l << ",r)/dr " << endl;
Francois Gygi committed
109 110 111 112 113 114
    for ( int i = 0; i < n; i++ )
    {
      double r = i * dr;
      s.dvpsr(l,r,v,dv);
      cout << r << " " << dv << endl;
    }
Francois Gygi committed
115
    cout << endl << endl;
Francois Gygi committed
116
  }
117

Francois Gygi committed
118
  cout << "# " << n << " Vloc(g) " << endl;
Francois Gygi committed
119 120 121 122 123 124
  for ( int i = 0; i < n; i++ )
  {
    double g = i * dg;
    s.vlocg(g,v);
    cout << g << " " << v << endl;
  }
Francois Gygi committed
125
  cout << endl << endl;
126

Francois Gygi committed
127
  cout << "# " << n << " dVloc(g)/dg " << endl;
Francois Gygi committed
128 129 130 131 132 133
  for ( int i = 0; i < n; i++ )
  {
    double g = i * dg;
    s.dvlocg(g,v,dv);
    cout << g << " " << dv << endl;
  }
Francois Gygi committed
134
  cout << endl << endl;
135

Francois Gygi committed
136 137 138 139
  for ( int l = 0; l <= s.lmax(); l++ )
  {
    if ( l != s.llocal() )
    {
Francois Gygi committed
140
      cout << "# " << n << " Vnl(l=" << l << ",g) " << endl;
Francois Gygi committed
141 142 143 144 145 146
      for ( int i = 0; i < n; i++ )
      {
        double g = i * dg;
        s.vnlg(l,g,v);
        cout << g << " " << v << endl;
      }
Francois Gygi committed
147
      cout << endl << endl;
148

Francois Gygi committed
149
      cout << "# " << n << " dVnl(l=" << l << ",g)/dg " << endl;
Francois Gygi committed
150 151 152 153 154 155
      for ( int i = 0; i < n; i++ )
      {
        double g = i * dg;
        s.dvnlg(l,g,v,dv);
        cout << g << " " << dv << endl;
      }
Francois Gygi committed
156
      cout << endl << endl;
Francois Gygi committed
157 158
    }
  }
159

Francois Gygi committed
160 161 162 163 164 165 166 167 168
  } // onpe0
#endif

  }
#if USE_MPI
  MPI_Finalize();
#endif
  return 0;
}