| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @file com_check_relative_residual.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:30:18 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Checks if the relative residual is small enough
|
|---|
| 7 | * to stop execution.
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #ifdef HAVE_CONFIG_H
|
|---|
| 12 | #include <config.h>
|
|---|
| 13 | #endif
|
|---|
| 14 |
|
|---|
| 15 | #include <cmath>
|
|---|
| 16 | #include <cstdio>
|
|---|
| 17 |
|
|---|
| 18 | #include "base/command.hpp"
|
|---|
| 19 | #include "base/factory.hpp"
|
|---|
| 20 | #include "base/object.hpp"
|
|---|
| 21 | #include "comm/comm.hpp"
|
|---|
| 22 | #include "grid/multigrid.hpp"
|
|---|
| 23 | #include "mg.hpp"
|
|---|
| 24 |
|
|---|
| 25 | using namespace VMG;
|
|---|
| 26 |
|
|---|
| 27 | class VMGCommandCheckRelativeResidual : public Command
|
|---|
| 28 | {
|
|---|
| 29 | public:
|
|---|
| 30 | Request Run(Command::argument_vector arguments)
|
|---|
| 31 | {
|
|---|
| 32 | VMG::Comm* comm = MG::GetComm();
|
|---|
| 33 | VMG::Factory& factory = MG::GetFactory();
|
|---|
| 34 |
|
|---|
| 35 | const vmg_float res = comm->ComputeResidualNorm(*MG::GetSol(), *MG::GetRhs());
|
|---|
| 36 | const vmg_float& init_res = factory.GetObject(arguments[0])->Cast< ObjectStorage<vmg_float> >()->Val();
|
|---|
| 37 | const vmg_float& precision = factory.GetObject("PRECISION")->Cast< ObjectStorage<vmg_float> >()->Val();
|
|---|
| 38 | const vmg_float rel_res = fabs(res / init_res);
|
|---|
| 39 |
|
|---|
| 40 | if (comm->Rank() == 0)
|
|---|
| 41 | printf("Multigrid: Relative residual: %e\n", rel_res);
|
|---|
| 42 |
|
|---|
| 43 | if (rel_res < precision)
|
|---|
| 44 | return StopCycleLater;
|
|---|
| 45 | else
|
|---|
| 46 | return Continue;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | static const char* Name() {return "CheckRelativeResidual";}
|
|---|
| 50 | static int Arguments() {return 1;}
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | CREATE_INITIALIZER(VMGCommandCheckRelativeResidual);
|
|---|
| 54 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.