Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_ObserverFactory.hpp"
00007
00008 #include "MOR_MultiVectorOutputFile.hpp"
00009 #include "MOR_MultiVectorOutputFileFactory.hpp"
00010 #include "MOR_ReducedSpace.hpp"
00011 #include "MOR_ReducedSpaceFactory.hpp"
00012
00013 #include "MOR_NOXEpetraCompositeObserver.hpp"
00014 #include "MOR_SnapshotCollectionObserver.hpp"
00015 #include "MOR_ProjectionErrorObserver.hpp"
00016 #include "MOR_FullStateReconstructor.hpp"
00017 #include "MOR_GeneralizedCoordinatesNOXObserver.hpp"
00018
00019 #include "MOR_RythmosSnapshotCollectionObserver.hpp"
00020 #include "MOR_RythmosProjectionErrorObserver.hpp"
00021 #include "MOR_RythmosFullStateReconstructor.hpp"
00022 #include "MOR_GeneralizedCoordinatesRythmosObserver.hpp"
00023
00024 #include "Rythmos_CompositeIntegrationObserver.hpp"
00025
00026 #include "Teuchos_ParameterList.hpp"
00027
00028 #include <string>
00029
00030 namespace MOR {
00031
00032 using ::Teuchos::RCP;
00033 using ::Teuchos::rcp;
00034 using ::Teuchos::ParameterList;
00035 using ::Teuchos::sublist;
00036
00037 namespace {
00038
00039 RCP<ParameterList> fillDefaultOutputParams(const RCP<ParameterList> ¶ms, std::string defaultValue)
00040 {
00041 params->get("Output File Group Name", defaultValue);
00042 params->get("Output File Default Base File Name", defaultValue);
00043 return params;
00044 }
00045
00046 RCP<ParameterList> fillDefaultProjectionErrorOutputParams(const RCP<ParameterList> ¶ms)
00047 {
00048 return fillDefaultOutputParams(params, "proj_error");
00049 }
00050
00051 RCP<ParameterList> fillDefaultSnapshotOutputParams(const RCP<ParameterList> ¶ms)
00052 {
00053 return fillDefaultOutputParams(params, "snapshots");
00054 }
00055
00056 RCP<MultiVectorOutputFile> createOutputFile(const RCP<ParameterList> ¶ms)
00057 {
00058 MultiVectorOutputFileFactory factory(params);
00059 return factory.create();
00060 }
00061
00062 RCP<MultiVectorOutputFile> createProjectionErrorOutputFile(const RCP<ParameterList> ¶ms)
00063 {
00064 return createOutputFile(fillDefaultProjectionErrorOutputParams(params));
00065 }
00066
00067 RCP<MultiVectorOutputFile> createSnapshotOutputFile(const RCP<ParameterList> ¶ms)
00068 {
00069 return createOutputFile(fillDefaultSnapshotOutputParams(params));
00070 }
00071
00072 int getSnapshotPeriod(const RCP<ParameterList> ¶ms)
00073 {
00074 return params->get("Period", 1);
00075 }
00076
00077 std::string getGeneralizedCoordinatesFilename(const RCP<ParameterList> ¶ms)
00078 {
00079 return params->get("Generalized Coordinates Output File Name", "generalized_coordinates.mtx");
00080 }
00081
00082 std::string getGeneralizedCoordinatesStampsFilename(const RCP<ParameterList> ¶ms)
00083 {
00084 const std::string defaultValue = "stamps_" + getGeneralizedCoordinatesFilename(params);
00085 return params->get("Generalized Coordinates Stamps Output File Name", defaultValue);
00086 }
00087
00088 }
00089
00090 ObserverFactory::ObserverFactory(
00091 const Teuchos::RCP<ReducedSpaceFactory> &spaceFactory,
00092 const Teuchos::RCP<Teuchos::ParameterList> &parentParams) :
00093 spaceFactory_(spaceFactory),
00094 params_(sublist(parentParams, "Model Order Reduction"))
00095 {
00096
00097 }
00098
00099 RCP<NOX::Epetra::Observer> ObserverFactory::create(const RCP<NOX::Epetra::Observer> &child)
00100 {
00101 RCP<NOX::Epetra::Observer> fullOrderObserver;
00102 {
00103 const RCP<NOXEpetraCompositeObserver> composite(new NOXEpetraCompositeObserver);
00104
00105 if (this->collectSnapshots()) {
00106 const RCP<ParameterList> params = this->getSnapParameters();
00107 const RCP<MultiVectorOutputFile> snapOutputFile = createSnapshotOutputFile(params);
00108 const int period = getSnapshotPeriod(params);
00109 composite->addObserver(rcp(new SnapshotCollectionObserver(period, snapOutputFile)));
00110 }
00111
00112 if (this->computeProjectionError()) {
00113 const RCP<ParameterList> params = this->getErrorParameters();
00114 const RCP<MultiVectorOutputFile> errorOutputFile = createProjectionErrorOutputFile(params);
00115 const RCP<ReducedSpace> projectionSpace = spaceFactory_->create(params);
00116 composite->addObserver(rcp(new ProjectionErrorObserver(projectionSpace, errorOutputFile)));
00117 }
00118
00119 if (composite->observerCount() > 0) {
00120 composite->addObserver(child);
00121 fullOrderObserver = composite;
00122 } else {
00123 fullOrderObserver = child;
00124 }
00125 }
00126
00127 if (this->useReducedOrderModel()) {
00128 const RCP<ParameterList> params = this->getReducedOrderModelParameters();
00129 const RCP<ReducedSpace> projectionSpace = spaceFactory_->create(params);
00130 const RCP<NOX::Epetra::Observer> reducedOrderObserver =
00131 rcp(new FullStateReconstructor(projectionSpace, fullOrderObserver));
00132
00133 if (this->observeGeneralizedCoordinates()) {
00134 const RCP<NOXEpetraCompositeObserver> composite(new NOXEpetraCompositeObserver);
00135 const RCP<ParameterList> genCoordParams = this->getGeneralizedCoordinatesParameters();
00136 const std::string filename = getGeneralizedCoordinatesFilename(genCoordParams);
00137 const std::string stampsFilename = getGeneralizedCoordinatesStampsFilename(genCoordParams);
00138 composite->addObserver(rcp(new GeneralizedCoordinatesNOXObserver(filename, stampsFilename)));
00139 composite->addObserver(reducedOrderObserver);
00140 return composite;
00141 } else {
00142 return reducedOrderObserver;
00143 }
00144 } else {
00145 return fullOrderObserver;
00146 }
00147 }
00148
00149 RCP<Rythmos::IntegrationObserverBase<double> > ObserverFactory::create(const RCP<Rythmos::IntegrationObserverBase<double> > &child) {
00150 RCP<Rythmos::IntegrationObserverBase<double> > fullOrderObserver;
00151 {
00152 const RCP<Rythmos::CompositeIntegrationObserver<double> > composite =
00153 Rythmos::createCompositeIntegrationObserver<double>();
00154 int observersInComposite = 0;
00155
00156 if (this->collectSnapshots()) {
00157 const RCP<ParameterList> params = this->getSnapParameters();
00158 const RCP<MultiVectorOutputFile> snapOutputFile = createSnapshotOutputFile(params);
00159 const int period = getSnapshotPeriod(params);
00160 composite->addObserver(rcp(new RythmosSnapshotCollectionObserver(period, snapOutputFile)));
00161 ++observersInComposite;
00162 }
00163
00164 if (this->computeProjectionError()) {
00165 const RCP<ParameterList> params = this->getErrorParameters();
00166 const RCP<MultiVectorOutputFile> errorOutputFile = createProjectionErrorOutputFile(params);
00167 const RCP<ReducedSpace> projectionSpace = spaceFactory_->create(params);
00168 composite->addObserver(rcp(new RythmosProjectionErrorObserver(projectionSpace, errorOutputFile)));
00169 ++observersInComposite;
00170 }
00171
00172 if (observersInComposite > 0) {
00173 composite->addObserver(child);
00174 fullOrderObserver = composite;
00175 } else {
00176 fullOrderObserver = child;
00177 }
00178 }
00179
00180 if (useReducedOrderModel()) {
00181 const RCP<ParameterList> params = this->getReducedOrderModelParameters();
00182 const RCP<ReducedSpace> projectionSpace = spaceFactory_->create(params);
00183 const RCP<Rythmos::IntegrationObserverBase<double> > reducedOrderObserver =
00184 rcp(new RythmosFullStateReconstructor(projectionSpace, fullOrderObserver));
00185
00186 if (this->observeGeneralizedCoordinates()) {
00187 const RCP<Rythmos::CompositeIntegrationObserver<double> > composite =
00188 Rythmos::createCompositeIntegrationObserver<double>();
00189 const RCP<ParameterList> genCoordParams = this->getGeneralizedCoordinatesParameters();
00190 const std::string filename = getGeneralizedCoordinatesFilename(genCoordParams);
00191 const std::string stampsFilename = getGeneralizedCoordinatesStampsFilename(genCoordParams);
00192 composite->addObserver(rcp(new GeneralizedCoordinatesRythmosObserver(filename, stampsFilename)));
00193 composite->addObserver(reducedOrderObserver);
00194 return composite;
00195 } else {
00196 return reducedOrderObserver;
00197 }
00198 } else {
00199 return fullOrderObserver;
00200 }
00201 }
00202
00203 bool ObserverFactory::collectSnapshots() const
00204 {
00205 return getSnapParameters()->get("Activate", false);
00206 }
00207
00208 bool ObserverFactory::computeProjectionError() const
00209 {
00210 return getErrorParameters()->get("Activate", false);
00211 }
00212
00213 bool ObserverFactory::useReducedOrderModel() const
00214 {
00215 return getReducedOrderModelParameters()->get("Activate", false);
00216 }
00217
00218 bool ObserverFactory::observeGeneralizedCoordinates() const
00219 {
00220 return Teuchos::isParameterType<std::string>(
00221 *this->getGeneralizedCoordinatesParameters(),
00222 "Generalized Coordinates Output File Name");
00223 }
00224
00225 RCP<ParameterList> ObserverFactory::getSnapParameters() const
00226 {
00227 return sublist(params_, "Snapshot Collection");
00228 }
00229
00230 RCP<ParameterList> ObserverFactory::getErrorParameters() const
00231 {
00232 return sublist(params_, "Projection Error");
00233 }
00234
00235 RCP<ParameterList> ObserverFactory::getReducedOrderModelParameters() const
00236 {
00237 return sublist(params_, "Reduced-Order Model");
00238 }
00239
00240 RCP<ParameterList> ObserverFactory::getGeneralizedCoordinatesParameters() const
00241 {
00242 return this->getReducedOrderModelParameters();
00243 }
00244
00245 }