Example #1
0
def get_ogs_parameters(path, noKf=False):
    """Return Ss, kf from the first block of the .mmp-file
    Return time_step_size and time_steps from the .tim-file."""


    from ogs5py import OGS

    ogsmodel = OGS(task_root=path)
    ogsmodel.load_model(task_root=path)
    # dir(ogsmodel.mmp)
    # print(vars(ogsmodel.mmp))
    # for any reason is this configuration not working with python2
    # Ss = ogsmodel.mmp.get_block()['STORAGE'][0][1]
    # kf = ogsmodel.mmp.get_block()['PERMEABILITY_TENSOR'][0][1]
    # print(vars(ogsmodel.mmp))

    # this configuration is probably only working for this kind of OGS setups
    # because it is indexing the contents of the mmp file and not refering to a
    # dictionary with keys!!!
    # alternative: mpd.get_block(0)[""]
    Ss = float(ogsmodel.mmp.cont[0][1][0][1])
    kf = float(ogsmodel.mmp.cont[0][2][0][1])
    time_step_size = float(ogsmodel.tim.cont[0][3][0][1])
    time_steps = float(ogsmodel.tim.cont[0][3][0][0])
    if noKf == True:
        return Ss, time_step_size, time_steps
    else:
        return Ss, kf, time_step_size, time_steps
Example #2
0
def get_kf_from_blocks(path):
    """
    This function returns a list with kf values from the mmp blocks in the
    ogs .mmp-file. It's sorted like the blocks are sorted, i.e. like the material
    groups.
    """
    from ogs5py import OGS
    ogsmodel = OGS(task_root=path)
    ogsmodel.load_model(task_root=path)
    kf_list = []
    number_of_blocks = ogsmodel.mmp.get_block_no()
    for i in range(number_of_blocks):
        kf_list.append(ogsmodel.mmp.get_block(i)['PERMEABILITY_TENSOR'][0][1])
    return kf_list
Example #3
0
def get_ogs_parameters(path):
    from ogs5py import OGS

    ogsmodel = OGS(task_root=path)
    ogsmodel.load_model(task_root=path)
    # dir(ogsmodel.mmp)
    # print(vars(ogsmodel.mmp))
    # for any reason is this configuration not working with python2
    # Ss = ogsmodel.mmp.get_block()['STORAGE'][0][1]
    # kf = ogsmodel.mmp.get_block()['PERMEABILITY_TENSOR'][0][1]
    # print(vars(ogsmodel.mmp))
    # this configuration is probably only working for this kind of OGS setups
    # because it is indexing the contents of the mmp file and not refering to a
    # dictionary with keys!!!
    Ss = float(ogsmodel.mmp.cont[0][1][0][1])
    kf = float(ogsmodel.mmp.cont[0][2][0][1])
    return Ss, kf
