testFunction3d.C 2.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2018 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
// 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/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// testFunction3d.C
//
////////////////////////////////////////////////////////////////////////////////
18
#include<iostream>
19
#include<iomanip>
20 21 22
#include "Function3d.h"
using namespace std;

23 24
// usage: ./testFunction3d file.xml

25 26
// Read a Function3d from an XML file and print contents as a cube file

27
int main(int argc, char** argv)
28 29
{
  Function3d f;
30 31 32 33 34 35
  if ( argc != 2 )
  {
    cerr << "usage: " << argv[0] << " file.xml" << endl;
    return 1;
  }
  f.read(argv[1]);
36

37 38 39
  cout << "function name: " << f.name << endl;
  cout << "function grid size: " << f.nx << " " << f.ny << " " << f.nz  << endl;
  cout << "function array size: " << f.val.size() << endl;
40 41

  double sum = 0.0;
42
  for ( int i = 0; i < f.val.size(); i++ )
43
  {
44
    sum += f.val[i]*f.val[i];
45
  }
46
  cout << "function norm2: " << sum / f.val.size() << endl;
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  f.write("output.xml");

  // output data in cube format on stdout
  cout << "Created by testFunction3d" << endl;
  cout << endl;
  cout << "8 0 0 0" << endl;
  cout << f.nx << " " << f.a / f.nx << endl;
  cout << f.ny << " " << f.b / f.ny << endl;
  cout << f.nz << " " << f.c / f.nz << endl;
  cout << "1 1 0.0 0.0 0.0" << endl;
  cout << "1 1 " << f.a << endl;
  cout << "1 1 " << f.b << endl;
  cout << "1 1 " << f.c << endl;
  cout << "1 1 " << f.a+f.b << endl;
  cout << "1 1 " << f.b+f.c << endl;
  cout << "1 1 " << f.c+f.a << endl;
  cout << "1 1 " << f.a+f.b+f.c << endl;
  cout.setf(ios::scientific,ios::floatfield);
  cout.precision(5);
67 68
  for ( int i = 0; i < f.val.size(); i++ )
  {
69 70 71
    cout << setw(13) << f.val[i];
    if ( ( (i+1) % 6 ) == 0 )
      cout << endl;
72
  }
73
  cout << endl;
74
}