CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > STAR-CCM+

Java with CCM+

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   October 1, 2013, 10:12
Question Java with CCM+
  #1
Member
 
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 71
Rep Power: 5
crevoise is on a distinguished road
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
crevoise is offline   Reply With Quote

Old   October 1, 2013, 12:56
Default
  #2
Super Moderator
 
Ryne Whitehill
Join Date: Aug 2009
Posts: 313
Rep Power: 9
rwryne is on a distinguished road
edit: see comment below, much better solution

Last edited by rwryne; October 2, 2013 at 13:12.
rwryne is offline   Reply With Quote

Old   October 2, 2013, 02:32
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Quote:
Originally Posted by crevoise View Post
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

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());
    }
}
olesen is offline   Reply With Quote

Old   October 2, 2013, 06:19
Default
  #4
Member
 
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 71
Rep Power: 5
crevoise is on a distinguished road
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
crevoise is offline   Reply With Quote

Old   October 4, 2013, 02:27
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Quote:
Originally Posted by crevoise View Post
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+?
The STARCCM installation contains the javadocs for its API. The descriptions are not exactly complete, but should provide you with enough information. The subdirectory: star/lib/doc/client/html/

Quote:
a/ clearing sim_ : Is it important to all time do so before starting a java script?
This is not needed, but I think it is good style.

Quote:
b/ declaring the string varaible Physic_name defined by the continuum.
If there are several continuum defined, how does this will work?
This only works for the case that you posed. If the continuum is named differently, or if there are more of them that you want to clear, you'll have a problem. If you want to loop over all possible physics continua, you'd need something like this:

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)
    {}
}
Note that we stuff the interesting bits inside of a try/catch grouping. This makes it failsafe for continua that are not actually gas mixtures.


Quote:
@Override
public void execute() etc....

*******************
c/ What is the use of @Override ?
This somewhat pedantic. It works equally well without this annotation. However, the StarMacro already provides an empty 'execute' method that we are overriding and the @Override annotation documuments this.
olesen is offline   Reply With Quote

Old   October 4, 2013, 10:44
Default
  #6
Member
 
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 71
Rep Power: 5
crevoise is on a distinguished road
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();
Which returns:
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");
In the javadoc, it is yet specified that the collection .getPassiveScalarMaterials is available.

What am I doing wrong?
Thanks again for your help
crevoise is offline   Reply With Quote

Old   October 4, 2013, 10:57
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Quote:
Originally Posted by crevoise View Post
I wrote the following:
Code:
import passivescalar.*;
.. 
PassiveScalarMaterial passiv=
physics.getModelManager().getModel(PassiveScalarModel.class)
.getPassiveScalarManager().getPassiveScalarMaterials();
Which returns:
incompatible type:
found: java.util.Collection<star.passivescalar.PassiveSca larMaterial>
required: star.passivesscalar.PassiveScalarMaterial
Like the error message states, you are trying to assign things incorrectly. It's not much different than trying to assign a String to a double, for example.

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();
You can then go on and do other useful things with this collection of materials. You can, of course, just get a single material by name too. That is what the "getPassiveScalarMaterial(String name)" method seems to provide.
olesen is offline   Reply With Quote

Old   October 10, 2013, 08:42
Default
  #8
Member
 
Join Date: Oct 2011
Location: Thessaloniki, Greece
Posts: 71
Rep Power: 5
crevoise is on a distinguished road
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
crevoise is offline   Reply With Quote

Old   October 12, 2013, 11:24
Default
  #9
New Member
 
cfdguy's Avatar
 
Join Date: Mar 2009
Location: Brazil
Posts: 16
Rep Power: 8
cfdguy is on a distinguished road
Dear all,

Have you visited MacroHut already?
__________________
Cheers,
cfdguy

** Every rose has its thorn **

PS: Please watch this Youtube channel.
cfdguy is offline   Reply With Quote

Reply

Tags
ccm+, java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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 22:15
Macro to access java files in sub-directory abraum STAR-CCM+ 3 July 11, 2012 02:46
Fluent Vs Star CCM firda Main CFD Forum 3 February 26, 2011 03:51
error in star ccm maurizio CD-adapco 3 October 16, 2007 05:17
Getting OpenFOAM to coexist with an existing JAVA VM nik777 OpenFOAM Installation 5 February 22, 2007 08:21


All times are GMT -4. The time now is 01:29.