Skip to content
Snippets Groups Projects
Verified Commit 8e0e6ad9 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch 'develop' of gitlab.uni-koblenz.de:tfrisch/wobble-bobble-irgendwas into develop

parents 76a7e73c 33948074
No related branches found
No related tags found
1 merge request!103Added project wobble_bobble and refactored some parts of the framework
......@@ -10,7 +10,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project
add_executable(wobble_bobble
src/main.cpp)
src/main.cpp
src/Material.hpp)
fix_project(wobble_bobble)
......
......@@ -12,8 +12,8 @@ layout(set=0, binding=2, std430) readonly buffer particleBuffer {
};
layout( push_constant ) uniform constants {
float K;
float E;
float lame1;
float lame2;
float t;
float dt;
};
......@@ -23,22 +23,6 @@ layout( push_constant ) uniform constants {
shared Particle shared_particles [SHARED_PARTICLES_BATCH_SIZE];
void main() {
const float K9_E = (9.0f * K - E);
float lame1 = 3.0f * K * (3.0f * K - E);
float lame2 = 3.0f * K * E;
float poisson = (3.0f * K - E);
float M = 3.0f * K * (3.0f * K + E);
if (K9_E > 0.0f) {
lame1 /= K9_E;
lame2 /= K9_E;
M /= K9_E;
}
if (K > 0.0f) {
poisson /= (6.0f * K);
}
barrier();
memoryBarrierBuffer();
......
#pragma once
enum MaterialType {
UNDEFINED = 0, GLASS = 1, WOOD = 2, ICE = 3, RUBBER = 4
};
struct Material {
MaterialType m_type;
float m_compression = 0.0f; // K - compression modulus, given in GPa (multiple of 10^9)
float m_elasticity = 0.0f; // E - elasticity modulus, given in GPa (multiple of 10^9)
float m_shear = 0.0f; // G - shear modulus, given in GPa (multiple of 10^9)
float m_lame1 = 0.0f; // lambda
float m_lame2 = 0.0f; // mu
float m_poission = 0.0f; // nu
float m_longitudinal = 0.0f; // M
Material(MaterialType materialType = GLASS) {
float K9_E;
switch (materialType) {
case UNDEFINED:
break;
case GLASS:
m_shear = 26.2f * 1E9; // valid for room temperature, data extracted from here: https://de.wikipedia.org/wiki/Schubmodul
m_elasticity = 65.0f * 1E9; // 40 ... 90, data extracted from here: https://de.wikipedia.org/wiki/Elastizitätsmodul
m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity); // 35 ... 55
m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression);
K9_E = (9.0f * m_compression - m_elasticity);
m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E;
m_lame2 = 3.0f * m_compression * m_elasticity / K9_E;
m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E;
break;
case WOOD:
m_shear = 4.0f * 1E9; // data extracted from here: https://en.wikipedia.org/wiki/Shear_modulus
m_elasticity = 11.0f * 1E9; // data extracted from here: https://de.wikipedia.org/wiki/Holz#Eigenschaften
m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity);
m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression);
K9_E = (9.0f * m_compression - m_elasticity);
m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E;
m_lame2 = 3.0f * m_compression * m_elasticity / K9_E;
m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E;
break;
case ICE:
m_elasticity = 10.0f * 1E9; // data extracted from here: https://www.yumpu.com/de/document/read/21025809/elastizitatsmodul-e-schubmodul-g-kompressionsmodul-k-
m_shear = 3.6f * 1E9; // data extracted from here: https://www.yumpu.com/de/document/read/21025809/elastizitatsmodul-e-schubmodul-g-kompressionsmodul-k-
m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity);
m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression);
K9_E = (9.0f * m_compression - m_elasticity);
m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E;
m_lame2 = 3.0f * m_compression * m_elasticity / K9_E;
m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E;
break;
case RUBBER:
m_elasticity = 0.05f * 1E9; // data extracted from here: https://www.tf.uni-kiel.de/matwis/amat/mw1_ge/kap_7/illustr/t7_1_2.html
m_shear = 0.0003f * 1E9; // data extracted from here: https://www.chemie-schule.de/KnowHow/Schubmodul
m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity);
m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression);
K9_E = (9.0f * m_compression - m_elasticity);
m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E;
m_lame2 = 3.0f * m_compression * m_elasticity / K9_E;
m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E;
}
}
void recalculate(float elasticityModulus, float compressionModulus) {
m_type = UNDEFINED;
m_elasticity = elasticityModulus * 1E9;
m_compression = compressionModulus * 1E9;
float K9_E = (9.0f * m_compression - m_elasticity);
m_shear = 3.0f * m_compression * m_elasticity / K9_E;
m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression);
m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E;
m_lame2 = 3.0f * m_compression * m_elasticity / K9_E;
m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E;
}
};
\ No newline at end of file
......@@ -3,6 +3,7 @@
#include <vkcv/camera/CameraManager.hpp>
#include <vkcv/gui/GUI.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
#include "Material.hpp"
#include <random>
......@@ -19,8 +20,8 @@ struct Particle {
};
struct Physics {
float K;
float E;
float lame1;
float lame2;
float t;
float dt;
};
......@@ -171,7 +172,9 @@ int main(int argc, const char **argv) {
swapchainExtent.width,
swapchainExtent.height
).getHandle();
int selectedMaterial = 1;
Material material(static_cast<MaterialType>(selectedMaterial));
glm::vec3 initialVelocity (0.0f, 1.0f, 0.0f);
float density = 2500.0f;
float radius = 0.1f;
......@@ -556,13 +559,9 @@ int main(int argc, const char **argv) {
bool renderGrid = true;
// Glass is glass and glass breaks...
float compression_modulus = 65.0f;
int compression_exponent = 9;
float elasticity_modulus = 45.0f;
int elasticity_exponent = 9;
float compression_modulus = material.m_compression / 1E9;
float elasticity_modulus = material.m_elasticity / 1E9;
float alpha = 1.0f;
float beta = 0.0f;
......@@ -599,8 +598,8 @@ int main(int argc, const char **argv) {
current = next;
Physics physics;
physics.K = static_cast<float>(compression_modulus * std::pow(10.0, compression_exponent));
physics.E = static_cast<float>(elasticity_modulus * std::pow(10.0, elasticity_exponent));
physics.lame1 = material.m_lame1;
physics.lame2 = material.m_lame2;
physics.t = static_cast<float>(0.000001 * static_cast<double>(time.count()));
physics.dt = static_cast<float>(0.000001 * static_cast<double>(deltatime.count()));
......@@ -784,7 +783,21 @@ int main(int argc, const char **argv) {
gui.beginGUI();
ImGui::Begin("Settings");
ImGui::BeginGroup();
const char* types[] = {"undefined", "glass", "wood", "ice", "rubber"};
if (ImGui::Combo("MaterialType", &selectedMaterial, types, IM_ARRAYSIZE(types))) {
if (static_cast<MaterialType>(selectedMaterial) == MaterialType::UNDEFINED) {
material.m_type = MaterialType::UNDEFINED;
}
else {
material = Material(static_cast<MaterialType>(selectedMaterial));
compression_modulus = material.m_compression / 1E9;
elasticity_modulus = material.m_elasticity / 1E9;
}
}
ImGui::EndGroup();
ImGui::SliderFloat("Density", &density, std::numeric_limits<float>::epsilon(), 5000.0f);
ImGui::SameLine(0.0f, 10.0f);
if (ImGui::SmallButton("Reset##density")) {
......@@ -796,24 +809,18 @@ int main(int argc, const char **argv) {
if (ImGui::SmallButton("Reset##radius")) {
radius = 0.1f;
}
ImGui::BeginGroup();
ImGui::SliderFloat("Compression Modulus", &compression_modulus, 0.0f, 500.0f);
ImGui::SliderInt("##compression_exponent", &compression_exponent, 1, 9);
ImGui::SameLine(0.0f, 10.0f);
if (ImGui::SmallButton("Reset##compression")) {
compression_modulus = 65.0f;
compression_exponent = 9;
if (ImGui::SliderFloat("Compression Modulus", &compression_modulus, 0.0f, 500.0f)) {
selectedMaterial = 0;
material.recalculate(elasticity_modulus, compression_modulus);
}
ImGui::EndGroup();
ImGui::BeginGroup();
ImGui::SliderFloat("Elasticity Modulus", &elasticity_modulus, 0.0f, 1000.0f);
ImGui::SliderInt("##elasticity_exponent", &elasticity_exponent, 1, 9);
ImGui::SameLine(0.0f, 10.0f);
if (ImGui::SmallButton("Reset##elasticity")) {
elasticity_modulus = 45.0f;
elasticity_exponent = 9;
if (ImGui::SliderFloat("Elasticity Modulus", &elasticity_modulus, 0.0f, 1000.0f)) {
selectedMaterial = 0;
material.recalculate(elasticity_modulus, compression_modulus);
}
ImGui::EndGroup();
......@@ -823,13 +830,13 @@ int main(int argc, const char **argv) {
ImGui::SliderFloat("Alpha (PIC -> FLIP)", &alpha, 0.0f, 1.0f);
ImGui::SameLine(0.0f, 10.0f);
if (ImGui::SmallButton("Reset##alpha")) {
alpha = 0.5f;
alpha =1.0f;
}
ImGui::SliderFloat("Beta (Alpha -> APIC)", &beta, 0.0f, 1.0f);
ImGui::SameLine(0.0f, 10.0f);
if (ImGui::SmallButton("Reset##beta")) {
beta = 0.75f;
beta = 0.0f;
}
ImGui::DragFloat3("Initial Velocity", reinterpret_cast<float*>(&initialVelocity), 0.001f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment