├── .gitignore ├── LICENSE.md ├── README.md ├── build.gradle ├── demos ├── Demo10_Colormaps.java ├── Demo11_Directed_Meshing.java ├── Demo12_Solution_History_And_Cameras.java ├── Demo13_Streamlines.java ├── Demo14_GCI.java ├── Demo15_Run_DES.java ├── Demo16_1D_Sound_Propagation.java ├── Demo1_Flow_In_a_Pipe.java ├── Demo2_Conduction_In_a_Channel.java ├── Demo3_Backward_Facing_Step.java ├── Demo4_Split_Part_Surfaces.java ├── Demo5_Lego_Kart_Wind_Tunnel.java ├── Demo6_Scene_Resolution.java ├── Demo6b_Write_Camera_Views.java ├── Demo6c_Read_Camera_Views.java ├── Demo7_Sloshing_Case.java ├── Demo8_Half_Wing.java └── Demo9_Make_Me_Pretty.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── macroutils ├── build.gradle └── src │ └── macroutils │ ├── MacroUtils.java │ ├── StaticDeclarations.java │ ├── UserDeclarations.java │ ├── checker │ ├── CheckHas.java │ ├── CheckIs.java │ └── MainChecker.java │ ├── creator │ ├── CreateDerivedPart.java │ ├── CreateGeometry.java │ ├── CreateInterface.java │ ├── CreateMeshOperation.java │ ├── CreatePartContact.java │ ├── CreatePhysicsContinua.java │ ├── CreatePlot.java │ ├── CreateRegion.java │ ├── CreateReport.java │ ├── CreateScene.java │ ├── CreateSolver.java │ ├── CreateTools.java │ ├── CreateUnits.java │ └── MainCreator.java │ ├── getter │ ├── GetBoundaries.java │ ├── GetCameras.java │ ├── GetGeometries.java │ ├── GetInfos.java │ ├── GetMesh.java │ ├── GetMonitors.java │ ├── GetObjects.java │ ├── GetPartCurves.java │ ├── GetPartSurfaces.java │ ├── GetParts.java │ ├── GetPlots.java │ ├── GetRegions.java │ ├── GetReports.java │ ├── GetScenes.java │ ├── GetSolver.java │ ├── GetStrings.java │ ├── GetUnits.java │ └── MainGetter.java │ ├── io │ ├── MainIO.java │ ├── Print.java │ ├── Read.java │ └── Write.java │ ├── misc │ ├── MainClearer.java │ ├── MainCloser.java │ ├── MainDisabler.java │ ├── MainEnabler.java │ ├── MainOpener.java │ ├── MainRemover.java │ ├── MainResetter.java │ └── MainUpdater.java │ ├── setter │ ├── MainSetter.java │ ├── SetBoundaries.java │ ├── SetDefaults.java │ ├── SetGeometry.java │ ├── SetMesh.java │ ├── SetObjects.java │ ├── SetPhysics.java │ ├── SetPlots.java │ ├── SetRegions.java │ ├── SetScenes.java │ └── SetSolver.java │ └── templates │ ├── MainTemplates.java │ ├── TemplateGCI.java │ ├── TemplateGeometry.java │ ├── TemplateMesh.java │ ├── TemplatePost.java │ ├── TemplatePrettifier.java │ ├── demos │ └── Demo16.java │ ├── simassistants │ ├── BlockMesher.java │ └── SimpleHexaMesher.java │ └── simtools │ ├── ImplicitUnsteadyConvergenceChecker.java │ └── MeshMetrics.java ├── settings.gradle ├── simassistants ├── build.gradle ├── demo16 │ ├── build.gradle │ ├── html │ │ └── Demo16.xhtml │ └── src │ │ ├── BuilderTask.java │ │ └── Demo16.java └── simplehexamesher │ ├── build.gradle │ ├── html │ ├── BlockTask.xhtml │ ├── IntroductionTask.xhtml │ ├── QuestionsAndAnswersTask.xhtml │ └── StartOverTask.xhtml │ ├── resources │ └── BlockTask.jpg │ └── src │ ├── BlockTask.java │ ├── IntroductionTask.java │ ├── QuestionsAndAnswersTask.java │ ├── SimpleHexaMesher.java │ └── StartOverTask.java ├── tests ├── common │ ├── __init__.py │ ├── executor.py │ ├── set_up.py │ ├── star.py │ ├── strings.py │ └── timer.py ├── execute_tests.py ├── macros │ ├── BugCreateStreamlineSceneTest.java │ ├── BugParentNameTest.java │ ├── BugWritingFilenamesTest.java │ ├── Demo14_EvalGCITest.java │ ├── SimAssistantBlockMesherTest.java │ ├── SimToolImplicitUnsteadyConvergenceCheckerTest.java │ ├── SimToolMeshMetricsTest.java │ ├── WriteSummaryTest.java │ └── common │ │ └── SummaryWriter.java ├── requirements.txt ├── test │ ├── movie.py │ ├── test_bugs.py │ ├── test_demo01.py │ ├── test_demo02.py │ ├── test_demo03.py │ ├── test_demo04.py │ ├── test_demo05.py │ ├── test_demo06.py │ ├── test_demo07.py │ ├── test_demo08.py │ ├── test_demo09.py │ ├── test_demo10.py │ ├── test_demo11.py │ ├── test_demo12.py │ ├── test_demo13.py │ ├── test_demo14.py │ ├── test_demo15.py │ ├── test_demo16.py │ ├── test_simulation_assistants.py │ ├── test_simulation_tools.py │ └── test_utils.py └── tests_definition.py └── wiki ├── NB_Custom_SpaceBraces.png ├── NB_FormattingComments.png ├── NB_FormattingGeneral.png ├── NB_MembersOrdering.png └── NB_OnSaveSettings.png /.gitignore: -------------------------------------------------------------------------------- 1 | # NetBeans and Compiler files 2 | .gradle/* 3 | build/ 4 | dist/ 5 | jars/ 6 | nbproject/ 7 | build.xml 8 | manifest.mf 9 | 10 | # STAR-CCM+ files 11 | *.sim 12 | *.sim~ 13 | *.simh 14 | 15 | # Python files 16 | .cache 17 | .spyproject 18 | *.pyc 19 | 20 | # Other files or folders 21 | .directory 22 | temp_*/ 23 | *.7z 24 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2012-2019 Fabio R. Sulzbacher Kasper 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MacroUtils 2 | 3 | MacroUtils is a collection of high-level APIs in order to make your life easier when writing Simcenter STAR-CCM+ JAVA macros. 4 | 5 | ## Requires 6 | 7 | 1. Simcenter STAR-CCM+ 2502 libraries; 8 | 9 | 1. Integrated development environment (IDE) supporting JDK 21.0.4 and gradle 10 | 11 | ## Recommended IDE 12 | 13 | NetBeans 22 or later. 14 | 15 | ## Need an older version? 16 | 17 | **Source:** navigate through git tags to checkout older code; 18 | 19 | **Binaries:** have a look in the Releases section to find out all the builds compiled over time. 20 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | 3 | gradle.projectsEvaluated { 4 | 5 | tasks.withType(JavaCompile) { 6 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" 7 | } 8 | 9 | } 10 | 11 | } 12 | 13 | def buildVersion() { 14 | 15 | File javaFile = file(java.nio.file.Paths.get(rootDir.getAbsolutePath()) 16 | .resolve('macroutils') 17 | .resolve('src') 18 | .resolve('macroutils') 19 | .resolve('MacroUtils.java')) 20 | 21 | String rowFound = javaFile.readLines().grep(~/\s\* \@version.*/)[0] 22 | String versionFound = rowFound.split(' ').grep(~/\d{4}/)[0] 23 | 24 | return versionFound 25 | 26 | } 27 | 28 | ext { 29 | buildDate = new java.text.SimpleDateFormat("MMdd").format(new Date()) 30 | buildVersion = buildVersion() 31 | jarBaseName = "${project.name}_${buildVersion}_build_${buildDate}".toLowerCase() 32 | libsFolder = file("${rootDir}/../libs_STAR-CCM+") 33 | } 34 | 35 | subprojects { 36 | 37 | apply plugin: 'base' 38 | apply plugin: 'java-library' 39 | 40 | dependencies { 41 | api fileTree(libsFolder.getAbsolutePath()) { 42 | include '*.jar' 43 | } 44 | } 45 | 46 | jar { 47 | 48 | onlyIf { 49 | !sourceSets.main.allSource.files.isEmpty() 50 | } 51 | 52 | archiveBaseName = "${jarBaseName}" 53 | 54 | } 55 | 56 | sourceSets { 57 | main.java.srcDirs 'src' 58 | } 59 | 60 | } 61 | 62 | // 63 | // Uncomment for debug printing 64 | // 65 | //println " Root Project: ${project.rootProject}"; 66 | //println " Project name: ${project.rootProject.name}"; 67 | //println " rootDir: ${project.rootDir}" 68 | //println " projectDir: ${project.projectDir}"; 69 | //println " user.dir: ${System.getProperty("user.dir")}"; 70 | //println " libsFolder: ${libsFolder}"; 71 | //println " build version: ${buildVersion}"; 72 | //println " build date: ${buildDate}"; 73 | //println " JAR base name: ${jarBaseName}"; 74 | -------------------------------------------------------------------------------- /demos/Demo10_Colormaps.java: -------------------------------------------------------------------------------- 1 | import java.awt.Color; 2 | import macroutils.MacroUtils; 3 | import macroutils.StaticDeclarations; 4 | import macroutils.UserDeclarations; 5 | import star.common.StarMacro; 6 | import star.vis.ScalarDisplayer; 7 | 8 | /** 9 | * This method is for creating custom Colormaps. 10 | * 11 | * @since Macro Utils v2d. 12 | * @author Fabio Kasper 13 | */ 14 | public class Demo10_Colormaps extends StarMacro { 15 | 16 | private MacroUtils mu; 17 | private UserDeclarations ud; 18 | 19 | @Override 20 | public void execute() { 21 | 22 | mu = new MacroUtils(getActiveSimulation()); 23 | 24 | ud = mu.userDeclarations; 25 | 26 | ud.simTitle = "Demo10_Colormaps"; 27 | 28 | ud.defCamView = mu.io.read.cameraView("cam|7.698946e-03,-2.109472e-02,7.961378e-02" 29 | + "|7.698946e-03,-2.109472e-02,6.679604e-01|0.000000e+00,1.000000e+00,0.000000e+00" 30 | + "|1.288606e-01|1", true); 31 | 32 | addColormaps(); 33 | 34 | mu.saveSim(); 35 | 36 | mu.io.write.all(ud.simTitle); 37 | 38 | } 39 | 40 | private void addColormaps() { 41 | ud.colors.add(Color.YELLOW); 42 | ud.colors.add(Color.black); 43 | ud.colors.add(Color.blue); 44 | mu.add.tools.colormap("myColormap", ud.colors, null, StaticDeclarations.ColorSpace.RGB); 45 | ud.colors.clear(); 46 | ud.colors.add(Color.GREEN); 47 | ud.colors.add(Color.YELLOW); 48 | ud.colors.add(Color.BLACK); 49 | ud.colors.add(Color.WHITE); 50 | ud.defColormap = mu.add.tools.colormap("myColormap2", ud.colors, null, 51 | StaticDeclarations.ColorSpace.HSV); 52 | 53 | ud.simpleSphPrt = mu.add.geometry.sphere(StaticDeclarations.COORD0, 100, ud.unit_mm); 54 | ud.simpleSphPrt.setPresentationName("Sphere"); 55 | ud.region = mu.add.region.fromAll(true); 56 | 57 | ud.defUnitLength = ud.unit_mm; 58 | ud.mshBaseSize = 7.5; 59 | ud.mshOp = mu.add.meshOperation.automatedMesh(mu.get.geometries.all(true), 60 | StaticDeclarations.Meshers.SURFACE_REMESHER, 61 | StaticDeclarations.Meshers.POLY_MESHER); 62 | mu.update.volumeMesh(); 63 | 64 | ud.namedObjects.addAll(mu.get.boundaries.all(true)); 65 | ud.scene = mu.add.scene.scalar(ud.namedObjects, 66 | mu.get.objects.fieldFunction("Centroid", true), ud.unit_mm, true); 67 | ((ScalarDisplayer) mu.get.scenes.displayerByREGEX(ud.scene, ".*", true)) 68 | .setDisplayMeshBoolean(true); 69 | ud.scene.open(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /demos/Demo16_1D_Sound_Propagation.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import macroutils.UserDeclarations; 3 | import macroutils.templates.demos.Demo16; 4 | import star.common.StarMacro; 5 | 6 | /** 7 | * Runs a simplified sound propagation problem inside a constant cross section channel. 8 | * 9 | * Boundary condition is a sinusoid unity Pressure (1Pa) and the domain length is 50 wavelengths. 10 | * Total time is 2 flows through. Flow is inviscid ideal gas run with the coupled explicit scheme of 11 | * STAR-CCM+. 12 | * 13 | * @since MacroUtils v11.04. 14 | * @author Fabio Kasper 15 | */ 16 | public class Demo16_1D_Sound_Propagation extends StarMacro { 17 | 18 | @Override 19 | public void execute() { 20 | 21 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 22 | 23 | UserDeclarations ud = mu.userDeclarations; 24 | 25 | ud.simTitle = "Demo16_1D_Sound_Propagation"; 26 | 27 | Demo16 demo16 = new Demo16(mu); 28 | 29 | demo16.updateCaseParameters(); 30 | 31 | demo16.executePre(); 32 | 33 | demo16.executePost(); 34 | 35 | demo16.printOverview(); 36 | 37 | mu.run(); 38 | 39 | mu.saveSim(); 40 | 41 | mu.io.write.all(ud.simTitle); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /demos/Demo1_Flow_In_a_Pipe.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import macroutils.StaticDeclarations; 3 | import macroutils.UserDeclarations; 4 | import star.common.StarMacro; 5 | 6 | /** 7 | * Simple Demo of a 3D laminar isothermal flow in a pipe. 8 | * 9 | * Geometry: 10 | * L 11 | * +---------------------------------------------------------------+ 12 | * | | 13 | * r * O(0,0,0) | 14 | * | | 15 | * +---------------------------------------------------------------+ 16 | * 17 | * @since Macro Utils v2b. 18 | * @author Fabio Kasper 19 | */ 20 | public class Demo1_Flow_In_a_Pipe extends StarMacro { 21 | 22 | private final double length = 500; 23 | private MacroUtils mu; 24 | private final double radius = 20; 25 | private UserDeclarations ud; 26 | 27 | @Override 28 | public void execute() { 29 | 30 | initMacro(); 31 | 32 | prep1_createPart(); 33 | 34 | prep2_createRegion(); 35 | 36 | prep3_BCsAndMesh(); 37 | 38 | prep4_setPost(); 39 | 40 | mu.run(); 41 | 42 | mu.saveSim(); 43 | 44 | mu.io.write.all(ud.simTitle); 45 | 46 | } 47 | 48 | private void initMacro() { 49 | mu = new MacroUtils(getActiveSimulation()); 50 | ud = mu.userDeclarations; 51 | ud.simTitle = "Demo1_Flow_In_a_Pipe"; 52 | } 53 | 54 | private void prep1_createPart() { 55 | ud.defCamView = mu.io.read.cameraView("myCam|2.498938e-01,-1.450833e-02,-2.222717e-02" 56 | + "|2.498938e-01,-1.450833e-02,9.690091e-01|0.000000e+00,1.000000e+00,0.000000e+00" 57 | + "|1.463440e-01|1", true); 58 | ud.defTessOpt = StaticDeclarations.Tessellation.FINE; 59 | ud.cadPrt = mu.add.geometry.cylinder3DCAD(radius, length, StaticDeclarations.COORD0, 60 | ud.unit_mm, StaticDeclarations.Axis.X); 61 | } 62 | 63 | private void prep2_createRegion() { 64 | mu.get.partSurfaces.byREGEX("x0", true).setPresentationName(ud.bcInlet); 65 | mu.get.partSurfaces.byREGEX("x1", true).setPresentationName(ud.bcOutlet); 66 | mu.get.partSurfaces.byREGEX("Def.*", true).setPresentationName(ud.bcWall); 67 | ud.region = mu.add.region.fromAll(true); 68 | } 69 | 70 | private void prep3_BCsAndMesh() { 71 | //-- Mesh settings 72 | ud.mshBaseSize = radius / 8; 73 | ud.prismsLayers = 3; 74 | ud.mshSrfSizeMin = 75.; 75 | ud.prismsRelSizeHeight = 30; 76 | //-- 77 | ud.geometryParts.add(mu.get.geometries.byREGEX(ud.cadPrt.getPresentationName(), true)); 78 | ud.mshOp = mu.add.meshOperation.automatedMesh(ud.geometryParts, 79 | StaticDeclarations.Meshers.SURFACE_REMESHER, 80 | StaticDeclarations.Meshers.POLY_MESHER, 81 | StaticDeclarations.Meshers.PRISM_LAYER_MESHER); 82 | ud.mshOp.setPresentationName("My Mesh"); 83 | mu.add.physicsContinua.generic(StaticDeclarations.Space.THREE_DIMENSIONAL, 84 | StaticDeclarations.Time.STEADY, StaticDeclarations.Material.LIQUID, 85 | StaticDeclarations.Solver.SEGREGATED, StaticDeclarations.Density.INCOMPRESSIBLE, 86 | StaticDeclarations.Energy.ISOTHERMAL, StaticDeclarations.Viscous.LAMINAR); 87 | mu.set.solver.aggressiveSettings(); 88 | //-- 89 | mu.set.boundary.asVelocityInlet(mu.get.boundaries.byREGEX(ud.bcInlet, true), 90 | 0.1, 0.0, 0.0, 0.0); 91 | mu.set.boundary.asPressureOutlet(mu.get.boundaries.byREGEX(ud.bcOutlet, true), 92 | 0.0, 0.0, 0.0, 0.0); 93 | //-- 94 | mu.update.volumeMesh(); 95 | } 96 | 97 | private void prep4_setPost() { 98 | //-- Contour Plot 99 | ud.plane = mu.add.derivedPart.sectionPlaneZ(StaticDeclarations.COORD0); 100 | ud.namedObjects.add(ud.plane); 101 | ud.ff1 = mu.get.objects.fieldFunction(StaticDeclarations.Vars.VEL.getVar(), true); 102 | mu.add.scene.scalar(ud.namedObjects, ud.ff1, ud.defUnitVel, true); 103 | //-- Stopping Criteria 104 | ud.bdry = mu.get.boundaries.byREGEX(ud.bcInlet, true); 105 | ud.ff2 = mu.get.objects.fieldFunction(StaticDeclarations.Vars.P.getVar(), true); 106 | ud.rep = mu.add.report.massFlowAverage(ud.bdry, "Pressure Inlet", ud.ff2, ud.unit_Pa, true); 107 | ud.mon = mu.get.monitors.byREGEX(ud.rep.getPresentationName(), true); 108 | mu.add.solver.stoppingCriteria(ud.mon, StaticDeclarations.StopCriteria.ASYMPTOTIC, 109 | 0.001, 50); 110 | mu.open.all(); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /demos/Demo2_Conduction_In_a_Channel.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import macroutils.StaticDeclarations; 3 | import macroutils.UserDeclarations; 4 | import star.common.StarMacro; 5 | import star.vis.ScalarDisplayer; 6 | import star.vis.Scene; 7 | 8 | /** 9 | * Simple Demo of a 3D conduction in a channel. 10 | * 11 | * Geometry: 12 | * 13 | * +---------------------------------------------------------------+ 14 | * D / /| 15 | * / L / | 16 | * +---------------------------------------------------------------+ | 17 | * | | + 18 | * H | | / 19 | * | |/ 20 | * *---------------------------------------------------------------+ 21 | * O(0,0,0) 22 | * 23 | * @since Macro Utils v2b. 24 | * @author Fabio Kasper 25 | */ 26 | public class Demo2_Conduction_In_a_Channel extends StarMacro { 27 | 28 | private final double depth = 50; 29 | private final double height = 100; 30 | private final double length = 1000; 31 | private MacroUtils mu; 32 | private UserDeclarations ud; 33 | 34 | @Override 35 | public void execute() { 36 | 37 | initMacro(); 38 | 39 | prep1_createPart(); 40 | 41 | prep2_createRegion(); 42 | 43 | prep3_BCsAndMesh(); 44 | 45 | prep4_setPost(); 46 | 47 | mu.run(); 48 | 49 | mu.saveSim(); 50 | 51 | mu.io.write.all(ud.simTitle); 52 | 53 | } 54 | 55 | private void initMacro() { 56 | mu = new MacroUtils(getActiveSimulation()); 57 | ud = mu.userDeclarations; 58 | ud.simTitle = "Demo2_Conduction_In_a_Channel"; 59 | } 60 | 61 | private void prep1_createPart() { 62 | ud.defCamView = mu.io.read.cameraView("myCam|5.003809e-01,1.413476e-02,4.204865e-03" 63 | + "|-1.256561e+00,7.844162e-01,1.422375e+00|2.630476e-01,9.462717e-01,-1.880847e-01" 64 | + "|2.280761e-01|1", true); 65 | ud.cadPrt = mu.add.geometry.block3DCAD(StaticDeclarations.COORD0, 66 | new double[]{ length, height, depth }, ud.unit_mm); 67 | ud.cadPrt.setPresentationName("Channel"); 68 | ud.geometryParts.add(mu.get.geometries.byREGEX(".*", true)); 69 | } 70 | 71 | private void prep2_createRegion() { 72 | mu.get.partSurfaces.byREGEX("x0", true).setPresentationName(ud.bcHot); 73 | mu.get.partSurfaces.byREGEX("x1", true).setPresentationName(ud.bcCold); 74 | mu.set.geometry.combinePartSurfaces(mu.get.partSurfaces.allByREGEX("y.*", true), true) 75 | .setPresentationName(ud.bcWall); 76 | mu.set.geometry.combinePartSurfaces(mu.get.partSurfaces.allByREGEX("z.*", true), true) 77 | .setPresentationName(ud.bcSym); 78 | ud.region = mu.add.region.fromAll(true); 79 | } 80 | 81 | private void prep3_BCsAndMesh() { 82 | //-- Physics/Mesh settings 83 | ud.mshBaseSize = depth / 5; 84 | ud.mshTrimmerMaxCellSize = 100; 85 | ud.urfSolidEnrgy = 1.0; 86 | //-- 87 | ud.autoMshOp = mu.add.meshOperation.automatedMesh(ud.geometryParts, 88 | StaticDeclarations.Meshers.TRIMMER_MESHER); 89 | ud.autoMshOp.setPresentationName("My Mesh"); 90 | ud.physCont = mu.add.physicsContinua.generic(StaticDeclarations.Space.THREE_DIMENSIONAL, 91 | StaticDeclarations.Time.STEADY, StaticDeclarations.Material.SOLID, 92 | StaticDeclarations.Solver.SEGREGATED, StaticDeclarations.Density.INCOMPRESSIBLE, 93 | StaticDeclarations.Energy.THERMAL, StaticDeclarations.Viscous.NOT_APPLICABLE); 94 | mu.update.solverSettings(); 95 | //-- 96 | ud.bdry = mu.get.boundaries.byREGEX(ud.bcHot, true); 97 | mu.set.boundary.asConvectionWall(ud.bdry, 50., 50.); 98 | ud.bdry = mu.get.boundaries.byREGEX(ud.bcCold, true); 99 | mu.set.boundary.asConvectionWall(ud.bdry, 20., 15.); 100 | ud.bdry = mu.get.boundaries.byREGEX(ud.bcSym, true); 101 | mu.set.boundary.asSymmetry(ud.bdry); 102 | //-- 103 | mu.update.volumeMesh(); 104 | } 105 | 106 | private void prep4_setPost() { 107 | //-- Stopping Criteria 108 | ud.ff = mu.get.objects.fieldFunction(StaticDeclarations.Vars.T.getVar(), true); 109 | ud.rep = mu.add.report.volumeAverage(mu.get.regions.all(false), 110 | StaticDeclarations.Vars.T.getVar(), ud.ff, ud.defUnitTemp, true); 111 | ud.mon = mu.get.monitors.byREGEX(ud.rep.getPresentationName(), true); 112 | mu.add.solver.stoppingCriteria(ud.mon, StaticDeclarations.StopCriteria.ASYMPTOTIC, 113 | 0.001, 50); 114 | //-- Contour Plot 115 | ud.namedObjects.addAll(mu.get.boundaries.all(true)); 116 | Scene scn = mu.add.scene.scalar(ud.namedObjects, ud.ff, ud.defUnitTemp, true); 117 | ScalarDisplayer sd = (ScalarDisplayer) mu.get.scenes.displayerByREGEX(scn, ".*", true); 118 | sd.setDisplayMeshBoolean(true); 119 | ud.updEvent = mu.add.tools.updateEvent_Iteration(50, 0); 120 | mu.set.scene.updateEvent(scn, ud.updEvent); 121 | mu.open.all(); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /demos/Demo4_Split_Part_Surfaces.java: -------------------------------------------------------------------------------- 1 | 2 | import macroutils.MacroUtils; 3 | import macroutils.StaticDeclarations; 4 | import macroutils.UserDeclarations; 5 | import star.common.StarMacro; 6 | 7 | /** 8 | * Demo on how to split Part Surfaces and identify them based on geometric ranges. Very useful when 9 | * automating processes. 10 | * 11 | * @since Macro Utils v2b. 12 | * @author Fabio Kasper 13 | */ 14 | public class Demo4_Split_Part_Surfaces extends StarMacro { 15 | 16 | private MacroUtils mu; 17 | private UserDeclarations ud; 18 | 19 | @Override 20 | public void execute() { 21 | 22 | mu = new MacroUtils(getActiveSimulation()); 23 | 24 | ud = mu.userDeclarations; 25 | 26 | ud.simTitle = "Demo4_Split_Part_Surfaces"; 27 | 28 | importGeometryAndSplitPartSurfaces(); 29 | 30 | mu.saveSim(); 31 | 32 | mu.io.write.all(ud.simTitle); 33 | 34 | } 35 | 36 | private void importGeometryAndSplitPartSurfaces() { 37 | 38 | mu.add.geometry.importPart("radial_impeller.stp"); 39 | 40 | ud.geomPrt = mu.get.geometries.byREGEX(".*", true); 41 | mu.get.partSurfaces.byREGEX(ud.geomPrt, ".*", true).setPresentationName("Faces"); 42 | 43 | //-- 44 | //-- First split by angle and rename the first two surfaces 45 | //-- 46 | mu.set.geometry.splitPartSurfacesByAngle( 47 | mu.get.partSurfaces.all(ud.geomPrt, true), 48 | 85, true); 49 | 50 | ud.partSrf = mu.get.partSurfaces.byRangeMin( 51 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true), 52 | StaticDeclarations.Axis.Y, 1.); 53 | ud.partSrf.setPresentationName("bottom"); 54 | 55 | ud.partSrf = mu.get.partSurfaces.byAreaMin( 56 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true)); 57 | ud.partSrf.setPresentationName("shaft"); 58 | 59 | //-- 60 | //-- Then split blades by the Part Curve and rename two more surfaces 61 | //-- 62 | mu.set.geometry.splitPartSurfacesByPartCurves( 63 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true), 64 | mu.get.partCurves.allByREGEX(ud.geomPrt, ".*", true), 65 | true); 66 | 67 | ud.partSrf = mu.get.partSurfaces.byRangeMin( 68 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true), 69 | StaticDeclarations.Axis.Y, 20.); 70 | ud.partSrf.setPresentationName("ext tip"); 71 | 72 | ud.partSrf = mu.get.partSurfaces.byAreaMax( 73 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true)); 74 | ud.partSrf.setPresentationName("blades"); 75 | 76 | //-- 77 | //-- Finally combine the remaining surfaces and rename it. 78 | //-- 79 | ud.partSrf = mu.set.geometry.combinePartSurfaces( 80 | mu.get.partSurfaces.allByREGEX(ud.geomPrt, "Faces.*", true), true); 81 | ud.partSrf.setPresentationName("blades tips"); 82 | 83 | ud.defCamView = mu.io.read.cameraView("cam|-2.343460e-03,4.096864e-02,2.864518e-02" 84 | + "|-1.684336e-02,5.075395e-01,3.809093e-01|1.234549e-02,6.027526e-01,-7.978326e-01" 85 | + "|9.030182e-02|1", true); 86 | mu.add.scene.geometry().open(); 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /demos/Demo6_Scene_Resolution.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import macroutils.UserDeclarations; 3 | import star.common.StarMacro; 4 | 5 | /** 6 | * How to adjust STAR-CCM+ GUI in order to get the desired resolution on Scenes. This is useful for 7 | * creating high quality pictures. 8 | * 9 | * @since Macro Utils v2c. 10 | * @author Fabio Kasper 11 | */ 12 | public class Demo6_Scene_Resolution extends StarMacro { 13 | 14 | private MacroUtils mu; 15 | private final int slpTime = 5; 16 | private UserDeclarations ud; 17 | 18 | @Override 19 | public void execute() { 20 | 21 | initMacro(); 22 | 23 | createOrUpdateResolutionScene(); 24 | 25 | while (true) { 26 | 27 | mu.get.objects.annotation(".*pixels", false).setText(getResolution()); 28 | 29 | mu.io.sleep(slpTime * 1000); 30 | 31 | if (!mu.check.is.open(ud.scene)) { 32 | 33 | break; 34 | 35 | } 36 | } 37 | 38 | mu.getSimulation().getSceneManager().remove(ud.scene); 39 | 40 | } 41 | 42 | private void createOrUpdateResolutionScene() { 43 | String sceneName = "__Resolution__"; 44 | ud.scene = mu.get.scenes.byREGEX(sceneName, true); 45 | if (ud.scene != null) { 46 | return; 47 | } 48 | ud.scene = mu.add.scene.empty(); 49 | ud.scene.setPresentationName(sceneName); 50 | mu.io.sleep(250); 51 | mu.add.scene.annotation(ud.scene, "Scene Resolution", 0.08, new double[]{ 0.1, 0.6, 0 }); 52 | mu.add.scene.annotation(ud.scene, "Close this Scene to stop the Macro...", 0.04, 53 | new double[]{ 0.1, 0.01, 0 }); 54 | String s = String.format("Refreshing Scene in %d seconds...", slpTime); 55 | mu.add.scene.annotation(ud.scene, getResolution(), 0.05, new double[]{ 0.1, 0.5, 0 }); 56 | mu.add.scene.annotation(ud.scene, s, 0.05, new double[]{ 0.1, 0.4, 0 }); 57 | ud.scene.open(); 58 | } 59 | 60 | private String getResolution() { 61 | int px = ud.scene.getWidth(); 62 | int py = ud.scene.getHeight(); 63 | return String.format("%d x %d pixels", px, py); 64 | } 65 | 66 | private void initMacro() { 67 | mu = new MacroUtils(getActiveSimulation()); 68 | ud = mu.userDeclarations; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /demos/Demo6b_Write_Camera_Views.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import star.common.StarMacro; 3 | 4 | public class Demo6b_Write_Camera_Views extends StarMacro { 5 | 6 | @Override 7 | public void execute() { 8 | 9 | new MacroUtils(getActiveSimulation()).io.write.cameraViews("myCameras.txt"); 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demos/Demo6c_Read_Camera_Views.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import star.common.StarMacro; 3 | import star.vis.Scene; 4 | import star.vis.VisView; 5 | 6 | public class Demo6c_Read_Camera_Views extends StarMacro { 7 | 8 | @Override 9 | public void execute() { 10 | 11 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 12 | 13 | mu.io.read.cameraViews("myCameras.txt"); 14 | 15 | Scene scene = mu.get.scenes.byREGEX(".*", true); 16 | 17 | for (VisView vv : mu.get.cameras.all(true)) { 18 | 19 | mu.set.scene.cameraView(scene, vv, true); 20 | 21 | mu.io.sleep(1000); // Wait one second. 22 | 23 | mu.io.write.picture(scene, "pic " + vv.getPresentationName(), 1280, 720, true); 24 | 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /demos/Demo9_Make_Me_Pretty.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import star.common.StarMacro; 3 | 4 | /** 5 | * Prettify Scenes, Plots, Annotations and Monitors with this very useful method. 6 | * 7 | * @since Macro Utils v2c. 8 | * @author Fabio Kasper 9 | */ 10 | public class Demo9_Make_Me_Pretty extends StarMacro { 11 | 12 | @Override 13 | public void execute() { 14 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 15 | mu.templates.prettify.all(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /macroutils/build.gradle: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * MacroUtils source code build.gradle script 4 | * 5 | *******************************************************************************/ 6 | 7 | jar { 8 | 9 | manifest { 10 | 11 | attributes( 12 | 'Manifest-Version' : '1.2', 13 | 'Build-JDK': System.properties['java.version'], 14 | 'Build-OS': System.properties['os.name'], 15 | 'Build-Date': new Date(), 16 | 'Created-By': "Gradle ${gradle.gradleVersion}", 17 | 'Specification-Title': "${rootProject.name}", 18 | 'Specification-Version': "build-${buildDate}", 19 | 'Implementation-Title': 'Simcenter STAR-CCM+', 20 | 'Implementation-Version': buildVersion, 21 | ) 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/checker/CheckHas.java: -------------------------------------------------------------------------------- 1 | package macroutils.checker; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.Simulation; 5 | import star.meshing.AutoMeshOperation; 6 | 7 | /** 8 | * Low-level class for has-type methods in MacroUtils. 9 | * 10 | * @since February of 2016 11 | * @author Fabio Kasper 12 | */ 13 | public class CheckHas { 14 | 15 | private macroutils.getter.MainGetter _get = null; 16 | private MacroUtils _mu = null; 17 | private Simulation _sim = null; 18 | 19 | /** 20 | * Main constructor for this class. 21 | * 22 | * @param m given MacroUtils object. 23 | */ 24 | public CheckHas(MacroUtils m) { 25 | _mu = m; 26 | _sim = m.getSimulation(); 27 | } 28 | 29 | /** 30 | * Does the simulation have the Eulerian Multiphase Solver (EMP)? 31 | * 32 | * @return True or False. 33 | */ 34 | public boolean EMP() { 35 | return _sim.getSolverManager().has("Multiphase Segregated Flow"); 36 | } 37 | 38 | /** 39 | * Does the simulation have the PISO Unsteady Solver? 40 | * 41 | * @return True or False. 42 | */ 43 | public boolean PISO() { 44 | return _sim.getSolverManager().has("PISO Unsteady"); 45 | } 46 | 47 | /** 48 | * Does the simulation have the Volume of Fluid Solver (VOF)? 49 | * 50 | * @return True or False. 51 | */ 52 | public boolean VOF() { 53 | return _sim.getSolverManager().has("Segregated VOF"); 54 | } 55 | 56 | /** 57 | * Does the simulation have the Coupled Implicit Solver? 58 | * 59 | * @return True or False. 60 | */ 61 | public boolean coupledImplicit() { 62 | return _sim.getSolverManager().has("Coupled Implicit"); 63 | } 64 | 65 | /** 66 | * Does the Automated Mesh Operation have the Polyhedral Mesher? 67 | * 68 | * @param amo given Automated Mesh Operation. 69 | * @return True or False. 70 | */ 71 | public boolean polyMesher(AutoMeshOperation amo) { 72 | return amo.getMeshers().has("Polyhedral Mesher"); 73 | } 74 | 75 | /** 76 | * Does the Automated Mesh Operation have the Prism Layer Mesher? 77 | * 78 | * @param amo given Automated Mesh Operation. 79 | * @return True or False. 80 | */ 81 | public boolean prismLayerMesher(AutoMeshOperation amo) { 82 | return amo.getMeshers().has("Prism Layer Mesher"); 83 | } 84 | 85 | /** 86 | * Does the Automated Mesh Operation have the Surface Remesher? 87 | * 88 | * @param amo given Automated Mesh Operation. 89 | * @return True or False. 90 | */ 91 | public boolean remesher(AutoMeshOperation amo) { 92 | return amo.getMeshers().has("Surface Remesher"); 93 | } 94 | 95 | /** 96 | * Does the simulation have the Segregated Energy Solver? 97 | * 98 | * @return True or False. 99 | */ 100 | public boolean segregatedEnergy() { 101 | return _sim.getSolverManager().has("Segregated Energy"); 102 | } 103 | 104 | /** 105 | * Does the simulation have the Segregated Flow Solver? 106 | * 107 | * @return True or False. 108 | */ 109 | public boolean segregatedFlow() { 110 | return _sim.getSolverManager().has("Segregated Flow"); 111 | } 112 | 113 | /** 114 | * Does the Simulation have a Solution, i.e., Fields were Initialized? 115 | * 116 | * @return True or False. 117 | */ 118 | public boolean solution() { 119 | return _sim.getSolution().isInitialized() || _get.solver.iteration() > 0; 120 | } 121 | 122 | /** 123 | * Does the Automated Mesh Operation have the Tetrahedral Mesher? 124 | * 125 | * @param amo given Automated Mesh Operation. 126 | * @return True or False. 127 | */ 128 | public boolean tetMesher(AutoMeshOperation amo) { 129 | return amo.getMeshers().has("Tetrahedral Mesher"); 130 | } 131 | 132 | /** 133 | * Does the Automated Mesh Operation have the Thin Layer Mesher? 134 | * 135 | * @param amo given Automated Mesh Operation. 136 | * @return True or False. 137 | */ 138 | public boolean thinMesher(AutoMeshOperation amo) { 139 | return amo.getMeshers().has("Thin Mesher"); 140 | } 141 | 142 | /** 143 | * Does the Automated Mesh Operation have the Trimmer Mesher? 144 | * 145 | * @param amo given Automated Mesh Operation. 146 | * @return True or False. 147 | */ 148 | public boolean trimmerMesher(AutoMeshOperation amo) { 149 | return amo.getMeshers().has("Trimmed Cell Mesher"); 150 | } 151 | 152 | /** 153 | * This method is called automatically by {@link MacroUtils}. 154 | */ 155 | public void updateInstances() { 156 | _get = _mu.get; 157 | } 158 | 159 | /** 160 | * Does the Simulation have a Valid Volume Mesh? 161 | * 162 | * @return True or False. 163 | */ 164 | public boolean volumeMesh() { 165 | return _sim.getRepresentationManager().has("Volume Mesh"); 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/checker/MainChecker.java: -------------------------------------------------------------------------------- 1 | package macroutils.checker; 2 | 3 | import macroutils.MacroUtils; 4 | 5 | /** 6 | * Main class for check-type (e.g.: is/has) methods in MacroUtils. 7 | * 8 | * @since February of 2016 9 | * @author Fabio Kasper 10 | */ 11 | public class MainChecker { 12 | 13 | /** 14 | * This class is responsible for assessing is-type comparisons. 15 | */ 16 | public CheckHas has = null; 17 | 18 | /** 19 | * This class is responsible for assessing is-type comparisons. 20 | */ 21 | public CheckIs is = null; 22 | 23 | private macroutils.io.MainIO _io = null; 24 | private MacroUtils _mu = null; 25 | 26 | /** 27 | * Main constructor for this class. 28 | * 29 | * @param m given MacroUtils object. 30 | */ 31 | public MainChecker(MacroUtils m) { 32 | _mu = m; 33 | has = new CheckHas(m); 34 | is = new CheckIs(m); 35 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 36 | } 37 | 38 | /** 39 | * This method is called automatically by {@link MacroUtils}. 40 | */ 41 | public void updateInstances() { 42 | has.updateInstances(); 43 | is.updateInstances(); 44 | _io = _mu.io; 45 | _io.print.msgDebug("" + this.getClass().getSimpleName() 46 | + " instances updated succesfully."); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/CreateInterface.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.Boundary; 5 | import star.common.BoundaryInterface; 6 | import star.common.InterfaceConfigurationOption; 7 | import star.common.Simulation; 8 | 9 | /** 10 | * Low-level class for creating Interfaces with MacroUtils. 11 | * 12 | * @since September of 2016 13 | * @author Fabio Kasper 14 | */ 15 | public class CreateInterface { 16 | 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public CreateInterface(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | } 30 | 31 | /** 32 | * Creates a Boundary Interface. 33 | * 34 | * @param b1 given Boundary 1. 35 | * @param b2 given Boundary 2. 36 | * @return The BoundaryInterface. 37 | */ 38 | public BoundaryInterface boundaryInterface(Boundary b1, Boundary b2) { 39 | BoundaryInterface bi = _createInterface(b1, b2); 40 | _io.say.created(bi, true); 41 | return bi; 42 | } 43 | 44 | /** 45 | * Creates a Boundary Interface. 46 | * 47 | * @param b1 given Boundary 1. 48 | * @param b2 given Boundary 2. 49 | * @param type given InterfaceConfigurationOption type; 50 | * @return The BoundaryInterface. 51 | */ 52 | public BoundaryInterface boundaryInterface(Boundary b1, Boundary b2, 53 | InterfaceConfigurationOption.Type type) { 54 | BoundaryInterface bi = _createInterface(b1, b2); 55 | _io.say.created(bi, true); 56 | bi.getTopology().setSelected(type); 57 | _io.say.value("Interface Type", type.getPresentationName(), true, true); 58 | _io.say.created(bi, true); 59 | return bi; 60 | } 61 | 62 | /** 63 | * This method is called automatically by {@link MacroUtils}. 64 | */ 65 | public void updateInstances() { 66 | _io = _mu.io; 67 | } 68 | 69 | private BoundaryInterface _createInterface(Boundary b1, Boundary b2) { 70 | _io.say.action("Creating a Boundary Interface", true); 71 | _io.say.object(b1, true); 72 | _io.say.object(b2, true); 73 | return _sim.getInterfaceManager().createBoundaryInterface(b1, b2, "Interface"); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/CreatePartContact.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.PartContactManager; 5 | import star.common.PartSurface; 6 | import star.common.Simulation; 7 | 8 | /** 9 | * Low-level class for creating Part Contacts with MacroUtils. 10 | * 11 | * @since March of 2017 12 | * @author Fabio Kasper 13 | */ 14 | public class CreatePartContact { 15 | 16 | private macroutils.io.MainIO _io = null; 17 | private MacroUtils _mu = null; 18 | private Simulation _sim = null; 19 | 20 | /** 21 | * Main constructor for this class. 22 | * 23 | * @param m given MacroUtils object. 24 | */ 25 | public CreatePartContact(MacroUtils m) { 26 | _mu = m; 27 | _sim = m.getSimulation(); 28 | } 29 | 30 | /** 31 | * Creates a Periodic contact between two Part Surfaces. 32 | * 33 | * @param psA given Part Surface side A. 34 | * @param psB given Part Surface side B. 35 | */ 36 | public void periodic(PartSurface psA, PartSurface psB) { 37 | _io.say.action("Creating a Periodic Part Contact", true); 38 | _io.say.object(psA, true); 39 | _io.say.object(psB, true); 40 | _getPCM().createPeriodic(psA, psB); 41 | _io.say.ok(true); 42 | } 43 | 44 | /** 45 | * This method is called automatically by {@link MacroUtils}. 46 | */ 47 | public void updateInstances() { 48 | _io = _mu.io; 49 | } 50 | 51 | private PartContactManager _getPCM() { 52 | return _sim.get(PartContactManager.class); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/CreatePlot.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import macroutils.MacroUtils; 6 | import star.base.neo.NamedObject; 7 | import star.common.Cartesian2DPlot; 8 | import star.common.FieldFunction; 9 | import star.common.PartGroupDataSet; 10 | import star.common.Simulation; 11 | import star.common.Units; 12 | import star.common.WeightingMode; 13 | import star.coremodule.ui.plotsetup.PlotAxisInput; 14 | import star.coremodule.ui.plotsetup.SimDataSourceType; 15 | import star.coremodule.ui.plotsetup.VariableType; 16 | import star.coremodule.ui.plotsetup.XyPlotTypeEnum; 17 | import star.coremodule.ui.plotsetup.dscfg.HistogramDataSeriesConfig; 18 | import star.coremodule.ui.plotsetup.dscfg.XyDataSeriesConfig; 19 | 20 | /** 21 | * Low-level class for creating Plots with MacroUtils. 22 | * 23 | * @since August of 2016 24 | * @author Fabio Kasper 25 | */ 26 | public class CreatePlot { 27 | 28 | private macroutils.io.MainIO _io = null; 29 | private MacroUtils _mu = null; 30 | private Simulation _sim = null; 31 | 32 | /** 33 | * Main constructor for this class. 34 | * 35 | * @param m given MacroUtils object. 36 | */ 37 | public CreatePlot(MacroUtils m) { 38 | _mu = m; 39 | _sim = m.getSimulation(); 40 | } 41 | 42 | /** 43 | * This method is called automatically by {@link MacroUtils}. 44 | */ 45 | public void updateInstances() { 46 | _io = _mu.io; 47 | } 48 | 49 | /** 50 | * Creates an empty plot. 51 | * 52 | * @return The Cartesian2DPlot 53 | */ 54 | public Cartesian2DPlot empty() { 55 | _io.say.action("Creating an empty Plot", true); 56 | Cartesian2DPlot plot = _sim.getPlotManager().createCartesian2DPlot("", List.of()); 57 | _io.say.created(plot, true); 58 | return plot; 59 | } 60 | 61 | /** 62 | * Creates a Histogram Plot from the selected Objects. 63 | * 64 | * @param ano given ArrayList of STAR-CCM+ Objects 65 | * @param ff given Field Function for the bin 66 | * 67 | * @return The HistogramPlot 68 | */ 69 | public Cartesian2DPlot histogram(ArrayList ano, FieldFunction ff) { 70 | 71 | _io.say.action("Creating a Histogram Plot", true); 72 | _io.say.objects(ano, "Parts", true); 73 | _io.say.object(ff, true); 74 | 75 | HistogramDataSeriesConfig config = new HistogramDataSeriesConfig(SimDataSourceType.PARTS, 76 | ano, null, 77 | new PlotAxisInput(VariableType.SCALAR, new PlotAxisInput.ScalarFunctionInput(ff)), 78 | new PlotAxisInput(VariableType.SCALAR), WeightingMode.FREQUENCY); 79 | Cartesian2DPlot plot = _sim.getPlotManager().createCartesian2DPlot("", 80 | List.of(XyPlotTypeEnum.HISTOGRAM), config); 81 | 82 | _io.say.created(plot, true); 83 | return plot; 84 | 85 | } 86 | 87 | /** 88 | * Creates a Single XY Plot type from the selected Objects. 89 | * 90 | * @param ano given ArrayList of STAR-CCM+ Objects. 91 | * @param ffx given Field Function for the x-axis. 92 | * @param ux given units for the Field Function in the x-axis. 93 | * @param ffy given Field Function for the y-axis. 94 | * @param uy given units for the Field Function in the y-axis. 95 | * 96 | * @return The created XY Plot. 97 | */ 98 | public Cartesian2DPlot xy(ArrayList ano, FieldFunction ffx, Units ux, FieldFunction ffy, 99 | Units uy) { 100 | 101 | _io.say.action("Creating a XY Plot", true); 102 | _io.say.objects(ano, "Parts", true); 103 | _io.say.value("X-Axis", ffx.getPresentationName(), true, true); 104 | _io.say.value("Y-Axis", ffy.getPresentationName(), true, true); 105 | 106 | XyDataSeriesConfig config = new XyDataSeriesConfig(SimDataSourceType.PARTS, 107 | ano, null, 108 | new PlotAxisInput(VariableType.SCALAR, new PlotAxisInput.ScalarFunctionInput(ffx)), 109 | new PlotAxisInput(VariableType.SCALAR, new PlotAxisInput.ScalarFunctionInput(ffy))); 110 | Cartesian2DPlot plot = _sim.getPlotManager().createCartesian2DPlot("", 111 | List.of(XyPlotTypeEnum.BASIC), config); 112 | PartGroupDataSet ds = (PartGroupDataSet) plot.getDataSeriesOrder().getFirst(); 113 | ds.getAxisTypeManager().getAxisType("Bottom Axis Data").getScalarFunction().setUnits(ux); 114 | ds.getAxisTypeManager().getAxisType("Left Axis Data").getScalarFunction().setUnits(uy); 115 | 116 | _io.say.created(plot, true); 117 | return plot; 118 | 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/CreateRegion.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import macroutils.StaticDeclarations; 6 | import star.common.GeometryPart; 7 | import star.common.Region; 8 | import star.common.RegionManager; 9 | import star.common.Simulation; 10 | import star.common.SimulationPartManager; 11 | 12 | /** 13 | * Low-level class for creating Regions with MacroUtils. 14 | * 15 | * @since April of 2016 16 | * @author Fabio Kasper 17 | */ 18 | public class CreateRegion { 19 | 20 | private macroutils.getter.MainGetter _get = null; 21 | private macroutils.io.MainIO _io = null; 22 | private MacroUtils _mu = null; 23 | private Simulation _sim = null; 24 | 25 | /** 26 | * Main constructor for this class. 27 | * 28 | * @param m given MacroUtils object. 29 | */ 30 | public CreateRegion(MacroUtils m) { 31 | _mu = m; 32 | _sim = m.getSimulation(); 33 | } 34 | 35 | /** 36 | * Creates a single Region from all Parts available in the model using one Boundary per Part 37 | * Surface and Contact-mode Interface (if available). 38 | * 39 | * @param vo given verbose option. False will not print anything. 40 | * @return The created Region. 41 | */ 42 | public Region fromAll(boolean vo) { 43 | return fromParts(_get.geometries.all(false), StaticDeclarations.RegionMode.ONE, 44 | StaticDeclarations.BoundaryMode.ONE_FOR_EACH_PART_SURFACE, 45 | StaticDeclarations.InterfaceMode.CONTACT, 46 | true).get(0); 47 | } 48 | 49 | /** 50 | * Creates a single Region from the Part provided. 51 | * 52 | * @param gp given GeometryPart. 53 | * @param bm given Boundary mode. See {@link macroutils.StaticDeclarations.BoundaryMode} for 54 | * options. 55 | * @param im given Interface mode. See {@link macroutils.StaticDeclarations.InterfaceMode} for 56 | * options. 57 | * @param vo given verbose option. False will not print anything. 58 | * @return The Region. 59 | */ 60 | public Region fromPart(GeometryPart gp, StaticDeclarations.BoundaryMode bm, 61 | StaticDeclarations.InterfaceMode im, boolean vo) { 62 | return fromParts(_get.objects.arrayList(gp), bm, im, vo); 63 | } 64 | 65 | /** 66 | * Creates a single Region from the Parts provided. 67 | * 68 | * @param agp given ArrayList of Geometry Parts. 69 | * @param bm given Boundary mode. See {@link macroutils.StaticDeclarations.BoundaryMode} for 70 | * options. 71 | * @param im given Interface mode. See {@link macroutils.StaticDeclarations.InterfaceMode} for 72 | * options. 73 | * @param vo given verbose option. False will not print anything. 74 | * @return An ArrayList of the created Regions. 75 | */ 76 | public Region fromParts(ArrayList agp, StaticDeclarations.BoundaryMode bm, 77 | StaticDeclarations.InterfaceMode im, boolean vo) { 78 | return fromParts(agp, StaticDeclarations.RegionMode.ONE, bm, im, vo).get(0); 79 | } 80 | 81 | /** 82 | * Creates a dedicated Region for every Part provided. 83 | * 84 | * @param agp given ArrayList of Geometry Parts. 85 | * @param rm given Region mode. See {@link macroutils.StaticDeclarations.RegionMode} for 86 | * options. 87 | * @param bm given Boundary mode. See {@link macroutils.StaticDeclarations.BoundaryMode} for 88 | * options. 89 | * @param im given Interface mode. See {@link macroutils.StaticDeclarations.InterfaceMode} for 90 | * options. 91 | * @param vo given verbose option. False will not print anything. 92 | * @return An ArrayList of the created Regions. 93 | */ 94 | public ArrayList fromParts(ArrayList agp, 95 | StaticDeclarations.RegionMode rm, StaticDeclarations.BoundaryMode bm, 96 | StaticDeclarations.InterfaceMode im, boolean vo) { 97 | switch (rm) { 98 | case ONE: 99 | _io.say.action("Assigning Parts to a Single Region", vo); 100 | break; 101 | case ONE_PER_PART: 102 | _io.say.action("Assigning Parts to Different Regions", vo); 103 | break; 104 | } 105 | if (agp.size() == 1) { 106 | rm = StaticDeclarations.RegionMode.ONE_PER_PART; 107 | } 108 | _io.say.msg(vo, "Boundary Mode: %s", bm.getMode()); 109 | _io.say.objects(agp, "Geometry Parts", vo); 110 | ArrayList ar0 = _get.regions.all(false); 111 | RegionManager rmg = _sim.getRegionManager(); 112 | rmg.newRegionsFromParts(agp, 113 | rm.getMode(), null, 114 | bm.getMode(), null, 115 | im.getMode()); 116 | ArrayList ar1 = _get.regions.all(false); 117 | ar1.removeAll(ar0); 118 | _io.say.msg(vo, "Regions created: %d", ar1.size()); 119 | ArrayList amp = new ArrayList<>(); 120 | amp.add(_sim.get(SimulationPartManager.class)); 121 | //-- Attempt to automatically create the Interfaces. 122 | rmg.updateInterfacesFromPartContacts(amp, im.getMode()); 123 | return ar1; 124 | } 125 | 126 | /** 127 | * This method is called automatically by {@link MacroUtils}. 128 | */ 129 | public void updateInstances() { 130 | _get = _mu.get; 131 | _io = _mu.io; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/CreateUnits.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.StaticDeclarations; 5 | import star.common.Dimensions; 6 | import star.common.Simulation; 7 | import star.common.Units; 8 | import star.common.UserUnits; 9 | 10 | /** 11 | * Low-level class for creating/updating Units with MacroUtils. 12 | * 13 | * @since February of 2016 14 | * @author Fabio Kasper 15 | */ 16 | public class CreateUnits { 17 | 18 | private macroutils.getter.MainGetter _get = null; 19 | private macroutils.io.MainIO _io = null; 20 | private MacroUtils _mu = null; 21 | private Simulation _sim = null; 22 | 23 | /** 24 | * Main constructor for this class. 25 | * 26 | * @param m given MacroUtils object. 27 | */ 28 | public CreateUnits(MacroUtils m) { 29 | _mu = m; 30 | _sim = m.getSimulation(); 31 | } 32 | 33 | /** 34 | * Creates a custom Unit. 35 | * 36 | * @param name given Unit name. 37 | * @param desc given Unit description. 38 | * @param conv given Unit conversion factor. 39 | * @param dim given Dimensions. 40 | * @return The created Unit. 41 | */ 42 | public Units custom(String name, String desc, double conv, Dimensions dim) { 43 | return custom(name, desc, conv, dim, true); 44 | } 45 | 46 | /** 47 | * Creates a custom Unit. 48 | * 49 | * @param name given Unit name. 50 | * @param desc given Unit description. 51 | * @param conv given Unit conversion factor. 52 | * @param dim given Dimensions. 53 | * @param vo given verbose option. False will not print anything. 54 | * @return The created Unit. 55 | */ 56 | public Units custom(String name, String desc, double conv, Dimensions dim, boolean vo) { 57 | Units u = _get.units.byName(name, false); 58 | if (u == null) { 59 | _io.print.msg(vo, StaticDeclarations.UNIT_FMT, "Creating Unit", name, desc); 60 | UserUnits uu = _sim.getUnitsManager().createUnits("Units"); 61 | uu.setPresentationName(name); 62 | uu.setDescription(desc); 63 | uu.setConversion(conv); 64 | uu.setDimensions(dim); 65 | return uu; 66 | } 67 | _io.print.msg(vo, StaticDeclarations.UNIT_FMT, "Unit already exists", name, 68 | u.getDescription()); 69 | return u; 70 | } 71 | 72 | /** 73 | * This method is called automatically by {@link MacroUtils}. 74 | */ 75 | public void updateInstances() { 76 | _get = _mu.get; 77 | _io = _mu.io; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/creator/MainCreator.java: -------------------------------------------------------------------------------- 1 | package macroutils.creator; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.ScalarGlobalParameter; 5 | 6 | /** 7 | * Main class for creating STAR-CCM+ objects with MacroUtils. 8 | * 9 | * @since February of 2016 10 | * @author Fabio Kasper 11 | */ 12 | public class MainCreator { 13 | 14 | /** 15 | * This class is responsible for creating Part Contacts. 16 | */ 17 | public CreatePartContact contact = null; 18 | 19 | /** 20 | * This class is responsible for creating Derived Parts. 21 | */ 22 | public CreateDerivedPart derivedPart = null; 23 | 24 | /** 25 | * This class is responsible for creating Geometries in general. 26 | */ 27 | public CreateGeometry geometry = null; 28 | 29 | /** 30 | * This class is responsible for creating Interfaces in general with MacroUtils. 31 | */ 32 | public CreateInterface intrf = null; 33 | 34 | /** 35 | * This class is responsible for creating Mesh Operations. 36 | */ 37 | public CreateMeshOperation meshOperation = null; 38 | 39 | /** 40 | * This class is responsible for creating Physics Continuas. 41 | */ 42 | public CreatePhysicsContinua physicsContinua = null; 43 | 44 | /** 45 | * This class is responsible for creating Plots. 46 | */ 47 | public CreatePlot plot = null; 48 | 49 | /** 50 | * This class is responsible for creating Regions. 51 | */ 52 | public CreateRegion region = null; 53 | 54 | /** 55 | * This class is responsible for creating Reports. 56 | */ 57 | public CreateReport report = null; 58 | 59 | /** 60 | * This class is responsible for creating Scenes. 61 | */ 62 | public CreateScene scene = null; 63 | 64 | /** 65 | * This class is responsible for creating Solver related objects. 66 | */ 67 | public CreateSolver solver = null; 68 | 69 | /** 70 | * This class is responsible for creating Tools related node in general. 71 | */ 72 | public CreateTools tools = null; 73 | 74 | /** 75 | * This class is responsible for creating/adding units to STAR-CCM+. 76 | */ 77 | public CreateUnits units = null; 78 | 79 | private macroutils.creator.MainCreator _add = null; 80 | private macroutils.io.MainIO _io = null; 81 | private MacroUtils _mu = null; 82 | private macroutils.UserDeclarations _ud = null; 83 | private macroutils.misc.MainUpdater _upd = null; 84 | 85 | /** 86 | * Main constructor for this class. 87 | * 88 | * @param m given MacroUtils object. 89 | */ 90 | public MainCreator(MacroUtils m) { 91 | _mu = m; 92 | contact = new CreatePartContact(m); 93 | derivedPart = new CreateDerivedPart(m); 94 | geometry = new CreateGeometry(m); 95 | intrf = new CreateInterface(m); 96 | meshOperation = new CreateMeshOperation(m); 97 | physicsContinua = new CreatePhysicsContinua(m); 98 | plot = new CreatePlot(m); 99 | region = new CreateRegion(m); 100 | report = new CreateReport(m); 101 | solver = new CreateSolver(m); 102 | scene = new CreateScene(m); 103 | tools = new CreateTools(m); 104 | units = new CreateUnits(m); 105 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 106 | } 107 | 108 | /** 109 | * Adds all custom modifications created automatically by MacroUtils, such as: 110 | *
    111 | *
  • Custom Units; 112 | *
  • Global Parameters. 113 | *
