void SolutionUserObject::updateExodusTimeInterpolation(Real time) { if (time != _interpolation_time) { if (updateExodusBracketingTimeIndices(time)) { for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) _exodusII_io->copy_nodal_solution(*_system, *it, _exodus_index1+1); for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) _exodusII_io->copy_elemental_solution(*_system, *it, *it, _exodus_index1+1); _system->update(); _es->update(); _system->solution->localize(*_serialized_solution); for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) _exodusII_io->copy_nodal_solution(*_system2, *it, _exodus_index2+1); for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) _exodusII_io->copy_elemental_solution(*_system2, *it, *it, _exodus_index1+1); _system2->update(); _es2->update(); _system2->solution->localize(*_serialized_solution2); } _interpolation_time = time; } }
void SolutionUserObject::readExodusII() { // Define a default system name if (_system_name == "") _system_name = "SolutionUserObjectSystem"; // Interpolate between times rather than using values from a set timestep if (_exodus_time_index == -1) _interpolate_times = true; // Read the file // Read the Exodus file _exodusII_io = new ExodusII_IO (*_mesh); _exodusII_io->read(_mesh_file); _exodus_times = &_exodusII_io->get_time_steps(); // Check that the number of time steps is valid int num_exo_times = _exodus_times->size(); if (num_exo_times == 0) mooseError("In SolutionUserObject, exodus file contains no timesteps."); // Account for parallel mesh if (dynamic_cast<ParallelMesh *>(_mesh)) { _mesh->allow_renumbering(true); _mesh->prepare_for_use(/*false*/); } else { _mesh->allow_renumbering(false); _mesh->prepare_for_use(/*true*/); } // Create EquationSystems object for solution _es = new EquationSystems(*_mesh); _es->add_system<ExplicitSystem> (_system_name); _system = &_es->get_system(_system_name); // Add the nodal variables to the system for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) _system->add_variable(*it, FIRST); for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) _system->add_variable(*it, CONSTANT, MONOMIAL); // Initilize the equations systems _es->init(); // Interpolate times if (_interpolate_times) { // Create a second equation system _es2 = new EquationSystems(*_mesh); _es2->add_system<ExplicitSystem> (_system_name); _system2 = &_es2->get_system(_system_name); // Add the variables for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) _system2->add_variable(*it, FIRST); for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) _system2->add_variable(*it, CONSTANT, MONOMIAL); // Initialize _es2->init(); // Update the times for interpolation (initially start at 0) updateExodusBracketingTimeIndices(0.0); // Copy the nodal solution to the equations systems from the Exodus file for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) { _exodusII_io->copy_nodal_solution(*_system, *it, *it, _exodus_index1+1); _exodusII_io->copy_nodal_solution(*_system2, *it, *it, _exodus_index2+1); } // Copy the elemental solution to the equations systems from the Exodus file for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) { _exodusII_io->copy_elemental_solution(*_system, *it, *it, _exodus_index1+1); _exodusII_io->copy_elemental_solution(*_system2, *it, *it, _exodus_index2+1); } // Update the systems _system->update(); _es->update(); _system2->update(); _es2->update(); // Populate variable numbers for the second system std::vector<unsigned int> var_num2; _system2->get_all_variable_numbers(var_num2); // Need to pull down a full copy of this vector on every processor so we can get values in parallel _serialized_solution2 = NumericVector<Number>::build(_communicator).release(); _serialized_solution2->init(_system2->n_dofs(), false, SERIAL); _system2->solution->localize(*_serialized_solution2); // Create the MeshFunction for the second copy of the data _mesh_function2 = new MeshFunction(*_es2, *_serialized_solution2, _system2->get_dof_map(), var_num2); _mesh_function2->init(); } // Non-interpolated times else { if (_exodus_time_index > num_exo_times) mooseError("In SolutionUserObject, timestep = "<<_exodus_time_index<<", but there are only "<<num_exo_times<<" time steps."); // Copy the values from the ExodusII file for (std::vector<std::string>::const_iterator it = _nodal_vars.begin(); it != _nodal_vars.end(); ++it) _exodusII_io->copy_nodal_solution(*_system, *it, *it, _exodus_time_index); for (std::vector<std::string>::const_iterator it = _elem_vars.begin(); it != _elem_vars.end(); ++it) _exodusII_io->copy_elemental_solution(*_system, *it, *it, _exodus_time_index); // Update the equations systems _system->update(); _es->update(); } }
void SolutionUserObject::readExodusII() { // Define a default system name if (_system_name == "") _system_name = "SolutionUserObjectSystem"; // Interpolate between times rather than using values from a set timestep if (_exodus_time_index == -1) _interpolate_times = true; // Read the file // Read the Exodus file _exodusII_io = new ExodusII_IO (*_mesh); _exodusII_io->read(_mesh_file); _exodus_times = &_exodusII_io->get_time_steps(); // Check that the number of time steps is valid int num_exo_times = _exodus_times->size(); if (num_exo_times == 0) mooseError("In SolutionUserObject, exodus file contains no timesteps."); // Account for parallel mesh if (dynamic_cast<ParallelMesh *>(_mesh)) { _mesh->allow_renumbering(true); _mesh->prepare_for_use(/*false*/); } else { _mesh->allow_renumbering(false); _mesh->prepare_for_use(/*true*/); } // Create EquationSystems object for solution _es = new EquationSystems(*_mesh); _es->add_system<ExplicitSystem> (_system_name); _system = &_es->get_system(_system_name); // Get the variable name lists as set; these need to be sets to perform set_intersection const std::vector<std::string> & all_nodal(_exodusII_io->get_nodal_var_names()); const std::vector<std::string> & all_elemental(_exodusII_io->get_elem_var_names()); // Storage for the nodal and elemental variables to consider std::vector<std::string> nodal, elemental; // Build nodal/elemental variable lists, limit to variables listed in 'system_variables', if provided if (!_system_variables.empty()) { for (std::vector<std::string>::const_iterator it = _system_variables.begin(); it != _system_variables.end(); ++it) { if (std::find(all_nodal.begin(), all_nodal.end(), *it) != all_nodal.end()) nodal.push_back(*it); if (std::find(all_elemental.begin(), all_elemental.end(), *it) != all_elemental.end()) elemental.push_back(*it); } } else { nodal = all_nodal; elemental = all_elemental; } // Add the variables to the system for (std::vector<std::string>::const_iterator it = nodal.begin(); it != nodal.end(); ++it) _system->add_variable(*it, FIRST); for (std::vector<std::string>::const_iterator it = elemental.begin(); it != elemental.end(); ++it) _system->add_variable(*it, CONSTANT, MONOMIAL); // Initilize the equations systems _es->init(); // Interpolate times if (_interpolate_times) { // Create a second equation system _es2 = new EquationSystems(*_mesh); _es2->add_system<ExplicitSystem> (_system_name); _system2 = &_es2->get_system(_system_name); // Add the variables to the system for (std::vector<std::string>::const_iterator it = nodal.begin(); it != nodal.end(); ++it) _system2->add_variable(*it, FIRST); for (std::vector<std::string>::const_iterator it = elemental.begin(); it != elemental.end(); ++it) _system2->add_variable(*it, CONSTANT, MONOMIAL); // Initialize _es2->init(); // Update the times for interpolation (initially start at 0) updateExodusBracketingTimeIndices(0.0); // Copy the solutions from the first system for (std::vector<std::string>::const_iterator it = nodal.begin(); it != nodal.end(); ++it) { _exodusII_io->copy_nodal_solution(*_system, *it, *it, _exodus_index1+1); _exodusII_io->copy_nodal_solution(*_system2, *it, *it, _exodus_index2+1); } for (std::vector<std::string>::const_iterator it = elemental.begin(); it != elemental.end(); ++it) { _exodusII_io->copy_elemental_solution(*_system, *it, *it, _exodus_index1+1); _exodusII_io->copy_elemental_solution(*_system2, *it, *it, _exodus_index2+1); } // Update the systems _system->update(); _es->update(); _system2->update(); _es2->update(); } // Non-interpolated times else { if (_exodus_time_index > num_exo_times) mooseError("In SolutionUserObject, timestep = "<<_exodus_time_index<<", but there are only "<<num_exo_times<<" time steps."); // Copy the values from the ExodusII file for (std::vector<std::string>::const_iterator it = nodal.begin(); it != nodal.end(); ++it) _exodusII_io->copy_nodal_solution(*_system, *it, *it, _exodus_time_index); for (std::vector<std::string>::const_iterator it = elemental.begin(); it != elemental.end(); ++it) _exodusII_io->copy_elemental_solution(*_system, *it, *it, _exodus_time_index); // Update the equations systems _system->update(); _es->update(); } }