예제 #1
0
    def test_all(self):
        cls = self.__class__
        rank = cls.comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = 'input_conductivity_dist_paramT.yaml'
        problem = Utils.createAlbanyProblem(file_dir+'/'+filename, cls.parallelEnv)

        parameter_map    = problem.getParameterMap(0)
        parameter        = Tpetra.MultiVector(parameter_map, 1, dtype="d")
        num_elems        = parameter_map.getNodeNumElements()
        parameter[0, :]  = 2.0*np.ones(num_elems)
    

        problem.performSolve()
        state_map    = problem.getStateMap()
        state        = Tpetra.MultiVector(state_map, 1, dtype="d")
        state[0, :]  = problem.getState()
        state_ref    = Utils.loadMVector('state_ref', 1, state_map, distributedFile=False, useBinary=False, readOnRankZero=True)
        

        stackedTimer = problem.getStackedTimer()
        setup_time = stackedTimer.accumulatedTime("PyAlbany: Setup Time")
        print("setup_time = " + str(setup_time))
        tol = 1.e-8
        self.assertTrue(np.linalg.norm(state_ref[0, :] - state[0,:]) < tol)
예제 #2
0
def setInitialGuess(problem, p, n_params, params_in_vector=True):
    if params_in_vector:
        parameter_map = problem.getParameterMap(0)
        parameter = Tpetra.Vector(parameter_map, dtype="d")
        for j in range(0, n_params):
            parameter[j] = p[j]
        problem.setParameter(0, parameter)
    else:
        for j in range(0, n_params):
            parameter_map = problem.getParameterMap(j)
            parameter = Tpetra.Vector(parameter_map, dtype="d")
            parameter[0] = p[j]
            problem.setParameter(j, parameter)
예제 #3
0
 def set_theta_star(self, theta_star):
     self.theta_star = theta_star
     if self.params_in_vector:
         parameter_map = self.problem.getParameterMap(0)
         parameter = Tpetra.Vector(parameter_map, dtype="d")
         for k in range(0, self.n_params):
             parameter[k] = theta_star[k]
         self.problem.setParameter(0, parameter)
     else:
         for k in range(0, self.n_params):
             parameter_map = self.problem.getParameterMap(k)
             parameter = Tpetra.Vector(parameter_map, dtype="d")
             parameter[0] = theta_star[k]
             self.problem.setParameter(k, parameter)
예제 #4
0
    def test_write_non_distributed_npy(self):
        cls = self.__class__
        rank = cls.comm.getRank()
        nproc = cls.comm.getSize()
        if nproc > 1:
            mvector_filename = 'out_mvector_write_test_' + str(nproc)
        else:
            mvector_filename = 'out_mvector_write_test'

        file_dir = os.path.dirname(__file__)

        filename = 'input.yaml'
        problem = Utils.createAlbanyProblem(file_dir + '/' + filename,
                                            cls.parallelEnv)

        n_cols = 4
        parameter_map = problem.getParameterMap(0)
        mvector = Tpetra.MultiVector(parameter_map, n_cols, dtype="d")

        mvector[0, :] = 1. * (rank + 1)
        mvector[1, :] = -1. * (rank + 1)
        mvector[2, :] = 3.26 * (rank + 1)
        mvector[3, :] = -3.1 * (rank + 1)

        Utils.writeMVector(file_dir + '/' + mvector_filename,
                           mvector,
                           distributedFile=False,
                           useBinary=True)
예제 #5
0
def evaluate_responses(X, Y, problem, recompute=False):
    if not recompute and os.path.isfile('Z1_2.txt'):
        Z1 = np.loadtxt('Z1_2.txt')
        Z2 = np.loadtxt('Z2_2.txt')
    else:
        comm = MPI.COMM_WORLD
        myGlobalRank = comm.rank

        parameter_map = problem.getParameterMap(0)
        parameter = Tpetra.Vector(parameter_map, dtype="d")

        n_x = len(X)
        n_y = len(Y)
        Z1 = np.zeros((n_y, n_x))
        Z2 = np.zeros((n_y, n_x))

        for i in range(n_x):
            parameter[0] = X[i]
            for j in range(n_y):
                parameter[1] = Y[j]
                problem.setParameter(0, parameter)

                problem.performSolve()

                Z1[j, i] = problem.getCumulativeResponseContribution(0, 0)
                Z2[j, i] = problem.getCumulativeResponseContribution(0, 1)

        np.savetxt('Z1_2.txt', Z1)
        np.savetxt('Z2_2.txt', Z2)
    return Z1, Z2
