From 196ced033b2d436941d4f11632aabb63da70bfb1 Mon Sep 17 00:00:00 2001 From: Roger Pawlowski Date: Mon, 14 Mar 2022 14:19:15 -0600 Subject: [PATCH] Panzer: add tempus example --- .../example/main_driver/CMakeLists.txt | 10 + .../energy-transient-tempus-blocked.xml | 453 ++++++++++++++++++ .../example/main_driver/main_driver.cpp | 12 + .../user_app_TempusObserverFactory.hpp | 99 ++++ .../user_app_TempusObserver_WriteToExodus.hpp | 127 +++++ 5 files changed, 701 insertions(+) create mode 100644 packages/panzer/adapters-stk/example/main_driver/energy-transient-tempus-blocked.xml create mode 100644 packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserverFactory.hpp create mode 100644 packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserver_WriteToExodus.hpp diff --git a/packages/panzer/adapters-stk/example/main_driver/CMakeLists.txt b/packages/panzer/adapters-stk/example/main_driver/CMakeLists.txt index 28314ce6e7f3..b9aba947ab6b 100644 --- a/packages/panzer/adapters-stk/example/main_driver/CMakeLists.txt +++ b/packages/panzer/adapters-stk/example/main_driver/CMakeLists.txt @@ -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 @@ -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) diff --git a/packages/panzer/adapters-stk/example/main_driver/energy-transient-tempus-blocked.xml b/packages/panzer/adapters-stk/example/main_driver/energy-transient-tempus-blocked.xml new file mode 100644 index 000000000000..922053b454ea --- /dev/null +++ b/packages/panzer/adapters-stk/example/main_driver/energy-transient-tempus-blocked.xml @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/panzer/adapters-stk/example/main_driver/main_driver.cpp b/packages/panzer/adapters-stk/example/main_driver/main_driver.cpp index 4e1dd294c79c..54b1314a0311 100644 --- a/packages/panzer/adapters-stk/example/main_driver/main_driver.cpp +++ b/packages/panzer/adapters-stk/example/main_driver/main_driver.cpp @@ -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 @@ -243,7 +246,16 @@ int main(int argc, char *argv[]) } // solver = me_factory.getResponseOnlyModelEvaluator(); +#ifdef PANZER_HAVE_TEMPUS + Teuchos::RCP 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 } } diff --git a/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserverFactory.hpp b/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserverFactory.hpp new file mode 100644 index 000000000000..78fc76ae2c15 --- /dev/null +++ b/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserverFactory.hpp @@ -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 (rppawlo@sandia.gov) and +// Eric C. Cyr (eccyr@sandia.gov) +// *********************************************************************** +// @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 > & stkIOResponseLibrary, + const Teuchos::RCP wkstContainer) + : stkIOResponseLibrary_(stkIOResponseLibrary) + , wkstContainer_(wkstContainer) + {} + + bool useNOXObserver() const { return false; } + + Teuchos::RCP > + buildTempusObserver(const Teuchos::RCP& mesh, + const Teuchos::RCP & dof_manager, + const Teuchos::RCP >& lof) const + { + Teuchos::RCP > composite_observer = + Teuchos::rcp(new Tempus::IntegratorObserverComposite); + + { + Teuchos::RCP 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 > stkIOResponseLibrary_; + + Teuchos::RCP wkstContainer_; + }; + +} + +#endif // PANZER_HAVE_TEMPUS +#endif diff --git a/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserver_WriteToExodus.hpp b/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserver_WriteToExodus.hpp new file mode 100644 index 000000000000..bf2db3711cff --- /dev/null +++ b/packages/panzer/adapters-stk/example/main_driver/user_app_TempusObserver_WriteToExodus.hpp @@ -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 (rppawlo@sandia.gov) and +// Eric C. Cyr (eccyr@sandia.gov) +// *********************************************************************** +// @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 { + + public: + + TempusObserver_WriteToExodus(const Teuchos::RCP& mesh, + const Teuchos::RCP& dof_manager, + const Teuchos::RCP >& lof, + const Teuchos::RCP > & 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 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& integrator) override {this->writeToExodus(integrator);}; + void observeStartTimeStep(const Tempus::Integrator& ) override {}; + void observeNextTimeStep(const Tempus::Integrator& ) override {}; + void observeBeforeTakeStep(const Tempus::Integrator& ) override {}; + void observeAfterTakeStep(const Tempus::Integrator& integrator) override {this->writeToExodus(integrator);} + void observeAfterCheckTimeStep(const Tempus::Integrator& ) override {}; + void observeEndTimeStep(const Tempus::Integrator& ) override {}; + void observeEndIntegrator(const Tempus::Integrator& ) override {}; + + void writeToExodus(const Tempus::Integrator& integrator) + { + + Teuchos::RCP > 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 > thyraContainer + = Teuchos::rcp_dynamic_cast >(ae_inargs.container_,true); + thyraContainer->set_x_th(Teuchos::rcp_const_cast >(solution)); + } + + m_response_library->addResponsesToInArgs(ae_inargs); + m_response_library->evaluate(ae_inargs); + m_mesh->writeToExodus(integrator.getSolutionHistory()->getCurrentTime()); + } + + protected: + + Teuchos::RCP m_mesh; + Teuchos::RCP m_dof_manager; + Teuchos::RCP > m_lof; + Teuchos::RCP > m_response_library; + }; + +} + +#endif