wiki:addfield

Version 13 (modified by srebuffi, 10 years ago) ( diff )

--

Let's use an example to illustrate how to add a field in the model. I want to add a field melting_rate to the class calving (I want to have md.calving.melting_rate) that is defined by the user.

Modify the User Interface

Go to src/m/classes and modify calving.m and its python equivalent.

  1. Declare the new field in properties
       melting_rate = NaN;
    

in ISSM, we use NaN for vectors and 0 for scalars. The default value is added with some explanation in the setdefaultparameters function of the class.

  1. Add a default value in setdefaultparameters (Optionals, for scalars only, Literature reference is encouraged)
  2. Add a consistency check
    md = checkfield(md,'fieldname','calving.meltingrate','NaN',1,'size',[md.mesh.numberofvertices 1],'>=',0);
    

which means that we want no NaN, the vecteur should be of size numberofvertices with positive values only.

  1. Add description in disp
  2. Add field to marshall

Add new Enums

Now, you have to add the Enum corresponding to your new field whose Enum name will be : ClassenameFieldnameEnum with Classename the name of the class with upper case for the first letter (here it will be Calving and Calvinglevermann for Classename) and Fieldname the name of your field you put in the previous files with upper case for the first letter (I put meltingrate in calving.m so Fieldname is Meltingrate). So I will add 2 Enums : CalvingMeltingrateEnum and CalvinglevermannMeltingrateEnum.

NB : don't forget to synchronize the Enums after it.

Implement the new field in the model

First, load the input:

Input* meltingrate_input  = NULL;
Note: See TracWiki for help on using the wiki.