Changes between Version 10 and Version 11 of addfield
- Timestamp:
- 11/19/14 16:45:48 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
addfield
v10 v11 1 Let's use an example to illustrate how to add a field in the model. I want to add a melting rate field to the calving parameters. This melting rate is given by the user so we add the field to the GUI interface.1 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. 2 2 3 == Modify the GUI==3 == Modify the User Interface == 4 4 5 Go to `src/m/classes` and modify all the classes concerned by the new field, here `calving.m` and`calvinglevermann.m` and their associated Python versions. Declare the new field, add default values (if desired), add consistency checks, display descriptions and marshall instructions. 5 Go to `src/m/classes` and modify `calving.m` and its python equivalent. 6 7 1. Declare the new field in `properties` 8 {{{ 9 #!m 10 melting_rate = NaN; 11 }}} 12 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. 13 14 2. Add a default value in `setdefaultparameters` (Optionals, for scalars only, Literature reference is encouraged) 15 3. Add a consistency check 16 #!m 17 md = checkfield(md,'fieldname','calving.meltingrate','NaN',1,'size',[md.mesh.numberofvertices 1],'>=',0); 18 }}} 19 which means that we want no `NaN`, the vecteur should be of size `numberofvertices` with positive values only. 20 4. Add description in `disp` 21 5. Add field to `marshall` 6 22 7 23 == Add new Enums == … … 12 28 == Implement the new field in the model == 13 29 14 First, load the input:15 16 30 {{{ 17 31 #!c 18 32 Input* meltingrate_input = NULL; 19 meltingrate_input = basalelement->GetInput(CalvinglevermannMeltingrateEnum); _assert_(meltingrate_input);20 33 }}} 21 22 Then, start looping on the number of gaussian points and fetch the input value at these points:23 24 {{{25 #!c26 meltingrate_input->GetInputValue(&meltingrate,gauss);27 }}}28 29 Ater that, you can do your computations using `meltingrate` for this gaussian point.30