예제 #6
0
    def test_all(self):
        cls = self.__class__
        rank = cls.comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = 'input_conductivity_dist_paramT.yaml'
        problem = Utils.createAlbanyProblem(file_dir+'/'+filename, cls.parallelEnv)

        n_vecs = 4
        parameter_map = problem.getParameterMap(0)
        num_elems     = parameter_map.getNodeNumElements()
        
        # generate vectors with random entries
        omega = Tpetra.MultiVector(parameter_map, n_vecs, dtype="d")
        for i in range(n_vecs):
            omega[i,:] = np.random.randn(num_elems)
        
        # call the orthonormalization method
        wpa.orthogTpMVecs(omega, 2)
        
        # check that the vectors are now orthonormal
        tol = 1.e-12
        for i in range(n_vecs):
            for j in range(i+1):
                omegaiTomegaj = Utils.inner(omega[i,:], omega[j,:], cls.comm)
                if rank == 0:
                    if i == j:
                        self.assertTrue(abs(omegaiTomegaj - 1.0) < tol)
                    else:
                        self.assertTrue(abs(omegaiTomegaj-0.0) < tol)
예제 #7
0
def main(parallelEnv):
    comm = Teuchos.DefaultComm.getComm()
    filename = 'input_conductivity_dist_paramT.yaml'
    problem = Utils.createAlbanyProblem(filename, parallelEnv)

    # We can get from the Albany problem the map of a distributed parameter:
    parameter_map = problem.getParameterMap(0)

    # This map can then be used to construct an RCP to a Tpetra::Multivector:
    m_directions = 4
    directions = Tpetra.MultiVector(parameter_map, m_directions, dtype="d")

    # Numpy operations, such as assignments, can then be performed on the local entries:
    directions[0, :] = 1.  # Set all entries of v_0 to   1
    directions[1, :] = -1.  # Set all entries of v_1 to  -1
    directions[2, :] = 3.  # Set all entries of v_2 to   3
    directions[3, :] = -3.  # Set all entries of v_3 to  -3

    # Now that we have an RCP to the directions, we provide it to the Albany problem:
    problem.setDirections(0, directions)

    # Finally, we can solve the problem (which includes applying the Hessian to the directions)
    # and get the Hessian-vector products:
    problem.performSolve()
    hessian = problem.getReducedHessian(0, 0)
예제 #8
0
    def test_all(self):
        cls = self.__class__
        rank = cls.comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = "input_dirichlet_mixed_paramsT.yaml"
        parameter = Utils.createParameterList(file_dir + "/" + filename,
                                              cls.parallelEnv)

        parameter.sublist("Discretization").set("1D Elements", 10)
        parameter.sublist("Discretization").set("2D Elements", 10)

        problem = Utils.createAlbanyProblem(parameter, cls.parallelEnv)

        parameter_map_0 = problem.getParameterMap(0)
        para_0_new = Tpetra.Vector(parameter_map_0, dtype="d")

        parameter_map_1 = problem.getParameterMap(1)
        para_1_new = Tpetra.Vector(parameter_map_1, dtype="d")
        para_1_new[:] = 0.333333

        n_values = 5
        para_0_values = np.linspace(-1, 1, n_values)
        responses = np.zeros((n_values, ))

        responses_target = np.array(
            [0.69247527, 0.48990929, 0.35681844, 0.29320271, 0.2990621])
        tol = 1e-8

        for i in range(0, n_values):
            para_0_new[:] = para_0_values[i]
            problem.setParameter(0, para_0_new)

            problem.performSolve()

            response = problem.getResponse(0)
            responses[i] = response.getData()[0]

        print("p = " + str(para_0_values))
        print("QoI = " + str(responses))

        if rank == 0:
            self.assertTrue(
                np.abs(np.amax(responses - responses_target)) < tol)
예제 #9
0
 def _matvec(self, x):
     parameter_map = self.problem.getParameterMap(self.parameter_id)
     direction = Tpetra.MultiVector(parameter_map, 1, dtype="d")
     direction[0, :] = x
     self.problem.setDirections(self.parameter_id, direction)
     self.problem.performSolve()
     hessian = self.problem.getReducedHessian(self.response_id,
                                              self.parameter_id)
     return hessian[0, :]
