示例#1
0
def test_output(file_name):
    LW_Test.write(file_name, file_format='yaml')
    with open(get_absolute_path(f'{file_name}.yaml')) as new, \
        open(get_absolute_path('$PF_SRC/test/correct_output/LW_test_ref.yaml.ref')) as ref:
        if new.read() == ref.read():
            print('Success we have the same file')
            return True
        else:
            print('Files are different')
            return False
示例#2
0
def verify_vegp_data(data):
    assert data

    path = get_absolute_path('$PF_SRC/test/correct_output/vegp_data.ref.json')
    with open(path, 'r') as rf:
        ref_data = json.load(rf)

    assert data == ref_data
示例#3
0
def test_clmin_round_trip(clm):
    path = Path(get_absolute_path('drv_clmin.dat'))
    if path.exists():
        path.unlink()

    CLMExporter(clm).write_input()

    new_clm = Run('clm', __file__)
    CLMImporter(new_clm).input_file(path)
    verify_clmin_data(new_clm)
示例#4
0
def verify_vegm_data(data):
    # Test the shape and a few data points
    assert data.shape == (5, 5, 23)
    assert data[1, 1, 14] == 1
    assert data[3, 4, 1] == -98.138
    assert data[1, 2, 3] == 0.265

    # Now test the whole array
    path = get_absolute_path('$PF_SRC/test/correct_output/drv_vegm.ref.npy')
    ref_data = np.load(path)
    assert np.array_equal(data, ref_data)
示例#5
0
 def load_csv_file(self, tableFile, encoding='utf-8-sig'):
     with open(get_absolute_path(tableFile), 'r',
               encoding=encoding) as csv_file:
         data_line = False
         for line in csv_file.readlines():
             tokens = _csv_line_tokenizer(line)
             if data_line:
                 self._process_data_line(tokens)
             else:
                 data_line = self._process_first_line(tokens)
     return self
示例#6
0
def test_vegp_round_trip(clm):
    path = Path(get_absolute_path('drv_vegp.dat'))
    if path.exists():
        path.unlink()

    CLMExporter(clm).write_parameters()

    new_clm = Run('clm', __file__)
    veg_params = new_clm.Solver.CLM.Vegetation.Parameters

    # Set the land cover items
    veg_params.LandNames = veg_params.LandNames

    CLMImporter(new_clm).parameters_file(path)
    verify_vegp_data(new_clm)
示例#7
0
    def load_csv_file(self, table_file, encoding='utf-8-sig'):
        """Method to load a .csv file of a table of subsurface parameters

        Args:
            table_file (str): Path to the input .csv file.
            encoding='utf-8-sig': encoding of input file.
        """
        with open(get_absolute_path(table_file), 'r',
                  encoding=encoding) as csv_file:
            data_line = False
            for line in csv_file:
                tokens = _csv_line_tokenizer(line)
                if data_line:
                    self._process_data_line(tokens)
                else:
                    data_line = self._process_first_line(tokens)
        return self
示例#8
0
sabino.ComputationalGrid.NZ = 20

#-----------------------------------------------------------------------------
# Names of the GeomInputs
#-----------------------------------------------------------------------------

sabino.GeomInput.Names = 'domaininput'

sabino.GeomInput.domaininput.GeomName = 'domain'
sabino.GeomInput.domaininput.GeomNames = 'domain'

#-----------------------------------------------------------------------------
# PFSOL generation
#-----------------------------------------------------------------------------

sabino_mask = load_patch_matrix_from_sa_file(get_absolute_path('$PF_SRC/test/input/Sabino_Mask.sa'))
# sabino_mask = load_patch_matrix_from_asc_file(get_absolute_path('$PF_SRC/test/input/Sabino_Mask.asc'))
# sabino_mask = load_patch_matrix_from_image_file(get_absolute_path('$PF_SRC/test/input/Sabino_Mask.png'))
# sabino_mask = load_patch_matrix_from_image_file(get_absolute_path('$PF_SRC/test/input/Sabino_Mask.tiff'))

SolidFileBuilder(top=1, bottom=2, side=3) \
  .mask(sabino_mask) \
  .write('sabino_domain.pfsol', xllcorner=0, yllcorner=0, cellsize=90, vtk=True) \
  .for_key(sabino.GeomInput.domaininput)

