CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Perform several simulations automatically (https://www.cfd-online.com/Forums/star-ccm/129175-perform-several-simulations-automatically.html)

guste933 January 30, 2014 06:17

Perform several simulations automatically
 
I am working on a project where I want to be able to loop the simulation process, i.e. set up the simulation properly with some design parameters, and then creating some automatic parameter study. Is there some way of doing this in STAR-CCM+, for example writing a macro?

Would appreciate the help greatly.

ping January 31, 2014 07:03

i suggest you do the help tutorials on macros first then you will understand the code below a little better

a field function can also be used - easier than a macro is some ways

you could also use optimate in simple design exploration mode - the easiest way, but you may not have a license for this

save the text below to a file called run_batch_inlets.java

// STAR-CCM+ macro: run_batch_inlets.java
package macro;

// Runs the current .sim with a range of inlet values, and saves each result to a different .sim file

import java.util.*;

import star.common.*;
import star.base.neo.*;
import star.flow.*;
import star.vis.*;

public class run_batch_inlets extends StarMacro {

public void execute() {

double Yin ;
int i;
String str1, str2;

// start of real code

Simulation simulation_0 =
getActiveSimulation();

StepStoppingCriterion stepStoppingCriterion_0 =
((StepStoppingCriterion) simulation_0.getSolverStoppingCriterionManager().g etSolverStoppingCriterion("Maximum Steps"));

stepStoppingCriterion_0.setMaximumNumberSteps(10);


i = 0;

for ( Yin = -1.0; Yin >= -11.0; Yin = Yin - 2.0) {

i = i + 1;

Region region_0 =
simulation_0.getRegionManager().getRegion("subdoma in-1");

Boundary boundary_0 =
region_0.getBoundaryManager().getBoundary("boundar y1");

VelocityProfile velocityProfile_0 =
((VelocityProfile) boundary_0.getValues().get(VelocityProfile.class)) ;

((ConstantVectorProfileMethod) velocityProfile_0.getMethod()).getQuantity().setVe ctor(new DoubleVector(new double[] {0.0, Yin, 0.0}));

Solution solution_0 = simulation_0.getSolution();

solution_0.clearSolution();

simulation_0.getSimulationIterator().run(true);


str1 = Integer.toString(i);
// pad on left with zeros
str1 = "0000000".substring(0,4 - str1.length()) + str1;

str2 = "part2_run_" + str1 + ".sim" ;

simulation_0.saveState(resolvePath(str2));


str2 = "part2_run_" + str1 + ".png" ;

Scene scene_0 = simulation_0.getSceneManager().getScene("Scalar Scene 1");

scene_0.printAndWait(resolvePath(str2), 1, 1198, 816);

}
}
}

guste933 January 31, 2014 07:46

Thanks for the response. I guess my thought process wasnt entirely clear at the moment of the post. I have been looking in the tutorial guide and can see that it is clearly possible to run several simulations within STAR-CCM+ automatically. However, my goals have changed somewhat since then.

What I actually in the end want to achieve is to perform a CFD parameter study on a geometry that I have created in CATIA v5 R21. So I figured that I can write a VBA macro in Microsoft Visual basic which alters my parameters in CATIA based on an excel sheet, and then exports a geometry file for each set of parameters. I figure that I can then basically run a pre-determined macro file which imports each geometry file, runs the desired simulation and produces the desired outputs. All of this I want to do automatically, so basically looping the following:

-Change parameters
-Export geometry from CATIA

followed by:
-Run java macro file in STAR-CCM+ to perform simulations on all geometries created

Can I do this using VBA script solely? If so, how? If not, what may be another way of doing it?

guste933 January 31, 2014 07:48

BTW, I know how to do the CATIA-related parts of the above post, Im more wondering about running the java macro automatically.

ping January 31, 2014 07:55

all very possible either in vba or in star-ccm+ using java since java can talk to the os of course.
if you have the cad client for catia it is easier since you can define parameters in catia which are now visible as star-ccm+ design parameters and can be driven by a macro or even easier by optimate - if you have optimate+ then you can do real optimization with the cfd results driving the cad changes in catia.

linyanx October 25, 2018 12:03

Quote:

Originally Posted by guste933 (Post 472783)
BTW, I know how to do the CATIA-related parts of the above post, Im more wondering about running the java macro automatically.

Hi,
Have you finally achieve this? Curious about that:)
I think one of the viable ways is to use a platform that can call either STAR-CCM and CATIA, like Netbean for example.
Best,
Linyan


All times are GMT -4. The time now is 04:22.