|
[Sponsors] |
October 1, 2013, 11:12 |
Java with CCM+
|
#1 |
Member
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 75
Rep Power: 15 |
Hello,
I am trying to write some Java script for some automation of tasks. I am totally new in this, so I guess the question will sound trivial to some. I want ,for example, to erase all the chemical species which are loaded in my continuum. To erase a particular one, I have the following script: Simulation simulation_0 = getActiveSimulation(); PhysicsContinuum physicsContinuum_0 = ((PhysicsContinuum)simulation_0.getContinuumManage r().getContinuum("continuum")); MultiComponentGasModel multiComponentGasModel_0 = physicsContinuum_0.getModelManager().getModel(Mult iComponentGasModel.class); GasMixture gasMixture_0 = ((GasMixture) multiComponentGasModel_0.getMixture()); GasComponent gasComponent_0 = ((GasComponent) gasMixture_0.getComponents().getComponent("Chemica l_1")); gasMixture_0.getComponents().deleteMixtureComponen ts(new NeoObjectVector(new Object[] {gasComponent_0})); So that it will erase the gasComponent_0 defined by chemical_1 How can I simply select all the gasComponent and put them in the new object to then erase them? Moreover, without knowing the name of the species (chemical_1), how can I selection the gasComponent on a specific position on the array? I tried with something like ((GasComponent) gasMixture_0.getComponents().getComponent([1])); but without success. If I can do that, I then can loop and erase one by on all the species. Thank you for your help |
|
October 1, 2013, 13:56 |
|
#2 |
Senior Member
Ryne Whitehill
Join Date: Aug 2009
Posts: 312
Rep Power: 19 |
edit: see comment below, much better solution
Last edited by rwryne; October 2, 2013 at 14:12. |
|
October 2, 2013, 03:32 |
|
#3 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
This is untested, but should give you ideas about another approach. You may wish to add try/catch in various places to improve the robustness. Code:
import star.common.PhysicsContinuum; import star.common.Simulation; import star.common.StarMacro; import star.material.MixtureComponentManager; import star.material.MultiComponentGasModel; /** * Erase all species attached to given physics continuum */ public class EraseSpecies extends StarMacro { private Simulation sim_ = null; private static final String PHYSICS_NAME = "continuum"; /** The entry point for a StarMacro. */ @Override public void execute() { sim_ = this.getActiveSimulation(); PhysicsContinuum physics = (PhysicsContinuum) sim_.getContinuumManager().getContinuum(PHYSICS_NAME); MixtureComponentManager gasMixMgr = physics.getModelManager() .getModel(MultiComponentGasModel.class).getMixture().getComponents(); gasMixMgr.deleteChildren(gasMixMgr.getComponents()); } } |
||
October 2, 2013, 07:19 |
|
#4 |
Member
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 75
Rep Power: 15 |
Hello Rwryne and Olessen
Thanks a lot for your answers I have tested the Olessen proposal, and it works perfectly. I have some questions about it, in order to fully understand it myself: 1/ You are calling the class 'MixtureComponentManager' How do you know the existence of this class? Is there somewhere a list of all the available classes available in CCM+? 2/ Before starting the StarMacro, you are doing this initialization: private Simulation sim_ = null; private static final String PHYSICS_NAME = "continuum"; **************************** If I understand well, you are a/ clearing sim_ : Is it important to all time do so before starting a java script? b/ declaring the string varaible Physic_name defined by the continuum. If there are several continuum defined, how does this will work? **************************** /** The entry point for a StarMacro. */ @Override public void execute() etc.... ******************* c/ What is the use of @Override ? Thanks a lot for your explanations and your help |
|
October 4, 2013, 03:27 |
|
#5 | ||||
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Quote:
Quote:
Code:
ContinuumManager contMgr = sim_.getContinuumManager(); for (PhysicsContinuum cont: contMgr.getObjectsOf(PhysicsContinuum.class)) { ModelManager mdlMgr = cont.getModelManager() try { MixtureComponentManager gasMixMgr = mdlMgr .getModel(MultiComponentGasModel.class).getMixture().getComponents(); gasMixMgr.deleteChildren(gasMixMgr.getComponents()); } catch (Exception ex) {} } Quote:
|
|||||
October 4, 2013, 11:44 |
|
#6 |
Member
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 75
Rep Power: 15 |
Thank you Olesen for your valuable answers and info about javadocs, this is really helpful.
It allowed me to go on with some script, but am facing one more problem: I am now working on passive scalar, where I wish to collect all of them. From what I've read from the javadocs (part PassiveScalarManager), and from the previous experience from the species collection, I wrote the following: Code:
import passivescalar.*; .. PassiveScalarMaterial passiv= physics.getModelManager().getModel(PassiveScalarModel.class) .getPassiveScalarManager().getPassiveScalarMaterials(); incompatible type: found: java.util.Collection<star.passivescalar.PassiveSca larMaterial> required: star.passivesscalar.PassiveScalarMaterial Yet, when I am applying the above script in order to collect a specific passive scalar, this will work: Code:
.. PassiveScalarMaterial passiv= physics.getModelManager().getModel(PassiveScalarModel.class) .getPassiveScalarManager().getPassiveScalarMaterial("PassSc1"); What am I doing wrong? Thanks again for your help |
|
October 4, 2013, 11:57 |
|
#7 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
If you try with the proper assignment, I'm convinced you can resolve the error: Code:
Collection<PassiveScalarMaterial> matlLst = physics.getModelManager().getModel(PassiveScalarModel.class) .getPassiveScalarManager().getPassiveScalarMaterials(); |
||
October 10, 2013, 09:42 |
|
#8 |
Member
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 75
Rep Power: 15 |
Hello Olesen,
A small reply to thanks you for all the hints and help your provided me, it was really useful to start scripting. It's going quite well so far. Thanks again |
|
Tags |
ccm+, java |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
problem when imported geometry from 3D CAD to star ccm, | TAREK GANAT | STAR-CCM+ | 1 | May 21, 2013 23:15 |
Macro to access java files in sub-directory | abraum | STAR-CCM+ | 3 | July 11, 2012 03:46 |
Fluent Vs Star CCM | firda | Main CFD Forum | 3 | February 26, 2011 03:51 |
error in star ccm | maurizio | Siemens | 3 | October 16, 2007 06:17 |
Getting OpenFOAM to coexist with an existing JAVA VM | nik777 | OpenFOAM Installation | 5 | February 22, 2007 08:21 |