本文整理汇总了C++中meshlib::Mesh::getProperties方法的典型用法代码示例。如果您正苦于以下问题:C++ Mesh::getProperties方法的具体用法?C++ Mesh::getProperties怎么用?C++ Mesh::getProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meshlib::Mesh
的用法示例。
在下文中一共展示了Mesh::getProperties方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setByElementType
std::size_t ElementValueModification::setByElementType(MeshLib::Mesh &mesh, MeshElemType ele_type, int const new_value)
{
auto* const property_value_vector =
mesh.getProperties().getPropertyVector<int>("MaterialIDs");
if (!property_value_vector)
{
return 0;
}
std::vector<MeshLib::Element*> const& elements(mesh.getElements());
std::size_t cnt(0);
for (std::size_t k(0); k<elements.size(); k++) {
if (elements[k]->getGeomType()!=ele_type)
continue;
(*property_value_vector)[k] = new_value;
cnt++;
}
return cnt;
}
示例2: replace
bool ElementValueModification::replace(MeshLib::Mesh &mesh,
std::string const& property_name, int const old_value, int const new_value,
bool replace_if_exists)
{
auto* const property_value_vec =
mesh.getProperties().getPropertyVector<int>(property_name);
if (!property_value_vec)
{
return false;
}
const std::size_t n_property_tuples(
property_value_vec->getNumberOfTuples());
if (!replace_if_exists)
{
for (std::size_t i = 0; i < n_property_tuples; ++i)
{
if ((*property_value_vec)[i] == new_value)
{
WARN(
"ElementValueModification::replaceElementValue() "
"- Replacement value \"%d\" is already taken, "
"no changes have been made.",
new_value);
return false;
}
}
}
for (std::size_t i = 0; i < n_property_tuples; ++i)
{
if ((*property_value_vec)[i] == old_value)
(*property_value_vec)[i] = new_value;
}
return true;
}
示例3: setMesh
void ElementTreeModel::setMesh(MeshLib::Mesh const& mesh)
{
this->clearView();
QList<QVariant> mesh_name;
mesh_name << "Name:" << QString::fromStdString(mesh.getName()) << "" << "" << "";
TreeItem* name_item = new TreeItem(mesh_name, _rootItem);
_rootItem->appendChild(name_item);
QList<QVariant> nodes_number;
nodes_number << "#Nodes: " << QString::number(mesh.getNumberOfNodes()) << "" << "";
TreeItem* nodes_item = new TreeItem(nodes_number, _rootItem);
_rootItem->appendChild(nodes_item);
QList<QVariant> elements_number;
elements_number << "#Elements: " << QString::number(mesh.getNumberOfElements()) << "" << "";
TreeItem* elements_item = new TreeItem(elements_number, _rootItem);
_rootItem->appendChild(elements_item);
const std::array<QString, 7> n_element_names = {{ "Lines:", "Triangles:", "Quads:", "Tetrahedra:", "Hexahedra:", "Pyramids:", "Prisms:" }};
const std::array<unsigned, 7>& n_element_types (MeshLib::MeshInformation::getNumberOfElementTypes(mesh));
for (std::size_t i=0; i<n_element_types.size(); ++i)
{
if (n_element_types[i])
{
QList<QVariant> elements_number;
elements_number << n_element_names[i] << QString::number(n_element_types[i]) << "" << "";
TreeItem* type_item = new TreeItem(elements_number, elements_item);
elements_item->appendChild(type_item);
}
}
QList<QVariant> bounding_box;
bounding_box << "Bounding Box" << "" << "" << "";
TreeItem* aabb_item = new TreeItem(bounding_box, _rootItem);
_rootItem->appendChild(aabb_item);
const GeoLib::AABB aabb (MeshLib::MeshInformation::getBoundingBox(mesh));
auto const& min = aabb.getMinPoint();
auto const& max = aabb.getMaxPoint();
QList<QVariant> min_aabb;
min_aabb << "Min:" << QString::number(min[0], 'f') << QString::number(min[1], 'f') << QString::number(min[2], 'f');
TreeItem* min_item = new TreeItem(min_aabb, aabb_item);
aabb_item->appendChild(min_item);
QList<QVariant> max_aabb;
max_aabb << "Max:" << QString::number(max[0], 'f') << QString::number(max[1], 'f') << QString::number(max[2], 'f');
TreeItem* max_item = new TreeItem(max_aabb, aabb_item);
aabb_item->appendChild(max_item);
QList<QVariant> edges;
edges << "Edge Length: " << "[" + QString::number(mesh.getMinEdgeLength(), 'f') + "," << QString::number(mesh.getMaxEdgeLength(), 'f') + "]" << "";
TreeItem* edge_item = new TreeItem(edges, _rootItem);
_rootItem->appendChild(edge_item);
std::vector<std::string> const& vec_names (mesh.getProperties().getPropertyVectorNames());
for (std::size_t i=0; i<vec_names.size(); ++i)
{
QList<QVariant> array_info;
array_info << QString::fromStdString(vec_names[i]) + ": ";
auto vec_bounds (MeshLib::MeshInformation::getValueBounds<int>(mesh, vec_names[i]));
if (vec_bounds.second != std::numeric_limits<int>::max())
array_info << "[" + QString::number(vec_bounds.first) + "," << QString::number(vec_bounds.second) + "]" << "";
else
{
auto vec_bounds (MeshLib::MeshInformation::getValueBounds<double>(mesh, vec_names[i]));
if (vec_bounds.second != std::numeric_limits<double>::max())
array_info << "[" + QString::number(vec_bounds.first) + "," << QString::number(vec_bounds.second) + "]" << "";
}
if (array_info.size() == 1)
array_info << "[ ?" << "? ]" << "";
TreeItem* vec_item = new TreeItem(array_info, _rootItem);
_rootItem->appendChild(vec_item);
}
reset();
}
示例4: if
std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh, std::string const& new_mesh_name)
{
std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(MeshLib::getBaseNodes(org_mesh.getElements()));
// create new elements with the quadratic nodes
std::vector<MeshLib::Element*> vec_new_eles;
for (MeshLib::Element const* e : org_mesh.getElements())
{
if (e->getCellType() == MeshLib::CellType::LINE3)
{
vec_new_eles.push_back(createLinearElement<MeshLib::Line>(
e, vec_new_nodes));
}
else if (e->getCellType() == MeshLib::CellType::QUAD8)
{
vec_new_eles.push_back(createLinearElement<MeshLib::Quad>(
e, vec_new_nodes));
}
else if (e->getCellType() == MeshLib::CellType::TRI6)
{
vec_new_eles.push_back(createLinearElement<MeshLib::Tri>(
e, vec_new_nodes));
}
else if (e->getCellType() == MeshLib::CellType::HEX20)
{
vec_new_eles.push_back(createLinearElement<MeshLib::Hex>(
e, vec_new_nodes));
}
else if (e->getCellType() == MeshLib::CellType::TET10)
{
vec_new_eles.push_back(createLinearElement<MeshLib::Tet>(
e, vec_new_nodes));
}
else
{
OGS_FATAL("Mesh element type %s is not supported", MeshLib::CellType2String(e->getCellType()).c_str());
}
}
auto new_mesh = std::make_unique<MeshLib::Mesh>(
new_mesh_name, vec_new_nodes, vec_new_eles,
org_mesh.getProperties().excludeCopyProperties(
std::vector<MeshLib::MeshItemType>(1,
MeshLib::MeshItemType::Node)));
// copy property vectors for nodes
MeshLib::Properties const& src_properties = org_mesh.getProperties();
for (auto name : src_properties.getPropertyVectorNames())
{
if (!src_properties.existsPropertyVector<double>(name))
{
continue;
}
auto const* src_prop = src_properties.getPropertyVector<double>(name);
if (src_prop->getMeshItemType() != MeshLib::MeshItemType::Node)
{
continue;
}
auto const n_src_comp = src_prop->getNumberOfComponents();
auto new_prop =
new_mesh->getProperties().createNewPropertyVector<double>(
name, MeshLib::MeshItemType::Node, n_src_comp);
new_prop->resize(new_mesh->getNumberOfNodes() * n_src_comp);
// copy only base node values
for (unsigned i=0; i<org_mesh.getNumberOfBaseNodes(); i++)
{
for (int j = 0; j < n_src_comp; j++)
{
(*new_prop)[i * n_src_comp + j] =
(*src_prop)[i * n_src_comp + j];
}
}
}
return new_mesh;
}
示例5: max_matID
std::unique_ptr<MeshLib::Mesh> appendLinesAlongPolylines(
const MeshLib::Mesh& mesh, const GeoLib::PolylineVec& ply_vec)
{
// copy existing nodes and elements
std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(mesh.getNodes());
std::vector<MeshLib::Element*> vec_new_eles = MeshLib::copyElementVector(mesh.getElements(), vec_new_nodes);
std::vector<int> new_mat_ids;
{
if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) {
auto ids =
mesh.getProperties().getPropertyVector<int>("MaterialIDs");
new_mat_ids.reserve(ids->size());
std::copy(ids->cbegin(), ids->cend(),
std::back_inserter(new_mat_ids));
}
}
int max_matID(0);
if (!new_mat_ids.empty())
max_matID = *(std::max_element(new_mat_ids.cbegin(), new_mat_ids.cend()));
const std::size_t n_ply (ply_vec.size());
// for each polyline
for (std::size_t k(0); k < n_ply; k++)
{
const GeoLib::Polyline* ply = (*ply_vec.getVector())[k];
// search nodes on the polyline
MeshGeoToolsLib::MeshNodesAlongPolyline mshNodesAlongPoly(
mesh, *ply, mesh.getMinEdgeLength() * 0.5,
MeshGeoToolsLib::SearchAllNodes::Yes);
auto &vec_nodes_on_ply = mshNodesAlongPoly.getNodeIDs();
if (vec_nodes_on_ply.empty()) {
std::string ply_name;
ply_vec.getNameOfElementByID(k, ply_name);
INFO("No nodes found on polyline %s", ply_name.c_str());
continue;
}
// add line elements
for (std::size_t i=0; i<vec_nodes_on_ply.size()-1; i++) {
std::array<MeshLib::Node*, 2> element_nodes;
element_nodes[0] = vec_new_nodes[vec_nodes_on_ply[i]];
element_nodes[1] = vec_new_nodes[vec_nodes_on_ply[i+1]];
vec_new_eles.push_back(
new MeshLib::Line(element_nodes, vec_new_eles.size()));
new_mat_ids.push_back(max_matID+k+1);
}
}
// generate a mesh
const std::string name = mesh.getName() + "_with_lines";
auto new_mesh =
std::make_unique<MeshLib::Mesh>(name, vec_new_nodes, vec_new_eles);
auto opt_mat_pv = new_mesh->getProperties().createNewPropertyVector<int>(
"MaterialIDs", MeshLib::MeshItemType::Cell);
if (opt_mat_pv) {
auto & mat_pv = *opt_mat_pv;
mat_pv.reserve(new_mat_ids.size());
std::copy(new_mat_ids.cbegin(), new_mat_ids.cend(),
std::back_inserter(mat_pv));
}
return new_mesh;
}
示例6: LocalToGlobalIndexMap
void ThermoMechanicsProcess<DisplacementDim>::initializeConcreteProcess(
NumLib::LocalToGlobalIndexMap const& dof_table,
MeshLib::Mesh const& mesh,
unsigned const integration_order)
{
ProcessLib::SmallDeformation::createLocalAssemblers<
DisplacementDim, ThermoMechanicsLocalAssembler>(
mesh.getElements(), dof_table, _local_assemblers,
mesh.isAxiallySymmetric(), integration_order, _process_data);
// TODO move the two data members somewhere else.
// for extrapolation of secondary variables
std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
*_mesh_subset_all_nodes};
_local_to_global_index_map_single_component.reset(
new NumLib::LocalToGlobalIndexMap(
std::move(all_mesh_subsets_single_component),
// by location order is needed for output
NumLib::ComponentOrder::BY_LOCATION));
_secondary_variables.addSecondaryVariable(
"sigma",
makeExtrapolator(
MathLib::KelvinVector::KelvinVectorType<
DisplacementDim>::RowsAtCompileTime,
getExtrapolator(), _local_assemblers,
&ThermoMechanicsLocalAssemblerInterface::getIntPtSigma));
_secondary_variables.addSecondaryVariable(
"epsilon",
makeExtrapolator(
MathLib::KelvinVector::KelvinVectorType<
DisplacementDim>::RowsAtCompileTime,
getExtrapolator(), _local_assemblers,
&ThermoMechanicsLocalAssemblerInterface::getIntPtEpsilon));
// Set initial conditions for integration point data.
for (auto const& ip_writer : _integration_point_writer)
{
// Find the mesh property with integration point writer's name.
auto const& name = ip_writer->name();
if (!mesh.getProperties().existsPropertyVector<double>(name))
{
continue;
}
auto const& mesh_property =
*mesh.getProperties().template getPropertyVector<double>(name);
// The mesh property must be defined on integration points.
if (mesh_property.getMeshItemType() !=
MeshLib::MeshItemType::IntegrationPoint)
{
continue;
}
auto const ip_meta_data = getIntegrationPointMetaData(mesh, name);
// Check the number of components.
if (ip_meta_data.n_components != mesh_property.getNumberOfComponents())
{
OGS_FATAL(
"Different number of components in meta data (%d) than in "
"the integration point field data for '%s': %d.",
ip_meta_data.n_components, name.c_str(),
mesh_property.getNumberOfComponents());
}
// Now we have a properly named vtk's field data array and the
// corresponding meta data.
std::size_t position = 0;
for (auto& local_asm : _local_assemblers)
{
std::size_t const integration_points_read =
local_asm->setIPDataInitialConditions(
name, &mesh_property[position],
ip_meta_data.integration_order);
if (integration_points_read == 0)
{
OGS_FATAL(
"No integration points read in the integration point "
"initial conditions set function.");
}
position += integration_points_read * ip_meta_data.n_components;
}
}
}
示例7: if
void SmallDeformationNonlocalProcess<DisplacementDim>::
initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const& dof_table,
MeshLib::Mesh const& mesh,
unsigned const integration_order)
{
// Reusing local assembler creation code.
ProcessLib::SmallDeformation::createLocalAssemblers<
DisplacementDim, SmallDeformationNonlocalLocalAssembler>(
mesh.getElements(), dof_table, _local_assemblers,
mesh.isAxiallySymmetric(), integration_order, _process_data);
// TODO move the two data members somewhere else.
// for extrapolation of secondary variables
std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
*_mesh_subset_all_nodes};
_local_to_global_index_map_single_component =
std::make_unique<NumLib::LocalToGlobalIndexMap>(
std::move(all_mesh_subsets_single_component),
// by location order is needed for output
NumLib::ComponentOrder::BY_LOCATION);
Process::_secondary_variables.addSecondaryVariable(
"sigma",
makeExtrapolator(MathLib::KelvinVector::KelvinVectorType<
DisplacementDim>::RowsAtCompileTime,
getExtrapolator(), _local_assemblers,
&LocalAssemblerInterface::getIntPtSigma));
Process::_secondary_variables.addSecondaryVariable(
"epsilon",
makeExtrapolator(MathLib::KelvinVector::KelvinVectorType<
DisplacementDim>::RowsAtCompileTime,
getExtrapolator(), _local_assemblers,
&LocalAssemblerInterface::getIntPtEpsilon));
Process::_secondary_variables.addSecondaryVariable(
"eps_p_V",
makeExtrapolator(1, getExtrapolator(), _local_assemblers,
&LocalAssemblerInterface::getIntPtEpsPV));
Process::_secondary_variables.addSecondaryVariable(
"eps_p_D_xx",
makeExtrapolator(1, getExtrapolator(), _local_assemblers,
&LocalAssemblerInterface::getIntPtEpsPDXX));
Process::_secondary_variables.addSecondaryVariable(
"damage",
makeExtrapolator(1, getExtrapolator(), _local_assemblers,
&LocalAssemblerInterface::getIntPtDamage));
GlobalExecutor::executeMemberOnDereferenced(
&LocalAssemblerInterface::nonlocal, _local_assemblers,
_local_assemblers);
// Set initial conditions for integration point data.
for (auto const& ip_writer : _integration_point_writer)
{
auto const& name = ip_writer->name();
// First check the field data, which is used for restart.
if (mesh.getProperties().existsPropertyVector<double>(name))
{
auto const& mesh_property =
*mesh.getProperties().template getPropertyVector<double>(name);
// The mesh property must be defined on integration points.
if (mesh_property.getMeshItemType() !=
MeshLib::MeshItemType::IntegrationPoint)
{
continue;
}
auto const ip_meta_data = getIntegrationPointMetaData(mesh, name);
// Check the number of components.
if (ip_meta_data.n_components !=
mesh_property.getNumberOfComponents())
{
OGS_FATAL(
"Different number of components in meta data (%d) than in "
"the integration point field data for '%s': %d.",
ip_meta_data.n_components, name.c_str(),
mesh_property.getNumberOfComponents());
}
// Now we have a properly named vtk's field data array and the
// corresponding meta data.
std::size_t position = 0;
for (auto& local_asm : _local_assemblers)
{
std::size_t const integration_points_read =
local_asm->setIPDataInitialConditions(
name, &mesh_property[position],
ip_meta_data.integration_order);
if (integration_points_read == 0)
{
OGS_FATAL(
"No integration points read in the integration point "
"initial conditions set function.");
}
position += integration_points_read * ip_meta_data.n_components;
}
//.........这里部分代码省略.........
示例8: accept
void CreateStructuredGridDialog::accept()
{
if (inputIsEmpty())
return;
if ((this->xLengthEdit->text().toDouble() <= 0) ||
(this->yLengthEdit->text().toDouble() <= 0) ||
(this->zLengthEdit->text().toDouble() <= 0))
{
OGSError::box("Length needs to be larger than 0.");
return;
}
if ((this->xElemEdit->text().toDouble() <= 0) ||
(this->yElemEdit->text().toDouble() <= 0) ||
(this->zElemEdit->text().toDouble() <= 0))
{
OGSError::box("Number of elements needs to be larger than 0.");
return;
}
GeoLib::Point const origin(this->xOriginEdit->text().toDouble(),
this->yOriginEdit->text().toDouble(),
this->zOriginEdit->text().toDouble());
std::string const name (this->meshNameEdit->text().toStdString());
MeshLib::Mesh* mesh (nullptr);
if (this->lineButton->isChecked())
if (this->meshExtentButton->isChecked())
mesh = MeshLib::MeshGenerator::generateLineMesh(
this->xLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(), origin, name);
else
mesh = MeshLib::MeshGenerator::generateLineMesh(
this->xElemEdit->text().toInt(), this->xLengthEdit->text().toDouble(), origin, name);
else if (this->triButton->isChecked())
if (this->meshExtentButton->isChecked())
mesh = MeshLib::MeshGenerator::generateRegularTriMesh(
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
origin, name);
else
mesh = MeshLib::MeshGenerator::generateRegularTriMesh(
this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
origin, name);
else if (this->quadButton->isChecked())
if (this->meshExtentButton->isChecked())
mesh = MeshLib::MeshGenerator::generateRegularQuadMesh(
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
origin, name);
else
mesh = MeshLib::MeshGenerator::generateRegularQuadMesh(
this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
origin, name);
else if (this->prismButton->isChecked())
if (this->meshExtentButton->isChecked())
mesh = MeshLib::MeshGenerator::generateRegularPrismMesh(
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
origin, name);
else
mesh = MeshLib::MeshGenerator::generateRegularPrismMesh(
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
origin, name);
else if (this->hexButton->isChecked())
if (this->meshExtentButton->isChecked())
mesh = MeshLib::MeshGenerator::generateRegularHexMesh(
this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
origin, name);
else
mesh = MeshLib::MeshGenerator::generateRegularHexMesh(
this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
this->zElemEdit->text().toInt(), this->xLengthEdit->text().toDouble(),
this->yLengthEdit->text().toDouble(), this->zLengthEdit->text().toDouble(),
origin, name);
if (mesh == nullptr)
{
OGSError::box("Error creating mesh.");
return;
}
boost::optional<MeshLib::PropertyVector<int>&> mat_ids (
mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
mat_ids->reserve(mesh->getNumberOfElements());
std::fill_n(std::back_inserter(*mat_ids), mesh->getNumberOfElements(), 0);
emit meshAdded(mesh);
this->done(QDialog::Accepted);
}