MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_ToggleCoordinatesTransferFactory_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef MUELU_TOGGLECOORDINATESTRANSFER_FACTORY_DEF_HPP
11#define MUELU_TOGGLECOORDINATESTRANSFER_FACTORY_DEF_HPP
12
14
15#include "MueLu_Level.hpp"
16#include "MueLu_Monitor.hpp"
17
18namespace MueLu {
19
20template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
22 RCP<ParameterList> validParamList = rcp(new ParameterList());
23
24 validParamList->set<RCP<const FactoryBase> >("Chosen P", Teuchos::null, "Name of TogglePFactory this ToggleCoordinatesTransferFactory is connected to. Parameter provides information which execution path (prolongator) has been chosen.");
25
26 return validParamList;
27}
28
29template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
31 const ParameterList& pL = GetParameterList();
32 TEUCHOS_TEST_FOR_EXCEPTION(!pL.isParameter("Chosen P"), Exceptions::RuntimeError, "MueLu::ToggleCoordinatesTransferFactory::DeclareInput: You have to set the 'Chosen P' parameter to a factory name of type TogglePFactory. The ToggleCoordinatesTransferFactory must be used together with a TogglePFactory!");
33 Input(coarseLevel, "Chosen P");
34 for (std::vector<RCP<const FactoryBase> >::const_iterator it = coordFacts_.begin(); it != coordFacts_.end(); ++it) {
35 coarseLevel.DeclareInput("Coordinates", (*it).get(), this); // request/release coarse coordinates
36 (*it)->CallDeclareInput(coarseLevel); // request dependencies
37 }
38 hasDeclaredInput_ = true;
39}
40
41template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
43 FactoryMonitor m(*this, "Coordinate transfer toggle", coarseLevel);
44
45 typedef Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO> xdMV;
46
47 TEUCHOS_TEST_FOR_EXCEPTION(coordFacts_.size() != 2, Exceptions::RuntimeError, "MueLu::TogglePFactory::Build: ToggleCoordinatesTransferFactory needs two different transfer operator strategies for toggling.");
48
49 int chosenP = Get<int>(coarseLevel, "Chosen P");
50 GetOStream(Runtime1) << "Transfer Coordinates" << chosenP << " to coarse level" << std::endl;
51 RCP<xdMV> coarseCoords = coarseLevel.Get<RCP<xdMV> >("Coordinates", (coordFacts_[chosenP]).get());
52 Set(coarseLevel, "Coordinates", coarseCoords);
53
54 // loop through all coord facts and check whether the coarse coordinates are available.
55 // This is the coarse coordinate transfer factory which belongs to the execution path
56 // chosen by the TogglePFactory
57 /*RCP<xdMV> coarseCoords = Teuchos::null;
58 for(size_t t=0; t<coordFacts_.size(); ++t) {
59 bool bIsAv = coarseLevel.IsAvailable("Coordinates",(coordFacts_[t]).get());
60 std::cout << "Coordinates generated by " << (coordFacts_[t]).get() << " available? " << bIsAv << std::endl;
61 if ( coarseLevel.IsAvailable("Coordinates",(coordFacts_[t]).get()) ) {
62 GetOStream(Runtime1) << "Choose factory " << t << " (" << (coordFacts_[t]).get() << ")" << std::endl;
63 coarseCoords = coarseLevel.Get< RCP<xdMV> >("Coordinates",(coordFacts_[t]).get());
64 Set(coarseLevel, "Coordinates", coarseCoords);
65 }
66 }*/
67
68 // Release dependencies of all coordinate transfer factories
69 for (size_t t = 0; t < coordFacts_.size(); ++t) {
70 coarseLevel.Release(*(coordFacts_[t]));
71 }
72
73 // TODO: exception if coarseCoords == Teuchos::null
74}
75
76template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78 // check if it's a TwoLevelFactoryBase based transfer factory
79 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null, Exceptions::BadCast,
80 "MueLu::ToggleCoordinatesTransferFactory::AddCoordTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. Make sure you provide the factory which generates the coarse coordinates. Usually this is a coordinate transfer factory."
81 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
82 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_, Exceptions::RuntimeError, "MueLu::ToggleCoordinatesTransferFactory::AddCoordTransferFactory: Factory is being added after we have already declared input");
83 coordFacts_.push_back(factory);
84}
85} // namespace MueLu
86
87#endif // MUELU_TOGGLECOORDINATESTRANSFER_FACTORY_DEF_HPP
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput().
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual const Teuchos::ParameterList & GetParameterList() const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void AddCoordTransferFactory(const RCP< const FactoryBase > &factory)
Add a coordinate transfer factory in the end of list of coordinate transfer factories.
std::vector< RCP< const FactoryBase > > coordFacts_
list of user-defined transfer coordinate factories which provide coordinates on the coarse level!
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Runtime1
Description of what is happening (more verbose).