Skip to content

Commit

Permalink
Merge Pull Request trilinos#10327 from rppawlo/Trilinos/panzer-add-te…
Browse files Browse the repository at this point in the history
…mpus-support

Automatically Merged using Trilinos Pull Request AutoTester
PR Title: Panzer add tempus support
PR Author: rppawlo
  • Loading branch information
trilinos-autotester authored Mar 15, 2022
2 parents ad816ab + 196ced0 commit 0b00ccf
Show file tree
Hide file tree
Showing 12 changed files with 878 additions and 10 deletions.
8 changes: 8 additions & 0 deletions packages/panzer/adapters-stk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ ELSE()
GLOBAL_SET(PANZER_HAVE_IFPACK2 OFF)
ENDIF()

# Optional Tempus dependency
#############################
IF(${PACKAGE_NAME}_ENABLE_Tempus)
GLOBAL_SET(PANZER_HAVE_TEMPUS ON)
ELSE()
GLOBAL_SET(PANZER_HAVE_TEMPUS OFF)
ENDIF()

ADD_SUBDIRECTORY(src)
TRIBITS_ADD_TEST_DIRECTORIES(test)
TRIBITS_ADD_EXAMPLE_DIRECTORIES(example)
Expand Down
2 changes: 1 addition & 1 deletion packages/panzer/adapters-stk/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# dependency.

SET(LIB_REQUIRED_DEP_PACKAGES STKUtil STKTopology STKMesh STKIO Zoltan Stratimikos Piro NOX Rythmos PanzerCore PanzerDiscFE)
SET(LIB_OPTIONAL_DEP_PACKAGES SEACASIoss SEACASExodus UMR Percept Teko MueLu Ifpack2)
SET(LIB_OPTIONAL_DEP_PACKAGES SEACASIoss SEACASExodus UMR Percept Teko MueLu Ifpack2 Tempus)
SET(TEST_REQUIRED_DEP_PACKAGES SEACASIoss SEACASExodus Teko MueLu Ifpack2)
SET(TEST_OPTIONAL_DEP_PACKAGES Pamgen)
SET(LIB_REQUIRED_DEP_TPLS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
#cmakedefine PANZER_HAVE_TEKO
#cmakedefine PANZER_HAVE_MUELU
#cmakedefine PANZER_HAVE_IFPACK2
#cmakedefine PANZER_HAVE_TEMPUS

#endif
10 changes: 10 additions & 0 deletions packages/panzer/adapters-stk/example/main_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TRIBITS_COPY_FILES_TO_BINARY_DIR(main_driver_files
energy-transient.xml
energy-ss-blocked.xml
energy-transient-blocked.xml
energy-transient-tempus-blocked.xml
energy-neumann.xml
energy-ss-blocked-tp.xml
meshmotion.xml
Expand Down Expand Up @@ -104,6 +105,15 @@ IF(${PACKAGE_NAME}_ENABLE_Teko)
ARGS --i=energy-transient-blocked.xml
PASS_REGULAR_EXPRESSION "panzer::MainDriver run completed."
)

IF(${PACKAGE_NAME}_ENABLE_Tempus)
TRIBITS_ADD_ADVANCED_TEST(
main_driver_energy-transient-tempus-blocked
TEST_0 EXEC main_driver
ARGS --i=energy-transient-tempus-blocked.xml
PASS_REGULAR_EXPRESSION "panzer::MainDriver run completed."
)
ENDIF()
ENDIF()

IF(${PACKAGE_NAME}_ENABLE_Pamgen)
Expand Down

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/panzer/adapters-stk/example/main_driver/main_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
#include "user_app_BCStrategy_Factory.hpp"
#include "user_app_NOXObserverFactory.hpp"
#include "user_app_RythmosObserverFactory.hpp"
#ifdef PANZER_HAVE_TEMPUS
#include "user_app_TempusObserverFactory.hpp"
#endif
#include "user_app_ResponseEvaluatorFactory_HOFlux.hpp"

#include <Ioss_SerializeIO.h>
Expand Down Expand Up @@ -243,7 +246,16 @@ int main(int argc, char *argv[])
}

// solver = me_factory.getResponseOnlyModelEvaluator();
#ifdef PANZER_HAVE_TEMPUS
Teuchos::RCP<const panzer_stk::TempusObserverFactory> tof;
{
tof = Teuchos::rcp(new user_app::TempusObserverFactory(stkIOResponseLibrary,rLibrary->getWorksetContainer()));
}

solver = me_factory.buildResponseOnlyModelEvaluator(physics,global_data,Teuchos::null,Teuchos::null,nof.ptr(),rof.ptr(),tof.ptr());
#else
solver = me_factory.buildResponseOnlyModelEvaluator(physics,global_data,Teuchos::null,nof.ptr(),rof.ptr());
#endif
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// @HEADER
// ***********************************************************************
//
// Panzer: A partial differential equation assembly
// engine for strongly coupled complex multiphysics systems
// Copyright (2011) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Roger P. Pawlowski ([email protected]) and
// Eric C. Cyr ([email protected])
// ***********************************************************************
// @HEADER