#-----------------------------------------------------------------------------

sabino.Geom.domain.Patches = 'top bottom edge'

#-----------------------------------------------------------------------------
# Domain Geometry
示例#9
0
    def write(self, name, xllcorner=0, yllcorner=0, cellsize=0, vtk=False):
        self.name = name
        output_file_path = get_absolute_path(name)
        if self.mask_array is None:
            raise Exception('No mask were define')

        jSize, iSize = self.mask_array.shape
        leftMask = np.zeros((jSize, iSize), dtype=np.int16)
        rightMask = np.zeros((jSize, iSize), dtype=np.int16)
        backMask = np.zeros((jSize, iSize), dtype=np.int16)
        frontMask = np.zeros((jSize, iSize), dtype=np.int16)
        bottomMask = np.zeros((jSize, iSize), dtype=np.int16)
        topMask = np.zeros((jSize, iSize), dtype=np.int16)

        for j in range(jSize):
            for i in range(iSize):
                if self.mask_array[j, i] != 0:
                    patch_value = 0 if self.patch_ids_side is None else self.patch_ids_side[
                        j, i]
                    # Left (-x)
                    if i == 0 or self.mask_array[j, i - 1] == 0:
                        leftMask[
                            j,
                            i] = patch_value if patch_value else self.side_id

                    # Right (+x)
                    if i + 1 == iSize or self.mask_array[j, i + 1] == 0:
                        rightMask[
                            j,
                            i] = patch_value if patch_value else self.side_id

                    # Back (-y) (y flipped)
                    if j + 1 == jSize or self.mask_array[j + 1, i] == 0:
                        backMask[
                            j,
                            i] = patch_value if patch_value else self.side_id

                    # Front (+y) (y flipped)
                    if j == 0 or self.mask_array[j - 1, i] == 0:
                        frontMask[
                            j,
                            i] = patch_value if patch_value else self.side_id

                    # Bottom (-z)
                    patch_value = 0 if self.patch_ids_bottom is None else self.patch_ids_bottom[
                        j, i]
                    bottomMask[
                        j, i] = patch_value if patch_value else self.bottom_id

                    # Top (+z)
                    patch_value = 0 if self.patch_ids_top is None else self.patch_ids_top[
                        j, i]
                    topMask[j, i] = patch_value if patch_value else self.top_id

        # Generate asc / sa files
        writeFn = write_patch_matrix_as_asc
        settings = {
            'xllcorner': xllcorner,
            'yllcorner': yllcorner,
            'cellsize': cellsize,
            'NODATA_value': 0,
        }
        short_name = name[:-6]

        left_file_path = get_absolute_path(f'{short_name}_left.asc')
        writeFn(leftMask, left_file_path, **settings)

        right_file_path = get_absolute_path(f'{short_name}_right.asc')
        writeFn(rightMask, right_file_path, **settings)

        front_file_path = get_absolute_path(f'{short_name}_front.asc')
        writeFn(frontMask, front_file_path, **settings)

        back_file_path = get_absolute_path(f'{short_name}_back.asc')
        writeFn(backMask, back_file_path, **settings)

        top_file_path = get_absolute_path(f'{short_name}_top.asc')
        writeFn(topMask, top_file_path, **settings)

        bottom_file_path = get_absolute_path(f'{short_name}_bottom.asc')
        writeFn(bottomMask, bottom_file_path, **settings)

        # Trigger conversion
        print('=== pfmask-to-pfsol ===: BEGIN')
        extra = []
        if vtk:
            extra.append('--vtk')
            extra.append(f'{output_file_path[:-6]}.vtk')
        os.system(
            f'$PARFLOW_DIR/bin/pfmask-to-pfsol --mask-top {top_file_path} --mask-bottom {bottom_file_path} --mask-left {left_file_path} --mask-right {right_file_path} --mask-front {front_file_path} --mask-back {back_file_path} --pfsol {output_file_path} {" ".join(extra)}'
        )
        print('=== pfmask-to-pfsol ===: END')
        return self
示例#10
0
#-----------------------------------------------------------------------------
# Test CLM with multiple reuse values for input.  The same test is run
# with different timesteps and reuse values set to match.   E.G. 1s = reuse 1, 0.1s = reuse 10.
#-----------------------------------------------------------------------------

