7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE
12 #include <boost/test/unit_test.hpp>
13 #include <boost/tokenizer.hpp>
14 #include <boost/algorithm/string.hpp>
15 #include "fparser/fparser.hh"
23 using namespace boost;
37 BOOST_AUTO_TEST_SUITE( math_integrate_test_suite )
42 Real result = integrate(
f(), 0., 1.);
52 BOOST_AUTO_TEST_SUITE_END()
56 class fparser_integral:
57 public FunctionParser::FunctionWrapper
61 const std::string&
name() {
return m_name; }
63 fparser_integral(
const std::string&
name,
const std::string& integrand,
const std::string& vars) : m_name(name), m_integrand(integrand,vars), integrate() {}
65 struct WrappedIntegrand
67 WrappedIntegrand(
const std::string& integrand,
const std::string& vars)
69 std::vector<std::string> deduced_vars;
70 func.ParseAndDeduceVariables(integrand,deduced_vars);
72 std::cout <<
"deduced = ";
74 std::cout << deduced_var << " ";
77 std::stringstream parse_vars;
78 std::vector<
std::
string> passed_vars; passed_vars.reserve(deduced_vars.size());
79 boost::char_separator<
char> sep(",");
80 typedef
boost::tokenizer<
boost::char_separator<
char> > tokenizer;
81 tokenizer tok (vars,sep);
83 for(tokenizer::iterator it=tok.begin(); it!=tok.end(); ++it)
85 if(idx>0) parse_vars <<
",";
88 passed_vars.push_back(*it);
92 std::vector<std::string> unknown_vars; unknown_vars.reserve(2);
99 if ( equals( passed_var, deduced_var) )
103 unknown_vars.push_back(deduced_var);
106 std::cout <<
"unknown = ";
108 std::cout << unknown << " ";
111 if(unknown_vars.size() != 2)
114 std::
string* dummy_var;
115 std::
string* integral_end;
116 if (unknown_vars[0].size() < unknown_vars[1].size())
118 if(idx>0) parse_vars <<
",";
119 parse_vars << unknown_vars[0];
120 var_idx[unknown_vars[0]] = idx++;
122 if(idx>0) parse_vars <<
",";
123 parse_vars << unknown_vars[1];
124 var_idx[unknown_vars[1]] = idx++;
128 if(idx>0) parse_vars <<
",";
129 parse_vars << unknown_vars[1];
130 var_idx[unknown_vars[1]] = idx++;
132 if(idx>0) parse_vars <<
",";
133 parse_vars << unknown_vars[0];
134 var_idx[unknown_vars[0]] = idx++;
140 std::cout <<
"parse_vars = " << parse_vars.str() << std::endl;
141 func.Parse(integrand, parse_vars.str());
144 Real operator()(Real
x)
const
152 mutable FunctionParser func;
154 mutable std::map<std::string,Uint> var_idx;
157 virtual double callFunction(
const double* values)
160 return integrate(m_integrand,values[0],values[1]);
166 WrappedIntegrand m_integrand;
171 BOOST_AUTO_TEST_SUITE( math_integrate_fparser_test_suite )
176 Real result = integrate(
f(), 0., 1.);
182 FunctionParser fparser;
184 fparser_integral my_integral(
"my_integral",
"sin(a*x)*dx",
"a");
185 fparser.AddFunctionWrapper(my_integral.name(), my_integral, 2);
187 fparser.Parse(
"my_integral(0,1)",
"a");
190 Real parsed_result = fparser.Eval(variables);
192 BOOST_CHECK_EQUAL(parsed_result,result);
200 BOOST_AUTO_TEST_SUITE_END()
#define CFinfo
these are always defined
std::string name(ComponentWrapper &self)
external boost library namespace
Basic Classes for Mathematical applications used by COOLFluiD.
#define boost_foreach
lowercase version of BOOST_FOREACH
Real operator()(Real x) const
BOOST_AUTO_TEST_CASE(test_integrate)
Uint nb_kernel_evaluations
Top-level namespace for coolfluid.
unsigned int Uint
typedef for unsigned int
Most basic kernel library.