1 /*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30 */
31
32 //#define WORLD_INSTANTIATE_STATIC_TEMPLATES
33
34 /*!
35 \file examples/sininteg.cc
36 \brief Compute the integral sin(x) x=0..10
37 \warning If you change this example, please update the "MADNESS Basics" module in the documentation (doc/getting_started/gstart_basics.dox).
38 \defgroup sininteg First example from getting started guide
39 \ingroup examples
40
41 Computes the integral
42 \f[
43 \int_0^{10} sin(x) dx
44 \f]
45 by projecting \f$ sin(x) \f$ into the discontinuous spectral element
46 basis and using the \c trace() method.
47 */
48
49 #warning If you changed this example, please update the "Getting started with MADNESS" documentation module.
50
51 #include <madness/mra/mra.h>
52
53 using namespace madness;
54
myf(const coord_1d & r)55 double myf(const coord_1d& r) {
56 return std::sin(r[0]);
57 }
58
main(int argc,char ** argv)59 int main(int argc, char** argv) {
60 initialize(argc, argv);
61 World world(SafeMPI::COMM_WORLD);
62
63 startup(world,argc,argv);
64
65 FunctionDefaults<1>::set_cubic_cell(0,10);
66
67 real_function_1d f = real_factory_1d(world).f(myf);
68
69 double integral = f.trace();
70
71 if (world.rank() == 0) print("The result is", integral);
72
73 finalize();
74 return 0;
75 }
76