from parflow import Run
from parflow.tools.fs import cp, mkdir, get_absolute_path

clm = Run("clm_reuse", __file__)

#-----------------------------------------------------------------------------
# Copying input files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/clm_reuse')
mkdir(dir_name)

cp('$PF_SRC/test/tcl/clm/clm-reuse/drv_clmin.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/clm-reuse/drv_vegm.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/clm-reuse/drv_vegp.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/clm-reuse/forcing_1.txt', dir_name)

#-----------------------------------------------------------------------------
# Setting test variables
#-----------------------------------------------------------------------------

# Total runtime of simulation
stopt = 100

# Reuse values to run with
reuseValues = [1, 4]
示例#11
0
dover.Solver.Nonlinear.DerivativeEpsilon = 1e-8
dover.Solver.Nonlinear.StepTol = 1e-20
dover.Solver.Nonlinear.Globalization = 'LineSearch'
dover.Solver.Linear.KrylovDimension = 20
dover.Solver.Linear.MaxRestart = 2

dover.Solver.Linear.Preconditioner = 'PFMG'
dover.Solver.PrintSubsurf = False
dover.Solver.Drop = 1E-20
dover.Solver.AbsTol = 1E-9

#---------------------------------------------------------
# Initial conditions: water pressure
#---------------------------------------------------------

# set water table to be at the bottom of the domain, the top layer is initially dry
dover.ICPressure.Type = 'HydroStaticPatch'
dover.ICPressure.GeomNames = 'domain'
dover.Geom.domain.ICPressure.Value = -3.0

dover.Geom.domain.ICPressure.RefGeom = 'domain'
dover.Geom.domain.ICPressure.RefPatch = 'z_upper'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/dover_pj')
mkdir(dir_name)
dover.run(working_directory=dir_name)
示例#12
0
wbx.Solver.WriteSiloSaturation = True
wbx.Solver.WriteSiloConcentration = True
wbx.Solver.WriteSiloSlopes = True
wbx.Solver.WriteSiloMask = True
wbx.Solver.WriteSiloEvapTrans = True
wbx.Solver.WriteSiloEvapTransSum = True
wbx.Solver.WriteSiloOverlandSum = True
wbx.Solver.WriteSiloMannings = True
wbx.Solver.WriteSiloSpecificStorage = True

#---------------------------------------------------------
# Initial conditions: water pressure
#---------------------------------------------------------

# set water table to be at the bottom of the domain, the top layer is initially dry
wbx.ICPressure.Type = 'HydroStaticPatch'
wbx.ICPressure.GeomNames = 'domain'

wbx.Geom.domain.ICPressure.Value = -3.0

wbx.Geom.domain.ICPressure.RefGeom = 'domain'
wbx.Geom.domain.ICPressure.RefPatch = 'z_upper'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/wbx')
mkdir(dir_name)
wbx.run(working_directory=dir_name)
示例#13
0
def driver_file_written_times():
    return {
        key: os.stat(get_absolute_path(x)).st_mtime
        for key, x in default_driver_file_names.items()
    }
示例#14
0
# Exact solution specification for error calculations
#-----------------------------------------------------------------------------

octree.KnownSolution = 'NoKnownSolution'

#-----------------------------------------------------------------------------
# Set solver parameters
#-----------------------------------------------------------------------------

octree.Solver = 'Richards'
octree.Solver.MaxIter = 5

octree.Solver.Nonlinear.MaxIter = 10
octree.Solver.Nonlinear.ResidualTol = 1e-9
octree.Solver.Nonlinear.EtaChoice = 'EtaConstant'
octree.Solver.Nonlinear.EtaValue = 1e-5
octree.Solver.Nonlinear.UseJacobian = True
octree.Solver.Nonlinear.DerivativeEpsilon = 1e-2

octree.Solver.Linear.KrylovDimension = 10

octree.Solver.Linear.Preconditioner = 'PFMG'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/octree')
mkdir(dir_name)
octree.run(working_directory=dir_name)
示例#15
0
def test_subsurface_table(file_name):
    path = '$PF_SRC/test/correct_output/tables_LW_subsurface.txt.ref'
    ref = Path(get_absolute_path(path)).read_text()
    new = Path(get_absolute_path(file_name)).read_text()
    assert ref == new
