PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
viewers.cc
Go to the documentation of this file.
1 // Copyright (C) 2004-2011, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022, 2023 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 "pism/icemodel/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/pism_utilities.hh"
28 #include "pism/util/petscwrappers/Viewer.hh"
29 #include "pism/util/Vars.hh"
30 
31 namespace pism {
32 
33 void IceModel::view_field(const array::Array *field) {
34  unsigned int viewer_size = (unsigned int)m_config->get_number("output.runtime.viewer.size");
35 
36  if (field->ndims() != 2) {
38  "map-plane views of 3D quantities are not supported.");
39  }
40 
41  auto name = field->get_name();
42 
43  if (m_viewers[name].empty()) {
44  for (size_t k = 0; k < field->ndof(); ++k) {
45  auto v = std::make_shared<petsc::Viewer>(m_grid->com, field->metadata(k)["short_name"],
46  viewer_size, m_grid->Lx(), m_grid->Ly());
47  m_viewers[name].emplace_back(v);
48  }
49  }
50 
51  field->view(m_viewers[name]);
52 }
53 
54 //! Update the runtime graphical viewers.
55 /*!
56 Most viewers are updated by this routine, but some other are updated elsewhere.
57  */
59 
60  auto viewers = set_split(m_config->get_string("output.runtime.viewer.variables"), ',');
61 
62  // map-plane viewers
63  for (auto v : viewers) {
64  if (m_grid->variables().is_available(v)) {
65  this->view_field(m_grid->variables().get(v));
66  } else {
67  // if not found, try to compute:
68  auto diag = m_diagnostics.find(v);
69 
70  if (diag != m_diagnostics.end()) {
71  this->view_field(diag->second->compute().get());
72  }
73  }
74  }
75 }
76 
77 } // end of namespace pism
virtual void view_field(const array::Array *field)
Definition: viewers.cc:33
const Config::Ptr m_config
Configuration flags and parameters.
Definition: IceModel.hh:243
std::map< std::string, std::vector< std::shared_ptr< petsc::Viewer > > > m_viewers
Definition: IceModel.hh:473
std::map< std::string, Diagnostic::Ptr > m_diagnostics
Requested spatially-variable diagnostics.
Definition: IceModel.hh:419
virtual void update_viewers()
Update the runtime graphical viewers.
Definition: viewers.cc:58
const std::shared_ptr< Grid > m_grid
Computational grid.
Definition: IceModel.hh:241
unsigned int ndof() const
Returns the number of degrees of freedom per grid point.
Definition: Array.cc:136
const std::string & get_name() const
Get the name of an Array object.
Definition: Array.cc:383
void view(std::vector< std::shared_ptr< petsc::Viewer > > viewers) const
View a 2D vector field using existing PETSc viewers.
Definition: Array.cc:1205
unsigned int ndims() const
Returns the number of spatial dimensions.
Definition: Array.cc:156
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
Definition: Array.hh:208
#define PISM_ERROR_LOCATION
static const double k
Definition: exactTestP.cc:42
std::set< std::string > set_split(const std::string &input, char separator)
Transform a separator-separated list (a string) into a set of strings.