if '&' in args:
        backgroundTask = False
        args.remove('&')

    if rc < 0:  # Requirement 3: Command fails
        os.write(2, ("Program terminated with exit code" + rc + "\n").encode())
        sys.exit(1)

    elif rc == 0:  # Child process

        # Check for Redirection
        if (redirect.hasRedirect(args)):
            if (redirect.isValid(args)):  # Check syntax of command
                if (redirect.hasOutput(args)):
                    outputIndex = redirect.output(args)  # Get Output Index
                    os.close(1)  # Close stdout
                    os.open(args[outputIndex],
                            os.O_CREAT | os.O_WRONLY)  # Open Output
                    os.set_inheritable(1, True)
                    args.remove('>')  # Remove redirection from command
                    args.remove(args[outputIndex])  # ^

                if (redirect.hasInput(args)):
                    inputIndex = redirect.input(args)  # Get Input Index
                    os.close(0)  # Close stdin
                    os.open(args[inputIndex], os.O_RDONLY)
                    # Open Input
                    os.set_inheritable(0, True)
                    args.remove('<')  # Remove redirection from command
                    args.remove(args[inputIndex])  # ^
Ejemplo n.º 2
0
    def setUp(self):
        self.r = redirect.output("modflowcomponent_test.log")
        self.r.toFile()

        #
        # Definition of the mesh
        #
        self.mesh = CartesianMesh2D("global", "XY")
        self.nx = 42
        self.ny = 1
        self.nb_of_intervals = [self.nx, self.ny]
        self.dx = [0.002]
        self.dx = self.dx * self.nx
        self.dx[0] = self.dx[0] * 0.5
        self.pointlist_x = [0.0]
        self.pointlist_y = [0.0]
        for i in range(1, len(self.dx), 1):
            self.pointlist_x.append(self.pointlist_x[i - 1] + self.dx[i - 1])
        self.pointlist_y = [0.0]
        self.pointlist_y.append(1.0)
        self.mesh.setAxis("X", self.pointlist_x)
        self.mesh.setAxis("Y", self.pointlist_y)
        #
        # End of Definitions for the mesh
        #
        #        print " Study name:",self.study._name
        #
        # Definitions of materials
        #
        print "-" * 20
        print " Definition of materials :"
        print "-" * 20
        self.clay_material = Material(name="clay",
                                      permeability=Permeability(1.0, "m/s"))
        self.cement_material = Material(name="Cement",
                                        permeability=Permeability(
                                            2.0e-7, "m/s"))
        #
        print "-" * 20
        print " Definition of meshes :"
        print "-" * 20
        self.clay_reg_m = CartesianMesh2D("Clay Region", "XY")
        self.clay_reg_m.setZone("Clay Region",
                                index_min=Index2D(2, 1),
                                index_max=Index2D(self.nx - 1, 1))
        #
        print "-" * 20
        print " Definition of meshes :"
        print "-" * 20
        self.east_bo_m = CartesianMesh2D("boundary east", "XY")
        self.east_bo_m.setZone("boundary east",
                               index_min=Index2D(1, 1),
                               index_max=Index2D(1, 1))
        #
        # Definition of regions
        #
        print "-" * 25
        print " Definition of regions :"
        print "-" * 25
        self.regions_list = []
        print type(self.clay_reg_m
                   ), " nom de la classe :", self.clay_reg_m.__class__.__name__
        print type(
            self.clay_material
        ), " nom de la classe :", self.clay_material.__class__.__name__
        print "-" * 20
        self.reg1 = Region(self.clay_reg_m, self.clay_material)
        self.regions_list.append(self.reg1)

        #print "  ---- type ----", hasattr(reg1,"material")
        #print "  ---- type ----", hasattr(reg1,"support")
        #temp = reg1.__class__
        #name = temp.__name__
        #print " nom ",name
        #pos = name.find('_objref_')
        #print " pos ",pos
        tclasses = [Region]
        #for c in tclasses:
        #    if isinstance(reg1,c):
        #        print " ok ",c
        #
        # Definition of boundary conditions
        #
        print "-" * 20
        print " Definition of boundary conditions :"
        print "-" * 20
        self.boundaryconditions_list = []
        print "-" * 10
        print " east_bo_m :"
        print "-" * 10

        self.east_bo_m = CartesianMesh2D("boundary east", "XY")
        self.east_min = Index2D(1, 1)
        self.east_max = Index2D(1, 1)
        #east_bo_m.setZone("boundary east",index_min = Index2D(1,1),index_max = Index2D(1,1))
        #east_bo_m.setZone("boundary east",index_min = Index2D(1,1),index_max = Index2D(1,1))
        self.east_bo_m.setZone("boundary east", self.east_min, self.east_max)
        self.Boundary = self.east_bo_m
        self.head_value = Head(2.2e-7, "m")
        print " class name ", self.head_value.__class__.__name__

        self.bc_east = BoundaryCondition(self.Boundary, 'Dirichlet',
                                         self.head_value)
        print " on verifie la classe "
        if not isinstance(self.bc_east, BoundaryCondition):
            raise Exception, " the instanciation of the boundary class must be verified "
        print " on a verifie la classe "
        print " east_bo_m : append"
        self.boundaryconditions_list.append(self.bc_east)
        #
        print "-" * 10
        print " west_bo_w :"
        print "-" * 10

        self.west_bo_m = CartesianMesh2D("boundary west", "XY")
        self.west_bo_m.setZone("boundary west",
                               index_min=Index2D(41, 1),
                               index_max=Index2D(41, 1))
        self.Boundary = self.west_bo_m
        self.Value = Head(0.0, "m")
        self.bc_west = BoundaryCondition(self.Boundary, 'Dirichlet',
                                         self.Value)
        print " east_bo_m : append"
        self.boundaryconditions_list.append(self.bc_west)

        #
        # Definition of initial conditions
        #
        self.initialconditions_list = []
        self.reg1_ic = InitialCondition(self.clay_reg_m,
                                        value=Head(1.e-8, "m"))
        self.initialconditions_list.append(self.reg1_ic)
        # ----------------
        # Darcy Resolution
        # ----------------
        self.title = " One dimensional simulation"
        print "Title of the study : ", self.title
        #
        # Definition of Modflow specific parameters
        #
        self.mxiter = 200
        self.accl = 1.0
        self.hclose = 1.e-15
        print " Study definition "
        self.Study_type = 'Saturated'
        print " SaturatedHydroModflow instance "
        #        self.darcy = SaturatedHydroModflow(self.study._name,self.regions_list,
        #	             self.boundaryconditions_list,self.initialconditions_list)
        self.darcy = SaturatedHydroModflow("Modflow_1/2D", self.regions_list,
                                           self.boundaryconditions_list,
                                           self.initialconditions_list)
        print " SaturatedHydroModflow setMesh method "
        self.darcy.setMesh(self.mesh)
        print " SaturatedHydroModflow setData method "
        self.darcy.setData()
        self.darcy.run()

        self.filename_sip = "Monod.sip"
        self.modflow_sip = setSolverParameter(self.mxiter, self.accl,
                                              self.hclose)
        self.modflow_sip.sauvegarde(self.filename_sip)
