Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_ReducedSpaceFactory.hpp"
00007
00008 #include "MOR_ReducedSpace.hpp"
00009
00010 #include "MOR_SampleDofListFactory.hpp"
00011 #include "MOR_EpetraSamplingOperator.hpp"
00012 #include "MOR_ContainerUtils.hpp"
00013 #include "MOR_EpetraUtils.hpp"
00014 #include "MOR_BasisOps.hpp"
00015
00016 #include "Epetra_MultiVector.h"
00017 #include "Epetra_Vector.h"
00018 #include "Epetra_Operator.h"
00019 #include "Epetra_Map.h"
00020
00021 #include "Teuchos_Tuple.hpp"
00022 #include "Teuchos_Array.hpp"
00023 #include "Teuchos_TestForException.hpp"
00024
00025 #include <stdexcept>
00026
00027 namespace MOR {
00028
00029 ReducedSpaceFactory::ReducedSpaceFactory(
00030 const Teuchos::RCP<ReducedBasisFactory> &basisFactory,
00031 const Teuchos::RCP<SampleDofListFactory> &samplingFactory) :
00032 basisRepository_(basisFactory),
00033 samplingFactory_(samplingFactory)
00034 {
00035
00036 }
00037
00038 Teuchos::RCP<ReducedSpace>
00039 ReducedSpaceFactory::create(const Teuchos::RCP<Teuchos::ParameterList> ¶ms)
00040 {
00041 const Teuchos::RCP<const Epetra_MultiVector> basis = this->getBasis(params);
00042 const Teuchos::RCP<const Epetra_Vector> origin = this->getOrigin(params);
00043 const Teuchos::RCP<const Epetra_MultiVector> projector = this->getProjector(params);
00044
00045 if (Teuchos::nonnull(origin)) {
00046 return Teuchos::rcp(new AffineReducedSpace(basis, projector, *origin));
00047 } else {
00048 return Teuchos::rcp(new LinearReducedSpace(basis, projector));
00049 }
00050 }
00051
00052 Teuchos::RCP<const Epetra_MultiVector>
00053 ReducedSpaceFactory::getBasis(const Teuchos::RCP<Teuchos::ParameterList> ¶ms)
00054 {
00055 return basisRepository_.getBasis(params);
00056 }
00057
00058 Teuchos::RCP<const Epetra_Vector>
00059 ReducedSpaceFactory::getOrigin(const Teuchos::RCP<Teuchos::ParameterList> ¶ms)
00060 {
00061 return basisRepository_.getOrigin(params);
00062 }
00063
00064 Teuchos::RCP<const Epetra_MultiVector>
00065 ReducedSpaceFactory::getProjector(const Teuchos::RCP<Teuchos::ParameterList> ¶ms)
00066 {
00067 const Teuchos::RCP<const Epetra_MultiVector> basis = this->getBasis(params);
00068
00069 const Teuchos::RCP<const Epetra_Map> basisMap = mapDowncast(basis->Map());
00070 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(basisMap));
00071
00072 const Teuchos::RCP<const Epetra_Operator> collocationOperator =
00073 this->getSamplingOperator(params, *basisMap);
00074
00075 Teuchos::RCP<const Epetra_MultiVector> result = basis;
00076 if (Teuchos::nonnull(collocationOperator)) {
00077 const Teuchos::RCP<Epetra_MultiVector> dualBasis(
00078 new Epetra_MultiVector(collocationOperator->OperatorRangeMap(), basis->NumVectors(), false));
00079 dualize(*basis, *collocationOperator, *dualBasis);
00080 result = dualBasis;
00081 }
00082 return result;
00083 }
00084
00085 Teuchos::RCP<const Epetra_Operator>
00086 ReducedSpaceFactory::getSamplingOperator(
00087 const Teuchos::RCP<Teuchos::ParameterList> ¶ms,
00088 const Epetra_Map &stateMap)
00089 {
00090 Teuchos::RCP<const Epetra_Operator> result;
00091 {
00092 const Teuchos::RCP<Teuchos::ParameterList> hyperreductionParams = Teuchos::sublist(params, "Hyper Reduction");
00093 const bool useHyperreduction = hyperreductionParams->get("Activate", false);
00094 if (useHyperreduction) {
00095 const Teuchos::Tuple<std::string, 1> allowedHyperreductionTypes = Teuchos::tuple<std::string>("Collocation");
00096 const std::string hyperreductionType = hyperreductionParams->get("Type", allowedHyperreductionTypes[0]);
00097 TEUCHOS_TEST_FOR_EXCEPTION(!contains(allowedHyperreductionTypes, hyperreductionType),
00098 std::out_of_range,
00099 hyperreductionType + " not in " + allowedHyperreductionTypes.toString());
00100 if (hyperreductionType == allowedHyperreductionTypes[0]) {
00101 const Teuchos::RCP<Teuchos::ParameterList> collocationParams = Teuchos::sublist(hyperreductionParams, "Collocation Data");
00102 const Teuchos::Array<int> sampleLocalEntries = samplingFactory_->create(collocationParams);
00103 result = Teuchos::rcp(new EpetraSamplingOperator(stateMap, sampleLocalEntries));
00104 } else {
00105 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Should not happen");
00106 }
00107 }
00108 }
00109 return result;
00110 }
00111
00112 }