本文整理汇总了C++中ErrorVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorVector::size方法的具体用法?C++ ErrorVector::size怎么用?C++ ErrorVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorVector
的用法示例。
在下文中一共展示了ErrorVector::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flag_elements_by_mean_stddev
void MeshRefinement::flag_elements_by_mean_stddev (const ErrorVector & error_per_cell,
const Real refine_frac,
const Real coarsen_frac,
const unsigned int max_l)
{
// The function arguments are currently just there for
// backwards_compatibility
if (!_use_member_parameters)
{
// If the user used non-default parameters, lets warn
// that they're deprecated
if (refine_frac != 0.3 ||
coarsen_frac != 0.0 ||
max_l != libMesh::invalid_uint)
libmesh_deprecated();
_refine_fraction = refine_frac;
_coarsen_fraction = coarsen_frac;
_max_h_level = max_l;
}
// Get the mean value from the error vector
const Real mean = error_per_cell.mean();
// Get the standard deviation. This equals the
// square-root of the variance
const Real stddev = std::sqrt (error_per_cell.variance());
// Check for valid fractions
libmesh_assert_greater_equal (_refine_fraction, 0);
libmesh_assert_less_equal (_refine_fraction, 1);
libmesh_assert_greater_equal (_coarsen_fraction, 0);
libmesh_assert_less_equal (_coarsen_fraction, 1);
// The refine and coarsen cutoff
const Real refine_cutoff = mean + _refine_fraction * stddev;
const Real coarsen_cutoff = std::max(mean - _coarsen_fraction * stddev, 0.);
// Loop over the elements and flag them for coarsening or
// refinement based on the element error
for (auto & elem : _mesh.active_element_ptr_range())
{
const dof_id_type id = elem->id();
libmesh_assert_less (id, error_per_cell.size());
const ErrorVectorReal elem_error = error_per_cell[id];
// Possibly flag the element for coarsening ...
if (elem_error <= coarsen_cutoff)
elem->set_refinement_flag(Elem::COARSEN);
// ... or refinement
if ((elem_error >= refine_cutoff) && (elem->level() < _max_h_level))
elem->set_refinement_flag(Elem::REFINE);
}
}
示例2: estimate_errors
void ErrorEstimator::estimate_errors(const EquationSystems & equation_systems,
ErrorVector & error_per_cell,
const std::map<const System *, SystemNorm> & error_norms,
const std::map<const System *, const NumericVector<Number> *> * solution_vectors,
bool estimate_parent_error)
{
SystemNorm old_error_norm = this->error_norm;
// Sum the error values from each system
for (unsigned int s = 0; s != equation_systems.n_systems(); ++s)
{
ErrorVector system_error_per_cell;
const System & sys = equation_systems.get_system(s);
if (error_norms.find(&sys) == error_norms.end())
this->error_norm = old_error_norm;
else
this->error_norm = error_norms.find(&sys)->second;
const NumericVector<Number> * solution_vector = nullptr;
if (solution_vectors &&
solution_vectors->find(&sys) != solution_vectors->end())
solution_vector = solution_vectors->find(&sys)->second;
this->estimate_error(sys, system_error_per_cell,
solution_vector, estimate_parent_error);
if (s)
{
libmesh_assert_equal_to (error_per_cell.size(), system_error_per_cell.size());
for (std::size_t i=0; i != error_per_cell.size(); ++i)
error_per_cell[i] += system_error_per_cell[i];
}
else
error_per_cell = system_error_per_cell;
}
// Restore our old state before returning
this->error_norm = old_error_norm;
}
示例3: estimate_error
void JumpErrorEstimator::estimate_error (const System& system,
ErrorVector& error_per_cell,
const NumericVector<Number>* solution_vector,
bool estimate_parent_error)
{
START_LOG("estimate_error()", "JumpErrorEstimator");
/*
Conventions for assigning the direction of the normal:
- e & f are global element ids
Case (1.) Elements are at the same level, e<f
Compute the flux jump on the face and
add it as a contribution to error_per_cell[e]
and error_per_cell[f]
----------------------
| | |
| | f |
| | |
| e |---> n |
| | |
| | |
----------------------
Case (2.) The neighbor is at a higher level.
Compute the flux jump on e's face and
add it as a contribution to error_per_cell[e]
and error_per_cell[f]
----------------------
| | | |
| | e |---> n |
| | | |
|-----------| f |
| | | |
| | | |
| | | |
----------------------
*/
// The current mesh
const MeshBase& mesh = system.get_mesh();
// The number of variables in the system
const unsigned int n_vars = system.n_vars();
// The DofMap for this system
const DofMap& dof_map = system.get_dof_map();
// Resize the error_per_cell vector to be
// the number of elements, initialize it to 0.
error_per_cell.resize (mesh.max_elem_id());
std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
// Declare a vector of floats which is as long as
// error_per_cell above, and fill with zeros. This vector will be
// used to keep track of the number of edges (faces) on each active
// element which are either:
// 1) an internal edge
// 2) an edge on a Neumann boundary for which a boundary condition
// function has been specified.
// The error estimator can be scaled by the number of flux edges (faces)
// which the element actually has to obtain a more uniform measure
// of the error. Use floats instead of ints since in case 2 (above)
// f gets 1/2 of a flux face contribution from each of his
// neighbors
std::vector<float> n_flux_faces;
if (scale_by_n_flux_faces)
n_flux_faces.resize(error_per_cell.size(), 0);
// Prepare current_local_solution to localize a non-standard
// solution vector if necessary
if (solution_vector && solution_vector != system.solution.get())
{
NumericVector<Number>* newsol =
const_cast<NumericVector<Number>*>(solution_vector);
System &sys = const_cast<System&>(system);
newsol->swap(*sys.solution);
sys.update();
}
fine_context.reset(new FEMContext(system));
coarse_context.reset(new FEMContext(system));
// Loop over all the variables we've been requested to find jumps in, to
// pre-request
for (var=0; var<n_vars; var++)
{
// Possibly skip this variable
if (error_norm.weight(var) == 0.0) continue;
// FIXME: Need to generalize this to vector-valued elements. [PB]
FEBase* side_fe = NULL;
const std::set<unsigned char>& elem_dims =
fine_context->elem_dimensions();
//.........这里部分代码省略.........
示例4: estimate_error
void JumpErrorEstimator::estimate_error (const System& system,
ErrorVector& error_per_cell,
const NumericVector<Number>* solution_vector,
bool estimate_parent_error)
{
START_LOG("estimate_error()", "JumpErrorEstimator");
/*
Conventions for assigning the direction of the normal:
- e & f are global element ids
Case (1.) Elements are at the same level, e<f
Compute the flux jump on the face and
add it as a contribution to error_per_cell[e]
and error_per_cell[f]
----------------------
| | |
| | f |
| | |
| e |---> n |
| | |
| | |
----------------------
Case (2.) The neighbor is at a higher level.
Compute the flux jump on e's face and
add it as a contribution to error_per_cell[e]
and error_per_cell[f]
----------------------
| | | |
| | e |---> n |
| | | |
|-----------| f |
| | | |
| | | |
| | | |
----------------------
*/
// The current mesh
const MeshBase& mesh = system.get_mesh();
// The dimensionality of the mesh
const unsigned int dim = mesh.mesh_dimension();
// The number of variables in the system
const unsigned int n_vars = system.n_vars();
// The DofMap for this system
const DofMap& dof_map = system.get_dof_map();
// Resize the error_per_cell vector to be
// the number of elements, initialize it to 0.
error_per_cell.resize (mesh.max_elem_id());
std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
// Declare a vector of floats which is as long as
// error_per_cell above, and fill with zeros. This vector will be
// used to keep track of the number of edges (faces) on each active
// element which are either:
// 1) an internal edge
// 2) an edge on a Neumann boundary for which a boundary condition
// function has been specified.
// The error estimator can be scaled by the number of flux edges (faces)
// which the element actually has to obtain a more uniform measure
// of the error. Use floats instead of ints since in case 2 (above)
// f gets 1/2 of a flux face contribution from each of his
// neighbors
std::vector<float> n_flux_faces (error_per_cell.size());
// Prepare current_local_solution to localize a non-standard
// solution vector if necessary
if (solution_vector && solution_vector != system.solution.get())
{
NumericVector<Number>* newsol =
const_cast<NumericVector<Number>*>(solution_vector);
System &sys = const_cast<System&>(system);
newsol->swap(*sys.solution);
sys.update();
}
// Loop over all the variables in the system
for (var=0; var<n_vars; var++)
{
// Possibly skip this variable
if (error_norm.weight(var) == 0.0) continue;
// The type of finite element to use for this variable
const FEType& fe_type = dof_map.variable_type (var);
// Finite element objects for the same face from
// different sides
fe_fine = FEBase::build (dim, fe_type);
fe_coarse = FEBase::build (dim, fe_type);
// Build an appropriate Gaussian quadrature rule
//.........这里部分代码省略.........
示例5: estimate_error
void ExactErrorEstimator::estimate_error (const System & system,
ErrorVector & error_per_cell,
const NumericVector<Number> * solution_vector,
bool estimate_parent_error)
{
// Ignore the fact that this variable is unused when !LIBMESH_ENABLE_AMR
libmesh_ignore(estimate_parent_error);
// The current mesh
const MeshBase & mesh = system.get_mesh();
// The dimensionality of the mesh
const unsigned int dim = mesh.mesh_dimension();
// The number of variables in the system
const unsigned int n_vars = system.n_vars();
// The DofMap for this system
const DofMap & dof_map = system.get_dof_map();
// Resize the error_per_cell vector to be
// the number of elements, initialize it to 0.
error_per_cell.resize (mesh.max_elem_id());
std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
// Prepare current_local_solution to localize a non-standard
// solution vector if necessary
if (solution_vector && solution_vector != system.solution.get())
{
NumericVector<Number> * newsol =
const_cast<NumericVector<Number> *>(solution_vector);
System & sys = const_cast<System &>(system);
newsol->swap(*sys.solution);
sys.update();
}
// Loop over all the variables in the system
for (unsigned int var=0; var<n_vars; var++)
{
// Possibly skip this variable
if (error_norm.weight(var) == 0.0) continue;
// The (string) name of this variable
const std::string & var_name = system.variable_name(var);
// The type of finite element to use for this variable
const FEType & fe_type = dof_map.variable_type (var);
UniquePtr<FEBase> fe (FEBase::build (dim, fe_type));
// Build an appropriate Gaussian quadrature rule
UniquePtr<QBase> qrule =
fe_type.default_quadrature_rule (dim,
_extra_order);
fe->attach_quadrature_rule (qrule.get());
// Prepare a global solution and a MeshFunction of the fine system if we need one
UniquePtr<MeshFunction> fine_values;
UniquePtr<NumericVector<Number> > fine_soln = NumericVector<Number>::build(system.comm());
if (_equation_systems_fine)
{
const System & fine_system = _equation_systems_fine->get_system(system.name());
std::vector<Number> global_soln;
// FIXME - we're assuming that the fine system solution gets
// used even when a different vector is used for the coarse
// system
fine_system.update_global_solution(global_soln);
fine_soln->init
(cast_int<numeric_index_type>(global_soln.size()), true,
SERIAL);
(*fine_soln) = global_soln;
fine_values = UniquePtr<MeshFunction>
(new MeshFunction(*_equation_systems_fine,
*fine_soln,
fine_system.get_dof_map(),
fine_system.variable_number(var_name)));
fine_values->init();
} else {
// Initialize functors if we're using them
for (unsigned int i=0; i != _exact_values.size(); ++i)
if (_exact_values[i])
_exact_values[i]->init();
for (unsigned int i=0; i != _exact_derivs.size(); ++i)
if (_exact_derivs[i])
_exact_derivs[i]->init();
for (unsigned int i=0; i != _exact_hessians.size(); ++i)
if (_exact_hessians[i])
_exact_hessians[i]->init();
}
// Request the data we'll need to compute with
fe->get_JxW();
fe->get_phi();
fe->get_dphi();
#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
//.........这里部分代码省略.........
示例6: estimate_error
void AdjointResidualErrorEstimator::estimate_error (const System & _system,
ErrorVector & error_per_cell,
const NumericVector<Number> * solution_vector,
bool estimate_parent_error)
{
LOG_SCOPE("estimate_error()", "AdjointResidualErrorEstimator");
// The current mesh
const MeshBase & mesh = _system.get_mesh();
// Resize the error_per_cell vector to be
// the number of elements, initialize it to 0.
error_per_cell.resize (mesh.max_elem_id());
std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
// Get the number of variables in the system
unsigned int n_vars = _system.n_vars();
// We need to make a map of the pointer to the solution vector
std::map<const System *, const NumericVector<Number> *>solutionvecs;
solutionvecs[&_system] = _system.solution.get();
// Solve the dual problem if we have to
if (!_system.is_adjoint_already_solved())
{
// FIXME - we'll need to change a lot of APIs to make this trick
// work with a const System...
System & system = const_cast<System &>(_system);
system.adjoint_solve(_qoi_set);
}
// Flag to check whether we have not been asked to weight the variable error contributions in any specific manner
bool error_norm_is_identity = error_norm.is_identity();
// Create an ErrorMap/ErrorVector to store the primal, dual and total_dual variable errors
ErrorMap primal_errors_per_cell;
ErrorMap dual_errors_per_cell;
ErrorMap total_dual_errors_per_cell;
// Allocate ErrorVectors to this map if we're going to use it
if (!error_norm_is_identity)
for(unsigned int v = 0; v < n_vars; v++)
{
primal_errors_per_cell[std::make_pair(&_system, v)] = new ErrorVector;
dual_errors_per_cell[std::make_pair(&_system, v)] = new ErrorVector;
total_dual_errors_per_cell[std::make_pair(&_system, v)] = new ErrorVector;
}
ErrorVector primal_error_per_cell;
ErrorVector dual_error_per_cell;
ErrorVector total_dual_error_per_cell;
// Have we been asked to weight the variable error contributions in any specific manner
if(!error_norm_is_identity) // If we do
{
// Estimate the primal problem error for each variable
_primal_error_estimator->estimate_errors
(_system.get_equation_systems(), primal_errors_per_cell, &solutionvecs, estimate_parent_error);
}
else // If not
{
// Just get the combined error estimate
_primal_error_estimator->estimate_error
(_system, primal_error_per_cell, solution_vector, estimate_parent_error);
}
// Sum and weight the dual error estimate based on our QoISet
for (unsigned int i = 0; i != _system.qoi.size(); ++i)
{
if (_qoi_set.has_index(i))
{
// Get the weight for the current QoI
Real error_weight = _qoi_set.weight(i);
// We need to make a map of the pointer to the adjoint solution vector
std::map<const System *, const NumericVector<Number> *>adjointsolutionvecs;
adjointsolutionvecs[&_system] = &_system.get_adjoint_solution(i);
// Have we been asked to weight the variable error contributions in any specific manner
if(!error_norm_is_identity) // If we have
{
_dual_error_estimator->estimate_errors
(_system.get_equation_systems(), dual_errors_per_cell, &adjointsolutionvecs,
estimate_parent_error);
}
else // If not
{
// Just get the combined error estimate
_dual_error_estimator->estimate_error
(_system, dual_error_per_cell, &(_system.get_adjoint_solution(i)), estimate_parent_error);
}
std::size_t error_size;
// Get the size of the first ErrorMap vector; this will give us the number of elements
if(!error_norm_is_identity) // If in non default weights case
{
error_size = dual_errors_per_cell[std::make_pair(&_system, 0)]->size();
}
else // If in the standard default weights case
{
error_size = dual_error_per_cell.size();
//.........这里部分代码省略.........
示例7: flag_elements_by_error_fraction
//-----------------------------------------------------------------
// Mesh refinement methods
void MeshRefinement::flag_elements_by_error_fraction (const ErrorVector& error_per_cell,
const Real refine_frac,
const Real coarsen_frac,
const unsigned int max_l)
{
parallel_only();
// The function arguments are currently just there for
// backwards_compatibility
if (!_use_member_parameters)
{
// If the user used non-default parameters, lets warn
// that they're deprecated
if (refine_frac != 0.3 ||
coarsen_frac != 0.0 ||
max_l != libMesh::invalid_uint)
libmesh_deprecated();
_refine_fraction = refine_frac;
_coarsen_fraction = coarsen_frac;
_max_h_level = max_l;
}
// Check for valid fractions..
// The fraction values must be in [0,1]
libmesh_assert_greater_equal (_refine_fraction, 0);
libmesh_assert_less_equal (_refine_fraction, 1);
libmesh_assert_greater_equal (_coarsen_fraction, 0);
libmesh_assert_less_equal (_coarsen_fraction, 1);
// Clean up the refinement flags. These could be left
// over from previous refinement steps.
this->clean_refinement_flags();
// We're getting the minimum and maximum error values
// for the ACTIVE elements
Real error_min = 1.e30;
Real error_max = 0.;
// And, if necessary, for their parents
Real parent_error_min = 1.e30;
Real parent_error_max = 0.;
// Prepare another error vector if we need to sum parent errors
ErrorVector error_per_parent;
if (_coarsen_by_parents)
{
create_parent_error_vector(error_per_cell,
error_per_parent,
parent_error_min,
parent_error_max);
}
// We need to loop over all active elements to find the minimum
MeshBase::element_iterator el_it =
_mesh.active_local_elements_begin();
const MeshBase::element_iterator el_end =
_mesh.active_local_elements_end();
for (; el_it != el_end; ++el_it)
{
const unsigned int id = (*el_it)->id();
libmesh_assert_less (id, error_per_cell.size());
error_max = std::max (error_max, error_per_cell[id]);
error_min = std::min (error_min, error_per_cell[id]);
}
CommWorld.max(error_max);
CommWorld.min(error_min);
// Compute the cutoff values for coarsening and refinement
const Real error_delta = (error_max - error_min);
const Real parent_error_delta = parent_error_max - parent_error_min;
const Real refine_cutoff = (1.- _refine_fraction)*error_max;
const Real coarsen_cutoff = _coarsen_fraction*error_delta + error_min;
const Real parent_cutoff = _coarsen_fraction*parent_error_delta + error_min;
// // Print information about the error
// libMesh::out << " Error Information:" << std::endl
// << " ------------------" << std::endl
// << " min: " << error_min << std::endl
// << " max: " << error_max << std::endl
// << " delta: " << error_delta << std::endl
// << " refine_cutoff: " << refine_cutoff << std::endl
// << " coarsen_cutoff: " << coarsen_cutoff << std::endl;
// Loop over the elements and flag them for coarsening or
// refinement based on the element error
MeshBase::element_iterator e_it =
_mesh.active_elements_begin();
const MeshBase::element_iterator e_end =
_mesh.active_elements_end();
for (; e_it != e_end; ++e_it)
{
//.........这里部分代码省略.........
示例8: flag_elements_by_nelem_target
bool MeshRefinement::flag_elements_by_nelem_target (const ErrorVector& error_per_cell)
{
parallel_only();
// Check for valid fractions..
// The fraction values must be in [0,1]
libmesh_assert_greater_equal (_refine_fraction, 0);
libmesh_assert_less_equal (_refine_fraction, 1);
libmesh_assert_greater_equal (_coarsen_fraction, 0);
libmesh_assert_less_equal (_coarsen_fraction, 1);
// This function is currently only coded to work when coarsening by
// parents - it's too hard to guess how many coarsenings will be
// performed otherwise.
libmesh_assert (_coarsen_by_parents);
// The number of active elements in the mesh - hopefully less than
// 2 billion on 32 bit machines
const unsigned int n_active_elem = _mesh.n_active_elem();
// The maximum number of active elements to flag for coarsening
const unsigned int max_elem_coarsen =
static_cast<unsigned int>(_coarsen_fraction * n_active_elem) + 1;
// The maximum number of elements to flag for refinement
const unsigned int max_elem_refine =
static_cast<unsigned int>(_refine_fraction * n_active_elem) + 1;
// Clean up the refinement flags. These could be left
// over from previous refinement steps.
this->clean_refinement_flags();
// The target number of elements to add or remove
const int n_elem_new = _nelem_target - n_active_elem;
// Create an vector with active element errors and ids,
// sorted by highest errors first
const unsigned int max_elem_id = _mesh.max_elem_id();
std::vector<std::pair<float, unsigned int> > sorted_error;
sorted_error.reserve (n_active_elem);
// On a ParallelMesh, we need to communicate to know which remote ids
// correspond to active elements.
{
std::vector<bool> is_active(max_elem_id, false);
MeshBase::element_iterator elem_it = _mesh.active_local_elements_begin();
const MeshBase::element_iterator elem_end = _mesh.active_local_elements_end();
for (; elem_it != elem_end; ++elem_it)
{
const unsigned int eid = (*elem_it)->id();
is_active[eid] = true;
libmesh_assert_less (eid, error_per_cell.size());
sorted_error.push_back
(std::make_pair(error_per_cell[eid], eid));
}
CommWorld.max(is_active);
CommWorld.allgather(sorted_error);
}
// Default sort works since pairs are sorted lexicographically
std::sort (sorted_error.begin(), sorted_error.end());
std::reverse (sorted_error.begin(), sorted_error.end());
// Create a sorted error vector with coarsenable parent elements
// only, sorted by lowest errors first
ErrorVector error_per_parent;
std::vector<std::pair<float, unsigned int> > sorted_parent_error;
Real parent_error_min, parent_error_max;
create_parent_error_vector(error_per_cell,
error_per_parent,
parent_error_min,
parent_error_max);
// create_parent_error_vector sets values for non-parents and
// non-coarsenable parents to -1. Get rid of them.
for (unsigned int i=0; i != error_per_parent.size(); ++i)
if (error_per_parent[i] != -1)
sorted_parent_error.push_back(std::make_pair(error_per_parent[i], i));
std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
// Keep track of how many elements we plan to coarsen & refine
unsigned int coarsen_count = 0;
unsigned int refine_count = 0;
const unsigned int dim = _mesh.mesh_dimension();
unsigned int twotodim = 1;
for (unsigned int i=0; i!=dim; ++i)
twotodim *= 2;
// First, let's try to get our element count to target_nelem
if (n_elem_new >= 0)
{
// Every element refinement creates at least
// 2^dim-1 new elements
//.........这里部分代码省略.........