Ejemplo n.º 3
0
def main():
    """
    parse command line options
    
    Three options are available :
    
        - F for flow
        - CT for chemical transport
        - C for chemistry
        
        for example, just type "python validationTest.py ct"
    
    for an interactive output type "python validationTest.py i"
    
    """
    startingDate = gmtime()
    initialCpuTime = clock()
    initialTime = time()
    result = 0
    ind = 0
    option = "WTCT"
    #print " sys ",sys.argv[1:],sys.argv[1:][0],type(sys.argv[1:])
    if sys.argv[1:] != []:
        if sys.argv[1:][0].lower() in ["f","ct","c","wtf","w"]:
            if sys.argv[1:][0].lower() in ["f","wtf"]:
                option = "WTF"
            elif sys.argv[1:][0].lower() == "ct":
                option = "WT"+sys.argv[1:][0].upper()
            if sys.argv[1:][0].lower() == "c":
                option = "WT"+sys.argv[1:][0].upper()
            if sys.argv[1:][0].lower() == "w":
                option = "WT"+sys.argv[1:][0].upper()
        print option
        stringc = environ[option]
        print " stringc ",stringc
    else:
        stringc = "all"
    print " now ",len(listOfTests)
    if len(sys.argv[1:]) == 1 and sys.argv[1:][0].lower() == "i":
        pass
    else:
        redic = redirect.output("validation.log")
        redic.toFile()
        pass
    path = ""
    #
    # ind controls the test case list length
    # while indc is the number of successfully run test cases
    #
    indc = 0
    while result == 0 and ind+1 <= len(listOfTests):
        if stringc == "all":
            path = chdir(listOfTests[ind][0])
            string = "python "+listOfTests[ind][1]
            print " ~~~~~~~~~~~ "
            print " case run id ",ind," name: ",listOfTests[ind][1]," in the directory: ",listOfTests[ind][0]
            print " ~~~~~~~~~~~ "
            sys.stdout.flush()
            result = system(string)
            indc+=1
        elif stringc in listOfTests[ind][0]:
            path = chdir(listOfTests[ind][0])
            string = "python "+listOfTests[ind][1]
            print " ~~~~~~~~~~~ "
            print " case run id ",ind," name: ",listOfTests[ind][1]," in the directory: ",listOfTests[ind][0]
            print " ~~~~~~~~~~~ "
            sys.stdout.flush()
            result = system(string)
            indc+=1
        else:
            pass
        sleep(0.5)
        if stringc in ["all", listOfTests[ind][0]]:
            print " reg",ind,stringc, path
        ind+=1
        pass
