Browse Source

before introducing cuda solver

multiple_top
cflin 1 year ago
parent
commit
3ecd262d29
  1. 10
      CMakeLists.txt
  2. 6
      examples/top-thermoelastic-BiclampedStructure-cuda/config.json
  3. 33
      src/Top3d.cu

10
CMakeLists.txt

@ -1,13 +1,15 @@
cmake_minimum_required(VERSION 3.22) 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) project(top3d LANGUAGES CUDA CXX)
option(PROJECT_WITH_SIMD "Enable SIMD" ON) option(PROJECT_WITH_SIMD "Enable SIMD" ON)
option(VERBOSE "Show more infos" ON) option(VERBOSE "Show more infos" ON)
# chose linear solver # chose linear solver
option(ENABLE_AMGCL "Use AMGCL" OFF) option(ENABLE_AMGCL "Use AMGCL" ON)
if (ENABLE_AMGCL) 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 () else ()
option(ENABLE_SUITESPARSE "Use SuiteSparse" ON) option(ENABLE_SUITESPARSE "Use SuiteSparse" OFF)
endif () endif ()
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@ -28,7 +30,7 @@ if (ENABLE_AMGCL AND ENABLE_AMGCL_CUDA)
File(GLOB CPP_FILES File(GLOB CPP_FILES
src/Boundary.cpp src/Boundary.cpp
src/Timer.cpp src/Timer.cpp
src/Util.cpt p src/Util.cpp
src/*/*.cpp src/*/*.cpp
) )
else () else ()

6
examples/top-thermoelastic-BiclampedStructure-cuda/config.json

@ -19,9 +19,9 @@
}, },
"model": { "model": {
"regular_model": { "regular_model": {
"lx": 300, "lx": 1,
"ly": 50, "ly": 500,
"lz": 35 "lz": 350
} }
}, },
"mechanical_boundary_condition":{ "mechanical_boundary_condition":{

33
src/Top3d.cu

@ -178,6 +178,39 @@ namespace da::sha {
return vt; 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 Top3d::GetTensorFromCol(const Eigen::VectorXd &proprty_col) {
Tensor3d ten_prop_to_write(sp_mesh_->GetLx() * sp_mesh_->GetLy() * sp_mesh_->GetLz(), 1, Tensor3d ten_prop_to_write(sp_mesh_->GetLx() * sp_mesh_->GetLy() * sp_mesh_->GetLz(), 1,
1); 1);

Loading…
Cancel
Save