Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78389467
transport_stagger.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Aug 20, 13:23
Size
5 KB
Mime Type
text/x-c
Expires
Thu, Aug 22, 13:23 (2 d)
Engine
blob
Format
Raw Data
Handle
20037981
Attached To
rSPECMICP SpecMiCP / ReactMiCP
transport_stagger.cpp
View Options
/*-------------------------------------------------------------------------------
Copyright (c) 2014,2015 F. Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
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 copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR 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.
-----------------------------------------------------------------------------*/
#include "transport_stagger.hpp"
#include "variables.hpp"
#include "reactmicp/solver/staggers_base/stagger_structs.hpp"
namespace specmicp {
namespace reactmicp {
namespace systems {
namespace satdiff {
// class SaturatedTransportStagger::
namespace internal {
//! \brief Translate a ParabolicDriverReturnCode to a StaggerReturnCode
solver::StaggerReturnCode Parabolic2StaggerReturnCode(dfpmsolver::ParabolicDriverReturnCode retcode)
{
using ParRC = dfpmsolver::ParabolicDriverReturnCode;
using StaRC = solver::StaggerReturnCode;
switch (retcode)
{
case ParRC::ResidualMinimized:
return StaRC::ResidualMinimized;
break;
case ParRC::ErrorMinimized:
return StaRC::ErrorMinimized;
break;
default: // error
switch(retcode)
{
case ParRC::MaxIterations:
return StaRC::MaximumIterationsReached;
break;
case ParRC::StationaryPoint:
return StaRC::StationaryPoint;
break;
case ParRC::NotConvergedYet:
return StaRC::NotConvergedYet;
break;
default:
return StaRC::UnknownError;
}
}
}
} // end namespace internal
SaturatedTransportStagger::SaturatedTransportStagger(SaturatedVariablesPtr variables,
std::vector<index_t> list_fixed_nodes):
m_program(variables, list_fixed_nodes),
m_solver(m_program)
{
}
SaturatedTransportStagger::SaturatedTransportStagger(
SaturatedVariablesPtr variables,
std::vector<index_t> list_fixed_nodes,
std::map<index_t, index_t> list_slave_nodes,
std::vector<index_t> list_immobile_components):
m_program(variables, list_fixed_nodes, list_slave_nodes, list_immobile_components),
m_solver(m_program)
{
}
//! \brief Initialize the stagger at the beginning of an iteration
void SaturatedTransportStagger::initialize_timestep(scalar_t dt, VariablesBasePtr var)
{
m_dt = dt;
SaturatedVariablesPtr true_var = cast_var_from_base(var);
true_var->predictor() = true_var->displacement();
true_var->velocity().setZero();
true_var->transport_rate().setZero();
m_solver.initialize_timestep(dt, true_var->displacement());
Vector tmp = true_var->chemistry_rate();
true_var->chemistry_rate().setZero();
Eigen::VectorXd residuals;
m_program.compute_residuals(true_var->displacement(), true_var->velocity(), residuals);
m_residual_0 = residuals.norm();
true_var->chemistry_rate() = tmp;
m_program.set_variables(true_var);
}
//! \brief Solve the equation for the timestep
solver::StaggerReturnCode SaturatedTransportStagger::restart_timestep(VariablesBasePtr var)
{
SaturatedVariablesPtr true_var = cast_var_from_base(var);
m_solver.velocity() = true_var->velocity();
dfpmsolver::ParabolicDriverReturnCode retcode = m_solver.restart_timestep(true_var->displacement());
// copy variables if successful
if (retcode > dfpmsolver::ParabolicDriverReturnCode::NotConvergedYet)
{
true_var->velocity() = m_solver.velocity();
}
return internal::Parabolic2StaggerReturnCode(retcode);
}
scalar_t SaturatedTransportStagger::get_update(VariablesBasePtr var)
{
return cast_var_from_base(var)->velocity().norm();
}
//! \brief Compute the residuals norm
scalar_t SaturatedTransportStagger::get_residual(VariablesBasePtr var)
{
SaturatedVariablesPtr true_var = cast_var_from_base(var);
Eigen::VectorXd residuals;
m_program.compute_residuals(true_var->displacement(), true_var->velocity(), residuals);
return residuals.norm();
}
} // end namespace satdiff
} // end namespace systems
} // end namespace reactmicp
} // end namespace specmicp
Event Timeline
Log In to Comment