diff --git a/FileIO/XmlIO/Boost/BoostXmlCndInterface.cpp b/FileIO/XmlIO/Boost/BoostXmlCndInterface.cpp index 82d906b356068c13af083e19a21315b7552ccf9c..472796d92bdf7ba29282111272d0cd3690abbe85 100644 --- a/FileIO/XmlIO/Boost/BoostXmlCndInterface.cpp +++ b/FileIO/XmlIO/Boost/BoostXmlCndInterface.cpp @@ -140,13 +140,18 @@ void BoostXmlCndInterface::readDistributionTag(boost::property_tree::ptree const else if (dis_tag.first.compare("Value") == 0) { FiniteElement::DistributionType const& dt(cond->getProcessDistributionType()); - if (dt == FiniteElement::CONSTANT || dt == FiniteElement::CONSTANT_NEUMANN) { + if (dt == FiniteElement::CONSTANT || + dt == FiniteElement::CONSTANT_NEUMANN || + dt == FiniteElement::NODESCONSTANT) + { cond->setConstantDisValue(BaseLib::str2number<double>(dis_tag.second.data())); return; } - if (dt == FiniteElement::LINEAR || dt == FiniteElement::LINEAR_NEUMANN - || dt == FiniteElement::DIRECT) { + if (dt == FiniteElement::LINEAR || + dt == FiniteElement::LINEAR_NEUMANN || + dt == FiniteElement::DIRECT) + { std::vector<std::size_t> dis_node_ids; std::vector<double> dis_values; diff --git a/FileIO/XmlIO/Qt/XmlCndInterface.cpp b/FileIO/XmlIO/Qt/XmlCndInterface.cpp index 328400e6c5a9da07e204c41dae12f5a38ed5e562..5d173d26ee6eafb6c7891c44ca4f4a671fa4947f 100644 --- a/FileIO/XmlIO/Qt/XmlCndInterface.cpp +++ b/FileIO/XmlIO/Qt/XmlCndInterface.cpp @@ -126,7 +126,8 @@ void XmlCndInterface::readConditions(const QDomNode &listRoot, std::vector<size_t> disNodes; std::vector<double> disValues; if (c->getProcessDistributionType()==FiniteElement::CONSTANT || - c->getProcessDistributionType()==FiniteElement::CONSTANT_NEUMANN) + c->getProcessDistributionType()==FiniteElement::CONSTANT_NEUMANN || + c->getProcessDistributionType()==FiniteElement::NODESCONSTANT) disValues.push_back( distProps.at(j).toElement().text().toDouble() ); else if (c->getProcessDistributionType()==FiniteElement::LINEAR || c->getProcessDistributionType()==FiniteElement::LINEAR_NEUMANN || diff --git a/GeoLib/PointVec.cpp b/GeoLib/PointVec.cpp index 3e16943f32a0064924f874791c097d3383549fe9..b47dbdcf923e4540227bcf313e70feda5b5f1b91 100644 --- a/GeoLib/PointVec.cpp +++ b/GeoLib/PointVec.cpp @@ -242,7 +242,7 @@ void PointVec::calculateShortestDistance () _sqr_shortest_dist = MathLib::sqrDist (*(*_data_vec)[i], *(*_data_vec)[j]); } -std::vector<GeoLib::Point*>* PointVec::getSubset(const std::vector<std::size_t> &subset) +std::vector<GeoLib::Point*>* PointVec::getSubset(const std::vector<std::size_t> &subset) const { std::vector<GeoLib::Point*> *new_points (new std::vector<GeoLib::Point*>(subset.size())); diff --git a/GeoLib/PointVec.h b/GeoLib/PointVec.h index bad45b89fb88987a43848c401020b9db2470d345..b7cd8ea2e8f08b5512cd1746f72dbeb22531be51 100644 --- a/GeoLib/PointVec.h +++ b/GeoLib/PointVec.h @@ -106,7 +106,7 @@ public: const GeoLib::AABB<GeoLib::Point>& getAABB () const; /// Returns a subset of this point vector containing only the points specified in "subset" as PointWithID-objects - std::vector<GeoLib::Point*>* getSubset(const std::vector<std::size_t> &subset); + std::vector<GeoLib::Point*>* getSubset(const std::vector<std::size_t> &subset) const; private: /** diff --git a/Gui/DataView/FEMConditionSetupDialog.cpp b/Gui/DataView/FEMConditionSetupDialog.cpp index 7f8628a95718d635e8411c1069b0368e72f05522..298129e5d95cde9817dda2df59e19e093e0a9436 100644 --- a/Gui/DataView/FEMConditionSetupDialog.cpp +++ b/Gui/DataView/FEMConditionSetupDialog.cpp @@ -162,7 +162,7 @@ void FEMConditionSetupDialog::accept() if (_cond.getGeomType() != GeoLib::GEOTYPE::INVALID) { - if (condTypeBox->currentIndex()>1) + if (condTypeBox->currentIndex()>1) // ST { if (this->disTypeBox->currentIndex()>0) _cond.setProcessDistributionType(FiniteElement::LINEAR_NEUMANN); @@ -172,7 +172,7 @@ void FEMConditionSetupDialog::accept() _cond.setConstantDisValue(this->firstValueEdit->text().toDouble()); } } - else + else // BC or IC { if (this->disTypeBox->currentIndex()>0) _cond.setProcessDistributionType(FiniteElement::LINEAR); @@ -184,7 +184,15 @@ void FEMConditionSetupDialog::accept() } } else // direct on mesh - _cond.setProcessDistributionType(FiniteElement::DIRECT); + { + if (this->condTypeBox->currentIndex()==1) // IC + { + _cond.setProcessDistributionType(FiniteElement::NODESCONSTANT); + _cond.setConstantDisValue(this->firstValueEdit->text().toDouble()); + } + else // BC or ST + _cond.setProcessDistributionType(FiniteElement::DIRECT); + } if (_cond.getDisValues().size()==0) { OGSError::box("No distribution values specified!"); @@ -218,41 +226,58 @@ void FEMConditionSetupDialog::on_condTypeBox_currentIndexChanged(int index) { if (index>1) // source terms selected { - while (this->disTypeBox->count()>0) - this->disTypeBox->removeItem(0); + this->clearDisTypeBox(); this->disTypeBox->addItem("Constant (Neumann)"); if (_cond.getGeomType() == GeoLib::GEOTYPE::POLYLINE) this->disTypeBox->addItem("Linear (Neumann)"); } else { - while (this->disTypeBox->count()>0) - this->disTypeBox->removeItem(0); + this->clearDisTypeBox(); this->disTypeBox->addItem("Constant (Dirichlet)"); if (_cond.getGeomType() == GeoLib::GEOTYPE::POLYLINE) this->disTypeBox->addItem("Linear (Dirichlet)"); } } + else { + if (index==1) // initial condition selected + { + this->clearDisTypeBox(); + this->disTypeBox->addItem("Domain"); + this->setValueInputWidget(false); + } + else + { + this->clearDisTypeBox(); + this->disTypeBox->addItem("Direct"); + this->setValueInputWidget(true); + } + } } void FEMConditionSetupDialog::on_disTypeBox_currentIndexChanged(int index) { - if (index>0) // linear + this->setValueInputWidget(index>0); +} + +void FEMConditionSetupDialog::setValueInputWidget(bool is_button) +{ + if (is_button) // linear or direct { static_cast<QGridLayout*>(this->layout())->removeWidget(this->firstValueEdit); directButton = new QPushButton("Calculate Values"); connect(this->directButton, SIGNAL(pressed()), this, SLOT(directButton_pressed())); static_cast<QGridLayout*>(this->layout())->addWidget(directButton,5,1); } - else // constant + else // constant or domain { static_cast<QGridLayout*>(this->layout())->removeWidget(this->directButton); delete directButton; directButton = nullptr; + this->firstValueEdit->setText("0"); static_cast<QGridLayout*>(this->layout())->addWidget(this->firstValueEdit,5,1); } - } void FEMConditionSetupDialog::directButton_pressed() @@ -283,7 +308,6 @@ void FEMConditionSetupDialog::addDisValues(std::vector< std::pair<size_t,double> { _cond.setDisValues(direct_values); this->directButton->setText(QString::number(direct_values.size()) + " values added"); - //this->directButton->setEnabled(false); } FEMCondition* FEMConditionSetupDialog::typeCast(const FEMCondition &cond) @@ -345,3 +369,9 @@ void FEMConditionSetupDialog::copyCondOnPoints() else ERR("FEMConditionSetupDialog::copyCondOnPoints(): discerning GeoType."); } + +void FEMConditionSetupDialog::clearDisTypeBox() +{ + while (this->disTypeBox->count()>0) + this->disTypeBox->removeItem(0); +} diff --git a/Gui/DataView/FEMConditionSetupDialog.h b/Gui/DataView/FEMConditionSetupDialog.h index fbbfc4df4c3707ab7330c62bfcac6e0d3aa21494..ed1cb3063c16d7aefa1c7f8ba596a48b243fb8b6 100644 --- a/Gui/DataView/FEMConditionSetupDialog.h +++ b/Gui/DataView/FEMConditionSetupDialog.h @@ -58,8 +58,12 @@ public: ~FEMConditionSetupDialog(void); private: + /// Clears the DistributionType-combobox + void clearDisTypeBox(); /// Sets layout of the dialog according to properties of the object void setupDialog(); + /// switches the input widget from lineEdit to PushButton (if true) and vice versa (if false) + void setValueInputWidget(bool is_button); /// Inserts existing values if an existing FEMCondition is being edited void setValuesFromCond(); diff --git a/Gui/DataView/ProcessModel.cpp b/Gui/DataView/ProcessModel.cpp index 96d93650b97fe6f1c483714f4d0c9163d1520bc8..93ee157d707a53aad4019f86a4718901582f3304 100644 --- a/Gui/DataView/ProcessModel.cpp +++ b/Gui/DataView/ProcessModel.cpp @@ -26,6 +26,7 @@ #include "GEOObjects.h" #include "GeoObject.h" #include "GeoType.h" +#include "FEMEnums.h" #include <QFileInfo> #include <vtkPolyDataAlgorithm.h> @@ -83,8 +84,9 @@ void ProcessModel::addConditionItem(FEMCondition* c) std::vector<size_t> dis_nodes = c->getDisNodes(); std::vector<double> dis_values = c->getDisValues(); TreeItem* disInfo; - if (c->getProcessDistributionType() == FiniteElement::CONSTANT - || c->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) + if (c->getProcessDistributionType() == FiniteElement::CONSTANT || + c->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN || + c->getProcessDistributionType() == FiniteElement::NODESCONSTANT) { disData << dis_values[0]; disInfo = new TreeItem(disData, condItem); @@ -112,10 +114,11 @@ void ProcessModel::addConditionItem(FEMCondition* c) void ProcessModel::addCondition(FEMCondition* condition) { - bool is_domain = (condition->getGeomType() == GeoLib::GEOTYPE::GEODOMAIN) ? true : false; // HACK: direct source terms are not domain conditions but they also don't contain geo-object-names - if (condition->getProcessDistributionType() == FiniteElement::DIRECT) - is_domain = true; + bool is_domain (false); + if (condition->getProcessDistributionType() == FiniteElement::NODESCONSTANT || + condition->getProcessDistributionType() == FiniteElement::DIRECT) + is_domain = true; const GeoLib::GeoObject* object = condition->getGeoObj(); if (object == nullptr) diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 15aba1929e039836854a488b85997f4c5261e870..154a7fc267742604f97e3e62628866077c530759 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -909,21 +909,28 @@ void MainWindow::addFEMConditions(std::vector<FEMCondition*> const& conditions) for (size_t i = 0; i < conditions.size(); i++) { bool condition_ok(true); - if (conditions[i]->getProcessDistributionType() == FiniteElement::DIRECT) + if (conditions[i]->getProcessDistributionType() == FiniteElement::DIRECT || + conditions[i]->getProcessDistributionType() == FiniteElement::NODESCONSTANT) { if (_meshModels->getMesh(conditions[i]->getAssociatedGeometryName()) != NULL) { - std::vector<MeshLib::Node*> nodes = _meshModels->getMesh(conditions[i]->getAssociatedGeometryName())->getNodes(); + const std::vector<MeshLib::Node*> &nodes = _meshModels->getMesh(conditions[i]->getAssociatedGeometryName())->getNodes(); const size_t nPoints(nodes.size()); std::vector<GeoLib::Point*> *new_points = new std::vector<GeoLib::Point*>(nPoints); for (size_t j = 0; j < nPoints; j++) (*new_points)[j] = new GeoLib::Point(nodes[j]->getCoords()); - GeoLib::PointVec pnt_vec("MeshNodes", new_points); - std::vector<GeoLib::Point*> *cond_points = pnt_vec.getSubset(conditions[i]->getDisNodes()); + if (conditions[i]->getProcessDistributionType() == FiniteElement::DIRECT) + { + const GeoLib::PointVec pnt_vec("MeshNodes", new_points); + std::vector<GeoLib::Point*> *cond_points = pnt_vec.getSubset(conditions[i]->getDisNodes()); + std::for_each(new_points->begin(), new_points->end(), [](GeoLib::Point const*const pnt){delete pnt;} ); + new_points->clear(); + new_points = cond_points; + } std::string geo_name = conditions[i]->getGeoName(); - this->_project.getGEOObjects()->addPointVec(cond_points, geo_name); + this->_project.getGEOObjects()->addPointVec(new_points, geo_name); conditions[i]->setGeoName(geo_name); // this might have been changed upon inserting it into geo_objects } else { - OGSError::box("Please load an appropriate geometry first", "Error"); + OGSError::box("Please load the referenced mesh first", "Error"); condition_ok = false; } } diff --git a/OGS/FEMEnums.cpp b/OGS/FEMEnums.cpp index 63db56d559274ec4599668cdb3e0db45454b96a3..4ccf7b7538f26c4b6ccaf86e33dfdd9c4a53064d 100644 --- a/OGS/FEMEnums.cpp +++ b/OGS/FEMEnums.cpp @@ -337,6 +337,8 @@ DistributionType convertDisType(const std::string& dis_type_string) return PRECIPITATION; if (dis_type_string.compare("DIRECT") == 0) return DIRECT; + if (dis_type_string.compare("DOMAIN") == 0) + return NODESCONSTANT; if (dis_type_string.compare("FUNCTION") == 0) return FUNCTION; //24.08.2011. WW @@ -377,6 +379,8 @@ std::string convertDisTypeToString(DistributionType dis_type) return "PRECIPITATION"; if (dis_type == DIRECT) return "DIRECT"; + if (dis_type == NODESCONSTANT) + return "DOMAIN"; if (dis_type == FUNCTION) return "FUNCTION"; //24.08.2011. WW diff --git a/OGS/FEMEnums.h b/OGS/FEMEnums.h index 22ed73c905286a5cefc02f7e40f493382bf1719e..21df8b059aa4cd4daf44b407c8ff0a445de27385 100644 --- a/OGS/FEMEnums.h +++ b/OGS/FEMEnums.h @@ -177,18 +177,18 @@ enum DistributionType CONSTANT_GEO, CONSTANT_NEUMANN, // ST CRITICALDEPTH, // ST - DIRECT, + DIRECT, // ST (directly on mesh nodes) FUNCTION, GRADIENT, // IC GREEN_AMPT, // ST RESTART, // IC LINEAR, // BC, ST LINEAR_NEUMANN, // ST + NODESCONSTANT, // IC (directly on mesh nodes) NORMALDEPTH, // ST POINT, // BC PRECIPITATION, SYSTEM_DEPENDENT, // ST - // Sort of Neumann BC //WW // make sure that this is always the last entry (important for iterating over the enum entries)! DIS_END };