Example #4
0
def get_ogs_polyline_length(path, name):
    """
    Returns the length of a polyline. The number of points which make up the
    polyline must not be more than 2!

    Parameters
    ----------
    path : string
        Path to OGS project folder.
    name : string
        Name of the polyline which length should be returned.
    """

    from ogs5py import OGS
    from scipy.spatial.distance import euclidean
    found = False
    ogsmodel = OGS(task_root=path)
    ogsmodel.load_model(task_root=path)
    for line in ogsmodel.gli.POLYLINES:
        if line["NAME"] == name:
            found = True
            points = line["POINTS"]
            if len(points) > 2:
                print("The polyline has more than 2 points!")
                print("Exit!")
                break
            return euclidean(ogsmodel.gli.POINTS[points[0]],
                             ogsmodel.gli.POINTS[points[1]])
        else:
            pass

    if found == False:
        raise NameError("No polyline with the name " + name +
                        " has been found!")
    else:
        pass
        tmp_root = ("test_{:03}".format(test_cnt) + "_model")

    tmp_log = (str(test_cnt) + " " + tmp_root + " - load: " +
               os.path.join(root, task_id))
    log_str.append(tmp_log)

    if print_progress:
        print(tmp_log)

    model = OGS(task_root=os.path.join(out_dir, tmp_root), output_dir="out")
    load_success = False
    try:
        model.load_model(
            verbose=False,
            task_root=root,
            task_id=task_id,
            encoding="ISO-8859-15",  # lots of windows files (non utf8)
            use_task_id=True,  # use the given task_id for some reference
        )
    except ValueError as valerr:
        print("FAIL..." + str(valerr))
        log_str.append("FAIL..." + str(valerr))
    else:
        load_success = True
        print("OK...loading successful")
        log_str.append("OK...loading successful")

    if gen_scr and load_success:
        model.gen_script(script_name=model.task_id + ".py",
                         script_dir=model.task_root,
                         task_root=task_id + "_root",
Example #6
0
class TestOGS(unittest.TestCase):
    def setUp(self):
        self.ogs_path = os.getcwd()
        self.ogs_exe = download_ogs(path=self.ogs_path)

    def test_pump(self):
        self.model = OGS(task_root=os.path.join(self.ogs_path, "pump_test"))
        self.model.output_dir = "out"
        # generate a radial mesh
        self.model.msh.generate("radial", dim=2, rad=range(51))
        # generate a radial outer boundary
        self.model.gli.generate("radial", dim=2, rad_out=50.0)
        self.model.gli.add_points([0.0, 0.0, 0.0], "pwell")
        self.model.gli.add_points([1.0, 0.0, 0.0], "owell")

        self.model.bc.add_block(  # boundary condition
            PCS_TYPE="GROUNDWATER_FLOW",
            PRIMARY_VARIABLE="HEAD",
            GEO_TYPE=["POLYLINE", "boundary"],
            DIS_TYPE=["CONSTANT", 0.0],
        )
        self.model.st.add_block(  # source term
            PCS_TYPE="GROUNDWATER_FLOW",
            PRIMARY_VARIABLE="HEAD",
            GEO_TYPE=["POINT", "pwell"],
            DIS_TYPE=["CONSTANT_NEUMANN", -1.0e-04],
        )
        self.model.ic.add_block(  # initial condition
            PCS_TYPE="GROUNDWATER_FLOW",
            PRIMARY_VARIABLE="HEAD",
            GEO_TYPE="DOMAIN",
            DIS_TYPE=["CONSTANT", 0.0],
        )
        self.model.mmp.add_block(  # medium properties
            GEOMETRY_DIMENSION=2,
            STORAGE=[1, 1.0e-04],
            PERMEABILITY_TENSOR=["ISOTROPIC", 1.0e-4],
            POROSITY=0.2,
        )
        self.model.num.add_block(  # numerical solver
            PCS_TYPE="GROUNDWATER_FLOW",
            LINEAR_SOLVER=[2, 5, 1.0e-14, 1000, 1.0, 100, 4],
        )
        self.model.out.add_block(  # point observation
            PCS_TYPE="GROUNDWATER_FLOW",
            NOD_VALUES="HEAD",
            GEO_TYPE=["POINT", "owell"],
            DAT_TYPE="TECPLOT",
            TIM_TYPE=["STEPS", 1],
        )
        self.model.pcs.add_block(  # set the process type
            PCS_TYPE="GROUNDWATER_FLOW", NUM_TYPE="NEW"
        )
        self.model.tim.add_block(  # set the timesteps
            PCS_TYPE="GROUNDWATER_FLOW",
            TIME_START=0,
            TIME_END=600,
            TIME_STEPS=[[10, 30], [5, 60]],
        )
        self.model.write_input()
        self.success = self.model.run_model(ogs_exe=self.ogs_exe)
        self.assertTrue(self.success)
        self.point = self.model.readtec_point(pcs="GROUNDWATER_FLOW")
        self.time = self.point["owell"]["TIME"]
        self.head = self.point["owell"]["HEAD"]
        self.assertTrue(len(self.time) == len(self.head) == 16)
        self.assertAlmostEqual(self.head[-1], -0.55744648, places=3)
        self.pnt = self.model.output_files(
            pcs="GROUNDWATER_FLOW", typ="TEC_POINT"
        )
        self.ply = self.model.output_files(
            pcs="GROUNDWATER_FLOW", typ="TEC_POLYLINE"
        )
        self.vtk = self.model.output_files(pcs="GROUNDWATER_FLOW", typ="VTK")
        self.pvd = self.model.output_files(pcs="GROUNDWATER_FLOW", typ="PVD")
        self.assertTrue(len(self.ply) == len(self.vtk) == len(self.pvd) == 0)
        self.assertTrue(len(self.pnt) == 1)

        self.model.gen_script(os.path.join(self.ogs_path, "script"))
        self.model.load_model(self.model.task_root)
        self.model.task_root = "new_root"
        self.model.task_id = "new_id"
        self.model.reset()

    def test_mesh(self):
        self.msh = MSH()
        self.gli = GLI()
        self.msh2 = MSH()
        self.msh2.generate(generator="radial", dim=3, rad=[0, 1])

        self.msh.generate(generator="rectangular", dim=2)
        self.msh.generate(generator="rectangular", dim=3)
        self.msh.generate(generator="radial", dim=2)
        self.msh.generate(generator="radial", dim=2, rad=range(1, 11))
        self.msh.generate(generator="radial", dim=3)
        self.msh.generate(generator="radial", dim=3, rad=range(1, 11))
        self.msh.combine_mesh(self.msh2)
        self.msh.transform(
            hull_deform,
            niv_top=0,
            niv_bot=-1,
            func_top=lambda x, y: np.cos(np.sqrt(x ** 2 + y ** 2)) + 1,
        )
        self.gli.generate(generator="rectangular", dim=2)
        self.gli.generate(generator="rectangular", dim=3)
        self.gli.generate(generator="radial", dim=2)
        self.gli.generate(generator="radial", dim=2, rad_in=1)
        self.gli.generate(generator="radial", dim=3)
        self.gli.generate(generator="radial", dim=3, rad_in=1)

        self.msh.swap_axis()
        self.msh.swap_axis(axis1=0, axis2=2)
        self.msh.rotate(0.1)
        self.msh.shift((1, 1, 1))
        self.msh.export_mesh("test.vtk")
        self.msh.import_mesh("test.vtk")
        self.gli.swap_axis()
        self.gli.swap_axis(axis1=0, axis2=2)
        self.gli.rotate(0.1)
        self.gli.shift((1, 1, 1))

        self.cen = self.msh.centroids_flat
        self.mat = self.msh.MATERIAL_ID_flat
        self.vol = self.msh.volumes_flat
        self.nod = self.msh.node_centroids_flat
        self.msh.center

        self.assertTrue(
            len(self.cen) == len(self.mat) == len(self.vol) == len(self.nod)
        )