From 91a5fbe785ab59630f3a1f952152adc373af0cfa Mon Sep 17 00:00:00 2001 From: LonnieWebb Date: Wed, 8 Nov 2023 20:46:30 -0500 Subject: [PATCH] Topo opt paramerization implementation and script --- .../topology_optimization_2d/2d_analysis.cpp | 33 ++++++++++++++++--- .../topology_optimization_2d/run_cases.sh | 30 +++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 examples/topology_optimization_2d/run_cases.sh diff --git a/examples/topology_optimization_2d/2d_analysis.cpp b/examples/topology_optimization_2d/2d_analysis.cpp index 4318c14d..88749ab5 100644 --- a/examples/topology_optimization_2d/2d_analysis.cpp +++ b/examples/topology_optimization_2d/2d_analysis.cpp @@ -306,6 +306,30 @@ int main(int argc, char *argv[]) { }; index_t num_boundary_verts = 0; + + switch (selected_case) { + case 0: + // Bridge Case + + // Boundary vertex labels + num_boundary_verts = 2 * (ny + 1); + break; + case 1: + // Pillars Case + + // Boundary vertex labels + num_boundary_verts = (nx + 1); + + break; + case 2: + // Cantilever Case + + // Boundary vertex labels + num_boundary_verts = (nx + 1); + break; + } + + // There's a better way to do this than two switch statements index_t boundary_verts[num_boundary_verts]; switch (selected_case) { @@ -478,10 +502,11 @@ int main(int argc, char *argv[]) { filter, analysis); // Set up the topology optimization problem - std::string prefix = std::string("./results_") + std::to_string(nx) + - std::string("x") + std::to_string(ny) + - std::string("_") + std::to_string(fact) + - std::string("/"); + std::string prefix = + std::string("./results/") + std::to_string(nx) + std::string("x") + + std::to_string(ny) + std::string("_") + std::to_string(selected_case) + + std::string("_") + std::to_string(fact) + std::string("_") + + std::to_string(bf) + std::string("/"); TopOptProb prob(prefix, comm, topo, functional, volume, target_volume, dfdx); prob.incref(); diff --git a/examples/topology_optimization_2d/run_cases.sh b/examples/topology_optimization_2d/run_cases.sh new file mode 100755 index 00000000..f58a813c --- /dev/null +++ b/examples/topology_optimization_2d/run_cases.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Define arrays of values for each variable +ny_values=(64) +selected_case_values=(0 1) +bf_values=(5.0) +fact_values=(0.2) + +# Loop through each combination of values and run the program +for ny in "${ny_values[@]}"; do + for selected_case in "${selected_case_values[@]}"; do + for bf in "${bf_values[@]}"; do + for fact in "${fact_values[@]}"; do + # Build the command + command="./2d_analysis ny=${ny} selected_case=${selected_case} bf=${bf} fact=${fact}" + echo "Running command: $command" + # Run the command + $command + # Check if the command was successful + if [ $? -ne 0 ]; then + echo "Command failed: $command" + # Uncomment the next line if you want the script to exit on failure + # exit 1 + fi + done + done + done +done + +echo "All combinations have been run."