#ifndef USER_APP_TEMPUS_OBSERVER_FACTORY_HPP
#define USER_APP_TEMPUS_OBSERVER_FACTORY_HPP

#include "PanzerAdaptersSTK_config.hpp"

#ifdef PANZER_HAVE_TEMPUS

#include "Panzer_STK_TempusObserverFactory.hpp"
#include "Panzer_ResponseLibrary.hpp"
#include "Panzer_Traits.hpp"

#include "Tempus_IntegratorObserverComposite.hpp"

// Individual Observers
#include "user_app_TempusObserver_WriteToExodus.hpp"

namespace user_app {

class TempusObserverFactory : public panzer_stk::TempusObserverFactory {

public:
TempusObserverFactory(const Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & stkIOResponseLibrary,
const Teuchos::RCP<panzer::WorksetContainer> wkstContainer)
: stkIOResponseLibrary_(stkIOResponseLibrary)
, wkstContainer_(wkstContainer)
{}

bool useNOXObserver() const { return false; }

Teuchos::RCP<Tempus::IntegratorObserver<double> >
buildTempusObserver(const Teuchos::RCP<panzer_stk::STK_Interface>& mesh,
const Teuchos::RCP<const panzer::GlobalIndexer> & dof_manager,
const Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> >& lof) const
{
Teuchos::RCP<Tempus::IntegratorObserverComposite<double> > composite_observer =
Teuchos::rcp(new Tempus::IntegratorObserverComposite<double>);

{
Teuchos::RCP<user_app::TempusObserver_WriteToExodus> observer
= Teuchos::rcp(new user_app::TempusObserver_WriteToExodus(mesh,dof_manager,lof,stkIOResponseLibrary_));
composite_observer->addObserver(observer);
}

return composite_observer;
}

private:
//! Store STK IO response library...be careful, it will be modified externally
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > stkIOResponseLibrary_;

Teuchos::RCP<panzer::WorksetContainer> wkstContainer_;
};

}

#endif // PANZER_HAVE_TEMPUS
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// @HEADER
// ***********************************************************************
//
// Panzer: A partial differential equation assembly
// engine for strongly coupled complex multiphysics systems
// Copyright (2011) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Roger P. Pawlowski ([email protected]) and
// Eric C. Cyr ([email protected])
// ***********************************************************************
// @HEADER

#ifndef USER_APP_TEMPUS_OBSERVER_WRITE_TO_EXODUS_HPP
#define USER_APP_TEMPUS_OBSERVER_WRITE_TO_EXODUS_HPP

#include "Tempus_Integrator.hpp"
#include "Tempus_IntegratorObserver.hpp"
#include "Teuchos_RCP.hpp"
#include "Teuchos_Assert.hpp"

#include "Panzer_STK_Interface.hpp"
#include "Panzer_GlobalIndexer.hpp"
#include "Panzer_STK_ResponseEvaluatorFactory_SolutionWriter.hpp"
#include "Panzer_STK_Utilities.hpp"