예제 #10
0
def importanceSamplingEstimator(theta_0,
                                C,
                                theta_star,
                                F_star,
                                P_star,
                                samples_0,
                                problem,
                                F_id=1,
                                params_in_vector=True):
    invC = np.linalg.inv(C)
    n_l = len(F_star)
    P = np.zeros((n_l, ))
    n_samples = np.shape(samples_0)[0]
    n_params = np.shape(samples_0)[1]
    # Loop over the lambdas
    for i in range(0, n_l):
        # Loop over the samples
        for j in range(0, n_samples):
            sample = samples_0[j, :] + theta_star[i, :] - theta_0

            if params_in_vector:
                parameter_map = problem.getParameterMap(0)
                parameter = Tpetra.Vector(parameter_map, dtype="d")
                for j in range(0, n_params):
                    parameter[j] = sample[j]
                problem.setParameter(0, parameter)
            else:
                for k in range(0, n_params):
                    parameter_map = problem.getParameterMap(k)
                    parameter = Tpetra.Vector(parameter_map, dtype="d")
                    parameter[0] = sample[k]
                    problem.setParameter(k, parameter)
            problem.performSolve()

            if problem.getCumulativeResponseContribution(0, F_id) > F_star[i]:
                P[i] += np.exp(-invC.dot(theta_star[i, :] -
                                         theta_0).dot(sample -
                                                      theta_star[i, :]))
        P[i] = P_star[i] * P[i] / n_samples
    return P
예제 #11
0
def main(parallelEnv):
    comm = MPI.COMM_WORLD
    myGlobalRank = comm.rank

    # Create an Albany problem:
    filename = "input_dirichletT.yaml"
    parameter = Utils.createParameterList(
        filename, parallelEnv
    )

    problem = Utils.createAlbanyProblem(parameter, parallelEnv)

    parameter_map_0 = problem.getParameterMap(0)
    parameter_0 = Tpetra.Vector(parameter_map_0, dtype="d")

    N = 200
    p_min = -2.
    p_max = 2.

    # Generate N samples randomly chosen in [p_min, p_max]:
    p = np.random.uniform(p_min, p_max, N)
    QoI = np.zeros((N,))

    # Loop over the N samples and evaluate the quantity of interest:
    for i in range(0, N):
        parameter_0[0] = p[i]
        problem.setParameter(0, parameter_0)

        problem.performSolve()

        response = problem.getResponse(0)
        QoI[i] = response.getData()[0]

    if myGlobalRank == 0:
        if printPlot:
            f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(16,6))

            ax1.hist(p)
            ax1.set_ylabel('Counts')
            ax1.set_xlabel('Random parameter')

            ax2.scatter(p, QoI)
            ax2.set_ylabel('Quantity of interest')
            ax2.set_xlabel('Random parameter')

            ax3.hist(QoI)
            ax3.set_ylabel('Counts')
            ax3.set_xlabel('Quantity of interest')

            plt.savefig('UQ.jpeg', dpi=800)
            plt.close()
예제 #12
0
    def test_all(self):
        cls = self.__class__
        rank = cls.comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = 'input_conductivity_dist_paramT.yaml'
        problem = Utils.createAlbanyProblem(file_dir+'/'+filename, cls.parallelEnv)

        n_directions = 4
        parameter_map = problem.getParameterMap(0)
        directions = Tpetra.MultiVector(parameter_map, n_directions, dtype="d")

        directions[0,:] = 1.
        directions[1,:] = -1.
        directions[2,:] = 3.
        directions[3,:] = -3.

        problem.setDirections(0, directions)

        problem.performSolve()

        response = problem.getResponse(0)
        sensitivity = problem.getSensitivity(0, 0)
        hessian = problem.getReducedHessian(0, 0)

        g_target = 3.23754626955999991e-01
        norm_target = 8.94463776843999921e-03
        h_target = np.array([0.009195356672103817, 0.009195356672103817, 0.027586070971800013, 0.027586070971800013])

        g_data = response.getData()
        norm = Utils.norm(sensitivity.getData(0), cls.comm)

        print("g_target = " + str(g_target))
        print("g_data[0] = " + str(g_data[0]))
        print("norm = " + str(norm))
        print("norm_target = " + str(norm_target))

        hessian_norms = np.zeros((n_directions,))
        for i in range(0,n_directions):
            hessian_norms[i] = Utils.norm(hessian.getData(i), cls.comm)

        tol = 1e-8
        if rank == 0:
            self.assertTrue(np.abs(g_data[0]-g_target) < tol)
            self.assertTrue(np.abs(norm-norm_target) < tol)
            for i in range(0,n_directions):
                self.assertTrue(np.abs(hessian_norms[i]-h_target[i]) < tol)