#    path = chdir(path"/Cec_column","guitest1.py")
#    subprocess( -> mpdboot)
#    mpirun -np 2 mpipython guitest_mpi.py
#    subprocess( -> mpdballexit)
    if result != 0:
        raise Exception,  " problem with the test case %s in the directory: %s"%(listOfTests[ind-1][1],listOfTests[ind-1][0])
    else:
        print " test cases run fine",indc
    print " the elapsed time in seconds is",time()-initialTime
    print " the starting date is ",startingDate 
    print " the date is          ",gmtime()
Ejemplo n.º 4
0
def main():
    """
    parse command line options
    
    Three options are available :
    
        - F for flow
        - CT for chemical transport
        - C for chemistry
        
        for example, just type "python validationTest.py ct"
    
    """  #
    redic = redirect.output("validation.log")
    redic.toFile()
    result = 0
    ind = 0
    # print " sys ",sys.argv[1:],sys.argv[1:][0],type(sys.argv[1:])
    if sys.argv[1:] != []:
        if sys.argv[1:][0].lower() in ["f", "ct", "c", "wtf"]:
            if sys.argv[1:][0].lower() in ["f", "wtf"]:
                option = "WTF"
            elif sys.argv[1:][0].lower() == "ct":
                option = "WT" + sys.argv[1:][0].upper()
            if sys.argv[1:][0].lower() == "c":
                option = "WT" + sys.argv[1:][0].upper()
        print option
        stringc = environ[option]
        print " stringc ", stringc
    else:
        stringc = "all"
    print " now ", len(a)
    path = ""
    #
    # ind controls the test case list length
    # while indc is the number of successfully run test cases
    #
    indc = 0
    while result == 0 and ind + 1 <= len(a):
        if stringc == "all":
            path = chdir(a[ind][0])
            string = "python " + a[ind][1]
            print " ~~~~~~~~~~~ "
            print " case run id ", ind, " name: ", a[ind][1], " in the directory: ", a[ind][0]
            print " ~~~~~~~~~~~ "
            sys.stdout.flush()
            result = system(string)
            indc += 1
        elif stringc in a[ind][0]:
            path = chdir(a[ind][0])
            string = "python " + a[ind][1]
            print " ~~~~~~~~~~~ "
            print " case run id ", ind, " name: ", a[ind][1], " in the directory: ", a[ind][0]
            print " ~~~~~~~~~~~ "
            sys.stdout.flush()
            result = system(string)
            indc += 1
        else:
            pass
        sleep(0.5)
        print " reg", ind, stringc, path
        ind += 1
        pass
    #    path = chdir(path"/Cec_column","guitest1.py")
    #    subprocess( -> mpdboot)
    #    mpirun -np 2 mpipython guitest_mpi.py
    #    subprocess( -> mpdballexit)
    if result != 0:
        raise Exception, " problem with the test case %s  in the directory: %s" % (a[ind - 1][1], a[ind - 1][0])
    else:
        print " test cases run fine", indc
Ejemplo n.º 5
0
    def setUp(self):
        self.r = redirect.output("modflowcomponent_test.log")
        self.r.toFile()

#
# Definition of the mesh
#
        self.mesh = CartesianMesh2D("global","XY")
        self.nx = 42
        self.ny = 1
        self.nb_of_intervals = [self.nx,self.ny]
        self.dx = [0.002]
        self.dx = self.dx*self.nx
        self.dx[0] = self.dx[0]*0.5
        self.pointlist_x = [0.0]
        self.pointlist_y = [0.0]
        for i in range(1,len(self.dx),1):
            self.pointlist_x.append(self.pointlist_x[i-1]+self.dx[i-1])
        self.pointlist_y = [0.0]
        self.pointlist_y.append(1.0)
        self.mesh.setAxis("X",self.pointlist_x)
        self.mesh.setAxis("Y",self.pointlist_y)
#
# End of Definitions for the mesh
#
#        print " Study name:",self.study._name
#
# Definitions of materials
#
        print "-"*20
        print " Definition of materials :"
        print "-"*20
        self. clay_material = Material(name =  "clay",   permeability = Permeability(1.0,"m/s"))
        self.cement_material = Material(name = "Cement", permeability = Permeability(2.0e-7,"m/s"))