示例#16
0
sabino = Run("sabino", __file__)

#-----------------------------------------------------------------------------
# PFSOL generation
#-----------------------------------------------------------------------------

color_to_patch = {
    '#FFFFFF': 0,  # Discard
    '#466CFF': 2,  # River
    '#C56C00': 3,  # Land
    '#1900FF': 4,  # Sea
    '#3DFFFF': 5,  # Lake
}

mask = load_patch_matrix_from_image_file(
    get_absolute_path('$PF_SRC/test/input/mask.png'))

top_patches = load_patch_matrix_from_image_file(
    get_absolute_path('$PF_SRC/test/input/mask_top.png'),
    color_to_patch,
    fall_back_id=6)

side_patches = load_patch_matrix_from_image_file(
    get_absolute_path('$PF_SRC/test/input/mask_side.png'),
    color_to_patch,
    fall_back_id=3)

#-----------------------------------------------------------------------------

SolidFileBuilder(bottom=1) \
  .mask(mask) \
示例#17
0
# Exact solution specification for error calculations
#-----------------------------------------------------------------------------

smg.KnownSolution = 'NoKnownSolution'

#-----------------------------------------------------------------------------
# Set solver parameters
#-----------------------------------------------------------------------------

smg.Solver = 'Richards'
smg.Solver.MaxIter = 5

smg.Solver.Nonlinear.MaxIter = 10
smg.Solver.Nonlinear.ResidualTol = 1e-9
smg.Solver.Nonlinear.EtaChoice = 'EtaConstant'
smg.Solver.Nonlinear.EtaValue = 1e-5
smg.Solver.Nonlinear.UseJacobian = True
smg.Solver.Nonlinear.DerivativeEpsilon = 1e-2

smg.Solver.Linear.KrylovDimension = 10

smg.Solver.Linear.Preconditioner = 'SMG'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/smg')
mkdir(dir_name)
smg.run(working_directory=dir_name)
示例#18
0
clm.Solver.CLM.Vegetation.Map.Clay.Value = 0.265

clm.Solver.CLM.Vegetation.Map.Color.Type = 'Constant'
clm.Solver.CLM.Vegetation.Map.Color.Value = 2

#---------------------------------------------------------
# Setting land use fractions
#---------------------------------------------------------

clm.Solver.CLM.Vegetation.Map.LandFrac.forest_en.Type = 'Constant'
clm.Solver.CLM.Vegetation.Map.LandFrac.forest_en.Value = 0.0

forest_eb_mat = np.zeros((clm.ComputationalGrid.NX, clm.ComputationalGrid.NY))
forest_eb_mat[1, :] = 1.0
file_name = 'forest_eb_mat.pfb'
write_array(get_absolute_path(file_name), forest_eb_mat)

clm.Solver.CLM.Vegetation.Map.LandFrac.forest_eb.Type = 'PFBFile'
clm.Solver.CLM.Vegetation.Map.LandFrac.forest_eb.FileName = file_name

clm.Solver.CLM.Vegetation.Map.LandFrac.forest_dn.Type = 'Constant'
clm.Solver.CLM.Vegetation.Map.LandFrac.forest_dn.Value = 0.5

clm.Solver.CLM.Vegetation.Map.LandFrac.forest_db.Type = 'Constant'
clm.Solver.CLM.Vegetation.Map.LandFrac.forest_db.Value = 0.0

#---------------------------------------------------------
# Testing clm data reader for veg mapping
#---------------------------------------------------------

# Reading drv_vegm.dat into 3D array
示例#19
0
# This runs a test case with the Richards' solver
# with simple flow domains, like a wall or a fault.
#------------------------------------------------------------------

from parflow import Run
from parflow.tools.fs import get_absolute_path, mkdir, chdir
from parflowio.pyParflowio import PFData
import numpy as np

rich_fbx = Run("richards_FBx", __file__)

#---------------------------------------------------------
# Creating and navigating to output directory
#---------------------------------------------------------

dir_name = get_absolute_path('test_output/rich_fbx')
mkdir(dir_name)
chdir(dir_name)

#------------------------------------------------------------------