namespace user_app {

class TempusObserver_WriteToExodus : public Tempus::IntegratorObserver<double> {

public:

TempusObserver_WriteToExodus(const Teuchos::RCP<panzer_stk::STK_Interface>& mesh,
const Teuchos::RCP<const panzer::GlobalIndexer>& dof_manager,
const Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> >& lof,
const Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > & response_library) :
m_mesh(mesh),
m_dof_manager(dof_manager),
m_lof(lof),
m_response_library(response_library)
{
// get all element blocks and add them to the list
std::vector<std::string> eBlocks;
mesh->getElementBlockNames(eBlocks);

panzer_stk::RespFactorySolnWriter_Builder builder;
builder.mesh = mesh;
m_response_library->addResponse("Main Field Output",eBlocks,builder);
}

void observeStartIntegrator(const Tempus::Integrator<double>& integrator) override {this->writeToExodus(integrator);};
void observeStartTimeStep(const Tempus::Integrator<double>& ) override {};
void observeNextTimeStep(const Tempus::Integrator<double>& ) override {};
void observeBeforeTakeStep(const Tempus::Integrator<double>& ) override {};
void observeAfterTakeStep(const Tempus::Integrator<double>& integrator) override {this->writeToExodus(integrator);}
void observeAfterCheckTimeStep(const Tempus::Integrator<double>& ) override {};
void observeEndTimeStep(const Tempus::Integrator<double>& ) override {};
void observeEndIntegrator(const Tempus::Integrator<double>& ) override {};

void writeToExodus(const Tempus::Integrator<double>& integrator)
{

Teuchos::RCP<const Thyra::VectorBase<double> > solution = integrator.getSolutionHistory()->getStateTimeIndexN()->getX();

// initialize the assembly container
panzer::AssemblyEngineInArgs ae_inargs;
ae_inargs.container_ = m_lof->buildLinearObjContainer();
ae_inargs.ghostedContainer_ = m_lof->buildGhostedLinearObjContainer();
ae_inargs.alpha = 0.0;
ae_inargs.beta = 1.0;
ae_inargs.evaluate_transient_terms = false;

// initialize the ghosted container
m_lof->initializeGhostedContainer(panzer::LinearObjContainer::X,*ae_inargs.ghostedContainer_);

{
// initialize the x vector
const Teuchos::RCP<panzer::ThyraObjContainer<double> > thyraContainer
= Teuchos::rcp_dynamic_cast<panzer::ThyraObjContainer<double> >(ae_inargs.container_,true);
thyraContainer->set_x_th(Teuchos::rcp_const_cast<Thyra::VectorBase<double> >(solution));
}

m_response_library->addResponsesToInArgs<panzer::Traits::Residual>(ae_inargs);
m_response_library->evaluate<panzer::Traits::Residual>(ae_inargs);
m_mesh->writeToExodus(integrator.getSolutionHistory()->getCurrentTime());
}

protected:

Teuchos::RCP<panzer_stk::STK_Interface> m_mesh;
Teuchos::RCP<const panzer::GlobalIndexer> m_dof_manager;
Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > m_lof;
Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > m_response_library;
};

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@

namespace Piro {
template <typename ScalarT> class RythmosSolver;
#ifdef PANZER_HAVE_TEMPUS
template <typename ScalarT> class TempusSolverForwardOnly;
#endif
}

namespace Thyra {
Expand All @@ -98,6 +101,9 @@ namespace panzer_stk {
class STKConnManager;
class NOXObserverFactory;
class RythmosObserverFactory;
#ifdef PANZER_HAVE_TEMPUS
class TempusObserverFactory;
#endif
class WorksetFactory;

template<typename ScalarT>
Expand Down Expand Up @@ -135,6 +141,10 @@ namespace panzer_stk {

void setRythmosObserverFactory(const Teuchos::RCP<const panzer_stk::RythmosObserverFactory>& rythmos_observer_factory);

#ifdef PANZER_HAVE_TEMPUS
void setTempusObserverFactory(const Teuchos::RCP<const panzer_stk::TempusObserverFactory>& tempus_observer_factory);
#endif

template <typename BuilderT>
int addResponse(const std::string & responseName,const std::vector<panzer::WorksetDescriptor> & wkstDesc,const BuilderT & builder);

Expand All @@ -148,8 +158,15 @@ namespace panzer_stk {
buildResponseOnlyModelEvaluator(const Teuchos::RCP<Thyra::ModelEvaluator<ScalarT> > & thyra_me,
const Teuchos::RCP<panzer::GlobalData>& global_data,
const Teuchos::RCP<Piro::RythmosSolver<ScalarT> > rythmosSolver = Teuchos::null,
const Teuchos::Ptr<const panzer_stk::NOXObserverFactory> & in_nox_observer_factory=Teuchos::null,
const Teuchos::Ptr<const panzer_stk::RythmosObserverFactory> & in_rythmos_observer_factory=Teuchos::null);
#ifdef PANZER_HAVE_TEMPUS
const Teuchos::RCP<Piro::TempusSolverForwardOnly<ScalarT> > tempusSolver = Teuchos::null,
#endif
const Teuchos::Ptr<const panzer_stk::NOXObserverFactory> & in_nox_observer_factory=Teuchos::null,
const Teuchos::Ptr<const panzer_stk::RythmosObserverFactory> & in_rythmos_observer_factory=Teuchos::null
#ifdef PANZER_HAVE_TEMPUS
, const Teuchos::Ptr<const panzer_stk::TempusObserverFactory> & in_tempus_observer_factory=Teuchos::null
#endif
);

//@}

Expand Down Expand Up @@ -327,6 +344,9 @@ namespace panzer_stk {

Teuchos::RCP<const panzer_stk::NOXObserverFactory> m_nox_observer_factory;
Teuchos::RCP<const panzer_stk::RythmosObserverFactory> m_rythmos_observer_factory;
#ifdef PANZER_HAVE_TEMPUS
Teuchos::RCP<const panzer_stk::TempusObserverFactory> m_tempus_observer_factory;
#endif
Teuchos::RCP<panzer_stk::WorksetFactory> m_user_wkst_factory;
Teuchos::RCP<panzer::WorksetContainer> m_wkstContainer;

Expand Down
Loading

0 comments on commit 0b00ccf

Please sign in to comment.