From 8626a947ecfa6734bcc15d15729dbe48223e1c9a Mon Sep 17 00:00:00 2001 From: cflin Date: Wed, 10 May 2023 11:38:24 +0800 Subject: [PATCH] add error cmp --- CMakeLists.txt | 10 +---- src/static_sim/StaticSim.h | 2 +- src/viewer/StaticSimGUIMenu.cpp | 71 ++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97becf2..770a1e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,6 @@ project(static_simulation_gui) list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -## libigl options -#option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF) -#option(LIBIGL_WITH_PREDICATES "Use exact predicates" ON) -#set(LIBIGL_WITH_OPENGL_GLFW_IMGUI ON CACHE BOOL "Use OpenGL" FORCE) -#set(LIBIGL_WITH_OPENGL_GLFW ON CACHE BOOL "Use GLFW" FORCE) -#set(LIBIGL_WITH_OPENGL ON CACHE BOOL "Use IMGUI" FORCE) -#set(LIBIGL_WITH_PNG ON CACHE BOOL "Use PNG" FORCE) - # Libigl include(libigl) @@ -54,4 +46,4 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/sim-test/rigid-test) target_link_libraries(${PROJECT_NAME} PUBLIC StaticSim) target_compile_definitions(${PROJECT_NAME} PUBLIC CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}") -#add_compile_definitions(DEBUG_SSIM) # for auto load json \ No newline at end of file +add_compile_definitions(DEBUG_SSIM) # for auto load json \ No newline at end of file diff --git a/src/static_sim/StaticSim.h b/src/static_sim/StaticSim.h index 8b77b5c..fa312ca 100644 --- a/src/static_sim/StaticSim.h +++ b/src/static_sim/StaticSim.h @@ -84,7 +84,7 @@ namespace ssim { Eigen::VectorXd &QU, Eigen::MatrixXd &Qstress); /// Extract data to save directory - /// \param save_dir absolute address, like "path/to/save_dir" + /// \param save_dir absolute address, like "/path/to/save_dir" /// \param v_is_extract if (v_is_extract[i]){ extract the target i; } /// \param extract_coord_flg void ExtractTarget(std::string save_dir,std::vector v_is_extract,bool extract_coord_flg){ diff --git a/src/viewer/StaticSimGUIMenu.cpp b/src/viewer/StaticSimGUIMenu.cpp index e312b2c..81f1c31 100644 --- a/src/viewer/StaticSimGUIMenu.cpp +++ b/src/viewer/StaticSimGUIMenu.cpp @@ -5,6 +5,7 @@ #include "StaticSimGUI.h" #include "Util.h" #include "ColorbarPlugin.h" +#include namespace ssim { @@ -13,18 +14,30 @@ namespace ssim { // menu_.draw_viewer_menu(); auto io_menu = [&]() { + static std::string f_json; if (ImGui::Button("加载文件##IO", ImVec2(-1, 0))) { #ifndef DEBUG_SSIM - std::string f_json = igl::file_dialog_open(); - if(f_json=="") return; + f_json = igl::file_dialog_open(); + if (f_json == "") return; reload_json(f_json); #else + f_json ="/debug/abspath/to/sim-test/rigid-test/cube/config.json/"; reload_json(CMAKE_SOURCE_DIR "/sim-test/rigid-test/cube/config.json"); #endif gui_ctrl_.is_initialized = true; gui_ctrl_.is_loaded_json = true; } + if (gui_ctrl_.is_loaded_json) { + ImGui::BeginChild("##filename", ImVec2(-1, ImGui::GetFontSize() * 3), false, + ImGuiWindowFlags_HorizontalScrollbar); + { + ImGui::Text("%s", f_json.c_str()); + ImGui::SetScrollHereY(0.5f); + } + ImGui::EndChild(); + } + }; auto model_menu = [&]() { @@ -58,8 +71,10 @@ namespace ssim { static bool is_drag[2]; ImGui::PushItemWidth(-80); - is_drag[0]= ImGui::DragFloat3(("最小值 " + std::to_string(i + 1)+"##Dir").c_str(),v_min_point.data(),0.01,0.0,1.0,"%.3f"); - is_drag[1]= ImGui::DragFloat3(("最大值 " + std::to_string(i + 1)+"##Dir").c_str(),v_max_point.data(),0.01,0.0,1.0,"%.3f"); + is_drag[0] = ImGui::DragFloat3(("最小值 " + std::to_string(i + 1) + "##Dir").c_str(), + v_min_point.data(), 0.01, 0.0, 1.0, "%.3f"); + is_drag[1] = ImGui::DragFloat3(("最大值 " + std::to_string(i + 1) + "##Dir").c_str(), + v_max_point.data(), 0.01, 0.0, 1.0, "%.3f"); ImGui::PopItemWidth(); if (is_drag[0] || is_drag[1]) { gui_ctrl_.is_modified = true; @@ -88,9 +103,12 @@ namespace ssim { (float) i_NBC.force.z()}; static bool is_drag[3]; ImGui::PushItemWidth(-80); - is_drag[0]= ImGui::DragFloat3(("最小值 " + std::to_string(i + 1)+"##Neu").c_str(),v_min_point.data(),0.01,0.0,1.0,"%.3f"); - is_drag[1]= ImGui::DragFloat3(("最大值 " + std::to_string(i + 1)+"##Neu").c_str(),v_max_point.data(),0.01,0.0,1.0,"%.3f"); - is_drag[2]= ImGui::DragFloat3(("力" + std::to_string(i + 1)+" (N)"+"##Neu").c_str(),v_force.data(),1,-1e10,1e10,"%.3f"); + is_drag[0] = ImGui::DragFloat3(("最小值 " + std::to_string(i + 1) + "##Neu").c_str(), + v_min_point.data(), 0.01, 0.0, 1.0, "%.3f"); + is_drag[1] = ImGui::DragFloat3(("最大值 " + std::to_string(i + 1) + "##Neu").c_str(), + v_max_point.data(), 0.01, 0.0, 1.0, "%.3f"); + is_drag[2] = ImGui::DragFloat3(("力" + std::to_string(i + 1) + " (N)" + "##Neu").c_str(), + v_force.data(), 1, -1e10, 1e10, "%.3f"); ImGui::PopItemWidth(); if (is_drag[0] || is_drag[1] || is_drag[2]) { gui_ctrl_.is_modified = true; @@ -109,7 +127,7 @@ namespace ssim { // -------------------------------------------------------------------- if (ImGui::CollapsingHeader("材料设置", ImGuiTreeNodeFlags_DefaultOpen)) { - static const int item_width=200; + static const int item_width = 200; ImGui::SetNextItemWidth(item_width); ImGui::InputFloat("杨氏模量 (Pa)", &sp_StaticSim_->get_material_property().Youngs_Modulus, 1.0f, 2e11f, "%.2e"); @@ -119,7 +137,8 @@ namespace ssim { "%.3f"); ImGui::SetNextItemWidth(item_width); - ImGui::InputFloat("密度 (kg/m^3)", &sp_StaticSim_->get_material_property().density, 1.0f, 1000.0f, "%.3f"); + ImGui::InputFloat("密度 (kg/m^3)", &sp_StaticSim_->get_material_property().density, 1.0f, 1000.0f, + "%.3f"); } if (ImGui::Button(("原始模型"), ImVec2(-1, 0))) { @@ -215,6 +234,37 @@ namespace ssim { ImGui::SameLine(); ImGui::Checkbox("导出坐标", &is_extract_coord); + }; + auto compare_menu = [&]() { + + double cpt_compliance = sp_StaticSim_->EvaluateTarget(ssim::SimTargetOption::COMPLIANCE)(0, 0); + Eigen::VectorXd cpt_UNorm = sp_StaticSim_->EvaluateTarget(ssim::SimTargetOption::U_NORM); + Eigen::VectorXd cpt_SVonMise = sp_StaticSim_->EvaluateTarget(ssim::SimTargetOption::S_VON_Mises); + + static double error_compliance; + static double error_UNorm; + static double error_SVonMise; + + static bool has_load_cmp_file = false; + if (ImGui::Button("导入Ansys文件", ImVec2(-1, 0))) { + std::string input_dir = ssim::directory_dialog_save(); + spdlog::info("input from: {}", input_dir); + double ref_compliance = cpt_compliance * 1.1;// TODO:fixme:read the file + Eigen::VectorXd ref_UNorm = cpt_UNorm * 1.1;// TODO:fixme + Eigen::VectorXd ref_SVonMise = cpt_SVonMise * 1.1;// TODO:fixme + error_compliance = std::abs(cpt_compliance - ref_compliance) / ref_compliance; + error_UNorm = (cpt_UNorm - ref_UNorm).norm() / ref_UNorm.norm(); + error_SVonMise = (cpt_SVonMise - ref_SVonMise).norm() / ref_SVonMise.norm(); + has_load_cmp_file = true; + } + + if (has_load_cmp_file) { + ImGui::TextWrapped("柔顺度误差: %.2f %%", error_compliance * 100); + ImGui::TextWrapped("位移范数误差: %.2f %%", error_UNorm * 100); + ImGui::TextWrapped("冯氏应力误差: %.2f %%", error_SVonMise * 100); + } + + }; if (ImGui::CollapsingHeader("载入模型", ImGuiTreeNodeFlags_DefaultOpen)) { @@ -229,6 +279,9 @@ namespace ssim { if (ImGui::CollapsingHeader("仿真结果", ImGuiTreeNodeFlags_DefaultOpen)) { result_menu(); } + if (ImGui::CollapsingHeader("结果对比", ImGuiTreeNodeFlags_DefaultOpen)) { + compare_menu(); + } } }