예제 #13
0
파일: steadyHeat.py 프로젝트: koomie/Albany
    def test_all(self):
        comm = Teuchos.DefaultComm.getComm()
        rank = comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = 'input_conductivity_dist_paramT.yaml'
        problem = Utils.createAlbanyProblem(file_dir + '/' + filename)

        n_directions = 4
        parameter_map = problem.getParameterMap(0)
        directions = Tpetra.MultiVector(parameter_map, n_directions, dtype="d")

        directions[0, :] = 1.
        directions[1, :] = -1.
        directions[2, :] = 3.
        directions[3, :] = -3.

        problem.setDirections(0, directions)

        problem.performSolve()

        response = problem.getResponse(0)
        sensitivity = problem.getSensitivity(0, 0)
        hessian = problem.getReducedHessian(0, 0)

        g_target = 3.23754626955999991e-01
        norm_target = 8.94463776843999921e-03
        h_target = np.array([
            4.2121719763904516e-05, -4.21216874727712e-05,
            0.00012636506241831498, -0.00012636506241831496
        ])

        g_data = response.getData()
        norm = Utils.norm(sensitivity.getData(0), comm)

        print("g_target = " + str(g_target))
        print("g_data[0] = " + str(g_data[0]))
        print("norm = " + str(norm))
        print("norm_target = " + str(norm_target))

        tol = 1e-8
        if rank == 0:
            self.assertTrue(np.abs(g_data[0] - g_target) < tol)
            self.assertTrue(np.abs(norm - norm_target) < tol)
            for i in range(0, n_directions):
                self.assertTrue(np.abs(hessian[i, 0] - h_target[i]) < tol)
예제 #14
0
    def _matvec(self, x):
        tmp1 = self.C_sqr.dot(self.R.dot(self.P.transpose().dot(x)))

        parameter_map = self.problem.getParameterMap(self.parameter_id)
        direction = Tpetra.MultiVector(parameter_map, 1, dtype="d")

        direction[0, :] = tmp1
        self.problem.setDirections(self.parameter_id, direction)
        self.problem.performSolve()
        hessian = self.problem.getReducedHessian(self.response_id,
                                                 self.parameter_id)

        tmp2 = hessian[0, :]
        tmp3 = self.P.dot(self.R.transpose().dot(
            self.C_sqr.transpose().dot(tmp2)))
        return tmp3
예제 #15
0
    def test_all(self):
        cls = self.__class__
        rank = cls.comm.getRank()

        file_dir = os.path.dirname(__file__)

        # Create an Albany problem:
        filename = "input_dirichlet_mixed_paramsT.yaml"
        parameter = Utils.createParameterList(
            file_dir + "/" + filename, cls.parallelEnv
        )

        parameter.sublist("Discretization").set("1D Elements", 10)
        parameter.sublist("Discretization").set("2D Elements", 10)

        problem = Utils.createAlbanyProblem(parameter, cls.parallelEnv)

        g_target_before = 0.35681844
        g_target_after = 0.17388298
        g_target_2 = 0.19570272
        p_0_target = 0.39886689
        p_1_norm_target = 5.37319376038225
        tol = 1e-8

        problem.performSolve()

        response_before_analysis = problem.getResponse(0)

        problem.performAnalysis()

        para_0 = problem.getParameter(0)
        para_1 = problem.getParameter(1)

        print(para_0.getData())
        print(para_1.getData())

        para_1_norm = Utils.norm(para_1.getData(), cls.comm)
        print(para_1_norm)

        if rank == 0:
            self.assertTrue(np.abs(para_0[0] - p_0_target) < tol)
            self.assertTrue(np.abs(para_1_norm - p_1_norm_target) < tol)

        problem.performSolve()

        response_after_analysis = problem.getResponse(0)

        print("Response before analysis " + str(response_before_analysis.getData()))
        print("Response after analysis " + str(response_after_analysis.getData()))
        if rank == 0:
            self.assertTrue(np.abs(response_before_analysis[0] - g_target_before) < tol)
            self.assertTrue(np.abs(response_after_analysis[0] - g_target_after) < tol)

        parameter_map_0 = problem.getParameterMap(0)
        para_0_new = Tpetra.Vector(parameter_map_0, dtype="d")
        para_0_new[:] = 0.0
        problem.setParameter(0, para_0_new)

        problem.performSolve()

        response = problem.getResponse(0)
        print("Response after setParameter " + str(response.getData()))
        if rank == 0:
            self.assertTrue(np.abs(response[0] - g_target_2) < tol)
