# Copyright (c) 2026 JSOL CORPORATION # # This script is released under the MIT License. # See the full license text at: # https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/ def setTopologyOptimizationOption(optimTable, engine, maxGen, numPop, numChild): """Set topology optimization options""" mapping = { # Optimization engine: Each key item in Genetic Algorithm (Topology)) "jsol_ga": (u"jsol_ga_max_generation", u"jsol_ga_num_population", u"jsol_ga_num_children", u"jsol_ga_shape_evalution", u"jsol_ga_result_evaluation"), # Optimization engine: Key items in Multi-Objective Genetic Algorithm (Topology) "jsol_moga2": (u"jsol_moga2_max_generation", u"jsol_moga2_num_population", u"jsol_moga2_num_children", u"jsol_moga2_shape_evalution", u"jsol_moga2_result_evaluation"), } keyMagGen, keyNumPop, keyNumChild, keyShapeEval, keyResultEval = mapping[engine] optimTable.SetParameter(u"engine", engine) optimTable.SetParameter(keyMagGen, maxGen) optimTable.SetParameter(keyNumPop, numPop) optimTable.SetParameter(keyNumChild, numChild) # Continuous Shapve Evaluation Parameters # 0:Do not use the continuity of the shape as an evaluation criterion # 1:Limit parts separation # 2:Limit parts separation to no more than the maximum of 2 independent regions optimTable.SetParameter(keyShapeEval, 1) # Results Evaluation Parameters # 0:Save the specified number of best objective cases(Optimization Engine:Genetic Algorithm (Topology)) # 0:Save results for cases on Pareto front(Optimization Engine:Multi-Objective Genetic Algorithm (Topology)) # 1:Save the best objective function case from each generation # 2:Save the results of all cases optimTable.SetParameter(keyResultEval, 1) app = designer.GetApplication() study = app.GetCurrentStudy() engine = u"jsol_ga" maxGeneration = 10 numPopulation = 60 numChildren = 55 setTopologyOptimizationOption( study.GetOptimizationTable(), engine, maxGeneration, numPopulation, numChildren)