1 | function md=collapse(md)
|
---|
2 | %COLLAPSE - collapses a 3d mesh into a 2d mesh
|
---|
3 | %
|
---|
4 | % This routine collapses a 3d model into a 2d model
|
---|
5 | % and collapses all the fileds of the 3d model by
|
---|
6 | % taking their depth-averaged values
|
---|
7 | %
|
---|
8 | % Usage:
|
---|
9 | % md=collapse(md)
|
---|
10 | %
|
---|
11 | % See also: EXTRUDE, MODELEXTRACT
|
---|
12 |
|
---|
13 | %Check that the model is really a 3d model
|
---|
14 | if ~md.mesh.dimension==3,
|
---|
15 | error('collapse error message: only 3d mesh can be collapsed')
|
---|
16 | end
|
---|
17 |
|
---|
18 | %Start with changing alle the fields from the 3d mesh
|
---|
19 |
|
---|
20 | %drag is limited to nodes that are on the bedrock.
|
---|
21 | md.friction.coefficient=project2d(md,md.friction.coefficient,1);
|
---|
22 |
|
---|
23 | %p and q (same deal, except for element that are on the bedrock: )
|
---|
24 | md.friction.p=project2d(md,md.friction.p,1);
|
---|
25 | md.friction.q=project2d(md,md.friction.q,1);
|
---|
26 |
|
---|
27 | %observations
|
---|
28 | if ~isnan(md.inversion.vx_obs), md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers); end;
|
---|
29 | if ~isnan(md.inversion.vy_obs), md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers); end;
|
---|
30 | if ~isnan(md.inversion.vel_obs), md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers); end;
|
---|
31 | if ~isnan(md.inversion.cost_functions_coefficients), md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers); end;
|
---|
32 | if ~isnan(md.inversion.min_parameters), md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers); end;
|
---|
33 | if ~isnan(md.inversion.max_parameters), md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers); end;
|
---|
34 | if ~isnan(md.surfaceforcings.mass_balance),
|
---|
35 | md.surfaceforcings.mass_balance=project2d(md,md.surfaceforcings.mass_balance,md.mesh.numberoflayers);
|
---|
36 | end;
|
---|
37 | if ~isnan(md.balancethickness.thickening_rate), md.balancethickness.thickening_rate=project2d(md,md.balancethickness.thickening_rate,md.mesh.numberoflayers); end;
|
---|
38 |
|
---|
39 | %results
|
---|
40 | if ~isnan(md.initialization.vx),md.initialization.vx=DepthAverage(md,md.initialization.vx);end;
|
---|
41 | if ~isnan(md.initialization.vy),md.initialization.vy=DepthAverage(md,md.initialization.vy);end;
|
---|
42 | if ~isnan(md.initialization.vz),md.initialization.vz=DepthAverage(md,md.initialization.vz);end;
|
---|
43 | if ~isnan(md.initialization.vel),md.initialization.vel=DepthAverage(md,md.initialization.vel);end;
|
---|
44 |
|
---|
45 | %bedinfo and surface info
|
---|
46 | md.mesh.elementonbed=ones(md.mesh.numberofelements2d,1);
|
---|
47 | md.mesh.elementonsurface=ones(md.mesh.numberofelements2d,1);
|
---|
48 | md.mesh.vertexonbed=ones(md.mesh.numberofvertices2d,1);
|
---|
49 | md.mesh.vertexonsurface=ones(md.mesh.numberofvertices2d,1);
|
---|
50 |
|
---|
51 | %elementstype
|
---|
52 | if ~isnan(md.flowequation.element_equation)
|
---|
53 | md.flowequation.element_equation=project2d(md,md.flowequation.element_equation,1);
|
---|
54 | md.flowequation.vertex_equation=project2d(md,md.flowequation.vertex_equation,1);
|
---|
55 | md.flowequation.bordermacayeal=project2d(md,md.flowequation.bordermacayeal,1);
|
---|
56 | md.flowequation.borderpattyn=project2d(md,md.flowequation.borderpattyn,1);
|
---|
57 | md.flowequation.borderstokes=project2d(md,md.flowequation.borderstokes,1);
|
---|
58 | end
|
---|
59 |
|
---|
60 | %boundary conditions
|
---|
61 | md.diagnostic.spcvx=project2d(md,md.diagnostic.spcvx,md.mesh.numberoflayers);
|
---|
62 | md.diagnostic.spcvy=project2d(md,md.diagnostic.spcvy,md.mesh.numberoflayers);
|
---|
63 | md.diagnostic.spcvz=project2d(md,md.diagnostic.spcvz,md.mesh.numberoflayers);
|
---|
64 | md.diagnostic.referential=project2d(md,md.diagnostic.referential,md.mesh.numberoflayers);
|
---|
65 | md.prognostic.spcthickness=project2d(md,md.prognostic.spcthickness,md.mesh.numberoflayers);
|
---|
66 | md.thermal.spctemperature=project2d(md,md.thermal.spctemperature,md.mesh.numberoflayers);
|
---|
67 |
|
---|
68 | %Extrusion of Neumann BC
|
---|
69 | if ~isnan(md.diagnostic.icefront),
|
---|
70 | numberofneumann2d=size(md.diagnostic.icefront,1)/(md.mesh.numberoflayers-1);
|
---|
71 | md.diagnostic.icefront=[md.diagnostic.icefront(1:numberofneumann2d,1:2) md.diagnostic.icefront(1:numberofneumann2d,5:6)]; %Add two columns on the first layer
|
---|
72 | end
|
---|
73 |
|
---|
74 | %materials
|
---|
75 | md.materials.rheology_B=DepthAverage(md,md.materials.rheology_B);
|
---|
76 | md.materials.rheology_n=project2d(md,md.materials.rheology_n,1);
|
---|
77 |
|
---|
78 | %special for thermal modeling:
|
---|
79 | md.basalforcings.melting_rate=project2d(md,md.basalforcings.melting_rate,1);
|
---|
80 | md.basalforcings.geothermalflux=project2d(md,md.basalforcings.geothermalflux,1); %bedrock only gets geothermal flux
|
---|
81 |
|
---|
82 | %update of connectivity matrix
|
---|
83 | md.mesh.average_vertex_connectivity=25;
|
---|
84 |
|
---|
85 | %Collapse the mesh
|
---|
86 | nodes2d=md.mesh.numberofvertices2d;
|
---|
87 | elements2d=md.mesh.numberofelements2d;
|
---|
88 |
|
---|
89 | %parameters
|
---|
90 | md.geometry.surface=project2d(md,md.geometry.surface,1);
|
---|
91 | md.geometry.thickness=project2d(md,md.geometry.thickness,1);
|
---|
92 | md.geometry.bed=project2d(md,md.geometry.bed,1);
|
---|
93 | md.mesh.vertexonboundary=project2d(md,md.mesh.vertexonboundary,1);
|
---|
94 | md.mask.elementonfloatingice=project2d(md,md.mask.elementonfloatingice,1);
|
---|
95 | md.mask.vertexonfloatingice=project2d(md,md.mask.vertexonfloatingice,1);
|
---|
96 | md.mask.elementongroundedice=project2d(md,md.mask.elementongroundedice,1);
|
---|
97 | md.mask.vertexongroundedice=project2d(md,md.mask.vertexongroundedice,1);
|
---|
98 | md.mask.elementonwater=project2d(md,md.mask.elementonwater,1);
|
---|
99 | md.mask.vertexonwater=project2d(md,md.mask.vertexonwater,1);
|
---|
100 |
|
---|
101 | %Initialize with the 2d mesh
|
---|
102 | md.mesh.x=md.mesh.x2d;
|
---|
103 | md.mesh.y=md.mesh.y2d;
|
---|
104 | md.mesh.z=zeros(size(md.mesh.x2d));
|
---|
105 | md.mesh.numberofvertices=md.mesh.numberofvertices2d;
|
---|
106 | md.mesh.numberofelements=md.mesh.numberofelements2d;
|
---|
107 | md.mesh.elements=md.mesh.elements2d;
|
---|
108 |
|
---|
109 | %Keep a trace of lower and upper nodes
|
---|
110 | md.mesh.lowervertex=NaN;
|
---|
111 | md.mesh.uppervertex=NaN;
|
---|
112 |
|
---|
113 | %Remove old mesh
|
---|
114 | md.mesh.x2d=NaN;
|
---|
115 | md.mesh.y2d=NaN;
|
---|
116 | md.mesh.elements2d=NaN;
|
---|
117 | md.mesh.numberofelements2d=md.mesh.numberofelements;
|
---|
118 | md.mesh.numberofvertices2d=md.mesh.numberofvertices;
|
---|
119 | md.mesh.numberoflayers=0;
|
---|
120 |
|
---|
121 | %Update mesh type
|
---|
122 | md.mesh.dimension=2;
|
---|