source: issm/trunk-jpl/src/m/classes/mesh3dsurface.m@ 19897

Last change on this file since 19897 was 19897, checked in by Mathieu Morlighem, 9 years ago

CHG: added check on Inf values in checkconsistency

File size: 12.7 KB
Line 
1%MESH3DSURFACE class definition
2%
3% Usage:
4% mesh3dsurface=mesh3dsurface();
5
6classdef mesh3dsurface
7 properties (SetAccess=public)
8 x = NaN;
9 y = NaN;
10 z = NaN;
11 elements = NaN;
12 numberofelements = 0;
13 numberofvertices = 0;
14 numberofedges = 0;
15
16 lat = NaN;
17 long = NaN;
18 r = NaN;
19
20 vertexonboundary = NaN;
21 edges = NaN;
22 segments = NaN;
23 segmentmarkers = NaN;
24 vertexconnectivity = NaN;
25 elementconnectivity = NaN;
26 average_vertex_connectivity = 0;
27
28 extractedvertices = NaN;
29 extractedelements = NaN;
30 end
31 methods (Static)
32 function self = loadobj(self) % {{{
33 % This function is directly called by matlab when a model selfect is
34 % loaded. Update old properties here
35
36 %2014 Oct. 1st
37 if isstruct(self),
38 oldself=self;
39 %Assign property values from struct
40 self=structtoobj(mesh3dsurface(),oldself);
41 if isfield(oldself,'hemisphere'),
42 disp('md.mesh.hemisphere has been automatically converted to EPSG code');
43 if strcmpi(oldself.hemisphere,'n'),
44 self.epsg=3413;
45 else
46 self.epsg=3031;
47 end
48 end
49 end
50
51 end% }}}
52 end
53 methods
54 function self = mesh3dsurface(varargin) % {{{
55 switch nargin
56 case 0
57 self=setdefaultparameters(self);
58 case 1
59 self=mesh3dsurface();
60 object=varargin{1};
61 fields=fieldnames(object);
62 for i=1:length(fields)
63 field=fields{i};
64 if ismember(field,properties('mesh3dsurface')),
65 self.(field)=object.(field);
66 end
67 end
68 otherwise
69 error('constructor not supported');
70 end
71 end % }}}
72 function obj = setdefaultparameters(obj) % {{{
73
74 %the connectivity is the averaged number of nodes linked to a
75 %given node through an edge. This connectivity is used to initially
76 %allocate memory to the stiffness matrix. A value of 16 seems to
77 %give a good memory/time ration. This value can be checked in
78 %trunk/test/Miscellaneous/runme.m
79 obj.average_vertex_connectivity=25;
80 end % }}}
81 function md = checkconsistency(obj,md,solution,analyses) % {{{
82
83 md = checkfield(md,'fieldname','mesh.x','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
84 md = checkfield(md,'fieldname','mesh.y','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
85 md = checkfield(md,'fieldname','mesh.z','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
86 md = checkfield(md,'fieldname','mesh.lat','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
87 md = checkfield(md,'fieldname','mesh.long','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
88 md = checkfield(md,'fieldname','mesh.r','NaN',1,'Inf',1,'size',[md.mesh.numberofvertices 1]);
89 md = checkfield(md,'fieldname','mesh.elements','NaN',1,'Inf',1,'>',0,'values',1:md.mesh.numberofvertices);
90 md = checkfield(md,'fieldname','mesh.elements','size',[md.mesh.numberofelements 3]);
91 if any(~ismember(1:md.mesh.numberofvertices,sort(unique(md.mesh.elements(:)))));
92 md = checkmessage(md,'orphan nodes have been found. Check the mesh outline');
93 end
94 md = checkfield(md,'fieldname','mesh.numberofelements','>',0);
95 md = checkfield(md,'fieldname','mesh.numberofvertices','>',0);
96 md = checkfield(md,'fieldname','mesh.average_vertex_connectivity','>=',9,'message','''mesh.average_vertex_connectivity'' should be at least 9 in 2d');
97
98 switch(solution),
99 case ThermalSolutionEnum(),
100 md = checkmessage(md,'thermal not supported for 2d mesh');
101 end
102 end % }}}
103 function disp(obj) % {{{
104 disp(sprintf(' 2D tria Mesh (horizontal):'));
105
106 disp(sprintf('\n Elements and vertices:'));
107 fielddisplay(obj,'numberofelements','number of elements');
108 fielddisplay(obj,'numberofvertices','number of vertices');
109 fielddisplay(obj,'elements','vertex indices of the mesh elements');
110 fielddisplay(obj,'x','vertices x coordinate [m]');
111 fielddisplay(obj,'y','vertices y coordinate [m]');
112 fielddisplay(obj,'z','vertices z coordinate [m]');
113 fielddisplay(obj,'lat','vertices latitude [degrees]');
114 fielddisplay(obj,'long','vertices longitude [degrees]');
115 fielddisplay(obj,'r','vertices radius [m]');
116
117 fielddisplay(obj,'edges','edges of the 2d mesh (vertex1 vertex2 element1 element2)');
118 fielddisplay(obj,'numberofedges','number of edges of the 2d mesh');
119
120 disp(sprintf('\n Properties:'));
121 fielddisplay(obj,'vertexonboundary','vertices on the boundary of the domain flag list');
122 fielddisplay(obj,'segments','edges on domain boundary (vertex1 vertex2 element)');
123 fielddisplay(obj,'segmentmarkers','number associated to each segment');
124 fielddisplay(obj,'vertexconnectivity','list of vertices connected to vertex_i');
125 fielddisplay(obj,'elementconnectivity','list of vertices connected to element_i');
126 fielddisplay(obj,'average_vertex_connectivity','average number of vertices connected to one vertex');
127
128 disp(sprintf('\n Extracted model:'));
129 fielddisplay(obj,'extractedvertices','vertices extracted from the model');
130 fielddisplay(obj,'extractedelements','elements extracted from the model');
131 end % }}}
132 function createxml(obj,fid) % {{{
133 fprintf(fid, '<!-- #D surface Mesh -->\n');
134
135 %elements and vertices
136 fprintf(fid,'%s\n%s\n%s\n','<frame key="1" label="Elements and vertices">','<section name="mesh" />');
137 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n',' <parameter key ="numberofelements" type="',class(obj.numberofelements),'" default="',convert2str(obj.numberofelements),'">',' <section name="mesh" />',' <help> number of elements </help>',' </parameter>');
138 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n',' <parameter key ="numberofvertices" type="',class(obj.numberofvertices),'" default="',convert2str(obj.numberofvertices),'">',' <section name="mesh" />',' <help> number of vertices </help>',' </parameter>');
139 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n',' <parameter key ="elements" type="',class(obj.elements),'" default="',convert2str(obj.elements),'">',' <section name="mesh" />',' <help> vertex indices of the mesh elements </help>',' </parameter>');
140 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="x" type="',class(obj.x),'" default="',convert2str(obj.x),'">',' <section name="mesh" />',' <help> vertices x coordinate [m] </help>',' </parameter>');
141 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="y" type="',class(obj.y),'" default="',convert2str(obj.y),'">',' <section name="mesh" />',' <help> vertices y coordinate [m] </help>',' </parameter>');
142 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="edges" type="',class(obj.edges),'" default="',convert2str(obj.edges),'">',' <section name="mesh" />',' <help> edges of the 2d mesh (vertex1 vertex2 element1 element2) </help>',' </parameter>');
143 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="numberofedges" type="',class(obj.numberofedges),'" default="',convert2str(obj.numberofedges),'">',' <section name="mesh" />',' <help> number of edges of the 2d mesh </help>',' </parameter>');
144 fprintf(fid,'%s\n%s\n','</frame>');
145
146 % properties
147 fprintf(fid,'%s\n%s\n%s\n','<frame key="2" label="Properties">','<section name="mesh" />');
148 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="vertexonboundary" type="',class(obj.vertexonboundary),'" default="',convert2str(obj.vertexonboundary),'">',' <section name="mesh" />',' <help> vertices on the boundary of the domain flag list </help>',' </parameter>');
149 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="segments" type="',class(obj.segments),'" default="',convert2str(obj.segments),'">',' <section name="mesh" />',' <help> edges on domain boundary (vertex1 vertex2 element) </help>',' </parameter>');
150 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="segmentmarkers" type="',class(obj.segmentmarkers),'" default="',convert2str(obj.segmentmarkers),'">',' <section name="mesh" />',' <help> number associated to each segment </help>',' </parameter>');
151 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="vertexconnectivity" type="',class(obj.vertexconnectivity),'" default="',convert2str(obj.vertexconnectivity),'">',' <section name="mesh" />',' <help> list of vertices connected to vertex_i </help>',' </parameter>');
152 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="elementconnectivity" type="',class(obj.elementconnectivity),'" default="',convert2str(obj.elementconnectivity),'">',' <section name="mesh" />',' <help> list of vertices connected to element_i </help>',' </parameter>');
153 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="average_vertex_connectivity" type="',class(obj.average_vertex_connectivity),'" default="',convert2str(obj.average_vertex_connectivity),'">',' <section name="mesh" />',' <help> average number of vertices connected to one vertex </help>',' </parameter>');
154 fprintf(fid,'%s\n%s\n','</frame>');
155
156 %extracted model
157 fprintf(fid,'%s\n%s\n%s\n','<frame key="3" label="Extracted Model">','<section name="mesh" />');
158 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="extractedvertices" type="',class(obj.extractedvertices),'" default="',convert2str(obj.extractedvertices),'">',' <section name="mesh" />',' <help> vertices extracted from the model </help>',' </parameter>');
159 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="extractedelements" type="',class(obj.extractedelements),'" default="',convert2str(obj.extractedelements),'">',' <section name="mesh" />',' <help> elements extracted from the model </help>',' </parameter>');
160 fprintf(fid,'%s\n%s\n','</frame>');
161
162 %projection
163 fprintf(fid,'%s\n%s\n%s\n','<frame key="4" label="Projection">','<section name="mesh" />');
164 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="lat" type="',class(obj.lat),'" default="',convert2str(obj.lat),'">',' <section name="mesh" />',' <help> vertices latitude [degrees] </help>',' </parameter>');
165 fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',' <parameter key ="long" type="',class(obj.long),'" default="',convert2str(obj.long),'">',' <section name="mesh" />',' <help> verticies longitude [degrees] </help>',' </parameter>');
166 % choice (epsg) 'n' or 's'
167 fprintf(fid,'%s\n%s\n%s\n',' <parameter key ="epsg" type="alternative" optional="false">',' <section name="mesh" />',' <help> Indicate epsg ''n'' or ''s'' </help>');
168 fprintf(fid,'%s\n',' <option value="n" type="string" default="true"> </option>');
169 fprintf(fid,'%s\n',' <option value="s" type="string" default="false"> </option>');
170 fprintf(fid,'%s\n',' </parameter>');
171 fprintf(fid,'%s\n%s\n','</frame>');
172
173 end % }}}
174 function marshall(obj,md,fid) % {{{
175 WriteData(fid,'enum',DomainTypeEnum(),'data',StringToEnum(['Domain' domaintype(obj)]),'format','Integer');
176 WriteData(fid,'enum',DomainDimensionEnum(),'data',dimension(obj),'format','Integer');
177 WriteData(fid,'enum',MeshElementtypeEnum(),'data',StringToEnum(elementtype(obj)),'format','Integer');
178 WriteData(fid,'object',obj,'class','mesh','fieldname','x','format','DoubleMat','mattype',1);
179 WriteData(fid,'object',obj,'class','mesh','fieldname','y','format','DoubleMat','mattype',1);
180 WriteData(fid,'object',obj,'class','mesh','fieldname','z','format','DoubleMat','mattype',1);
181 WriteData(fid,'object',obj,'class','mesh','fieldname','lat','format','DoubleMat','mattype',1);
182 WriteData(fid,'object',obj,'class','mesh','fieldname','long','format','DoubleMat','mattype',1);
183 WriteData(fid,'object',obj,'class','mesh','fieldname','r','format','DoubleMat','mattype',1);
184 WriteData(fid,'enum',MeshZEnum(),'data',zeros(obj.numberofvertices,1),'format','DoubleMat','mattype',1);
185 WriteData(fid,'object',obj,'class','mesh','fieldname','elements','format','DoubleMat','mattype',2);
186 WriteData(fid,'object',obj,'class','mesh','fieldname','numberofelements','format','Integer');
187 WriteData(fid,'object',obj,'class','mesh','fieldname','numberofvertices','format','Integer');
188 WriteData(fid,'object',obj,'class','mesh','fieldname','average_vertex_connectivity','format','Integer');
189 WriteData(fid,'object',obj,'class','mesh','fieldname','vertexonboundary','format','DoubleMat','mattype',1);
190 end % }}}
191 function t = domaintype(obj) % {{{
192 t = '3Dsurface';
193 end % }}}
194 function d = dimension(obj) % {{{
195 d = 2;
196 end % }}}
197 function s = elementtype(obj) % {{{
198 s = 'Tria';
199 end % }}}
200 function [x y z elements is2d isplanet] = processmesh(self,options) % {{{
201
202 isplanet = 1;
203 is2d = 0;
204
205 elements = self.elements;
206 x = self.x;
207 y = self.y;
208 z = self.z;
209 end % }}}
210 end
211end
Note: See TracBrowser for help on using the repository browser.