-
Notifications
You must be signed in to change notification settings - Fork 0
/
dry-mass.tex
1922 lines (1705 loc) · 173 KB
/
dry-mass.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% 11/23/2015
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AGUJournalTemplate.tex: this template file is for articles formatted with LaTeX
%
% This file includes commands and instructions
% given in the order necessary to produce a final output that will
% satisfy AGU requirements.
%
% You may copy this file and give it your
% article name, and enter your text.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLEASE DO NOT USE YOUR OWN MACROS
% DO NOT USE \newcommand, \renewcommand, or \def, etc.
%
% FOR FIGURES, DO NOT USE \psfrag or \subfigure.
% DO NOT USE \psfrag or \subfigure commands.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% All questions should be e-mailed to [email protected].
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Step 1: Set the \documentclass
%
% There are two options for article format:
%
% 1) PLEASE USE THE DRAFT OPTION TO SUBMIT YOUR PAPERS.
% The draft option produces double spaced output.
%
% 2) numberline will give you line numbers.
%% To submit your paper:
%\documentclass[draft,linenumbers]{agujournal}
%\draftfalse
%% For final version.
\documentclass{agujournal}
\usepackage{url}
% Now, type in the journal name: \journalname{<Journal Name>}
% ie, \journalname{Journal of Geophysical Research}
%% Choose from this list of Journals:
%
% JGR-Atmospheres
% JGR-Biogeosciences
% JGR-Earth Surface
% JGR-Oceans
% JGR-Planets
% JGR-Solid Earth
% JGR-Space Physics
% Global Biochemical Cycles
% Geophysical Research Letters
% Paleoceanography
% Radio Science
% Reviews of Geophysics
% Tectonics
% Space Weather
% Water Resource Research
% Geochemistry, Geophysics, Geosystems
% Journal of Advances in Modeling Earth Systems (JAMES)
% Earth's Future
% Earth and Space Science
%
%
\journalname{Journal of Advances in Modeling Earth Systems (JAMES)}
\begin{document}
%% ------------------------------------------------------------------------ %%
% Title
%
% (A title should be specific, informative, and brief. Use
% abbreviations only if they are defined in the abstract. Titles that
% start with general keywords then specific terms are optimized in
% searches)
%
%% ------------------------------------------------------------------------ %%
% Example: \title{This is a test title}
\title{NCAR {\color{red}{release of CAM-SE in CESM2.0}}: A reformulation of the spectral-element dynamical core in dry-mass vertical coordinates with comprehensive treatment of condensates and energy}
%% ------------------------------------------------------------------------ %%
%
% AUTHORS AND AFFILIATIONS
%
%% ------------------------------------------------------------------------ %%
% Authors are individuals who have significantly contributed to the
% research and preparation of the article. Group authors are allowed, if
% each author in the group is separately identified in an appendix.)
% List authors by first name or initial followed by last name and
% separated by commas. Use \affil{} to number affiliations, and
% \thanks{} for author notes.
% Additional author notes should be indicated with \thanks{} (for
% example, for current addresses).
% Example: \authors{A. B. Author\affil{1}\thanks{Current address, Antartica}, B. C. Author\affil{2,3}, and D. E.
% Author\affil{3,4}\thanks{Also funded by Monsanto.}}
\authors{P.H. Lauritzen\affil{1}\thanks{1850 Table Mesa Drive, Boulder, Colodaro, USA}, R.D. Nair\affil{1}, A.R. Herrington\affil{2},P. Callaghan\affil{1}, S. Goldhaber\affil{1}, J.M. Dennis\affil{1}, J.T. Bacmeister\affil{1}, B.E. Eaton\affil{1}, C.M. Zarzycki\affil{1}, Mark A. Taylor\affil{3}, P.A. Ullrich\affil{4}, T. Dubos\affil{5}, A. Gettelman\affil{1}, R.B. Neale\affil{1}, B. Dobbins\affil{1}, K.A. Reed\affil{2}, C. Hannay\affil{1}, B. Medeiros\affil{1}, J.J. Benedict and J.J. Tribbia\affil{1}}
\affiliation{1}{National Center for Atmospheric Research, Boulder, Colorado, USA}
\affiliation{2}{School of Marine and Atmospheric Sciences, Stony Brook University, State University of New York, Stony Brook, New York}
\affiliation{3}{Sandia National Laboratories, Albuquerque, New Mexico, USA}
\affiliation{4}{Department of Land, Air and Water Resources, University of California, Davis, California, USA}
\affiliation{5}{Ecole Polytechnique, UMR 8539, Laboratoire de M\'et\'eorologie Dynamique/IPSL, Palaiseau, France}
\affiliation{6}{Rosenstiel School of Marine and Atmospheric Science, University of Miami, Miami, Florida, USA}
% \affiliation{3}{Third Affiliation}
% \affiliation{4}{Fourth Affiliation}
%(repeat as many times as is necessary)
%% Corresponding Author:
% Corresponding author mailing address and e-mail address:
% (include name and email addresses of the corresponding author. More
% than one corresponding author is allowed in this LaTeX file and for
% publication; but only one corresponding author is allowed in our
% editorial system.)
% Example: \correspondingauthor{First and Last Name}{[email protected]}
\correspondingauthor{peter Hjort Lauritzen}{[email protected]}
%% Keypoints, final entry on title page.
% Example:
% \begin{keypoints}
% \item List up to three key points (at least one is required)
% \item Key Points summarize the main points and conclusions of the article
% \item Each must be 100 characters or less with no special characters or punctuation
% \end{keypoints}
% List up to three key points (at least one is required)
% Key Points summarize the main points and conclusions of the article
% Each must be 100 characters or less with no special characters or punctuation
\begin{keypoints}
\item The CESM2.0 release of the spectral-element dynamical core (CAM-SE) is documented
\item Model has comprehensive treatment of condensates and energy
\item The CAM-SE model has been sped-up significantly compared to its predecessor CAM-HOMME
\end{keypoints}
%% ------------------------------------------------------------------------ %%
%
% ABSTRACT
%
% A good abstract will begin with a short description of the problem
% being addressed, briefly describe the new data or analyses, then
% briefly states the main conclusion(s) and how they are supported and
% uncertainties.
%% ------------------------------------------------------------------------ %%
%% \begin{abstract} starts the second page
\begin{abstract}
It is the purpose of this paper to provide a comprehensive documentation of the new NCAR version of the spectral-element (SE) dynamical core as part of the CESM2.0 release. This version differs from previous releases of the SE dynamical core in several ways. Most notably the hybrid-sigma vertical coordinate is based on dry air mass, the condensates are dynamically active in the thermodynamic and momentum equations (also referred to as condensate loading), and the continuous equations of motion conserve a more comprehensive total energy that includes condensates. {\color{red}{Not related to the vertical coordinate change, the hyperviscosity operators and the vertical remapping algorithms have been modified.}} The code base has been significantly reduced, sped-up, and cleaned up as part of integrating SE as a dynamical core in the CAM (Community Atmosphere Model) repository rather than importing the SE dynamical core from HOMME (High-Order Method Modeling Environment) as an external code.
\end{abstract}
%% ------------------------------------------------------------------------ %%
%
% TEXT
%
%% ------------------------------------------------------------------------ %%
%%% Suggested section heads:
%\section{Introduction}
%
% The main text should start with an introduction. Except for short
% manuscripts (such as comments and replies), the text should be divided
% into sections, each with its own heading.
% Headings should be sentence fragments and do not begin with a
% lowercase letter or number. Examples of good headings are:
% \section{Materials and Methods}
% Here is text on Materials and Methods.
%
% \subsection{A descriptive heading about methods}
% More about Methods.
%
% \section{Data} (Or section title might be a descriptive heading about data)
%
% \section{Results} (Or section title might be a descriptive heading about the
% results)
%
% \section{Conclusions}
\section{Introduction}
Over the last two decades or so, the spectral-element (SE) method has been considered as a numerical method for the fluid flow solver in global weather/climate models \citep{FT2004MWR,BWTF2006MWR,KG2012JCP,GKC2013SIAM,CH2016APJAS}. The main motivations were the SE methods' near perfect scalability \citep{DetAl2012IJHPCA}, GPU acceleration \citep[e.g.][]{AWWGIJHPCA,AetAl2017IJHPCA}, high-order accuracy for smooth problems, and mesh-refinement capabilities. For some time the Community Earth System Model \citep[CESM; ][]{CESM1} has supported a SE dynamical core option in the atmosphere component CAM \citep[Community Atmosphere Model; ][]{CAM5} discretized on a cubed-sphere grid (Figure \ref{fig:grids}a). The SE dynamical core in CAM supports uniform resolution grids based on the equi-angular gnomonic cubed-sphere grid \citep{RP1996QJ} as well as a mesh-refinement capability with local increases in resolution through conformal mesh-refinement as shown on Figure \ref{fig:grids}b {\citep{FT2004MWR,BWTF2006MWR,ZetAl2014JC,ZetAl2014JCb}. The dynamical core code resided in the High-Order Methods Modeling environment (HOMME), a framework for developing new generation computationally efficient and petascale capable dynamical cores based on the SE method \citep{TL2000JSC,TES2008JPCS}, the discontinuous Galerkin method \citep{NCT2009CF} and finite-volume method \citep{ELGT2012PCS,LTOUNGK2017MWR}. Previously, the SE dynamical core was imported into CAM as an external code base. Consequently any updates to the HOMME code base would have to be imported into CAM and pass regression tests in both HOMME and CAM. We refer to this setup as CAM-HOMME, which has been extensively tested in AMIP-style climate simulations \citep[e.g., ][]{ELMNTT2012JC,ZJ2014JAMES,RetAl2015GRL,BetAl2016CC,RHUZ2016JAMC,GetAl2017JAMES}. CAM-SE's code base is in CAM and not HOMME. CAM-SE and HOMME codes have diverged significantly due to a massive code clean-up to satisfy software engineering standards in CAM (and make the code more user-friendly for the community) as well as considerable {\color{red}{reformulations of the dynamical core}} described herein.
\begin{figure}[h]
\centering
\includegraphics[scale=0.45]{figs/grids}
\caption{(a) The gnomonic equi-angular cubed-sphere grid that define the elements in CAM-SE. (b) Elements of a conformal mesh-refinement grid referred to as the CONUS-grid (Contiguous United States) used in CAM-SE.}
\label{fig:grids}
\end{figure}
In this paper we present a version of the SE dynamical core using a dry-mass vertical coordinate that includes condensate-loading, and the continuous equations of motion conserve a comprehensive moist total energy containing all prognostic water variables and their respective heat capacities in the thermodynamic equation. {\color{red}{The basic spectral-element method has not been changed but we present changes to the details of how hyperviscosity is applied and the vertical remapping that are not specific to the dry-mass vertical coordinate.}} As this paper serves as documentation for the CESM2.0 version of SE we also provide details on the spectral-element method and viscosity operators that have not been comprehensively documented in previous publications.
The SE dynamical core is the default dynamical core for high-resolution CESM applications, in particular, the configuration in which the average distance between grid-points is approximately ~28km \citep{BetAl2016CC}. At such resolutions the effects of condensates (such as cloud liquid and rain) may have a significant effect on the dynamics \citep{BLDT2012GRL}. CAM-HOMME does not represent the effect of condensates in the thermodynamic and momentum equations (also referred to as condensate loading). Including the thermodynamic and mass effect of condensates in the dynamical core using a dry-mass hybrid-sigma vertical coordinate {\color{red}{is mathematically simpler due to the clear separation of dry air, water vapor and condensates in the discretization.}} This is the initial motivation for using a dry-mass vertical coordinate. {\color{red}{That said, certain parts of the implementation of a dry-mass coordinate in the dynamical core is slightly more complicated since moist pressure is a diagnostic in a dry-mass vertical coordinate formulation (mass effects of moisture and condensates need to be explicitly added)} whereas in a moist coordinate pressure is prognostic.}
% That said, when using the usual moist-mass hybrid-sigma vertical coordinate \citep[e.g., ][]{SB1981MWR}.
A second motivation for switching to a dry-mass vertical coordinate is the consistent coupling with the physical parameterizations. CAM physics assumes that the (moist) pressure levels are constant during the parameterization updates. Consequently the moist pressure levels stay constant even when moisture leaves the column (e.g., rains out). At the very end of CAM physics the change in water vapor in each column is taken into account by scaling the mixing ratios for all tracers that are based on specific/moist mixing ratios so that dry air mass and tracer mass is conserved \citep[see Section 3.1.6 in ][]{CAM5}. This scaling does not guarantee shape-preservation and changes the total energy. In addition, the pressure field in CAM physics does not take into account the mass of condensates. When using a dry-mass vertical coordinate, the coordinate surfaces (assuming dry mass is constant) remain constant throughout the physics updates and there is no need to adjust tracer mixing ratios and one can more easily take into account the work performed by water variables in the context of the energy cycle.
The third motivation for using a dry-mass vertical coordinate relates to total energy conservation. Currently the energy fixer in CAM is based on a dry total energy \citep{WOHTTV2015JAMES} that uses the same heat-capacity for dry air and water vapor, and does not include the effect of condensates. To move towards a more accurate treatment of energy in CAM, a first step is to develop a dynamical core based on equations of motion conserving an energy that more accurately represents water vapor as well as condensates. This is most easily done when using a dry-mass vertical coordinate so that the energies associates with all water variables are clearly separated. Similarly for axial angular momentum (AAM) which is an important conserved quantity of the continuous equations of motion \citep[e.g., ][]{LHECFF2010JGR}. {\color{red}{The changes to physics needed to make it consistent with the dynamical core (discussed in this paragraph and the previous paragraph) is necessary for a fully consistent model. This adaptation is, however, not treated in this paper.}}
{\color{red}{The fourth motivation for a dry-mass formulation is the consistent coupling between CAM-SE and CSLAM \cite[Conservative Semi-LAgrangian Multi-tracer scheme; ][]{LNU2010JCP} in a moist atmosphere. The consistent coupling between the SE continuity equation for air and the continuity equation for tracers (solved with CSLAM) is much more consistent in a dry-mass coordinate as explained in the following. In a dry-mass formulation CSLAM transports water tracers while SE solves the continuity equation for dry air. The two are consistently coupled by making sure that if a tracer has value 1 (in which case CSLAM predicts the evolution of dry air mass) then the CSLAM dry mass field is identical to the SE dry mass field integrated over CSLAM control volumes \citep[how this is done is explained in detail in ][]{LTOUNGK2017MWR}. Had one used a moist vertical coordinate then this coupling between SE and CSLAM would be complicated by the fact that water tracers would implicitly be predicted by SE through solving the continuity equation for moist air mass (using a moist vertical coordinate). CAM-SE-CSLAM in a moist atmosphere is the subject of a separate paper.}}
This paper presents the reformulation of the SE dynamical core alone, while a reformulation of the physical parameterizations, as necessary for a fully consistent model in dry-mass vertical coordinates, is a separate endeavor. The paper is organized as follows. In section \ref{sec:cont-eq} the continuous equations of motion are derived which involves a detailed discussion of moist thermodynamics in the presence of condensates. The AAM and total energy conservation properties of continuous system of equations is also discussed. In section \ref{sec:discretized_eqs} the discretized equations of motion with focus on the vertical discretization in dry-mass vertical coordinates are derived. Details on the horizontal SE discretization on the cubed-sphere are also presented. Section \ref{sec:results} presents some results, validating the new dynamical core in idealized configurations. First, a moist baroclinic wave with simple warm-rain micro-physics and secondly in a CAM6{\footnote{the CAM6 physics tag is {\tt{cam5\_4\_128}} which is a near final pre-release version of the CESM2.0-CAM6 physics package; this paper focuses on the dynamical core and the details of the physics package are less important}} aqua-planet configuration. The computational performance of CAM-SE is presented in section \ref{sec:results}. The paper ends with summary and conclusions in section \ref{sec:concl}.
%
\section{Continuous equations}\label{sec:cont-eq}
Before writing the continuous equations of motion using a dry-mass vertical coordinate (section \ref{eq:eqnsmotion}), we first need to discuss the representation of water variables (section \ref{sec:mixing_ratios}), discuss the ideal gas law (section \ref{sec:tv}) and derive the thermodynamic equation for a mixture containing all water species (section \ref{sec:teqn}). The discussion of the equations of motion in the presence of water vapor, cloud liquid, ice, rain and snow closely follows \citet{joyOfUM}. {\color{red}{While the appropriate thermodynamics of moist air is well-understood \citep[e.g.][]{E1994} it is unclear how to best represent moist dynamical effects in numerical models \citep{O1990JAS,O2001MWR,S2003MWR,B2003JAS}.}} Therefore the derivation of the equations of motion including non-gas components is discussed in detail.
%As noted in \cite{cotton2010storm} ' ... the fundamental equations governing dry air are generally accepted in fluid dynamics communities. By contrast, the governing equations for moist atmosphere flows remain a source of some controversy and active research'.
Thereafter the dry mass vertical coordinate is defined in section \ref{eq:vertical_coord}. Details on viscosity and frictional heating are presented in section \ref{sec:hypvervisfric} and global conservation properties derived in section \ref{sec:aam}.
\subsection{Representation of water phases in terms of dry and wet (specific) mixing ratios}\label{sec:mixing_ratios}
{\color{red}{Equation \eqref{eq:mx} defines}} the dry mixing ratios for the water variables (vapor 'wv', cloud liquid 'cl', cloud ice 'ci', rain 'rn' and snow 'sw')
\begin{equation}
m^{(\ell)}\equiv \frac{\rho^{(\ell)}}{\rho^{(d)}}, \text{ where }\ell=`wv`,`cl`,`ci`,`rn`,`sw`,\label{eq:mx}
\end{equation}
where $\rho^{(d)}$ is the mass of dry air per unit volume of moist air and $\rho^{(\ell)}$ is the mass of the water substance of type $\ell$ per unit volume of moist air. Note that the mixing ratio for dry air is unity: $m^{(d)}\equiv \frac{\rho^{(d)}}{\rho^{(d)}}=1$.
Moist air refers to air containing dry air, water vapor, cloud liquid, cloud ice, rain amount and snow amount. For notational purposes define the set of all components of air
\begin{equation}
\mathcal{L}_{all}=\left\{ `d`,`wv`,`cl`,`ci`,`rn`,`sw`\right\},
\end{equation}
a set only referring to all water variables,
\begin{equation}
\mathcal{L}_{water}=\left\{`wv`,`cl`,`ci`,`rn`,`sw`\right\},
\end{equation}
and a set referring to all condensates (non-gas components of water)
\begin{equation}
\mathcal{L}_{cond}=\left\{`cl`,`ci`,`rn`,`sw`\right\}.
\end{equation}
The density of a unit volume of moist air is related to the dry air density through
\begin{equation}
\label{eq:rhosum}
\rho=\rho^{(d)}\left(\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right).
\end{equation}
Mixing ratios can also be specified in terms of density per density of moist air, in other words, specific/moist mixing ratios
\begin{equation}
q^{(\ell)}\equiv \frac{\rho^{(\ell)}}{\rho},\label{eq:qx}
\end{equation}
where, in particular, $q^{(wv)}$ is the specific humidity.
It is straight forward to convert between moist and dry mixing ratios
\begin{align}
m^{(\ell)}&=\frac{q^{(\ell)}}{1-\sum_{\ell \in \mathcal{L}_{water}} q^{(\ell)}},\label{eq:mxqx}\\
q^{(\ell)}&=\frac{m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}.
\end{align}
Note that if water vapor undergoes a phase change to rain and leaves the column, then the specific/wet mixing ratios change but the dry mixing ratios do not.
%
\subsection{Ideal gas law and virtual temperature}\label{sec:tv}
%In this section, the ideal gas law is derived for moist air containing condensates. In a parcel of moist air
%of volume $V$, the condensed phases occupy volumes $V^{(\ell)}$ with $\ell \in \mathcal{L}_{cond}$. Dry air and pure water vapor are
%assumed to be ideal perfect gases, and the gaseous part of moist air is assumed to be a perfect mixture of
%those gases. Therefore it is possible to assign a volume $V^{(d)}$ to dry air and $V^{(wv)}$ to water vapor, in proportion
%to their respective number of molecules. The total volume is $V=\sum_{\ell \in \mathcal{L}_{all}}V^{(\ell)}$. Now let
%\begin{equation}
%\alpha^{(\ell)}\equiv \frac{V^{(\ell)}}{V\, \rho^{(\ell)}},
%\end{equation}
%be the specific volume of each phase or component considered separately, let
%\begin{equation}
%\alpha^{(gas)}\equiv \frac{ V^{(d)} + V^{(wv)}}{V \left( \rho^{(d)} + \rho^{(wv)}\right)},
%\end{equation}
%be the specific volume of the gaseous phase considered separately from the condensed phases, and let
%\begin{equation}
%\alpha\equiv \frac{1}{\rho},\label{eq:rhoalpha}
%\end{equation}
%be the total specific volume. Also, note that
%\begin{equation}
%\label{eq:sum1}
%1 = \sum_{\ell \in \mathcal{L}_{(all)}} \rho^{(\ell)}\alpha^{(\ell)} = \alpha^{(gas)}\rho^{(gas)} + \sum_{\ell \in \mathcal{L}_{cond}}\rho^{(\ell)}\alpha^{(\ell)}.
%\end{equation}
In this section, the ideal gas law is derived for moist air containing condensates. In a parcel of moist air
of volume $V$, the gaseous components of moist air (dry air and water vapor) occupy volume $V^{(gas)}$ and the the condensed phases occupy volume $V^{(cond)}=V-V^{(gas)}$. The ideal gas law applies to the gaseous component of air only. In that case, the partial pressure of dry air (the pressure dry air would exert if it alone would occupy the volume)
\begin{equation}
p^{(d)}V^{(gas)}=N^{(d)}k_B T,
\end{equation}
where $k_B$ is the Boltzmann constant and $N^{(d)}$ is the number of molecules of dry air. Now
\begin{equation}
N^{(d)}=\frac{V \rho^{(d)}}{\mathcal{M}^{(d)}},
\end{equation}
where $\mathcal{M}^{(d)}$ is the molar mass of dry air, so the ideal gas law for the partial pressure of dry air can be written as
\begin{equation}
p^{(d)}V^{(gas)}=V\rho^{(d)}R^{(d)}T,
\end{equation}
where $R^{(d)}\equiv \frac{k_B}{\mathcal{M}^{(d)}}$ is the dry air gas constant. Similarly for the partial pressure of water vapor:
\begin{equation}
p^{(wv)}V^{(gas)}=V\rho^{(vw)}R^{(vw)}T,
\end{equation}
where $R^{(wv)}\equiv \frac{k_B}{\mathcal{M}^{(wv)}}$ is the gas constant for water vapor. According to Dalton's law of partial pressures, the total pressure exerted is equal to the sum of the partial pressures of the individual gases:
\begin{equation}
\label{eq:ptmp}
p=\frac{V}{V^{(gas)}}\left( \rho^{(d)}R^{(d)}T+\rho^{(wv)}R^{(wv)}T\right).
\end{equation}
Note that the condensates do not exert a gas pressure ({\color{red}{see}} Section \ref{sec:dryairp}). Moving $T$, $R^{(d)}$ and $\rho^{(d)}$ outside the parenthesis on the right-hand side of \eqref{eq:ptmp} yields
\begin{equation}
\label{eq:ptmp2}
p=\frac{V}{V^{(gas)}}\rho^{(d)}R^{(d)}\left( 1+\frac{1}{\epsilon}m^{(wv)}\right)T,
\end{equation}
where $\epsilon\equiv \frac{R^{(d)}}{R^{(wv)}}$. Multiplying \eqref{eq:ptmp2} with $\rho/\rho$ and simplifying using \eqref{eq:mx}, and \eqref{eq:rhosum} yields
\begin{equation}
\label{eq:ptmp3}
p=\frac{V}{V^{(gas)}}\rho R^{(d)}\left(\frac{ 1+\frac{1}{\epsilon}m^{(wv)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\right)T,
\end{equation}
By defining the virtual temperature
\begin{equation}
T_v =T\left( \frac{1+\frac{1}{\epsilon}m^{(wv)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\right),\label{eq:tv}
\end{equation}
and assuming that the volume of the condensates is zero $V=V^{(gas)}$ then \eqref{eq:ptmp3} can be written as
\begin{equation}
p=\rho R^{(d)} T_v\label{eq:igl}.
\end{equation}
%
%Now $\rho^{(\ell)}\alpha^{(\ell)}$ is the volume fraction $\frac{V^{(\ell)}}{V}$, especially:
%\begin{equation}
%\rho^{(gas)}\alpha^{(gas)}=\frac{V^{(gas)}}{V}.\label{eq:rhogas}
%\end{equation}
%Consequently, by substituting \eqref{eq:rhogas} into \eqref{eq:ptmp}, using \eqref{eq:mx} to write density in terms of mixing ratio, and simplifying yields
%\begin{equation}
%p=\rho^{(d)}\frac{R^{(d)} T\left( 1+\frac{1}{\epsilon}m^{(wv)}\right)}{\rho^{(gas)}\alpha^{(gas)}}\label{eq:ig3},
%\end{equation}
%where $\epsilon\equiv \frac{R^{(d)}}{R^{(wv)}}$. Using \eqref{eq:sum1} to eliminate $\rho^{(gas)}\alpha^{(gas)}$ in \eqref{eq:ig3},
%Multiplying by $\frac{\rho}{\rho}$, and manipulating the denominator using \eqref{eq:mx}, and \eqref{eq:rhosum}, and simplifying yields
%
%where the virtual temperature is given by
%\begin{equation}
%T_v =T\left[ \frac{1+\frac{1}{\epsilon}m^{(wv)}}{1+m^{(wv)}+\sum_{\ell\in \mathcal{L}_{cond}}m^{(\ell)}\left(1-\frac{\alpha^{(\ell)}}{\alpha}\right)}\right].
%\end{equation}
%The ratios of the specific volume of the condensates to the total specific volume of moist air are negligible (e.g., the terms $\frac{\alpha^{(\ell)}}{\alpha}$ are of order $10^{-3}$ or less) hence the formula for virtual temperature is simplified to
%\begin{equation}
%T_v =T\left( \frac{1+\frac{1}{\epsilon}m^{(wv)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\right), \text{ if } V^{(\ell)}=0 \text{ for }\ell \in \mathcal{L}_{cond}.\label{eq:tv}
%\end{equation}
%Even though the density of condensates can be $10^{3}$ larger than the density of the gaseous components of air, the fraction of a unit volume occupied by the condensates is negligible, i.e. $\alpha^{(gas)}\rho^{(gas)} \ll \sum_{\ell \in \mathcal{L}_{cond}}\rho^{(\ell)}\alpha^{(\ell)}$. Henceforth we assume that
%\begin{equation}
%V^{(\ell)}=0, \text{ for }\ell \in \mathcal{L}_{cond}.
%\end{equation}
%Using Dalton's law of partial pressures, the total gas pressure is the sum of the partial pressure of dry air (the pressure dry air would exert if it alone would occupy the volume) and the partial pressure of water vapor
%\begin{equation}
%p=p^{(d)}+p^{(wv)},\label{eq:ig} %=\rho^{(d)} R^{(d)} T+\rho^{(wv)} R^{(wv)} T
%\end{equation}
%The ideal gas law for dry air is
%e may write \eqref{eq:ig} in terms of $\rho^{(gas)}$ by multiplying \eqref{eq:ig} with $\frac{\rho^{(gas)}}{\rho^{(gas)}}$ and write the equation in terms of mixing ratios
%In this section the ideal gas law is derived for moist air containing condensates. Part of that derivation is the definition of virtual temperature. A unit volume of moist air $V=1$ is the sum of the volume of dry air and the volumes of the different forms of water in the air
%\begin{equation}
%V=\sum_{\ell \in \mathcal{L}_{all}} V^{(\ell)}.\label{eq:Volumes}
%\end{equation}
%Now let $\alpha\equiv \frac{1}{\rho}$ denote the specific volume of moist air, let $\alpha^{(gas)}$ be the specific volume of the gaseous components of moist air (the volume of water vapor and dry air per unit mass of water vapor and dry air), let $\alpha^{(cl)}$ be the specific volume of cloud liquid (i.e. volume occupied by unit mass of cloud liquid), and similarly for cloud ice, rain and snow. Then we can write \eqref{eq:Volumes} in terms of densities and specific volumes
%\begin{equation}
%\rho \alpha=\rho^{(gas)}\alpha^{(gas)}+\sum_{\ell\in \mathcal{L}_{cond}}\rho^{(\ell)}\alpha^{(\ell)},\label{eq:massV}
%\end{equation}
%where $\rho^{(gas)}=\rho^{(d)}+\rho^{(wv)}$. Note that $\alpha^{(\ell)}\neq \frac{1}{\rho^{(\ell)}}$ since $\rho^{(\ell)}$ is defined in terms mass of $\ell$ per unit volume of moist air and not mass of $\ell$ per unit volume of water phase $\ell$. Dividing \eqref{eq:massV} with $\rho^{(d)}$ and substituting \eqref{eq:mx} yields
%\begin{equation}
% \left(\sum_\ell m^{(\ell)}\right) \alpha = \left( 1+m^{(wv)}\right) \alpha^{(gas)}+\sum_{\ell\in \mathcal{L}_{cond}}m^{(\ell)}\alpha^{(\ell)}.\label{eq:vol}
%\end{equation}
%The ideal gas law for the gaseous components, using Dalton's law of partial pressures, is
%\begin{equation}
%p=p^{(d)}+p^{(wv)}=\rho^{(d)} R^{(d)} T+\rho^{(wv)} R^{(wv)} T,\label{eq:ig}
%\end{equation}
%where $p^{(d)}$ is the partial pressure exerted by dry air (the pressure dry air would exert if it alone would occupy the volume) and $p^{(wv)}$ is the partial pressure of water vapor (again, the pressure exerted by water vapor if it alone would occupy the volume). Note that the condensates do not exert a gas pressure (more in this in Section \ref{sec:dryairp}). We may write \eqref{eq:ig} in terms of $\rho^{(gas)}$ by multiplying \eqref{eq:ig} with $\frac{\rho^{(gas)}}{\rho^{(gas)}}$ and write the equation in terms of mixing ratios
%\begin{equation}
%p=R^{(d)} T\rho^{(gas)}\left( \frac{\rho^{(d)}}{\rho^{(gas)}}+\frac{\rho^{(wv)}}{\rho^{(gas)}}\frac{R^{(wv)}}{R^{(d)}}\right)=\frac{R^{(d)} \rho^{(gas)}T\left( 1+\frac{1}{\epsilon}m^{(wv)}\right)}{\left(1+m^{(wv)}\right)}\label{eq:ig2}.
%\end{equation}
%where . Since \eqref{eq:ig} holds for the gaseous components only we may substitute $\frac{1}{\rho^{(gas)}}$ with $\alpha^{(gas)}$ to get:
\subsection{Thermodynamic equation}\label{sec:teqn}
Let $S$ denote the total entropy of moist air
\begin{equation}
S=\sum_{\ell \in \mathcal{L}_{all}}S^{(\ell)},
\end{equation}
where $S^{(\ell)}$ is the entropy of component $\ell$ of moist air. From the chain rule applied to each component separately we get
\begin{align}
dS&=\sum_{\ell \in \mathcal{L}_{all}}dS^{(\ell)},\\
&=\sum_{\ell \in \mathcal{L}_{all}}\left( \frac{\partial S^{(\ell)}}{\partial E^{(\ell)}}\right) dE^{(\ell)}+\sum_{\ell \in \mathcal{L}_{gas}}\left( \frac{\partial S^{(\ell)}}{\partial V^{(gas)}}\right)dV^{(gas)}+\sum_{\ell \in \mathcal{L}_{cond}}\left( \frac{\partial S^{(\ell)}}{\partial V^{(\ell)}}\right) dV^{(\ell)},\label{eq:dS1}
\end{align}
where $V^{(\ell)}$ is the volume occupied by component $\ell$ of moist air and $E^{(\ell)}$ is the internal energy of $\ell$. If we assume that the condensates are incompressible, $dV^{(\ell)}=0$ for $\ell \in \mathcal{L}_{cond}$, then \eqref{eq:dS1} becomes
\begin{equation}
dS =\sum_{\ell \in \mathcal{L}_{all}}\left( \frac{\partial S^{(\ell)}}{\partial E^{(\ell)}}\right) dE^{(\ell)}+\sum_{\ell \in \mathcal{L}_{gas}}\left( \frac{\partial S^{(\ell)}}{\partial V^{(gas)}}\right) dV^{(gas)}.\label{eq:dS2}
\end{equation}
Using that $\frac{\partial S^{(\ell)}}{\partial V^{(gas)}}=\frac{p^{(\ell)}}{T}$ for $\ell \in \mathcal{L}_{gas}$, {\color{red}{$\frac{\partial S^{(\ell)}}{\partial E^{(\ell)}} = \frac{1}{T}$}} and that
\begin{equation}
dE^{(\ell)}=C_v^{(\ell)}dT,
\end{equation}
where $C_v^{(\ell)}$ is the heat capacity of $\ell$ at constant volume, then \eqref{eq:dS2} can be written as
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}C_v^{(\ell)}dT = T \sum_{\ell \in \mathcal{L}_{all}}dS^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}p^{(\ell)}dV^{(gas)},\label{eq:dS3}
\end{equation}
Note that \eqref{eq:dS3} holds for each component $\ell$. Multiply each component version of \eqref{eq:dS3} with $\frac{N^{(\ell)}\mathcal{M}^{(\ell)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}$, and using that $\rho^{(\ell)}=\frac{N^{(\ell)}\mathcal{M}^{(\ell)}}{V}$, then equation \eqref{eq:dS3} can be written as
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}\rho^{(\ell)}c_v^{(\ell)}dT = T \sum_{\ell \in \mathcal{L}_{all}}\rho^{(\ell)}ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}\frac{\rho^{(\ell)}p^{(\ell)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}dV^{(gas)},\label{eq:dS4}
\end{equation}
where $c_v^{(\ell)}=\frac{C_v^{(\ell)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}$ is the specific heat capacity for $\ell$ and $s^{(\ell)}=\frac{S^{(\ell)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}$ is specific entropy for $\ell$. To rewrite the last sum on the right-hand side of \eqref{eq:dS4}, we note that for gaseous components of moist air, $\ell \in \mathcal{L}_{gas}$,
\begin{align}
\frac{V^{(gas)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}&=\frac{V^{(gas)}+V^{(cond)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}-\frac{V^{(cond)}}{N^{(\ell)}\mathcal{M}^{(\ell)}},\\
&=\alpha^{(\ell)}-\frac{V^{(cond)}}{V}\frac{V}{N^{(\ell)}\mathcal{M}^{(\ell)}},\\
&=\left( 1-\chi^{(cond)}\right) \alpha^{(\ell)},\label{eq:dS5}
\end{align}
where {\color{red}{$\alpha^{(\ell)} = \frac{V}{N^{(\ell)}{\mathcal{M}^{(\ell)}}}$}} the specific volume of component $\ell$ and $\chi^{(cond)}\equiv \frac{V^{(cond)}}{V}$. Taking the differential of \eqref{eq:dS5}, and assume no phase changes ($N^{\ell}$ constant {\color{red}{so $dN^{(\ell)}$=0}}) then \eqref{eq:dS4} can be rewritten as
%, and for the condensates
%\begin{align}
%\frac{V^{(\ell)}}{N^{(\ell)}\mathcal{M}^{(\ell)}}&=\frac{V^{(\ell)}}{V}\frac{V}{N^{(\ell)}\mathcal{M}^{(\ell)}},\\
%&=\chi^{(cond)}\alpha^{(\ell)}.\label{eq:dS6}
%\end{align
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}\rho^{(\ell)}c_v^{(\ell)}dT = T \sum_{\ell \in \mathcal{L}_{all}}\rho^{(\ell)}ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}\rho^{(\ell)}p^{(\ell)}d\left[ \left( 1-\chi^{(cond)}\right) \alpha^{(\ell)}\right].\label{eq:dS7tmp}
\end{equation}
Using \eqref{eq:mx} equation \eqref{eq:dS7tmp} can be written as
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}c_v^{(\ell)}dT = T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)}p^{(\ell)}d\left[ \left( 1-\chi^{(cond)}\right) \alpha^{(\ell)}\right].\label{eq:dS7}
\end{equation}
Henceforth we assume that the volume of condensates is zero, $V^{(cond)}=0$ i.e. $\chi^{(cond)}=0$. Consequently we can rewrite \eqref{eq:dS7} as
\begin{align}
\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}c_v^{(\ell)}dT &= T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)} p^{(\ell)}d\alpha^{(\ell)},\\
&= T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)} d\left[p^{(\ell)} \alpha^{(\ell)}\right]+\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)}\alpha^{(\ell)}dp^{(\ell)},\\
&= T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)}-\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)} d\left[R^{(\ell)} T\right]+\sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)} \alpha^{(\ell)}dp^{(\ell)},\label{eq:dS8}
\end{align}
again using the chain rule and the ideal gas law \eqref{eq:ptmp} with $\frac{V}{V^{(gas)}}=1$. Using that $c_p^{(\ell)}=R^{(\ell)}+c_v^{(\ell)}$ and rearranging terms in \eqref{eq:dS8} yields
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} c_p^{(\ell)}dT - \sum_{\ell \in \mathcal{L}_{gas}}m^{(\ell)} \alpha^{(\ell)}dp^{(\ell)}=T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)},
\end{equation}
which can be written as
\begin{equation}
\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} c_p^{(\ell)}dT - \frac{1}{\rho_d}\sum_{\ell \in \mathcal{L}_{gas}}dp^{(\ell)}=T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)},\label{eq:ptmp8}
\end{equation}
since $m^{(\ell)} \alpha^{(\ell)}=\frac{m^{(\ell)}}{\rho^{(\ell)}}=\rho^{(d)}$. Dividing \eqref{eq:ptmp8} with $\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}$ and using \eqref{eq:rhosum} results in
\begin{equation}
\frac{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} c_p^{(\ell)}dT}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}} - \frac{1}{\rho}dp=\frac{T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}.\label{eq:ptmp9}
\end{equation}
%\sum_{\ell \in \mathcal{L}_{all}}dQ^{(\ell)},
%\end{equation}
%where $dQ^{(\ell)}=T \sum_{\ell \in \mathcal{L}_{all}}ds^{(\ell)}$ is the amount of heat per unit mass that is supplied reversibly to component $\ell$ of moist air.
If we define
\begin{align}
R &=\frac{\sum_{\ell \in \mathcal{L}_{all}} R^{(\ell)} m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}},\\
c_v&=\frac{\sum_{\ell \in \mathcal{L}_{all}} c_v^{(\ell)}m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}},\\
c_p&=\frac{\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)}m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}},\label{eq:cp}
\end{align}
where $R^{(\ell)}\equiv 0$ for the condensates, then {\color{red}{using \eqref{eq:ptmp}}} the thermodynamic equation can be written in compact form
\begin{equation}
\delta T-\frac{RT}{c_p\, p}\delta p=\frac{d Q}{c_p},\label{eq:thermo1}
\end{equation}
where $dQ=\frac{T \sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)} ds^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}$ is is the amount of heat per unit mass that is supplied reversibly to moist air. Note that \eqref{eq:thermo1} includes the effect of condensates but assumes that the condensates are incompressible and that their volume is zero.
%\subsection{old - thermodynamic section version - to be removed}
%The second law of of thermodynamics states
%\begin{equation}
%\delta Q=T\delta s,\label{eq:slt}
%\end{equation}
%where $\delta Q$ is the amount of heat per unit mass that is supplied reversibly to the moist air, and $s$ is specific entropy of moist air. Introducing specific internal energy $e$ and specific enthalphy
%\begin{equation}
%h=e+p\alpha,\label{eq:enthalphy}
%\end{equation}
%where $\alpha$ is specific volume of moist air, the right-hand side of \eqref{eq:slt} can be written as
%\begin{align}
%T\delta s &=\delta e+p\delta \alpha,\\
% &=\delta h-\alpha \delta p,\label{eq:TdS}
%\end{align}
%provided no phase change occurs. For each component
%\begin{align}
%e^{(\ell)}&=c^{(\ell)}_vT,\\
%h^{(\ell)}&=c^{(\ell)}_pT+\alpha^{(\ell)}_0p,
%\end{align}
%where the specific heats $c_v^{(\ell)}$ and $c_p^{(\ell)}$ are assumed constant. For the gas phases, $c_p^{(\ell)}-c_v^{(\ell)}=R^{(\ell)}$ and $\alpha_0^{(\ell)}$=0, while for the condensates, which are assumed incompressible, $c_p^{(\ell)}=c_v^{(\ell)}$ (hence $R^{(\ell)}=0$) and $\alpha_0^{(\ell)}$ is the constant specific volume of condensate phase $\ell$. Assuming that specific energy and enthalphy are mass-weighted sums of specific energy and enthalphy of the constituents of moist air,
%\begin{align}
%e&=c_vT,\label{eq:e}\\
%h&=c_pT+\left(\frac{V^{(cond)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\right) p\label{eq:h},
%\end{align}
%where $V^{(cond)}=\sum_{\ell \in \mathcal{L}_{cond}} V^{(\ell)}=V-V^{(gas)}=\sum_{\ell \in \mathcal{L}_{cond}}m^{(\ell)}\alpha^{(\ell)}_0$ is the constant volume occupied by the condensates and
%\begin{align}
%c_v=\frac{\sum_{\ell \in \mathcal{L}_{all}} c_v^{(\ell)}m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}},\\
%c_p=\frac{\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)}m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}.%\label{eq:cp}
%\end{align}
%Our definitions of $h$ and $e$ should be consistent with the ideal gas law \eqref{eq:ptmp}. From \eqref{eq:e} and \eqref{eq:h} we get specific volume $\alpha$ using \eqref{eq:enthalphy}
%\begin{align}
%\alpha \equiv \frac{V}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}} &=\frac{h-e}{p},\\
% &=\frac{RT}{p}+\frac{V^{(cond)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}},\label{eq:tmpalpha}
%\end{align}
%where
%\begin{equation}
%R =\frac{\sum_{\ell \in \mathcal{L}_{all}} R^{(\ell)} m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}.
%\end{equation}
%Note that $c_p=R+c_v$. Using that $V-V^{(cond)}=V^{(gas)}$ we get
%\begin{equation}
%\frac{RT}{p}=\frac{V^{(gas)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}
%\end{equation}
%which is precisely \eqref{eq:ptmp} since
%\begin{align}
%p&=\frac{V}{V^{(gas)}}\left( \rho^{(d)}R^{(d)}T+\rho^{(wv)}R^{(wv)}T\right),\\
% &=\frac{1}{V^{(gas)}}\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}R^{(\ell)}T,\\
% &=\frac{\left(\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}\right)}{V^{(gas)}}RT.\label{eq:plall}
%\end{align}
%Furthermore, substituting \eqref{eq:h} into $\delta Q=\delta h-\alpha \delta p$, the thermodynamic equation can be written as
%\begin{align}
%\delta Q&=c_p\delta T+\frac{V^{(cond)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\delta p-\alpha \delta p,\\
% &=c_p\delta T+\frac{V^{(cond)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\delta p-\frac{V}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}} \delta p,\\
% &=c_p\delta T-\frac{V^{(gas)}}{\sum_{\ell \in \mathcal{L}_{all}}m^{(\ell)}}\delta p,
%\end{align}
%and when using \eqref{eq:plall} we finally get
%\begin{equation}
%\delta T-\frac{RT}{c_p\, p}\delta p=\frac{\delta Q}{c_p},%\label{eq:thermo1}
%\end{equation}
%If we assume that the condensates do not occupy any volume then \eqref{eq:thermo1} can be written as
%\begin{equation}
%\delta T-\frac{1}{c_p\, \rho}\delta p=\frac{\delta Q}{c_p},\text{ if }V^{(cond)}=0.\label{eq:thermo2}
%\end{equation}
%Henceforth we will assume that $V^{(cond)}=0$.
%where
%\begin{equation}
%p=\rho^{(d)}R^{(d)}T+\rho^{(wv)}R^{(wv)}T,
%\end{equation}
%and
%The first law of thermodynamics for a mixture of dry air, water vapor, cloud liquid water, cloud ice, rain and snow is given by
%\begin{equation}
%\frac{\sum_{\ell\in \mathcal{L}_{all}} c_{v}^{(\ell)}\, m^{(\ell)}}{\sum_{\ell\in \mathcal{L}_{all}} m^{(\ell)}}\delta T+p\delta \alpha=\delta Q,\label{eq:1stT}
%\end{equation}
%where $\delta Q$ is the amount of heat per unit mass that is supplied reversibly to the moist air, $\delta T$ and $\delta \alpha$ are the moist air temperature and specific volume changes, and $c_v^{(\ell)}$ is the heat capacity at constant volume for component $\ell$ of moist air. Note that
%\begin{eqnarray}
%\left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right)p\delta \alpha &=& p \delta \left[ \left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)} \right)\alpha \right],\label{eq:pdalpha}\\
% &=& (1+m^{(wv)})p\delta \alpha^{(gas)},\label{eq:pdalpha2}\\
% &=& \left(R^{(d)}+m^{(wv)}R^{(wv)}\right)\left(\delta T-\frac{T}{p}\delta p\right)\label{eq:dt}.
%\end{eqnarray}
%where, in \eqref{eq:pdalpha}, we have assumed that $m^{(\ell)}$ is constant. To get \eqref{eq:pdalpha2} we substituted \eqref{eq:vol} into the right-hand side of \eqref{eq:pdalpha} and assumed that the condensates are incompressible ($\delta \alpha^{(\ell)}=0$ for $\ell \in \mathcal{L}_{cond}$). Finally \eqref{eq:ig3} has been used to substitute for $\alpha^{(gas)}$ in \eqref{eq:dt}.
%Using \eqref{eq:dt} in the first law of thermodynamics \eqref{eq:1stT}, substituting $R^{(d)}=c_p^{(d)}-c_v^{(d)}$ and $R^{(wv)}=c_p^{(wv)}-c_{v}^{(wv)}$, using that $c_p^{(\ell)}=c^{(\ell)}_v$ for the condensates (they are incompressible) and rearranging terms yields
%\begin{equation}
%\delta T-\frac{\left(R^{(d)}+m^{(wv)}R^{(wv)}\right)}{\left(\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)}m^{(\ell)}\right)}\frac{T}{p}\delta p=\frac{\left(\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right)}{\left(\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)}m^{(\ell)}\right)}\delta Q.\label{eq:thermo1}
%\end{equation}
%Equation \eqref{eq:thermo1} can be written in a more familiar form
%\begin{equation}
%\delta T-\frac{R}{c_p}\frac{T}{p}\delta p=\frac{1}{c_p}\delta Q\label{eq:thermo},
%\end{equation}
%if we define $c_p$ and $R$ as
%\begin{eqnarray}
%c_p&=&\frac{\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)}m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}, \\
%R &=&\frac{\sum_{\ell \in \mathcal{L}_{all}} R^{(\ell)} m^{(\ell)}}{\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}}.
%\end{eqnarray}
%where $R^{(\ell)}=0$ for $\ell \in \mathcal{L}_{cond}$. %%
%
%The thermodynamic equation \eqref{eq:thermo} may also be written in terms of full density
%\begin{equation}
%\delta T-\frac{1}{\rho\, c_p}\delta p=\frac{1}{c_p}\delta Q
%\end{equation}
%
\subsection{Vertical coordinate}\label{eq:vertical_coord}
\subsubsection{Definition}
Let $M^{(d)}_s$ be the mass of a column of dry air per unit area at the surface (i.e. the weight of dry air at the surface per unit area is $g\, M^{(d)}_s$, where $g$ is the gravitational acceleration; assumed constant) and $M_t^{(d)}$ is the mass of air per unit area in the column above the model top. Note that weight differs from mass in that weight constitutes the force exerted by the matter when it is in a gravitational field whereas mass is the amount of matter (which is invariant and does not depend on $g$). The SI unit for $M^{(d)}_s$ is $kg/m^2$ and the weight $g\, M^{(d)}_s$ is $\frac{1}{s^2}\frac{kg}{m}\equiv Pa$ (pressure). {\color{red}{We assume that the composition of dry air is constant and that there is no moisture}} above the model top so $p_t=g\, M_t^{(d)}$. Consider a general, terrain-following, vertical coordinate $\eta^{(d)}$ that is a function of the dry air mass $M^{(d)}$
%We assume that there is no moisture or condensate
\begin{equation}
\eta^{(d)}=h(M^{(d)},M_s^{(d)}),
\end{equation}
where $h(M_s^{(d)},M_s^{(d)})=1$ and $h(M_t^{(d)},M_s^{(d)})=0$. Note that by removing the superscript $(d)$ from the equations above (so that the dry variables represent moist variables) and assume that there are no condensates, then the vertical coordinate is the usual hybrid-pressure coordinate widely used in hydrostatic global modeling \citep{SB1981MWR}. The top and bottom boundary conditions are that $\dot{\eta}\left({M_s^{(d)},M_s^{(d)}}\right)=0$ and $\dot{\eta}\left( M_t^{(d)},M_s^{(d)}\right)=0$. Note that using a dry-mass vertical coordinate simplifies the coupling to physics since the dry mass coordinate remains constant even if water leaves the column.
\subsubsection{Partial pressure of dry air and mass of dry air}\label{sec:dryairp}
The observant reader will have noticed that we denote the mass of dry air per unit surface $M^{(d)}$, which exerts pressure $gM^{(d)}$, and not the dry air partial pressure $p^{(d)}$. As explained below this is because $gM^{(d)}\neq p^{(d)}$ in the presence of condensates.
The hydrostatic (moist) pressure at given height $z$ can be computed from the hydrostatic balance
\begin{align}
p(z)&=g\int^{z'=\infty}_{z'=z}\rho\, dz',\\
&=g\int^{z'=\infty}_{z'=z}\rho^{(d)} \left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)} \right)\, dz',\\
&=g\sum_{\ell \in \mathcal{L}_{all}} M^{(\ell)}(z),\label{eq:z'2}
\end{align}
where the right-hand side of \eqref{eq:z'2} is the mass of dry air, water vapor, cloud liquid, cloud ice, rain and snow per unit area above height $z$, respectively:
\begin{equation}
{M}^{(\ell)}(z)=\int^{z'=\infty}_{z'=z}\rho^{(d)} \, m^{(\ell)} \, dz'\label{eq:z'}.
\end{equation}
Using Dalton's law of partial pressures on the left-hand side of \eqref{eq:z'2}, one obtains the partial pressure at a certain height $z$ is
\begin{equation}
p^{(d)}(z)+p^{(wv)}(z)=g\sum_{\ell \in \mathcal{L}_{all}} {M}^{(\ell)}(z).\label{eq:dalton}
\end{equation}
From \eqref{eq:dalton} it is clear that in the presence of condensate one can not equate $p^{(d)}(z)$ with $g{M}^{(d)}(z)$, nor $p^{(wv)}(z)$ with $g{M}^{(wv)}(z)$. The partial pressures of dry air and water vapor are both affected by the mass of the condensates even though the condensates do not exert a gas pressure. Hence the partial pressure of dry air $p^{(d)}(z)$ at height $z$ is different from force exerted by the mass of dry air in Earth's gravitational field $gM^{(d)}(z)$; and similar for moisture. {\color{red}{A physical explanation is that when hydrometeors are falling at terminal velocity, the gravitational force pulling the hydrometeors downward is compensating by the upward frictional force of the gaseous atmosphere on the hydrometeors. This compensating force adds to the atmospheric pressure.}}
The hydrostatic balance for dry air mass, written in terms of differentials, is given by
\begin{equation}
dM^{(d)}(z)=-g\rho^{(d)}\, dz,\label{eq:dry_atm_hydro}
\end{equation}
whereas, in a moist atmosphere (with condensates), a dry air partial pressure hydrostatic equation does not hold
\begin{equation}
dp^{(d)}(z)\ne -g\, \rho^{(d)}\, dz.
\end{equation}
The partial pressure of dry air $p^{(d)}(z)$ at height $z$ will increase in the presence of condensates whereas the mass of dry air does not. The differential of the (moist) pressure can be written in terms of the dry air mass (under the hydrostatic assumption) though:
\begin{equation}
dp(z)=-g\, \rho \, dz = -g\rho^{(d)} \left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right)\, dz = g\, dM^{(d)}(z)\left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right).
\end{equation}
In all, $g\, M^{(d)}(z)$ is equal to $p^{(d)}(z)$ at height $z$ {\color{red}{only if there are no condensates present at higher levels}} (i.e. air is a gas only) and similarly for water vapor. Henceforth we drop the notation of the vertical dependence (in this section we used $z$) on $M^{(\ell)}(z)=M^{(\ell)}$. Since $\eta^{(d)}$ is the vertical coordinate, $M^{(\ell)}$ will henceforth refer to the mass per unit area of water form $\ell$ above $\eta^{(d)}$. The weight of dry air per unit area $g M^{(d)}$ is not a directly measurable quantity but a theoretical construction for the dry-mass vertical coordinate. Only moist pressure (or simply {\em{pressure}}) is directly measurable.
%p_s=p^{(d)}+p^{(wv)}=\int
%
\subsection{Equations of motion}\label{eq:eqnsmotion}
The $\eta^{(d)}$-coordinate adiabatic and frictionless atmospheric primitive equations assuming floating Lagrangian vertical coordinates \citep{S1945JAS,L2004MWR} can be written in vector invariant form as
\begin{align}
\frac{\partial \mathbf{v}}{\partial t} + \left( \zeta + f \right) {\hat{\vec{k}}} \times \mathbf{v} + \nabla_{\eta^{(d)}} \left( \frac12 \mathbf{v}^2 + \Phi \right) + \frac{1}{\rho} \nabla_{\eta^{(d)}} p &= 0,\label{E:PEmom} \\
\frac{\partial T}{\partial t} + \mathbf{v} \cdot \nabla_{\eta^{(d)}} T - \frac{1}{c_p \rho} \omega &= 0, \label{E:PEtemp} \\
%\frac{\partial}{\partial t} \left(\frac{\partial M^{(d)}}{\partial \eta^{(d)}}\right) + \nabla_{\eta^{(d)}}\cdot \left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} \mathbf{v} \right) &= \nu \nabla^4_{\eta^{(d)}} \left(\frac{\partial M^{(d)}\quad }{\partial \eta^{(d)}}\right), \label{E:PEcont} \\
\frac{\partial}{\partial t} \left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} m^{(\ell)} \right) + \nabla_{\eta^{(d)}}\cdot \left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} m^{(\ell)} \mathbf{v} \right) &= 0, \quad \ell \in \mathcal{L}_{all}, \label{E:PEq}
\end{align}
where $\Phi$ is the geopotential height ($\Phi=g\, z$), ${\hat{\vec{k}}}$ is the unit vector normal to the surface of the sphere, $\mathbf{v}=(u,v)$ is the velocity vector with $u$ being the zonal velocity component and $v$ the meridional velocity component, $\zeta = {\hat{\vec{k}}} \cdot {\nabla \times} \mathbf{v}$ is vorticity, $f$ Coriolis parameter, and $\omega = dp/dt$ is the (moist) pressure vertical velocity with $d/dt=\frac{\partial }{\partial t}+\mathbf{v}\cdot \nabla_{\eta_d}$ being the material/total derivative along $\eta^{(d)}$.
The prognostic equations for $\mathbf{v}$, the temperature $T$, dry air mass ${\frac{\partial {M^{(d)}}}{\partial \eta^{(d)}}}$, and tracer mass ${\frac{\partial {M^{(d)}}}{\partial \eta^{(d)}}} m^{(\ell)}$ are solved with the diagnostic equation for geopotential height (hydrostatic balance)
\begin{equation}
\frac{\partial \Phi\quad }{\partial \eta^{(d)}}=-\frac{R^{(d)} \,T_v}{p}\frac{\partial p\quad }{\partial \eta^{(d)}},\label{eq:phi_1}
\end{equation}
where
\begin{equation}
\frac{\partial p\quad }{\partial \eta^{(d)}}=g\frac{\partial M^{(d)}}{\partial \eta^{(d)}}\left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right).
\end{equation}
For diagnosing vertical pressure velocity $\omega$ we note that
\begin{align}
\omega(\eta^{(d)})&=\frac{dp}{dt}(\eta^{(d)}),\\
&=\int_{\eta^{(d)}}^{\eta^{(d)}=0}\frac{d}{dt}\left( \frac{\partial p\quad }{\partial \eta^{(d)}}\right)d\eta^{(d)},\\
&=\int_{\eta^{(d)}}^{\eta^{(d)}=0}\frac{\partial}{\partial t}\left( \frac{\partial p\quad }{\partial \eta^{(d)}}\right)d\eta^{(d)}+\int_{\eta^{(d)}}^{\eta^{(d)}=0} \mathbf{v}\cdot \nabla_{\eta^{(d)}} \left( \frac{\partial p\quad }{\partial \eta^{(d)}}\right)d\eta^{(d)}.\label{eq:omega}
\end{align}
%
\subsection{Hyperviscosity and frictional heating}\label{sec:hypvervisfric}
The spectral-element method does not have implicit diffusion. Hyperviscosity operators are applied to the prognostic variables to dissipate energy near the grid scale \citep{DetAl2012IJHPCA}. Hyperviscosity also damps the propagation of spurious grid-scale modes \citep{AW2009SIAM} and, in particular, smoothes the solution at element boundaries where the basis-functions are least smooth ($C^0$-continuous). For the uniform resolution configuration constant hyperviscosity coefficients are used on all elements whereas the variable resolution configuration uses either a scaling of the coefficients according to individual element length scale \citep{ZetAl2014JCb} or a tensor-based hyperviscosity operator approach \citep{GetAl2014GMD}.
\subsubsection{Viscosity operator}\label{sec:hyper}
On the right-hand side of the equations of motion hyperviscosity terms are added. For the momentum equations \eqref{E:PEmom} the viscous terms are as follows. By using the vector identity $\nabla^2 \mathbf{v} = \nabla(\nabla \cdot \mathbf{v}) - \nabla \times (\nabla \times \mathbf{v}) $, the viscosity term splits into two terms. The first term damps divergent modes and the latter term damps rotational modes. Thereby one can damp divergent modes more (or less) than rotational modes by having different coefficients ($\nu_{div}$ and $\nu_{vor}$, respectively) in front of the respective terms
\begin{equation}
\nu_{div} \, \nabla(\nabla \cdot \mathbf{v}) -
\nu_{vor} \, \nabla \times (\nabla \times \mathbf{v}),\label{eq:vec_diff}
\end{equation}
The 4th-order hyperviscosity operator is computed by iteratively applying the Laplacian operator \eqref{eq:vec_diff} \citep[for a detailed derivation with metric terms see, e.g., ][]{U2014GMD}.
The dry air mass layer thickness is damped with $\nu_p \nabla^4\left\{ \frac{\partial M^{(d)}}{\partial \eta^{(d)}}\right\}$, temperature with $\nu_T \nabla^4 T$ {\color{red}{and tracers with $\nu_q \nabla^4 q$. The damping coefficients for divergence ($\nu_{div}$), vorticity ($\nu_{vor}$), level-thickness ($\nu_p$), temperature $(\nu_T)$ and tracers $\nu_q$ are resolution dependent and provided in Appendix \ref{app:nu}. These coefficients were determined empirically for stability and may have to be increased for specific applications such as data-assimilation cycling where additional damping to remove short-wavelengths due to imbalances may be necessary. Note that the viscosity coefficient for pressure, $\nu_p$, and tracers, $\nu_q$ should be the same otherwise the model is no longer 'free-stream' preserving (i.e. a constant mixing ratio is preserved; also referred to as mass-wind consistency in the literature).
The dispersion properties of CAM-SE with hyperviscosity are similar to A-grid models. There are no computational modes, but the grid scale modes are erratic with large phase errors \citep{AW2009SIAM,A2014JCP}. Empirically we have found that increasing $\nu_{div}$ and $\nu_p$ compared to $\nu_T$ and $\nu_{vor}$ is effective at damping grid-scale modes and noise resulting from the SE basis functions being least smooth, $C^0$, at element edges, while not making the total kinetic energy spectrum too dissipative at the high wavenumbers.}}
%The specific damping coefficients for divergence ($\nu_{div}$), vorticity ($\nu_{vor}$), level-thickness ($\nu_p$) and temperature $(\nu_T)$ are resolution specific and provided in Appendix \ref{app:nu}.
The horizontal hyperviscosity operator can be applied on $\eta_d$-surfaces, $\nabla^4=\nabla^4_{\eta_d}$, but it may be advantageous to apply the hyperviscosity operator on approximate dry-mass surfaces
\begin{equation}
\nu \nabla^4 \Xi =\nu \nabla^4_{\eta_d}\Xi -\nu \frac{\partial \Xi\quad }{\partial M^{(d)}} \nabla^4_{\eta_d}M^{(d)},\qquad \Xi=\mathbf{v}, T,
\end{equation}
\citep[p.58 in ][]{CAM5} to reduce spurious diffusion over steep topography. {\color{red}{This `correction' is currently not applied to tracers}}. In theory the damping of dry-mass layer thickness should be zero if hyperviscosity is applied on dry-mass surfaces. However, for stability it is necessary to damp dry-mass layer thickness, but instead of applying $\nabla^4$ to $\frac{\partial M^{(d)}}{\partial \eta^{(d)}}$ it is applied to the difference between $\frac{\partial M^{(d)}}{\partial \eta^{(d)}}$ and a smoothed version of $\frac{\partial M^{(d)}}{\partial \eta^{(d)}}$ referred to as $\left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}}\right)^{(ref)}$. The reference/smoothed dry-mass layer thickness is defined in Appendix \ref{app:ref_dp}.
In the top three layers second-order diffusion (Laplacian operator) is applied to the prognostic variables to provide a sponge layer. The sponge layer plays an important role in controlling the polar night jet in low-top models \citep[see, e.g., ][]{L2011IJHPC}.
%
\subsubsection{Frictional heating}\label{sec:frictional_heating}
Let $\delta \mathbf{v}$ be the change in the velocity vector due to diffusion of momentum. Then the change in kinetic energy due to hyperviscosity applied to $\mathbf{v}$ is $\frac{1}{2}\rho \mathbf{v} \cdot \delta \mathbf{v}$. This kinetic energy is converted to a heating rate by adding a heating term $\delta \mathcal{T}$ in the thermodynamic equation corresponding to the kinetic energy change
\begin{equation}
\rho c_p \delta \mathcal{T}=-\frac{1}{2}\rho \mathbf{v} \cdot \delta \mathbf{v} \Rightarrow
\delta \mathcal{T}=-\frac{1}{2 c_p}\left(\mathbf{v}\cdot \delta \mathbf{v}\right),\label{eq:tcp}
\end{equation}
\citep[p.71 in ][]{CAM5}. As shown in the results section \ref{sec:APE} this term is rather large and therefore important for good energy conservation characteristics of the dynamical core.
Before discretizing the equations of motion some important conservation properties of the equations are discussed. For models intended for long simulations, it is beneficial to have good energy conservation properties to minimize non-local restoration of global energy via global energy fixers \citep[e.g.][]{T2008JCP}. As an aside, it is noted that the global energy fixers take up a significant fraction of runtime at ultra-high resolution as the operations require global communications. Good AAM conservation may be important for the simulation of the Quasi-Biennial Oscillation (QBO) although the accurate simulation of the QBO also depends on vertical resolution, location of model top, {\color{red}{model dissipation (numerical and physical)}} and parameterizations \citep[such as nonorographic gravity wave drag {\color{red}{and convection parameterization}}; ][]{RSB2014JGR}. For the simulation of superrotating atmospheres (e.g., Venus), however, the conservation of angular momentum is crucial \citep{LCGPSWLJ2012JGR}. Below we discuss the conservation properties of the moist equations of motion used in this paper.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Global conservation: AAM and energy}\label{sec:aam}
The conservation law for AAM
\begin{equation}
\mathcal{M}=\left( u+\Omega r \cos \varphi \right) r \cos \varphi,
\end{equation}
(where $r$ is the mean radius of Earth, $\Omega$ angular velocity and $\varphi$ latitude), integrated over the entire domain is derived in Appendix \ref{app:conservation} and the final equation is
\begin{equation}
\frac{\partial}{\partial t}\int_{\eta=0}^{\eta=1}\iint_{\mathcal{S}}\left[ g\left( \sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}\right) \left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} \right) \mathcal{M} \right] dA\, d\eta^{(d)}=-\iint_{\mathcal{S}}\left[ p_s \frac{\partial z_s}{\partial \lambda}\right] dA,\label{eq:aam_final}
\end{equation}
where $\mathcal{S}$ is the global domain and $dA=r^2\cos\varphi d\lambda d\varphi$ is an infinitesimal surface area element on the sphere. The equation clearly separates the AAM of each component of moist air. The term in the square brackets on the right-hand side of \eqref{eq:aam_final} is referred to as the mountain torque. In the absence of topography, $z_s=0m$, \eqref{eq:aam_final} states that the angular momentum integrated over the entire domain is constant for the continuous equations of motion. Note that the AAM can be separated into a part ($\mathcal{M}_r$) associated with the motion of the atmosphere relative to Earth's surface (also known as wind AAM) and another part ($\mathcal{M}_{\Omega}$) associated with the angular velocity $\Omega$ of Earth's surface (referred to as mass AAM)
\begin{equation}
\mathcal{M}=\mathcal{M}_r+\mathcal{M}_\Omega=\left( u r \cos \varphi\right)+\left(\Omega r^2 \cos^2 \varphi \right) .
\end{equation}
The total energy equation integrated over the global domain is also derived in Appendix \ref{app:conservation}. The final equation is
\begin{equation}
\frac{\partial }{\partial t}\int_{\eta=0}^{\eta=1} \iint_\mathcal{S} \left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} \right)\sum_{\ell \in \mathcal{L}_{all}} \left[m^{(\ell)} \left(K+c_p^{(\ell)}T+\Phi_s \right)\right] dA d \eta^{(d)}=0,\label{eq:comprehensice_energy}
\end{equation}
where $K=\frac{1}{2}\mathbf{v}\cdot \mathbf{v}$. Note that the energy terms (inside square brackets) in \eqref{eq:comprehensice_energy} separate into contributions from each component of moist air. The total energy equation \eqref{eq:comprehensice_energy} shows that the equations of motion used in this paper conserve a moist total energy that includes condensates. That said, the CAM physics package energy fixer assumes that the `perfect' adiabatic dynamical core conserves an energy where $c_p^{(wv)}= c_p^{(d)}$, $c_p^{(\ell)}=0$ for $\ell\in \mathcal{L}_{cond}$ and $m^{(\ell)}=0$ for $\ell\in \mathcal{L}_{cond}$ in \eqref{eq:comprehensice_energy} \citep{WOHTTV2015JAMES} in which case the integrand in \eqref{eq:comprehensice_energy} becomes
\begin{equation}
\left( \frac{\partial M^{(d)}}{\partial \eta^{(d)}} \right)\left(1+m^{(wv)}\right)\left[ \left(K+c_p^{(d)}T+\Phi_s\right)\right].
\end{equation}
The discrepancy between the more comprehensive energy formula \eqref{eq:comprehensice_energy} and the CAM physics formula for total energy is about 0.5 $W/m^2$ \citep{T2011LNCSEb}. By only including dry air and water vapor in $\rho$ and setting $c_p^{(wv)}= c_p^{(d)}$ in the equations of motion, the dynamical core (in the absence of truncation errors) will conserve the energy used in CAM physics. {\color{red}{CAM-SE's total energy can be made consistent with CAM physics (described above) and it is enabled/disabled in the model code with the logical parameter $\tt{lcp\_moist}$.}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Discretized equations of motion}\label{sec:discretized_eqs}
\subsection{Vertical discretization}
In the vertical the atmosphere is discretized into $nlev$ floating Lagrangian layers. The vertical index is 1 for the upper most level and $nlev$ in the lower most level. The level interfaces are referred to as half-levels so that layer k is bounded by interface level $k+1/2$ and $k-1/2$. Since we are using a dry-mass vertical reference coordinate, the dry air mass per unit area at the layer interfaces is defined in terms of the hybrid coefficients $A$ and $B$
that are only a function of level index
\begin{equation}
M^{(d)}_{k+1/2}=A_{k+1/2}M^{(d)}_t+B_{k+1/2}M_s^{(d)},\label{eq:ABs}
\end{equation}
and similarly for full levels $k$ \color{red}{where $A_k=\frac{1}{2}\left( A_{k+1/2}+A_{k-/12}\right)$ and $B_k=\frac{1}{2}\left( B_{k+1/2}+B_{k-/12}\right)$}}. Note that if the $`d`$ is removed from the above equation and multiplied by gravity then the levels would be based on (moist) pressure, i.e. the vertical coordinate becomes the usual hybrid vertical coordinate used in many global hydrostatic models (assuming no condensates). Every ${\tt{se\_rsplit}}$ dynamics time-steps the prognostic variables on the floating Lagrangian levels are remapped to the dry-mass reference coordinate \eqref{eq:ABs} (see Section \ref{sec:verticalRemappin}).
CAM-SE is based on a Lorenz vertical staggering -- the full level prognostic variables are $\mathbf{v}_k$ (velocity vector), $T_k$ (temperature), $\Delta M^{(d)}_k=M^{(d)}_{k+1/2}-M^{(d)}_{k-1/2}$ (dry air mass per unit area in layer $k$), and $\Delta M^{(d)}_k m_k^{(\ell)}$ (tracer mass per unit area in a layer). At the level interfaces, the geopotential, (moist) pressure, and vertical velocity are defined. In the equations of motion, the full level (moist) pressure, geopotential height, vertical velocity and density are needed and choices must be made on how these variables are derived (in discretized space) from the prognostic variables. Here we use the energy and angular momentum conserving method of \citet{SB1981MWR} to compute these quantities at full levels. For simplicity, we do not consider the discretization in the horizontal in this section.
\subsubsection{Pressure}\label{sec:pk}
The half-level (moist) pressure is
\begin{equation}
p_{k+1/2}=p_t+g\sum_{j=1}^{k}\Delta M^{(d)}_j \left(\sum_{\ell \in \mathcal{L}_{all}} m_j^{(\ell)}\right),\label{eq:halfpfull}
\end{equation}
where $p_t$ is the pressure at the model top, $\eta^{(d)}=0$.
The full level (moist) pressure is obtained by averaging \citep{SB1981MWR}
\begin{equation}
p_k=\frac{p_{k+1/2}+p_{k-1/2}}{2}.\label{eq:pk}
\end{equation}
\subsubsection{Geopotential height}
Discretizing \eqref{eq:phi_1} in the vertical yields
\begin{equation}
\Phi_{k+1/2}=\Phi_s+R^{(d)}\sum_{j=k}^{nlev} \left[ \frac{(T_v)_j}{p_j}\right]\, \Delta p_j,
\end{equation}
where the (moist) pressure $p_k$ is given in \eqref{eq:pk}. The half level geopotential is computed by averaging
\begin{equation}
\Phi_k=\frac{\Phi_{k+1/2}+\Phi_{k-1/2}}{2}.
\end{equation}
\subsubsection{Vertical pressure velocity}
The vertical pressure velocity $\omega$ is obtained by discretizing \eqref{eq:omega}. The first term on the right-hand side of \eqref{eq:omega} can be computed by using the continuity equations for dry air mass and water masses in each layer \eqref{E:PEq}
\begin{equation}
\frac{\partial }{\partial t}\left[\sum_{j=1}^k \Delta M^{(d)}_j \left( \sum_{\ell \in \mathcal{L}_{all}} m_j^{(\ell)}\right)\right] = -\sum_{j=1}^k \nabla_{\eta^{(d)}}\cdot \left[ \Delta M^{(d)}_j\left(\sum_{\ell \in \mathcal{L}_{all}} m_j^{(\ell)} \right)\mathbf{v}_j\right],
\end{equation}
so that the vertical pressure velocity at half-levels is given by
\begin{equation}
\omega_{k+1/2}=-g\sum_{j=1}^k \nabla_{\eta^{(d)}}\cdot \left[ \Delta M^{(d)}_j\left(\sum_{\ell \in \mathcal{L}_{all}} m_j^{(\ell)} \right)\mathbf{v}_j \right]+g\sum_{j=1}^k \mathbf{v}_k \cdot \nabla_{\eta^{(d)}}\left[ \Delta M^{(d)}_j\left( \sum_{\ell \in \mathcal{L}_{all}} m_j^{(\ell)}\right)\right],
\end{equation}
and full level $\omega$ is
\begin{equation}
\omega_k=\frac{\omega_{k+1/2}+\omega_{k-1/2}}{2}.
\end{equation}
\subsubsection{Density}
Full level density is computed from the ideal gas law \eqref{eq:igl}
\begin{equation}
\rho_k=\frac{p_k}{R^{(d)} T_k^{(v)}},
\end{equation}
where the (moist) pressure $p_k$ is computed as described in section \ref{sec:pk}. The virtual temperature is based on prognostic variables defined at the layer centers, so simple substitution into \eqref{eq:tv} yields $\left(T^{(v)}\right)_k$, and similarly for the computation of $\left( c_p\right)_k$.
\subsubsection{Vertical remapping}\label{sec:verticalRemappin}
To avoid excessive deformation or even crossing of the floating Lagrangian levels, the prognostic variables defined at
\begin{equation}
M^{(d)}_{k+1/2}=M^{(d)}_t+\sum_{j=1}^{k}\Delta M^{(d)}_j,
\end{equation}
are remapped back to the (Eulerian) reference levels given in \eqref{eq:ABs} every ${\tt{se\_rsplit}}$ dynamics time-steps \citep{L2004MWR}. In the remapping process we enforce conservation of mass by mapping $m^{(\ell)}_k\Delta M^{(d)}_k$ using the piecewise-parabolic method \cite[PPM; ][]{CW1984JCP} and applying a standard shape-preserving limiter to avoid unphysical (in particular negative) mixing ratios in the remapping process. The internal energy is also conserved during the remapping process by mapping $\sum_{\ell \in \mathcal{L}_{all}} c_p^{(\ell)} m_k^{(\ell)}T_k \Delta M^{(d)}_k$. Note that temperature must be recovered from the internal energy using the remapped tracer values for $m^{(\ell)}_k$. A shape-preserving filter is also used for the remapping of internal energy so that an isothermal profile remains isothermal if the limiter is active on one of the water variables, $m^{(\ell)}_k$. Note that if the limiter is active at the same points for more than one of the water species then one can not guarantee preservation of an isothermal atmosphere when non-linear limiting filters are turned on \citep[see, e.g., Section 2.5 in ][]{LT2011QJR}.
The moist mass-weighted velocity components, $\sum_{\ell \in \mathcal{L}_{all}} m^{(\ell)}_k \Delta M^{(d)}_k u_k$ and $\sum_{\ell \in \mathcal{L}_{all}} m_k^{(\ell)} \Delta M^{(d)}_k v_k$ respectively, are remapped separately. Mapping the moist mass weighted velocity components conservatively leads to an AAM conserving vertical remapping algorithm. For the velocity components we do not enforce shape-preservation in the vertical remapping process to reduce the amount of kinetic energy dissipation.
\subsection{Horizontal discretization using the SE method}
\begin{figure}[h]
\centering
\includegraphics[scale=0.75]{figs/cs_gll4_2017}
\caption{The left panel shows the Gauss-Lobatto-Legendre (GLL) grid with $ N_p \times N_p$ quadrature points defined
on a standard element $[-1,1]^2$, where $N_p=4$. The right panel shows the cubed-sphere ($\mathcal{S}$) grid system tiled with
$6 N_e^2 $ spectral elements $\Omega_e$, where $N_e$ is the number of elements in each coordinate direction
on a panel (in this case $N_e=5$).
Each element $\Omega_e$ on $\mathcal{S}$ has the GLL grid structure. }
\label{fig:gll4}
\end{figure}
The CAM-SE
uses a cubed-sphere geometry originally introduced by \cite{S1972MWR} to represent the planet earth. The spherical surface
$\mathcal{S}$ is a patched domain, which is partitioned into non-overlapping quadrilateral elements
$\Omega_e$ such that $\mathcal{S} = \cup \, \Omega_e$ (see Fig.~\ref{fig:gll4}).
On $\mathcal{S}$ each 2D element $\Omega_e(x^1,x^2)$ defined in terms of
central (gnomonic) projection angles $x^1,x^2 \in [-\pi/4, \pi/4]$, which serve as the independent variables in the computational domain.
The mapping from cube to sphere results in a non-orthogonal curvilinear coordinate system on $\mathcal{S}$, with
the metric tensor $G_{ij}$ and analytic Jacobian $ \sqrt{G} = |G_{ij}|^{1/2}$, $i, j \in \{1,2\}$.
A physical vector quantity such as the wind vector $\mathbf{v} = (u,v)$, defined on $\mathcal{S}$
in orthogonal lat-lon coordinates, can be uniquely
expressed in tensor form using conventional notations as the covariant $(u_1,u_2)$ and contravariant $(u^1, u^2)$ vectors
using the $2 \times 2$ transformation matrix $\mathbf{D}$ associated with the gnomonic mapping
such that $\mathbf{D}^T\mathbf{D} = G_{ij}$ (see \cite{NTL2005MWR} for the details):
%
\begin{equation}
\left[ \begin{array}{c}
u \\ v
\end{array}
\right]
=
\mathbf{D} \, \left[ \begin{array}{c}
u^1 \\ u^2
\end{array}
\right] =
\mathbf{D}^{-T} \, \left[ \begin{array}{c}
u_1 \\ u_2
\end{array}
\right].
% \quad \mathbf{D}^T\mathbf{D} = G_{ij}.
\label{eq:covcontra}
\end{equation}
The governing equations defined in familiar vector form can also be expressed
in general tensor form. In order to describe the SE discretization process in simple terms, we consider the
the following conservation law on $\mathcal{S}$ for an arbitrary scalar $\phi$:
%
\begin{equation}
\frac{\partial \phi }{\partial t} + \nabla \cdot \mathbf{F}(\phi) = S(\phi),
\label{eq:se1}
\end{equation}
where
\begin{equation}
\nabla \cdot \mathbf{F}(\phi) = \frac{1}{\sqrt{G}} \left[ \frac{\partial \sqrt{G} F^1}{\partial x^1} +
\frac{\partial \sqrt{G} F^2}{\partial x^2} \right] .
\end{equation}
%
In the special case of the flux-form transport equation the
contravariant fluxes $(F^1, F^2) = (u^1 \phi , u^2 \phi)$, and $S(\phi)$ is an arbitrary source term.
% and the gradient $\nabla_h = (\partial/\partial x^1, \partial/\partial x^2)$ defined on computational domain $\mathcal{C}$ corresponding
% to $\mathcal{S}$ under the gnomonic mapping. Note that the flux-form transport equation is a special case of (\ref{eq:se1}), with flux function
% $(F^1, F^2) = (u^1 U, u^2 U)$.
\subsection{\normalsize SE spatial discretization in 2D}
%In order to describe the spectral-element (SE) horizontal discretization as used in CAM-SE, we consider the
%following generic form of a governing equation (33-35):
% \begin{equation}
% \frac{\partial U }{\partial t} + \nabla_h \cdot \mathbf{F}(U) = S(U) \quad {\rm in} \quad \mathcal{S}, \label{eq:se1}
% \end{equation}
% %
%where $U$ is a prognostic variable defined on the spherical domain $\mathcal{S}$ and $\nabla_h \cdot$ is the horizontal divergence operator.
%$\mathbf{F}$ is a general flux function and $S(U)$ is the source term, which can be
%a diffusive flux or any forcing term.
The SE solution process involves casting the partial differential equation in Galerkin form, i.e., by multiplying (\ref{eq:se1}) with a test (weight) function
$\psi$ and integrating over the domain $\mathcal{S}$,
\begin{equation}
\int_{\mathcal{S}} \psi \, \left[ \frac{\partial \phi }{\partial t} + \nabla \cdot \mathbf{F}(\phi) - S(\phi) \right] d\mathcal{S} = 0. \label{eq:se2}
\end{equation}
A computational form of (\ref{eq:se2}) is obtained by applying Green's theorem,
resulting in the weak Galerkin form, as follows:
%
\begin{equation}
\int_{\mathcal{S}} \psi \ \frac{\partial \phi }{\partial t} \, d\mathcal{S} =
\int_{\mathcal{S}} \nabla \psi \cdot \mathbf{F}(\phi) \, d\mathcal{S} +
\int_{\mathcal{S}} \psi \, S(\phi) \, d\mathcal{S}, \label{eq:se3}
\end{equation}
%
where the approximation to the solution $\phi$ and the test function belong to a polynomial space $V^{N}$.
The SE method consists of partitioning the domain into non-overlapping elements and solving the global problem
locally on each element, where the solution is approximated by using a set of basis (polynomial) functions of prescribed
order $N$. A basic assumption used in SE (or continuous Galerkin) method is that the global basis
corresponding to (\ref{eq:se3}) is
$C^0$ continuous.
Therefore the problem (\ref{eq:se3}) can be solved locally for each
element $\Omega_e$, if there is a mechanism by which the solution maintains $C^0$
continuity at the element boundaries as required
by the SE discretization.
%
%
For efficient evaluation of the integral equation (\ref{eq:se3}), the SE method employs the Gauss-Lobatto-Legendre (GLL)
quadrature rule for integrals and collocation differentiation for derivative operators. All the corresponding numerical
operations are performed on a square $[-1,1]^2$ known as the standard (or reference) element.
% For that each 2D element $\Omega_e(x^1,x^2)$ defined in terms of
% central angles $x^1,x^2 \in [-\pi/4, \pi/4]$, which are essentially the independent variables
% in the physical domain (Nair et al. 2004).
In order to facilitate local mesh refinement,
the spectral elements $\Omega_e$ on $\mathcal{S}$ are defined as arbitrary spherical quadrilaterals
in the CAM-SE grid system, which should be mapped onto the standard element.
A direct way to address this problem is establishing % a composite mapping in computational space.
a transformation $\mathcal{J}_e: \Omega_e \rightarrow [-1,1]^2$, where $\mathcal{J}_e$
may be considered as a composite mapping combining the gnomonic and the quadrilateral to standard-element mapping.
Let the Jacobian associated with the composite mapping be $J_e = J_e(\sqrt{G})$.
Then an arbitrary surface integral on $\Omega_e$ can be expressed in terms of local coordinates $\xi^1, \xi^2 \in [-1, 1] $
and the Jacobian $J_e$
%
\begin{equation}
\int_{\Omega_e} \psi (x^1,x^2) \, d\Omega_e = \int_{-1}^{1} \int_{-1}^{1} J_e(\xi^1,\xi^2) \, \psi(\xi^1,\xi^2) \, d\xi^1 \, d\xi^2
\approx \sum_{k=0}^{N} \sum_{l=0}^{N} w_k w_l \, J_e(\xi^1_k,\xi^2_l) \, \psi(\xi^1_k,\xi^2_l),
\label{eq:se4}
\end{equation}
%
where $w_k, w_l$ are the Gauss quadrature weights.
In the case of GLL quadrature rule, the nodal points $\xi_k$, $k=0, 1, \dots, N$,
are the roots of the polynomial $(1-\xi^2) P'_N(\xi) = 0$,
$\xi \in [-1,1]$; and the corresponding GLL quadrature weights are given by
\[ w_k = \frac{2}{N(N+1) \, [P_N(\xi_k)]^2 },
\]
where $P_N(\xi)$ is the Legendre polynomial of degree $N$.
For the SE discretization it is customary to use Lagrange polynomials $h_k(\xi)$, with roots at the
GLL quadrature points $\xi_k$, as basis functions. This setup provides discrete orthogonality
for the basis function $h_k(\xi)$, which is formally defined as:
%
\begin{equation}
h_k(\xi) = \frac{ (\xi^2-1)\, P'_N(\xi)}{ N (N+1)\, P_N(\xi_k) \,(\xi-\xi_k)}. \label{eq:se5}
\end{equation}
%
Note that there are $N+1 = N_p$ GLL quadrature points in 1D,
and $N_p \times N_p$ GLL points are needed for 2D spectral elements $\Omega_e$.
Figure~(\ref{fig:gll4}) shows the GLL grid with $N_p =4$ on the left panel,
and the right panel shows the cubed-sphere grid $\mathcal{S}$ tiled with elements $\Omega_e$,
each with the GLL grid points.
A semi-discrete form of (\ref{eq:se3}) on an element $\Omega_e$ can by obtained by
approximating the solution as a tensor product of 1D Lagrange basis $\{ h_k(\xi)\}_{k=0}^N$ such that
%
\begin{equation}
\phi |_{\Omega_e} \approx \phi^e(\xi^1,\xi^2,t) =
\sum_{k=0}^{N} \sum_{l=0}^{N} \phi^e_{kl}(t) \, h_k(\xi^1) \, h_l(\xi^2), \label{eq:se60}
\end{equation}
%
where $\phi^e_{kl}(t) = \phi^e(\xi_k^1, \xi_l^2,t) $ are the nodal grid-point values of the solution, and defining the test function as
$\psi(\xi^1,\xi^2) = h_k(\xi^1) \, h_l(\xi^2)$.\\
By using (\ref{eq:se4}) and the discrete orthogonality property of $h_k(\xi)$,
we get a completely decoupled system of ODEs on $\Omega_e$, for each grid-point $(k,l)$
%
\begin{eqnarray}
\widetilde M^e_{kl}\, \, \frac{d }{dt} \phi^e_{kl}(t) &= & A^e_{kl} + S^e_{kl} \label{eq:se6} \\
\widetilde M^e_{kl} &= & \int_{-1}^{1} \int_{-1}^{1} J_e \, h_k(\xi^1) \, h_l(\xi^2) \, d\xi^1 d\xi^2 = J_e(k,l) \, w_k \, w_l \\
A^e_{kl} &= & \sum_{i=0}^N J^{(1)}_e(i,l) \, F^1_{i l} \, D_{ik}^{(1)}\, w_i w_l +
\sum_{i=0}^N J^{(2)}_e(k, i) \, F^2_{k i} \, D_{l i}^{(2)} \, w_k w_i \\
S^e_{kl} &= &J_e(k,l) \, w_k w_l \, S(U_{kl})
\end{eqnarray}
%
%where $ \widetilde M^e_{kl}$ is the so-called mass matrix, $(F^1,F^2) = \mathbf{F}$ are the flux terms,
where $J^{(i)}_e = J_e \,\partial \xi^i / \partial x^i$ is the metric term and
$D^{(i)}_{lk}$ is the derivative matrix $h'_k(\xi^i_l)$,
along the $x^i$-direction and $ i \in \{1, 2\}$.
The ODEs (\ref{eq:se6}) can be written in a formal matrix-vector form
for $\Omega_e$ following
\cite{KS2013book}:
%
\begin{equation}
\widetilde{\mathbf{M}}^e\, \, \frac{d }{dt} \Phi^e = \mathbf{A}^e + \mathbf{S}^e + \mathbf{B}^e, \label{eq:se7}
\end{equation}
%
where $\widetilde{\mathbf{M}}^e$ is the so-called mass matrix, which is a diagonal matrix with entries $\widetilde M^e_{kl}$. $\mathbf{B}^e$
indicates the boundary terms for the element
$\Omega_e$, which is a key component linking the local and global problem (\ref{eq:se3}) and enforcing $C^0$ continuity
for solutions across element boundaries.
The global matrices associated with (\ref{eq:se3}) can be obtained
by summing the contributions from elemental matrices and this procedure is known as the
direct stiffness summation (DSS). However the global matrices are not explicitly constructed.
In practice, the DSS operation replaces interface values of two contiguous elements sharing the same physical location
by the weighted sum (average) so that the boundary nodes get unique values,
which maintains the continuity of the global solution across the element edges. This strategy has been adopted in CAM-SE.
Note that the DSS operation does not affect interior nodal values of any element, and preserves global conservation of the SE discretization
for (\ref{eq:se1}). The elemental discretization (\ref{eq:se7}) combined with the DSS operation leads
to the time-dependent system of ODE corresponding to (\ref{eq:se1}),
\begin{equation}
\frac{d }{dt} \phi(t) = DSS(\phi). \label{eq:se8}
\end{equation}
The details of the discretization of the dissipation operators are provided in Appendix \ref{sec:dissipation}.
{\color{red}{Note that nodes on the element boundary are shared between elements and that after each Runge-Kutta step the shared nodes will have different values. The elements are coupled by averaging the two solutions at the shared nodes (so the halo communicated between elements is only one node/point deep). This is referred to as the DSS operation. The basis function representation of the solution is therefore only $C^0$ at element boundaries. The ability to obtain high-order accuracy with only edge point communication is an attractive feature of the spectral element method \citep{MadayPatera87,canuto2007}. Another aspect of the spectral element is that the basis function representation is spectral on each element so if, for example, one of the quadrature values are changed then it affects the basis functions throughout the element (except at the GLL nodes)}}.
%
\subsection{Mimetic discretization}
A numerical method is mimetic (or compatible) if key integral properties of divergence, gradient and curl-operators are mimicked in discretized space. The CAM-SE discretization satisfies the divergence/gradient adjoint relation
\begin{equation}
\int \phi \nabla \cdot \mathbf{v} \, d\mathcal{S}+\int \mathbf{v} \cdot \nabla \phi \, d\mathcal{S}=0
\end{equation}
in discretized space \citep{TF2010JCP}. This property can be used to show the inherent conservation properties of CAM-SE {\color{red}{in the horizontal discretization \citep[see ][ for details]{T2011LNCSEb}. Mass is conserved and, in the absence of viscosity terms, energy is conserved with exact timestepping}}.
Since the CAM-SE discretization is mimetic the adiabatic, frictionless discretization of the equations of motion conserves total moist energy to within time-truncation errors. The equivalent internal energy change due to hyperviscosity damping of the velocity vector is added as frictional heating in the thermodynamic equation so the energy budget for the viscosity on the momentum equations is closed. The dissipation of energy due to hyperviscosity on temperature and dry-mass, however, is not energy-conserving. The vertical remapping does not conserve total energy either but it does conserve moist internal energy and AAM. {\color{red}{Hyperviscosity reduces variance but is a mass-conserving operation in CAM-SE.}}
% CAM-SE is based on a continuous Galerkin finite-element (or spectral-element) method \citep{TTI1997JCP} and is discretized using a cubed-sphere tiling of the sphere. Petascale scalability of CAM-SE was demonstrated in \cite{DetAl2012IJHPCA}. Also, CAM-SE provided refined mesh functionality in CAM \cite[e.g., ][]{SJDTT2008MWR,ZetAl2014JC}, improved accuracy of idealized baroclinic wave simulation \citep{LJTN2010JAMES}, conserved total energy to time-truncation errors \citep{T2011LNCSEb} and improved global axial angular momentum budgets compared to CAM-FV \citep{LBDL2014JAMES}. That said, the tracer transport component of CAM-SE appeared to be less accurate than CAM-FV for non-smooth tracer distributions \citep{LetAl2011GMD,HetAl2016QJRMS}. In an idealized terminator test in which two species react according to a reaction coefficient proportional to the solar terminator while being transported by an idealized 2D flow, CAM-SE produces errors larger than CAM-FV \citep{LCLVT2015GMD}. The errors are due to the limiter used for tracer transport that prevents oscillatory (and in particular negative) solutions for tracers \citep{GTS2014JCP}. In terms of computational throughput it was also found that CAM-SE was slower for large tracer counts (at least when run with core counts similar to the non-scalable CAM-FV).
\subsection{Temporal discretization}
In a typical CAM setup where the model top is approximately 40km, the maximum stable time-step for solving the continuity equation for water species $\ell$, $\ell \in \mathcal{L}_{water}$ (referred to as tracer advection), is limited by the maximum horizontal advective wind speed. The maximum stable time-step for the remaining equations of motion (thermodynamic equation, momentum equations and the continuity equation for dry air) is limited by the fastest gravity waves. Since the maximum advective winds are typically slower than the fastest gravity waves, different time-stepping methods are used for tracer advection and the remaining equations of motion. While the overall time-step is the same, different Runge-Kutta (RK) methods are used to maintain stability.
The SE tracer advection algorithm uses a three-stage RK strong-stability-preserving (SSP) time-stepping method, ensuring the time step will preserve any shape-preserving properties preserved by the underlying spatial discretization \citep{SR2002SIAM}. The shape-preserving filter used is described in \citet{GTS2014JCP}. The shape-preserving SE tracer advection algorithm is formally second-order accurate.
The momentum, thermodynamic and dry air continuity equations are solved using an explicit nonlinearly third-order accurate five-stage Runga-Kutta method based on \cite{KG1984MCSb} and described in \cite[][ see their equation (56)]{GU2016GMD}. For sake of completeness, this scheme is described in appendix \ref{app:KG53}, and will be referred to as KG53. {\color{red}{The choice of a five stage large-timestep Runga-Kutta method for dynamics and a three stage RK-SSP method allows both dynamics and tracers to use the same timestep. For mass / tracer-mass consistency, the dynamics computes a mean dry-air mass flux averaged over the five Runge-Kutte stages. This mean flux is then used by all three tracer RK stages.}} The inviscid equations of motion are advanced one dynamics time-step using the KG53 method followed by an application of the hyperviscosity operators through solving the advection-diffusion equation of the updated prognostic variables using forward Euler time-stepping. Note that it is necessary to subcycle the hyperviscosity-step for stability. The viscosity terms are computed as described in section \ref{sec:hyper} and discretized using the SE method presented in Appendix \ref{sec:dissipation}.
The time-steps in CAM-SE are controlled with namelist variables {\tt{se\_nsplit}}, {\tt{se\_rsplit}}, {\tt{se\_qsplit}},
{\tt{se\_hypervis\_subcycle}} so that the time-steps for vertical remapping $\Delta t_{remap}$, tracer advection $\Delta t_{trac}$ (RK3), KG53 time-stepping for non-tracers $\Delta t_{dyn}$, and hyperviscosity $\Delta t_{hyper}$ are
\begin{align}
\Delta t_{remap}&=\frac{\Delta t_{phys}}{\tt{se\_nsplit}},\\
\Delta t_{tracer}&=\frac{\Delta t_{phys}}{\tt{se\_nsplit}*\tt{se\_qsplit}},\\
\Delta t_{dyn}&=\frac{\Delta t_{phys}}{\tt{se\_nsplit*se\_rsplit}*\tt{se\_qsplit}},\\
\Delta t_{hyper}&=\frac{\Delta t_{phys}}{\tt{se\_nsplit*se\_rsplit*se\_hypervis\_subcycle}*\tt{se\_qsplit}},
\end{align}
where $\Delta t_{phys}$ is the time-step used for computing physics tendencies. For the $1^\circ$ configuration ($N_e=30$, $N_p=4$ where $N_e$ is the number of elements in each coordinate direction on a panel and $N_p$ is the number of quadrature points along each coordinate direction in an element) the physics time-step is $\Delta t_{phys}=30 min$, and the subcycling parameters are {\tt{se\_nsplit}=2}, {\tt{se\_rsplit=3}}, {\tt{se\_qsplit=1}} and {\tt{se\_hypervis\_subcycle=3}}. See Table \ref{table:subc} for other resolutions.
\begin{table}
\caption{The table shows physics time-step (column 3), sub-cycling parameters (columns 4-6) as a function of resolution (column 1-2). The horizontal resolution is specified in the format $ne30np4$ which refers to $N_e=30$ and $N_p=4$; similar for other resolutions. $N_e=0$ denotes a variable-resolution configuration. The approximate average quadrature node spacing at the Equator, $\Delta x_{ave}$ (in kilometers), is also listed (column 2). For all configurations presented in this paper {\tt{se\_qsplit}}=1.}
\centering
\begin{tabular}{llcccc}
\hline
Horizontal res. & $\Delta x_{ave}$ & $\Delta t_{phys}$ & {\tt{se\_nsplit}} & {\tt{se\_rsplit}} & {\tt{se\_hypervis\_}} \\
&&&&&{\tt subcycle} \\
\hline
{\tt{ne}}16{\tt{np4}} & $\sim$208km & 1800s & 1 & 3 & 3 \\
{\tt{ne}}30{\tt{np4}} & $\sim$111km & 1800s & 2 & 3 & 3 \\
{\tt{ne}}60{\tt{np4}} & $\sim$ 56km & 900s & 2 & 3 & 3 \\
{\tt{ne}}120{\tt{np4}} & $\sim$28km & 450s & 2 & 3 & 3 \\
{\tt{ne}}240{\tt{np4}} & $\sim$14km & 225s & 2 & 3 & 3 \\
{\tt{ne}}0{\tt{np4CONUS30x8}} & $\sim$111km$\rightarrow$ $\sim$14km & 600s & 5 & 3 & 4 \\
\hline
% \multicolumn{2}{l}{$^{a}$Footnote text here.}