7 #include <boost/array.hpp>
8 #include <boost/bind.hpp>
9 #include <boost/function.hpp>
49 using namespace solver::actions::Proto;
58 options().add(
"velocity_field_tag",
"navier_stokes_u_solution")
59 .pretty_name(
"Velocity Field Tag")
60 .description(
"Tag for the field containing the velocity")
61 .attach_trigger(boost::bind(&ComputeCFL::trigger_variable,
this));
63 options().add(
"velocity_variable_name",
"Velocity")
64 .pretty_name(
"Velocity Variable Name")
65 .description(
"Name of the velocity to use")
66 .attach_trigger(boost::bind(&ComputeCFL::trigger_variable,
this));
68 options().add(
"max_cfl", m_max_cfl)
69 .pretty_name(
"Max CFL")
70 .description(
"Maximum allowed CFL number")
75 .description(
"Time component for the simulation")
81 ComputeCFL::~ComputeCFL()
92 typedef boost::mpl::int_<T::shape>
type;
98 typedef boost::mpl::void_
type;
101 template<
typename UT>
104 typedef typename UT::EtypeT ElementT;
108 template<
typename UT,
typename NodesT,
unsigned long N>
109 Real
max_edge_projection(
const UT& u,
const NodesT&
nodes,
const boost::array<int, N>& a_nodes,
const boost::array<int, N>& b_nodes)
const
112 for(
int i = 0; i !=
N; ++i)
114 const UT
diff = nodes.row(a_nodes[i]) - nodes.row(b_nodes[i]);
115 const Real projection = fabs(u.dot(diff) / diff.squaredNorm());
116 result = projection > result ? projection : result;
122 template<
typename UT>
123 void get_scale(boost::mpl::int_<cf3::mesh::GeoShape::TRIAG>,
const UT& u, Real& cfl_scale)
const
126 const boost::array<int, 3> a_nodes = { 0, 1, 2 };
127 const boost::array<int, 3> b_nodes = { 1, 2, 0 };
128 cfl_scale = max_edge_projection(u.eval(center), u.support().nodes(), a_nodes, b_nodes);
131 template<
typename UT>
132 void get_scale(boost::mpl::int_<cf3::mesh::GeoShape::TETRA>,
const UT& u, Real& cfl_scale)
const
134 static const RealVector3 center(1./3., 1./3., 1./3.);
135 const boost::array<int, 6> a_nodes = { 0, 1, 2, 0, 1, 2 };
136 const boost::array<int, 6> b_nodes = { 1, 2, 0, 3, 3, 3 };
137 cfl_scale = max_edge_projection(u.eval(center), u.support().nodes(), a_nodes, b_nodes);
140 template<
typename UT>
141 void get_scale(boost::mpl::int_<cf3::mesh::GeoShape::PRISM>,
const UT& u, Real& cfl_scale)
const
144 const boost::array<int, 9> a_nodes = { 0, 1, 2, 3, 4, 5, 0, 1, 2 };
145 const boost::array<int, 9> b_nodes = { 1, 2, 0, 4, 5, 3, 3, 4, 5 };
146 cfl_scale = max_edge_projection(u.eval(center), u.support().nodes(), a_nodes, b_nodes);
149 template<
typename UT>
150 void get_scale(boost::mpl::int_<cf3::mesh::GeoShape::QUAD>,
const UT& u, Real& cfl_scale)
const
153 const boost::array<int, 4> a_nodes = { 0, 1, 2, 3 };
154 const boost::array<int, 4> b_nodes = { 1, 2, 3, 0 };
155 cfl_scale = max_edge_projection(u.eval(center), u.support().nodes(), a_nodes, b_nodes);
158 template<
typename UT>
159 void get_scale(boost::mpl::int_<cf3::mesh::GeoShape::HEXA>,
const UT& u, Real& cfl_scale)
const
162 const boost::array<int, 12> a_nodes = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 };
163 const boost::array<int, 12> b_nodes = { 1, 2, 3, 0, 5, 6, 7, 4, 4, 5, 6, 7 };
164 cfl_scale = max_edge_projection(u.eval(center), u.support().nodes(), a_nodes, b_nodes);
167 template<
typename UT>
168 inline void get_scale(boost::mpl::void_,
const UT& u, Real& cfl_scale)
const
175 void ComputeCFL::trigger_variable()
177 using boost::proto::lit;
179 const std::string tag = options().option(
"velocity_field_tag").value<std::string>();
180 const std::string var = options().option(
"velocity_variable_name").value<std::string>();
187 boost::mpl::vector10<mesh::LagrangeP0::Triag, mesh::LagrangeP1::Triag2D, mesh::LagrangeP0::Quad, mesh::LagrangeP1::Quad2D, mesh::LagrangeP0::Hexa, mesh::LagrangeP1::Hexa3D, mesh::LagrangeP0::Tetra, mesh::LagrangeP1::Tetra3D, mesh::LagrangeP0::Prism, mesh::LagrangeP1::Prism3D>(),
191 cfl = lit(m_dt) * lit(m_cfl_scaling),
192 lit(m_max_computed_cfl) =
_max(lit(m_max_computed_cfl), cfl)
197 void ComputeCFL::execute()
204 m_max_computed_cfl = 0.;
205 ProtoAction::execute();
207 Real global_max_cfl = m_max_computed_cfl;
213 CFinfo <<
"CFL for time step " << m_dt <<
" is " << global_max_cfl <<
CFendl;
boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
static solver::actions::Proto::MakeSFOp< CFLOp >::type const compute_cfl
T * all_reduce(const Op &op, const T *in_values, const int in_n, T *out_values, const int stride=1)
#define CFinfo
these are always defined
std::string name(ComponentWrapper &self)
void get_scale(boost::mpl::int_< cf3::mesh::GeoShape::TRIAG >, const UT &u, Real &cfl_scale) const
bool is_null(T ptr)
predicate for comparison to nullptr
void get_scale(boost::mpl::int_< cf3::mesh::GeoShape::PRISM >, const UT &u, Real &cfl_scale) const
Helper class to create the Builder and place it in the factory.
common::ComponentBuilder< ComputeCFL, common::Action, LibUFEM > ComputeCFL_Builder
This header collects all the headers needed for the linear system solver, also including configure-ti...
Class to encapsulate Proto actions.
boost::shared_ptr< ElementsExpression< ExprT, ElementTypes > > elements_expression(ElementTypes, const ExprT &expr)
Dim
Enumeration of the dimensions.
void get_scale(boost::mpl::void_, const UT &u, Real &cfl_scale) const
Real max(const Real a, const Real b)
Maximum between two scalars.
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
boost::proto::terminal< SFOp< CustomSFOp< OpT > > >::type type
boost::mpl::int_< T::shape > type
void get_scale(boost::mpl::int_< cf3::mesh::GeoShape::HEXA >, const UT &u, Real &cfl_scale) const
Top-level namespace for coolfluid.
void get_scale(boost::mpl::int_< cf3::mesh::GeoShape::QUAD >, const UT &u, Real &cfl_scale) const
static std::string library_namespace()
void operator()(const UT &u, Real &cfl_scale) const
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
static boost::proto::terminal< double(*)(double, double) >::type const _max
Dummy shape function type used for element-based fields.
Real max_edge_projection(const UT &u, const NodesT &nodes, const boost::array< int, N > &a_nodes, const boost::array< int, N > &b_nodes) const
static Comm & instance()
Return a reference to the current PE.
ComputeCFL(const std::string &name)
Contructor.
Eigen::Matrix< Real, 3, 1 > RealVector3
Fixed size 3x1 column vector.
void get_scale(boost::mpl::int_< cf3::mesh::GeoShape::TETRA >, const UT &u, Real &cfl_scale) const