186 Pass in file object, move it along and return it
189 unknown_name = current_line.strip().split()[-1][1:-1]
199 current_line = file_object.readline().strip()
201 use_default_mapping =
True
204 while not end_condition
in current_line:
205 if "number-of-unknowns" in current_line:
206 patch_unknown.set_unknowns(
int(current_line.strip().split()[1]))
207 if "number-of-dofs-per-axis" in current_line:
208 patch_unknown.set_dof(
int(current_line.strip().split()[1]))
209 if "description" in current_line:
210 patch_unknown.set_description(
211 current_line.strip().split(
"description")[1]
213 if '"' in patch_unknown.description:
215 "Warning: data description field "
216 + patch_unknown.description
217 +
" holds \" which might lead to issues with VTK's XML export. Remove them"
219 patch_unknown.description = patch_unknown.description.replace(
222 if "mapping" in current_line:
223 use_default_mapping =
False
224 values = current_line.strip().split(
"mapping")[1]
225 patch_unknown.set_mapping(np.fromstring(values, dtype=float, sep=
" "))
227 current_line = file_object.readline().strip()
229 if use_default_mapping:
230 patch_unknown._initialise_default_mapping_if_no_mapping_specified()
235 return file_object, current_line
238 self, current_line, file_object, end_condition="end patch"
241 Pass in file object, run it until we encounter the end condition,
244 We assume that current_line == "begin patch file" at this stage
246 This is where we read the actual data
250 current_line = file_object.readline().strip()
251 line = current_line.strip().split()
253 offset = (float(line[1]), float(line[2]))
255 offset = (float(line[1]), float(line[2]), float(line[3]))
258 current_line = file_object.readline().strip()
259 line = current_line.strip().split()
261 size = (float(line[1]), float(line[2]))
263 size = (float(line[1]), float(line[2]), float(line[3]))
267 while end_condition
not in current_line:
268 current_line = file_object.readline().strip()
273 if current_line.startswith(
"begin cell-values")
and (
279 ),
"is_data_associated_to_cell flag set incorrectly"
280 unknown_name = current_line.strip().split()[-1][1:-1]
281 current_line = file_object.readline()
282 values = np.fromstring(current_line, dtype=float, sep=
" ")
285 if current_line.startswith(
"begin vertex-values")
and (
291 ),
"is_data_associated_to_cell flag set incorrectly"
292 unknown_name = current_line.strip().split()[-1][1:-1]
293 current_line = file_object.readline()
294 values = np.fromstring(current_line, dtype=float, sep=
" ")
297 if values
is not None:
303 return file_object, current_line
307 Read file and return cell data, dimensions, number of degrees of freedom and number of unknowns
311 set_identifier: String
312 Name of the set of unknowns we want to extract. If this is the empty string
313 then I parse all content.
315 @todo: clean up the loop below. we can separate into getting metadata, and then reading patches
320 with open(self.
file_path,
"r")
as data_file:
321 current_line = data_file.readline()
325 the reason we keep track of 2 variables current_line and
326 line is because we want current_line to eval to False when we reach
327 EOF. However, we need to strip the whitespaces and newline
328 characters off the line for the data processing, without
329 exiting the loop if we have empty lines.
331 current_line = data_file.readline()
332 stripped_line = current_line.strip()
333 if stripped_line.startswith(
"dimensions"):
338 ],
"Only 2d and 3d patches are supported"
341 if stripped_line.startswith(
"begin cell-metadata")
and (
348 stripped_line, data_file,
"end cell-metadata"
351 if stripped_line.startswith(
"begin vertex-metadata")
and (
358 stripped_line, data_file,
"end vertex-metadata"
361 elif stripped_line.startswith(
"begin patch"):
366 stripped_line, data_file
371 except Exception
as e:
373 "Error: was not able to read "
389 We need to call the render function for each filter
390 on a variety of attributes, and then return them if they
393 We do this in a functional style, ie the Visualiser class
394 contains all of the filters we wish to apply, and we pass
395 the render function that we intend to use back to this
396 layer. Ugly, but we need to do some looping over the
397 different unknowns we see in the patch files, and I thought
398 it best to hide that from the parse_snapshot region of
401 The same apply for the validate function from the Visualiser
410 unknown_data.cell_data,
412 unknown_data.dimensions,
413 unknown_data.unknowns,
414 unknown_data.is_data_associated_to_cell,
415 unknown_data.description,
416 unknown_data.mapping,
417 ) = render_or_validate(
418 unknown_data.cell_data,
420 unknown_data.dimensions,
421 unknown_data.unknowns,
422 unknown_data.is_data_associated_to_cell,
423 unknown_data.description,
424 unknown_data.mapping,