idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.74k stars 1.05k forks source link

Adding a solution vector screen print out for debugging purpose #1003

Closed YaqiWang closed 10 years ago

YaqiWang commented 10 years ago

It is nice to have a method under FEProblem like printSolution(bool current). Developers can quickly see what the solution is during debugging an executioner.

A possible implementation is (I originally designed uner Executioner):

void Executioner::printSystemSolution(FEProblem & problem, bool current) { std::set var_indices;

// print the primal system { TransientNonlinearImplicitSystem &system = problem.getNonlinearSystem().sys();

unsigned int n_vars = system.n_vars();
std::vector<std::string> var_name;
for(unsigned int i=0;i<n_vars;++i)
{
  std::string variable_name = system.variable_name(i);
  var_name.push_back(variable_name); 
}

for(unsigned int j=0; j<var_name.size(); j++)   
{
  std::cout << var_name[<< ":" << std::endl;
  int i = system.variable_number(var_name[j](j]).c_str());
  system.local_dof_indices(i,var_indices);
  std::set<unsigned int>::iterator it_beg = var_indices.begin();
  std::set<unsigned int>::iterator it = var_indices.begin();
  std::set<unsigned int>::iterator it_end = var_indices.end();
  if (current)
    for(; it !=it_end; ++it)
      std::cout << " "  << *it << ' ' << (*system.solution)(*it) << std::endl;
  else
    for(; it !=it_end; ++it)
      std::cout << " "  << *it << ' ' << (*system.old_local_solution)(*it) << std::endl;
}

}

// aux system { TransientExplicitSystem &system = problem.getAuxiliarySystem().sys();

unsigned int n_vars = system.n_vars();
std::vector<std::string> var_name;
for(unsigned int i=0;i<n_vars;++i)
{
  std::string variable_name = system.variable_name(i);
  var_name.push_back(variable_name); 
}

for(unsigned int j=0; j<var_name.size(); j++)   
{
  std::cout << var_name[<< ":" << std::endl;
  int i = system.variable_number(var_name[j](j]).c_str());
  system.local_dof_indices(i,var_indices);
  std::set<unsigned int>::iterator it_beg = var_indices.begin();
  std::set<unsigned int>::iterator it = var_indices.begin();
  std::set<unsigned int>::iterator it_end = var_indices.end();
  if (current)
    for(; it !=it_end; ++it)
      std::cout << " "  << *it << ' ' << (*system.solution)(*it) << std::endl;
  else
    for(; it !=it_end; ++it)
      std::cout << " "  << *it << ' ' << (*system.old_local_solution)(*it) << std::endl;
}

} }

permcody commented 10 years ago

@YaqiWang - you might make a custom Outputter using the new system. This ticket is no longer valid.