rich_fbx.FileVersion = 4

rich_fbx.Process.Topology.P = 1
rich_fbx.Process.Topology.Q = 1
rich_fbx.Process.Topology.R = 1

#---------------------------------------------------------
# Computational Grid
#---------------------------------------------------------
示例#20
0
# this runs CLM test case

#
# Import the ParFlow TCL package
#
from parflow import Run
from parflow.tools.fs import mkdir, get_absolute_path

clm_samrai = Run("clm_samrai", __file__)

dir_name = get_absolute_path('test_output/clm_samrai')
mkdir(dir_name)

# foreach dir {qflx_evap_grnd eflx_lh_tot qflx_evap_tot qflx_tran_veg correct_output qflx_infl swe_out eflx_lwrad_out t_grnd diag_out qflx_evap_soi eflx_soil_grnd eflx_sh_tot qflx_evap_veg qflx_top_soil} {
#     file mkdir $dir
# }

#-----------------------------------------------------------------------------
# File input version number
#-----------------------------------------------------------------------------
clm_samrai.FileVersion = 4

#-----------------------------------------------------------------------------
# Process Topology
#-----------------------------------------------------------------------------

P = 1
Q = 1
R = 1

NumPatches = [lindex $argv 3]
# Exact solution specification for error calculations
#-----------------------------------------------------------------------------

drich.KnownSolution = 'NoKnownSolution'

#-----------------------------------------------------------------------------
# Set solver parameters
#-----------------------------------------------------------------------------

drich.Solver = 'Richards'
drich.Solver.MaxIter = 5

drich.Solver.Nonlinear.MaxIter = 10
drich.Solver.Nonlinear.ResidualTol = 1e-9
drich.Solver.Nonlinear.EtaChoice = 'EtaConstant'
drich.Solver.Nonlinear.EtaValue = 1e-5
drich.Solver.Nonlinear.UseJacobian = True
drich.Solver.Nonlinear.DerivativeEpsilon = 1e-2

drich.Solver.Linear.KrylovDimension = 10

drich.Solver.Linear.Preconditioner = 'MGSemi'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/drich_w')
mkdir(dir_name)
drich.run(working_directory=dir_name)
示例#22
0
#-----------------------------------------------------------------------------
# this runs CLM test case
#-----------------------------------------------------------------------------

from parflow import Run
from parflow.tools.fs import mkdir, cp, get_absolute_path

#-----------------------------------------------------------------------------
# Making output directories and copying input files
#-----------------------------------------------------------------------------

clm_jac = Run("clm_jac", __file__)

dir_name = get_absolute_path('test_output/clm_jac')
mkdir(dir_name)

directories = [
    'qflx_evap_grnd', 'eflx_lh_tot', 'qflx_evap_tot', 'qflx_tran_veg',
    'correct_output', 'qflx_infl', 'swe_out', 'eflx_lwrad_out', 't_grnd',
    'diag_out', 'qflx_evap_soi', 'eflx_soil_grnd', 'eflx_sh_tot',
    'qflx_evap_veg', 'qflx_top_soil'
]

for directory in directories:
    mkdir(dir_name + '/' + directory)

cp('$PF_SRC/test/tcl/clm/drv_clmin.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/drv_vegm.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/drv_vegp.dat', dir_name)
cp('$PF_SRC/test/tcl/clm/narr_1hr.sc3.txt.0', dir_name)
示例#23
0
#--------------------------------------------------------------
#  This runs the a Little Washita Test Problem with variable dz
#  and a constant rain forcing.  The full Jacobian is use and there is no dampening in the
#  overland flow.
#--------------------------------------------------------------

from parflow import Run
from parflow.tools.fs import cp, mkdir, chdir, get_absolute_path

LWvdz = Run("LWvdz", __file__)

#---------------------------------------------------------
# Copying slope files
#---------------------------------------------------------

dir_name = get_absolute_path('test_output/LWvdz')
mkdir(dir_name)
chdir(dir_name)

cp('$PF_SRC/test/input/lw.1km.slope_x.10x.pfb')
cp('$PF_SRC/test/input/lw.1km.slope_y.10x.pfb')

#---------------------------------------------------------

LWvdz.FileVersion = 4

