Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_ProblemFactory.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_PROBLEM_FACTORY_HPP
15 #define ZOLTAN2_PROBLEM_FACTORY_HPP
16 #include <Zoltan2_TestHelpers.hpp>
17 #include <Zoltan2_Problem.hpp>
21 #include <Zoltan2_Typedefs.hpp>
22 
23 using namespace Zoltan2_TestingFramework;
24 using namespace Zoltan2;
25 
26 namespace Zoltan2_TestingFramework {
29  public:
39  ProblemFactory(const std::string & problemName,
40  RCP<AdapterFactory> adapterFactory,
41  ParameterList *params
42  #ifdef HAVE_ZOLTAN2_MPI
43  , MPI_Comm comm
44  #endif
45  ) {
46 
47  problem_name = problemName;
48  adapterType = adapterFactory->getMainAdapterType();
49 
50  #ifdef HAVE_ZOLTAN2_MPI
51  #define CREATE_PRBLM(problemClass, adapterClass) \
52  adapterClass * pCast = dynamic_cast<adapterClass *> \
53  (adapterFactory->getMainAdapter()); \
54  if(!pCast) { throw std::logic_error( \
55  "ProblemFactory adapter dynamic_cast failed for problem name " \
56  + problem_name + " and adapterClass " + #adapterClass ); } \
57  problem = rcp(new problemClass<adapterClass>(pCast, params, comm));
58  #else
59  #define CREATE_PRBLM(problemClass, adapterClass) \
60  adapterClass * pCast = dynamic_cast<adapterClass *> \
61  (adapterFactory->getMainAdapter()); \
62  if(!pCast) { throw std::logic_error( \
63  "ProblemFactory adapter dynamic_cast failed for problem name " \
64  + problem_name + " and adapterClass " + #adapterClass ); } \
65  problem = rcp(new problemClass<adapterClass>(pCast, params));
66  #endif
67 
68  #define MAKE_PARTITION_PROBLEM(adapterClass) \
69  CREATE_PRBLM(PartitioningProblem, adapterClass);
70 
71  #define MAKE_ORDERING_PROBLEM(adapterClass) \
72  CREATE_PRBLM(OrderingProblem, adapterClass);
73 
74  // PartitioningProblem
75  if(problem_name == "partitioning") {
77  }
78  else if(problem_name == "ordering") {
80  }
81 
82  if(problem == Teuchos::null) {
83  throw std::logic_error("ProblemFactory failed to create Problem!");
84  }
85  }
86 
87  RCP<ProblemRoot> getProblem() { return problem; }
88  const std::string & getProblemName() const { return problem_name; }
89  EAdapterType getAdapterType() const { return adapterType; }
90 
91  private:
92  std::string problem_name; // string converts to a problem type
93  EAdapterType adapterType; // converts to an adapter type
94  RCP<ProblemRoot> problem;
95  };
96 }
97 #endif // ZOLTAN2_PROBLEM_FACTORY_HPP
98 
keep typedefs that commonly appear in many places localized
Defines the ColoringProblem class.
ProblemFactory class contains 1 static factory method.
common code used by tests
#define MAKE_PARTITION_PROBLEM(adapterClass)
#define Z2_TEST_UPCAST(adptr, TEMPLATE_ACTION)
#define MAKE_ORDERING_PROBLEM(adapterClass)
Defines the Problem base class.
Defines the OrderingProblem class.
ProblemFactory(const std::string &problemName, RCP< AdapterFactory > adapterFactory, ParameterList *params)
Zoltan2::Problem factory method
Defines the PartitioningProblem class.