예제 #16
0
def mixedImportanceSamplingEstimator(theta_0,
                                     C,
                                     theta_star,
                                     F_star,
                                     P_star,
                                     samples_0,
                                     problem,
                                     angle_1,
                                     angle_2,
                                     F_id=1,
                                     params_in_vector=True):
    invC = np.linalg.inv(C)
    n_l = len(F_star)
    P = np.zeros((n_l, ))
    n_samples = np.shape(samples_0)[0]
    n_params = np.shape(samples_0)[1]

    problem.updateCumulativeResponseContributionWeigth(0, 0, -1)
    problem.updateCumulativeResponseContributionWeigth(0, F_id, 0)
    # Loop over the lambdas
    for i in range(0, n_l):
        # Compute the normal of I - lambda F (= normal of F)
        n_theta_star = np.zeros((n_params, ))

        if params_in_vector:
            parameter_map = problem.getParameter(0)
            parameter = Tpetra.Vector(parameter_map, dtype="d")
            for j in range(0, n_params):
                parameter[j] = theta_star[i, j]
            problem.setParameter(0, parameter)
        else:
            for k in range(0, n_params):
                parameter_map = problem.getParameterMap(k)
                parameter = Tpetra.Vector(parameter_map, dtype="d")
                parameter[0] = theta_star[i, k]
                problem.setParameter(k, parameter)

        problem.performSolve()
        if params_in_vector:
            n_theta_star = -problem.getSensitivity(0, 0).getData(0)
        else:
            for k in range(0, n_params):
                n_theta_star[k] = -problem.getSensitivity(0, k).getData(0)[0]
        norm = np.linalg.norm(n_theta_star)
        n_theta_star /= norm

        # Loop over the samples
        for j in range(0, n_samples):

            vector_2 = samples_0[j, :] - theta_0
            unit_vector_2 = vector_2 / np.linalg.norm(vector_2)
            dot_product = np.dot(n_theta_star, unit_vector_2)
            shifted_sample_angles = np.arccos(dot_product)

            sample = samples_0[j, :] + theta_star[i, :] - theta_0

            if shifted_sample_angles < angle_1:
                current_F_above = True
            elif shifted_sample_angles > angle_2:
                current_F_above = False
            else:

                if params_in_vector:
                    parameter_map = problem.getParameter(0)
                    parameter = Tpetra.Vector(parameter_map, dtype="d")
                    for j in range(0, n_params):
                        parameter[j] = sample[j]
                    problem.setParameter(0, parameter)
                else:
                    for k in range(0, n_params):
                        parameter_map = problem.getParameterMap(k)
                        parameter = Tpetra.Vector(parameter_map, dtype="d")
                        parameter[0] = sample[k]
                        problem.setParameter(k, parameter)
                problem.performSolve()
                current_F_above = problem.getCumulativeResponseContribution(
                    0, F_id) > F_star[i]
            if current_F_above:
                P[i] += np.exp(-invC.dot(theta_star[i, :] -
                                         theta_0).dot(sample -
                                                      theta_star[i, :]))
        P[i] = P_star[i] * P[i] / n_samples
    return P
