CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Calling multiple simulations in Java (https://www.cfd-online.com/Forums/star-ccm/122831-calling-multiple-simulations-java.html)

frownless August 29, 2013 02:49

Calling multiple simulations in Java
 
Hi guys,
I need to use a macro to work with properties of two separate simulations. I know I can identify one of them (simulation_0) through getActiveSimulation() , but is there any other way to identify simulations through a path or a file name?

Thanks in Advance!

Roman August 29, 2013 03:06

If your other simulations are active you could use SelectSimulationDialog class in StarCCM API.

You can find documentation in STAR-install-dir/star/lib/doc/client/html/star/coremodule/ui/SelectSimulationDialog.html

If you are trying to modify several simulations with the same macro why not just write a simple bash script/ bat script (depending if you have linux or windows enviroment) to launch simulations and run your macro?

frownless September 3, 2013 01:05

Thanks Roman! This is the area I needed to be looking in, I ended up going down the SimulationProcessObject path. Apologies for my ignorance, I am new to using star ccm, what could I do with batch scripts and what would I write in one? I use windows.
Thanks again for your help!

Roman September 3, 2013 04:31

Glad you found a solution to your problem! Actually, I mostly used star with linux, however batch scripts in windows should do the same tricks.

I imagine what you are trying to do is to apply the same java macro to several simulations, right? I would recommend to take alook at this thread:

http://www.cfd-online.com/Forums/sta...rting-run.html

frownless September 3, 2013 05:55

Thanks for the link, that is some pretty cool stuff! Unfortunately what I am trying to do is run two star ccm files simultaneously in a time unsteady simulation. Sort of a hand made cosimulation because I am doing some other funky things in the macro that I need to modulate between the files.
I hoped I could do something like this:
"
Simulation simulation_0 =
getActiveSimulation();
SimulationProcessObject simulation1a = new SimulationProcessObject(path1);
Simulation simulation_1 = simulation1a.getSimulation();
Solution solution_0 = simulation_0.getSolution();
Solution solution_1 = simulation_1.getSolution();
"
And then pull info from both, do some maths, send things back to both and run a time step on both. When I run the macro it loads my second sim file at path1 but then comes up with the error: "error: Macro run-time error: null" Which I assume is it saying it doesnt like flicking between sims. Is there some better way to handle trying to run both of these sims at once? Since it is unsteady and time step at a time, I can alternate between the two if star CCM is less likely to mind that. Any Ideas?
Thanks for helping me out with this!

Roman September 3, 2013 06:12

Ah! This sound like really exiting stuff! I think there is a slightly easier way to work around this in Star.

Take a look at the manual under Interacting with CAD/CAE Products -> Co-Simulation with STAR-CCM+

That should at least get you started in the right direction, you can use Field Functions in the leading and lagging simulation to calculate and report values you want to calculate.

frownless September 3, 2013 06:36

Looks like I am going to have to have a look in to this Co Simulation stuff. I was trying to avoid it but it looks like Star normally can only handle one active simulation at a time. Thanks Roman, I will hit you back in a couple of days and tell you if it worked or not. Have a good one!

Jimmy123 September 9, 2013 12:11

Hello, it seems like we want to do about the same things. Did you get it to work as you wanted by using co-simulation? In my case, I have not managed to get it to work with co-simulation as I wanted and I don’t know how to write a macro that handles 2 simulations.

I’m bad at java, so I mostly record things and maybe write a for-loop at most. But this is how I try to solve a similar problem. I hope it can give you some ideas if you are stuck!

I have 1 macro for each simulation that at least seems promising... To exchange data between the simulations I use File->Export… and File->Import (recorded with a macro). Then in order to get them to wait on each other, I have included the code below that checks if the exported file with boundary data have been changed (in the other macro it look for changes in a FLUIDmapdata.ccm instead). If the file have been updated, the loop breaks and the macro can continue.

The pause part below works, but I have some issues with the imported files that I hope to fix tonight.

long Oldfilversion=0; //in the beginning of the macro

while (true){
File filversion = new File("/home /Jimmy123/triggerfile.trn"); //triggerfile.trn should be some small junkfile that you export AFTER the real file. If you use the actual file, it might be imported before it is written becuase I noticed that lastmodified() changes as soon as the file is started to be written. I tried to wait for tryLock() to be true as well for the real file. But that did not work either.
long Newfilversion=filversion.lastModified();
if (Newfilversion != Oldfilversion){
Oldfilversion=Newfilversion;
break;
} //the code below is just for a small pause before next check.
else {
try {
Thread.sleep(1000);
}
catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}


}

Alex C. September 9, 2013 13:59

As brought by Roman, I also suggest you run in batch mode (assuming windows...) You could then call starccm+ from the cmd promt and use a batch file (.bat) to automate multiple call. Assuming you're cmd prompt path is set to the folder where you're simulation is saved :

starccm+ "my_first_simulation.sim" -batch
starccm+ "my_second_simulation.sim" -batch

You can include a java macro to include automated feature (like meshing for example, or control over the boundary conditions)

starccm+ "my_second_simulation.sim" -batch "my_macro.java"

You can specify a lot a option. The one I use the most is number of process to run to enable multi-threading. (In the examples 3 parallel process are launched)

starccm+ "my_second_simulation.sim" -np 3 -batch "my_macro.java"

frownless September 10, 2013 05:53

Yeah Jimmy I have spent the week looking in to it and I think Co-Simulation is far too narrow for what I am doing here.. I am going to have to find a way to run two simulations simultaneously.. The batch idea is interesting. Is this just to run the code outside of star ccm? Its just that because the simulations depend on each other so heavily I need to be able for them to interact at every time step. Is there any java for changing the active simulation (such as simulation_0.setActiveSimulation()) or something like that?
Thanks for the help everybody!

Jimmy123 September 12, 2013 19:37

Hi again,
Steve (the great CD-adapco support) told me that if you want to control both simulations from the same macro you can write:

///////////////////////////////////////////////////////////////////
Simulation sim1 = getActiveSimulation();

Simulation sim2 = new Simulation("G:/StarCCM/sim2.sim");

sim1.getSimulationIterator().step(1);
sim2.getSimulationIterator().step(1);
sim2.close();
///////////////////////////////////////////////////////////////////

But I think (since my macros are made mostly of recorded text) that it will be easier to write two macros, and use a trigger (for example as I described in my previous post) that decides when to import new data.

Basically, just to clarify, I do as described below. Before each "Step" I also do some changes that depend on the time.
Simulation 1 _______________ Simulation 2
1: Step ____________________ wait
2: export ____--triggers->_____ import and map
3: wait _____________________ Step
4: import and mapp _<-triggers--_ export
5: Back to 1. ________________ Back to 1.


All times are GMT -4. The time now is 16:43.