Ejemplo n.º 1
0
AAdapt::STKAdapt<SizeField>::
STKAdapt(const Teuchos::RCP<Teuchos::ParameterList>& params_,
         const Teuchos::RCP<ParamLib>& paramLib_,
         Albany::StateManager& StateMgr_,
         const Teuchos::RCP<const Epetra_Comm>& comm_) :
  AAdapt::AbstractAdapter(params_, paramLib_, StateMgr_, comm_),
  remeshFileIndex(1) {

  disc = StateMgr_.getDiscretization();

  stk_discretization = static_cast<Albany::STKDiscretization*>(disc.get());

  genericMeshStruct = Teuchos::rcp_dynamic_cast<Albany::GenericSTKMeshStruct>(stk_discretization->getSTKMeshStruct());

  eMesh = genericMeshStruct->getPerceptMesh();
  TEUCHOS_TEST_FOR_EXCEPT(eMesh.is_null());

  refinerPattern = genericMeshStruct->getRefinerPattern();
  TEUCHOS_TEST_FOR_EXCEPT(refinerPattern.is_null());

  num_iterations = adapt_params_->get<int>("Max Number of STK Adapt Iterations", 1);

  // Save the initial output file name
  base_exo_filename = stk_discretization->getSTKMeshStruct()->exoOutFile;


}
AAdapt::AdaptiveSolutionManagerT::AdaptiveSolutionManagerT(
    const Teuchos::RCP<Teuchos::ParameterList>& appParams,
    const Teuchos::RCP<const Tpetra_Vector>& initial_guessT,
    const Teuchos::RCP<ParamLib>& param_lib,
    const Albany::StateManager& stateMgr,
    const Teuchos::RCP<rc::Manager>& rc_mgr,
    const Teuchos::RCP<const Teuchos_Comm>& commT) :

    out(Teuchos::VerboseObjectBase::getDefaultOStream()),
    appParams_(appParams),
    disc_(stateMgr.getDiscretization()),
    paramLib_(param_lib),
    stateMgr_(stateMgr),
    num_time_deriv(appParams->sublist("Discretization").get<int>("Number Of Time Derivatives")),
    commT_(commT)
{

  // Create problem PL
  Teuchos::RCP<Teuchos::ParameterList> problemParams =
      Teuchos::sublist(appParams_, "Problem", true);

  // Note that piroParams_ is a member of Thyra_AdaptiveSolutionManager
  piroParams_ = Teuchos::sublist(appParams_, "Piro", true);

  if (problemParams->isSublist("Adaptation")) { // If the user has specified adaptation on input, grab the sublist
    // Note that piroParams_ and adaptiveMesh_ are members of Thyra_AdaptiveSolutionManager
    adaptParams_ = Teuchos::sublist(problemParams, "Adaptation", true);
    adaptiveMesh_ = true;
    buildAdapter(rc_mgr);
  }

  // Want the initial time in the parameter library to be correct
  // if this is a restart solution
  if (disc_->hasRestartSolution()) {
    if (paramLib_->isParameter("Time")) {

      double initialValue = 0.0;

      if(appParams->sublist("Problem").
         get<std::string>("Solution Method", "Steady") == "Continuation")
      {
        initialValue =
          appParams->sublist("Piro").sublist("LOCA").sublist("Stepper").
          get<double>("Initial Value", 0.0);
      }
      else if(appParams->sublist("Problem").
              get<std::string>("Solution Method", "Steady") == "Transient")
      {
        initialValue =
          appParams->sublist("Piro").sublist("Trapezoid Rule").
          get<double>("Initial Time", 0.0);
      }
      paramLib_->setRealValue<PHAL::AlbanyTraits::Residual>("Time", initialValue);
    }
  }

  const Teuchos::RCP<const Tpetra_Map> mapT = disc_->getMapT();
  const Teuchos::RCP<const Tpetra_Map> overlapMapT = disc_->getOverlapMapT();
#ifdef ALBANY_AERAS
  //IKT, 1/20/15: the following is needed to ensure Laplace matrix is non-diagonal
  //for Aeras problems that have hyperviscosity and are integrated using an explicit time
  //integration scheme.
  const Teuchos::RCP<const Tpetra_CrsGraph> overlapJacGraphT = disc_
      ->getImplicitOverlapJacobianGraphT();
#else
  const Teuchos::RCP<const Tpetra_CrsGraph> overlapJacGraphT = disc_
      ->getOverlapJacobianGraphT();
#endif

  resizeMeshDataArrays(mapT, overlapMapT, overlapJacGraphT);

  {
    Teuchos::ArrayRCP<
        Teuchos::ArrayRCP<Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> > > > wsElNodeEqID =
        disc_->getWsElNodeEqID();
    Teuchos::ArrayRCP<Teuchos::ArrayRCP<Teuchos::ArrayRCP<double*> > > coords =
        disc_->getCoords();
    Teuchos::ArrayRCP<std::string> wsEBNames = disc_->getWsEBNames();
    const int numDim = disc_->getNumDim();
    const int neq = disc_->getNumEq();

    Teuchos::RCP<Teuchos::ParameterList> problemParams = Teuchos::sublist(
        appParams_,
        "Problem",
        true);
    if (Teuchos::nonnull(initial_guessT)) {

      *current_soln->getVectorNonConst(0) = *initial_guessT;

    } else {

      overlapped_soln->getVectorNonConst(0)->doImport(*current_soln->getVector(0), *importerT, Tpetra::INSERT);

      AAdapt::InitialConditionsT(
          overlapped_soln->getVectorNonConst(0), wsElNodeEqID, wsEBNames, coords, neq, numDim,
          problemParams->sublist("Initial Condition"),
          disc_->hasRestartSolution());

      current_soln->getVectorNonConst(0)->doExport(*overlapped_soln->getVector(0), *exporterT, Tpetra::INSERT);

      if(num_time_deriv > 0){
          overlapped_soln->getVectorNonConst(1)->doImport(*current_soln->getVector(1), *importerT, Tpetra::INSERT);
          AAdapt::InitialConditionsT(
             overlapped_soln->getVectorNonConst(1), wsElNodeEqID, wsEBNames, coords, neq, numDim,
             problemParams->sublist("Initial Condition Dot"));
          current_soln->getVectorNonConst(1)->doExport(*overlapped_soln->getVector(1), *exporterT, Tpetra::INSERT);
       }

       if(num_time_deriv > 1){
          overlapped_soln->getVectorNonConst(2)->doImport(*current_soln->getVector(2), *importerT, Tpetra::INSERT);
          AAdapt::InitialConditionsT(
             overlapped_soln->getVectorNonConst(2), wsElNodeEqID, wsEBNames, coords, neq, numDim,
             problemParams->sublist("Initial Condition DotDot"));
          current_soln->getVectorNonConst(2)->doExport(*overlapped_soln->getVector(2), *exporterT, Tpetra::INSERT);
        }

    }
  }
#if (defined(ALBANY_SCOREC) || defined(ALBANY_AMP))
  {
    const Teuchos::RCP< Albany::APFDiscretization > apf_disc =
      Teuchos::rcp_dynamic_cast< Albany::APFDiscretization >(disc_);
    if ( ! apf_disc.is_null()) {
      apf_disc->writeSolutionMVToMeshDatabase(*overlapped_soln, 0, true);
      apf_disc->initTemperatureHack();
    }
  }
#endif
}