예제 #17
0
def main(parallelEnv):
    comm = MPI.COMM_WORLD
    nMaxProcs = comm.Get_size()
    myGlobalRank = comm.rank

    timerNames = [
        "PyAlbany: Create Albany Problem", "PyAlbany: Set directions",
        "PyAlbany: Perform Solve", "PyAlbany: Total"
    ]

    nTimers = len(timerNames)

    # number of times that the test is repeated for a fixed
    # number of MPI processes
    N = 10

    timers_sec = np.zeros((nMaxProcs, nTimers, N))
    mean_timers_sec = np.zeros((nMaxProcs, nTimers))

    speedUp = np.zeros((nMaxProcs, nTimers))

    for nProcs in range(1, nMaxProcs + 1):
        newGroup = comm.group.Incl(np.arange(0, nProcs))
        newComm = comm.Create_group(newGroup)

        if myGlobalRank < nProcs:
            parallelEnv.comm = Teuchos.MpiComm(newComm)

            for i_test in range(0, N):
                timers = Utils.createTimers(timerNames)
                timers[3].start()
                timers[0].start()

                filename = 'input_conductivity_dist_paramT.yaml'
                problem = Utils.createAlbanyProblem(filename, parallelEnv)
                timers[0].stop()

                timers[1].start()
                n_directions = 4
                parameter_map = problem.getParameterMap(0)
                directions = Tpetra.MultiVector(parameter_map,
                                                n_directions,
                                                dtype="d")

                directions[0, :] = 1.
                directions[1, :] = -1.
                directions[2, :] = 3.
                directions[3, :] = -3.

                problem.setDirections(0, directions)
                timers[1].stop()

                timers[2].start()
                problem.performSolve()
                timers[2].stop()
                timers[3].stop()

                if myGlobalRank == 0:
                    for j in range(0, nTimers):
                        timers_sec[nProcs - 1, j,
                                   i_test] = timers[j].totalElapsedTime()

    if myGlobalRank == 0:
        for i in range(0, nMaxProcs):
            for j in range(0, nTimers):
                mean_timers_sec[i, j] = np.mean(timers_sec[i, j, :])
            speedUp[i, :] = mean_timers_sec[0, :] / (mean_timers_sec[i, :])

        print('timers')
        print(mean_timers_sec)

        print('speed up')
        print(speedUp)
        if printPlot:
            fig = plt.figure(figsize=(10, 6))
            plt.plot(np.arange(1, nMaxProcs + 1), np.arange(1, nMaxProcs + 1),
                     '--')
            for j in range(0, nTimers):
                plt.plot(np.arange(1, nMaxProcs + 1),
                         speedUp[:, j],
                         'o-',
                         label=timerNames[j])
            plt.ylabel('speed up')
            plt.xlabel('number of MPI processes')
            plt.grid(True)
            plt.legend()
            plt.savefig('speedup.jpeg', dpi=800)
            plt.close()
예제 #18
0
def loadMVector(filename,
                n_cols,
                map,
                distributedFile=True,
                useBinary=True,
                readOnRankZero=True,
                dtype="d"):
    """@brief Loads distributed a multivector stored using numpy format.
    
    \param filename [in] Base name of the file(s) to load.
    \param n_cols [in] Number of columns of the multivector.
    \param map [in] Tpetra map of the multivector which has to be loaded.
    \param distributedFile (default: True) [in] Bool which specifies whether each MPI process reads a different
    file (if distributedFile==True, MPI process i reads filename+"_"+str(i)) or if all the entries are stored inside
    a unique file.
    \param useBinary (default: True) [in] Bool which specifies if the function reads a binary or a text file.
    \param readOnRankZero (default: True) [in] Bool which specifies if the file is read by the rank 0 and scattered or if
    it is read by all the MPI processes.
    \param dtype (default: "d") [in] Data type of the entries of the multivector.
    """
    rank = map.getComm().getRank()
    nproc = map.getComm().getSize()
    mvector = Tpetra.MultiVector(map, n_cols, dtype=dtype)
    if nproc == 1:
        if useBinary:
            mVectorNP = np.load(filename + '.npy')
        else:
            mVectorNP = np.loadtxt(filename + '.txt')

        if (mVectorNP.ndim == 1 and n_cols == 1):
            mvector[0, :] = mVectorNP
        else:
            for i in range(0, n_cols):
                mvector[i, :] = mVectorNP[i, :]
    elif distributedFile:
        if useBinary:
            mVectorNP = np.load(filename + '_' + str(rank) + '.npy')
        else:
            mVectorNP = np.loadtxt(filename + '_' + str(rank) + '.txt')
        for i in range(0, n_cols):
            mvector[i, :] = mVectorNP[i, :]
    else:
        if readOnRankZero:
            map0 = wpa.getRankZeroMap(map)
            mvector0 = Tpetra.MultiVector(map0, n_cols, dtype=dtype)
            if rank == 0:
                if useBinary:
                    mVectorNP = np.load(filename + '.npy')
                else:
                    mVectorNP = np.loadtxt(filename + '.txt')

                if (mVectorNP.ndim == 1 and n_cols == 1):
                    mvector0[0, :] = mVectorNP
                else:
                    for i in range(0, n_cols):
                        mvector0[i, :] = mVectorNP[i, :]
            mvector = wpa.scatterMVector(mvector0, map)
        else:
            if useBinary:
                mVectorNP = np.load(filename + '.npy')
            else:
                mVectorNP = np.loadtxt(filename + '.txt')
            for lid in range(0, map.getNodeNumElements()):
                gid = map.getGlobalElement(lid)
                mvector[:, lid] = mVectorNP[:, gid]
    return mvector