LWvdz.Process.Topology.P = 1
LWvdz.Process.Topology.Q = 1
LWvdz.Process.Topology.R = 1

#---------------------------------------------------------
示例#24
0
#-----------------------------------------------------------------------------
#  This is a 2D crater problem w/ time varying input and topography
#-----------------------------------------------------------------------------

from parflow import Run
from parflow.tools.fs import cp, mkdir, get_absolute_path

crater = Run("crater", __file__)

# ---------------------------------------------------------
# Copy testing data in test directory
# ---------------------------------------------------------

dir_name = get_absolute_path('test_output/crater')
mkdir(dir_name)

cp('$PF_SRC/test/input/crater2D.pfsol', dir_name)

# ---------------------------------------------------------

crater.FileVersion = 4

crater.Process.Topology.P = 1
crater.Process.Topology.Q = 1
crater.Process.Topology.R = 1

#---------------------------------------------------------
# Computational Grid
#---------------------------------------------------------

crater.ComputationalGrid.Lower.X = 0.0
示例#25
0
def test_fewer_land_names(clm):
    vegm_file = Path(get_absolute_path('drv_vegm.dat'))
    vegp_file = Path(get_absolute_path('drv_vegp.dat'))
    for path in (vegm_file, vegp_file):
        if path.exists():
            path.unlink()

    CLMExporter(clm).write_map().write_parameters()

    new_clm = Run('clm', __file__)
    veg_params = new_clm.Solver.CLM.Vegetation.Parameters
    veg_map = new_clm.Solver.CLM.Vegetation.Map

    # Set only two land cover items
    veg_params.LandNames = 'forest_en forest_eb'

    CLMImporter(new_clm) \
        .map_file(vegm_file) \
        .parameters_file(vegp_file)

    assert veg_params.LandNames == ['forest_en', 'forest_eb']
    assert 'water' not in veg_params.keys()
    assert 'water' not in veg_map.keys()

    veg_map.LandFrac.forest_en.Value = 0.6
    veg_map.LandFrac.forest_eb.Value = 0.4
    veg_map.LandFrac.forest_en.Type = 'Constant'
    veg_map.LandFrac.forest_eb.Type = 'Constant'

    new_clm.ComputationalGrid.NX = 5
    new_clm.ComputationalGrid.NY = 5

    CLMExporter(new_clm).write_map().write_parameters()

    vegm_data = read_clm(vegm_file, type='vegm')
    vegp_data = read_clm(vegp_file, type='vegp')

    # These should be 0.6 and 0.4
    shape = vegm_data.shape[:2]
    assert np.array_equal(vegm_data[:, :, 5], np.full(shape, 0.6))
    assert np.array_equal(vegm_data[:, :, 6], np.full(shape, 0.4))

    # All of the vegm data after the 2 land types should be zero
    last_land_ind = 6
    zeros = np.zeros(shape)
    for i in range(last_land_ind + 1, vegm_data.shape[2]):
        assert np.array_equal(vegm_data[:, :, i], zeros)

    # All of the vegp data after the second land type should be equal
    # to the default
    default_vegp = CLMExporter(new_clm)._default_vegp_values
    for key, val in vegp_data.items():
        for i in range(2, len(val)):
            assert val[i] == default_vegp[key]

    # Make sure at least one of the other values is correct
    key = 'z0m'
    ind = 1
    val = 2.2
    assert vegp_data[key][ind] != default_vegp[key]
    assert vegp_data[key][ind] == val
示例#26
0
sabino.ComputationalGrid.NZ = 20

#-----------------------------------------------------------------------------
# Names of the GeomInputs
#-----------------------------------------------------------------------------

sabino.GeomInput.Names = 'domaininput'

sabino.GeomInput.domaininput.GeomName = 'domain'
sabino.GeomInput.domaininput.GeomNames = 'domain'

#-----------------------------------------------------------------------------
# PFSOL generation
#-----------------------------------------------------------------------------

sabino_mask = load_patch_matrix_from_pfb_file(get_absolute_path('$PF_SRC/test/input/sabino_mask.pfb'))

SolidFileBuilder(top=1, bottom=2, side=3) \
  .mask(sabino_mask) \
  .write('sabino_domain.pfsol', xllcorner=0, yllcorner=0, cellsize=90, vtk=True) \
  .for_key(sabino.GeomInput.domaininput)

