Ejemplo n.º 1
0
//---------------------------------------------------------------------------
//Reading the parameters of simulation
int Input::Read_simulation_parameters(struct Simu_para &simu_para, ifstream &infile)
{
    if(simu_para.mark)
    {
        cout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl;
        return 0;
    }
    else simu_para.mark = true;

    istringstream istr0(Get_Line(infile));
    istr0 >> simu_para.simu_name;			//Read the name of simulation

    istringstream istr1(Get_Line(infile));
    istr1 >> simu_para.sample_num;			//Read the number of samples
    if(simu_para.sample_num<1)	 {
        hout << "Error: the number of samples less than 1." << endl;
        return 0;
    }

    istringstream istr2(Get_Line(infile));
    istr2 >> simu_para.create_read_network;		//Read a signal to show if create a new network or read a previouse network from a file
    if(simu_para.create_read_network!="Create_Network"&&simu_para.create_read_network!="Read_Network")
    {
        hout << "Error: the 'create_read_network' is neither 'Create_Network' nor 'Read_Network'." << endl;
        return 0;
    }

    return 1;
}
Ejemplo n.º 2
0
int check_for_error(int argc, char** argv) {
	if (argc != 3)
		return through_error(1);

	//check for first file reading failure or whether file is available or not
	std::ifstream istr(argv[1]);
	if (istr.fail())
		return through_error(2, argv[1]);

	//check for second file reading failure or whether file is available or not
	std::ifstream istr1(argv[2]);
	if (istr1.fail())
		return through_error(2, argv[2]);
	return 1;
}
Ejemplo n.º 3
0
std::string Settings::Suppressions::addSuppressionLine(const std::string &line)
{
    std::istringstream lineStream(line);
    std::string id;
    std::string file;
    unsigned int lineNumber = 0;
    if (std::getline(lineStream, id, ':'))
    {
        if (std::getline(lineStream, file))
        {
            // If there is not a dot after the last colon in "file" then
            // the colon is a separator and the contents after the colon
            // is a line number..

            // Get position of last colon
            const std::string::size_type pos = file.rfind(":");

            // if a colon is found and there is no dot after it..
            if (pos != std::string::npos &&
                file.find(".", pos) == std::string::npos)
            {
                // Try to parse out the line number
                try
                {
                    std::istringstream istr1(file.substr(pos+1));
                    istr1 >> lineNumber;
                }
                catch (...)
                {
                    lineNumber = 0;
                }

                if (lineNumber > 0)
                {
                    file.erase(pos);
                }
            }
        }
    }

    // We could perhaps check if the id is valid and return error if it is not
    const std::string errmsg(addSuppression(id, file, lineNumber));
    if (!errmsg.empty())
        return errmsg;

    return "";
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------------
//Reading geometric information of the RVE
int Input::Read_rve_geometry(struct Geom_RVE &geom_rve, ifstream &infile)
{
    if(geom_rve.mark)
    {
        cout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl;
        return 0;
    }
    else geom_rve.mark = true;

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the domain of RVE: the lower-left corner point of RVE and the length, width and height of RVE
    istringstream istr0(Get_Line(infile));
    istr0 >> geom_rve.origin.x >> geom_rve.origin.y >> geom_rve.origin.z;
    istr0 >> geom_rve.len_x >> geom_rve.wid_y >> geom_rve.hei_z;
    if(geom_rve.len_x<=0||geom_rve.wid_y<=0||geom_rve.hei_z<=0)
    {
        cout << "Error: the sizes of RVE should be positive!" << endl;
        hout << "Error: the sizes of RVE should be positive!" << endl;
        return 0;
    }
    geom_rve.volume = geom_rve.len_x*geom_rve.wid_y*geom_rve.hei_z;

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the size range of the observation window and descrement by every step in x, y and z directions
    istringstream istr1(Get_Line(infile));
    istr1 >> geom_rve.win_max_x >> geom_rve.win_max_y >> geom_rve.win_max_z;
    istringstream istr2(Get_Line(infile));
    istr2 >> geom_rve.win_delt_x >> geom_rve.win_delt_y >> geom_rve.win_delt_z;
    istringstream istr3(Get_Line(infile));
    istr3 >> geom_rve.win_min_x >> geom_rve.win_min_y >> geom_rve.win_min_z;

    if(geom_rve.win_max_x<=0.0||geom_rve.win_max_y<=0.0||geom_rve.win_max_z<=0.0||
            geom_rve.win_max_x>geom_rve.len_x||geom_rve.win_max_y>geom_rve.wid_y||geom_rve.win_max_z>geom_rve.hei_z)
    {
        cout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl;
        hout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl;
        return 0;
    }
    if(geom_rve.win_min_x<=0.0||geom_rve.win_min_y<=0.0||geom_rve.win_min_z<=0.0||
            geom_rve.win_min_x>geom_rve.win_max_x||geom_rve.win_min_y>geom_rve.win_max_y||geom_rve.win_min_z>geom_rve.win_max_z)
    {
        cout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl;
        hout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl;
        return 0;
    }
    if(geom_rve.win_delt_x<=0.0||geom_rve.win_delt_y<=0.0||geom_rve.win_delt_z<=0.0)
    {
        cout << "Error: the win_delt in each direction of RVE should be positive." << endl;
        hout << "Error: the win_delt in each direction of RVE should be positive." << endl;
        return 0;
    }

    //Details: +Zero for reducing the error of division
    int num[3] = {	(int)((geom_rve.win_max_x-geom_rve.win_min_x + Zero)/geom_rve.win_delt_x),
                    (int)((geom_rve.win_max_y-geom_rve.win_min_y + Zero)/geom_rve.win_delt_y),
                    (int)((geom_rve.win_max_z-geom_rve.win_min_z + Zero)/geom_rve.win_delt_z)
                 };

    if(num[0]!=num[1]||num[0]!=num[2])
    {
        cout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl;
        hout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl;
        return 0;
    }
    else geom_rve.cut_num = num[0];

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the minimum size for background grids (looking for contact points)
    istringstream istr4(Get_Line(infile));
    istr4 >> geom_rve.gs_minx >> geom_rve.gs_miny >> geom_rve.gs_minz;
    if(geom_rve.gs_minx<=0||geom_rve.gs_miny<=0||geom_rve.gs_minz<=0)
    {
        cout << "Error: the number of segments in each direction of RVE should be positive!" << endl;
        hout << "Error: the number of segments in each direction of RVE should be positive" << endl;
        return 0;
    }
    else if((int)(geom_rve.win_max_x/geom_rve.gs_minx)>500||
            (int)(geom_rve.win_max_y/geom_rve.gs_miny)>500||
            (int)(geom_rve.win_max_z/geom_rve.gs_minz)>500)
    {
        cout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl;
        hout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl;
        return 0;
    }

    return 1;
}