1+ /*
2+ // * GNU GPL v3 License
3+ *
4+ * Copyright 2019 Niccolo` Tubini
5+ *
6+ * This program is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation, either version 3 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+ package it .geoframe .blogpsot .netcdf .monodimensionalproblemtimedependent ;
21+
22+ import java .io .IOException ;
23+ import oms3 .annotations .Author ;
24+ import oms3 .annotations .Description ;
25+ import oms3 .annotations .Documentation ;
26+ import oms3 .annotations .Execute ;
27+ import oms3 .annotations .In ;
28+ import oms3 .annotations .Keywords ;
29+ import oms3 .annotations .Label ;
30+ import oms3 .annotations .License ;
31+ import oms3 .annotations .Name ;
32+ import oms3 .annotations .Out ;
33+ import oms3 .annotations .Status ;
34+ import oms3 .annotations .Unit ;
35+ import ucar .ma2 .ArrayDouble ;
36+ import ucar .ma2 .ArrayDouble .D1 ;
37+ import ucar .ma2 .ArrayInt ;
38+ import ucar .ma2 .InvalidRangeException ;
39+ import ucar .nc2 .NetcdfFile ;
40+ import ucar .nc2 .Variable ;
41+
42+ @ Description ("This class reads a NetCDF containing 1D grid data." )
43+ @ Documentation ("" )
44+ @ Author (
name =
"Niccolo' Tubini" ,
contact =
"[email protected] " )
45+ @ Keywords ("Soil heat conduction, phase change, frozen soil, GEOframe, Permafrostnet" )
46+ @ Label ("GEOframe.NETCDF" )
47+ @ Name ("readFreezingThawing1Dgrid" )
48+ @ Status (Status .CERTIFIED )
49+ @ License ("General Public License Version 3 (GPLv3)" )
50+
51+ public class ReadNetCDFHeatAdvectionDiffusionGrid1D {
52+
53+ @ Description ("File name of NetCDF containing grid data" )
54+ @ In
55+ public String gridFilename ;
56+
57+ @ Description ("Number of control volume" )
58+ @ Out
59+ @ Unit ("-" )
60+ public int KMAX ;
61+
62+ @ Description ("eta coordinate of volume centroids: zero is at soil surface and and positive upward" )
63+ @ Out
64+ @ Unit ("m" )
65+ public double [] eta ;
66+
67+ @ Description ("eta coordinate of volume interfaces: zero is at soil surface and and positive upward." )
68+ @ Out
69+ @ Unit ("m" )
70+ public double [] etaDual ;
71+
72+ @ Description ("z coordinate of volume centroids: zero is at the bottom of the column and and positive upward" )
73+ @ Out
74+ @ Unit ("m" )
75+ public double [] z ;
76+
77+ @ Description ("z coordinate of volume interfaces: zero is at soil surface and and positive upward." )
78+ @ Out
79+ @ Unit ("m" )
80+ public double [] zDual ;
81+
82+ @ Description ("Water suction profile" )
83+ @ Out
84+ @ Unit ("m" )
85+ public double [] psi ;
86+
87+ @ Description ("Initial condition for temperature" )
88+ @ Out
89+ @ Unit ("K" )
90+ public double [] temperatureIC ;
91+
92+ @ Description ("Distance between consecutive controids, is used to compute gradients" )
93+ @ Out
94+ @ Unit ("m" )
95+ public double [] spaceDelta ;
96+
97+ @ Description ("Dimension of the control volume. It is used to integrate enthalpy function" )
98+ @ Out
99+ @ Unit ("m" )
100+ public double [] controlVolume ;
101+
102+ @ Description ("Control volume label identifying the equation state" )
103+ @ Out
104+ @ Unit ("-" )
105+ public int [] equationStateID ;
106+
107+ @ Description ("Control volume label identifying the set of paremeters describing the soil" )
108+ @ Out
109+ @ Unit ("-" )
110+ public int [] parameterID ;
111+
112+ @ Description ("Soil particles density" )
113+ @ Out
114+ @ Unit ("kg m-3" )
115+ public double [] soilParticlesDensity ;
116+
117+ @ Description ("Soil particles thermal conductivity" )
118+ @ Out
119+ @ Unit ("W m-2 K-1" )
120+ public double [] soilParticlesThermalConductivity ;
121+
122+ @ Description ("Soil particles specific heat capacity" )
123+ @ Out
124+ @ Unit ("J kg-1 m-3" )
125+ public double [] soilParticlesSpecificHeatCapacity ;
126+
127+ @ Description ("Adimensional water content at saturation" )
128+ @ Out
129+ @ Unit ("-" )
130+ public double [] thetaS ;
131+
132+ @ Description ("Adimensional residual water content" )
133+ @ Out
134+ @ Unit ("-" )
135+ public double [] thetaR ;
136+
137+ @ Description ("Melting temperature" )
138+ @ Out
139+ @ Unit ("K" )
140+ public double [] meltingTemperature ;
141+
142+ @ Description ("Hydraulic conductivity at saturation" )
143+ @ Out
144+ @ Unit ("m/s" )
145+ public double [] Ks ;
146+
147+ @ Description ("Aquitard compressibility" )
148+ @ Out
149+ @ Unit ("1/Pa" )
150+ public double [] alphaSS ;
151+
152+ @ Description ("Water compressibility" )
153+ @ Out
154+ @ Unit ("1/Pa" )
155+ public double [] betaSS ;
156+
157+ @ Description ("SWRC parameter 1. This depends on the SWRC used, look at the documentation." )
158+ @ Out
159+ @ Unit ("-" )
160+ public double [] par1SWRC ;
161+
162+ @ Description ("SWRC parameter 2. This depends on the SWRC used, look at the documentation." )
163+ @ Out
164+ @ Unit ("-" )
165+ public double [] par2SWRC ;
166+
167+ @ Description ("SWRC parameter 3. This depends on the SWRC used, look at the documentation." )
168+ @ Out
169+ @ Unit ("-" )
170+ public double [] par3SWRC ;
171+
172+ @ Description ("SWRC parameter 4. This depends on the SWRC used, look at the documentation." )
173+ @ Out
174+ @ Unit ("-" )
175+ public double [] par4SWRC ;
176+
177+ @ Description ("Fifth SWRC parameter. This depends on the SWRC used, look at the documentation." )
178+ @ Out
179+ @ Unit (" " )
180+ public double [] par5SWRC ;
181+
182+ private int [] size ;
183+ private int [] size1 ;
184+ private int [] sizeParameter ;
185+ // private int[] sizeCellSize;
186+ private int step = 0 ;
187+
188+ @ Execute
189+ /**
190+ * Read the computational grid.
191+ **/
192+ public void read () throws IOException {
193+
194+ if (step == 0 ) {
195+
196+ // Open the file. The ReadOnly parameter tells netCDF we want
197+ // read-only access to the file.
198+ NetcdfFile dataFile = null ;
199+ String filename = gridFilename ;
200+ // Open the file.
201+ try {
202+
203+ dataFile = NetcdfFile .open (filename , null );
204+
205+ // Retrieve the variables named "___"
206+ Variable dataKMAX = dataFile .findVariable ("KMAX" );
207+ Variable dataEta = dataFile .findVariable ("eta" );
208+ Variable dataEtaDual = dataFile .findVariable ("etaDual" );
209+ Variable dataZ = dataFile .findVariable ("z" );
210+ Variable dataZDual = dataFile .findVariable ("zDual" );
211+ Variable dataPsiIC = dataFile .findVariable ("psi0" );
212+ Variable dataTemperatureIC = dataFile .findVariable ("T0" );
213+ Variable dataSpaceDelta = dataFile .findVariable ("spaceDelta" );
214+ Variable dataControlVolume = dataFile .findVariable ("controlVolume" );
215+ Variable dataEquationStateID = dataFile .findVariable ("equationStateID" );
216+ Variable dataParameterID = dataFile .findVariable ("parameterID" );
217+
218+ Variable dataSoilParticlesDensity = dataFile .findVariable ("soilParticlesDensity" );
219+ Variable dataThermalConductivitySoilParticles = dataFile .findVariable ("thermalConductivitySoilParticles" );
220+ Variable dataSpecificThermalCapacitySoilParticles = dataFile .findVariable ("specificThermalCapacitySoilParticles" );
221+ Variable dataThetaS = dataFile .findVariable ("thetaS" );
222+ Variable dataThetaR = dataFile .findVariable ("thetaR" );
223+ Variable dataMeltingTemperature = dataFile .findVariable ("meltingTemperature" );
224+ Variable dataKs = dataFile .findVariable ("ks" );
225+ Variable dataAlphaSS = dataFile .findVariable ("alphaSpecificStorage" );
226+ Variable dataBetaSS = dataFile .findVariable ("betaSpecificStorage" );
227+ Variable dataPar1SWRC = dataFile .findVariable ("par1SWRC" );
228+ Variable dataPar2SWRC = dataFile .findVariable ("par2SWRC" );
229+ Variable dataPar3SWRC = dataFile .findVariable ("par3SWRC" );
230+ Variable dataPar4SWRC = dataFile .findVariable ("par4SWRC" );
231+ Variable dataPar5SWRC = dataFile .findVariable ("par5SWRC" );
232+
233+
234+ size = dataEta .getShape ();
235+
236+ KMAX = 0 ;
237+ eta = new double [size [0 ]];
238+ etaDual = new double [size [0 ]];
239+ z = new double [size [0 ]];
240+ zDual = new double [size [0 ]];
241+ controlVolume = new double [size [0 ]];
242+ psi = new double [size [0 ]];
243+ temperatureIC = new double [size [0 ]];
244+ equationStateID = new int [size [0 ]];
245+ parameterID = new int [size [0 ]];
246+
247+ size1 = dataSpaceDelta .getShape ();
248+ spaceDelta = new double [size1 [0 ]];
249+
250+
251+ sizeParameter = dataPar1SWRC .getShape ();
252+ soilParticlesDensity = new double [sizeParameter [0 ]];
253+ soilParticlesThermalConductivity = new double [sizeParameter [0 ]];
254+ soilParticlesSpecificHeatCapacity = new double [sizeParameter [0 ]];
255+ thetaS = new double [sizeParameter [0 ]];
256+ thetaR = new double [sizeParameter [0 ]];
257+ meltingTemperature = new double [sizeParameter [0 ]];
258+ par1SWRC = new double [sizeParameter [0 ]];
259+ par2SWRC = new double [sizeParameter [0 ]];
260+ par3SWRC = new double [sizeParameter [0 ]];
261+ par4SWRC = new double [sizeParameter [0 ]];
262+ par5SWRC = new double [sizeParameter [0 ]];
263+ Ks = new double [sizeParameter [0 ]];
264+ alphaSS = new double [sizeParameter [0 ]];
265+ betaSS = new double [sizeParameter [0 ]];
266+
267+ ArrayDouble .D1 dataArrayEta = (ArrayDouble .D1 ) dataEta .read (null , size );
268+ ArrayDouble .D1 dataArrayEtaDual = (ArrayDouble .D1 ) dataEtaDual .read (null , size );
269+ ArrayDouble .D1 dataArrayZ = (ArrayDouble .D1 ) dataZ .read (null , size );
270+ ArrayDouble .D1 dataArrayZDual = (ArrayDouble .D1 ) dataZDual .read (null , size );
271+ ArrayDouble .D1 dataArrayPsiIC = (ArrayDouble .D1 ) dataPsiIC .read (null , size );
272+ ArrayDouble .D1 dataArrayTemperatureIC = (ArrayDouble .D1 ) dataTemperatureIC .read (null , size );
273+ ArrayDouble .D1 dataArraySpaceDelta = (ArrayDouble .D1 ) dataSpaceDelta .read (null , size1 );
274+ ArrayDouble .D1 dataArrayControlVolume = (ArrayDouble .D1 ) dataControlVolume .read (null , size );
275+ ArrayInt .D1 dataArrayEquationStateID = (ArrayInt .D1 ) dataEquationStateID .read (null , size );
276+ ArrayInt .D1 dataArrayParameterID = (ArrayInt .D1 ) dataParameterID .read (null , size );
277+ ArrayDouble .D1 dataArraySoilParticlesDensity = (ArrayDouble .D1 ) dataSoilParticlesDensity .read (null , sizeParameter );
278+ ArrayDouble .D1 dataArrayThermalConductivitySoilParticles = (ArrayDouble .D1 ) dataThermalConductivitySoilParticles .read (null , sizeParameter );
279+ ArrayDouble .D1 dataArraySpecificThermalCapacitySoilParticles = (ArrayDouble .D1 ) dataSpecificThermalCapacitySoilParticles .read (null , sizeParameter );
280+ ArrayDouble .D1 dataArrayThetaS = (ArrayDouble .D1 ) dataThetaS .read (null , sizeParameter );
281+ ArrayDouble .D1 dataArrayThetaR = (ArrayDouble .D1 ) dataThetaR .read (null , sizeParameter );
282+ ArrayDouble .D1 dataArrayMeltingTemperature = (ArrayDouble .D1 ) dataMeltingTemperature .read (null , sizeParameter );
283+ ArrayDouble .D1 dataArrayKs = (ArrayDouble .D1 ) dataKs .read (null , sizeParameter );
284+ ArrayDouble .D1 dataArrayAlphaSS = (ArrayDouble .D1 ) dataAlphaSS .read (null , sizeParameter );
285+ ArrayDouble .D1 dataArrayBetaSS = (ArrayDouble .D1 ) dataBetaSS .read (null , sizeParameter );
286+ ArrayDouble .D1 dataArrayPar1SWRC = (ArrayDouble .D1 ) dataPar1SWRC .read (null , sizeParameter );
287+ ArrayDouble .D1 dataArrayPar2SWRC = (ArrayDouble .D1 ) dataPar2SWRC .read (null , sizeParameter );
288+ ArrayDouble .D1 dataArrayPar3SWRC = (ArrayDouble .D1 ) dataPar3SWRC .read (null , sizeParameter );
289+ ArrayDouble .D1 dataArrayPar4SWRC = (ArrayDouble .D1 ) dataPar4SWRC .read (null , sizeParameter );
290+ ArrayDouble .D1 dataArrayPar5SWRC = (ArrayDouble .D1 ) dataPar5SWRC .read (null , sizeParameter );
291+
292+
293+
294+
295+
296+
297+ KMAX = dataKMAX .readScalarInt ();
298+ for (int i = 0 ; i < size [0 ]; i ++) {
299+
300+ eta [i ] = dataArrayEta .get (i );
301+ etaDual [i ] = dataArrayEtaDual .get (i );
302+ z [i ] = dataArrayZ .get (i );
303+ zDual [i ] = dataArrayZDual .get (i );
304+ psi [i ] = dataArrayPsiIC .get (i );
305+ temperatureIC [i ] = dataArrayTemperatureIC .get (i );
306+ controlVolume [i ] = dataArrayControlVolume .get (i );
307+ equationStateID [i ] = (int ) dataArrayEquationStateID .get (i );
308+ parameterID [i ] = (int ) dataArrayParameterID .get (i );
309+
310+ }
311+
312+ for (int i = 0 ; i < size1 [0 ]; i ++) {
313+
314+ spaceDelta [i ] = dataArraySpaceDelta .get (i );
315+
316+ }
317+
318+ for (int i = 0 ; i < sizeParameter [0 ]; i ++) {
319+
320+ soilParticlesDensity [i ] = dataArraySoilParticlesDensity .get (i );
321+ soilParticlesThermalConductivity [i ] = dataArrayThermalConductivitySoilParticles .get (i );
322+ soilParticlesSpecificHeatCapacity [i ] = dataArraySpecificThermalCapacitySoilParticles .get (i );
323+ thetaS [i ] = dataArrayThetaS .get (i );
324+ thetaR [i ] = dataArrayThetaR .get (i );
325+ meltingTemperature [i ] = dataArrayMeltingTemperature .get (i );
326+ Ks [i ] = dataArrayKs .get (i );
327+ alphaSS [i ] = dataArrayAlphaSS .get (i );
328+ betaSS [i ] = dataArrayBetaSS .get (i );
329+ par1SWRC [i ] = dataArrayPar1SWRC .get (i );
330+ par2SWRC [i ] = dataArrayPar2SWRC .get (i );
331+ par3SWRC [i ] = dataArrayPar3SWRC .get (i );
332+ par4SWRC [i ] = dataArrayPar4SWRC .get (i );
333+ par5SWRC [i ] = dataArrayPar5SWRC .get (i );
334+
335+ }
336+
337+
338+ } catch (InvalidRangeException e ) {
339+ e .printStackTrace ();
340+
341+ } finally {
342+ if (dataFile != null )
343+ try {
344+ dataFile .close ();
345+ } catch (IOException ioe ) {
346+ ioe .printStackTrace ();
347+ }
348+ }
349+
350+ System .out .println ("*** SUCCESS reading file " + gridFilename );
351+
352+ }
353+ step ++;
354+
355+ }
356+ }
0 commit comments