#
        print "-"*20
        print " Definition of meshes :"
        print "-"*20
        self.clay_reg_m   = CartesianMesh2D("Clay Region","XY")
        self.clay_reg_m.setZone("Clay Region",index_min = Index2D(2,1),index_max = Index2D(self.nx-1,1))
#
        print "-"*20
        print " Definition of meshes :"
        print "-"*20
        self.east_bo_m   = CartesianMesh2D("boundary east","XY")
        self.east_bo_m.setZone("boundary east",index_min = Index2D(1,1),index_max = Index2D(1,1))
#
# Definition of regions
#
        print "-"*25
        print " Definition of regions :"
        print "-"*25
        self.regions_list = []
        print type(self.clay_reg_m)," nom de la classe :",self.clay_reg_m.__class__.__name__
        print type(self.clay_material)," nom de la classe :",self.clay_material.__class__.__name__
        print "-"*20
        self.reg1 = Region(self.clay_reg_m,self.clay_material)
        self.regions_list.append(self.reg1)

#print "  ---- type ----", hasattr(reg1,"material")
#print "  ---- type ----", hasattr(reg1,"support")
#temp = reg1.__class__
#name = temp.__name__
#print " nom ",name
#pos = name.find('_objref_')
#print " pos ",pos
        tclasses=[Region]
#for c in tclasses:
#    if isinstance(reg1,c):
#        print " ok ",c
#
# Definition of boundary conditions
#
        print "-"*20
        print " Definition of boundary conditions :"
        print "-"*20
        self.boundaryconditions_list = []
        print "-"*10
        print " east_bo_m :"
        print "-"*10

        self.east_bo_m   = CartesianMesh2D("boundary east","XY")
        self.east_min = Index2D(1,1)
        self.east_max = Index2D(1,1)
#east_bo_m.setZone("boundary east",index_min = Index2D(1,1),index_max = Index2D(1,1))
#east_bo_m.setZone("boundary east",index_min = Index2D(1,1),index_max = Index2D(1,1))
        self.east_bo_m.setZone("boundary east",self.east_min,self.east_max)
        self.Boundary=self.east_bo_m
        self.head_value=Head(2.2e-7,"m")
        print " class name ",self.head_value.__class__.__name__

        self.bc_east = BoundaryCondition(self.Boundary,'Dirichlet',self.head_value)
        print " on verifie la classe "
        if not isinstance(self.bc_east,BoundaryCondition):
            raise Exception, " the instanciation of the boundary class must be verified "
        print " on a verifie la classe "
        print " east_bo_m : append"
        self.boundaryconditions_list.append(self.bc_east)
#
        print "-"*10
        print " west_bo_w :"
        print "-"*10

        self.west_bo_m   = CartesianMesh2D("boundary west","XY")
        self.west_bo_m.setZone("boundary west",index_min = Index2D(41,1),index_max = Index2D(41,1))
        self.Boundary=self.west_bo_m
        self.Value=Head(0.0,"m")
        self.bc_west = BoundaryCondition(self.Boundary,'Dirichlet',self.Value)
        print " east_bo_m : append"
        self.boundaryconditions_list.append(self.bc_west)

#
# Definition of initial conditions
#
        self.initialconditions_list = []
        self.reg1_ic = InitialCondition(self.clay_reg_m,value=Head(1.e-8,"m"))
        self.initialconditions_list.append(self.reg1_ic)
# ----------------
# Darcy Resolution
# ----------------
        self.title = " One dimensional simulation"
        print "Title of the study : ",self.title
#
# Definition of Modflow specific parameters
#
        self.mxiter = 200
        self.accl = 1.0
        self.hclose = 1.e-15
        print " Study definition "
        self.Study_type = 'Saturated'
        print " SaturatedHydroModflow instance "
#        self.darcy = SaturatedHydroModflow(self.study._name,self.regions_list,
#	             self.boundaryconditions_list,self.initialconditions_list)
        self.darcy = SaturatedHydroModflow("Modflow_1/2D",self.regions_list,
	             self.boundaryconditions_list,self.initialconditions_list)
        print " SaturatedHydroModflow setMesh method "
        self.darcy.setMesh(self.mesh)
        print " SaturatedHydroModflow setData method "
        self.darcy.setData()
	self.darcy.run()
	
        self.filename_sip="Monod.sip" 
        self.modflow_sip=setSolverParameter(self.mxiter,self.accl,self.hclose)
        self.modflow_sip.sauvegarde(self.filename_sip)