wiki:addfield

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 of all, you have to fetch the data in the UpdateElements function:

iomodel->FetchDataToInput(elements,CalvingMeltingrateEnum);

After, load the input in the computation function (i.e. wherever you need to use this input):

Input* meltingrate_input = element->GetInput(CalvinglevermannMeltingrateEnum); _assert_(meltingrate_input); 

You can then use meltingrate_input like any other input.

Add a Nightly run test

Now, you have to add a Nightly run test to check your new field keeps working as desired.

NB : don't forget to modify other tests that could be concerned by the addition of this new field. For example in my case, I have to write

md.calving.meltingrate=zeros(md.mesh.numberofvertices,1);

in some other already existing tests.

Last modified 3 years ago Last modified on 11/19/20 15:24:25
Note: See TracWiki for help on using the wiki.