Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_EvaluateFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #ifndef ZOLTAN2_EVALUATE_FACTORY_HPP
15 #define ZOLTAN2_EVALUATE_FACTORY_HPP
16 
17 #include <Zoltan2_Typedefs.hpp>
22 
23 using namespace Zoltan2_TestingFramework;
24 using namespace Zoltan2;
25 
26 namespace Zoltan2_TestingFramework {
29  public:
30 
39 
40  EvaluateFactory(const std::string & problemName,
41  RCP<AdapterFactory> adapterFactory,
42  ParameterList *params,
43  RCP<ProblemFactory> problemFactory) {
44 
45  adapterType = adapterFactory->getMainAdapterType();
46  problem_name = problemName;
47 
48  if (problem_name == "partitioning") {
49  #define PARTITIONING_PROBLEM(adapterClass) rcp_dynamic_cast< \
50  PartitioningProblem<adapterClass>> (problemFactory->getProblem())
51 
52  #define EVALUATE_PARTITION(adapterClass) \
53  const adapterClass * pAdapterClassUpCast = dynamic_cast< \
54  const adapterClass *>(adapterFactory->getMainAdapter()); \
55  if(!pAdapterClassUpCast) throw std::logic_error( \
56  "Bad adapter class cast!" ); \
57  evaluate = rcp(new EvaluatePartition<adapterClass>( \
58  pAdapterClassUpCast, params, \
59  problemFactory->getProblem()->getComm(), \
60  (&PARTITIONING_PROBLEM(adapterClass)->getSolution())));
61 
63  }
64  else if(problem_name == "ordering") {
65  #define ORDERING_PROBLEM(adapterClass) rcp_dynamic_cast< \
66  OrderingProblem<adapterClass>> (problemFactory->getProblem())
67 
68  #define LOCAL_ORDERING(adapterClass) \
69  const adapterClass * pAdapterClassUpCast = dynamic_cast< \
70  const adapterClass *>(adapterFactory->getMainAdapter()); \
71  if(!pAdapterClassUpCast) throw std::logic_error( \
72  "Bad adapter class cast!"); \
73  evaluate = rcp(new EvaluateLocalOrdering<adapterClass>( \
74  pAdapterClassUpCast, params, \
75  problemFactory->getProblem()->getComm(), \
76  ORDERING_PROBLEM(adapterClass)->getLocalOrderingSolution()));
77 
78  // EvaluateGlobalOrdering not tested/implemented yet
79  #define GLOBAL_ORDERING(adapterClass) \
80  const adapterClass * pAdapterClassUpCast = dynamic_cast< \
81  const adapterClass *>(adapterFactory->getMainAdapter()); \
82  if(!pAdapterClassUpCast) throw std::logic_error( \
83  "Bad adapter class cast!" ); \
84  evaluate = rcp(new EvaluateGlobalOrdering<adapterClass>( \
85  pAdapterClassUpCast, \
86  params, ORDERING_PROBLEM(adapterClass)->getComm(), \
87  ORDERING_PROBLEM(adapterClass)->getGlobalOrderingSolution()));
88 
89  Z2_TEST_UPCAST(adapterType, LOCAL_ORDERING)
90  }
91  else if(problem_name == "coloring") {
92  // Coloring code here... EvaluateColoringFactory not created yet
93  // return EvaluateColoringFactory::newEvaluatColoring(
94  // dynamic_cast<coloring_problem_t*> (problem),
95  // adapter_name, input, params);
96  }
97 
98  if(evaluate == Teuchos::null) {
99  throw std::logic_error("EvaluateFactory failed to create!");
100  }
101  }
102 
103  RCP<EvaluateBaseClassRoot> getEvaluateClass() { return evaluate; }
104  const std::string & getProblemName() const { return problem_name; }
105  EAdapterType getAdapterType() const { return adapterType; }
106 
107  private:
108  std::string problem_name; // string converts to a problem type
109  EAdapterType adapterType; // converts to an adapter type
110  RCP<EvaluateBaseClassRoot> evaluate;
111  };
112 }
113 #endif // ZOLTAN2_EVALUATE_FACTORY_HPP
114 
keep typedefs that commonly appear in many places localized
ProblemFactory class contains 1 static factory method.
#define Z2_TEST_UPCAST(adptr, TEMPLATE_ACTION)
Defines the EvaluatePartition class.
#define LOCAL_ORDERING(adapterClass)
EvaluateFactory(const std::string &problemName, RCP< AdapterFactory > adapterFactory, ParameterList *params, RCP< ProblemFactory > problemFactory)
Zoltan2::EvaluateBaseClass factory method
Defines the Zoltan2_EvaluateOrdering.hpp class.
Defines the OrderingProblem class.
#define EVALUATE_PARTITION(adapterClass)