Ejemplo n.º 1
0
void read_output(EquationSystems & es,
                 unsigned int t_step,
                 unsigned int a_step,
                 std::string solution_type,
                 FEMParameters & param)
{
    MeshBase & mesh = es.get_mesh();

    std::string file_name_mesh, file_name_soln;
    // Look for ASCII files first
    if (param.output_xda)
    {
        file_name_mesh = numbered_filename(t_step, a_step, solution_type, "mesh", "xda", param);
        file_name_soln = numbered_filename(t_step, a_step, solution_type, "soln", "xda", param);
    }
    else if (param.output_xdr)
    {
        file_name_mesh = numbered_filename(t_step, a_step, solution_type, "mesh", "xdr", param);
        file_name_soln = numbered_filename(t_step, a_step, solution_type, "soln", "xdr", param);
    }

    // Read in the mesh
    mesh.read(file_name_mesh);

    // And the stored solution
    es.read(file_name_soln, READ,
            EquationSystems::READ_HEADER |
            EquationSystems::READ_DATA |
            EquationSystems::READ_ADDITIONAL_DATA);

    // Put systems in a consistent state
    for (unsigned int i = 0; i != es.n_systems(); ++i)
        es.get_system<FEMSystem>(i).update();

    // Figure out the current time
    Real current_time = 0., current_timestep = 0.;

    if (param.timesolver_tolerance)
    {
        std::ifstream times ("out_time.m");
        std::ifstream timesteps ("out_timesteps.m");
        if (times.is_open() && timesteps.is_open())
        {
            // Read headers
            const unsigned int headersize = 25;
            char header[headersize];
            timesteps.getline (header, headersize);
            if (strcmp(header, "vector_timesteps = [") != 0)
                libmesh_error_msg("Bad header in out_timesteps.m:\n" << header);

            times.getline (header, headersize);
            if (strcmp(header, "vector_time = [") != 0)
                libmesh_error_msg("Bad header in out_time.m:\n" << header);

            // Read each timestep
            for (unsigned int i = 0; i != t_step; ++i)
            {
                if (!times.good())
                    libmesh_error_msg("Error: File out_time.m is in non-good state.");
                times >> current_time;
                timesteps >> current_timestep;
            }
            // Remember to increment the last timestep; out_times.m
            // lists each *start* time
            current_time += current_timestep;
        }
        else