Skip to content

Commit 2b4bf4a

Browse files
committed
test critical functions
1 parent b709874 commit 2b4bf4a

File tree

7 files changed

+160
-0
lines changed

7 files changed

+160
-0
lines changed

tests/test.cpp

Whitespace-only changes.

tests/test_geometry.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include <catch2/catch.hpp>
3+
#include <Eigen/Dense>
4+
#include "geometry.h"
5+
6+
TEST_CASE("nodal_coordinates_initial produces correct number of nodes", "[geometry]") {
7+
int n = 10;
8+
double c = 1.0, q = 0.2, p = 0.04, t_m = 0.12;
9+
int trailing_edge_type = 0;
10+
Eigen::VectorXd x0(n), y0(n);
11+
12+
nodal_coordinates_initial(n, c, q, p, trailing_edge_type, t_m, x0, y0);
13+
14+
REQUIRE(x0.size() == n);
15+
REQUIRE(y0.size() == n);
16+
REQUIRE(x0(0) == Approx(0.0).epsilon(0.01)); // Leading edge
17+
REQUIRE(y0(0) == Approx(0.0).epsilon(0.01));
18+
}
19+
20+
TEST_CASE("nodal_coordinates_initial handles invalid inputs", "[geometry]") {
21+
int n = 0;
22+
double c = 1.0, q = 0.2, p = 0.04, t_m = 0.12;
23+
int trailing_edge_type = 0;
24+
Eigen::VectorXd x0(n), y0(n);
25+
26+
nodal_coordinates_initial(n, c, q, p, trailing_edge_type, t_m, x0, y0);
27+
28+
REQUIRE(x0.size() == 0);
29+
REQUIRE(y0.size() == 0);
30+
}

tests/test_influencematrix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <catch2/catch.hpp>
2+
#include <Eigen/Dense>
3+
#include "InfluenceMatrix.h"
4+
5+
TEST_CASE("influence_matrix returns correct size", "[influencematrix]") {
6+
double x1 = 0.0, y1 = 0.0, x2 = 1.0, y2 = 0.0, x = 0.5, y = 0.1;
7+
8+
Eigen::MatrixXd matrix = influence_matrix(x1, y1, x2, y2, x, y);
9+
10+
REQUIRE(matrix.rows() == 2);
11+
REQUIRE(matrix.cols() == 2);
12+
}

tests/test_input.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"__geometry_explain": {
3+
"n": "Number of nodes along the airfoil surface (n-1 panels) [It can be even or odd]",
4+
"ymc": "1st digit of NACA 4-digit series (camber percentage)",
5+
"xmc": "2nd digit of NACA 4-digit series (location of max camber)",
6+
"tmax": "Last two digits of NACA 4-digit series (thickness percentage)",
7+
"trailing_edge_type": "1 = open trailing edge, else closed",
8+
"c": "Chord length of the airfoil [m]"
9+
},
10+
"geometry": {
11+
"n": 101,
12+
"c": 0.1,
13+
"ymc": 0.0,
14+
"xmc": 0.0,
15+
"tmax": 12.0,
16+
"trailing_edge_type": 2
17+
},
18+
"__flow_explain": {
19+
"rho": "Fluid density [kg/m^3]",
20+
"mu": "Dynamic viscosity [Pa.s]",
21+
"Re": "Reynolds number (dimensionless)",
22+
"Uinf": "Freestream X-velocity [optional: null means auto-compute from Re]",
23+
"Vinf": "Freestream Y-velocity (usually 0)"
24+
},
25+
"flow": {
26+
"rho": 998.2,
27+
"mu": 0.0010016,
28+
"Re": 40000.0,
29+
"Qinf": null,
30+
"Vinf": 0.0
31+
},
32+
"__motion_explain": {
33+
"k": "Reduced frequency (k = omega * c / (2 * Uinf))",
34+
"h1": "Amplitude of plunge motion [m]",
35+
"h0": "Mean plunge offset [m]",
36+
"alpha1": "pitch amplitude angle in degrees",
37+
"alpha0": "Mean pitch angle in degrees",
38+
"phi_h": "Plunge phase angle in degrees",
39+
"x_pitch": "pitching axis x coord",
40+
"y_pitch": "pitching axis y coord"
41+
},
42+
"motion": {
43+
"k": 1.2,
44+
"h1": null,
45+
"h0": 0.0,
46+
"alpha1": null,
47+
"alpha0": 0.0,
48+
"phi_h": 0.0,
49+
"x_pitch": null,
50+
"y_pitch": null
51+
},
52+
"__simulation_explain": {
53+
"wake": "0 = free wake, 1 = prescribed wake",
54+
"tolerance": "Convergence tolerance for Newton iteration",
55+
"epsilon": "Small number for perturbation / finite differences",
56+
"ncycles": "Number of oscillation cycles to simulate",
57+
"nsteps": "Number of time steps per cycle",
58+
"z": "Number of points for stagnation streamline integration"
59+
},
60+
"simulation": {
61+
"wake": 0,
62+
"tolerance": 1e-6,
63+
"epsilon": 1e-8,
64+
"ncycles": 1,
65+
"nsteps": 40,
66+
"z": 200
67+
}
68+
}

