# Thermo-elastic/Mechanical Topology Optimization/Simuation ![Screenshot from 2023-07-02 13-57-29.png](docs%2Fimgs%2FScreenshot%20from%202023-07-02%2013-57-29.png) (Optional) temperature limits, optimization of voxel mesh. This is the implementation of the paper [Thermo-elastic topology optimization with stress and temperature constraints.](ref%2FThermo-elastic%20topology%20optimization%20with%20stress%0Aand%20temperature%20constraints.pdf) By the way, this procedure realized the thermo-elastic TO(topology optimization)([Thermo-elastic topology optimization with stress and temperature constraints.](ref%2FThermo-elastic%20topology%20optimization%20with%20stress%0Aand%20temperature%20constraints), mechanical TO([top3d.pdf](ref%2Ftop3d.pdf)) and corresponding simulations. ## Files * `3rd/`: third-party library * `assets/`: user-defined assets * `examples/`: several teaching examples - `defined_model_writer`: User defined voxel mesh/model as TO/simulation input. - `clamped_model_writer`: Clamped to 0 or 1 of the optimized density. - `sim_mechanical`: Mechanical simulation. - `sim_thermoelastic`: Thermo-elastic simulation. - `top_mechanical`: Mechanical TO. - `top_thermoelastic`: Thermoelastic TO. * `output/`: output directory * `ref/`: reference material * `src/`: source code * `cmake/`: CMake files ## Dependencies **Inside libraries**: * [mma](3rd%2Fmma): constrained optimization algorithm * [Eigen](https://eigen.tuxfamily.org/): linear algebra * [libigl](https://github.com/libigl/libigl): basic geometry functions * [AMGCL](https://github.com/ddemidov/amgcl): Linear solver. Optional. * [json](https://github.com/nlohmann/json): parsing input JSON scenes * [spdlog](https://github.com/gabime/spdlog): logging information * OpenMP: CPU parallel processing. ```bash sudo apt install libomp-dev ``` **The following dependencies require user installation**: * [SuiteSparse](https://github.com/DrTimothyAldenDavis/SuiteSparse): Linear solver. Optional, NOTE: Use of the Intel MKL BLAS is strongly recommended. * [CUDA Toolkit](https://developer.nvidia.com/cuda-toolkit): CUDA support. Optional (Strongly recommend). **Select a Linear solver** If your matrix has less than **50w** of freedom, then it is recommended to choose a direct solver (e.g. SuiteSparse): 1. install SuiteSparse. 2. Set `ENABLE_AMGCL` to `OFF` and set `ENABLE_SUITESPARSE` to `ON` in [CMakeLists.txt](CMakeLists.txt). Otherwise, it is recommended to choose an iterative solver (e.g. AMGCL),in CPU: 1. install OpenMP and AMGCL. 2. Set `ENABLE_AMGCL` to `ON`, `ENABLE_AMGCL_CUDA` to `OFF` and `ENABLE_SUITESPARSE` to `OFF` in [CMakeLists.txt](CMakeLists.txt). Further, CUDA can be used to speed up the iterative solver: 1. install OpenMP, CUDA Toolkit and AMGCL. 2. Set `ENABLE_AMGCL` to `ON`, `ENABLE_AMGCL_CUDA` to `ON` and `ENABLE_SUITESPARSE` to `OFF` in [CMakeLists.txt](CMakeLists.txt). Finally, if all options are set to `OFF`, then the Eigen build-in iterative solver will be chosen.(not recommended). ## Build 1. set path in [CMakeLists.txt](CMakeLists.txt). ```cmake set(CMAKE_CUDA_COMPILER "/path/to/nvcc") # set path to nvcc(if AMGCL_CUDA is ON) ``` 2. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j 16 ``` ## Usage ### updated: top and sim sequence 1. Use `example/defined_model_writer` to generate a user-defined voxel mesh/model as TO input. 2. Use `example/top_mechanical` to run mechanical TO. 3. Use `example/top_thermoelastic` to run thermo-elastic TO.(`||Fth|| / ||Fm||` means the ratio of the thermal force to the mechanical force, the value suggested is `0.1-10`). 4. Use `example/clamped_model_writer` to clamp the optimized density to 0 or 1(select a suitable threshold) as SIM input. 5. Use `example/sim_mechanical` to run mechanical simulation. 6. Use `example/sim_thermoelastic` to run thermo-elastic simulation. Note: 1. open `*.vtk` via [Paraview](https://www.paraview.org/download/). 2. Input 1. Set parameters in *.json. see comments in `assets/top-thermoelastic-*.json`(see comments in `assets/config_biclamed.json` and ref paper for MeTh parameters; see comments in `assets/top/config_Lshape.json`) 2. Redirect in `main.cpp` or `main.cu` if ENABLE_AMGCL_CUDA is ON: 3. `"//*"` in `config_*.json` file mean comments. 3. Output see `output/txt/${example_name}`, `output/txt/${example_name}/${clamed_example_name*}/` and `output/vtk/${example_name}/${clamed_example_name*}/`. 4. you can modify `OUTPUT_DIR` and `ASSETS_DIR` in `CMAKEList.txt`. 5. you can modify the linear solver arguments `prm.solver.tol` and `prm.solver.maxiter` in `src/LinearSolver/Amgcl.h` or `src/LinearSolver/AmgclCuda.h`. 6. you should modify example content in `*.cpp` rather than `*.cu`, the latter is copied from the former by cmake. ---