PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
OrographicPrecipitation.cc
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2023 PISM Authors
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 "pism/coupler/atmosphere/OrographicPrecipitation.hh"
20 
21 #include "pism/coupler/atmosphere/OrographicPrecipitationSerial.hh"
22 #include "pism/coupler/util/options.hh"
23 #include "pism/geometry/Geometry.hh"
24 #include "pism/util/ConfigInterface.hh"
25 #include "pism/util/Grid.hh"
26 
27 namespace pism {
28 namespace atmosphere {
29 
30 OrographicPrecipitation::OrographicPrecipitation(std::shared_ptr<const Grid> grid,
31  std::shared_ptr<AtmosphereModel> in)
32  : AtmosphereModel(grid, in) {
33 
35 
36  m_work0 = m_precipitation->allocate_proc0_copy();
37 
38  const int
39  Mx = m_grid->Mx(),
40  My = m_grid->My(),
41  Z = m_config->get_number("atmosphere.orographic_precipitation.grid_size_factor"),
42  Nx = m_grid->periodicity() & grid::X_PERIODIC ? Mx : Z * (Mx - 1) + 1,
43  Ny = m_grid->periodicity() & grid::Y_PERIODIC ? My : Z * (My - 1) + 1;
44 
45  ParallelSection rank0(m_grid->com);
46  try {
47  if (m_grid->rank() == 0) {
49  Mx, My,
50  m_grid->dx(), m_grid->dy(),
51  Nx, Ny));
52  }
53  } catch (...) {
54  rank0.failed();
55  }
56  rank0.check();
57 }
58 
60  // empty
61 }
62 
64  return *m_precipitation;
65 }
66 
68  (void)geometry;
69 
70  m_input_model->init(geometry);
71 
72  m_log->message(2, "* Initializing the atmosphere model computing precipitation using the\n"
73  " Linear Theory of Orographic Precipitation model with scalar wind speeds...\n");
74 
75  m_reference = "R. B. Smith and I. Barstad, 2004.\n"
76  "A Linear Theory of Orographic Precipitation. J. Atmos. Sci. 61, 1377-1391.";
77 
78  m_precipitation->metadata()["source"] = m_reference;
79 }
80 
81 
82 void OrographicPrecipitation::update_impl(const Geometry &geometry, double t, double dt) {
83  m_input_model->update(geometry, t, dt);
84 
86 
87  ParallelSection rank0(m_grid->com);
88  try {
89  if (m_grid->rank() == 0) { // processor zero updates the precipitation
90  m_serial_model->update(*m_work0);
91 
92  PetscErrorCode ierr = VecCopy(m_serial_model->precipitation(), *m_work0);
93  PISM_CHK(ierr, "VecCopy");
94  }
95  } catch (...) {
96  rank0.failed();
97  }
98  rank0.check();
99 
100  m_precipitation->get_from_proc0(*m_work0);
101 
102  // convert from mm/s to kg / (m^2 s):
103  double water_density = m_config->get_number("constants.fresh_water.density");
104  m_precipitation->scale(1e-3 * water_density);
105 }
106 
108  std::vector<double> &result) const {
109 
110  for (unsigned int k = 0; k < m_ts_times.size(); k++) {
111  result[k] = (*m_precipitation)(i, j);
112  }
113 }
114 
116  m_input_model->begin_pointwise_access();
117  m_precipitation->begin_access();
118 }
119 
121  m_precipitation->end_access();
122  m_input_model->end_pointwise_access();
123 }
124 
125 } // end of namespace atmosphere
126 } // end of namespace pism
std::shared_ptr< const Grid > grid() const
Definition: Component.cc:105
const Config::ConstPtr m_config
configuration database used by this component
Definition: Component.hh:158
const Logger::ConstPtr m_log
logger (for easy access)
Definition: Component.hh:162
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition: Component.hh:156
array::Scalar2 ice_surface_elevation
Definition: Geometry.hh:57
void failed()
Indicates a failure of a parallel section.
void put_on_proc0(petsc::Vec &onp0) const
Puts a local array::Scalar on processor 0.
Definition: Array.cc:1052
std::shared_ptr< AtmosphereModel > m_input_model
static std::shared_ptr< array::Scalar > allocate_precipitation(std::shared_ptr< const Grid > grid)
std::vector< double > m_ts_times
A purely virtual class defining the interface of a PISM Atmosphere Model.
void update_impl(const Geometry &geometry, double t, double dt)
std::unique_ptr< OrographicPrecipitationSerial > m_serial_model
Serial orographic precipitation model.
const array::Scalar & precipitation_impl() const
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
std::shared_ptr< array::Scalar > m_precipitation
OrographicPrecipitation(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
#define PISM_CHK(errcode, name)
@ Y_PERIODIC
Definition: Grid.hh:51
@ X_PERIODIC
Definition: Grid.hh:51
static const double k
Definition: exactTestP.cc:42