Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samayala22 committed May 25, 2024
1 parent 99ecc75 commit 294aa99
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions data/theodorsen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def uvlm_data(filename):
)

files = [
#"cl_data"
"cl_data_025",
"cl_data_050",
"cl_data_075",
"cl_data"
# "cl_data_025",
# "cl_data_050",
# "cl_data_075",
]

for file in files:
Expand Down
23 changes: 12 additions & 11 deletions tests/test_uvlm_theodorsen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ class Kinematics {
}
tmatrix displacement(float t) {return displacement(t, m_joints.size());}

linalg::alias::float3 velocity(float t, const linalg::vec<fwd::Float,4> vertex, u64 n = 0) {
tmatrix transform = displacement(t);
linalg::alias::float3 velocity(const tmatrix& transform, const linalg::vec<fwd::Float,4> vertex) {
linalg::vec<fwd::Float,4> new_pt = linalg::mul(transform, vertex);
return {new_pt.x.grad(), new_pt.y.grad(), new_pt.z.grad()};
}

f32 velocity_magnitude(float t, const linalg::vec<fwd::Float,4> vertex) {
return linalg::length(velocity(t, vertex));
f32 velocity_magnitude(const tmatrix& transform, const linalg::vec<fwd::Float,4> vertex) {
return linalg::length(velocity(transform, vertex));
}

private:
Expand Down Expand Up @@ -123,7 +122,7 @@ int main() {
const f32 cycles = 3.0f;
const f32 u_inf = 1.0f; // freestream velocity
const f32 amplitude = 0.1f; // amplitude of the wing motion
const f32 k = 1.0; // reduced frequency
const f32 k = 0.75; // reduced frequency
const f32 omega = k * 2.0f * u_inf / (2*b);
const f32 t_final = cycles * 2.0f * PI_f / omega; // 4 periods
//const f32 t_final = 5.0f;
Expand Down Expand Up @@ -213,9 +212,10 @@ int main() {
std::cout << "Timestep calculation\n";
vec_t.push_back(0.0f);
for (f32 t = 0.0f; t < t_final;) {
f32 dt = segment_chord / kinematics.velocity_magnitude(t, {trailing_vertices.x[0], trailing_vertices.y[0], trailing_vertices.z[0], 1.0f});
const auto total_transform = kinematics.displacement(t);
f32 dt = segment_chord / kinematics.velocity_magnitude(total_transform, {trailing_vertices.x[0], trailing_vertices.y[0], trailing_vertices.z[0], 1.0f});
for (u64 i = 1; i < trailing_vertices.size; i++) {
dt = std::min(dt, segment_chord / kinematics.velocity_magnitude(t, {trailing_vertices.x[i], trailing_vertices.y[i], trailing_vertices.z[i], 1.0f}));
dt = std::min(dt, segment_chord / kinematics.velocity_magnitude(total_transform, {trailing_vertices.x[i], trailing_vertices.y[i], trailing_vertices.z[i], 1.0f}));
}

auto transform = dual_to_float(kinematics.displacement(t+dt));
Expand Down Expand Up @@ -254,7 +254,7 @@ int main() {

// Unsteady loop
std::cout << "SIMULATION NB OF TIMESTEPS: " << vec_t.size() << "\n";
f32 avg_vel_error = 0.0f;

for (u64 i = 0; i < vec_t.size()-1; i++) {
#ifdef DEBUG_DISPLACEMENT_DATA
dump_buffer(wing_data, mesh->v.x.data(), mesh->v.x.data() + mesh->nb_vertices_wing());
Expand All @@ -273,17 +273,18 @@ int main() {

const f32 t = vec_t[i];
const f32 dt = vec_t[i+1] - t;
std::cout << "\n----------------\n" << "T = " << t << "\n";
const auto total_transform = kinematics.displacement(t);
const auto freestream_transform = kinematics.displacement(t,1);

linalg::alias::float3 freestream;
for (u64 idx = 0; idx < mesh->nb_panels_wing(); idx++) {
auto local_velocity = -kinematics.velocity(t, {mesh->colloc.x[idx], mesh->colloc.y[idx], mesh->colloc.z[idx], 1.0f});
auto local_velocity = -kinematics.velocity(total_transform, {mesh->colloc.x[idx], mesh->colloc.y[idx], mesh->colloc.z[idx], 1.0f});
velocities.x[idx] = local_velocity.x;
velocities.y[idx] = local_velocity.y;
velocities.z[idx] = local_velocity.z;

if (idx == 0) {
freestream = -kinematics.velocity(t, {mesh->colloc.x[idx], mesh->colloc.y[idx], mesh->colloc.z[idx], 1.0f}, 1);
freestream = -kinematics.velocity(freestream_transform, {mesh->colloc.x[idx], mesh->colloc.y[idx], mesh->colloc.z[idx], 1.0f});
}
}

Expand Down
6 changes: 4 additions & 2 deletions vlm/backends/cpu/src/vlm_backend_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void BackendCPU::reset() {
}

void BackendCPU::compute_delta_gamma() {
// const tiny::ScopedTimer timer("Delta Gamma");
std::copy(gamma.data(), gamma.data()+mesh.ns, delta_gamma.data());

// note: this is efficient as the memory is contiguous
Expand Down Expand Up @@ -133,7 +134,7 @@ void BackendCPU::compute_rhs(const FlowData& flow) {
}

void BackendCPU::add_wake_influence() {
const tiny::ScopedTimer timer("Wake Influence");
// const tiny::ScopedTimer timer("Wake Influence");

tf::Taskflow taskflow;

Expand Down Expand Up @@ -198,6 +199,7 @@ void BackendCPU::wake_rollup(float dt) {
}

void BackendCPU::shed_gamma() {
// const tiny::ScopedTimer timer("Shed Gamma");
const Mesh& m = mesh;
const u64 wake_row_start = (m.nc + m.nw - m.current_nw - 1) * m.ns;

Expand All @@ -221,7 +223,7 @@ void BackendCPU::lu_factor() {
}

void BackendCPU::lu_solve() {
const tiny::ScopedTimer timer("Solve");
// const tiny::ScopedTimer timer("Solve");
const int32_t n = static_cast<int32_t>(mesh.nb_panels_wing());
std::copy(rhs.begin(), rhs.end(), gamma.begin());

Expand Down
3 changes: 3 additions & 0 deletions vlm/src/vlm_mesh.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "vlm_mesh.hpp"
#include "linalg.h"
#include "vlm_types.hpp"

#include "tinyconfig.hpp"
#include "tinytimer.hpp"

#include <cassert>
#include <iostream>
Expand Down Expand Up @@ -407,6 +409,7 @@ void Mesh::io_read(const std::string& filename) {
}

void Mesh::move(const linalg::alias::float4x4& transform, const SoA_3D_t<f32>& origin_pos) {
// const tiny::ScopedTimer t("Mesh::move");
assert(current_nw < nw); // check if we have capacity

// Shed wake before moving
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_rules("mode.debug", "mode.release", "mode.releasedbg", "mode.asan")
-- set_toolchains("cuda")

-- set_toolset("cxx", "clang")
set_policy("build.sanitizer.address", true)
-- set_policy("build.sanitizer.address", true)
set_policy("build.warning", true)
set_policy("build.cuda.devlink", true) -- magic
set_policy("run.autobuild", true)
Expand Down

0 comments on commit 294aa99

Please sign in to comment.