source: issm/trunk/src/m/parameterization/setmask.js@ 25836

Last change on this file since 25836 was 25836, checked in by Mathieu Morlighem, 4 years ago

merged trunk-jpl and trunk for revision 25834

File size: 3.0 KB
Line 
1function setmask(md,floatingice,groundedice){
2//SETMASK - establish boundaries between grounded and floating ice.
3//
4// By default, ice is considered grounded. The contour floatingice defines nodes
5// for which ice is floating. The contour groundedice defines nodes inside a floatingice,
6// that are grounded (ie: ice rises, islands, etc ...)
7// All inputs are either strings or actually javascript arrays (included in the html file)
8// For example:
9//
10// floatingice[0]['x']=[0,0,0,1];
11// floatingice[0]['y']=[0,1,1,1];
12// floatingice[1]['x']=[0,0.5,0.5,.5];
13// floatingice[1]['y']=[0,.5,.5,.5];
14//
15//
16// Usage:
17// md=setmask(md,floatingice,groundedice)
18//
19// Examples:
20// md=setmask(md,'all','');
21// md=setmask(md,iceshelves,islands);
22
23 //variables:
24 var icedomain=[];
25
26 //some checks on list of arguments
27 if (!((arguments.length==3) | (arguments.length==5))){
28 throw Error('mask error message: wrong usage.');
29 }
30
31 if(arguments.length>3){
32 if (arguments[3]=='icedomain'){
33 icedomain=arguments[4];
34 }
35 else{
36 throw Error('mask error message: wrong field specified. Only icedomain allowed for now.');
37 }
38 if (IsArray(icedomain)){
39 throw Error('setmask error message: icedomain should be an array!');
40 }
41 }
42
43 //Get assigned fields
44 var x=md.mesh.x;
45 var y=md.mesh.y;
46 var elements=md.mesh.elements;
47
48 //Assign elementonfloatingice, elementongroundedice, vertexongroundedice and vertexonfloatingice.
49 //Only change at your own peril! This is synchronized heavily with the GroundingLineMigration module.
50 elementonfloatingice=FlagElements(md,floatingice);
51 elementongroundedice=FlagElements(md,groundedice);
52
53 //Because groundedice nodes and elements can be included into an floatingice, we need to update. Remember, all the previous
54 //arrays come from domain outlines that can intersect one another:
55 elementonfloatingice=ArrayAnd(elementonfloatingice,ArrayNot(elementongroundedice));
56 elementongroundedice=ArrayNot(elementonfloatingice);
57
58 //the order here is important. we choose vertexongroundedice as default on the grounding line.
59 vertexonfloatingice=NewArrayFill(md.mesh.numberofvertices,0);
60 vertexongroundedice=NewArrayFill(md.mesh.numberofvertices,0);
61 pos=ArrayFind(elementongroundedice,1); for (var i=0;i<pos.length;i++)for(var j=0;j<3;j++) vertexongroundedice[md.mesh.elements[i,j]-1]=1;
62 pos=ArrayFind(vertexongroundedice,0); for (var i=0;i<pos.length;i++)vertexonfloatingice[i]=1;
63
64 //level sets
65 ocean_levelset=vertexongroundedice;
66 pos=ArrayFind(vertexongroundedice,0);for(var i=0;i<pos.length;i++) ocean_levelset[i]=-1;
67 md.mask.ocean_levelset=ocean_levelset;
68
69 if(arguments.length>3){
70 md.mask.ice_levelset = NewArrayFill(md.mesh.numberofvertices,1.0);
71 //use contourtomesh to set ice values inside ice domain
72 //[vertexinsideicedomain,elementinsideicedomain]=ContourToMesh(elements,x,y,icedomain,'node',1);
73 pos=ArrayFind(vertexinsideicedomain,1.0);for(var i=0;i<pos.length;i++) md.mask.ice_levelset[pos]=-1;
74 }
75 else{
76 md.mask.ice_levelset = NewArrayFill(md.mesh.numberofvertices,-1);
77 }
78}
Note: See TracBrowser for help on using the repository browser.