1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <vector>
#include <complex> // <=====
using namespace std;
const double PI = 3.14159265358979323846;
const complex<double> I{ 0.0, 1.0 }; // <=====
void resfexact( vector<double> &xnodo, double k, complex<double> &pbal )
{
double r0 = 0.25;
complex<double> u0;
double r = sqrt( xnodo[0] * xnodo[0] + xnodo[1] * xnodo[1] + xnodo[2] * xnodo[2] );
u0 = 10.0 * I / ( 2.0 * PI * pow( k, 3 ) * pow( 343, 3 ) );
pbal = exp( -I * k * ( r - r0 ) ) * I * k * 1.21 * u0 * r0 * r0 / ( 343 * r * ( 1.0 + I * k * r0 ) );
}
void pistonff( vector<double> &xnodo, double k, double a, complex<double> &baliozehatz )
{
double f = k * 343 / ( 2.0 * PI );
double r = sqrt( xnodo[0] * xnodo[0] + xnodo[1] * xnodo[1] + xnodo[2] * xnodo[2] );
double theta = acos( xnodo[0] / r );
double besselfun1 = k * a * sin( theta ); // 1st order Bessel function
baliozehatz = -20.0 * 1.21 * PI * PI * exp( I * k * r ) * ( 2.0 * besselfun1 / ( k * a * sin( theta ) ) )
/ ( r * f * f );
}
int main()
{
double k = 0.1, a = 2.0;
vector<double> x = { 1.0, 2.0, 3.0 };
complex<double> pbal, baliozehatz;
resfexact( x, k, pbal );
pistonff( x, k, a, baliozehatz );
cout << "pbal = " << pbal << '\n';
cout << "baliozehatz = " << baliozehatz << '\n';
}
|