tviewers.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tviewers.cc (3488B)
---
1 // Copyright (C) 2004-2011, 2013, 2014, 2015, 2016, 2017 Jed Brown, Ed Bueler and Constantine Khroulev
2 //
3 // This file is part of PISM.
4 //
5 // PISM is free software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with PISM; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #include <cstring>
20 #include <cmath>
21
22 #include "IceModel.hh"
23
24 #include "pism/util/ConfigInterface.hh"
25 #include "pism/util/Diagnostic.hh"
26 #include "pism/util/error_handling.hh"
27 #include "pism/util/Vars.hh"
28 #include "pism/util/pism_utilities.hh"
29
30 namespace pism {
31
32 void IceModel::view_field(const IceModelVec *field) {
33 unsigned int viewer_size = (unsigned int)m_config->get_number("output.runtime.viewer.size");
34
35 unsigned int dims = field->ndims();
36
37 if (dims != 2) {
38 throw RuntimeError(PISM_ERROR_LOCATION, "map-plane views of 3D quantities are not supported.");
39 }
40
41 if (field->ndof() == 1) { // scalar fields
42 std::string name = field->metadata().get_string("short_name");
43 petsc::Viewer::Ptr viewer = m_viewers[name];
44
45 if (not viewer) {
46 m_viewers[name].reset(new petsc::Viewer(m_grid->com, name, viewer_size, m_grid->Lx(), m_grid->Ly()));
47 viewer = m_viewers[name];
48 }
49
50 const IceModelVec2S *v2d = dynamic_cast<const IceModelVec2S*>(field);
51 if (v2d == NULL) {
52 throw RuntimeError(PISM_ERROR_LOCATION, "get_ndims() returns GRID_2D but dynamic_cast gives a NULL");
53 }
54
55 v2d->view(viewer, petsc::Viewer::Ptr());
56
57 } else if (field->ndof() == 2) { // vector fields
58 std::string
59 name_1 = field->metadata(0).get_string("short_name"),
60 name_2 = field->metadata(1).get_string("short_name");
61 petsc::Viewer::Ptr
62 v1 = m_viewers[name_1],
63 v2 = m_viewers[name_2];
64
65 if (not v1) {
66 m_viewers[name_1].reset(new petsc::Viewer(m_grid->com, name_1, viewer_size, m_grid->Lx(), m_grid->Ly()));
67 v1 = m_viewers[name_1];
68 }
69
70 if (not v2) {
71 m_viewers[name_2].reset(new petsc::Viewer(m_grid->com, name_2, viewer_size, m_grid->Lx(), m_grid->Ly()));
72 v2 = m_viewers[name_2];
73 }
74
75 const IceModelVec2 *v2d = dynamic_cast<const IceModelVec2*>(field);
76 if (v2d == NULL) {
77 throw RuntimeError(PISM_ERROR_LOCATION, "get_ndims() returns GRID_2D but dynamic_cast gives a NULL");
78 }
79
80 v2d->view(v1, v2);
81 }
82 }
83
84 //! Update the runtime graphical viewers.
85 /*!
86 Most viewers are updated by this routine, but some other are updated elsewhere.
87 */
88 void IceModel::update_viewers() {
89
90 auto viewers = set_split(m_config->get_string("output.runtime.viewer.variables"), ',');
91
92 // map-plane viewers
93 for (auto v : viewers) {
94 if (m_grid->variables().is_available(v)) {
95 this->view_field(m_grid->variables().get(v));
96 } else {
97 // if not found, try to compute:
98 auto diag = m_diagnostics.find(v);
99
100 if (diag != m_diagnostics.end()) {
101 this->view_field(diag->second->compute().get());
102 }
103 }
104 }
105 }
106
107 } // end of namespace pism