Adding a New Field to the Model
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 (md.calving.melting_rate), which will be defined by the user.
Modifying the User Interface
Go to src/m/classes and modify calving.m and its Python equivalent:
- Declare the new field in
properties,melting_rate = NaN;in ISSM, we use
NaNfor vectors and0for scalars. The default value is added with some explanation in thesetdefaultparametersfunction of the class. - Add a default value in
setdefaultparameters(optional, for scalars only; literature reference is encouraged). - 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 vector should be of sizenumberofverticeswith positive values only. - Add description in
disp - Add field to
marshall
Add New Enums
Now, you have to add a new Enum corresponding to your new field whose Enum name will be ClassnameFieldnameEnum where,
Classnameis the name of the class with an upper case first letter (in this example,CalvingandCalvinglevermannforClassname)Fieldnameis the name of your field you put in the previous files with an upper case first letter (I putmeltingrateincalving.m, soFieldnameisMeltingrate).
So I will add two Enums: CalvingMeltingrateEnum and CalvinglevermannMeltingrateEnum.
NOTE: Don’t forget to synchronize the Enums after creating them.
Implement the New Field in the Model
First, 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 new Nightly Run to check that your new field continues to work as new changes are committed.
NOTE: 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 add,
md.calving.meltingrate=zeros(md.mesh.numberofvertices,1);
to some already existing tests.