17#include "libmesh/distributed_mesh.h"
18#include "libmesh/equation_systems.h"
19#include "libmesh/mesh_function.h"
20#include "libmesh/explicit_system.h"
28 params.
addParam<
unsigned int>(
"refinements",
30 "Number of uniform refinements for oversampling "
31 "(refinement levels beyond any level of "
32 "refinements already applied on the regular mesh)");
34 "Set a positional offset, this vector will get added to the "
35 "nodal coordinates to move the domain.");
36 params.
addParam<MeshFileName>(
"file",
"The name of the mesh file to read, for oversampling");
37 params.
addParam<std::vector<SubdomainName>>(
38 "sampling_blocks",
"The list of blocks to restrict the mesh sampling to");
42 "If set to true, all sampled output (see sampling parameters) will be done "
43 "on rank 0. This option is useful to debug suspected parallel output issues");
48 "Append '_oversample' to the output file base",
49 "This parameter is deprecated. To append '_oversample' utilize "
50 "the output block name or the 'file_base'");
54 "Modified Mesh Sampling");
61 _refinements(getParam<unsigned
int>(
"refinements")),
62 _using_external_sampling_file(isParamValid(
"file")),
63 _change_position(isParamValid(
"position")),
64 _use_sampled_output(_refinements > 0 || _using_external_sampling_file ||
65 isParamValid(
"sampling_blocks") || _change_position),
66 _position(_change_position ? getParam<Point>(
"position") : Point()),
67 _sampling_mesh_changed(true),
68 _mesh_subdomains_match(true),
69 _serialize(getParam<bool>(
"serialize_sampling"))
109 TIME_SECTION(
"outputStep", 2,
"Outputting Step");
180 DistributedMesh * dist_mesh =
dynamic_cast<DistributedMesh *
>(&source_es.get_mesh());
183 for (
auto & elem : dist_mesh->active_local_element_ptr_range())
184 dist_mesh->add_extra_ghost_elem(elem);
188 const auto num_systems = source_es.
n_systems();
199 for (
const auto sys_num : make_range(num_systems))
202 const auto & source_sys = source_es.get_system(sys_num);
205 ExplicitSystem & dest_sys =
_sampling_es->add_system<ExplicitSystem>(source_sys.name());
208 const auto num_vars = source_sys.n_vars();
209 unsigned int num_actual_vars = 0;
216 for (
const auto var_num : make_range(num_vars))
219 const auto & var_name = source_sys.variable_name(var_num);
220 if (!nodal_data.count(var_name) && !elemental_data.count(var_name))
224 const std::set<SubdomainID> * subdomains;
225 std::set<SubdomainID> restricted_subdomains;
227 subdomains =
nullptr;
230 subdomains = &source_sys.variable(var_num).active_subdomains();
232 if (
isParamValid(
"sampling_blocks") && !subdomains->empty())
235 getParam<std::vector<SubdomainName>>(
"sampling_blocks"));
236 set_intersection(subdomains->begin(),
238 sampling_blocks.begin(),
239 sampling_blocks.end(),
240 std::inserter(restricted_subdomains, restricted_subdomains.begin()));
241 subdomains = &restricted_subdomains;
244 if (subdomains->empty())
257 const FEType & fe_type = source_sys.variable_type(var_num);
260 dest_sys.add_variable(source_sys.variable_name(var_num), fe_type, subdomains);
263 "Variables sampled as nodal currently require serialization with a "
264 "distributed mesh.");
268 const auto & var_name = source_sys.variable_name(var_num);
269 if (fe_type != FEType(CONSTANT, MONOMIAL))
272 "' onto a constant monomial");
275 "Projection without serialization may fail with insufficient ghosting. "
276 "Consider setting 'serialize_sampling' to true.");
278 dest_sys.add_variable(var_name, FEType(CONSTANT, MONOMIAL), subdomains);
311 const auto num_systems = source_es.
n_systems();
314 for (
const auto sys_num : make_range(num_systems))
319 System & source_sys = source_es.get_system(sys_num);
341 _mesh_functions[sys_num][var_num] = std::make_unique<libMesh::MeshFunction>(
344 source_sys.get_dof_map(),
367 const FEType & fe_type = source_sys.variable_type(original_var_num);
369 const auto * var_blocks = &source_sys.variable(original_var_num).active_subdomains();
381 if (node->n_dofs(sys_num, var_num) &&
385 DenseVector<Real> value(1);
386 if (var_blocks->size())
388 *node -
_position, 0., value, var_blocks);
392 if (value[0] != -1e6)
393 dest_sys.solution->set(node->dof_number(sys_num, var_num, 0), value[0]);
396 "Sampling at location ",
400 " was outside the problem mesh.\nThis message will not be repeated"));
409 for (
const auto & elem : elem_range)
411 if (elem->n_dofs(sys_num, var_num) &&
414 DenseVector<Real> value(1);
415 if (var_blocks->size())
417 elem->true_centroid() -
_position, 0., value, var_blocks);
421 if (value[0] != -1e6)
422 dest_sys.solution->set(elem->dof_number(sys_num, var_num, 0), value[0]);
425 "Sampling at location ",
427 " was outside the problem mesh.\nThis message will not be repeated."));
434 dest_sys.solution->close();
451 mesh_params.
set<
bool>(
"nemesis") =
false;
461 mooseWarning(
"Recovering or Restarting with oversampling may not work (especially with "
462 "adapted meshes)!! Refs #2295");
470 const auto & blocks_to_keep_names = getParam<std::vector<SubdomainName>>(
"sampling_blocks");
471 const auto & blocks_to_keep =
_sampling_mesh_ptr->getSubdomainIDs(blocks_to_keep_names);
473 if (std::find(blocks_to_keep.begin(), blocks_to_keep.end(), elem_ptr->subdomain_id()) ==
474 blocks_to_keep.end())
493 "CopyMeshPartitioner",
"sampled_output_part", partition_params);
519 const std::vector<SubdomainID> initial_mesh_subdomain_ids_vec(
526 mooseInfoRepeated(
"Variable block restriction disabled in sampled output due to non-matching "
527 "subdomain names and ids");
535 if (getParam<bool>(
"append_oversample"))
543 const auto continuity = FEInterface::get_continuity(fe_type);
544 return (continuity == C_ZERO || continuity == C_ONE);
void mooseInfoRepeated(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
const ExecFlagType EXEC_FORCED
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_NONE
const ExecFlagType EXEC_FINAL
void ErrorVector unsigned int
Based class for output objects.
virtual void output()
A single call to this function should output all the necessary data for a single timestep.
virtual void initialSetup()
Call init() method on setup.
virtual bool shouldOutput()
Handles logic for determining if a step should be output.
const std::set< std::string > & getElementalVariableOutput()
The list of elemental nonlinear variables names that are set for output.
void hideAdditionalVariable(const std::string &category, const std::string &var_name)
Add an additional variable to the hide list.
const std::set< std::string > & getNodalVariableOutput()
The list of nodal nonlinear variables names that are set for output.
static InputParameters validParams()
virtual libMesh::EquationSystems & es() override
virtual MooseMesh & mesh() override
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
std::unique_ptr< MooseObject > createUnique(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())
std::string _file_base
The base filename from the input paramaters.
virtual void setFileBaseInternal(const std::string &file_base)
Internal function that sets the file_base.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
bool isRecovering() const
Whether or not this is a "recover" calculation.
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & type() const
Get the type of this class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Class for containing MooseEnum item information.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
void allowRecovery(bool allow)
Set whether or not this mesh is allowed to read a recovery file.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
std::vector< SubdomainName > getSubdomainNames(const std::vector< SubdomainID > &subdomain_ids) const
Get the associated subdomainNames for the subdomain ids that are passed in.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
virtual std::unique_ptr< MooseMesh > safeClone() const =0
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer.
MooseApp & _app
The MOOSE application this is associated with.
Base class for MOOSE partitioner.
bool _allow_output
Flag for disabling output.
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
ExecFlagType _current_execute_flag
Current execute on flag.
virtual bool onInterval()
Returns true if the output interval is satisfied.
libMesh::EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Real & _time
The current time for output purposes.
Real & _last_output_simulation_time
last simulation time an output has occured
MooseMesh * _mesh_ptr
A convenience pointer to the current mesh (reference or displaced depending on "use_displaced")
std::chrono::time_point< std::chrono::steady_clock > _last_output_wall_time
last wall time an output has occured
Factory & _factory
The Factory associated with the MooseApp.
bool _use_sampled_output
Flag indicating that the sampled output should be used to re-sample the underlying EquationSystem of ...
std::unique_ptr< EquationSystems > _sampling_es
Equation system holding the solution vectors for the sampled variables.
bool isSampledAtNodes(const FEType &fe_type) const
Used to decide which variable is sampled at nodes, then output as a nodal variable for (over)sampling...
virtual void outputStep(const ExecFlagType &type) override
A single call to this function should output all the necessary data for a single timestep.
void cloneMesh()
Clone mesh in preperation for re-positioning or oversampling.
bool _sampling_mesh_changed
A flag indicating that the mesh has changed and the sampled mesh needs to be re-initialized.
const bool _using_external_sampling_file
Flag indicating another file is being used for the sampling.
std::vector< std::vector< std::unique_ptr< libMesh::MeshFunction > > > _mesh_functions
A vector of pointers to the mesh functions on the sampled mesh This is only populated when the initSa...
std::unique_ptr< NumericVector< Number > > _serialized_solution
Sample solution vector.
void initSample()
Setups the output object to produce re-positioned and/or sampled results.
const unsigned int _refinements
The number of oversampling refinements.
virtual void setFileBaseInternal(const std::string &file_base) override
Appends the base class's file base string.
virtual void updateSample()
Performs the update of the solution vector for the sample/re-positioned mesh.
bool _mesh_subdomains_match
A flag tracking whether the sampling and source meshes match in terms of subdomains.
const bool _change_position
Flag for re-positioning.
virtual void initialSetup() override
Call init() method on setup.
bool _serialize
Flag indicating whether we are outputting in serial or parallel.
virtual void meshChanged() override
Called on this object when the mesh changes.
std::vector< std::vector< unsigned int > > _variable_numbers_in_system
A vector of vectors that keeps track of the variable numbers in each system for each mesh function.
std::unique_ptr< MooseMesh > _sampling_mesh_ptr
Mesh used for sampling. The Output class' _mesh_ptr will refer to this mesh if sampling is being used...
Point _position
When oversampling, the output is shift by this amount.
static InputParameters validParams()
SampledOutput(const InputParameters ¶meters)
void paramWarning(const std::string ¶m, Args... args) const
processor_id_type size() const
unsigned int n_systems() const
void uniformly_refine(unsigned int n=1)
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
virtual void partition(MeshBase &mesh, const unsigned int n)