#-----------------------------------------------------------------------------

sabino.Geom.domain.Patches = 'top bottom edge'

#-----------------------------------------------------------------------------
# Domain Geometry
#-----------------------------------------------------------------------------

sabino.Geom.domain.Lower.X = 0.0
示例#27
0
#-----------------------------------------------------------------------------
# Testing pfset with a .pfidb file
#-----------------------------------------------------------------------------

from pathlib import Path

from parflow import Run
from parflow.tools.fs import get_absolute_path

dsingle = Run("dsingle", __file__)

dsingle.pfset(pfidb_file=get_absolute_path(
    '$PF_SRC/test/correct_output/dsingle.pfidb.ref'))


# Test pfidb
generated, _ = dsingle.write()
old_text = Path(generated).read_text()

dsingle2 = Run.from_definition(generated)
generated, _ = dsingle2.write()

new_text = Path(generated).read_text()

assert old_text and new_text
assert old_text == new_text


# Test yaml
generated, _ = dsingle.write(file_format='yaml')
old_text = Path(generated).read_text()
示例#28
0
#    pfset Patch.z-upper.BCPressure.Type		      OverlandDiffusive
#    pfset Solver.Nonlinear.UseJacobian                       True
#    pfset Solver.Linear.Preconditioner.PCMatrixType         FullJacobian

#    set runname Slab.$name.OverlandDif
#    puts "Running $runname OverlandDiffusive Jacobian True Nonsymmetric Preconditioner"
#    pfrun $runname
#    pfundist $runname
#    if $runcheck==1 {
#      set passed 1
#      foreach i "00000 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010" {
#        if ![pftestFile $runname.out.press.$i.pfb "Max difference in Pressure for timestep $i" $sig_digits] {
#          set passed 0
#        }
#        if ![pftestFile  $runname.out.satur.$i.pfb "Max difference in Saturation for timestep $i" $sig_digits] {
#          set passed 0
#        }
#      }
#      if $passed {
#        puts "$runname : PASSED"
#      } {
#        puts "$runname : FAILED"
#      }
#    }

# }

dir_name = get_absolute_path('test_output/os_dwe')
mkdir(dir_name)
overland.run(working_directory=dir_name)
示例#29
0
#-----------------------------------------------------------------------------
# pfset: flat_map
#-----------------------------------------------------------------------------

pfset_test.pfset(
    flat_map={
        'Phase.Saturation.Type': 'VanGenuchten',
        'Phase.Saturation.GeomNames': 'domain',
    })

pfset_test.Phase.pfset(flat_map={
    'RelPerm.Type': 'VanGenuchten',
    'RelPerm.GeomNames': 'domain',
})

#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------

pfset_test.validate()
generatedFile, runFile = pfset_test.write(file_format='yaml')

# Prevent regression
with open(generatedFile) as new, open(
        get_absolute_path(
            '$PF_SRC/test/correct_output/pfset_test.yaml.ref')) as ref:
    if new.read() == ref.read():
        print('Success we have the same file')
    else:
        print('Files are different')
        sys.exit(1)
示例#30
0
#-----------------------------------------------------------------------------

rbp.KnownSolution = 'NoKnownSolution'

#-----------------------------------------------------------------------------
# Set solver parameters
#-----------------------------------------------------------------------------

rbp.Solver = 'Richards'
rbp.Solver.MaxIter = 50000

rbp.Solver.Nonlinear.MaxIter = 100
rbp.Solver.Nonlinear.ResidualTol = 1e-6
rbp.Solver.Nonlinear.EtaChoice = 'EtaConstant'
rbp.Solver.Nonlinear.EtaValue = 1e-2
rbp.Solver.Nonlinear.UseJacobian = True

rbp.Solver.Nonlinear.DerivativeEpsilon = 1e-12

rbp.Solver.Linear.KrylovDimension = 100

rbp.Solver.Linear.Preconditioner = 'PFMG'

#-----------------------------------------------------------------------------
# Run and Unload the ParFlow output files
#-----------------------------------------------------------------------------

dir_name = get_absolute_path('test_output/rbp')
mkdir(dir_name)
rbp.run(working_directory=dir_name)