tests/test_kinematics.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <catch2/catch.hpp>
2+
#include "kinematics.h"
3+
#include "constants.h"
4+
5+
TEST_CASE("alpha_instantaneous computes correct angle", "[kinematics]") {
6+
double alpha0 = 0.0, alpha1 = 15.0 * DEG2RAD, phi_alpha = 90.0 * DEG2RAD;
7+
double t = 0.0, omega = 1.0;
8+
9+
double alpha = alpha_instantaneous(alpha0, alpha1, phi_alpha, t, omega);
10+
11+
REQUIRE(alpha == Approx(alpha0).epsilon(0.01)); // At t=0, expect alpha0
12+
}

tests/test_newtonraphson.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <catch2/catch.hpp>
2+
#include <Eigen/Dense>
3+
#include "NewtonRaphsonNonLinear.h"
4+
#include "geometry.h"
5+
#include "velocity.h"
6+
7+
TEST_CASE("newton_raphson returns residuals of correct size", "[newtonraphson]") {
8+
int n = 10;
9+
double dt = 0.1, t = 0.0, lwp = 0.1, theta_wp = 0.0;
10+
Eigen::VectorXd freestream(2), vtotal_wp_cp(2), x_pp(n), y_pp(n), x_cp(n-1), y_cp(n-1), l(n-1);
11+
Eigen::VectorXd B_unsteady(n+1), gamma_unsteady(n+1), gamma_bound(n);
12+
std::vector<double> gamma_wake_strength, gamma_wake_x_location, gamma_wake_y_location;
13+
Eigen::VectorXd wake_panel_cp(2), wake_panel_normal(2);
14+
Eigen::MatrixXd A_unsteady(n+1, n+1), unit_normal(n-1, 2), wake_panel_coordinates(2, 2);
15+
double gamma_old = 0.0;
16+
17+
freestream << 1.0, 0.0;
18+
x_pp.setZero(); y_pp.setZero(); x_cp.setZero(); y_cp.setZero(); l.setOnes();
19+
20+
Eigen::VectorXd residuals = newton_raphson(n, dt, t, lwp, theta_wp, freestream, vtotal_wp_cp, x_pp, y_pp, x_cp, y_cp, l, B_unsteady, gamma_unsteady, gamma_old, gamma_bound, gamma_wake_strength, gamma_wake_x_location, gamma_wake_y_location, wake_panel_cp, wake_panel_normal, A_unsteady, unit_normal, wake_panel_coordinates);
21+
22+
REQUIRE(residuals.size() == 2);
23+
}

tests/test_velocity.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <catch2/catch.hpp>
2+
#include <Eigen/Dense>
3+
#include "velocity.h"
4+
#include "constants.h"
5+
6+
TEST_CASE("velocity_at_surface_of_the_body_inertial_frame computes correct velocity", "[velocity]") {
7+
double Qinf = 1.0, x_pitch = 0.5, y_pitch = 0.0, h0 = 0.0, h1 = 0.25, phi_h = 0.0;
8+
double alpha0 = 0.0, alpha1 = 0.0, phi_alpha = 0.0, t = 0.0, omega = 1.0;
9+
double x = 0.5, y = 0.0;
10+
11+
Eigen::Vector2d velocity = velocity_at_surface_of_the_body_inertial_frame(Qinf, x_pitch, y_pitch, h0, h1, phi_h, alpha0, alpha1, phi_alpha, t, omega, x, y);
12+
13+
REQUIRE(velocity(0) == Approx(Qinf).epsilon(0.01)); // Freestream velocity
14+
REQUIRE(velocity(1) == Approx(0.0).epsilon(0.01));
15+
}

0 commit comments

Comments
 (0)