Skip to content

Commit

Permalink
Merge Pull Request #3460 from rppawlo/Trilinos/nox-solvers-and-observ…
Browse files Browse the repository at this point in the history
…sers

Automatically Merged using Trilinos Pull Request AutoTester
PR Title: NOX: update solvers and observers
PR Author: rppawlo
  • Loading branch information
trilinos-autotester authored Sep 20, 2018
2 parents 5257e95 + cea35fa commit e5715f9
Show file tree
Hide file tree
Showing 45 changed files with 935 additions and 490 deletions.
3 changes: 0 additions & 3 deletions packages/nox/examples/lapack/NOX_ExportMakefile/Rosenbrock.C
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ private:
//! Main subroutine of Rosenbrock.C
int main()
{
// Print out the NOX code version number
std::cout << "\n" << NOX::version() << std::endl;

// Set up the problem interface
Rosenbrock rosenbrock;

Expand Down
3 changes: 0 additions & 3 deletions packages/nox/examples/lapack/NOX_SimpleExamples/Rosenbrock.C
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ int main()
bool success = false;
bool verbose = false;
try {
// Print out the NOX code version number
std::cout << "\n" << NOX::version() << std::endl;

// Set up the problem interface
Rosenbrock rosenbrock;

Expand Down
9 changes: 8 additions & 1 deletion packages/nox/src-loca/src/LOCA_Solver_Wrapper.C
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,15 @@ reset(const NOX::Abstract::Vector& initialGuess)
resetWrapper();
}

void
LOCA::Solver::Wrapper::
reset()
{
resetWrapper();
}

NOX::StatusTest::StatusType
LOCA::Solver::Wrapper::getStatus()
LOCA::Solver::Wrapper::getStatus() const
{
return solverPtr->getStatus();
}
Expand Down
5 changes: 4 additions & 1 deletion packages/nox/src-loca/src/LOCA_Solver_Wrapper.H
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ namespace LOCA {
//! Destructor
~Wrapper();

//! Implementation of reset method (forwarded to wrapped solver)
void reset();

//! Implementation of reset method (forwarded to wrapped solver)
void reset(const NOX::Abstract::Vector& initialGuess);

Expand All @@ -119,7 +122,7 @@ namespace LOCA {
const Teuchos::RCP<NOX::StatusTest::Generic>& tests);

//! Implementation of getStatus method (forwarded to wrapped solver)
NOX::StatusTest::StatusType getStatus();
NOX::StatusTest::StatusType getStatus() const;

//! Implementation of step method (forwarded to wrapped solver)
NOX::StatusTest::StatusType step();
Expand Down
27 changes: 24 additions & 3 deletions packages/nox/src-thyra/NOX_Solver_PseudoTransient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,36 @@ reset(const NOX::Abstract::Vector& initialGuess,
{
solnPtr->setX(initialGuess);
testPtr = t;
init();
stepSize = 0.0;
nIter = 0;
status = NOX::StatusTest::Unconverged;
globalDataPtr->getNonConstSolverStatistics()->reset();
time = 0.0;
}

void NOX::Solver::PseudoTransient::
reset(const NOX::Abstract::Vector& initialGuess)
{
solnPtr->setX(initialGuess);
init();
stepSize = 0.0;
nIter = 0;
status = NOX::StatusTest::Unconverged;
globalDataPtr->getNonConstSolverStatistics()->reset();
time = 0.0;
}

NOX::StatusTest::StatusType NOX::Solver::PseudoTransient::getStatus()
void NOX::Solver::PseudoTransient::
reset()
{
stepSize = 0.0;
nIter = 0;
status = NOX::StatusTest::Unconverged;
globalDataPtr->getNonConstSolverStatistics()->reset();
time = 0.0;
}

NOX::StatusTest::StatusType
NOX::Solver::PseudoTransient::getStatus() const
{
return status;
}
Expand Down Expand Up @@ -377,6 +396,8 @@ NOX::StatusTest::StatusType NOX::Solver::PseudoTransient::solve()
{
observer->runPreSolve(*this);

this->reset();

// Iterate until converged or failed
while (status == NOX::StatusTest::Unconverged)
step();
Expand Down
3 changes: 2 additions & 1 deletion packages/nox/src-thyra/NOX_Solver_PseudoTransient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ namespace Solver {
void reset(const NOX::Abstract::Vector& initialGuess,
const Teuchos::RCP<NOX::StatusTest::Generic>& tests);
void reset(const NOX::Abstract::Vector& initialGuess);
NOX::StatusTest::StatusType getStatus();
void reset();
NOX::StatusTest::StatusType step();
NOX::StatusTest::StatusType solve();
const NOX::Abstract::Group& getSolutionGroup() const;
const NOX::Abstract::Group& getPreviousSolutionGroup() const;
NOX::StatusTest::StatusType getStatus() const;
int getNumIterations() const;
const Teuchos::ParameterList& getList() const;
double getStepSize() const;
Expand Down
2 changes: 1 addition & 1 deletion packages/nox/src-thyra/NOX_Thyra_Group.H
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

// Forward declares
namespace NOX {
class SolverStats;
struct SolverStats;
namespace Parameter {
class List;
}
Expand Down
9 changes: 6 additions & 3 deletions packages/nox/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,20 @@ APPEND_SET(HEADERS
NOX_Utils.H
NOX_SharedObjectTemplate.H
NOX_Random.H
NOX_Version.H
NOX_GlobalData.H
NOX_PrePostOperator_Vector.H
NOX_Observer_Vector.hpp
NOX_Observer_Log.hpp
NOX_Observer_Print.hpp
NOX_Assert.H
)
APPEND_SET(SOURCES
NOX_Utils.C
NOX_Random.C
NOX_Version.C
NOX_GlobalData.C
NOX_PrePostOperator_Vector.C
NOX_Observer_Vector.cpp
NOX_Observer_Log.cpp
NOX_Observer_Print.cpp
)

# Multivector
Expand Down
1 change: 0 additions & 1 deletion packages/nox/src/NOX.H
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
#include "NOX_StatusTest_RelativeNormF.H"
#include "NOX_StatusTest_NStep.H"
#include "NOX_Utils.H"
#include "NOX_Version.H"
#include "NOX_LineSearch_UserDefinedFactory.H"
#include "NOX_LineSearch_UserDefinedFactoryT.H"
#include "NOX_Direction_UserDefinedFactory.H"
Expand Down
2 changes: 1 addition & 1 deletion packages/nox/src/NOX_Abstract_Group.H
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Teuchos {
class ParameterList;
}
namespace NOX {
class SolverStats;
struct SolverStats;
namespace Abstract {
class MultiVector;
}
Expand Down
9 changes: 4 additions & 5 deletions packages/nox/src/NOX_Abstract_PrePostOperator.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// $Id$
// $Source$

//@HEADER
// ************************************************************************
//
Expand Down Expand Up @@ -46,8 +43,10 @@

#include "NOX_Observer.hpp"

// Backwards compatibility for renaming the PrePostOperator to
// Observer.
// This file is deprecated but exists for backwards compatibility in
// transition from PrePostOperator to Observer. Please include
// NOX_Observer.hpp instead.

namespace NOX {
namespace Abstract {
using PrePostOperator = NOX::Observer;
Expand Down
2 changes: 1 addition & 1 deletion packages/nox/src/NOX_GlobalData.H
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace NOX {
namespace MeritFunction {
class Generic;
}
class SolverStats;
struct SolverStats;
}

namespace NOX {
Expand Down
9 changes: 8 additions & 1 deletion packages/nox/src/NOX_Multiphysics_Solver_FixedPointBased.C
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ NOX::Multiphysics::Solver::FixedPointBased::reset(
TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
}

void
NOX::Multiphysics::Solver::FixedPointBased::reset()
{
std::string msg = "Error - NOX::Multiphysics::Solver::FixedPointBased::reset() - this reset method is not valid for a Multiphysics Solver!";
TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
}

NOX::Multiphysics::Solver::FixedPointBased::~FixedPointBased()
{

}


NOX::StatusTest::StatusType
NOX::Multiphysics::Solver::FixedPointBased::getStatus()
NOX::Multiphysics::Solver::FixedPointBased::getStatus() const
{
return status;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nox/src/NOX_Multiphysics_Solver_FixedPointBased.H
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public:
virtual void reset(const NOX::Abstract::Vector& initialGuess,
const Teuchos::RCP<NOX::StatusTest::Generic>& tests);
virtual void reset(const NOX::Abstract::Vector& initialGuess);
virtual NOX::StatusTest::StatusType getStatus();
virtual void reset();
virtual NOX::StatusTest::StatusType getStatus() const;
virtual NOX::StatusTest::StatusType step();
virtual NOX::StatusTest::StatusType solve();
virtual const NOX::Abstract::Group& getSolutionGroup() const;
Expand Down
2 changes: 2 additions & 0 deletions packages/nox/src/NOX_Multiphysics_Solver_Manager.C
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ reset(const Abstract::Vector& initialGuess)
cplPtr->reset(initialGuess);
}

void NOX::Multiphysics::Solver::Manager::reset() {}

// PRIVATE
void NOX::Multiphysics::Solver::Manager::deprecated(const std::string& oldName, const std::string& newName) const
{
Expand Down
1 change: 1 addition & 0 deletions packages/nox/src/NOX_Multiphysics_Solver_Manager.H
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public:
virtual void reset(const NOX::Abstract::Vector& initialGuess,
const Teuchos::RCP<NOX::StatusTest::Generic>& tests);
virtual void reset(const NOX::Abstract::Vector& initialGuess);
virtual void reset();
virtual NOX::StatusTest::StatusType getStatus();
virtual NOX::StatusTest::StatusType step();
virtual NOX::StatusTest::StatusType solve();
Expand Down
144 changes: 144 additions & 0 deletions packages/nox/src/NOX_Observer_Log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//@HEADER
// ************************************************************************
//
// NOX: An Object-Oriented Nonlinear Solver Package
// Copyright (2002) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// 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 Pawlowski ([email protected]) or
// Eric Phipps ([email protected]), Sandia National Laboratories.
//@HEADER

#include "NOX_Observer_Log.hpp"

namespace NOX {

ObserverLog::ObserverLog(const bool log_call_order) :
pre_it_count_(0),
post_it_count_(0),
pre_solve_count_(0),
post_solve_count_(0),
pre_solution_update_count_(0),
post_solution_update_count_(0),
pre_linesearch_count_(0),
post_linesearch_count_(0),
log_call_order_(log_call_order)
{}

ObserverLog::~ObserverLog() {}

void ObserverLog::
runPreIterate(const NOX::Solver::Generic& solver)
{
pre_it_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPreIterate");
}

void ObserverLog::runPostIterate(const NOX::Solver::Generic& solver)
{
post_it_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPostIterate");
}

void ObserverLog::runPreSolve(const NOX::Solver::Generic& solver)
{
pre_solve_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPreSolve");
}

void ObserverLog::runPostSolve(const NOX::Solver::Generic& solver)
{
post_solve_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPostSolve");
}

void ObserverLog::runPreSolutionUpdate(const NOX::Abstract::Vector& update,
const NOX::Solver::Generic& solver)
{
pre_solution_update_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPreSolutionUpdate");
}

void ObserverLog::runPostSolutionUpdate(const NOX::Solver::Generic& solver)
{
post_solution_update_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPostSolutionUpdate");
}

void ObserverLog::runPreLineSearch(const NOX::Solver::Generic& solver)
{
pre_linesearch_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPreLineSearch");
}

void ObserverLog::runPostLineSearch(const NOX::Solver::Generic& solver)
{
post_linesearch_count_ += 1;
if (log_call_order_)
call_order_.push_back("runPostLineSearch");
}

int ObserverLog::preIterateCount() const
{return pre_it_count_;}

int ObserverLog::postIterateCount() const
{return post_it_count_;}

int ObserverLog::preSolveCount() const
{return pre_solve_count_;}

int ObserverLog::postSolveCount() const
{return post_solve_count_;}

int ObserverLog::preSolutionUpdateCount() const
{return pre_solution_update_count_;}

int ObserverLog::postSolutionUpdateCount() const
{return post_solution_update_count_;}

int ObserverLog::preLineSearchCount() const
{return pre_linesearch_count_;}

int ObserverLog::postLineSearchCount() const
{return post_linesearch_count_;}

const std::vector<std::string>& ObserverLog::getCallOrder() const
{return call_order_;}

}
Loading

0 comments on commit e5715f9

Please sign in to comment.