/** * @file techniques.hpp * @author Julian Iseringhausen * @date Mon Apr 18 13:06:42 2011 * * @brief Some examples for multigrid methods this library * might be used for. * */ #ifndef TECHNIQUES_HPP_ #define TECHNIQUES_HPP_ #include #include #include "base/command_list.hpp" namespace VMG { class Techniques { public: static void SetCorrectionSchemeDirichlet(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("CopyBoundary", "RHS:SOL"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); loop->AddCommand("ClearCoarseLevels", "RHS"); loop->AddCommand("ClearCoarseLevels", "SOL"); AddCycleGamma(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetCorrectionSchemeDirichletDebug(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("CopyBoundary", "RHS:SOL"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); loop->AddCommand("ClearCoarseLevels", "RHS"); loop->AddCommand("ClearCoarseLevels", "SOL"); AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetCorrectionSchemePeriodic(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); loop->AddCommand("ClearCoarseLevels", "SOL"); loop->AddCommand("ClearCoarseLevels", "RHS"); AddCycleGamma(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetCorrectionSchemePeriodicDebug(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); loop->AddCommand("ClearCoarseLevels", "SOL"); loop->AddCommand("ClearCoarseLevels", "RHS"); AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetFullApproximationSchemeDirichlet(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("CopyBoundary", "RHS:SOL"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); AddCycleGamma(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetFullApproximationSchemeDirichletDebug(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("CopyBoundary", "RHS:SOL"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetFullApproximationSchemePeriodic(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); AddCycleGamma(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } static void SetFullApproximationSchemePeriodicDebug(int minLevel, int maxLevel, int gamma) { CommandList* init = new CommandList(); CommandList* loop = new CommandList(); CommandList* finalize = new CommandList(); init->AddCommand("ClearGrid", "RHS"); init->AddCommand("ClearGrid", "SOL"); init->AddCommand("ImportRightHandSide"); init->AddCommand("CheckConsistency", "RHS"); init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL"); AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma); loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL"); loop->AddCommand("CheckIterationCounter"); finalize->AddCommand("ExportSolution"); init->Register("COMMANDLIST_INIT"); loop->Register("COMMANDLIST_LOOP"); finalize->Register("COMMANDLIST_FINALIZE"); } private: static void AddCycleGamma(CommandList& list, int numLevels, int gamma) { for (int i=0; i=0; j--) { for (int k=0; k<=j; k++) { list.AddCommand("Prolongate"); list.AddCommand("Smooth", "POSTSMOOTHSTEPS"); } for (int k=0; k<=j; k++) { list.AddCommand("Smooth", "PRESMOOTHSTEPS"); list.AddCommand("Restrict"); } list.AddCommand("Solve"); } } for (int i=0; i=0; j--) { for (int k=0; k<=j; k++) { list.AddCommand("Prolongate"); list.AddCommand("PrintGrid", "RHS"); list.AddCommand("Smooth", "POSTSMOOTHSTEPS"); list.AddCommand("PrintGrid", "SOL"); list.AddCommand("PrintDefect"); } for (int k=0; k<=j; k++) { list.AddCommand("PrintGrid", "RHS"); list.AddCommand("Smooth", "PRESMOOTHSTEPS"); list.AddCommand("PrintGrid", "SOL"); list.AddCommand("PrintDefect"); list.AddCommand("Restrict"); } list.AddCommand("PrintGrid", "RHS"); list.AddCommand("Solve"); list.AddCommand("PrintGrid", "SOL"); list.AddCommand("PrintDefect"); } } for (int i=0; i