Version 16 (modified by 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.
- 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.
- Add a default value in
setdefaultparameters
(Optionals, 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 vecteur should be of size numberofvertices
with positive values only.
- Add description in
disp
- 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:
Input* meltingrate_input = NULL; meltingrate_input = basalelement->GetInput(CalvinglevermannMeltingrateEnum); _assert_(meltingrate_input);
Then, start looping on the number of gaussian points and fetch the input value at these points:
meltingrate_input->GetInputValue(&meltingrate,gauss);
Ater that, you can do your computations using meltingrate
for this gaussian point.
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, I have to write md.calving.meltingrate=zeros(md.mesh.numberofvertices,1);
in other tests)