00001
00002
00003
00004
00005
00006
00007 #include "AAdapt_AdaptiveSolutionManager.hpp"
00008 #include "AAdapt_AdaptationFactory.hpp"
00009 #include "AAdapt_InitialCondition.hpp"
00010
00011 #include "Teuchos_RCP.hpp"
00012 #include "Teuchos_ArrayRCP.hpp"
00013 #include "Teuchos_ParameterList.hpp"
00014
00015 #include "AAdapt_ThyraAdaptiveModelEvaluator.hpp"
00016
00017 using Teuchos::rcp;
00018 using Teuchos::RCP;
00019
00020 AAdapt::AdaptiveSolutionManager::AdaptiveSolutionManager(
00021 const Teuchos::RCP<Teuchos::ParameterList>& appParams,
00022 const Teuchos::RCP<Albany::AbstractDiscretization>& disc_,
00023 const Teuchos::RCP<const Epetra_Vector>& initial_guess) :
00024 disc(disc_),
00025 out(Teuchos::VerboseObjectBase::getDefaultOStream()),
00026 thyra_model_factory(new AAdapt::AdaptiveModelFactory(appParams)),
00027 solutionObserver(new AAdapt::SolutionObserver()),
00028 Piro::Epetra::AdaptiveSolutionManager(appParams,
00029 disc_->getMap(), disc_->getOverlapMap(), disc_->getOverlapJacobianGraph()) {
00030 setInitialSolution(disc->getSolutionField());
00031
00032
00033 const Albany::WorksetArray<Teuchos::ArrayRCP<Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> > > >::type&
00034 wsElNodeEqID = disc->getWsElNodeEqID();
00035 const Albany::WorksetArray<Teuchos::ArrayRCP<Teuchos::ArrayRCP<double*> > >::type&
00036 coords = disc->getCoords();
00037 const Albany::WorksetArray<std::string>::type& wsEBNames = disc->getWsEBNames();
00038
00039 int numDim = disc->getNumDim();
00040 int neq = disc->getNumEq();
00041
00042 RCP<Teuchos::ParameterList> problemParams =
00043 Teuchos::sublist(appParams, "Problem", true);
00044
00045 if(initial_guess != Teuchos::null) *initial_x = *initial_guess;
00046
00047 else {
00048 overlapped_x->Import(*initial_x, *importer, Insert);
00049 AAdapt::InitialConditions(overlapped_x, wsElNodeEqID, wsEBNames, coords, neq, numDim,
00050 problemParams->sublist("Initial Condition"),
00051 disc->hasRestartSolution());
00052 AAdapt::InitialConditions(overlapped_xdot, wsElNodeEqID, wsEBNames, coords, neq, numDim,
00053 problemParams->sublist("Initial Condition Dot"));
00054 initial_x->Export(*overlapped_x, *exporter, Insert);
00055 initial_xdot->Export(*overlapped_xdot, *exporter, Insert);
00056 }
00057
00058 }
00059
00060 AAdapt::AdaptiveSolutionManager::~AdaptiveSolutionManager() {
00061
00062 thyra_model_factory = Teuchos::null;
00063 #ifdef ALBANY_DEBUG
00064 *out << "Calling destructor for Albany_AdaptiveSolutionManager" << std::endl;
00065 #endif
00066 }
00067
00068 void
00069 AAdapt::AdaptiveSolutionManager::buildAdaptiveProblem(const Teuchos::RCP<ParamLib>& paramLib,
00070 Albany::StateManager& stateMgr,
00071 const Teuchos::RCP<const Epetra_Comm>& comm) {
00072
00073 RCP<AAdapt::AdaptationFactory> adaptationFactory
00074 = rcp(new AAdapt::AdaptationFactory(adaptParams, paramLib, stateMgr, comm));
00075
00076 adaptManager = adaptationFactory->createAdapter();
00077
00078 *out << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
00079 << " Mesh adapter has been initialized:\n"
00080 << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
00081 << std::endl;
00082
00083 }
00084
00085 bool
00086 AAdapt::AdaptiveSolutionManager::
00087 adaptProblem() {
00088
00089 const Epetra_Vector& oldSolution
00090 = dynamic_cast<const NOX::Epetra::Vector&>(grp->getX()).getEpetraVector();
00091
00092 const Epetra_Vector& oldOvlpSolution = *getOverlapSolution(oldSolution);
00093
00094
00095 if(adaptManager->adaptMesh(oldSolution, oldOvlpSolution)) {
00096
00097 resizeMeshDataArrays(disc->getMap(),
00098 disc->getOverlapMap(), disc->getOverlapJacobianGraph());
00099
00100
00101 setInitialSolution(disc->getSolutionField());
00102
00103
00104 Teuchos::RCP<ThyraAdaptiveModelEvaluator> thyra_model
00105 = Teuchos::rcp_dynamic_cast<ThyraAdaptiveModelEvaluator>(thyra_model_factory->getThyraModel());
00106
00107
00108 const int num_g = thyra_model->Ng();
00109
00110
00111 const Teuchos::RCP<Thyra::VectorBase<double> > g_j
00112 = thyra_model->resize_g_space(num_g-1, disc->getMap());
00113 solutionObserver->set_g_vector(num_g-1, g_j);
00114
00115
00116
00117
00118
00119
00120
00121
00122 *out << "Mesh adaptation was successfully performed!" << std::endl;
00123
00124 return true;
00125
00126 }
00127
00128 return false;
00129
00130 }
00131
00132 Teuchos::RCP<AAdapt::AdaptiveModelFactory>
00133 AAdapt::AdaptiveSolutionManager::
00134 modelFactory() const {
00135
00136 return thyra_model_factory;
00137
00138 }
00139
00140
00141 void
00142 AAdapt::AdaptiveSolutionManager::
00143 projectCurrentSolution() {
00144 #if 1 // turn on to print debug info from MeshAdapt
00145
00146
00147 const Epetra_Vector& oldSolution
00148 = dynamic_cast<const NOX::Epetra::Vector&>(grp->getX()).getEpetraVector();
00149
00150 adaptManager->solutionTransfer(oldSolution, currentSolution->getEpetraVector());
00151 #endif
00152
00153 }
00154
00155 void
00156 AAdapt::AdaptiveSolutionManager::
00157 scatterX(const Epetra_Vector& x, const Epetra_Vector* xdot, const Epetra_Vector* xdotdot) {
00158
00159
00160 overlapped_x->Import(x, *importer, Insert);
00161
00162 if(xdot != NULL) overlapped_xdot->Import(*xdot, *importer, Insert);
00163 if(xdotdot != NULL) overlapped_xdotdot->Import(*xdotdot, *importer, Insert);
00164
00165 }
00166