|
|
|
#include "ConfigMechanicalInterface.h"
|
|
|
|
#include "ConfigThermalInterface.h"
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
// INPUT ARGS
|
|
|
|
fs_path config_file(ASSETS_DIR "/top/config_Lshape.json");
|
|
|
|
fs_path model_file(
|
|
|
|
ASSETS_DIR "/voxel_model/Lshape_model.txt");
|
|
|
|
bool extract_inner_vtk = true;
|
|
|
|
// END INPUT
|
|
|
|
|
|
|
|
std::string model_name = model_file.filename().replace_extension();
|
|
|
|
Tensor3d tr_model = ReadTensor3d(model_file);
|
|
|
|
fs_path output_dir(OUTPUT_DIR);
|
|
|
|
spdlog::info("Read config from '{}'", config_file.string());
|
|
|
|
spdlog::info("Read model from '{}'", model_file.string());
|
|
|
|
spdlog::info("Output to '{}'", output_dir.string());
|
|
|
|
|
|
|
|
std::shared_ptr<ConfigMechanicalInterface> sp_mech_inter = std::make_shared<ConfigMechanicalInterface>(
|
|
|
|
config_file,tr_model);
|
|
|
|
std::string ex_name = sp_mech_inter->ex_name_;
|
|
|
|
spdlog::critical("Mechanical TO example: {}", ex_name);
|
|
|
|
|
|
|
|
// initialize Top3d
|
|
|
|
auto sp_mech_top3d = sp_mech_inter->CreatTop();
|
|
|
|
// loop
|
|
|
|
spdlog::critical("start to mechanical top opt ...");
|
|
|
|
Tensor3d t_me_rho = sp_mech_top3d->TopOptMainLoop(false, extract_inner_vtk);
|
|
|
|
// postprocess
|
|
|
|
{
|
|
|
|
spdlog::critical("extract compliance and volume each iteration ...");
|
|
|
|
// extract compliance and volume each iteration
|
|
|
|
fs_path compliance_path =
|
|
|
|
output_dir / "txt" / ex_name /
|
|
|
|
(ex_name + "_MeTop" + "_compliance.txt");
|
|
|
|
WriteStdVector(compliance_path, sp_mech_top3d->v_compliance_);
|
|
|
|
spdlog::info("write compliance txt to: {}", compliance_path.c_str());
|
|
|
|
|
|
|
|
fs_path volume_path =
|
|
|
|
output_dir / "txt" / ex_name /
|
|
|
|
(ex_name + "_MeTop" + "_volume.txt");
|
|
|
|
WriteStdVector(volume_path, sp_mech_top3d->v_volume_);
|
|
|
|
spdlog::info("write volume txt to: {}", volume_path.c_str());
|
|
|
|
|
|
|
|
// extract rho (txt and vtk)
|
|
|
|
fs_path rho_txt_path =
|
|
|
|
output_dir / "txt" / ex_name /
|
|
|
|
(ex_name + "_MeTop" + "_rho.txt");
|
|
|
|
WriteTensor3d(rho_txt_path, t_me_rho);
|
|
|
|
spdlog::info("write density txt to: {}", rho_txt_path.c_str());
|
|
|
|
|
|
|
|
fs_path rho_vtk_path =
|
|
|
|
output_dir / "vtk" / ex_name /
|
|
|
|
(ex_name + "_MeTop" + "_rho.vtk");
|
|
|
|
WriteTensorToVtk(rho_vtk_path, t_me_rho, sp_mech_inter->sp_mesh_);
|
|
|
|
spdlog::info("write density vtk to: {}", rho_vtk_path.c_str());
|
|
|
|
}
|
|
|
|
if (extract_inner_vtk) {
|
|
|
|
if (sp_mech_top3d->v_ten_rho_.size() == 0) {
|
|
|
|
throw std::runtime_error("v_ten_rho_ is empty");
|
|
|
|
}
|
|
|
|
for (int i = 0; i <sp_mech_top3d->v_ten_rho_.size(); ++i) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::setw(3) << std::setfill('0') << i;
|
|
|
|
std::string suffix_idx = ss.str();
|
|
|
|
fs_path inner_vtk_path =
|
|
|
|
output_dir / "vtk" / ex_name /
|
|
|
|
(ex_name + "_MeTop" + "_inner") / (suffix_idx + ".vtk");
|
|
|
|
WriteTensorToVtk(inner_vtk_path,sp_mech_top3d->v_ten_rho_[i],
|
|
|
|
sp_mech_inter->sp_mesh_);
|
|
|
|
if (i == 0) {
|
|
|
|
spdlog::info("write inner vtk(0,1,...) to: {}",
|
|
|
|
inner_vtk_path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|