TEST(ProcessLib_Parameter, GroupBasedParameterElement) { const char xml[] = "<parameter>" "<type>Group</type>" "<group_id_property>MaterialIDs</group_id_property>" "<index_values><index>0</index><value>0</value></index_values>" "<index_values><index>1</index><value>100</value></index_values>" "<index_values><index>3</index><value>300</value></index_values>" "</parameter>"; auto const ptree = readXml(xml); std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::MeshGenerator::generateLineMesh(4u, 1.0)); std::vector<int> mat_ids({0, 1, 2, 3}); MeshLib::addPropertyToMesh(*mesh, "MaterialIDs", MeshLib::MeshItemType::Cell, 1, mat_ids); BaseLib::ConfigTree conf(ptree, "", BaseLib::ConfigTree::onerror, BaseLib::ConfigTree::onwarning); std::unique_ptr<ProcessLib::ParameterBase> parameter_base = ProcessLib::createGroupBasedParameter( "", conf.getConfigSubtree("parameter"), *mesh); auto parameter = dynamic_cast<ProcessLib::Parameter<double>*>(parameter_base.get()); double t = 0; ProcessLib::SpatialPosition x; x.setElementID(0); ASSERT_EQ(0.0, (*parameter)(t, x)[0]); x.setElementID(1); ASSERT_EQ(100.0, (*parameter)(t, x)[0]); x.setElementID(2); ASSERT_ANY_THROW((*parameter)(t, x)); x.setElementID(3); ASSERT_EQ(300.0, (*parameter)(t, x)[0]); }
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); }