void IterationAdaptiveDT::init() { if (isParamValid("timestep_limiting_function")) { _timestep_limiting_function = &_fe_problem.getFunction(getParam<FunctionName>("timestep_limiting_function"), isParamValid("_tid") ? getParam<THREAD_ID>("_tid") : 0); _piecewise_timestep_limiting_function = dynamic_cast<Piecewise*>(_timestep_limiting_function); if (_piecewise_timestep_limiting_function) { unsigned int time_size = _piecewise_timestep_limiting_function->functionSize(); _times.resize(time_size); for (unsigned int i = 0; i < time_size; ++i) _times[i] = _piecewise_timestep_limiting_function->domain(i); } else mooseError("timestep_limiting_function must be a Piecewise function"); } }
RenameBlockGenerator::RenameBlockGenerator(const InputParameters & parameters) : MeshGenerator(parameters), _input(getMesh("input")) { // error checking. Must have exactly one of old_block_id or old_block_name if (isParamValid("old_block_id") && isParamValid("old_block_name")) mooseError( "RenameBlockGenerator: You must supply exactly one of old_block_id or old_block_name\n"); else if (!isParamValid("old_block_id") && !isParamValid("old_block_name")) mooseError( "RenameBlockGenerator: You must supply exactly one of old_block_id or old_block_name\n"); // error checking. Must have exactly one of new_block_id or new_block_name // In principal we could have both (the old block would then be given a new ID and a new name) // but i feel that could lead to confusion for the user. If the user wants to do that they // should use two of these RenameBlock MeshModifiers. if (isParamValid("new_block_id") && isParamValid("new_block_name")) mooseError( "RenameBlockGenerator: You must supply exactly one of new_block_id or new_block_name\n"); else if (!isParamValid("new_block_id") && !isParamValid("new_block_name")) mooseError( "RenameBlockGenerator: You must supply exactly one of new_block_id or new_block_name\n"); }
// DEPRECATED CONSTRUCTOR ComputeStressBase::ComputeStressBase(const std::string & deprecated_name, InputParameters parameters) : DerivativeMaterialInterface<Material>(deprecated_name, parameters), _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : "" ), _total_strain(getMaterialPropertyByName<RankTwoTensor>(_base_name + "total_strain")), _stress(declareProperty<RankTwoTensor>(_base_name + "stress")), _elastic_strain(declareProperty<RankTwoTensor>(_base_name + "elastic_strain")), _elasticity_tensor(getMaterialPropertyByName<ElasticityTensorR4>(_base_name + "elasticity_tensor")), _extra_stress(getDefaultMaterialProperty<RankTwoTensor>(_base_name + "extra_stress")), _Jacobian_mult(declareProperty<ElasticityTensorR4>(_base_name + "Jacobian_mult")) { const std::vector<FunctionName> & fcn_names(getParam<std::vector<FunctionName> >("initial_stress")); const unsigned num = fcn_names.size(); if (!(num == 0 || num == 3*3)) mooseError("Either zero or " << 3*3 << " initial stress functions must be provided to TensorMechanicsMaterial. You supplied " << num << "\n"); _initial_stress.resize(num); for (unsigned i = 0 ; i < num ; ++i) _initial_stress[i] = &getFunctionByName(fcn_names[i]); }
XFEMMarkerUserObject::XFEMMarkerUserObject(const InputParameters & parameters) : ElementUserObject(parameters), _mesh(_subproblem.mesh()), _secondary_cracks(getParam<bool>("secondary_cracks")) { FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem); if (fe_problem == NULL) mooseError("Problem casting _subproblem to FEProblemBase in XFEMMarkerUserObject"); _xfem = MooseSharedNamespace::dynamic_pointer_cast<XFEM>(fe_problem->getXFEM()); if (_xfem == NULL) mooseError("Problem casting to XFEM in XFEMMarkerUserObject"); if (isNodal()) mooseError("XFEMMarkerUserObject can only be run on an element variable"); if (isParamValid("initiate_on_boundary")) { std::vector<BoundaryName> initiation_boundary_names = getParam<std::vector<BoundaryName> >("initiate_on_boundary"); _initiation_boundary_ids = _mesh.getBoundaryIDs(initiation_boundary_names,true); } }
void ImageFunction::vtkMagnitude() { #ifdef LIBMESH_HAVE_VTK // Do nothing if 'component' is set if (isParamValid("component")) return; // Apply the greyscale filtering _magnitude_filter = vtkSmartPointer<vtkImageMagnitude>::New(); #if VTK_MAJOR_VERSION <= 5 _magnitude_filter->SetInput(_data); #else _magnitude_filter->SetInputData(_data); #endif _magnitude_filter->Update(); _data = _magnitude_filter->GetOutput(); #endif }
testnewExampleMaterial::testnewExampleMaterial(const InputParameters & parameters) : Material(parameters), // Declare that this material is going to provide a Real // valued property named "diffusivity" that Kernels can use. _sourcet(declareProperty<Real>("sourcet")), _diffusivity(declareProperty<Real>("diffusivity")), //adding rate depedent chihat _chihat(declareProperty<Real>("chihat")), _dpl(declareProperty<RankTwoTensor>("plrate")), //############### _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), _pk2_prop_name(_base_name + "pk2"), _pk2(getMaterialProperty<RankTwoTensor>(_pk2_prop_name)), _ce(getMaterialProperty<RankTwoTensor>(_base_name + "ce")), _fp(getMaterialProperty<RankTwoTensor>(_base_name + "fp")), _fp_old(getMaterialPropertyOld<RankTwoTensor>(_base_name + "fp")), _stensor(getMaterialProperty<RankTwoTensor>("stress")), _chihatst(getParam<Real>("chihatst")) {}
void MultiAppNearestNodeTransfer::getLocalNodes(MooseMesh * mesh, std::vector<Node *> & local_nodes) { if (isParamValid("source_boundary")) { BoundaryID src_bnd_id = mesh->getBoundaryID(getParam<BoundaryName>("source_boundary")); ConstBndNodeRange & bnd_nodes = *mesh->getBoundaryNodeRange(); for (const auto & bnode : bnd_nodes) if (bnode->_bnd_id == src_bnd_id && bnode->_node->processor_id() == processor_id()) local_nodes.push_back(bnode->_node); } else { local_nodes.resize(mesh->getMesh().n_local_nodes()); unsigned int i = 0; for (auto & node : as_range(mesh->localNodesBegin(), mesh->localNodesEnd())) local_nodes[i++] = node; } }
LibmeshPartitioner::LibmeshPartitioner(const InputParameters & params) : MoosePartitioner(params), _partitioner_name(getParam<MooseEnum>("partitioner")) { switch (_partitioner_name) { case -2: // metis _partitioner = new MetisPartitioner; break; case -1: // parmetis _partitioner = new ParmetisPartitioner; break; case 0: // linear _partitioner = new LinearPartitioner; break; case 1: // centroid { if (!isParamValid("centroid_partitioner_direction")) mooseError("If using the centroid partitioner you _must_ specify centroid_partitioner_direction!"); MooseEnum direction = getParam<MooseEnum>("centroid_partitioner_direction"); if (direction == "x") _partitioner = new CentroidPartitioner(CentroidPartitioner::X); else if (direction == "y") _partitioner = new CentroidPartitioner(CentroidPartitioner::Y); else if (direction == "z") _partitioner = new CentroidPartitioner(CentroidPartitioner::Z); else if (direction == "radial") _partitioner = new CentroidPartitioner(CentroidPartitioner::RADIAL); break; } case 2: // hilbert_sfc _partitioner = new HilbertSFCPartitioner; break; case 3: // morton_sfc _partitioner = new MortonSFCPartitioner; break; } }
void CreateDisplacedProblemAction::act() { if (isParamValid("displacements")) { if (!_displaced_mesh) mooseError("displacements were set but a displaced mesh wasn't created!"); // Define the parameters InputParameters object_params = _factory.getValidParams("DisplacedProblem"); object_params.set<std::vector<std::string> >("displacements") = getParam<std::vector<std::string> >("displacements"); object_params.set<MooseMesh *>("mesh") = _displaced_mesh.get(); object_params.set<FEProblem *>("_fe_problem") = _problem.get(); // Create the object MooseSharedPointer<DisplacedProblem> disp_problem = MooseSharedNamespace::dynamic_pointer_cast<DisplacedProblem>(_factory.create("DisplacedProblem", "DisplacedProblem", object_params)); // Add the Displaced Problem to FEProblem _problem->addDisplacedProblem(disp_problem); } }
void CopyNodalVarsAction::act() { if (isParamValid("initial_from_file_var")) { SystemBase * system; if (_current_task == "check_copy_nodal_vars") _app.setFileRestart() = true; else { // Is this a NonlinearSystem variable or an AuxiliarySystem variable? if (_current_task == "copy_nodal_vars") system = &_problem->getNonlinearSystem(); else system = &_problem->getAuxiliarySystem(); system->addVariableToCopy(getShortName(), getParam<std::string>("initial_from_file_var"), getParam<int>("initial_from_file_timestep")); } } }
Action::Action(InputParameters parameters) : ConsoleStreamInterface( *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")), _pars(parameters), _registered_identifier(isParamValid("registered_identifier") ? getParam<std::string>("registered_identifier") : ""), _name(getParam<std::string>("_action_name")), _action_type(getParam<std::string>("action_type")), _app(*getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")), _factory(_app.getFactory()), _action_factory(_app.getActionFactory()), _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""), _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")), _current_task(_awh.getCurrentTaskName()), _mesh(_awh.mesh()), _displaced_mesh(_awh.displacedMesh()), _problem(_awh.problemBase()), _executioner(_app.executioner()) { }
std::unique_ptr<MeshBase> SubdomainBoundingBoxGenerator::generate() { std::unique_ptr<MeshBase> mesh = std::move(_input); // Loop over the elements for (const auto & elem : mesh->active_element_ptr_range()) { bool contains = _bounding_box.contains_point(elem->centroid()); if (contains && _location == "INSIDE") elem->subdomain_id() = _block_id; else if (!contains && _location == "OUTSIDE") elem->subdomain_id() = _block_id; } // Assign block name, if provided if (isParamValid("block_name")) mesh->subdomain_name(_block_id) = getParam<SubdomainName>("block_name"); return dynamic_pointer_cast<MeshBase>(mesh); }
DiscreteNucleationInserter::DiscreteNucleationInserter(const InputParameters & parameters) : ElementUserObject(parameters), _probability(getMaterialProperty<Real>("probability")), _hold_time(getParam<Real>("hold_time")), _changes_made(0), _global_nucleus_list(declareRestartableData("global_nucleus_list", NucleusList(0))), _local_nucleus_list(declareRestartableData("local_nucleus_list", NucleusList(0))) { setRandomResetFrequency(EXEC_TIMESTEP_END); // debugging code (this will insert the entry into every processors list, but duplicate entries in // global should be OK) // we also assume that time starts at 0! But hey, this is only for debugging anyways... if (isParamValid("test")) _insert_test = true; else _insert_test = false; // force a map rebuild after restart or recover _changes_made = _app.isRecovering() || _app.isRestarting(); }
Real GolemMaterialBase::computeQpScaling() { Real scaling_factor = 0.0; switch (_material_type) { case 1: scaling_factor += PI * _scaling_factor0 * _scaling_factor0; break; case 2: case 3: scaling_factor += _scaling_factor0; break; } if (isParamValid("function_scaling")) { scaling_factor = _function_scaling->value(_t, Point()); if (_has_scaled_properties) scaling_factor /= _scaling_uo->_s_length; } return scaling_factor; }
ComputeEigenstrainFromInitialStress::ComputeEigenstrainFromInitialStress( const InputParameters & parameters) : ComputeEigenstrainBase(parameters), _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), _elasticity_tensor(getMaterialPropertyByName<RankFourTensor>(_base_name + "elasticity_tensor")), _eigenstrain_old(getMaterialPropertyOld<RankTwoTensor>(_eigenstrain_name)) { const std::vector<FunctionName> & fcn_names( getParam<std::vector<FunctionName>>("initial_stress")); const unsigned num = fcn_names.size(); if (num != LIBMESH_DIM * LIBMESH_DIM) mooseError("ComputeEigenstrainFromInitialStress: ", LIBMESH_DIM * LIBMESH_DIM, " initial stress functions must be provided. You supplied ", num, "\n"); _initial_stress_fcn.resize(num); for (unsigned i = 0; i < num; ++i) _initial_stress_fcn[i] = &getFunctionByName(fcn_names[i]); }
FeatureFloodCountAux::FeatureFloodCountAux(const InputParameters & parameters) : AuxKernel(parameters), _flood_counter(getUserObject<FeatureFloodCount>("flood_counter")), _grain_tracker_ptr(dynamic_cast<const GrainTrackerInterface *>(&_flood_counter)), _var_idx(isParamValid("map_index") ? getParam<unsigned int>("map_index") : std::numeric_limits<unsigned int>::max()), _field_display(getParam<MooseEnum>("field_display")), _var_coloring(_field_display == "VARIABLE_COLORING"), _field_type(_field_display.getEnum<FeatureFloodCount::FieldType>()) { if (_flood_counter.isElemental() == isNodal() && (_field_display == "UNIQUE_REGION" || _field_display == "VARIABLE_COLORING" || _field_display == "GHOSTED_ENTITIES" || _field_display == "HALOS")) mooseError("UNIQUE_REGION, VARIABLE_COLORING, GHOSTED_ENTITIES and HALOS must be on variable types that match the entity mode of the FeatureFloodCounter"); if (isNodal()) { if (_field_display == "ACTIVE_BOUNDS") mooseError("ACTIVE_BOUNDS is only available for elemental aux variables"); if (_field_display == "CENTROID") mooseError("CENTROID is only available for elemental aux variables"); } }
ConstitutiveModel::ConstitutiveModel(const InputParameters & parameters) :Material(parameters), _has_temp(isCoupled("temp")), _temperature(_has_temp ? coupledValue("temp") : _zero), _temperature_old(_has_temp ? coupledValueOld("temp") : _zero), _alpha(parameters.isParamValid("thermal_expansion") ? getParam<Real>("thermal_expansion") : 0.), _alpha_function(parameters.isParamValid("thermal_expansion_function") ? &getFunction("thermal_expansion_function") : NULL), _has_stress_free_temp(isParamValid("stress_free_temperature")), _stress_free_temp(_has_stress_free_temp ? getParam<Real>("stress_free_temperature") : 0.0), _ref_temp(0.0) { if (parameters.isParamValid("thermal_expansion_function_type")) { if (!_alpha_function) mooseError("thermal_expansion_function_type can only be set when thermal_expansion_function is used"); MooseEnum tec = getParam<MooseEnum>("thermal_expansion_function_type"); if (tec == "mean") _mean_alpha_function = true; else if (tec == "instantaneous") _mean_alpha_function = false; else mooseError("Invalid option for thermal_expansion_function_type"); } else _mean_alpha_function = false; if (parameters.isParamValid("thermal_expansion_reference_temperature")) { if (!_alpha_function) mooseError("thermal_expansion_reference_temperature can only be set when thermal_expansion_function is used"); if (!_mean_alpha_function) mooseError("thermal_expansion_reference_temperature can only be set when thermal_expansion_function_type = mean"); _ref_temp = getParam<Real>("thermal_expansion_reference_temperature"); if (!_has_temp) mooseError("Cannot specify thermal_expansion_reference_temperature without coupling to temperature"); } else if (_mean_alpha_function) mooseError("Must specify thermal_expansion_reference_temperature if thermal_expansion_function_type = mean"); }
ParsedGenerateSideset::ParsedGenerateSideset(const InputParameters & parameters) : SideSetsGeneratorBase(parameters), FunctionParserUtils(parameters), _input(getMesh("input")), _function(parameters.get<std::string>("combinatorial_geometry")), _sideset_name(getParam<BoundaryName>("new_sideset_name")), _check_subdomains(isParamValid("included_subdomain_ids")), _check_normal(parameters.isParamSetByUser("normal")), _included_ids(_check_subdomains ? parameters.get<std::vector<SubdomainID>>("included_subdomain_ids") : std::vector<SubdomainID>()), _normal(getParam<Point>("normal")) { if (typeid(_input).name() == typeid(std::unique_ptr<DistributedMesh>).name()) mooseError("GenerateAllSideSetsByNormals only works with ReplicatedMesh."); // base function object _func_F = ADFunctionPtr(new ADFunction()); // set FParser internal feature flags setParserFeatureFlags(_func_F); // add the constant expressions addFParserConstants(_func_F, getParam<std::vector<std::string>>("constant_names"), getParam<std::vector<std::string>>("constant_expressions")); // parse function if (_func_F->Parse(_function, "x,y,z") >= 0) mooseError("Invalid function\n", _function, "\nin ParsedAddSideset ", name(), ".\n", _func_F->ErrorMsg()); _func_params.resize(3); }
void TensorMechanicsAxisymmetricRZAction::act() { std::vector<NonlinearVariableName> displacements = getParam<std::vector<NonlinearVariableName> > ("displacements"); std::vector<VariableName> coupled_displacements; Real dim = displacements.size(); //Error checking: Can only take two displacement variables in AxisymmetricRZ mooseAssert(dim == 2, "Expected two displacement variables but recieved " << dim); for (unsigned int i = 0; i < dim; ++i) { coupled_displacements.push_back(displacements[i]); } InputParameters params = _factory.getValidParams("StressDivergenceRZTensors"); params.set<std::vector<VariableName> >("displacements") = coupled_displacements; params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); if (isParamValid("base_name")) params.set<std::string>("base_name") = getParam<std::string>("base_name"); std::string short_name = "TensorMechanicsRZ"; for (unsigned int i = 0; i < dim; ++i) { std::stringstream name; name << short_name; name << i; params.set<unsigned int>("component") = i; params.set<NonlinearVariableName>("variable") = displacements[i]; _problem->addKernel("StressDivergenceRZTensors", name.str(), params); } }
// DEPRECATED CONSTRUCTOR MultiPhaseStressMaterial::MultiPhaseStressMaterial(const std::string & deprecated_name, InputParameters parameters) : Material(deprecated_name, parameters), _h_list(getParam<std::vector<std::string> >("h")), _n_phase(_h_list.size()), _h_eta(_n_phase), _phase_base(getParam<std::vector<std::string> >("phase_base")), _phase_stress(_n_phase), _dphase_stress_dstrain(_n_phase), _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : "" ), _stress(declareProperty<RankTwoTensor>(_base_name + "stress")), _dstress_dstrain(declareProperty<ElasticityTensorR4>(_base_name + "Jacobian_mult")) { // verify parameter length if (_n_phase != _phase_base.size()) mooseError("h and phase_base input vectors need to have teh same length in MultiPhaseStressMaterial " << deprecated_name); for (unsigned int i = 0; i < _n_phase; ++i) { _h_eta[i] = &getMaterialProperty<Real>(_h_list[i]); _phase_stress[i] = &getMaterialProperty<RankTwoTensor>(_phase_base[i] + "_stress"); _dphase_stress_dstrain[i] = &getMaterialProperty<ElasticityTensorR4>(_phase_base[i] + "_Jacobian_mult"); } }
void ImageFunction::initialSetup() { #ifdef LIBMESH_HAVE_VTK // Initialize the image data (i.e, set origin, ...) initImageData(); // Create a list of files to extract data from getFiles(); // Read the image stack if (_file_type == "png") readImages<vtkPNGReader>(); else if (_file_type == "tiff" || _file_type == "tif") readImages<vtkTIFFReader>(); else mooseError("Un-supported file type '" << _file_type << "'"); // Set the component parameter /* If the parameter is not set then vtkMagnitude() will applied */ if (isParamValid("component")) { unsigned int n = _data->GetNumberOfScalarComponents(); _component = getParam<unsigned int>("component"); if (_component >= n) mooseError("'component' parameter must be empty or have a value of 0 to " << n-1); } else _component = 0; // Apply filters, the toggling on and off of each filter is handled internally vtkMagnitude(); vtkShiftAndScale(); vtkThreshold(); vtkFlip(); #endif }
void AddVariableAction::addVariable(std::string & var_name) { std::set<SubdomainID> blocks = getSubdomainIDs(); Real scale_factor = isParamValid("scaling") ? getParam<Real>("scaling") : 1; // Scalar variable if (_scalar_var) _problem->addScalarVariable(var_name, _fe_type.order, scale_factor); // Block restricted variable else if (blocks.empty()) _problem->addVariable(var_name, _fe_type, scale_factor); // Non-block restricted variable else _problem->addVariable(var_name, _fe_type, scale_factor, &blocks); if (getParam<bool>("eigen")) { EigenSystem & esys(static_cast<EigenSystem &>(_problem->getNonlinearSystem())); esys.markEigenVariable(var_name); } }
void SubdomainBoundingBox::modify() { // Check that we have access to the mesh if (!_mesh_ptr) mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()"); // Reference the the libMesh::MeshBase MeshBase & mesh = _mesh_ptr->getMesh(); // Loop over the elements for (MeshBase::element_iterator el = mesh.active_elements_begin(); el != mesh.active_elements_end(); ++el) { bool contains = _bounding_box.contains_point((*el)->centroid()); if (contains && _location == "INSIDE") (*el)->subdomain_id() = _block_id; else if (!contains && _location == "OUTSIDE") (*el)->subdomain_id() = _block_id; } // Assign block name, if provided if (isParamValid("block_name")) _mesh_ptr->getMesh().subdomain_name(_block_id) = getParam<SubdomainName>("block_name"); }
Axisymmetric2D3DSolutionFunction::Axisymmetric2D3DSolutionFunction(const InputParameters & parameters) : Function(parameters), _solution_object_ptr(NULL), _scale_factor(getParam<Real>("scale_factor")), _add_factor(getParam<Real>("add_factor")), _2d_axis_point1(getParam<RealVectorValue>("2d_axis_point1")), _2d_axis_point2(getParam<RealVectorValue>("2d_axis_point2")), _3d_axis_point1(getParam<RealVectorValue>("3d_axis_point1")), _3d_axis_point2(getParam<RealVectorValue>("3d_axis_point2")), _has_component(isParamValid("component")), _component(_has_component?getParam<unsigned int>("component"):99999), _var_names(getParam<std::vector<std::string> >("from_variables")) { if (_has_component && _var_names.size() != 2) mooseError("Must supply names of 2 variables in 'from_variables' if 'component' is specified"); else if (!_has_component && _var_names.size() == 2) mooseError("Must supply 'component' if 2 variables specified in 'from_variables'"); else if (_var_names.size() > 2) mooseError("If 'from_variables' is specified, it must have either 1 (scalar) or 2 (vector components) variables"); Point zero; Point unit_vec_y; unit_vec_y(1) = 1; if (_2d_axis_point1 == zero && _2d_axis_point2 == unit_vec_y && _3d_axis_point1 == zero && _3d_axis_point2 == unit_vec_y) _default_axes = true; else _default_axes = false; if (_3d_axis_point1.relative_fuzzy_equals(_3d_axis_point2)) mooseError("3d_axis_point1 and 3d_axis_point2 must be different points"); if (_2d_axis_point1.relative_fuzzy_equals(_2d_axis_point2)) mooseError("2d_axis_point1 and 2d_axis_point2 must be different points"); }
FeatureFloodCount::FeatureFloodCount(const InputParameters & parameters) : GeneralPostprocessor(parameters), Coupleable(this, false), MooseVariableDependencyInterface(), ZeroInterface(parameters), _vars(getCoupledMooseVars()), _threshold(getParam<Real>("threshold")), _connecting_threshold(isParamValid("connecting_threshold") ? getParam<Real>("connecting_threshold") : getParam<Real>("threshold")), _mesh(_subproblem.mesh()), _var_number(_vars[0]->number()), _single_map_mode(getParam<bool>("use_single_map")), _condense_map_info(getParam<bool>("condense_map_info")), _global_numbering(getParam<bool>("use_global_numbering")), _var_index_mode(getParam<bool>("enable_var_coloring")), _compute_halo_maps(getParam<bool>("compute_halo_maps")), _compute_var_to_feature_map(getParam<bool>("compute_var_to_feature_map")), _use_less_than_threshold_comparison(getParam<bool>("use_less_than_threshold_comparison")), _n_vars(_vars.size()), _maps_size(_single_map_mode ? 1 : _vars.size()), _n_procs(_app.n_processors()), _entities_visited(_vars.size()), // This map is always sized to the number of variables _feature_counts_per_map(_maps_size), _feature_count(0), _partial_feature_sets(_maps_size), _feature_maps(_maps_size), _pbs(nullptr), _element_average_value(parameters.isParamValid("elem_avg_value") ? getPostprocessorValue("elem_avg_value") : _real_zero), _halo_ids(_maps_size), _is_elemental(getParam<MooseEnum>("flood_entity_type") == "ELEMENTAL"), _is_master(processor_id() == 0) { if (_var_index_mode) _var_index_maps.resize(_maps_size); addMooseVariableDependency(_vars); }
InteractionIntegral::InteractionIntegral(const std::string & name, InputParameters parameters) : ElementIntegralPostprocessor(name, parameters), _grad_of_scalar_q(coupledGradient("q")), _crack_front_definition(&getUserObject<CrackFrontDefinition>("crack_front_definition")), _has_crack_front_node_index(isParamValid("crack_front_node_index")), _crack_front_node_index(_has_crack_front_node_index ? getParam<unsigned int>("crack_front_node_index") : 0), _treat_as_2d(false), _Eshelby_tensor(getMaterialProperty<ColumnMajorMatrix>("Eshelby_tensor")), _stress(getMaterialProperty<SymmTensor>("stress")), _strain(getMaterialProperty<SymmTensor>("elastic_strain")), _grad_disp_x(coupledGradient("disp_x")), _grad_disp_y(coupledGradient("disp_y")), _grad_disp_z(parameters.get<SubProblem *>("_subproblem")->mesh().dimension() == 3 ? coupledGradient("disp_z") : _grad_zero), _aux_stress_name(getParam<std::string>("aux_stress")), _aux_stress(getMaterialProperty<ColumnMajorMatrix>(_aux_stress_name)), _aux_disp_name(getParam<std::string>("aux_disp")), _aux_disp(getMaterialProperty<ColumnMajorMatrix>(_aux_disp_name)), _aux_grad_disp_name(getParam<std::string>("aux_grad_disp")), _aux_grad_disp(getMaterialProperty<ColumnMajorMatrix>(_aux_grad_disp_name)), _aux_strain_name(getParam<std::string>("aux_strain")), _aux_strain(getMaterialProperty<ColumnMajorMatrix>(_aux_strain_name)), _K_factor(getParam<Real>("K_factor")) { }
void MultiAppNearestNodeTransfer::getLocalNodes(MooseMesh * mesh, std::vector<Node *> & local_nodes) { if (isParamValid("source_boundary")) { BoundaryID src_bnd_id = mesh->getBoundaryID(getParam<BoundaryName>("source_boundary")); ConstBndNodeRange & bnd_nodes = *mesh->getBoundaryNodeRange(); for (const auto & bnode : bnd_nodes) if (bnode->_bnd_id == src_bnd_id && bnode->_node->processor_id() == processor_id()) local_nodes.push_back(bnode->_node); } else { local_nodes.resize(mesh->getMesh().n_local_nodes()); MeshBase::const_node_iterator nodes_begin = mesh->localNodesBegin(); MeshBase::const_node_iterator nodes_end = mesh->localNodesEnd(); unsigned int i = 0; for (MeshBase::const_node_iterator node_it = nodes_begin; node_it != nodes_end; ++node_it, ++i) local_nodes[i] = *node_it; } }
AnisoHeatConductionMaterial::AnisoHeatConductionMaterial(const InputParameters & parameters) : Material(parameters), _has_temp(isCoupled("temp")), _temperature(_has_temp ? coupledValue("temp") : _zero), _my_thermal_conductivity_x( isParamValid("thermal_conductivity_x") ? getParam<Real>("thermal_conductivity_x") : -1), _my_thermal_conductivity_y( isParamValid("thermal_conductivity_y") ? getParam<Real>("thermal_conductivity_y") : -1), _my_thermal_conductivity_z( isParamValid("thermal_conductivity_z") ? getParam<Real>("thermal_conductivity_z") : -1), _thermal_conductivity_x_pp(isParamValid("thermal_conductivity_x_pp") ? &getPostprocessorValue("thermal_conductivity_x_pp") : NULL), _thermal_conductivity_y_pp(isParamValid("thermal_conductivity_y_pp") ? &getPostprocessorValue("thermal_conductivity_y_pp") : NULL), _thermal_conductivity_z_pp(isParamValid("thermal_conductivity_z_pp") ? &getPostprocessorValue("thermal_conductivity_z_pp") : NULL), _my_specific_heat(isParamValid("specific_heat") ? getParam<Real>("specific_heat") : 0), _thermal_conductivity_x(&declareProperty<Real>("thermal_conductivity_x")), _thermal_conductivity_x_dT(&declareProperty<Real>("thermal_conductivity_x_dT")), _thermal_conductivity_y(isParamValid("thermal_conductivity_y") || isParamValid("thermal_conductivity_y_pp") ? &declareProperty<Real>("thermal_conductivity_y") : NULL), _thermal_conductivity_y_dT( _thermal_conductivity_y ? &declareProperty<Real>("thermal_conductivity_y_dT") : NULL), _thermal_conductivity_z(isParamValid("thermal_conductivity_z") || isParamValid("thermal_conductivity_z_pp") ? &declareProperty<Real>("thermal_conductivity_z") : NULL), _thermal_conductivity_z_dT( _thermal_conductivity_z ? &declareProperty<Real>("thermal_conductivity_z_dT") : NULL), _specific_heat(declareProperty<Real>("specific_heat")), _specific_heat_temperature_function( getParam<FunctionName>("specific_heat_temperature_function") != "" ? &getFunction("specific_heat_temperature_function") : NULL) { bool k_x = isParamValid("thermal_conductivity_x") || (NULL != _thermal_conductivity_x_pp); bool k_y = isParamValid("thermal_conductivity_y") || (NULL != _thermal_conductivity_y_pp); bool k_z = isParamValid("thermal_conductivity_z") || (NULL != _thermal_conductivity_z_pp); if (!k_x || (_subproblem.mesh().dimension() > 1 && !k_y) || (_subproblem.mesh().dimension() > 2 && !k_z)) { mooseError("Incomplete set of orthotropic thermal conductivity parameters"); } if (_specific_heat_temperature_function && !_has_temp) { mooseError("Must couple with temperature if using specific heat function"); } if (isParamValid("specific_heat") && _specific_heat_temperature_function) { mooseError("Cannot define both specific heat and specific heat temperature function"); } k_x = isParamValid("thermal_conductivity_x") && (NULL != _thermal_conductivity_x_pp); k_y = isParamValid("thermal_conductivity_y") && (NULL != _thermal_conductivity_y_pp); k_z = isParamValid("thermal_conductivity_z") && (NULL != _thermal_conductivity_z_pp); if (k_x || k_y || k_z) { mooseError("Cannot define thermal conductivity value and Postprocessor"); } }
void MultiAppNearestNodeTransfer::execute() { _console << "Beginning NearestNodeTransfer " << name() << std::endl; getAppInfo(); // Get the bounding boxes for the "from" domains. std::vector<BoundingBox> bboxes = getFromBoundingBoxes(); // Figure out how many "from" domains each processor owns. std::vector<unsigned int> froms_per_proc = getFromsPerProc(); //////////////////// // For every point in the local "to" domain, figure out which "from" domains // might contain it's nearest neighbor, and send that point to the processors // that own those "from" domains. // // How do we know which "from" domains might contain the nearest neighbor, you // ask? Well, consider two "from" domains, A and B. If every point in A is // closer than every point in B, then we know that B cannot possibly contain // the nearest neighbor. Hence, we'll only check A for the nearest neighbor. // We'll use the functions bboxMaxDistance and bboxMinDistance to figure out // if every point in A is closer than every point in B. //////////////////// // outgoing_qps = nodes/centroids we'll send to other processors. std::vector<std::vector<Point>> outgoing_qps(n_processors()); // When we get results back, node_index_map will tell us which results go with // which points std::vector<std::map<std::pair<unsigned int, unsigned int>, unsigned int>> node_index_map( n_processors()); if (!_neighbors_cached) { for (unsigned int i_to = 0; i_to < _to_problems.size(); i_to++) { System * to_sys = find_sys(*_to_es[i_to], _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); MeshBase * to_mesh = &_to_meshes[i_to]->getMesh(); bool is_nodal = to_sys->variable_type(var_num).family == LAGRANGE; if (is_nodal) { std::vector<Node *> target_local_nodes; if (isParamValid("target_boundary")) { BoundaryID target_bnd_id = _to_meshes[i_to]->getBoundaryID(getParam<BoundaryName>("target_boundary")); ConstBndNodeRange & bnd_nodes = *(_to_meshes[i_to])->getBoundaryNodeRange(); for (const auto & bnode : bnd_nodes) if (bnode->_bnd_id == target_bnd_id && bnode->_node->processor_id() == processor_id()) target_local_nodes.push_back(bnode->_node); } else { target_local_nodes.resize(to_mesh->n_local_nodes()); unsigned int i = 0; for (auto & node : to_mesh->local_node_ptr_range()) target_local_nodes[i++] = node; } for (const auto & node : target_local_nodes) { // Skip this node if the variable has no dofs at it. if (node->n_dofs(sys_num, var_num) < 1) continue; // Find which bboxes might have the nearest node to this point. Real nearest_max_distance = std::numeric_limits<Real>::max(); for (const auto & bbox : bboxes) { Real distance = bboxMaxDistance(*node, bbox); if (distance < nearest_max_distance) nearest_max_distance = distance; } unsigned int from0 = 0; for (processor_id_type i_proc = 0; i_proc < n_processors(); from0 += froms_per_proc[i_proc], i_proc++) { bool qp_found = false; for (unsigned int i_from = from0; i_from < from0 + froms_per_proc[i_proc] && !qp_found; i_from++) { Real distance = bboxMinDistance(*node, bboxes[i_from]); if (distance < nearest_max_distance || bboxes[i_from].contains_point(*node)) { std::pair<unsigned int, unsigned int> key(i_to, node->id()); node_index_map[i_proc][key] = outgoing_qps[i_proc].size(); outgoing_qps[i_proc].push_back(*node + _to_positions[i_to]); qp_found = true; } } } } } else // Elemental { for (auto & elem : as_range(to_mesh->local_elements_begin(), to_mesh->local_elements_end())) { Point centroid = elem->centroid(); // Skip this element if the variable has no dofs at it. if (elem->n_dofs(sys_num, var_num) < 1) continue; // Find which bboxes might have the nearest node to this point. Real nearest_max_distance = std::numeric_limits<Real>::max(); for (const auto & bbox : bboxes) { Real distance = bboxMaxDistance(centroid, bbox); if (distance < nearest_max_distance) nearest_max_distance = distance; } unsigned int from0 = 0; for (processor_id_type i_proc = 0; i_proc < n_processors(); from0 += froms_per_proc[i_proc], i_proc++) { bool qp_found = false; for (unsigned int i_from = from0; i_from < from0 + froms_per_proc[i_proc] && !qp_found; i_from++) { Real distance = bboxMinDistance(centroid, bboxes[i_from]); if (distance < nearest_max_distance || bboxes[i_from].contains_point(centroid)) { std::pair<unsigned int, unsigned int> key(i_to, elem->id()); node_index_map[i_proc][key] = outgoing_qps[i_proc].size(); outgoing_qps[i_proc].push_back(centroid + _to_positions[i_to]); qp_found = true; } } } } } } } //////////////////// // Send local node/centroid positions off to the other processors and take // care of points sent to this processor. We'll need to check the points // against all of the "from" domains that this processor owns. For each // point, we'll find the nearest node, then we'll send the value at that node // and the distance between the node and the point back to the processor that // requested that point. //////////////////// std::vector<std::vector<Real>> incoming_evals(n_processors()); std::vector<Parallel::Request> send_qps(n_processors()); std::vector<Parallel::Request> send_evals(n_processors()); // Create these here so that they live the entire life of this function // and are NOT reused per processor. std::vector<std::vector<Real>> processor_outgoing_evals(n_processors()); if (!_neighbors_cached) { for (processor_id_type i_proc = 0; i_proc < n_processors(); i_proc++) { if (i_proc == processor_id()) continue; _communicator.send(i_proc, outgoing_qps[i_proc], send_qps[i_proc]); } // Build an array of pointers to all of this processor's local nodes. We // need to do this to avoid the expense of using LibMesh iterators. This // step also takes care of limiting the search to boundary nodes, if // applicable. std::vector<std::vector<Node *>> local_nodes(froms_per_proc[processor_id()]); for (unsigned int i = 0; i < froms_per_proc[processor_id()]; i++) { getLocalNodes(_from_meshes[i], local_nodes[i]); } if (_fixed_meshes) { _cached_froms.resize(n_processors()); _cached_dof_ids.resize(n_processors()); } for (processor_id_type i_proc = 0; i_proc < n_processors(); i_proc++) { std::vector<Point> incoming_qps; if (i_proc == processor_id()) incoming_qps = outgoing_qps[i_proc]; else _communicator.receive(i_proc, incoming_qps); if (_fixed_meshes) { _cached_froms[i_proc].resize(incoming_qps.size()); _cached_dof_ids[i_proc].resize(incoming_qps.size()); } std::vector<Real> & outgoing_evals = processor_outgoing_evals[i_proc]; outgoing_evals.resize(2 * incoming_qps.size()); for (unsigned int qp = 0; qp < incoming_qps.size(); qp++) { Point qpt = incoming_qps[qp]; outgoing_evals[2 * qp] = std::numeric_limits<Real>::max(); for (unsigned int i_local_from = 0; i_local_from < froms_per_proc[processor_id()]; i_local_from++) { MooseVariableFEBase & from_var = _from_problems[i_local_from]->getVariable(0, _from_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); System & from_sys = from_var.sys().system(); unsigned int from_sys_num = from_sys.number(); unsigned int from_var_num = from_sys.variable_number(from_var.name()); for (unsigned int i_node = 0; i_node < local_nodes[i_local_from].size(); i_node++) { Real current_distance = (qpt - *(local_nodes[i_local_from][i_node]) - _from_positions[i_local_from]).norm(); if (current_distance < outgoing_evals[2 * qp]) { // Assuming LAGRANGE! if (local_nodes[i_local_from][i_node]->n_dofs(from_sys_num, from_var_num) > 0) { dof_id_type from_dof = local_nodes[i_local_from][i_node]->dof_number(from_sys_num, from_var_num, 0); outgoing_evals[2 * qp] = current_distance; outgoing_evals[2 * qp + 1] = (*from_sys.solution)(from_dof); if (_fixed_meshes) { // Cache the nearest nodes. _cached_froms[i_proc][qp] = i_local_from; _cached_dof_ids[i_proc][qp] = from_dof; } } } } } } if (i_proc == processor_id()) incoming_evals[i_proc] = outgoing_evals; else _communicator.send(i_proc, outgoing_evals, send_evals[i_proc]); } } else // We've cached the nearest nodes. { for (processor_id_type i_proc = 0; i_proc < n_processors(); i_proc++) { std::vector<Real> & outgoing_evals = processor_outgoing_evals[i_proc]; outgoing_evals.resize(_cached_froms[i_proc].size()); for (unsigned int qp = 0; qp < outgoing_evals.size(); qp++) { MooseVariableFEBase & from_var = _from_problems[_cached_froms[i_proc][qp]]->getVariable( 0, _from_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); System & from_sys = from_var.sys().system(); dof_id_type from_dof = _cached_dof_ids[i_proc][qp]; // outgoing_evals[qp] = (*from_sys.solution)(_cached_dof_ids[i_proc][qp]); outgoing_evals[qp] = (*from_sys.solution)(from_dof); } if (i_proc == processor_id()) incoming_evals[i_proc] = outgoing_evals; else _communicator.send(i_proc, outgoing_evals, send_evals[i_proc]); } } //////////////////// // Gather all of the evaluations, find the nearest one for each node/element, // and apply the values. //////////////////// for (processor_id_type i_proc = 0; i_proc < n_processors(); i_proc++) { if (i_proc == processor_id()) continue; _communicator.receive(i_proc, incoming_evals[i_proc]); } for (unsigned int i_to = 0; i_to < _to_problems.size(); i_to++) { // Loop over the master nodes and set the value of the variable System * to_sys = find_sys(*_to_es[i_to], _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); NumericVector<Real> * solution = nullptr; switch (_direction) { case TO_MULTIAPP: solution = &getTransferVector(i_to, _to_var_name); break; case FROM_MULTIAPP: solution = to_sys->solution.get(); break; default: mooseError("Unknown direction"); } MeshBase * to_mesh = &_to_meshes[i_to]->getMesh(); bool is_nodal = to_sys->variable_type(var_num).family == LAGRANGE; if (is_nodal) { std::vector<Node *> target_local_nodes; if (isParamValid("target_boundary")) { BoundaryID target_bnd_id = _to_meshes[i_to]->getBoundaryID(getParam<BoundaryName>("target_boundary")); ConstBndNodeRange & bnd_nodes = *(_to_meshes[i_to])->getBoundaryNodeRange(); for (const auto & bnode : bnd_nodes) if (bnode->_bnd_id == target_bnd_id && bnode->_node->processor_id() == processor_id()) target_local_nodes.push_back(bnode->_node); } else { target_local_nodes.resize(to_mesh->n_local_nodes()); unsigned int i = 0; for (auto & node : to_mesh->local_node_ptr_range()) target_local_nodes[i++] = node; } for (const auto & node : target_local_nodes) { // Skip this node if the variable has no dofs at it. if (node->n_dofs(sys_num, var_num) < 1) continue; Real best_val = 0; if (!_neighbors_cached) { Real min_dist = std::numeric_limits<Real>::max(); for (unsigned int i_from = 0; i_from < incoming_evals.size(); i_from++) { std::pair<unsigned int, unsigned int> key(i_to, node->id()); if (node_index_map[i_from].find(key) == node_index_map[i_from].end()) continue; unsigned int qp_ind = node_index_map[i_from][key]; if (incoming_evals[i_from][2 * qp_ind] >= min_dist) continue; min_dist = incoming_evals[i_from][2 * qp_ind]; best_val = incoming_evals[i_from][2 * qp_ind + 1]; if (_fixed_meshes) { // Cache these indices. _cached_from_inds[node->id()] = i_from; _cached_qp_inds[node->id()] = qp_ind; } } } else { best_val = incoming_evals[_cached_from_inds[node->id()]][_cached_qp_inds[node->id()]]; } dof_id_type dof = node->dof_number(sys_num, var_num, 0); solution->set(dof, best_val); } } else // Elemental { for (auto & elem : as_range(to_mesh->local_elements_begin(), to_mesh->local_elements_end())) { // Skip this element if the variable has no dofs at it. if (elem->n_dofs(sys_num, var_num) < 1) continue; Real best_val = 0; if (!_neighbors_cached) { Real min_dist = std::numeric_limits<Real>::max(); for (unsigned int i_from = 0; i_from < incoming_evals.size(); i_from++) { std::pair<unsigned int, unsigned int> key(i_to, elem->id()); if (node_index_map[i_from].find(key) == node_index_map[i_from].end()) continue; unsigned int qp_ind = node_index_map[i_from][key]; if (incoming_evals[i_from][2 * qp_ind] >= min_dist) continue; min_dist = incoming_evals[i_from][2 * qp_ind]; best_val = incoming_evals[i_from][2 * qp_ind + 1]; if (_fixed_meshes) { // Cache these indices. _cached_from_inds[elem->id()] = i_from; _cached_qp_inds[elem->id()] = qp_ind; } } } else { best_val = incoming_evals[_cached_from_inds[elem->id()]][_cached_qp_inds[elem->id()]]; } dof_id_type dof = elem->dof_number(sys_num, var_num, 0); solution->set(dof, best_val); } } solution->close(); to_sys->update(); } if (_fixed_meshes) _neighbors_cached = true; // Make sure all our sends succeeded. for (processor_id_type i_proc = 0; i_proc < n_processors(); i_proc++) { if (i_proc == processor_id()) continue; send_qps[i_proc].wait(); send_evals[i_proc].wait(); } _console << "Finished NearestNodeTransfer " << name() << std::endl; }
MaterialStdVectorAux::MaterialStdVectorAux(const InputParameters & parameters) : MaterialStdVectorAuxBase<Real>(parameters), _has_selected_qp(isParamValid("selected_qp")), _selected_qp(_has_selected_qp ? getParam<unsigned int>("selected_qp") : 0) { }