114 | */ 115 | public void all() { 116 | if (!_mu.getIntrusiveOption()) { 117 | _io.print.msg("Intrusive Option is Disabled. Skipping..."); 118 | return; 119 | } 120 | customUnits(); 121 | globalParameters(); 122 | } 123 | 124 | /** 125 | * Adds custom units that are not shipped with STAR-CCM+. Those are created within 126 | * MacroUtils. 127 | */ 128 | public void customUnits() { 129 | if (!_mu.getIntrusiveOption()) { 130 | _io.print.msgDebug("Intrusive Option is Disabled. Skipping add.customUnits()"); 131 | return; 132 | } 133 | _upd.customUnits(true); 134 | } 135 | 136 | /** 137 | * Adds custom Global Parameters that are not shipped with STAR-CCM+. Those are created 138 | * within MacroUtils. 139 | */ 140 | public void globalParameters() { 141 | ScalarGlobalParameter pi; 142 | pi = _add.tools.scalarParameter("PI", Math.PI, _ud.unit_Dimensionless); 143 | _add.tools.comment(pi, "The good old PI number"); 144 | } 145 | 146 | /** 147 | * This method is called automatically by {@link MacroUtils}. 148 | */ 149 | public void updateInstances() { 150 | contact.updateInstances(); 151 | derivedPart.updateInstances(); 152 | geometry.updateInstances(); 153 | intrf.updateInstances(); 154 | meshOperation.updateInstances(); 155 | physicsContinua.updateInstances(); 156 | plot.updateInstances(); 157 | region.updateInstances(); 158 | report.updateInstances(); 159 | scene.updateInstances(); 160 | solver.updateInstances(); 161 | tools.updateInstances(); 162 | units.updateInstances(); 163 | _add = _mu.add; 164 | _io = _mu.io; 165 | _ud = _mu.userDeclarations; 166 | _upd = _mu.update; 167 | _io.print.msgDebug("" + this.getClass().getSimpleName() 168 | + " instances updated succesfully."); 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetBoundaries.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.common.Boundary; 6 | import star.common.InterfaceBoundary; 7 | import star.common.Region; 8 | 9 | /** 10 | * Low-level class for getting Boundaries with MacroUtils. 11 | * 12 | * @since April of 2016 13 | * @author Fabio Kasper 14 | */ 15 | public class GetBoundaries { 16 | 17 | private MainGetter _get = null; 18 | private macroutils.io.MainIO _io = null; 19 | private MacroUtils _mu = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public GetBoundaries(MacroUtils m) { 27 | _mu = m; 28 | } 29 | 30 | /** 31 | * Gets all Boundaries from all Regions available in the model. 32 | * 33 | * @param vo given verbose option. False will not print anything. 34 | * @return An ArrayList of Boundaries. 35 | */ 36 | public ArrayList all(boolean vo) { 37 | ArrayList ab = new ArrayList<>(); 38 | _io.say.msg(vo, "Getting all Boundaries from all Regions..."); 39 | _get.regions.all(false).forEach(r -> ab.addAll(all(r, false))); 40 | _io.say.objects(ab, "Boundaries", vo); 41 | return ab; 42 | } 43 | 44 | /** 45 | * Gets all Boundaries from a given Region. 46 | * 47 | * @param r given Region. 48 | * @param vo given verbose option. False will not print anything. 49 | * @return An ArrayList of Boundaries. 50 | */ 51 | public ArrayList all(Region r, boolean vo) { 52 | _io.say.value("Getting all Boundaries from Region", r.getPresentationName(), true, vo); 53 | ArrayList ab = new ArrayList<>(r.getBoundaryManager().getBoundaries()); 54 | _io.say.objects(ab, "Boundaries", vo); 55 | return ab; 56 | } 57 | 58 | /** 59 | * Gets all Boundaries that matches the REGEX search pattern from all Regions available in the 60 | * model. 61 | * 62 | * @param regexPatt given Regular Expression (REGEX) pattern. 63 | * @param vo given verbose option. False will not print anything. 64 | * @return An ArrayList of Boundaries. 65 | */ 66 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 67 | return _get.objects.allByREGEX(regexPatt, "all Boundaries", all(false), vo); 68 | } 69 | 70 | /** 71 | * Gets a Boundary that matches the REGEX search pattern among all Boundaries available in the 72 | * model. 73 | * 74 | * @param regexPatt given Regular Expression (REGEX) pattern. 75 | * @param vo given verbose option. False will not print anything. 76 | * @return The Boundary. Null if nothing is found. 77 | */ 78 | public Boundary byREGEX(String regexPatt, boolean vo) { 79 | return _get.objects.byREGEX(regexPatt, "Boundary", all(false), vo); 80 | } 81 | 82 | /** 83 | * Gets a Boundary within a Region that matches the REGEX search pattern. 84 | * 85 | * @param r given Region. 86 | * @param regexPatt given Regular Expression (REGEX) pattern. 87 | * @param vo given verbose option. False will not print anything. 88 | * @return The Boundary. Null if nothing is found. 89 | */ 90 | public Boundary byREGEX(Region r, String regexPatt, boolean vo) { 91 | return _get.objects.byREGEX(regexPatt, "Boundary", all(r, false), vo); 92 | } 93 | 94 | /** 95 | * Gets the first interface associated to a Boundary. 96 | * 97 | * @param b given Boundary. 98 | * @param vo given verbose option. False will not print anything. 99 | * @return The InterfaceBoundary. Null if nothing is found. 100 | */ 101 | public InterfaceBoundary interfaceBoundary(Boundary b, boolean vo) { 102 | _io.print.msg(vo, "Getting the InterfaceBoundary associated to Boundary: \"%s\".", 103 | b.getPresentationName()); 104 | if (b.getDependentInterfaces().isEmpty()) { 105 | _io.print.msg("No Interfaces found. Returning NULL!", vo); 106 | return null; 107 | } 108 | InterfaceBoundary ib = b.getDependentInterfaces().get(0).getInterfaceBoundary0(); 109 | _io.say.value("Found", ib.getPresentationName(), true, vo); 110 | return ib; 111 | } 112 | 113 | /** 114 | * This method is called automatically by {@link MacroUtils}. 115 | */ 116 | public void updateInstances() { 117 | _get = _mu.get; 118 | _io = _mu.io; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetGeometries.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import java.util.stream.Collectors; 5 | import macroutils.MacroUtils; 6 | import star.cadmodeler.Body; 7 | import star.cadmodeler.SolidModelPart; 8 | import star.common.GeometryPart; 9 | import star.common.PartSurface; 10 | import star.common.Simulation; 11 | import star.common.SimulationPartManager; 12 | import star.meshing.CadPart; 13 | import star.meshing.PartRepresentation; 14 | import star.meshing.RootDescriptionSource; 15 | 16 | /** 17 | * Low-level class for getting Geometry entities in general with MacroUtils. 18 | * 19 | * @since April of 2016 20 | * @author Fabio Kasper 21 | */ 22 | public class GetGeometries { 23 | 24 | private MainGetter _get = null; 25 | private macroutils.io.MainIO _io = null; 26 | private MacroUtils _mu = null; 27 | private Simulation _sim = null; 28 | 29 | /** 30 | * Main constructor for this class. 31 | * 32 | * @param m given MacroUtils object. 33 | */ 34 | public GetGeometries(MacroUtils m) { 35 | _mu = m; 36 | _sim = m.getSimulation(); 37 | } 38 | 39 | /** 40 | * Gets all Geometry Parts from the model. 41 | * 42 | * @param vo given verbose option. False will not print anything. 43 | * @return An ArrayList with Geometry Parts. 44 | */ 45 | public ArrayList all(boolean vo) { 46 | ArrayList agp = new ArrayList<>( 47 | _sim.get(SimulationPartManager.class).getLeafParts()); 48 | _io.say.objects(agp, "Getting all Leaf Parts", vo); 49 | return agp; 50 | } 51 | 52 | /** 53 | * Gets the Geometry Part that matches the REGEX search pattern. 54 | * 55 | * @param regexPatt given Regular Expression (REGEX) pattern. 56 | * @param vo given verbose option. False will not print anything. 57 | * @return The Geometry Part. 58 | */ 59 | public GeometryPart byREGEX(String regexPatt, boolean vo) { 60 | return _get.objects.byREGEX(regexPatt, "Geometry Part", all(false), vo); 61 | } 62 | 63 | /** 64 | * Gets a single CAD Part from a single 3D-CAD body. 65 | * 66 | * @param bd given 3D-CAD body. 67 | * @param vo given verbose option. False will not print anything. 68 | * @return CadPart. 69 | */ 70 | public CadPart cadPart(Body bd, boolean vo) { 71 | return (CadPart) _getSolidModelPart(bd); 72 | } 73 | 74 | /** 75 | * Gets the Geometry Parts contained in the given Part Surfaces. 76 | * 77 | * @param aps given ArrayList of Part Surfaces. 78 | * @return An ArrayList with Geometry Parts. 79 | */ 80 | public ArrayList fromPartSurfaces(ArrayList aps) { 81 | return new ArrayList<>( 82 | aps.stream() 83 | .map(ps -> ps.getPart()) 84 | .collect(Collectors.toSet())); 85 | } 86 | 87 | /** 88 | * Gets the Geometry Representation. 89 | * 90 | * @return The PartRepresentation. 91 | */ 92 | public PartRepresentation representation() { 93 | return (PartRepresentation) _sim.getRepresentationManager().getObject("Geometry"); 94 | } 95 | 96 | /** 97 | * Get the RootDescriptionSource. 98 | * 99 | * @return The RootDescriptionSource. 100 | */ 101 | public RootDescriptionSource rootDescriptionSource() { 102 | return (RootDescriptionSource) _get.mesh.descriptionSource("Root"); 103 | } 104 | 105 | /** 106 | * This method is called automatically by {@link MacroUtils}. 107 | */ 108 | public void updateInstances() { 109 | _get = _mu.get; 110 | _io = _mu.io; 111 | } 112 | 113 | private SolidModelPart _getSolidModelPart(Body bd) { 114 | for (GeometryPart gp : all(false)) { 115 | if (gp instanceof SolidModelPart) { 116 | SolidModelPart smp = (SolidModelPart) gp; 117 | if (smp.getCadModel().equals(bd.getModel())) { 118 | return smp; 119 | } 120 | } 121 | } 122 | return null; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetMonitors.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.base.report.IterationMonitor; 6 | import star.base.report.Monitor; 7 | import star.base.report.PhysicalTimeMonitor; 8 | import star.base.report.PlotableMonitor; 9 | import star.base.report.Report; 10 | import star.base.report.ReportMonitor; 11 | import star.common.Simulation; 12 | 13 | /** 14 | * Low-level class for getting Monitor related objects with MacroUtils. 15 | * 16 | * @since April of 2016 17 | * @author Fabio Kasper 18 | */ 19 | public class GetMonitors { 20 | 21 | private MainGetter _get = null; 22 | private macroutils.io.MainIO _io = null; 23 | private MacroUtils _mu = null; 24 | private Simulation _sim = null; 25 | 26 | /** 27 | * Main constructor for this class. 28 | * 29 | * @param m given MacroUtils object. 30 | */ 31 | public GetMonitors(MacroUtils m) { 32 | _mu = m; 33 | _sim = m.getSimulation(); 34 | } 35 | 36 | /** 37 | * Gets all Monitors available in the model. 38 | * 39 | * @param vo given verbose option. False will not print anything. 40 | * @return An ArrayList of Monitors. 41 | */ 42 | public ArrayList all(boolean vo) { 43 | ArrayList ar = new ArrayList<>(_sim.getMonitorManager().getObjects()); 44 | _io.say.objects(ar, "Getting all Monitors", vo); 45 | return ar; 46 | } 47 | 48 | /** 49 | * Gets all Monitors that matches the REGEX search pattern. 50 | * 51 | * @param regexPatt given Regular Expression (REGEX) pattern. 52 | * @param vo given verbose option. False will not print anything. 53 | * @return An ArrayList of Monitors. 54 | */ 55 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 56 | return _get.objects.allByREGEX(regexPatt, "Monitors", all(false), vo); 57 | } 58 | 59 | /** 60 | * Gets the Monitor that matches the REGEX search pattern. 61 | * 62 | * @param regexPatt given Regular Expression (REGEX) pattern. 63 | * @param vo given verbose option. False will not print anything. 64 | * @return The Monitor. 65 | */ 66 | public Monitor byREGEX(String regexPatt, boolean vo) { 67 | return _get.objects.byREGEX(regexPatt, "Monitor", all(false), vo); 68 | } 69 | 70 | /** 71 | * Gets the Monitor that contains the given Report, if applicable. 72 | * 73 | * @param rep given Report. 74 | * @param vo given verbose option. False will not print anything. 75 | * @return The ReportMonitor. Null if there is no Monitor associated with the Report. 76 | */ 77 | public ReportMonitor fromReport(Report rep, boolean vo) { 78 | _io.say.action("Getting a Monitor from a Report", vo); 79 | for (ReportMonitor rm : _sim.getMonitorManager().getObjectsOf(ReportMonitor.class)) { 80 | if (rm.getReport() == rep) { 81 | _io.say.value("Found", rm.getPresentationName(), true, vo); 82 | return rm; 83 | } 84 | } 85 | _io.say.msg("Nothing found. Returning NULL!"); 86 | return null; 87 | } 88 | 89 | /** 90 | * Gets the Iteration Monitor which is a type of {@link PlotableMonitor}. 91 | * 92 | * @return The Iteration Monitor. 93 | */ 94 | public IterationMonitor iteration() { 95 | return (IterationMonitor) _getMonitor("Iteration"); 96 | } 97 | 98 | /** 99 | * Gets the Physical Time Monitor which is a type of {@link PlotableMonitor}. 100 | * 101 | * @return The Physical Time Monitor. 102 | */ 103 | public PhysicalTimeMonitor physicalTime() { 104 | return (PhysicalTimeMonitor) _getMonitor("Physical Time"); 105 | } 106 | 107 | /** 108 | * This method is called automatically by {@link MacroUtils}. 109 | */ 110 | public void updateInstances() { 111 | _get = _mu.get; 112 | _io = _mu.io; 113 | } 114 | 115 | private Monitor _getMonitor(String name) { 116 | return _sim.getMonitorManager().getMonitor(name); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetPartCurves.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.common.GeometryPart; 6 | import star.common.PartCurve; 7 | import star.common.PartCurveManager; 8 | import star.meshing.CadPart; 9 | import star.meshing.LeafMeshPart; 10 | import star.meshing.MeshOperationPart; 11 | import star.meshing.SimpleBlockPart; 12 | import star.meshing.SimpleCylinderPart; 13 | 14 | /** 15 | * Low-level class for getting Part Curves with MacroUtils. 16 | * 17 | * @since April of 2016 18 | * @author Fabio Kasper 19 | */ 20 | public class GetPartCurves { 21 | 22 | private MainGetter _get = null; 23 | private macroutils.io.MainIO _io = null; 24 | private MacroUtils _mu = null; 25 | 26 | /** 27 | * Main constructor for this class. 28 | * 29 | * @param m given MacroUtils object. 30 | */ 31 | public GetPartCurves(MacroUtils m) { 32 | _mu = m; 33 | } 34 | 35 | /** 36 | * Gets all Part Curves from all Geometries available in the model. 37 | * 38 | * @param vo given verbose option. False will not print anything. 39 | * @return An ArrayList of Part Curves. 40 | */ 41 | public ArrayList all(boolean vo) { 42 | ArrayList apc = new ArrayList<>(); 43 | _get.geometries.all(false).forEach(gp -> apc.addAll(gp.getPartCurves())); 44 | _io.say.objects(apc, "Getting all Part Curves from all Geometries", vo); 45 | return apc; 46 | } 47 | 48 | /** 49 | * Gets all Part Curves from the given Geometry Part. 50 | * 51 | * @param gp given GeometryPart. 52 | * @param vo given verbose option. False will not print anything. 53 | * @return An ArrayList of Part Curves. 54 | */ 55 | public ArrayList all(GeometryPart gp, boolean vo) { 56 | ArrayList apc = new ArrayList<>(gp.getPartCurves()); 57 | _io.say.objects(apc, "Getting all Part Surfaces", vo); 58 | return apc; 59 | } 60 | 61 | /** 62 | * Gets all Part Curves that matches the REGEX search pattern from all Geometries available in 63 | * the model. 64 | * 65 | * @param regexPatt given Regular Expression (REGEX) pattern. 66 | * @param vo given verbose option. False will not print anything. 67 | * @return An ArrayList of Part Curves. 68 | */ 69 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 70 | return _get.objects.allByREGEX(regexPatt, "all Part Curves", all(false), true); 71 | } 72 | 73 | /** 74 | * Gets all Part Curves that matches the REGEX search pattern from the Part Curves available in 75 | * the Geometry Part. 76 | * 77 | * @param gp given GeometryPart. 78 | * @param regexPatt given Regular Expression (REGEX) pattern. 79 | * @param vo given verbose option. False will not print anything. 80 | * @return An ArrayList of Part Curves. 81 | */ 82 | public ArrayList allByREGEX(GeometryPart gp, String regexPatt, boolean vo) { 83 | return _get.objects.allByREGEX(regexPatt, "all Part Curves", all(gp, false), true); 84 | } 85 | 86 | /** 87 | * Gets a Part Curve that matches the REGEX search pattern among all Part Curves available in 88 | * the model. 89 | * 90 | * @param regexPatt given Regular Expression (REGEX) pattern. 91 | * @param vo given verbose option. False will not print anything. 92 | * @return The PartCurve. Null if nothing is found. 93 | */ 94 | public PartCurve byREGEX(String regexPatt, boolean vo) { 95 | return _get.objects.byREGEX(regexPatt, "Part Curve", all(false), vo); 96 | } 97 | 98 | /** 99 | * Gets a Part Curve that matches the REGEX search pattern from the Part Curves available in the 100 | * Geometry Part. 101 | * 102 | * @param gp given GeometryPart. 103 | * @param regexPatt given Regular Expression (REGEX) pattern. 104 | * @param vo given verbose option. False will not print anything. 105 | * @return The PartCurve. Null if nothing is found. 106 | */ 107 | public PartCurve byREGEX(GeometryPart gp, String regexPatt, boolean vo) { 108 | return _get.objects.byREGEX(regexPatt, "Part Curve", all(gp, false), vo); 109 | } 110 | 111 | /** 112 | * Gets its manager object from a Part Curve, if applicable. 113 | * 114 | * @param pc given Part Curve. 115 | * @return The PartCurveManager. Null if nothing is found. 116 | */ 117 | public PartCurveManager manager(PartCurve pc) { 118 | GeometryPart gp = pc.getPart(); 119 | if (gp instanceof CadPart) { 120 | return ((CadPart) gp).getPartCurveManager(); 121 | } 122 | if (gp instanceof SimpleBlockPart) { 123 | return ((SimpleBlockPart) gp).getPartCurveManager(); 124 | } 125 | if (gp instanceof SimpleCylinderPart) { 126 | return ((SimpleCylinderPart) gp).getPartCurveManager(); 127 | } 128 | if (gp instanceof MeshOperationPart) { 129 | return ((MeshOperationPart) gp).getPartCurveManager(); 130 | } 131 | //-- Leave Leaf for the last. 132 | if (gp instanceof LeafMeshPart) { 133 | return ((LeafMeshPart) gp).getPartCurveManager(); 134 | } 135 | return null; 136 | } 137 | 138 | /** 139 | * This method is called automatically by {@link MacroUtils}. 140 | */ 141 | public void updateInstances() { 142 | _get = _mu.get; 143 | _io = _mu.io; 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetParts.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.common.Part; 6 | import star.common.Simulation; 7 | 8 | /** 9 | * Low-level class for getting Parts in general, e.g.: Derived Parts, with MacroUtils. 10 | * 11 | * @since August of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class GetParts { 15 | 16 | private MainGetter _get = null; 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public GetParts(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | } 30 | 31 | /** 32 | * Gets all Parts available in the model. 33 | * 34 | * @param vo given verbose option. False will not print anything. 35 | * @return An ArrayList of Parts. 36 | */ 37 | public ArrayList all(boolean vo) { 38 | ArrayList ap = new ArrayList<>(_sim.getPartManager().getObjects()); 39 | _io.say.objects(ap, "Getting all Parts", vo); 40 | return ap; 41 | } 42 | 43 | /** 44 | * Gets all Parts that matches the REGEX search pattern. 45 | * 46 | * @param regexPatt given Regular Expression (REGEX) pattern. 47 | * @param vo given verbose option. False will not print anything. 48 | * @return An ArrayList of Parts. 49 | */ 50 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 51 | return _get.objects.allByREGEX(regexPatt, "all Parts", all(false), vo); 52 | } 53 | 54 | /** 55 | * Gets a Part that matches the REGEX search pattern among all Parts available in the model. 56 | * 57 | * @param regexPatt given Regular Expression (REGEX) pattern. 58 | * @param vo given verbose option. False will not print anything. 59 | * @return The Part. Null if nothing is found. 60 | */ 61 | public Part byREGEX(String regexPatt, boolean vo) { 62 | return _get.objects.byREGEX(regexPatt, "Part Surface", all(false), vo); 63 | } 64 | 65 | /** 66 | * This method is called automatically by {@link MacroUtils}. 67 | */ 68 | public void updateInstances() { 69 | _get = _mu.get; 70 | _io = _mu.io; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetRegions.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.common.Region; 6 | import star.common.Simulation; 7 | 8 | /** 9 | * Low-level class for getting Regions with MacroUtils. 10 | * 11 | * @since April of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class GetRegions { 15 | 16 | private MainGetter _get = null; 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public GetRegions(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | } 30 | 31 | /** 32 | * Gets all Regions available in the model. 33 | * 34 | * @param vo given verbose option. False will not print anything. 35 | * @return An ArrayList of Regions. 36 | */ 37 | public ArrayList all(boolean vo) { 38 | ArrayList ar = new ArrayList<>(_sim.getRegionManager().getRegions()); 39 | _io.say.objects(ar, "Getting all Regions", vo); 40 | return ar; 41 | } 42 | 43 | /** 44 | * Gets all Regions that matches the REGEX search pattern. 45 | * 46 | * @param regexPatt given Regular Expression (REGEX) pattern. 47 | * @param vo given verbose option. False will not print anything. 48 | * @return An ArrayList of Regions. 49 | */ 50 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 51 | return _get.objects.allByREGEX(regexPatt, "Regions", all(false), vo); 52 | } 53 | 54 | /** 55 | * Gets the Region that matches the REGEX search pattern. 56 | * 57 | * @param regexPatt given Regular Expression (REGEX) pattern. 58 | * @param vo given verbose option. False will not print anything. 59 | * @return The Region. 60 | */ 61 | public Region byREGEX(String regexPatt, boolean vo) { 62 | return _get.objects.byREGEX(regexPatt, "Region", all(false), vo); 63 | } 64 | 65 | /** 66 | * This method is called automatically by {@link MacroUtils}. 67 | */ 68 | public void updateInstances() { 69 | _get = _mu.get; 70 | _io = _mu.io; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetReports.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import java.util.ArrayList; 4 | import macroutils.MacroUtils; 5 | import star.base.report.Report; 6 | import star.common.Simulation; 7 | 8 | /** 9 | * Low-level class for getting Report related objects with MacroUtils. 10 | * 11 | * @since April of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class GetReports { 15 | 16 | private MainGetter _get = null; 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public GetReports(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | } 30 | 31 | /** 32 | * Gets all Reports available in the model. 33 | * 34 | * @param vo given verbose option. False will not print anything. 35 | * @return An ArrayList of Reports. 36 | */ 37 | public ArrayList all(boolean vo) { 38 | ArrayList ar = new ArrayList<>(_sim.getReportManager().getObjects()); 39 | _io.say.objects(ar, "Getting all Reports", vo); 40 | return ar; 41 | } 42 | 43 | /** 44 | * Gets all Reports that matches the REGEX search pattern. 45 | * 46 | * @param regexPatt given Regular Expression (REGEX) pattern. 47 | * @param vo given verbose option. False will not print anything. 48 | * @return An ArrayList of Reports. 49 | */ 50 | public ArrayList allByREGEX(String regexPatt, boolean vo) { 51 | return _get.objects.allByREGEX(regexPatt, "Reports", all(false), vo); 52 | } 53 | 54 | /** 55 | * Gets the Report that matches the REGEX search pattern. 56 | * 57 | * @param regexPatt given Regular Expression (REGEX) pattern. 58 | * @param vo given verbose option. False will not print anything. 59 | * @return The Report. 60 | */ 61 | public Report byREGEX(String regexPatt, boolean vo) { 62 | return _get.objects.byREGEX(regexPatt, "Report", all(false), vo); 63 | } 64 | 65 | /** 66 | * This method is called automatically by {@link MacroUtils}. 67 | */ 68 | public void updateInstances() { 69 | _get = _mu.get; 70 | _io = _mu.io; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/GetUnits.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.StaticDeclarations; 5 | import star.base.report.Monitor; 6 | import star.base.report.ReportMonitor; 7 | import star.common.Dimensions; 8 | import star.common.ResidualMonitor; 9 | import star.common.Simulation; 10 | import star.common.Units; 11 | import star.common.UnitsManager; 12 | 13 | /** 14 | * Low-level class for getting Units with MacroUtils. 15 | * 16 | * @since February of 2016 17 | * @author Fabio Kasper 18 | */ 19 | public class GetUnits { 20 | 21 | private MainGetter _get = null; 22 | private macroutils.io.MainIO _io = null; 23 | private MacroUtils _mu = null; 24 | private final String _s = StaticDeclarations.UNIT_DIMENSIONLESS; 25 | private Simulation _sim = null; 26 | private final String _unitDimensionless = _s; 27 | 28 | /** 29 | * Main constructor for this class. 30 | * 31 | * @param m given MacroUtils object. 32 | */ 33 | public GetUnits(MacroUtils m) { 34 | _mu = m; 35 | _sim = m.getSimulation(); 36 | } 37 | 38 | /** 39 | * Gets a unit by its Presentation Name. 40 | * 41 | * @param name given unit name. 42 | * @return The Unit. Null if nothing is found. 43 | */ 44 | public Units byName(String name) { 45 | return byName(name, true); 46 | } 47 | 48 | /** 49 | * Gets a unit by its Presentation Name. 50 | * 51 | * @param name given unit name. 52 | * @param vo given verbose option. False will not print anything. 53 | * @return The Unit. Null if nothing is found. 54 | */ 55 | public Units byName(String name, boolean vo) { 56 | UnitsManager um = _sim.getUnitsManager(); 57 | if (name.equals(_unitDimensionless)) { 58 | return um.getObject(_unitDimensionless); 59 | } 60 | _io.print.value("Getting Unit by exact match", name, true, vo); 61 | for (Units u : um.getObjects()) { 62 | if (_get.strings.fromUnit(u).equals(name) || u.getDescription().equals(name)) { 63 | _io.say.value("Found", _get.strings.fromUnit(u), true, vo); 64 | return u; 65 | } 66 | } 67 | _io.say.msg("Nothing found. Returning NULL!", vo); 68 | return null; 69 | } 70 | 71 | /** 72 | * Gets the corresponding dimensions from the unit. 73 | * 74 | * @param u given unit. 75 | * @return The Dimensions. 76 | */ 77 | public Dimensions dimensions(Units u) { 78 | return (u != null) ? u.getDimensions() : new Dimensions(); 79 | } 80 | 81 | /** 82 | * Gets the corresponding unit associated with a Monitor. 83 | * 84 | * @param m given Monitor. 85 | * @return The Unit. Null if nothing is found. 86 | */ 87 | public Units fromMonitor(Monitor m) { 88 | if (m instanceof ResidualMonitor) { 89 | return byName(_unitDimensionless, false); 90 | } else if (m instanceof ReportMonitor) { 91 | return ((ReportMonitor) m).getReport().getUnits(); 92 | } else { 93 | return null; 94 | } 95 | } 96 | 97 | /** 98 | * This method is called automatically by {@link MacroUtils}. 99 | */ 100 | public void updateInstances() { 101 | _get = _mu.get; 102 | _io = _mu.io; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/getter/MainGetter.java: -------------------------------------------------------------------------------- 1 | package macroutils.getter; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.Simulation; 5 | 6 | /** 7 | * Main class for get-type methods in MacroUtils. 8 | * 9 | * @since January of 2016 10 | * @author Fabio Kasper 11 | */ 12 | public class MainGetter { 13 | 14 | /** 15 | * This class is responsible for getting Boundaries. 16 | */ 17 | public GetBoundaries boundaries = null; 18 | 19 | /** 20 | * This class is responsible for getting Camera Views (VisView). 21 | */ 22 | public GetCameras cameras = null; 23 | 24 | /** 25 | * This class is responsible for getting Geometry Parts. 26 | */ 27 | public GetGeometries geometries = null; 28 | 29 | /** 30 | * This class is responsible for getting other kind of information in general. 31 | */ 32 | public GetInfos info = null; 33 | 34 | /** 35 | * This class is responsible for getting mesh parameters in general. 36 | */ 37 | public GetMesh mesh = null; 38 | 39 | /** 40 | * This class is responsible for getting Monitors and related objects. 41 | */ 42 | public GetMonitors monitors = null; 43 | 44 | /** 45 | * This class is responsible for getting STAR-CCM+ objects in general. 46 | */ 47 | public GetObjects objects = null; 48 | 49 | /** 50 | * This class is responsible for getting Part Curves. 51 | */ 52 | public GetPartCurves partCurves = null; 53 | 54 | /** 55 | * This class is responsible for getting Part Surfaces. 56 | */ 57 | public GetPartSurfaces partSurfaces = null; 58 | 59 | /** 60 | * This class is responsible for getting Parts in general, such as Derived Parts. 61 | */ 62 | public GetParts parts = null; 63 | 64 | /** 65 | * This class is responsible for getting Plots. 66 | */ 67 | public GetPlots plots = null; 68 | 69 | /** 70 | * This class is responsible for getting Regions. 71 | */ 72 | public GetRegions regions = null; 73 | 74 | /** 75 | * This class is responsible for getting Reports and related objects. 76 | */ 77 | public GetReports reports = null; 78 | 79 | /** 80 | * This class is responsible for getting Scenes and related parameters. 81 | */ 82 | public GetScenes scenes = null; 83 | 84 | /** 85 | * This class is responsible for getting solver related parameters. 86 | */ 87 | public GetSolver solver = null; 88 | 89 | /** 90 | * This class is responsible for getting STAR-CCM+ strings in general. 91 | */ 92 | public GetStrings strings = null; 93 | 94 | /** 95 | * This class is responsible for getting STAR-CCM+ units. 96 | */ 97 | public GetUnits units = null; 98 | 99 | private macroutils.io.MainIO _io = null; 100 | private MacroUtils _mu = null; 101 | private Simulation _sim = null; 102 | 103 | /** 104 | * Main constructor for this class. 105 | * 106 | * @param m given MacroUtils object. 107 | */ 108 | public MainGetter(MacroUtils m) { 109 | _mu = m; 110 | _sim = m.getSimulation(); 111 | boundaries = new GetBoundaries(m); 112 | cameras = new GetCameras(m); 113 | geometries = new GetGeometries(m); 114 | info = new GetInfos(m); 115 | mesh = new GetMesh(m); 116 | monitors = new GetMonitors(m); 117 | objects = new GetObjects(m); 118 | partCurves = new GetPartCurves(m); 119 | partSurfaces = new GetPartSurfaces(m); 120 | parts = new GetParts(m); 121 | plots = new GetPlots(m); 122 | regions = new GetRegions(m); 123 | reports = new GetReports(m); 124 | scenes = new GetScenes(m); 125 | solver = new GetSolver(m); 126 | strings = new GetStrings(m); 127 | units = new GetUnits(m); 128 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 129 | } 130 | 131 | /** 132 | * Gets the active Simulation being used by MacroUtils. 133 | * 134 | * @return the active Simulation object. 135 | */ 136 | public Simulation activeSimulation() { 137 | return _sim; 138 | } 139 | 140 | /** 141 | * This method is called automatically by {@link MacroUtils}. 142 | */ 143 | public void updateInstances() { 144 | boundaries.updateInstances(); 145 | cameras.updateInstances(); 146 | geometries.updateInstances(); 147 | info.updateInstances(); 148 | mesh.updateInstances(); 149 | monitors.updateInstances(); 150 | objects.updateInstances(); 151 | partCurves.updateInstances(); 152 | partSurfaces.updateInstances(); 153 | parts.updateInstances(); 154 | plots.updateInstances(); 155 | regions.updateInstances(); 156 | reports.updateInstances(); 157 | scenes.updateInstances(); 158 | solver.updateInstances(); 159 | strings.updateInstances(); 160 | units.updateInstances(); 161 | _io = _mu.io; 162 | _io.print.msgDebug("" + this.getClass().getSimpleName() + " instances updated succesfully."); 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/io/MainIO.java: -------------------------------------------------------------------------------- 1 | package macroutils.io; 2 | 3 | import java.io.File; 4 | import macroutils.MacroUtils; 5 | import macroutils.UserDeclarations; 6 | 7 | /** 8 | * Main class for IO methods in MacroUtils. 9 | * 10 | * @since January of 2016 11 | * @author Fabio Kasper 12 | */ 13 | public class MainIO { 14 | 15 | /** 16 | * This class is responsible for printing information into STAR-CCM+ console/output. 17 | */ 18 | public Print print = null; 19 | /** 20 | * This class is responsible for reading objects in general with MacroUtils. 21 | */ 22 | public Read read = null; 23 | /** 24 | * Useful for printing information into console/output. It is the same as {@link #print}. 25 | */ 26 | public Print say = null; 27 | /** 28 | * This class is responsible for writing data in general with MacroUtils. 29 | */ 30 | public Write write = null; 31 | 32 | private MacroUtils _mu = null; 33 | private UserDeclarations _ud = null; 34 | 35 | /** 36 | * Main constructor for this class. 37 | * 38 | * @param m given MacroUtils object. 39 | * @param debugOpt given Debug option. True to enable. 40 | */ 41 | public MainIO(MacroUtils m, boolean debugOpt) { 42 | _mu = m; 43 | print = new Print(m); 44 | read = new Read(m); 45 | write = new Write(m); 46 | say = print; 47 | print.setDebug(debugOpt); 48 | say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 49 | } 50 | 51 | /** 52 | * Creates a folder in the same {@link UserDeclarations#simPath}. 53 | * 54 | * @param fld given folder name. 55 | * @return The File. Null if an error is caught. 56 | */ 57 | public File createFolder(String fld) { 58 | File f = new File(_ud.simPath, fld); 59 | if (f.canWrite()) { 60 | say.value("Folder already exists", f.toString(), true, true); 61 | return f; 62 | } 63 | say.value("Creating a Folder", f.toString(), true, true); 64 | if (f.mkdir()) { 65 | say.ok(true); 66 | } else { 67 | say.msg(true, "Could not be created due an unknown error."); 68 | return null; 69 | } 70 | return f; 71 | } 72 | 73 | /** 74 | * Sleeps for a while. 75 | * 76 | * @param ms the length of time to sleep in milliseconds. 77 | */ 78 | public void sleep(int ms) { 79 | try { 80 | Thread.sleep(ms); 81 | } catch (Exception e) { 82 | say.msg(true, "Sleep stopped via: %s", e.getMessage()); 83 | } 84 | } 85 | 86 | /** 87 | * This method is called automatically by {@link MacroUtils}. It is internal to MacroUtils. 88 | */ 89 | public void updateInstances() { 90 | print.updateInstances(); 91 | read.updateInstances(); 92 | write.updateInstances(); 93 | _ud = _mu.userDeclarations; 94 | print.msgDebug("" + this.getClass().getSimpleName() + " instances updated succesfully."); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/misc/MainClearer.java: -------------------------------------------------------------------------------- 1 | package macroutils.misc; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.StaticDeclarations; 5 | import star.common.Comment; 6 | import star.common.CommentManager; 7 | import star.common.Simulation; 8 | import star.meshing.MeshPipelineController; 9 | 10 | /** 11 | * Main class for "clearing" methods in MacroUtils. 12 | * 13 | * @since July of 2016 14 | * @author Fabio Kasper 15 | */ 16 | public class MainClearer { 17 | 18 | private macroutils.io.MainIO _io = null; 19 | private MacroUtils _mu = null; 20 | private Simulation _sim = null; 21 | 22 | /** 23 | * Main constructor for this class. 24 | * 25 | * @param m given MacroUtils object. 26 | */ 27 | public MainClearer(MacroUtils m) { 28 | _mu = m; 29 | _sim = m.getSimulation(); 30 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 31 | } 32 | 33 | /** 34 | * Clears a comment from a STAR-CCM+ object. 35 | * 36 | * @param comment given Comment object 37 | */ 38 | public void comment(Comment comment) { 39 | _sim.get(CommentManager.class).remove(comment); 40 | } 41 | 42 | /** 43 | * Clears all generated meshes. 44 | */ 45 | public void meshes() { 46 | _io.say.msg("Clearing Meshes..."); 47 | _sim.get(MeshPipelineController.class).clearGeneratedMeshes(); 48 | _io.say.ok(true); 49 | } 50 | 51 | /** 52 | * Clears the Solution and all Fields are erased. 53 | */ 54 | public void solution() { 55 | _io.say.msg("Clearing Solution..."); 56 | _sim.getSolution().clearSolution(); 57 | _io.say.ok(true); 58 | } 59 | 60 | /** 61 | * This method gives you the ability to clears different areas of the Solution. 62 | * 63 | * @param sc given option. See {@link macroutils.StaticDeclarations.SolutionClear} for options. 64 | */ 65 | public void solution(StaticDeclarations.SolutionClear... sc) { 66 | _io.say.action("Clearing Solution", true); 67 | for (StaticDeclarations.SolutionClear sc1 : sc) { 68 | _io.say.msg(true, " - %s", sc1.toString()); 69 | _sim.getSolution().clearSolution(sc1.getClear()); 70 | } 71 | _io.say.ok(true); 72 | } 73 | 74 | /** 75 | * Clears only the Solution History and Fields are kept. 76 | */ 77 | public void solutionHistory() { 78 | solution(StaticDeclarations.SolutionClear.HISTORY); 79 | } 80 | 81 | /** 82 | * This method is called automatically by {@link MacroUtils}. 83 | */ 84 | public void updateInstances() { 85 | _io = _mu.io; 86 | _io.print.msgDebug("" + this.getClass().getSimpleName() 87 | + " instances updated succesfully."); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/misc/MainCloser.java: -------------------------------------------------------------------------------- 1 | package macroutils.misc; 2 | 3 | import macroutils.MacroUtils; 4 | import star.base.neo.ClientServerObject; 5 | import star.common.Simulation; 6 | import star.common.StarPlot; 7 | import star.vis.Scene; 8 | 9 | /** 10 | * Main class for "closing" methods in MacroUtils. 11 | * 12 | * @since May of 2016 13 | * @author Fabio Kasper 14 | */ 15 | public class MainCloser { 16 | 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public MainCloser(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 30 | } 31 | 32 | /** 33 | * Closes all Plots and Scenes in the model. 34 | */ 35 | public void all() { 36 | allPlots(true); 37 | allScenes(true); 38 | } 39 | 40 | /** 41 | * Closes all Plots in the model. 42 | * 43 | * @param vo given verbose option. False will not print anything. 44 | */ 45 | public void allPlots(boolean vo) { 46 | _closingAll("Plots", vo); 47 | for (StarPlot sp : _sim.getPlotManager().getObjects()) { 48 | _closing(sp, vo); 49 | sp.close(); 50 | } 51 | _io.say.ok(vo); 52 | } 53 | 54 | /** 55 | * Closes all Scenes in the model. 56 | * 57 | * @param vo given verbose option. False will not print anything. 58 | */ 59 | public void allScenes(boolean vo) { 60 | _closingAll("Scenes", vo); 61 | for (Scene scn : _sim.getSceneManager().getScenes()) { 62 | _closing(scn, vo); 63 | scn.close(true); 64 | } 65 | _io.say.ok(vo); 66 | } 67 | 68 | /** 69 | * This method is called automatically by {@link MacroUtils}. 70 | */ 71 | public void updateInstances() { 72 | _io = _mu.io; 73 | _io.print.msgDebug("" + this.getClass().getSimpleName() 74 | + " instances updated succesfully."); 75 | } 76 | 77 | private void _closing(ClientServerObject cso, boolean vo) { 78 | _io.say.value("Closing", cso.getPresentationName(), true, vo); 79 | } 80 | 81 | private void _closingAll(String what, boolean vo) { 82 | _io.say.action(String.format("Closing All %s...", what), vo); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/misc/MainOpener.java: -------------------------------------------------------------------------------- 1 | package macroutils.misc; 2 | 3 | import macroutils.MacroUtils; 4 | import star.base.neo.ClientServerObject; 5 | import star.common.Simulation; 6 | import star.common.StarPlot; 7 | import star.vis.Scene; 8 | 9 | /** 10 | * Main class for "opening" methods in MacroUtils. 11 | * 12 | * @since April of 2016 13 | * @author Fabio Kasper 14 | */ 15 | public class MainOpener { 16 | 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public MainOpener(MacroUtils m) { 27 | _mu = m; 28 | _sim = m.getSimulation(); 29 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 30 | } 31 | 32 | /** 33 | * Opens all Plots and Scenes in the model. 34 | */ 35 | public void all() { 36 | allPlots(true); 37 | allScenes(true); 38 | } 39 | 40 | /** 41 | * Opens all Plots in the model. 42 | * 43 | * @param vo given verbose option. False will not print anything. 44 | */ 45 | public void allPlots(boolean vo) { 46 | _openingAll("Plots", vo); 47 | for (StarPlot sp : _sim.getPlotManager().getObjects()) { 48 | _opening(sp, vo); 49 | sp.open(); 50 | } 51 | _io.say.ok(vo); 52 | } 53 | 54 | /** 55 | * Opens all Scenes in the model. 56 | * 57 | * @param vo given verbose option. False will not print anything. 58 | */ 59 | public void allScenes(boolean vo) { 60 | _openingAll("Scenes", vo); 61 | for (Scene scn : _sim.getSceneManager().getScenes()) { 62 | _opening(scn, vo); 63 | scn.open(); 64 | } 65 | _io.say.ok(vo); 66 | } 67 | 68 | /** 69 | * This method is called automatically by {@link MacroUtils}. 70 | */ 71 | public void updateInstances() { 72 | _io = _mu.io; 73 | _io.print.msgDebug("" + this.getClass().getSimpleName() 74 | + " instances updated succesfully."); 75 | } 76 | 77 | private void _opening(ClientServerObject cso, boolean vo) { 78 | _io.say.value("Opening", cso.getPresentationName(), true, vo); 79 | } 80 | 81 | private void _openingAll(String what, boolean vo) { 82 | _io.say.action(String.format("Opening All %s", what), vo); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/misc/MainResetter.java: -------------------------------------------------------------------------------- 1 | package macroutils.misc; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.UserDeclarations; 5 | import star.common.Simulation; 6 | import star.vis.Displayer; 7 | 8 | /** 9 | * Main class for "resetting" objects or variables in MacroUtils. 10 | * 11 | * @since July of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class MainResetter { 15 | 16 | private macroutils.getter.MainGetter _get = null; 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private Simulation _sim = null; 20 | private macroutils.UserDeclarations _ud = null; 21 | 22 | /** 23 | * Main constructor for this class. 24 | * 25 | * @param m given MacroUtils object. 26 | */ 27 | public MainResetter(MacroUtils m) { 28 | _mu = m; 29 | _sim = m.getSimulation(); 30 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 31 | } 32 | 33 | /** 34 | * Resets internal MacroUtils variable: 35 | *
    36 | *
  • {@link UserDeclarations#picPath} 37 | *
38 | */ 39 | public void picPath() { 40 | _ud.picPath = _sim.getSessionDir(); 41 | } 42 | 43 | /** 44 | * Resets internal MacroUtils variable: 45 | *
    46 | *
  • {@link UserDeclarations#simPath} 47 | *
48 | */ 49 | public void simPath() { 50 | _ud.simPath = _sim.getSessionDir(); 51 | } 52 | 53 | /** 54 | * Resets the Transform on a Displayer. 55 | * 56 | * @param d given Displayer. 57 | */ 58 | public void transform(Displayer d) { 59 | if (d == null) { 60 | return; 61 | } 62 | d.setVisTransform(_get.objects.transform("Identity", false)); 63 | } 64 | 65 | /** 66 | * This method is called automatically by {@link MacroUtils}. 67 | */ 68 | public void updateInstances() { 69 | _get = _mu.get; 70 | _io = _mu.io; 71 | _ud = _mu.userDeclarations; 72 | _io.print.msgDebug("" + this.getClass().getSimpleName() 73 | + " instances updated succesfully."); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/setter/MainSetter.java: -------------------------------------------------------------------------------- 1 | package macroutils.setter; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.AutoSave; 5 | import star.common.Simulation; 6 | import star.common.UpdateEvent; 7 | 8 | /** 9 | * Main class for set-type methods in MacroUtils. 10 | * 11 | * @since January of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class MainSetter { 15 | 16 | /** 17 | * This class is responsible for setting Boundary conditions (BCs) parameters. 18 | */ 19 | public SetBoundaries boundary = null; 20 | 21 | /** 22 | * This class is responsible for setting Geometry parameters. 23 | */ 24 | public SetGeometry geometry = null; 25 | 26 | /** 27 | * This class is responsible for setting mesh parameters. 28 | */ 29 | public SetMesh mesh = null; 30 | 31 | /** 32 | * This class is responsible for setting objects in general. 33 | */ 34 | public SetObjects object = null; 35 | 36 | /** 37 | * This class is responsible for setting physics parameters. 38 | */ 39 | public SetPhysics physics = null; 40 | 41 | /** 42 | * This class is responsible for setting physics parameters. 43 | */ 44 | public SetPlots plots = null; 45 | 46 | /** 47 | * This class is responsible for setting Region parameters. 48 | */ 49 | public SetRegions region = null; 50 | 51 | /** 52 | * This class is responsible for setting Scene parameters. 53 | */ 54 | public SetScenes scene = null; 55 | /** 56 | * This class is responsible for setting solver parameters. 57 | */ 58 | public SetSolver solver = null; 59 | 60 | /** 61 | * This class is responsible for setting MacroUtils defaults. 62 | */ 63 | public SetDefaults userDefault = null; 64 | 65 | private macroutils.checker.MainChecker _chk = null; 66 | private macroutils.misc.MainDisabler _dis = null; 67 | private macroutils.misc.MainEnabler _ena = null; 68 | private macroutils.io.MainIO _io = null; 69 | 70 | private final MacroUtils _mu; 71 | private final Simulation _sim; 72 | 73 | /** 74 | * Main constructor for this class. 75 | * 76 | * @param m given MacroUtils object. 77 | */ 78 | public MainSetter(MacroUtils m) { 79 | _mu = m; 80 | _sim = m.getSimulation(); 81 | boundary = new SetBoundaries(m); 82 | mesh = new SetMesh(m); 83 | object = new SetObjects(m); 84 | geometry = new SetGeometry(m); 85 | physics = new SetPhysics(m); 86 | plots = new SetPlots(m); 87 | region = new SetRegions(m); 88 | scene = new SetScenes(m); 89 | solver = new SetSolver(m); 90 | userDefault = new SetDefaults(m); 91 | _chk = m.check; 92 | _dis = m.disable; 93 | _ena = m.enable; 94 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 95 | } 96 | 97 | /** 98 | * Set the Auto Save functionality based on an Update Event. 99 | * 100 | * @param ue given Update Event. 101 | * @param maxSavedFiles given number of Simulation files to keep. 102 | */ 103 | public void autoSave(UpdateEvent ue, int maxSavedFiles) { 104 | _io.say.action("Setting Auto Save", true); 105 | _io.say.value("Update Event", ue.getPresentationName(), true, true); 106 | AutoSave as = _sim.getSimulationIterator().getAutoSave(); 107 | as.setMaxAutosavedFiles(maxSavedFiles); 108 | object.updateEvent(as, ue, false); 109 | _io.say.ok(true); 110 | } 111 | 112 | /** 113 | * Sets suggested parameters prior for a run, based on experience, such as: 114 | *
    115 | *
  • Make sure ABORT Stopping Criteria is enabled;
  • 116 | *
  • Make sure Maximum Steps Stopping Criteria is disabled when running unsteady;
  • 117 | *
118 | */ 119 | public void suggestedPreRun() { 120 | _io.say.msg("Setting Suggested Pre-Run Parameters:", true); 121 | //-- 122 | _io.say.msg(" - Making sure ABORT Stopping Criteria is enabled..."); 123 | _ena.stoppingCriteriaAbortFile(false); 124 | if (_chk.is.unsteady()) { 125 | _io.say.msg(" - Making sure Maximum Steps is disabled..."); 126 | _dis.stoppingCriteriaAbortFile(false); 127 | } 128 | _io.say.ok(true); 129 | if (_mu.getIntrusiveOption()) { 130 | _mu.templates.prettify.all(); 131 | } 132 | } 133 | 134 | /** 135 | * This method is called automatically by {@link MacroUtils}. 136 | */ 137 | public void updateInstances() { 138 | boundary.updateInstances(); 139 | geometry.updateInstances(); 140 | mesh.updateInstances(); 141 | object.updateInstances(); 142 | plots.updateInstances(); 143 | physics.updateInstances(); 144 | region.updateInstances(); 145 | scene.updateInstances(); 146 | solver.updateInstances(); 147 | userDefault.updateInstances(); 148 | _chk.updateInstances(); 149 | _dis.updateInstances(); 150 | _ena.updateInstances(); 151 | _io = _mu.io; 152 | _io.print.msgDebug("" + this.getClass().getSimpleName() 153 | + " instances updated succesfully."); 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/setter/SetDefaults.java: -------------------------------------------------------------------------------- 1 | package macroutils.setter; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.StaticDeclarations; 5 | import macroutils.UserDeclarations; 6 | import star.vis.VisView; 7 | 8 | /** 9 | * Low-level class for setting MacroUtils user defaults defined in {@link UserDeclarations}. 10 | * 11 | * @since April of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class SetDefaults { 15 | 16 | private macroutils.getter.MainGetter _get = null; 17 | private macroutils.io.MainIO _io = null; 18 | private MacroUtils _mu = null; 19 | private macroutils.UserDeclarations _ud = null; 20 | 21 | /** 22 | * Main constructor for this class. 23 | * 24 | * @param m given MacroUtils object. 25 | */ 26 | public SetDefaults(MacroUtils m) { 27 | _mu = m; 28 | } 29 | 30 | /** 31 | * Sets the default Camera View (VisView) used by MacroUtils. 32 | * 33 | * @param vv given VisView. 34 | */ 35 | public void cameraView(VisView vv) { 36 | _setting("Camera View", vv.toString()); 37 | _ud.defCamView = vv; 38 | } 39 | 40 | /** 41 | * Sets the default Colormap used by MacroUtils. 42 | * 43 | * @param opt given option. See {@link macroutils.StaticDeclarations.Colormaps} for options. 44 | */ 45 | public void colormap(StaticDeclarations.Colormaps opt) { 46 | _setting("Colormap", opt.getName()); 47 | _ud.defColormap = _get.objects.colormap(opt); 48 | } 49 | 50 | /** 51 | * Sets the default picture path/folder when saving pictures with MacroUtils. 52 | * 53 | * @param path given path for storing pictures. 54 | */ 55 | public void picturePath(String path) { 56 | _setting("Picture Path", path); 57 | _ud.picPath = _io.createFolder(path).toString(); 58 | } 59 | 60 | /** 61 | * Sets the default resolution when saving pictures with MacroUtils. 62 | * 63 | * @param resx given resolution in x. This will change {@link UserDeclarations#picResX} 64 | * variable. 65 | * @param resy given resolution in y. This will change {@link UserDeclarations#picResY} 66 | * variable. 67 | */ 68 | public void pictureResolution(int resx, int resy) { 69 | _setting("Picture resolution", String.format("%d x %d pixels", resx, resy)); 70 | _ud.picResX = resx; 71 | _ud.picResY = resy; 72 | } 73 | 74 | /** 75 | * Sets the default Tessellation option used by MacroUtils. 76 | * 77 | * @param opt given option. See {@link macroutils.StaticDeclarations.Tessellation} for options. 78 | */ 79 | public void tessellation(StaticDeclarations.Tessellation opt) { 80 | _setting("Tessellation", opt.toString()); 81 | _ud.defTessOpt = opt; 82 | } 83 | 84 | /** 85 | * This method is called automatically by {@link MacroUtils}. 86 | */ 87 | public void updateInstances() { 88 | _get = _mu.get; 89 | _io = _mu.io; 90 | _ud = _mu.userDeclarations; 91 | } 92 | 93 | private void _setting(String what, String opt) { 94 | _io.say.action(String.format("Setting Default %s", what), true); 95 | _io.say.value(what, opt, true, true); 96 | _io.say.ok(true); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/setter/SetPlots.java: -------------------------------------------------------------------------------- 1 | package macroutils.setter; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.BinningDescriptor; 5 | import star.common.Cartesian2DAxis; 6 | import star.common.Cartesian2DPlot; 7 | import star.common.PartGroupDataSet; 8 | import star.common.RangedData; 9 | import star.common.StarPlot; 10 | 11 | /** 12 | * Low-level class for setting Plot parameters with MacroUtils. 13 | * 14 | * @since April of 2019 15 | * @author Fabio Kasper 16 | */ 17 | public class SetPlots { 18 | 19 | private macroutils.checker.MainChecker _chk = null; 20 | private macroutils.getter.MainGetter _get = null; 21 | private macroutils.io.MainIO _io = null; 22 | private final MacroUtils _mu; 23 | 24 | /** 25 | * Main constructor for this class. 26 | * 27 | * @param m given MacroUtils object. 28 | */ 29 | public SetPlots(MacroUtils m) { 30 | _mu = m; 31 | } 32 | 33 | /** 34 | * Sets the axes names for a Plot. 35 | * 36 | * @param sp given StarPlot 37 | * @param xName given x-axis titles 38 | * @param yName given y-axis titles 39 | * @param vo given verbose option. False will not print anything 40 | */ 41 | public void axesTitles(StarPlot sp, String xName, String yName, boolean vo) { 42 | 43 | _io.say.action("Setting Plot Axes Titles", vo); 44 | _io.say.object(sp, vo); 45 | 46 | _axisTitle(_get.plots.axisX(sp), "X-Axis", xName); 47 | _axisTitle(_get.plots.axisY(sp), "Y-Axis", yName); 48 | 49 | _io.say.ok(vo); 50 | 51 | } 52 | 53 | /** 54 | * Sets the bins number for a Histogram Plot. 55 | * 56 | * @param hp given StarPlot 57 | * @param bins given number of bins 58 | * @param vo given verbose option. False will not print anything 59 | */ 60 | public void bins(StarPlot hp, int bins, boolean vo) { 61 | binsParameters(hp, bins, new double[]{}, vo); 62 | } 63 | 64 | /** 65 | * Sets the bins parameters for a Histogram Plot. 66 | * 67 | * @param hp given StarPlot 68 | * @param bins given number of bins 69 | * @param range given range for the bins 70 | * @param vo given verbose option. False will not print anything 71 | */ 72 | public void binsParameters(StarPlot hp, int bins, double[] range, boolean vo) { 73 | 74 | _io.say.action("Setting Histogram Plot range on bins", vo); 75 | _io.say.object(hp, vo); 76 | 77 | if (_chk.is.histogram(hp) && hp instanceof Cartesian2DPlot plot) { 78 | plot.getDataSeriesOrder().stream() 79 | .filter(PartGroupDataSet.class::isInstance) 80 | .map(PartGroupDataSet.class::cast) 81 | .forEach(dataSet -> _setBinsParameters(dataSet, bins, range, vo)); 82 | _io.say.ok(vo); 83 | } else { 84 | _io.say.msg("Skipped! Plot is not supported", vo); 85 | } 86 | 87 | } 88 | 89 | /** 90 | * This method is called automatically by {@link MacroUtils}. 91 | */ 92 | public void updateInstances() { 93 | _chk = _mu.check; 94 | _get = _mu.get; 95 | _io = _mu.io; 96 | } 97 | 98 | private void _axisTitle(Cartesian2DAxis axis, String key, String name) { 99 | axis.getTitle().setText(name); 100 | _io.say.value(key, axis.getTitle().getText(), true, true); 101 | } 102 | 103 | private void _setBinsParameters(PartGroupDataSet ds, int bins, double[] range, boolean vo) { 104 | _io.say.object(ds, vo); 105 | _io.say.value("Number of bins", bins, vo); 106 | _io.say.value("Bin range", range, vo); 107 | BinningDescriptor descriptor = _get.plots.axisX(ds).hasBinningDescriptor(); 108 | descriptor.setNumberOfBins(bins); 109 | if (range.length == 2) { 110 | descriptor.setDataRangeMode(RangedData.RangeMode.Manual); 111 | descriptor.setManualDataExtentsMin(range[0]); 112 | descriptor.setManualDataExtentsMax(range[1]); 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/setter/SetRegions.java: -------------------------------------------------------------------------------- 1 | package macroutils.setter; 2 | 3 | import macroutils.MacroUtils; 4 | import star.common.Region; 5 | import star.motion.Motion; 6 | import star.motion.MotionSpecification; 7 | 8 | /** 9 | * Low-level class for setting Region parameters with MacroUtils. 10 | * 11 | * @since May of 2016 12 | * @author Fabio Kasper 13 | */ 14 | public class SetRegions { 15 | 16 | private macroutils.io.MainIO _io = null; 17 | private MacroUtils _mu = null; 18 | 19 | /** 20 | * Main constructor for this class. 21 | * 22 | * @param m given MacroUtils object. 23 | */ 24 | public SetRegions(MacroUtils m) { 25 | _mu = m; 26 | } 27 | 28 | /** 29 | * Sets Motion to a Region. 30 | * 31 | * @param m given Motion. 32 | * @param r given Region. 33 | */ 34 | public void motion(Motion m, Region r) { 35 | _io.say.action("Setting Motion to a Region", true); 36 | _io.say.object(m, true); 37 | _io.say.object(r, true); 38 | ((MotionSpecification) r.getValues().get(MotionSpecification.class)).setMotion(m); 39 | _io.say.ok(true); 40 | } 41 | 42 | /** 43 | * This method is called automatically by {@link MacroUtils}. 44 | */ 45 | public void updateInstances() { 46 | _io = _mu.io; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/templates/MainTemplates.java: -------------------------------------------------------------------------------- 1 | package macroutils.templates; 2 | 3 | import macroutils.MacroUtils; 4 | 5 | /** 6 | * Main class for templates methods in MacroUtils. 7 | * 8 | * @since February of 2016 9 | * @author Fabio Kasper 10 | */ 11 | public class MainTemplates { 12 | 13 | /** 14 | * This class is responsible for assessing the Grid Convergence Index (GCI) metric. 15 | */ 16 | public TemplateGCI gci = null; 17 | 18 | /** 19 | * This class is responsible for some templated geometries. 20 | */ 21 | public TemplateGeometry geometry = null; 22 | 23 | /** 24 | * This class is responsible for some templated meshes. 25 | */ 26 | public TemplateMesh mesh = null; 27 | 28 | /** 29 | * This class is responsible for creating useful postprocessing objects in general. 30 | */ 31 | public TemplatePost post = null; 32 | 33 | /** 34 | * This class is responsible for prettifying the simulation. 35 | */ 36 | public TemplatePrettifier prettify = null; 37 | 38 | private macroutils.io.MainIO _io = null; 39 | private MacroUtils _mu = null; 40 | 41 | /** 42 | * Main constructor for this class. 43 | * 44 | * @param m given MacroUtils object. 45 | */ 46 | public MainTemplates(MacroUtils m) { 47 | _mu = m; 48 | gci = new TemplateGCI(m); 49 | geometry = new TemplateGeometry(m); 50 | mesh = new TemplateMesh(m); 51 | prettify = new TemplatePrettifier(m); 52 | post = new TemplatePost(m); 53 | m.io.say.msgDebug("Class loaded: %s...", this.getClass().getSimpleName()); 54 | } 55 | 56 | /** 57 | * This method is called automatically by {@link MacroUtils}. 58 | */ 59 | public void updateInstances() { 60 | gci.updateInstances(); 61 | geometry.updateInstances(); 62 | mesh.updateInstances(); 63 | post.updateInstances(); 64 | prettify.updateInstances(); 65 | _io = _mu.io; 66 | _io.print.msgDebug("" + this.getClass().getSimpleName() 67 | + " instances updated succesfully."); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/templates/simassistants/BlockMesher.java: -------------------------------------------------------------------------------- 1 | package macroutils.templates.simassistants; 2 | 3 | import macroutils.MacroUtils; 4 | import star.base.neo.DoubleVector; 5 | import star.common.Region; 6 | import star.common.Tag; 7 | import star.common.Units; 8 | import star.common.VectorGlobalParameter; 9 | import star.vis.Scene; 10 | 11 | /** 12 | * A simple and efficient hexa mesher in a block. 13 | * 14 | * Use the Parameters under Tools node to control settings. 15 | * 16 | * @since June of 2018 17 | * @author Fabio Kasper 18 | */ 19 | public final class BlockMesher extends SimpleHexaMesher { 20 | 21 | private static final String BLOCK_C1 = "Block Coordinate1"; 22 | private static final String BLOCK_C2 = "Block Coordinate2"; 23 | private static final String BLOCK_NCELLS = "Block Number of Cells"; 24 | private static final String TAG_2D = "MacroUtils 2D Mesh"; 25 | 26 | public BlockMesher(MacroUtils m) { 27 | super(m); 28 | } 29 | 30 | /** 31 | * Generate the mesh using current parameters. 32 | */ 33 | public void generateMesh() { 34 | _mu.templates.mesh.setBadgeFor2D(is2D()); 35 | 36 | VectorGlobalParameter c1 = getParameter(BLOCK_C1); 37 | VectorGlobalParameter c2 = getParameter(BLOCK_C2); 38 | VectorGlobalParameter nc = getParameter(BLOCK_NCELLS); 39 | 40 | Region r = _mesher.hexaBlock(getDouble(c1), getDouble(c2), 41 | c1.getQuantity().getUnits(), getInt(nc), "Block"); 42 | 43 | if (is2D()) { 44 | _ud.namedObjects.add(r); 45 | _remove.tag(getTag()); 46 | _mesher.setBadgeFor2D(false); 47 | } else { 48 | _ud.namedObjects.addAll(_get.boundaries.all(r, false)); 49 | } 50 | 51 | Scene scn = _add.scene.mesh(_ud.namedObjects); 52 | scn.open(); 53 | if (!is2D()) { 54 | scn.setViewOrientation(new DoubleVector(new double[]{ -1.0, 1.0, -1.0 }), 55 | new DoubleVector(new double[]{ 0.0, 1.0, 0.0 })); 56 | } 57 | scn.resetCamera(); 58 | 59 | _ud.namedObjects.clear(); 60 | } 61 | 62 | /** 63 | * The block first coordinate Parameter. 64 | * 65 | * @return A VectorGlobalParameter 66 | */ 67 | public VectorGlobalParameter getBlockCoordinate1Parameter() { 68 | return getParameter(BLOCK_C1); 69 | } 70 | 71 | /** 72 | * The block second coordinate Parameter. 73 | * 74 | * @return A VectorGlobalParameter 75 | */ 76 | public VectorGlobalParameter getBlockCoordinate2Parameter() { 77 | return getParameter(BLOCK_C2); 78 | } 79 | 80 | /** 81 | * The block number of i x j x k cells Parameter. 82 | * 83 | * @return A VectorGlobalParameter 84 | */ 85 | public VectorGlobalParameter getBlockNumberOfCellsParameter() { 86 | return getParameter(BLOCK_NCELLS); 87 | } 88 | 89 | /** 90 | * Are the parameters in place? 91 | * 92 | * @return A boolean 93 | */ 94 | public boolean haveParameters() { 95 | return getBlockCoordinate1Parameter() != null; 96 | } 97 | 98 | /** 99 | * Set the block to be two-dimensional. 100 | */ 101 | public void setAs2D() { 102 | _add.tools.tag(TAG_2D); 103 | _io.say.action("Geometry will be flagged as 2D.", true); 104 | } 105 | 106 | /** 107 | * Set block mesh parameters. 108 | * 109 | * @param coord1 given array of coordinates 110 | * @param coord2 given array of coordinates 111 | * @param nCells given number of i x j x k hexahedral cells 112 | * @param u given Units 113 | */ 114 | public void setParameters(double[] coord1, double[] coord2, double[] nCells, Units u) { 115 | _add.tools.vectorParameter(BLOCK_C1, coord1, u); 116 | _add.tools.vectorParameter(BLOCK_C2, coord2, u); 117 | _add.tools.vectorParameter(BLOCK_NCELLS, nCells, u); 118 | } 119 | 120 | private Tag getTag() { 121 | return _get.objects.tag(TAG_2D, false); 122 | } 123 | 124 | private double[] getDouble(VectorGlobalParameter vgp) { 125 | 126 | return vgp.getQuantity().getInternalVector().stream() 127 | .mapToDouble(Double::doubleValue) 128 | .toArray(); 129 | 130 | } 131 | 132 | private int[] getInt(VectorGlobalParameter vgp) { 133 | 134 | return vgp.getQuantity().getInternalVector().stream() 135 | .mapToInt(Double::intValue) 136 | .toArray(); 137 | 138 | } 139 | 140 | private VectorGlobalParameter getParameter(String name) { 141 | return _get.objects.vectorParameter(name, false); 142 | } 143 | 144 | private boolean is2D() { 145 | return getTag() != null; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/templates/simassistants/SimpleHexaMesher.java: -------------------------------------------------------------------------------- 1 | package macroutils.templates.simassistants; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.UserDeclarations; 5 | import macroutils.creator.MainCreator; 6 | import macroutils.getter.MainGetter; 7 | import macroutils.io.MainIO; 8 | import macroutils.misc.MainRemover; 9 | import macroutils.misc.MainUpdater; 10 | import macroutils.setter.MainSetter; 11 | import macroutils.templates.TemplateMesh; 12 | import star.common.Simulation; 13 | 14 | /** 15 | * Low-level instructions for SimpleHexaMesher. 16 | * 17 | * @since June of 2018 18 | * @author Fabio Kasper 19 | */ 20 | public abstract class SimpleHexaMesher { 21 | 22 | protected final MainCreator _add; 23 | protected final MainGetter _get; 24 | protected final MainIO _io; 25 | protected final TemplateMesh _mesher; 26 | protected final MacroUtils _mu; 27 | protected final MainRemover _remove; 28 | protected final MainSetter _set; 29 | protected final Simulation _sim; 30 | protected final UserDeclarations _ud; 31 | protected final MainUpdater _upd; 32 | 33 | /** 34 | * Main constructor for this class. 35 | * 36 | * @param m given MacroUtils object. 37 | */ 38 | public SimpleHexaMesher(MacroUtils m) { 39 | _mu = m; 40 | _sim = m.getSimulation(); 41 | _ud = _mu.userDeclarations; 42 | _add = _mu.add; 43 | _get = _mu.get; 44 | _io = _mu.io; 45 | _set = _mu.set; 46 | _remove = _mu.remove; 47 | _mesher = _mu.templates.mesh; 48 | _upd = _mu.update; 49 | } 50 | 51 | /** 52 | * Removes all objects. 53 | */ 54 | protected void removeAll() { 55 | _remove.all(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/templates/simtools/ImplicitUnsteadyConvergenceChecker.java: -------------------------------------------------------------------------------- 1 | package macroutils.templates.simtools; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | import macroutils.MacroUtils; 6 | import macroutils.UserDeclarations; 7 | import macroutils.creator.MainCreator; 8 | import macroutils.getter.MainGetter; 9 | import macroutils.setter.MainSetter; 10 | import star.base.report.Monitor; 11 | import star.base.report.Report; 12 | import star.base.report.ReportMonitor; 13 | import star.base.report.graph.MultiAxisMonitorDataSet; 14 | import star.common.Cartesian2DPlot; 15 | import star.common.Simulation; 16 | import star.common.StarPlot; 17 | import star.common.StarUpdateModeOption; 18 | import star.common.SymbolShapeOption; 19 | import star.common.UserTag; 20 | 21 | /** 22 | * This class will create a plot for every Report available in the Simulation. 23 | * 24 | * In addition, it will perform the following actions: 25 | *
    26 | *
  • Create a ReportMonitor and set to update at every iteration; 27 | *
  • Create a MonitorPlot from the above and set to update at every iteration; 28 | *
  • Set a custom tag at every object created above; 29 | *
30 | * 31 | * Application: when performing implicit unsteady simulations, such as SIMPLE scheme 32 | * available in STAR-CCM+, it is very important that all timesteps are successfully converged. 33 | * 34 | * Otherwise error will build up over time. 35 | * 36 | * @since April of 2019 37 | * @author Fabio Kasper 38 | */ 39 | public class ImplicitUnsteadyConvergenceChecker { 40 | 41 | private final MainCreator _add; 42 | private final MainGetter _get; 43 | private final MacroUtils _mu; 44 | private final MainSetter _set; 45 | private final Simulation _sim; 46 | private final UserTag _tag; 47 | private final UserDeclarations _ud; 48 | 49 | /** 50 | * Main constructor for this class. 51 | * 52 | * @param m given MacroUtils object. 53 | */ 54 | public ImplicitUnsteadyConvergenceChecker(MacroUtils m) { 55 | 56 | _mu = m; 57 | _sim = m.getSimulation(); 58 | _ud = _mu.userDeclarations; 59 | _add = _mu.add; 60 | _get = _mu.get; 61 | _set = _mu.set; 62 | 63 | _tag = _add.tools.tag("Convergence Checker"); 64 | 65 | } 66 | 67 | /** 68 | * Execute this class. 69 | */ 70 | public void execute() { 71 | 72 | _mu.get.reports.all(true).forEach(r -> createConvergenceCheckPlot(r)); 73 | 74 | } 75 | 76 | /** 77 | * Remove all artifacts created by this class. 78 | */ 79 | public void removeArtifacts() { 80 | 81 | _mu.io.say.action("Removing artifacts", true); 82 | 83 | List createdPlots = _get.plots.all(false).stream() 84 | .filter(plot -> plot.getTagGroup().has(_tag)) 85 | .collect(Collectors.toList()); 86 | 87 | List createdMonitors = _get.monitors.all(false).stream() 88 | .filter(monitor -> monitor.getTagGroup().has(_tag)) 89 | .collect(Collectors.toList()); 90 | 91 | _mu.io.say.msg("Removing Plots..."); 92 | _sim.getPlotManager().removeObjects(createdPlots); 93 | 94 | _mu.io.say.msg("Removing Monitors..."); 95 | _sim.getMonitorManager().removeObjects(createdMonitors); 96 | _mu.io.say.ok(true); 97 | 98 | _mu.remove.tag(_tag); 99 | 100 | } 101 | 102 | private void createConvergenceCheckPlot(Report report) { 103 | 104 | final String name = _tag.getPresentationName() + ": " + report.getPresentationName(); 105 | 106 | // Create ReportMonitor and set to update at every iteration 107 | ReportMonitor rm = report.createMonitor(); 108 | rm.setPresentationName(name); 109 | rm.getStarUpdate().getUpdateModeOption().setSelected(StarUpdateModeOption.Type.ITERATION); 110 | 111 | // Create MonitorPlot and set to update at every iteration 112 | Cartesian2DPlot plot = _add.plot.empty(); 113 | plot.setPresentationName(name); 114 | plot.getDataSetManager().addDataProvider(rm); 115 | MultiAxisMonitorDataSet ds = (MultiAxisMonitorDataSet) plot.getDataSeriesOrder().getFirst(); 116 | ds.setPresentationName(name); 117 | _get.plots.axisX(ds).getMonitorRef().setReferencedObject(_get.monitors.iteration()); 118 | plot.getLegend().setVisible(false); 119 | 120 | // Now prettify the DataSet 121 | ds.getSymbolStyle().getSymbolShapeOption().setSelected(SymbolShapeOption.Type.STAR); 122 | 123 | _set.object.tag(rm, _tag, true); 124 | _set.object.tag(plot, _tag, true); 125 | 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /macroutils/src/macroutils/templates/simtools/MeshMetrics.java: -------------------------------------------------------------------------------- 1 | package macroutils.templates.simtools; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | import macroutils.MacroUtils; 7 | import macroutils.UserDeclarations; 8 | import macroutils.creator.MainCreator; 9 | import macroutils.getter.MainGetter; 10 | import macroutils.setter.MainSetter; 11 | import star.base.report.Monitor; 12 | import star.common.Cartesian2DPlot; 13 | import star.common.Simulation; 14 | import star.common.StarPlot; 15 | import star.common.UserTag; 16 | 17 | /** 18 | * This class will create some post processing objects to evaluate Mesh Metrics in current 19 | * Simulation. 20 | * 21 | * The following will be created: 22 | *
    23 | *
  • Histogram Plots covering important mesh metrics; 24 | *
25 | * 26 | * @since April of 2019 27 | * @author Fabio Kasper 28 | */ 29 | public class MeshMetrics { 30 | 31 | private final MainCreator _add; 32 | private final MainGetter _get; 33 | private final MacroUtils _mu; 34 | private final MainSetter _set; 35 | private final Simulation _sim; 36 | private final UserTag _tag; 37 | private final UserDeclarations _ud; 38 | 39 | /** 40 | * Main constructor for this class. 41 | * 42 | * @param m given MacroUtils object. 43 | */ 44 | public MeshMetrics(MacroUtils m) { 45 | 46 | _mu = m; 47 | _sim = m.getSimulation(); 48 | _ud = _mu.userDeclarations; 49 | _add = _mu.add; 50 | _get = _mu.get; 51 | _set = _mu.set; 52 | 53 | _tag = _add.tools.tag("Mesh Metrics"); 54 | 55 | } 56 | 57 | /** 58 | * Execute this class. 59 | */ 60 | public void execute() { 61 | createHistograms(); 62 | _mu.templates.prettify.plots(); 63 | } 64 | 65 | /** 66 | * Remove all artifacts created by this class. 67 | */ 68 | public void removeArtifacts() { 69 | 70 | _mu.io.say.action("Removing artifacts", true); 71 | 72 | List createdPlots = _get.plots.all(false).stream() 73 | .filter(plot -> plot.getTagGroup().has(_tag)) 74 | .collect(Collectors.toList()); 75 | 76 | List createdMonitors = _get.monitors.all(false).stream() 77 | .filter(monitor -> monitor.getTagGroup().has(_tag)) 78 | .collect(Collectors.toList()); 79 | 80 | _mu.io.say.msg("Removing Plots..."); 81 | _sim.getPlotManager().removeObjects(createdPlots); 82 | 83 | _mu.io.say.msg("Removing Monitors..."); 84 | _sim.getMonitorManager().removeObjects(createdMonitors); 85 | _mu.io.say.ok(true); 86 | 87 | _mu.remove.tag(_tag); 88 | 89 | } 90 | 91 | private void createHistogram(Metric metric) { 92 | 93 | String name; 94 | 95 | _ud.namedObjects.clear(); 96 | _ud.ff = _get.objects.fieldFunction(metric.getFunction(), true); 97 | 98 | if (metric instanceof VolumeMeshMetric) { 99 | _ud.namedObjects.addAll(_get.regions.all(false)); 100 | name = metric.getFunction() + " on All Regions"; 101 | } else { 102 | _ud.namedObjects.addAll(_get.partSurfaces.all(false)); 103 | name = metric.getFunction() + " Part Surfaces"; 104 | } 105 | 106 | Cartesian2DPlot hp = _add.plot.histogram(_ud.namedObjects, _ud.ff); 107 | hp.setPresentationName(name); 108 | hp.setTitle(name); 109 | hp.open(); 110 | 111 | _set.object.tag(hp, _tag, true); 112 | 113 | } 114 | 115 | private void createHistograms() { 116 | 117 | Arrays.stream(SurfaceMeshMetric.values()).forEach(metric -> createHistogram(metric)); 118 | Arrays.stream(VolumeMeshMetric.values()).forEach(metric -> createHistogram(metric)); 119 | 120 | } 121 | 122 | private interface Metric { 123 | 124 | public String getFunction(); 125 | 126 | } 127 | 128 | private enum SurfaceMeshMetric implements Metric { 129 | 130 | FACE_VALIDITY("Face Validity"); 131 | 132 | private final String function; 133 | 134 | private SurfaceMeshMetric(final String function) { 135 | this.function = function; 136 | } 137 | 138 | @Override 139 | public String getFunction() { 140 | return function; 141 | } 142 | 143 | } 144 | 145 | private enum VolumeMeshMetric implements Metric { 146 | 147 | CELL_QUALITY("Cell Quality"), 148 | SKEWNESS_ANGLE("Skewness Angle"), 149 | VOLUME_CHANGE("Volume Change"); 150 | 151 | private final String function; 152 | 153 | private VolumeMeshMetric(final String function) { 154 | this.function = function; 155 | } 156 | 157 | @Override 158 | public String getFunction() { 159 | return function; 160 | } 161 | 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'MacroUtils' 2 | 3 | include 'macroutils' 4 | include 'simassistants:demo16' 5 | include 'simassistants:simplehexamesher' -------------------------------------------------------------------------------- /simassistants/build.gradle: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Simulation Assistants common build.gradle script 4 | * 5 | *******************************************************************************/ 6 | 7 | 8 | subprojects { 9 | 10 | configurations { 11 | resolvableApi.extendsFrom(api) 12 | resolvableApi.canBeResolved(true) 13 | } 14 | 15 | dependencies { 16 | api project(':macroutils') 17 | } 18 | 19 | jar { 20 | 21 | exclude '*.jar' 22 | 23 | from { 24 | configurations.resolvableApi.collect { 25 | it.name.contains("${jarBaseName}") ? zipTree(it) : it 26 | } 27 | } 28 | 29 | into 'html', { 30 | from 'html' 31 | } 32 | 33 | archiveBaseName = "${project.name}_assistant_${buildVersion}_build_${buildDate}" 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /simassistants/demo16/build.gradle: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Demo16 Simulation Assistant build.gradle script 4 | * 5 | *******************************************************************************/ 6 | 7 | 8 | jar { 9 | 10 | manifest { 11 | 12 | attributes( 13 | 'Manifest-Version' : '1.1', 14 | 'Build-JDK': System.properties['java.version'], 15 | 'Build-OS': System.properties['os.name'], 16 | 'Build-Date': new Date(), 17 | 'Created-By': "Gradle ${gradle.gradleVersion}", 18 | 'Specification-Title': 'Demo 16 Simulation Assistant', 19 | 'Specification-Version': "build-${buildDate}", 20 | 'Implementation-Title': 'Simcenter STAR-CCM+', 21 | 'Implementation-Version': buildVersion, 22 | ) 23 | 24 | } 25 | 26 | } 27 | 28 | jar.dependsOn(":macroutils:jar") 29 | -------------------------------------------------------------------------------- /simassistants/demo16/html/Demo16.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Introduction 5 | 6 | 7 | 8 | 9 |

Welcome to the Demo16 assistant.

10 | 11 |

This Simulation Assistant is based on a legacy demo shipped with MacroUtils. Case is a 2D sound propagation in a channel. All one needs to do is the following:

12 |
    13 |
  1. Update the sound signal frequency;
  2. 14 |
  3. Click here to prepare everything;
  4. 15 |
  5. Then, case is ready to run.
  6. 16 |
17 | 18 |

Demo16 is powered by MacroUtils.

19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /simassistants/demo16/src/BuilderTask.java: -------------------------------------------------------------------------------- 1 | package demo16; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.templates.demos.Demo16; 5 | import star.assistant.Task; 6 | import star.assistant.annotation.StarAssistantTask; 7 | import star.assistant.ui.FunctionTaskController; 8 | import star.common.ScalarGlobalParameter; 9 | 10 | /** 11 | * Build/Update Task. 12 | * 13 | * @since MacroUtils v11.06. 14 | * @author Fabio Kasper 15 | */ 16 | @StarAssistantTask( 17 | display = "Task", 18 | contentPath = "html/Demo16.xhtml", 19 | controller = BuilderTask.BuilderController.class 20 | ) 21 | public class BuilderTask extends Task { 22 | 23 | private macroutils.templates.demos.Demo16 _demo16 = null; 24 | private final MacroUtils _mu; 25 | private macroutils.UserDeclarations _ud = null; 26 | 27 | public BuilderTask(MacroUtils m) { 28 | _mu = m; 29 | } 30 | 31 | /** 32 | * The Builder Controller class. 33 | */ 34 | public class BuilderController extends FunctionTaskController { 35 | 36 | /** 37 | * Builds or updates the case. 38 | */ 39 | public void buildCase() { 40 | initializeMacro(); 41 | cleanUpCase(); 42 | _demo16.updateCaseParameters(); 43 | _demo16.executePre(); 44 | _demo16.executePost(); 45 | _demo16.printOverview(); 46 | } 47 | 48 | /** 49 | * Runs the case. 50 | */ 51 | public void runCase() { 52 | _mu.run(); 53 | } 54 | 55 | /** 56 | * Updates the Pressure signal frequency used to build the case. 57 | */ 58 | public void updateSignalFrequency() { 59 | initializeMacro(); 60 | _demo16.updateCaseParameters(); 61 | _ud.scalParam = (ScalarGlobalParameter) _mu.get.objects.scalarParameter("F", false); 62 | selectNode(_ud.scalParam); 63 | _demo16.printOverview(); 64 | } 65 | 66 | private void cleanUpCase() { 67 | if (_mu.get.regions.all(false).isEmpty()) { 68 | return; 69 | } 70 | _mu.remove.allScenes(); 71 | _mu.remove.allPlots(); 72 | _mu.remove.allMonitors(); 73 | _mu.remove.allReports(); 74 | _mu.remove.allRegions(); 75 | _mu.remove.allMeshOperations(); 76 | _mu.remove.allParts(); 77 | _mu.remove.allSolidModelParts(); 78 | _mu.remove.allContinuas(); 79 | _mu.remove.allUpdateEvents(); 80 | _mu.remove.allUserFieldFunctions(); 81 | } 82 | 83 | private void initializeMacro() { 84 | _mu.setSimulation(getActiveSimulation(), true); 85 | _mu.setDebugMode(true); 86 | _ud = _mu.userDeclarations; 87 | _demo16 = new Demo16(_mu); 88 | } 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /simassistants/demo16/src/Demo16.java: -------------------------------------------------------------------------------- 1 | import demo16.BuilderTask; 2 | import java.util.ArrayList; 3 | import macroutils.MacroUtils; 4 | import star.assistant.SimulationAssistant; 5 | import star.assistant.Task; 6 | import star.assistant.annotation.StarAssistant; 7 | 8 | /** 9 | * Main code. 10 | * 11 | * @since MacroUtils v11.06. 12 | * @author Fabio Kasper 13 | */ 14 | @StarAssistant( 15 | desc = "Simulation Assistant", 16 | display = "Demo16 Simulation Assistant." 17 | ) 18 | public class Demo16 extends SimulationAssistant { 19 | 20 | public Demo16() { 21 | 22 | ArrayList tasks = new ArrayList<>(); 23 | 24 | MacroUtils mu = new MacroUtils(null); 25 | 26 | tasks.add(new BuilderTask(mu)); 27 | 28 | setOutline(tasks); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/build.gradle: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * SimpleHexaMesher Simulation Assistant build.gradle script 4 | * 5 | *******************************************************************************/ 6 | 7 | 8 | jar { 9 | 10 | manifest { 11 | 12 | attributes( 13 | 'Manifest-Version' : '1.1', 14 | 'Build-JDK': System.properties['java.version'], 15 | 'Build-OS': System.properties['os.name'], 16 | 'Build-Date': new Date(), 17 | 'Created-By': "Gradle ${gradle.gradleVersion}", 18 | 'Specification-Title': 'SimpleHexaMesher Simulation Assistant', 19 | 'Specification-Version': "build-${buildDate}", 20 | 'Implementation-Title': 'Simcenter STAR-CCM+', 21 | 'Implementation-Version': buildVersion, 22 | ) 23 | 24 | } 25 | 26 | into 'resources', { 27 | from 'resources' 28 | } 29 | 30 | } 31 | 32 | jar.dependsOn(":macroutils:jar") 33 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/html/BlockTask.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Block Task 5 | 6 | 7 | 8 | 9 |

This task is to build the Block geometry and mesh it using a Directed Mesh Operation. Steps involved in this Task are the following:

10 |
    11 |
  1. Define block dimensions and number of cells here;
  2. 12 |
  3. Click here to make it as a 2D mesh (Optional);
  4. 13 |
  5. Finally, click here to generate your mesh.
  6. 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/html/IntroductionTask.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Introduction 5 | 6 | 7 | 8 | 9 |

Welcome to the SimpleHexaMesher assistant.

10 |

This Simulation Assistant generates 100% hexahedron cells using the Directed Mesher in STAR-CCM+. Currently, it supports the following options:

11 |
    12 |
  • Block mesher: Generate a nice and uniform hexa grid in a block;
  • 13 |
14 |

SimpleHexaMesher is powered by MacroUtils.

15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/html/QuestionsAndAnswersTask.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Questions and Answers 5 | 6 | 7 | 8 | 9 |

Q: How can I use the Block mesher?

10 |

A: See an example in the picture below where a mesh is generated using the default values in this assistant.

11 |

12 | 13 |

Q: Can I build a non-uniform grid?

14 |

A: Yes. Use this assistant to get an uniform grid and then edit the spacing in the Mesh Operation.

15 | 16 |

Q: Can I build more than one mesh?

17 |

A: Yes. One can create multiple meshes in multiple Regions.

18 | 19 |

Q: What are the limitations of the Block mesher?

20 |

A: Limitations are:

21 |
    22 |
  • One is able to build multiple meshes. Mixing 2D and 3D meshes will likely not work;
  • 23 |
  • The way this assistant was coded, Block Coordinate2 must always have positive values.
  • 24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/html/StartOverTask.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Block Task 5 | 6 | 7 | 8 | 9 |

Click here to clear everything and start over.

10 |

Note this will erase all your objects in the tree. Use with caution.

11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/resources/BlockTask.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/simassistants/simplehexamesher/resources/BlockTask.jpg -------------------------------------------------------------------------------- /simassistants/simplehexamesher/src/BlockTask.java: -------------------------------------------------------------------------------- 1 | package simplehexamesher; 2 | 3 | import macroutils.MacroUtils; 4 | import macroutils.templates.simassistants.BlockMesher; 5 | import star.assistant.Task; 6 | import star.assistant.annotation.StarAssistantTask; 7 | import star.assistant.ui.FunctionTaskController; 8 | 9 | /** 10 | * Block Mesher Task. 11 | * 12 | * @since MacroUtils v11.06. 13 | * @author Fabio Kasper 14 | */ 15 | @StarAssistantTask( 16 | contentPath = "html/BlockTask.xhtml", 17 | controller = BlockTask.MesherController.class, 18 | display = "Block Mesher" 19 | ) 20 | public class BlockTask extends Task { 21 | 22 | private final MacroUtils _mu; 23 | 24 | /** 25 | * Main constructor for this class. 26 | * 27 | * @param m given MacroUtils object. 28 | */ 29 | public BlockTask(MacroUtils m) { 30 | _mu = m; 31 | } 32 | 33 | /** 34 | * Current {@link FunctionTaskController} subclass. 35 | */ 36 | public class MesherController extends FunctionTaskController { 37 | 38 | /** 39 | * Generate Mesh Task. 40 | */ 41 | public void generateMesh() { 42 | initializeTask(); 43 | BlockMesher bm = new BlockMesher(_mu); 44 | if (bm.haveParameters()) { 45 | bm.generateMesh(); 46 | } else { 47 | _mu.io.say.loud("Please define Block dimensions first and try again."); 48 | } 49 | } 50 | 51 | /** 52 | * Set as Two-Dimensional Task. 53 | */ 54 | public void setAs2D() { 55 | initializeTask(); 56 | new BlockMesher(_mu).setAs2D(); 57 | _mu.io.say.action("Set as Two-Dimensional Task is finished.", true); 58 | } 59 | 60 | /** 61 | * Set Parameters Task. 62 | */ 63 | public void setParameters() { 64 | initializeTask(); 65 | BlockMesher bm = new BlockMesher(_mu); 66 | bm.setParameters(new double[]{ 0, 0, 0 }, new double[]{ 1, 1, 1 }, 67 | new double[]{ 2, 4, 6 }, _mu.userDeclarations.unit_m); 68 | selectNodeExclusive(bm.getBlockCoordinate1Parameter()); 69 | _mu.io.say.action("Set Parameters Task is finished.", true); 70 | } 71 | 72 | private void initializeTask() { 73 | _mu.setSimulation(getActiveSimulation(), false); 74 | } 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/src/IntroductionTask.java: -------------------------------------------------------------------------------- 1 | package simplehexamesher; 2 | 3 | import star.assistant.Task; 4 | import star.assistant.annotation.StarAssistantTask; 5 | 6 | /** 7 | * Introduction Task. 8 | * 9 | * @since MacroUtils v11.06. 10 | * @author Fabio Kasper 11 | */ 12 | @StarAssistantTask( 13 | contentPath = "html/IntroductionTask.xhtml", 14 | display = "Introduction" 15 | ) 16 | public class IntroductionTask extends Task { } 17 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/src/QuestionsAndAnswersTask.java: -------------------------------------------------------------------------------- 1 | package simplehexamesher; 2 | 3 | import star.assistant.Task; 4 | import star.assistant.annotation.StarAssistantTask; 5 | 6 | /** 7 | * Q&A Task. 8 | * 9 | * @since MacroUtils v11.06. 10 | * @author Fabio Kasper 11 | */ 12 | @StarAssistantTask( 13 | contentPath = "html/QuestionsAndAnswersTask.xhtml", 14 | display = "Q&A" 15 | ) 16 | public class QuestionsAndAnswersTask extends Task { } 17 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/src/SimpleHexaMesher.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import macroutils.MacroUtils; 3 | import simplehexamesher.BlockTask; 4 | import simplehexamesher.IntroductionTask; 5 | import simplehexamesher.QuestionsAndAnswersTask; 6 | import simplehexamesher.StartOverTask; 7 | import star.assistant.SimulationAssistant; 8 | import star.assistant.Task; 9 | import star.assistant.annotation.StarAssistant; 10 | 11 | /** 12 | * Main code. 13 | * 14 | * @since MacroUtils v11.06. 15 | * @author Fabio Kasper 16 | */ 17 | @StarAssistant( 18 | desc = "Assistant", 19 | display = "SimpleHexaMesher Assistant." 20 | ) 21 | public class SimpleHexaMesher extends SimulationAssistant { 22 | 23 | public SimpleHexaMesher() { 24 | 25 | ArrayList tasks = new ArrayList<>(); 26 | 27 | MacroUtils mu = new MacroUtils(null); 28 | 29 | tasks.add(new IntroductionTask()); 30 | 31 | tasks.add(new BlockTask(mu)); 32 | 33 | tasks.add(new StartOverTask(mu)); 34 | 35 | tasks.add(new QuestionsAndAnswersTask()); 36 | 37 | setOutline(tasks); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /simassistants/simplehexamesher/src/StartOverTask.java: -------------------------------------------------------------------------------- 1 | package simplehexamesher; 2 | 3 | import macroutils.MacroUtils; 4 | import star.assistant.Task; 5 | import star.assistant.annotation.StarAssistantTask; 6 | import star.assistant.ui.FunctionTaskController; 7 | 8 | /** 9 | * Start over Task. 10 | * 11 | * @since MacroUtils v11.06. 12 | * @author Fabio Kasper 13 | */ 14 | @StarAssistantTask( 15 | contentPath = "html/StartOverTask.xhtml", 16 | controller = StartOverTask.RemoverController.class, 17 | display = "Start Over" 18 | ) 19 | public class StartOverTask extends Task { 20 | 21 | private final MacroUtils _mu; 22 | 23 | /** 24 | * Main constructor for this class. 25 | * 26 | * @param m given MacroUtils object. 27 | */ 28 | public StartOverTask(MacroUtils m) { 29 | _mu = m; 30 | } 31 | 32 | /** 33 | * Current {@link FunctionTaskController} subclass. 34 | */ 35 | public class RemoverController extends FunctionTaskController { 36 | 37 | /** 38 | * Removes all objects. 39 | */ 40 | public void removeAll() { 41 | _mu.setSimulation(getActiveSimulation(), false); 42 | _mu.remove.all(); 43 | _mu.io.say.action("Start Over Task is finished.", true); 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tests/common/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------------- /tests/common/executor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | This module executes commands. 4 | 5 | Created on Fri Apr 27 10:44:34 2018 6 | 7 | @author: Fabio Kasper 8 | """ 9 | import glob 10 | import os 11 | import queue 12 | import re 13 | import threading 14 | import time 15 | import common.timer as timer 16 | import common.strings as strings 17 | 18 | 19 | def _flat(commands): 20 | """Flatten commands while preserving order""" 21 | commands = [cmd for cmd in commands if cmd is not None] 22 | flattened = [] 23 | for command in commands: 24 | if isinstance(command, str): 25 | flattened.append(command) 26 | elif isinstance(command, list): 27 | flattened.extend(command) 28 | else: 29 | raise TypeError('Invalid command: %s' % str(command)) 30 | return flattened 31 | 32 | 33 | def _case_name(command): 34 | """Demo name based on command supplied""" 35 | found = re.findall('(\w*)\.java', command) 36 | assert len(found) == 1, 'Could not parse name from command: %s' % command 37 | return found[0] 38 | 39 | 40 | def _log(command): 41 | """Automatic log file generation based on macro""" 42 | return '%s.log' % _case_name(command) 43 | 44 | 45 | def _number_of_cores(command): 46 | """Retrieve np info""" 47 | found = re.findall('-np (\d+)', command) 48 | assert len(found) < 2, 'Could not parse np from command: %s' % command 49 | return int(found[0]) if found else 1 50 | 51 | 52 | def _run(testhome, command): 53 | os.chdir(testhome) 54 | os.system('%s > %s' % (command, _log(command))) 55 | 56 | 57 | def _will_run(testhome, base_name): 58 | pictures = glob.glob(os.path.join(testhome, '%s*.png' % base_name)) 59 | log_file = glob.glob(os.path.join(testhome, '%s.log' % base_name)) 60 | return len(pictures) + len(log_file) == 0 61 | 62 | 63 | def run_commands(testhome, commands, threads): 64 | """General runner""" 65 | star_time = timer.ExecutionTime(key='STAR-CCM+ macros') 66 | print('') 67 | if threads > 1: 68 | run_multiple(testhome, commands, threads) 69 | else: 70 | run_sequential(testhome, commands) 71 | star_time.finalize(extra_info='STAR-CCM+ macros') 72 | print('\n') 73 | 74 | 75 | def run_multiple(testhome, commands, threads): 76 | """Run multiple threads""" 77 | print(strings.heading(f'Running in threaded mode ({threads = })')) 78 | 79 | commands_to_run = _flat(commands) 80 | if len(commands_to_run) == 0: 81 | return 82 | 83 | run_queue = queue.Queue() 84 | for i in range(threads): 85 | thread = TesterThread(queue=run_queue) 86 | thread.start() 87 | 88 | for command in commands_to_run: 89 | base_name = _case_name(command) 90 | if _will_run(testhome, base_name): 91 | run_queue.put([testhome, command]) 92 | time.sleep(1) 93 | else: 94 | print(f'Bypassed due presence of log/picture files: {base_name}') 95 | 96 | run_queue.join() 97 | 98 | 99 | def run_sequential(testhome, commands): 100 | """Run invidually""" 101 | print(strings.heading('Running in sequential mode')) 102 | 103 | commands_to_run = _flat(commands) 104 | if len(commands_to_run) == 0: 105 | return 106 | 107 | for command in commands_to_run: 108 | base_name = _case_name(command) 109 | np = _number_of_cores(command) 110 | snp = 'np=%d' % np if np > 1 else 'serial' 111 | if _will_run(testhome, base_name): 112 | print('Running: %s (running %s)' % (base_name, snp)) 113 | _run(testhome, command) 114 | else: 115 | print('Bypassed due presence of log/picture files: %s' % base_name) 116 | 117 | 118 | class TesterThread(threading.Thread): 119 | def __init__(self, queue=None): 120 | threading.Thread.__init__(self) 121 | self.queue = queue 122 | self.setDaemon(True) 123 | 124 | def run(self): 125 | while True: 126 | self.run_command() 127 | self.queue.task_done() 128 | 129 | def run_command(self): 130 | et = timer.ExecutionTime(verbose=False) 131 | testhome, command = self.queue.get() 132 | name = _case_name(command) 133 | np = _number_of_cores(command) 134 | snp = 'np=%d' % np if np > 1 else 'serial' 135 | print(' |--> Started: %s (at %s running %s)' % (name, et.s_t0, snp)) 136 | _run(testhome, command) 137 | et.finalize() 138 | print(' -->| Finished: %s (duration: %s)' % (name, et.s_tf)) 139 | 140 | 141 | if __name__ == "__main__": 142 | pass 143 | -------------------------------------------------------------------------------- /tests/common/set_up.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Apr 27 08:25:53 2018 4 | 5 | @author: Fabio Kasper 6 | """ 7 | import os 8 | from pathlib import Path 9 | import shutil 10 | import common.strings as strings 11 | 12 | 13 | def _copy(files: list[Path], testhome: Path): 14 | n = len(files) 15 | print('Copying {} file{} to TESTHOME:'.format(n, 's' if n > 1 else ''), 16 | end=' ') 17 | print(strings.itemized([repr(file.name) for file in files])) 18 | for file in files: 19 | shutil.copy(file, testhome) 20 | 21 | 22 | def _setup_testhome(testhome: Path): 23 | print('Setting up TESTHOME:', end=' ') 24 | if testhome.is_dir(): 25 | print('folder already exists') 26 | else: 27 | os.mkdir(testhome) 28 | print('folder created') 29 | 30 | 31 | def environment(datahome, demohome, jarfile, starhome, testhome, files): 32 | """Set up the environment to run the demos""" 33 | print(strings.heading('Environment preparation')) 34 | _setup_testhome(testhome) 35 | files.append(jarfile) 36 | _copy(files, testhome) 37 | print('\n') 38 | 39 | 40 | if __name__ == "__main__": 41 | pass 42 | -------------------------------------------------------------------------------- /tests/common/star.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Apr 27 08:47:26 2018 4 | 5 | @author: Fabio Kasper 6 | """ 7 | import os 8 | import sys 9 | 10 | 11 | def _assert_exists(f): 12 | assert os.path.exists(f), 'File does not exist: %s' % f 13 | 14 | 15 | def _executable(starhome): 16 | """Return full path to STAR-CCM+""" 17 | if _is_linux(): 18 | star_exe = os.path.join(starhome, 'star/bin/starccm+') 19 | _assert_exists(star_exe) 20 | return star_exe 21 | else: 22 | raise NotImplementedError('Have not tested in non Linux platforms') 23 | 24 | 25 | def _no_path(macro_file): 26 | """Everything is run in the same folder so no full path is needed""" 27 | bp, fn = os.path.split(macro_file) 28 | return fn 29 | 30 | 31 | def _is_linux(): 32 | platform = sys.platform 33 | return platform == "linux" or platform == "linux2" 34 | 35 | 36 | def _basic_syntax(macro_file, np, is_batch, sim_file=None): 37 | """Return the full syntax to run STAR-CCM+""" 38 | macro = '%s %s' % ('-batch' if is_batch else '-m', _no_path(macro_file)) 39 | cores = '-np %d' % np if np > 1 else '' 40 | sim = '' if sim_file is None else sim_file 41 | return '-classpath . %s %s %s' % (macro, cores, sim) 42 | 43 | 44 | def load_simulation(starhome, sim_file, macro_file, np, is_batch): 45 | """Return the full syntax to run STAR-CCM+""" 46 | basic_syntax = _basic_syntax(macro_file, np, is_batch) 47 | return '%s %s %s' % (_executable(starhome), basic_syntax, sim_file) 48 | 49 | 50 | def new_simulation(starhome, macro_file, np, is_batch): 51 | """Return the full syntax to run STAR-CCM+""" 52 | basic_syntax = _basic_syntax(macro_file, np, is_batch) 53 | return '%s -new %s' % (_executable(starhome), basic_syntax) 54 | 55 | 56 | if __name__ == "__main__": 57 | pass 58 | -------------------------------------------------------------------------------- /tests/common/strings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Some string utilities. 4 | 5 | Created on Fri Apr 27 08:06:06 2018 6 | 7 | @author: Fabio Kasper 8 | """ 9 | 10 | 11 | N_CHARS = 80 12 | 13 | 14 | def _assert_is_list(items): 15 | assert isinstance(items, list), _reason('Must be a list', items) 16 | 17 | 18 | def _assert_is_list_of_strings(items): 19 | _assert_is_list(items) 20 | assert len(items) == sum([isinstance(item, str) for item in items]), \ 21 | _reason('Must be a list of strings', items) 22 | 23 | 24 | def _reason(reason, obj): 25 | return '%s: "%s"' % (reason, obj) 26 | 27 | 28 | def frame(message): 29 | """Create a fancy frame""" 30 | line = N_CHARS * '=' 31 | string = ' '.join(message.upper()).center(N_CHARS) 32 | return '\n'.join([line, string, line]) 33 | 34 | 35 | def heading(message): 36 | """Return a heading message""" 37 | return '%s\n%s' % (message, line()) 38 | 39 | 40 | def itemized(items): 41 | """Return a fancy list of strings""" 42 | _assert_is_list_of_strings(items) 43 | if len(items) < 2: 44 | return ' '.join(items) 45 | else: 46 | flat_items = ', '.join(items[:-1]) 47 | return '%s and %s' % (flat_items, items[-1]) 48 | 49 | 50 | def line(): 51 | """Return a simple line""" 52 | return N_CHARS * '-' 53 | 54 | 55 | if __name__ == "__main__": 56 | pass 57 | -------------------------------------------------------------------------------- /tests/common/timer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | A few useful timer tools. 4 | 5 | @author: Fabio Kasper 6 | """ 7 | import datetime 8 | 9 | 10 | class ExecutionTime(): 11 | 12 | """A very useful information to have""" 13 | 14 | def __init__(self, t0=None, key=None, verbose=True): 15 | """Initialize with no argument as a start""" 16 | self.verbose = verbose 17 | if t0 is None: 18 | t0 = datetime.datetime.now() 19 | self.t0 = t0 20 | self.s_t0 = t0.strftime('%H:%M:%S') 21 | if verbose: 22 | if key is None: 23 | print('Execution started at %s.' % self.s_t0) 24 | else: 25 | print('Execution of %s started at %s.' % (key, self.s_t0)) 26 | 27 | def __delta(self, t1): 28 | return int((t1 - self.t0).total_seconds()) 29 | 30 | def finalize(self, extra_info=None): 31 | dt = self.__delta(datetime.datetime.now()) 32 | h = dt // 3600 33 | m = (dt % 3600) // 60 34 | s = (dt % 3600) % 60 35 | sh = '%dh' % h if h > 0 else '' 36 | sm = '%dmin' % m if m > 0 else '' 37 | ss = '%ds' % s if s > 0 else '' 38 | self.s_tf = '%s%s%s' % (sh, sm, ss) if dt > 0 else '0s' 39 | ei = '' if extra_info is None else ' -- %s' % extra_info 40 | if self.verbose: 41 | print('Execution time%s: %s.' % (ei, self.s_tf)) 42 | 43 | 44 | if __name__ == "__main__": 45 | pass 46 | -------------------------------------------------------------------------------- /tests/macros/BugCreateStreamlineSceneTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import macroutils.UserDeclarations; 4 | import star.base.neo.DoubleVector; 5 | import star.common.StarMacro; 6 | 7 | /** 8 | * This test is to prevent bug filed at Feb 14, 2017 from happening again (issue #14). 9 | * 10 | * @since MacroUtils v13.04 11 | * @author Fabio Kasper 12 | */ 13 | public class BugCreateStreamlineSceneTest extends StarMacro { 14 | 15 | @Override 16 | public void execute() { 17 | 18 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 19 | 20 | createStreamlineScene(mu); 21 | 22 | writeSummary(mu); 23 | 24 | } 25 | 26 | private void createStreamlineScene(MacroUtils mu) { 27 | UserDeclarations ud = mu.userDeclarations; 28 | ud.postStreamlinesTubesWidth = 0.001; 29 | ud.namedObjects.add(mu.get.boundaries.byREGEX("inlet", true)); 30 | ud.namedObjects.addAll(mu.get.regions.all(true)); 31 | ud.scene = mu.add.scene.streamline(ud.namedObjects, true); 32 | ud.scene.open(); 33 | ud.scene.getCurrentView().setInput( 34 | new DoubleVector(new double[] {0.24779246893912843, -0.010367, -0.005769}), 35 | new DoubleVector(new double[] {-0.6836124057786044, 0.332600, 0.494371}), 36 | new DoubleVector(new double[] {0.2016193914075902, 0.941481, -0.270117}), 37 | 0.090454, 1); 38 | ud.string = "Bug_" + ud.simTitle; 39 | mu.saveSim(ud.string); 40 | mu.io.write.picture(ud.scene, ud.string, 1280, 720, true); 41 | } 42 | 43 | private void writeSummary(MacroUtils mu) { 44 | SummaryWriter sw = new SummaryWriter(mu); 45 | sw.collectScenes(); 46 | sw.execute(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/macros/BugParentNameTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import macroutils.StaticDeclarations; 4 | import macroutils.UserDeclarations; 5 | import star.common.StarMacro; 6 | 7 | /** 8 | * This test is to prevent bug filed at Apr 28, 2018 from happening again (issue #20). 9 | * 10 | * @since MacroUtils v13.04 11 | * @author Fabio Kasper 12 | */ 13 | public class BugParentNameTest extends StarMacro { 14 | 15 | @Override 16 | public void execute() { 17 | 18 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 19 | 20 | UserDeclarations ud = mu.userDeclarations; 21 | 22 | mu.add.geometry.block(StaticDeclarations.COORD0, new double[] {1, 1, 1}, ud.unit_mm) 23 | .setPresentationName("My Block"); 24 | 25 | ud.scene = mu.add.scene.geometry(); 26 | 27 | ud.scene.setPresentationName("My Scene"); 28 | 29 | mu.get.scenes.displayerByREGEX(ud.scene, ".*", true).setPresentationName("My Displayer"); 30 | 31 | ud.region = mu.add.region.fromAll(true); 32 | 33 | ud.region.setPresentationName("My Region"); 34 | 35 | mu.get.boundaries.byREGEX(".*", true).setPresentationName("My Boundary"); 36 | 37 | ud.ff = mu.get.objects.fieldFunction(StaticDeclarations.Vars.POS).getComponentFunction(0); 38 | 39 | mu.add.report.minimum(ud.region, "My Report", ud.ff, ud.unit_mm, true); 40 | 41 | mu.saveSim("BugParentNameTest"); 42 | 43 | new SummaryWriter(mu).execute(); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /tests/macros/BugWritingFilenamesTest.java: -------------------------------------------------------------------------------- 1 | import macroutils.MacroUtils; 2 | import macroutils.StaticDeclarations; 3 | import macroutils.UserDeclarations; 4 | import star.common.StarMacro; 5 | 6 | /** 7 | * This test is to prevent bug filed at Mar 29, 2018 from happening again (issue #19). 8 | * 9 | * @since MacroUtils v13.04 10 | * @author Fabio Kasper 11 | */ 12 | public class BugWritingFilenamesTest extends StarMacro { 13 | 14 | @Override 15 | public void execute() { 16 | 17 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 18 | 19 | UserDeclarations ud = mu.userDeclarations; 20 | 21 | ud.simTitle = "Block 95.2 mm^3"; 22 | 23 | mu.add.geometry.block(StaticDeclarations.COORD0, new double[] {3.4, 4.0, 7.0}, ud.unit_mm); 24 | 25 | ud.scene = mu.add.scene.geometry(); 26 | 27 | ud.scene.resetCamera(); 28 | 29 | ud.scene.setPresentationName("Block 3.4 x 4.0 x 7.0 mm^3"); 30 | 31 | mu.io.write.picture(ud.scene, true); 32 | 33 | mu.saveSim(); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/macros/Demo14_EvalGCITest.java: -------------------------------------------------------------------------------- 1 | 2 | import common.SummaryWriter; 3 | import java.io.File; 4 | import macroutils.MacroUtils; 5 | import macroutils.UserDeclarations; 6 | import star.common.StarMacro; 7 | 8 | /** 9 | * This test is assess the GCI metrics in a unit-test fashion. 10 | * 11 | * @since MacroUtils v13.04 12 | * @author Fabio Kasper 13 | */ 14 | public class Demo14_EvalGCITest extends StarMacro { 15 | 16 | private static final String PLOT_NAME = "Numerical vs Analytical Solutions"; 17 | private static final String PLOT_NAME_GCI = "Numerical vs Analytical Solutions - GCI23"; 18 | 19 | @Override 20 | public void execute() { 21 | 22 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 23 | 24 | UserDeclarations ud = mu.userDeclarations; 25 | 26 | ud.simTitle = "Demo14_GCI"; 27 | 28 | for (int i = 1; i <= 3; i++) { 29 | ud.files.add(new File(ud.simPath, ud.simTitle + "_Grid00" + i + ".sim")); 30 | } 31 | 32 | mu.templates.gci.evaluate(mu.get.plots.byREGEX(PLOT_NAME, true), ud.files); 33 | 34 | mu.saveSim(); 35 | 36 | mu.io.write.all(ud.simTitle); 37 | 38 | writeSummary(mu); 39 | 40 | } 41 | 42 | private void writeSummary(MacroUtils mu) { 43 | SummaryWriter sw = new SummaryWriter(mu, false); 44 | sw.collectReports(); 45 | sw.collectPlot(mu.get.plots.byREGEX(PLOT_NAME_GCI, true)); 46 | sw.execute(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/macros/SimAssistantBlockMesherTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import macroutils.UserDeclarations; 4 | import macroutils.templates.simassistants.BlockMesher; 5 | import star.common.StarMacro; 6 | 7 | /** 8 | * This is an automated test for the BlockMesher simulation assistant. 9 | * 10 | * @since MacroUtils v13.04 11 | * @author Fabio Kasper 12 | */ 13 | public class SimAssistantBlockMesherTest extends StarMacro { 14 | 15 | @Override 16 | public void execute() { 17 | MacroUtils mu = new MacroUtils(getActiveSimulation()); 18 | 19 | generateMesh(mu, false); 20 | 21 | generateMesh(mu, true); 22 | } 23 | 24 | private void generateMesh(MacroUtils mu, boolean is2D) { 25 | final UserDeclarations ud = mu.userDeclarations; 26 | ud.simTitle = "SimAssistantBlockMesher"; 27 | 28 | final double[] coord1 = new double[]{ 0, 0, 0 }; 29 | final double[] coord2 = new double[]{ 1, 2, 3 }; 30 | final double[] nCells = new double[]{ 4, 7, 8 }; 31 | 32 | BlockMesher bm = new BlockMesher(mu); 33 | bm.setParameters(coord1, coord2, nCells, ud.unit_m); 34 | if (is2D) { 35 | ud.simTitle += "_2D"; 36 | bm.setAs2D(); 37 | } 38 | bm.generateMesh(); 39 | mu.saveSim(); 40 | 41 | SummaryWriter sw = new SummaryWriter(mu); 42 | sw.collectMesh(); 43 | sw.execute(); 44 | 45 | mu.remove.all(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tests/macros/SimToolImplicitUnsteadyConvergenceCheckerTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import macroutils.templates.simtools.ImplicitUnsteadyConvergenceChecker; 4 | import star.common.StarMacro; 5 | 6 | /** 7 | * This is an automated test for the ImplicitUnsteadyConvergenceChecker simulation tool. 8 | * 9 | * @since MacroUtils 2019.2 10 | * @author Fabio Kasper 11 | */ 12 | public class SimToolImplicitUnsteadyConvergenceCheckerTest extends StarMacro { 13 | 14 | @Override 15 | public void execute() { 16 | 17 | final MacroUtils mu = new MacroUtils(getSimulation()); 18 | final String prefix = "SimToolConvergenceChecker_"; 19 | final ImplicitUnsteadyConvergenceChecker cc = new ImplicitUnsteadyConvergenceChecker(mu); 20 | 21 | new SummaryWriter(mu, prefix + "0_Original.ref").execute(); 22 | 23 | cc.execute(); 24 | 25 | new SummaryWriter(mu, prefix + "1_Artifacts_Created.ref").execute(); 26 | 27 | cc.removeArtifacts(); 28 | 29 | new SummaryWriter(mu, prefix + "2_Artifacts_Removed.ref").execute(); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/macros/SimToolMeshMetricsTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import macroutils.templates.simtools.MeshMetrics; 4 | import star.common.StarMacro; 5 | 6 | /** 7 | * This is an automated test for the MeshMetrics simulation tool. 8 | * 9 | * @since MacroUtils 2019.2 10 | * @author Fabio Kasper 11 | */ 12 | public class SimToolMeshMetricsTest extends StarMacro { 13 | 14 | @Override 15 | public void execute() { 16 | 17 | final MacroUtils mu = new MacroUtils(getSimulation()); 18 | final String prefix = "SimToolMeshMetrics_"; 19 | final MeshMetrics mm = new MeshMetrics(mu); 20 | 21 | new SummaryWriter(mu, prefix + "0_Original.ref").execute(); 22 | 23 | mm.execute(); 24 | 25 | new SummaryWriter(mu, prefix + "1_Artifacts_Created.ref").execute(); 26 | 27 | mm.removeArtifacts(); 28 | 29 | new SummaryWriter(mu, prefix + "2_Artifacts_Removed.ref").execute(); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/macros/WriteSummaryTest.java: -------------------------------------------------------------------------------- 1 | import common.SummaryWriter; 2 | import macroutils.MacroUtils; 3 | import star.common.StarMacro; 4 | 5 | /** 6 | * Write an overview of the Simulation -- focus is on quantitative data. 7 | * 8 | * @since MacroUtils v13.04 9 | * @author Fabio Kasper 10 | */ 11 | public class WriteSummaryTest extends StarMacro { 12 | 13 | @Override 14 | public void execute() { 15 | 16 | new SummaryWriter(new MacroUtils(getSimulation(), false)).execute(); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | iniconfig==2.0.0 2 | packaging==24.2 3 | pluggy==1.5.0 4 | pytest==8.3.5 5 | -------------------------------------------------------------------------------- /tests/test/movie.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Generate movies from pictures with FFMPEG. 4 | 5 | Created on Wed Jun 6 14:54:06 2018 6 | 7 | @author: Fabio Kasper 8 | """ 9 | import glob 10 | import os 11 | import re 12 | import shutil 13 | 14 | 15 | _FMT_PICS = 'pic%08d.png' 16 | 17 | 18 | def _rename_pictures(folder): 19 | pwd = os.getcwd() 20 | os.chdir(folder) 21 | files = sorted(glob.glob("*"), key=os.path.getmtime) 22 | print('Renaming %d pictures ... ' % len(files)), 23 | for n, filename in enumerate(files[::2]): 24 | os.rename(filename, _FMT_PICS % (n+1)) 25 | print('OK!') 26 | os.chdir(pwd) 27 | 28 | 29 | def _remove(folder): 30 | if os.path.isdir(folder): 31 | print('Removing "%s" ... ' % folder), 32 | shutil.rmtree(folder) 33 | print('OK!') 34 | 35 | 36 | def name(folder): 37 | assert re.match('^pics_.*', folder), 'Invalid folder: %s' % folder 38 | return '_%s.mp4' % folder.replace('pics_', '') 39 | 40 | 41 | def write(folder): 42 | movie_file = name(folder) 43 | 44 | print('') 45 | print('This folder: "%s"' % os.getcwd()) 46 | print('Movie file: "%s"' % movie_file) 47 | print('From Folder: "%s"' % folder) 48 | 49 | if os.path.isfile(movie_file): 50 | print('Movie already exists.') 51 | return 52 | 53 | temp_folder = 'tmp_%s' % folder 54 | _remove(temp_folder) 55 | 56 | print('Duplicating to "%s"...' % temp_folder) 57 | shutil.copytree(folder, temp_folder) 58 | 59 | _rename_pictures(temp_folder) 60 | 61 | command = 'ffmpeg -i %s/%s -framerate 60 -c:v libx264 ' \ 62 | '-pix_fmt yuv420p %s; rm -fr %s' % (temp_folder, _FMT_PICS, 63 | movie_file, temp_folder) 64 | print('\nCommand: "%s"\n' % command) 65 | os.system(command) 66 | _remove(temp_folder) 67 | 68 | 69 | if __name__ == "__main__": 70 | pass 71 | -------------------------------------------------------------------------------- /tests/test/test_bugs.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import glob 3 | import os 4 | import re 5 | import test_utils 6 | 7 | 8 | def _assert_opacity_bug_14(key, expected): 9 | re_patt = r'Scene -> \w+ -> \w+ -> %s Opacity:\s(.*)\n' % key 10 | actual = _float(re_patt, _bug_sim(1)) 11 | test_utils.assert_value(actual, expected, tolerance=0) 12 | 13 | 14 | def _bug_sim(demo_id): 15 | return 'Bug_%s' % _sim(demo_id) 16 | 17 | 18 | def _clean_up(key): 19 | if isinstance(key, int): 20 | key = _bug_sim(key) 21 | os.chdir(test_utils._test_home()) 22 | files = glob.glob('%s.*' % os.path.splitext(key)[0]) 23 | files.append(test_utils._summary_file(key)) 24 | test_utils._remove([f for f in files if not _is_java(f)]) 25 | 26 | 27 | def _float(re_patt, sim_file): 28 | contents = test_utils.summary_contents(sim_file=sim_file) 29 | return test_utils._float_from_contents(re_patt, contents) 30 | 31 | 32 | def _is_java(f): 33 | return os.path.splitext(f)[-1] == '.java' 34 | 35 | 36 | def _load_demo(demo_id, macro_name): 37 | _clean_up(demo_id) 38 | test_utils._load_sim(_sim(demo_id), '%s.java' % macro_name) 39 | 40 | 41 | def _new_sim(macro_name): 42 | _clean_up(macro_name) 43 | test_utils._new_sim('%s.java' % macro_name) 44 | 45 | 46 | def _sim(demo_id): 47 | sim_file = test_utils.simulation(demo_id) 48 | assert os.path.exists(sim_file), 'Demo %d needs to be run first' % demo_id 49 | return sim_file 50 | 51 | 52 | def test_bug_14(): 53 | _load_demo(1, 'BugCreateStreamlineSceneTest') 54 | bug_sim = _bug_sim(1) 55 | _assert_opacity_bug_14('Part', 0.2) 56 | _assert_opacity_bug_14('Scalar', 1.0) 57 | _assert_opacity_bug_14('Streamline', 1.0) 58 | assert os.path.exists(bug_sim.replace('.sim', '.png')) 59 | 60 | 61 | def test_bug_19(): 62 | file_name = 'Block 95.2 mm^3.sim' 63 | scene_name = 'Block 3.4 x 4.0 x 7.0 mm^3.png' 64 | _new_sim('BugWritingFilenamesTest') 65 | assert os.path.exists(file_name.replace(' ', '_')) 66 | assert os.path.exists(scene_name.replace(' ', '_')) 67 | 68 | 69 | def test_bug_20(): 70 | _new_sim('BugParentNameTest') 71 | ref_file = test_utils._summary_file('BugParentNameTest') 72 | contents = test_utils._contents(ref_file) 73 | assert len(re.findall('Part ->', contents)) == 1 74 | assert len(re.findall('Region ->', contents)) == 2 # Multiple words 75 | assert len(re.findall('Report ->', contents)) == 7 # found 76 | assert len(re.findall('Monitor ->', contents)) == 2 77 | assert len(re.findall('Scene ->', contents)) == 4 78 | assert len(re.findall('Displayer ->', contents)) == 2 79 | -------------------------------------------------------------------------------- /tests/test/test_demo01.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Cylinder', 3) 14 | 15 | 16 | def test_cell_count(): 17 | test_utils.assert_cell_count(DEMO_ID, 55200, tolerance=0.01, relative=True) 18 | 19 | 20 | def test_solution(): 21 | test_utils.assert_iteration(DEMO_ID, 110, tolerance=30, relative=False) 22 | 23 | 24 | def test_report(): 25 | test_utils.assert_report(DEMO_ID, 'Pressure Inlet', 3.9, tolerance=0.02) 26 | 27 | 28 | def test_scalar_min(): 29 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 0, relative=False) 30 | 31 | 32 | def test_scalar_max(): 33 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 0.126, 34 | tolerance=0.02) 35 | -------------------------------------------------------------------------------- /tests/test/test_demo02.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Channel', 4) 14 | 15 | 16 | def test_cell_count(): 17 | test_utils.assert_cell_count(DEMO_ID, 6000, relative=False) 18 | 19 | 20 | def test_solution(): 21 | test_utils.assert_iteration(DEMO_ID, 50) 22 | 23 | 24 | def test_report(): 25 | test_utils.assert_report(DEMO_ID, 'Temperature', 42.702) 26 | 27 | 28 | def test_scalar_min(): 29 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 42.0) 30 | 31 | 32 | def test_scalar_max(): 33 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 43.4) 34 | -------------------------------------------------------------------------------- /tests/test/test_demo03.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_block1_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Block1', 5) 14 | 15 | 16 | def test_block2_part_surfaces_count(): 17 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Block2', 5) 18 | 19 | 20 | def test_channel_part_surfaces_count(): 21 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Channel', 6) 22 | 23 | 24 | def test_cell_count(): 25 | test_utils.assert_cell_count(DEMO_ID, 11400) 26 | 27 | 28 | def test_solution(): 29 | test_utils.assert_iteration(DEMO_ID, 1000) 30 | 31 | 32 | def test_report(): 33 | test_utils.assert_report(DEMO_ID, 'P_in', 0.0016, 34 | tolerance=0.05, relative=True) 35 | 36 | 37 | def test_scalar_min(): 38 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 0.0, 39 | tolerance=1e-6, relative=False) 40 | 41 | 42 | def test_scalar_max(): 43 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 6.0563) 44 | 45 | 46 | def test_vector_min(): 47 | test_utils.assert_scene_min(DEMO_ID, 'Vector', 'Vector', 0.0) 48 | 49 | 50 | def test_vector_max(): 51 | test_utils.assert_scene_max(DEMO_ID, 'Vector', 'Vector', 0.0821) 52 | -------------------------------------------------------------------------------- /tests/test/test_demo04.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_cell_count(): 13 | test_utils.assert_face_count(DEMO_ID, 95652) 14 | 15 | 16 | def test_vertex_count(): 17 | test_utils.assert_vertex_count(DEMO_ID, 47826) 18 | 19 | 20 | def test_part_surfaces_count(): 21 | test_utils.assert_part_surfaces_count(DEMO_ID, 'radial_impeller', 5) 22 | 23 | 24 | def test_pictures_count(): 25 | test_utils.assert_pictures_count(DEMO_ID, 1) 26 | 27 | 28 | def test_solution(): 29 | test_utils.assert_iteration(DEMO_ID, 0) 30 | -------------------------------------------------------------------------------- /tests/test/test_demo05.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_tunnel_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Tunnel', 4) 14 | 15 | 16 | def test_kart_wrap_part_surfaces_count(): 17 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Kart Wrap', 91) 18 | 19 | 20 | def test_cell_count(): 21 | test_utils.assert_cell_count(DEMO_ID, 640000, tolerance=0.05) 22 | 23 | 24 | def test_solution(): 25 | test_utils.assert_iteration(DEMO_ID, 250, tolerance=100, relative=False) 26 | 27 | 28 | def test_frontal_area_report(): 29 | test_utils.assert_report(DEMO_ID, 'Frontal Area', 0.002692) 30 | 31 | 32 | def test_cd_report(): 33 | test_utils.assert_report(DEMO_ID, 'C_d', 0.64, 34 | tolerance=0.02, relative=False) 35 | 36 | 37 | def test_cl_report(): 38 | test_utils.assert_report(DEMO_ID, 'C_l', 0.34, 39 | tolerance=0.02, relative=False) 40 | 41 | 42 | def test_scalar_pressure_kart_min(): 43 | test_utils.assert_scene_min(DEMO_ID, 'Pressure Kart', 'Scalar', -1.6, 44 | tolerance=0.5, relative=False) 45 | 46 | 47 | def test_scalar_pressure_kart_max(): 48 | test_utils.assert_scene_max(DEMO_ID, 'Pressure Kart', 'Scalar', 1.1, 49 | tolerance=1.0, relative=False) 50 | 51 | 52 | def test_scalar_pressure_section_min(): 53 | test_utils.assert_scene_min(DEMO_ID, 'Pressure Section', 'Scalar', -0.65, 54 | tolerance=0.1, relative=True) 55 | 56 | 57 | def test_scalar_pressure_section_max(): 58 | test_utils.assert_scene_max(DEMO_ID, 'Pressure Section', 'Scalar', 1.1, 59 | tolerance=1.0, relative=False) 60 | 61 | 62 | def test_vector_velocity_section_min(): 63 | test_utils.assert_scene_min(DEMO_ID, 'Vector Section', 'Vector', 0.0) 64 | 65 | 66 | def test_vector_velocity_section_max(): 67 | test_utils.assert_scene_max(DEMO_ID, 'Vector Section', 'Vector', 56.83) 68 | -------------------------------------------------------------------------------- /tests/test/test_demo06.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | There is no urging value in testing demo 06. 4 | ''' 5 | 6 | 7 | if __name__ == "__main__": 8 | pass 9 | -------------------------------------------------------------------------------- /tests/test/test_demo07.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import movie 3 | import test_utils 4 | 5 | 6 | DEMO_ID = test_utils.demo_id(__file__) 7 | MOVIE_FOLDER = 'pics_Demo7_VOF' 8 | 9 | 10 | def test_write_summary(): 11 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 12 | 13 | 14 | def test_tunnel_part_surfaces_count(): 15 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Block', 2) 16 | 17 | 18 | def test_cell_count(): 19 | test_utils.assert_cell_count(DEMO_ID, 5000, tolerance=0, relative=False) 20 | 21 | 22 | def test_solution(): 23 | test_utils.assert_iteration(DEMO_ID, 31200) 24 | test_utils.assert_time(DEMO_ID, 8.0, tolerance=0.0) 25 | 26 | 27 | def test_cfl_avg_report(): 28 | test_utils.assert_report(DEMO_ID, 'CFL_avg', 0.01, 29 | tolerance=0.005, relative=False) 30 | 31 | 32 | def test_cfl_max_report(): 33 | """Fluid should be at rest by the end of simulation""" 34 | test_utils.assert_report(DEMO_ID, 'CFL_max', 0.0, 35 | tolerance=0.05, relative=False) 36 | 37 | 38 | def test_time_report(): 39 | test_utils.assert_report(DEMO_ID, 'Time', 8.0, tolerance=0, relative=False) 40 | 41 | 42 | def test_motion_reports(): 43 | test_utils.assert_report(DEMO_ID, 'MotionDispl', 0.0) 44 | test_utils.assert_report(DEMO_ID, 'MotionVel', 0.0) 45 | 46 | 47 | def test_scalar_min(): 48 | test_utils.assert_scene_min(DEMO_ID, 'Demo7_VOF', 'Scalar', 0.0) 49 | 50 | 51 | def test_scalar_max(): 52 | test_utils.assert_scene_max(DEMO_ID, 'Demo7_VOF', 'Scalar', 1.0, 53 | relative=False) 54 | 55 | 56 | def test_pictures_count(): 57 | folder = '%s/*.png' % MOVIE_FOLDER 58 | test_utils.assert_pictures_count_in_folder(folder, 1599) 59 | 60 | 61 | def test_write_movie(): 62 | movie.write(MOVIE_FOLDER) 63 | test_utils.assert_file_size(movie.name(MOVIE_FOLDER), 2981852, 64 | tolerance=0.1, relative=True) 65 | -------------------------------------------------------------------------------- /tests/test/test_demo08.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_wing_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'WING', 4) 14 | 15 | 16 | def test_domain_part_surfaces_count(): 17 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Subtract', 5) 18 | 19 | 20 | def test_cell_count(): 21 | test_utils.assert_cell_count(DEMO_ID, 726000, 22 | tolerance=0.015, relative=True) 23 | 24 | 25 | def test_solution(): 26 | test_utils.assert_iteration(DEMO_ID, 200, tolerance=40, relative=False) 27 | 28 | 29 | def test_frontal_area_report(): 30 | test_utils.assert_report(DEMO_ID, 'Frontal Area', 0.216328) 31 | 32 | 33 | def test_upper_area_report(): 34 | test_utils.assert_report(DEMO_ID, 'Upper Area', 0.956046) 35 | 36 | 37 | def test_cd_report(): 38 | test_utils.assert_report(DEMO_ID, 'C_d', 0.190, tolerance=0.02) 39 | 40 | 41 | def test_cl_report(): 42 | test_utils.assert_report(DEMO_ID, 'C_l', 0.357, tolerance=0.02) 43 | 44 | 45 | def test_scalar_pressure_coefficient_min(): 46 | test_utils.assert_scene_min(DEMO_ID, 'Cp Wing', 'Scalar', -1.503, 47 | tolerance=0.02) 48 | 49 | 50 | def test_scalar_pressure_kart_max(): 51 | test_utils.assert_scene_max(DEMO_ID, 'Cp Wing', 'Scalar', 0.97297) 52 | 53 | 54 | def test_vector_pressure_section_min(): 55 | test_utils.assert_scene_min(DEMO_ID, 'Vector Wing', 'Vector', 0.0) 56 | 57 | 58 | def test_vector_pressure_section_max(): 59 | test_utils.assert_scene_max(DEMO_ID, 'Vector Wing', 'Vector', 14.64) 60 | -------------------------------------------------------------------------------- /tests/test/test_demo09.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | There is no urging value in testing demo 09. 4 | ''' 5 | 6 | 7 | if __name__ == "__main__": 8 | pass 9 | -------------------------------------------------------------------------------- /tests/test/test_demo10.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_sphere_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Sphere', 1) 14 | 15 | 16 | def test_cell_count(): 17 | test_utils.assert_cell_count(DEMO_ID, 7000, tolerance=0.025) 18 | 19 | 20 | def test_scalar_min(): 21 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 99.63, 22 | tolerance=0.01, relative=True) 23 | 24 | 25 | def test_scalar_max(): 26 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 99.82, 27 | tolerance=0.01, relative=True) 28 | 29 | 30 | def test_solution(): 31 | test_utils.assert_iteration(DEMO_ID, 0) 32 | -------------------------------------------------------------------------------- /tests/test/test_demo11.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_block_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Block', 6) 14 | 15 | 16 | def test_cylinders_part_surfaces_count(): 17 | for i in range(1, 10): 18 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Cylinder%d' % i, 3) 19 | 20 | 21 | def test_subtract_part_surfaces_count(): 22 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Subtract', 15) 23 | 24 | 25 | def test_cell_count(): 26 | test_utils.assert_cell_count(DEMO_ID, 157000, tolerance=0.025) 27 | 28 | 29 | def test_scalar_min(): 30 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 0.0) 31 | 32 | 33 | def test_scalar_max(): 34 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 9.0, 35 | relative=False) 36 | 37 | 38 | def test_solution(): 39 | test_utils.assert_iteration(DEMO_ID, 0) 40 | -------------------------------------------------------------------------------- /tests/test/test_demo12.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import movie 3 | import test_utils 4 | 5 | 6 | DEMO_ID = test_utils.demo_id(__file__) 7 | MOVIE_FOLDER = 'pics_Demo12_Solution_History_And_Cameras' 8 | 9 | 10 | def test_write_summary(): 11 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 12 | 13 | 14 | def test_channel_part_surfaces_count(): 15 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Channel', 6) 16 | 17 | 18 | def test_cylinder_part_surfaces_count(): 19 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Cylinder', 3) 20 | 21 | 22 | def test_subtract_part_surfaces_count(): 23 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Subtract', 7) 24 | 25 | 26 | def test_cell_count(): 27 | test_utils.assert_cell_count(DEMO_ID, 18118) 28 | 29 | 30 | def test_solution(): 31 | test_utils.assert_iteration(DEMO_ID, 14400) 32 | test_utils.assert_time(DEMO_ID, 12.0) 33 | 34 | 35 | def test_cfl_avg_report(): 36 | test_utils.assert_report(DEMO_ID, 'CFL_avg', 0.577062) 37 | 38 | 39 | def test_cfl_max_report(): 40 | test_utils.assert_report(DEMO_ID, 'CFL_max', 8.5, 41 | tolerance=1.0, relative=False) 42 | 43 | 44 | def test_time_report(): 45 | test_utils.assert_report(DEMO_ID, 'Time', 12.0, tolerance=0, 46 | relative=False) 47 | 48 | 49 | def test_fx_report(): 50 | test_utils.assert_report(DEMO_ID, 'Fx', 0.0, tolerance=1.5e-3) 51 | 52 | 53 | def test_fy_report(): 54 | test_utils.assert_report(DEMO_ID, 'Fy', 0.0, tolerance=1.5e-3) 55 | 56 | 57 | def test_scalar_min(): 58 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', 0.0) 59 | 60 | 61 | def test_scalar_max(): 62 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 0.4, 63 | tolerance=0, relative=False) 64 | 65 | 66 | def test_pictures_count(): 67 | folder = '%s/*.png' % MOVIE_FOLDER 68 | test_utils.assert_pictures_count_in_folder(folder, 1190) 69 | 70 | 71 | def test_write_movie(): 72 | movie.write(MOVIE_FOLDER) 73 | test_utils.assert_file_size(movie.name(MOVIE_FOLDER), 6901583, 74 | tolerance=0.1, relative=True) -------------------------------------------------------------------------------- /tests/test/test_demo13.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import movie 3 | import test_utils 4 | 5 | 6 | DEMO_ID = test_utils.demo_id(__file__) 7 | MOVIE_FOLDER = 'pics_Demo13_Streamlines' 8 | 9 | 10 | def test_write_summary(): 11 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 12 | 13 | 14 | def test_cylinders_part_surfaces_count(): 15 | for cyl in ['Main', 'In', 'Out']: 16 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Cyl%s' % cyl, 3) 17 | 18 | 19 | def test_unite_part_surfaces_count(): 20 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Unite', 7) 21 | 22 | 23 | def test_cell_count(): 24 | test_utils.assert_cell_count(DEMO_ID, 14400, tolerance=0.025) 25 | 26 | 27 | def test_solution(): 28 | test_utils.assert_iteration(DEMO_ID, 200) 29 | 30 | 31 | def test_pressure_scalar_min(): 32 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Scalar', -9.5, 33 | tolerance=1.0, relative=False) 34 | 35 | 36 | def test_pressure_scalar_max(): 37 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Scalar', 14.0, 38 | tolerance=0.5, relative=False) 39 | 40 | 41 | def test_streamline_min(): 42 | test_utils.assert_scene_min(DEMO_ID, 'Scalar', 'Streamline', 0.0, 43 | tolerance=0, relative=False) 44 | 45 | 46 | def test_streamline_max(): 47 | test_utils.assert_scene_max(DEMO_ID, 'Scalar', 'Streamline', 3.0, 48 | tolerance=0, relative=False) 49 | 50 | 51 | def test_pictures_count(): 52 | folder = '%s/*.png' % MOVIE_FOLDER 53 | test_utils.assert_pictures_count_in_folder(folder, 1548) 54 | 55 | 56 | def test_write_movie(): 57 | movie.write(MOVIE_FOLDER) 58 | test_utils.assert_file_size(movie.name(MOVIE_FOLDER), 9285152, 59 | tolerance=0.1, relative=True) 60 | -------------------------------------------------------------------------------- /tests/test/test_demo14.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import re 3 | import test_utils 4 | 5 | 6 | DEMO_ID = test_utils.demo_id(__file__) 7 | 8 | 9 | def _assert_report(grid_file, report_name, expected, tolerance=0.005, 10 | relative=True): 11 | re_patt = r'Report -> %s:\s(.*)\n' % report_name 12 | actual = test_utils._float_from_sim_file(re_patt, grid_file) 13 | print('\n[assert Report] %s: ' % report_name), 14 | test_utils.assert_value(actual, expected, tolerance, relative) 15 | 16 | 17 | def _assert_summary_contents(grid_number): 18 | test_utils.assert_summary_contents_by_sim_file(_grid(grid_number)) 19 | 20 | 21 | def _gci_coefficients(): 22 | """Reconstruct GCI23 values from Plot""" 23 | num_vals = _values_from_plot(r'.*Numerical .. Y values:\s\[(.*)\]') 24 | gci_all_vals = _values_from_plot(r'.*GCI23 .. Y values:\s\[(.*)\]') 25 | gci_vals = gci_all_vals[::2] 26 | assert len(num_vals) == len(gci_vals) 27 | return [xs / x - 1.0 for xs, x in zip(gci_vals, num_vals)] 28 | 29 | 30 | def _grid(grid_number): 31 | sfs = test_utils.simulations(DEMO_ID) 32 | sf_grid = [sf for sf in sfs if re.search('Grid%03d' % grid_number, sf)] 33 | assert len(sf_grid) == 1, 'Invalid grid files: %s' % str(sfs) 34 | return sf_grid[0] 35 | 36 | 37 | def _ref_file_gci(): 38 | sim_file = test_utils.simulation(DEMO_ID) 39 | return test_utils._summary_file(sim_file) 40 | 41 | 42 | def _values_from_plot(re_patt): 43 | contents = test_utils._contents(_ref_file_gci()) 44 | s_vals = re.findall('Plot -> %s' % re_patt, contents) 45 | assert len(s_vals) < 2, 'Parsed too many chunk of values: %d' % len(s_vals) 46 | assert len(s_vals) > 0, 'Could not parse values. Found: %s' % str(s_vals) 47 | vals = [float(x) for x in s_vals[0].split(',')] 48 | return vals 49 | 50 | 51 | def _vmax(): 52 | """Analytical solution; Vmax = 0.15625 m/s""" 53 | dPdL = 1.0 54 | R = 0.025 55 | visc = 0.001 56 | return dPdL / (4 * visc) * pow(R, 2) 57 | 58 | 59 | def test_write_summary_grid_001(): 60 | _assert_summary_contents(1) 61 | 62 | 63 | def test_cylinder_part_surfaces_count(): 64 | test_utils.assert_part_surfaces_count(_grid(1), 'Cylinder', 3) 65 | 66 | 67 | def test_cell_count_grid_001(): 68 | test_utils.assert_cell_count(_grid(1), 900, 69 | tolerance=50, relative=False) 70 | 71 | 72 | def test_vmean_report_grid_001(): 73 | _assert_report(_grid(1), 'Vmean', 0.09, tolerance=0.1, relative=True) 74 | 75 | 76 | def test_vmax_report_grid_001(): 77 | _assert_report(_grid(1), 'Vmax', 0.14, tolerance=0.1, relative=True) 78 | 79 | 80 | def test_write_summary_grid_002(): 81 | _assert_summary_contents(2) 82 | 83 | 84 | def test_cell_count_grid_002(): 85 | test_utils.assert_cell_count(_grid(2), 2625, 86 | tolerance=25, relative=False) 87 | 88 | 89 | def test_vmean_report_grid_002(): 90 | _assert_report(_grid(2), 'Vmean', 0.1, tolerance=0.05, relative=True) 91 | 92 | 93 | def test_vmax_report_grid_002(): 94 | _assert_report(_grid(2), 'Vmax', 0.15, tolerance=0.05, relative=True) 95 | 96 | 97 | def test_write_summary_grid_003(): 98 | _assert_summary_contents(3) 99 | 100 | 101 | def test_cell_count_grid_003(): 102 | test_utils.assert_cell_count(_grid(3), 9275, 103 | tolerance=25, relative=False) 104 | 105 | 106 | def test_solution_grid_003(): 107 | test_utils.assert_iteration(_grid(3), 12000, tolerance=0.02, relative=True) 108 | 109 | 110 | def test_vmean_report_grid_003(): 111 | _assert_report(_grid(3), 'Vmean', 0.104, tolerance=0.02, relative=True) 112 | 113 | 114 | def test_vmax_report_grid_003(): 115 | _assert_report(_grid(3), 'Vmax', 0.156, tolerance=0.02, relative=True) 116 | 117 | 118 | def test_evaluate_gci_summary(): 119 | test_utils._remove(_ref_file_gci()) 120 | test_utils._load_sim(_grid(3), 'Demo14_EvalGCITest.java') 121 | 122 | 123 | def test_maximum_velocity_from_plot(): 124 | num_vals = _values_from_plot(r'.*Numerical .. Y values:\s\[(.*)\]') 125 | assert len(num_vals) == 21 126 | test_utils.assert_value(max(num_vals), _vmax()) 127 | 128 | 129 | def test_gci23_coefficients(): 130 | gci23_coeffs = _gci_coefficients() 131 | test_utils.assert_value(min(gci23_coeffs), 0.0005, 132 | tolerance=0.0005, relative=False) 133 | test_utils.assert_value(max(gci23_coeffs), 0.06, 134 | tolerance=0.02, relative=False) 135 | -------------------------------------------------------------------------------- /tests/test/test_demo15.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import movie 3 | import pytest 4 | import test_utils 5 | 6 | 7 | DEMO_ID = test_utils.demo_id(__file__) 8 | MOVIES_FOLDERS = { 9 | 'pics_Demo15_Run_DES_Structures': 1179880, 10 | 'pics_Demo15_Run_DES_Turbulent_Viscosity_Ratio': 2871033, 11 | 'pics_Demo15_Run_DES_Velocity': 2997786, 12 | 'pics_Demo15_Run_DES_Wall_Y+': 2408223, 13 | } 14 | MOVIES_IDS = ['-'.join(x.split('_')[4:]) for x in MOVIES_FOLDERS] 15 | 16 | 17 | def des_sim(): 18 | return sim_files()[2] 19 | 20 | 21 | def ss_sim(): 22 | return sim_files()[0] 23 | 24 | 25 | def sim_files(): 26 | sfs = test_utils.simulations(DEMO_ID) 27 | assert len(sfs) == 3, 'Invalid files: %s' % str(sfs) 28 | return sfs 29 | 30 | 31 | def test_write_summary_ss(): 32 | test_utils.assert_summary_contents_by_sim_file(ss_sim()) 33 | 34 | 35 | def test_unite_part_surfaces_count(): 36 | test_utils.assert_part_surfaces_count(ss_sim(), 'Unite', 11) 37 | 38 | 39 | def test_cell_count_ss(): 40 | test_utils.assert_cell_count(ss_sim(), 17000, 41 | tolerance=2000, relative=False) 42 | 43 | 44 | def test_solution_ss(): 45 | test_utils.assert_iteration(ss_sim(), 100, tolerance=0.2, relative=True) 46 | 47 | 48 | def test_pressure_drop_report_ss(): 49 | test_utils.assert_report(ss_sim(), 'Pressure Drop', 8.0, 50 | tolerance=0.25, relative=False) 51 | 52 | 53 | def test_pressure_scalar_min_ss(): 54 | test_utils.assert_scene_min(ss_sim(), 'Pressure', 'Scalar', -11.1, 55 | tolerance=0.1, relative=True) 56 | 57 | 58 | def test_pressure_scalar_max_ss(): 59 | test_utils.assert_scene_max(ss_sim(), 'Pressure', 'Scalar', 13.7, 60 | tolerance=0.02, relative=True) 61 | 62 | 63 | def test_vector_min_ss(): 64 | test_utils.assert_scene_min(ss_sim(), 'Vector', 'Vector', 0.0, 65 | tolerance=0.015) 66 | 67 | 68 | def test_vector_max_ss(): 69 | test_utils.assert_scene_max(ss_sim(), 'Vector', 'Vector', 5.4, 70 | tolerance=0.02) 71 | 72 | 73 | def test_write_summary_des(): 74 | test_utils.assert_summary_contents_by_sim_file(des_sim()) 75 | 76 | 77 | def test_cell_count_des(): 78 | test_utils.assert_cell_count(des_sim(), 97500, 79 | tolerance=0.02, relative=True) 80 | 81 | 82 | def test_solution_des(): 83 | test_utils.assert_iteration(des_sim(), 18000) 84 | test_utils.assert_time(des_sim(), 0.3) 85 | 86 | 87 | # Too sensitive 88 | # def test_pressure_drop_report_des(): 89 | # test_utils.assert_report(des_sim(), 'Pressure Drop', 47.0, 90 | # tolerance=0.05, relative=True) 91 | 92 | 93 | def test_cfl_avg_report_des(): 94 | test_utils.assert_report(des_sim(), 'CFL_avg', 0.2, 95 | tolerance=0.1, relative=False) 96 | 97 | 98 | def test_cfl_max_report_des(): 99 | test_utils.assert_report(des_sim(), 'CFL_max', 1.6, 100 | tolerance=0.50, relative=False) 101 | 102 | 103 | def test_time_report_des(): 104 | test_utils.assert_report(des_sim(), 'Time', 0.3, tolerance=0.0, 105 | relative=False) 106 | 107 | 108 | # Too sensitive 109 | # def test_p1_report_des(): 110 | # test_utils.assert_report(des_sim(), 'P1', 23.5, 111 | # tolerance=0.05, relative=True) 112 | 113 | 114 | def test_vector_min_des(): 115 | test_utils.assert_scene_min(des_sim(), 'Vector', 'Vector', 0.0, 116 | tolerance=0.015, relative=False) 117 | 118 | 119 | def test_vector_max_des(): 120 | test_utils.assert_scene_max(des_sim(), 'Vector', 'Vector', 6.0, 121 | tolerance=0.05, relative=True) 122 | 123 | 124 | def test_pictures_count(): 125 | for movie_folder in MOVIES_FOLDERS: 126 | folder = '%s/*.png' % movie_folder 127 | test_utils.assert_pictures_count_in_folder(folder, 599) 128 | 129 | 130 | def test_write_movies(): 131 | for movie_folder in MOVIES_FOLDERS: 132 | movie.write(movie_folder) 133 | 134 | 135 | @pytest.mark.parametrize('movie_folder', MOVIES_FOLDERS.keys(), ids=MOVIES_IDS) 136 | def test_movie_size(movie_folder): 137 | file_size = MOVIES_FOLDERS[movie_folder] 138 | print('Movie folder: %s' % movie_folder) 139 | test_utils.assert_file_size(movie.name(movie_folder), file_size, 140 | tolerance=0.1) 141 | -------------------------------------------------------------------------------- /tests/test/test_demo16.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import test_utils 3 | 4 | 5 | DEMO_ID = test_utils.demo_id(__file__) 6 | 7 | 8 | def test_write_summary(): 9 | test_utils.assert_summary_contents_by_demo(DEMO_ID) 10 | 11 | 12 | def test_domain_part_surfaces_count(): 13 | test_utils.assert_part_surfaces_count(DEMO_ID, 'Domain', 3) 14 | 15 | 16 | def test_cell_count(): 17 | test_utils.assert_cell_count(DEMO_ID, 1000, tolerance=0, relative=False) 18 | 19 | 20 | def test_solution(): 21 | test_utils.assert_iteration(DEMO_ID, 2140) 22 | test_utils.assert_time(DEMO_ID, 0.0200081) 23 | -------------------------------------------------------------------------------- /tests/test/test_simulation_assistants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import glob 3 | import os 4 | import test_utils 5 | 6 | 7 | BLOCK_MESHER = 'SimAssistantBlockMesher' 8 | 9 | 10 | def _assert_cell_count(sim_file, expected): 11 | test_utils.assert_cell_count(argument=sim_file, expected=expected, 12 | tolerance=0, relative=False) 13 | 14 | 15 | def _clean_up(base_name): 16 | 17 | os.chdir(test_utils._test_home()) 18 | 19 | files = glob.glob('%s*.*' % os.path.splitext(base_name)[0]) 20 | files.append(test_utils._summary_file(base_name)) 21 | test_utils._remove([f for f in files if not _is_java(f)]) 22 | 23 | 24 | def _is_java(f): 25 | return os.path.splitext(f)[-1] == '.java' 26 | 27 | 28 | def _new_sim(base_name): 29 | _clean_up(base_name) 30 | test_utils._new_sim('%sTest.java' % base_name) 31 | 32 | 33 | def test_block_mesher_macro_play(): 34 | _new_sim(BLOCK_MESHER) 35 | assert os.path.exists('%s.sim' % BLOCK_MESHER) 36 | assert os.path.exists('%s_2D.sim' % BLOCK_MESHER) 37 | 38 | 39 | def test_block_mesher_cell_count(): 40 | i, j, k = 4, 7, 8 41 | _assert_cell_count('%s.sim' % BLOCK_MESHER, i * j * k) 42 | _assert_cell_count('%s_2D.sim' % BLOCK_MESHER, i * j) 43 | -------------------------------------------------------------------------------- /tests/test/test_simulation_tools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import re 4 | import test_utils 5 | 6 | 7 | CONVERGENCE_CHECKER = 'SimToolImplicitUnsteadyConvergenceChecker' 8 | MESH_METRICS = 'SimToolMeshMetrics' 9 | 10 | SIM_TOOL = { 11 | 12 | CONVERGENCE_CHECKER: 'SimToolConvergenceChecker', 13 | 14 | MESH_METRICS: MESH_METRICS, 15 | 16 | } 17 | 18 | 19 | def _contents_sim_tool(key, mesh_metric): 20 | 21 | ref_file = '%s_%s.ref' % (SIM_TOOL[mesh_metric], key) 22 | 23 | return test_utils._contents(ref_file) 24 | 25 | 26 | def _load_demo(demo_id, macro_name): 27 | 28 | os.chdir(test_utils._test_home()) 29 | 30 | sim_file = test_utils.simulation(demo_id) 31 | assert os.path.exists(sim_file), 'Demo %d needs to be run first' % demo_id 32 | 33 | test_utils._load_sim(sim_file, '%sTest.java' % macro_name) 34 | 35 | 36 | def test_convergence_checker(): 37 | 38 | _load_demo(15, CONVERGENCE_CHECKER) 39 | 40 | original = _contents_sim_tool('0_Original', CONVERGENCE_CHECKER) 41 | created = _contents_sim_tool('1_Artifacts_Created', CONVERGENCE_CHECKER) 42 | removed = _contents_sim_tool('2_Artifacts_Removed', CONVERGENCE_CHECKER) 43 | 44 | assert not re.findall('Convergence Checker', removed) 45 | assert original == removed 46 | 47 | expected = 6 * 2 # Number of Reports x 2 48 | fmt = '%s -> Convergence Checker' 49 | 50 | assert expected == len(re.findall(fmt % 'Monitor', created)) 51 | assert expected == len(re.findall(fmt % 'Plot', created)) 52 | 53 | 54 | def test_mesh_metrics(): 55 | 56 | _load_demo(5, MESH_METRICS) 57 | 58 | metric_example = 'Face Validity Part Surfaces' 59 | 60 | original = _contents_sim_tool('0_Original', MESH_METRICS) 61 | created = _contents_sim_tool('1_Artifacts_Created', MESH_METRICS) 62 | removed = _contents_sim_tool('2_Artifacts_Removed', MESH_METRICS) 63 | 64 | assert not re.findall(metric_example, original) 65 | assert re.findall(metric_example, created) 66 | assert original == removed 67 | 68 | plots_created = 4 69 | expected = plots_created * 2 + 2 # The last term is the included ones 70 | assert expected == len(re.findall('Plot -> ', created)) 71 | assert plots_created == len(re.findall('Function:', created)) 72 | assert plots_created == len(re.findall('Bins:', created)) 73 | -------------------------------------------------------------------------------- /tests/tests_definition.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Basic definitions for the demos. 4 | 5 | @author: Fabio Kasper 6 | """ 7 | from pathlib import Path 8 | from dataclasses import dataclass 9 | 10 | 11 | class Case: 12 | 13 | @property 14 | def name(self) -> str: 15 | return self.__class__.__name__ 16 | 17 | 18 | @dataclass 19 | class Macro(Case): 20 | macro_name: str 21 | 22 | @property 23 | def java_file(self) -> str: 24 | return f'{self.macro_name}.java' 25 | 26 | @property 27 | def name(self) -> str: 28 | return f'{self.macro_name}' 29 | 30 | def java_path(self, testhome: Path) -> Path: 31 | path = testhome.joinpath(self.java_file) 32 | if not path.is_file(): 33 | raise OSError(f'not a file: {path!r}') 34 | return path 35 | 36 | 37 | @dataclass 38 | class Bug(Macro): 39 | load_demo: str 40 | 41 | 42 | @dataclass 43 | class Demo(Case): 44 | id: int # demo number 45 | np: int # core count 46 | batch: bool # run in batch? 47 | files: list[str] # list of support files 48 | 49 | @property 50 | def name(self) -> str: 51 | return f'{super().name}{self.id:02d}' 52 | 53 | def java_files(self, demohome: Path) -> list[Path]: 54 | """Return a list of JAVA files files related to this demo""" 55 | files = demohome.glob(f'Demo{self.id}_*.java') 56 | if not files: 57 | raise OSError(f'no JAVA files found for {self}') 58 | return list(files) 59 | 60 | def running_files(self, demohome: Path, datahome: Path) -> list[Path]: 61 | """Return a list of necessary files to run this demo""" 62 | paths = self.java_files(demohome) 63 | for file in self.files: 64 | path = datahome.joinpath(file) 65 | paths.append(path) 66 | if not path.is_file(): 67 | raise OSError(f'invalid {path=}') 68 | return sorted(paths) 69 | 70 | 71 | class SimAssistant(Macro): 72 | ... 73 | 74 | 75 | class SimTool(Macro): 76 | ... 77 | 78 | 79 | CASES = [ # A list defining all cases 80 | #----------- 81 | # Demos 82 | #----------- 83 | Demo(id=1, np=2, batch=True, files=[]), 84 | Demo(id=2, np=2, batch=True, files=[]), 85 | Demo(id=3, np=2, batch=True, files=[]), 86 | Demo(id=4, np=1, batch=True, files=['radial_impeller.stp']), 87 | Demo(id=5, np=6, batch=True, files=['LegoKart.x_b']), 88 | # Demo 6 is bypassed 89 | Demo(id=7, np=4, batch=True, files=[]), 90 | Demo(id=8, np=6, batch=True, files=['WING.x_b', 'wingCams.txt']), 91 | # Demo 9 is bypassed 92 | Demo(id=10, np=1, batch=True, files=[]), 93 | Demo(id=11, np=1, batch=True, files=[]), 94 | Demo(id=12, np=2, batch=True, files=[]), 95 | Demo(id=13, np=2, batch=True, files=[]), 96 | Demo(id=14, np=1, batch=True, files=[]), 97 | Demo(id=15, np=8, batch=True, files=['TableFromPeriodicRun.csv']), 98 | Demo(id=16, np=4, batch=True, files=[]), 99 | #----------- 100 | # Bugs 101 | #----------- 102 | Bug(load_demo=1, macro_name='BugCreateStreamlineSceneTest'), 103 | #----------- 104 | # Simulation assistants 105 | #----------- 106 | SimAssistant(macro_name='SimAssistantBlockMesherTest'), 107 | #----------- 108 | # Simulation tools 109 | #----------- 110 | SimTool(macro_name='SimToolImplicitUnsteadyConvergenceCheckerTest'), 111 | SimTool(macro_name='SimToolMeshMetricsTest'), 112 | ] 113 | 114 | 115 | def filtered_cases(cases: list[Case], class_type: Case) -> list[Case]: 116 | return list(filter(lambda x: isinstance(x, class_type), cases)) 117 | 118 | 119 | def get_demo(number: int) -> Demo: 120 | demos = filtered_cases(CASES, Demo) 121 | ids = [demo.id for demo in demos] 122 | try: 123 | if int(number) in ids: 124 | return demos[ids.index(int(number))] 125 | except Exception: 126 | ... # Do nothing 127 | raise ValueError(f'invalid demo {number = }') 128 | 129 | 130 | def main(): 131 | """Local debug""" 132 | testhome = Path(__file__).parent.joinpath('macros') 133 | 134 | demo = get_demo(1) 135 | print(f'{demo=}') 136 | print(f'{demo.name=}') 137 | 138 | print(filtered_cases(CASES, Bug)[0].java_path(testhome)) 139 | print(filtered_cases(CASES, SimAssistant)[0].name) 140 | 141 | 142 | if __name__ == "__main__": 143 | main() 144 | -------------------------------------------------------------------------------- /wiki/NB_Custom_SpaceBraces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/wiki/NB_Custom_SpaceBraces.png -------------------------------------------------------------------------------- /wiki/NB_FormattingComments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/wiki/NB_FormattingComments.png -------------------------------------------------------------------------------- /wiki/NB_FormattingGeneral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/wiki/NB_FormattingGeneral.png -------------------------------------------------------------------------------- /wiki/NB_MembersOrdering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/wiki/NB_MembersOrdering.png -------------------------------------------------------------------------------- /wiki/NB_OnSaveSettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/frkasper/MacroUtils/bf6edf3ebe5d37c42105de9e154155471bddeebb/wiki/NB_OnSaveSettings.png --------------------------------------------------------------------------------