User Tools

Site Tools


soft:simeo:private:the_simeo_script_mode_in_java_to_run_background_simulations

The Simeo script mode (in java) to run background simulations

The models in Simeo are hosted in modules. When launching Simeo in interactive mode, the user first creates a project and chooses which module he wants to use. An initialization stage follows to build an initial scene (e.g. an empty 100 x 100m scene, or a new scene with plants inside by loading an ops file…) and to set the parameters for the simulation time (e.g. values for coefficients). If the module implements a growth model, it is then possible to trigger an evolution to a given date or time.

It is possible to do the same without any user interaction by writing a java script. Simeo script mode can be useful for long or repetitive tasks: first tune your simulation in interactive mode with few iterations or data, then write the script and launch it on a bigger machine to have results on more iterations or bigger data.

A script example

The Simeo scripts follow the Capsis architecture. Here is an example script to do the following:

  • start an Edito project (Edito is a module of Simeo: the scene editor, no growth capabilities)
  • load an ops file which name was given to the script (parameter 1)
  • set Edito overwrite mode (the original files will be overwritten)
  • send the root scene of the project to the Archimed1 export plugin
  • configure Archimed1 with a given parameter file (parameter 2)
  • run the plugin (will calculate irradiance at the organ level and write the result in new attributes in the original files)

This script may be run on a bigger machine if needed, for example if the scene contains a lot of adult trees with numerous and fine organs, or if Archimed1 is configured to work with a lot of details.

The script

package jeeb.simeo.module.simeoeditor.scripts;
 
import java.util.List;
 
import jeeb.simeo.app.SimeoScript;
import jeeb.simeo.extension.export.archimed1.Archimed1ExportScriptStarter;
import jeeb.simeo.module.simeoeditor.model.EditoInitialParameters;
import jeeb.simeo.module.simeoeditor.model.EditoMockup;
import jeeb.simeo.module.simeoeditor.model.EditoScene;
import capsis.kernel.GScene;
import capsis.kernel.Step;
 
/**
 * A Simeo script. Loads the given .ops scene file and sends it to the Archimed v1 radiative balance
 * tool.
 * 
 * Two ways to launch it:
 * 
 * <pre>
 * (1) sh simeo.sh -p script jeeb.simeo.module.simeoeditor.scripts.ScriptTristan2012 
 * (2) java -cp class:ext/* jeeb.simeo.module.simeoeditor.scripts.ScriptTristan2012
 * </pre>
 * 
 * See usage () below for expected parameters.
 * 
 * @author F. de Coligny - 5.10.2012
 */
public class ScriptTristan2012 {
 
	private static void usage () {
		System.out.println ("Simeo-Edito: ScriptTristan2012");
		System.out
				.println ("  Windows: simeo -p script jeeb.simeo.module.simeoeditor.scripts.ScriptTristan2012 opsFileName archimed1ConfigFileName");
		System.out
				.println ("  Linux:   sh simeo.sh -p script jeeb.simeo.module.simeoeditor.scripts.ScriptTristan2012 opsFileName archimed1ConfigFileName");
		System.out.println ("  -> needs two parameters: opsFileName and archimed1ConfigFileName");
	}
 
	/**
	 * Script entry point.
	 */
	public static void main (String[] args) throws Exception {
 
		// Check script parameters
		if (args == null || args.length != 3) { // 0: script name, 1: opsFileName 2:
												// archimedConfigFileName
			usage ();
			return;
		}
 
		System.out.println ("ScriptTristan2012...");
 
		// prefixes: r_ means 'relative path', a_ means 'absolute path'
		String opsFileName = args[1]; // e.g. /home/coligny/workspace/amapstudio/tmp/tristan/tristan.ops
		String archimed1ConfigFileName = args[2]; // e.g. /home/coligny/workspace/amapstudio/tmp/tristan/archimed1.config
 
		System.out.println ("opsFileName            : " + opsFileName);
		System.out.println ("archimed1ConfigFileName: " + archimed1ConfigFileName);
 
		// Create script
		SimeoScript script = new SimeoScript ("jeeb.simeo.module.simeoeditor");
 
		EditoInitialParameters i = (EditoInitialParameters) script.getModel ().getSettings ();
 
		// Set Edito overwrite mode: the mockups files (.opf) will not be copied and will be
		// overwritten
		i.setEditoOverwriteMode ();
		i.opsFileName = opsFileName;
 
		// Init
		System.out.println ("Loading scene... ");
		script.init (i);
 
		Step root = script.getRoot ();
		GScene scene = root.getScene ();
 
		// Check the first mockup files
		EditoScene es = (EditoScene) scene;
		List<EditoMockup> mockups = es.getElements ();
		for (EditoMockup m : mockups) {
			System.out.println ("Checking first mockup...");
			System.out.println ("  Mockup id: " + m.getId ());
			System.out.println ("  Mockup a_filePath_0: " + m.getA_FilePath_0 ());
			System.out.println ("  Mockup   fileName_0: " + m.getFileName_0 ());
			System.out.println ("  Mockup a_filePath_1: " + m.getA_FilePath_1 ());
			System.out.println ("  Mockup r_filePath_1: " + m.getR_FilePath_1 ());
			System.out.println ("  Mockup   fileName_1: " + m.getFileName_1 ());
			System.out.println ("  Mockup r_sceneDir  : " + m.getR_SceneDir ());
			System.out.println ("  Mockup opf: " + m.getFile ("opf"));
			for (String f : m.getFiles ()) {
				System.out.println ("  Mockup file: " + f);
			}
			break; // only the first one
		}
 
		// Export to Archimed1
		Archimed1ExportScriptStarter s = new Archimed1ExportScriptStarter (es, archimed1ConfigFileName);
		s.execute ();
 
		// Close project
		script.closeProject ();
 
		System.out.println ("ScriptTristan2012 is over");
	}
}

How to launch the script

Open a terminal, change directory to the amapstudio install directory, then type a command like the following (adapt for your ops and Archimed1 configuration file):

sh simeo.sh -p script jeeb.simeo.module.simeoeditor.scripts.ScriptTristan2012 tmp/francois/francois.ops tmp/francois/archimed1.config
soft/simeo/private/the_simeo_script_mode_in_java_to_run_background_simulations.txt · Last modified: 2021/12/17 09:22 by 127.0.0.1