From 3ecd262d29a7f510a8b4be6c5c0feba65456737f Mon Sep 17 00:00:00 2001 From: cflin Date: Tue, 16 Jan 2024 19:33:47 +0800 Subject: [PATCH] before introducing cuda solver --- CMakeLists.txt | 10 +++--- .../config.json | 6 ++-- src/Top3d.cu | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2317f3d..c9139c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,15 @@ cmake_minimum_required(VERSION 3.22) +set(CMAKE_CUDA_ARCHITECTURES native) +set(CMAKE_CUDA_COMPILER "/usr/local/cuda-11.6/bin/nvcc") project(top3d LANGUAGES CUDA CXX) option(PROJECT_WITH_SIMD "Enable SIMD" ON) option(VERBOSE "Show more infos" ON) # chose linear solver -option(ENABLE_AMGCL "Use AMGCL" OFF) +option(ENABLE_AMGCL "Use AMGCL" ON) if (ENABLE_AMGCL) - option(ENABLE_AMGCL_CUDA "use Cuda to speed up AMGCL" OFF) + option(ENABLE_AMGCL_CUDA "use Cuda to speed up AMGCL" ON) else () - option(ENABLE_SUITESPARSE "Use SuiteSparse" ON) + option(ENABLE_SUITESPARSE "Use SuiteSparse" OFF) endif () set(CMAKE_CXX_STANDARD 17) @@ -28,7 +30,7 @@ if (ENABLE_AMGCL AND ENABLE_AMGCL_CUDA) File(GLOB CPP_FILES src/Boundary.cpp src/Timer.cpp - src/Util.cpt p + src/Util.cpp src/*/*.cpp ) else () diff --git a/examples/top-thermoelastic-BiclampedStructure-cuda/config.json b/examples/top-thermoelastic-BiclampedStructure-cuda/config.json index 38d1be5..07aa581 100644 --- a/examples/top-thermoelastic-BiclampedStructure-cuda/config.json +++ b/examples/top-thermoelastic-BiclampedStructure-cuda/config.json @@ -19,9 +19,9 @@ }, "model": { "regular_model": { - "lx": 300, - "ly": 50, - "lz": 35 + "lx": 1, + "ly": 500, + "lz": 350 } }, "mechanical_boundary_condition":{ diff --git a/src/Top3d.cu b/src/Top3d.cu index 9db86dc..5952615 100644 --- a/src/Top3d.cu +++ b/src/Top3d.cu @@ -178,6 +178,39 @@ namespace da::sha { return vt; } + Tensor3d Top3d::GetVonStress() { + Eigen::VectorXd ele_to_write = + Eigen::VectorXd::Zero( + sp_mesh_->GetLx() * sp_mesh_->GetLy() * sp_mesh_->GetLz()); + Eigen::VectorXi pixel_idx = sp_mesh_->GetGlobalIdxOfEleInUse(); + // stress + Eigen::MatrixXd mat_stress(sp_mesh_->GetNumEles(), 6); + Eigen::MatrixXd B = sp_fea_->computeBe({0, 0, 0}); + for (int i = 0; i < sp_mesh_->GetNumEles(); ++i) { + Eigen::VectorXi dofs_in_ele_i = sp_mesh_->MapEleId2Dofs(i); + Eigen::VectorXd Ue = U_(dofs_in_ele_i); + mat_stress.row(i) = rho_(i) * sp_fea_->computeD() * B * Ue; + } + // fill + Tensor3d vt; + auto computeVonStress = [&](Eigen::VectorXd stress) -> double { + double x = stress(0); + double y = stress(1); + double z = stress(2); + double xy = stress(3); + double yz = stress(4); + double zx = stress(5); + return sqrt(0.5 * (x * x + y * y + z * z) + 3 * (xy * xy + yz * yz + zx * zx)); + }; + Eigen::VectorXd vonStress = Eigen::VectorXd::Zero(mat_stress.rows()); + for (int i = 0; i < sp_mesh_->GetNumEles(); ++i) { + vonStress(i) = computeVonStress(mat_stress.row(i)); + } + ele_to_write(pixel_idx) = vonStress; + vt = GetTensorFromCol(ele_to_write); + return vt; + } + Tensor3d Top3d::GetTensorFromCol(const Eigen::VectorXd &proprty_col) { Tensor3d ten_prop_to_write(sp_mesh_->GetLx() * sp_mesh_->GetLy() * sp_mesh_->GetLz(), 1, 1);