/** * @file com_check_relative_residual.cpp * @author Julian Iseringhausen * @date Mon Apr 18 12:30:18 2011 * * @brief Checks if the relative residual is small enough * to stop execution. * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "base/command.hpp" #include "base/factory.hpp" #include "base/object.hpp" #include "comm/comm.hpp" #include "grid/multigrid.hpp" #include "mg.hpp" using namespace VMG; class VMGCommandCheckRelativeResidual : public Command { public: Request Run(Command::argument_vector arguments) { VMG::Comm* comm = MG::GetComm(); VMG::Factory& factory = MG::GetFactory(); const vmg_float res = comm->ComputeResidualNorm(*MG::GetSol(), *MG::GetRhs()); const vmg_float& init_res = factory.GetObject(arguments[0])->Cast< ObjectStorage >()->Val(); const vmg_float& precision = factory.GetObject("PRECISION")->Cast< ObjectStorage >()->Val(); const vmg_float rel_res = fabs(res / init_res); if (comm->Rank() == 0) printf("Multigrid: Relative residual: %e\n", rel_res); if (rel_res < precision) return StopCycleLater; else return Continue; } static const char* Name() {return "CheckRelativeResidual";} static int Arguments() {return 1;} }; CREATE_INITIALIZER(VMGCommandCheckRelativeResidual);