Fem: Change ConstraintPressure::Pressure property to App::PropertyPressure

This commit is contained in:
Uwe
2023-10-03 01:38:23 -03:00
committed by marioalexis
parent d8636dd058
commit 6845cb66f8
10 changed files with 72 additions and 56 deletions

View File

@@ -58,6 +58,21 @@ const char* ConstraintPressure::getViewProviderName() const
return "FemGui::ViewProviderFemConstraintPressure";
}
void ConstraintPressure::handleChangedPropertyType(Base::XMLReader& reader,
const char* TypeName,
App::Property* prop)
{
// property Pressure had App::PropertyFloat and was changed to App::PropertyPressure
if (prop == &Pressure && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat PressureProperty;
// restore the PropertyFloat to be able to set its value
PressureProperty.Restore(reader);
// the old implementation or pressure stored the value as MPa
// therefore we must convert the value with a factor 1000
Pressure.setValue(PressureProperty.getValue() * 1000.0);
}
}
void ConstraintPressure::onChanged(const App::Property* prop)
{
Constraint::onChanged(prop);

View File

@@ -37,7 +37,7 @@ class FemExport ConstraintPressure: public Fem::Constraint
public:
ConstraintPressure();
App::PropertyFloat Pressure;
App::PropertyPressure Pressure;
App::PropertyBool Reversed;
App::PropertyVectorList Points;
App::PropertyVectorList Normals;
@@ -49,6 +49,8 @@ public:
const char* getViewProviderName() const override;
protected:
void
handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop);
void onChanged(const App::Property* prop) override;
};

View File

@@ -52,6 +52,33 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
// Get the feature data
Fem::ConstraintPressure* pcConstraint =
static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
// Fill data into dialog elements
ui->if_pressure->setUnit(pcConstraint->Pressure.getUnit());
ui->if_pressure->setMinimum(0);
ui->if_pressure->setMaximum(FLOAT_MAX);
ui->if_pressure->setValue(pcConstraint->Pressure.getQuantityValue());
ui->if_pressure->bind(pcConstraint->Pressure);
bool reversed = pcConstraint->Reversed.getValue();
ui->checkBoxReverse->setChecked(reversed);
ui->lw_references->clear();
for (std::size_t i = 0; i < Objects.size(); i++) {
ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i]));
}
if (!Objects.empty()) {
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
}
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
connect(deleteAction,
@@ -72,37 +99,9 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(
this,
&TaskFemConstraintPressure::onCheckReverse);
this->groupLayout()->addWidget(proxy);
/* Note: */
// Get the feature data
Fem::ConstraintPressure* pcConstraint =
static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
// Fill data into dialog elements
ui->if_pressure->setMinimum(0);
ui->if_pressure->setMaximum(FLOAT_MAX);
Base::Quantity p =
Base::Quantity(1000 * (pcConstraint->Pressure.getValue()), Base::Unit::Stress);
ui->if_pressure->setValue(p);
bool reversed = pcConstraint->Reversed.getValue();
ui->checkBoxReverse->setChecked(reversed);
/* */
ui->lw_references->clear();
for (std::size_t i = 0; i < Objects.size(); i++) {
ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i]));
}
if (!Objects.empty()) {
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
}
// Selection buttons
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
buttonGroup->addButton(ui->btnAdd, static_cast<int>(SelectionChangeModes::refAdd));
buttonGroup->addButton(ui->btnRemove, static_cast<int>(SelectionChangeModes::refRemove));
updateUI();
}
@@ -252,12 +251,9 @@ const std::string TaskFemConstraintPressure::getReferences() const
return TaskFemConstraint::getReferences(items);
}
/* Note: */
double TaskFemConstraintPressure::get_Pressure() const
std::string TaskFemConstraintPressure::get_Pressure() const
{
Base::Quantity pressure = ui->if_pressure->getQuantity();
double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal);
return pressure_in_MPa;
return ui->if_pressure->value().getSafeUserString().toStdString();
}
bool TaskFemConstraintPressure::get_Reverse() const
@@ -323,9 +319,9 @@ bool TaskDlgFemConstraintPressure::accept()
try {
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Pressure = %f",
"App.ActiveDocument.%s.Pressure = \"%s\"",
name.c_str(),
parameterPressure->get_Pressure());
parameterPressure->get_Pressure().c_str());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Reversed = %s",
name.c_str(),

View File

@@ -46,7 +46,7 @@ public:
QWidget* parent = nullptr);
~TaskFemConstraintPressure() override;
const std::string getReferences() const override;
double get_Pressure() const;
std::string get_Pressure() const;
bool get_Reverse() const;
private Q_SLOTS:

View File

@@ -70,12 +70,12 @@
</widget>
</item>
<item>
<widget class="Gui::InputField" name="if_pressure">
<property name="text">
<string>0 MPa</string>
</property>
<widget class="Gui::QuantitySpinBox" name="if_pressure">
<property name="unit" stdset="0">
<string notr="true">MPa</string>
<string notr="true"/>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
</widget>
</item>
@@ -92,9 +92,9 @@
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@@ -51,5 +51,5 @@ class ConstraintInitialPressure(base_fempythonobject.BaseFemPythonObject):
"Parameter",
"Initial Pressure"
)
# App::PropertyPressure is in kPa and we initialize 1 bar
obj.Pressure = 100
# we initialize 1 bar
obj.Pressure = "100 kPa"

View File

@@ -25,6 +25,7 @@ __title__ = "FreeCAD FEM calculix constraint pressure"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecad.org"
import FreeCAD
def get_analysis_types():
return ["buckling", "static", "thermomech"]
@@ -47,7 +48,9 @@ def write_meshdata_constraint(f, femobj, prs_obj, ccxwriter):
# floats read from ccx should use {:.13G}, see comment in writer module
rev = -1 if prs_obj.Reversed else 1
press_rev = rev * prs_obj.Pressure
# the pressure has to be output in MPa
pressure_quantity = FreeCAD.Units.Quantity(prs_obj.Pressure.getValueAs("MPa"))
press_rev = rev * pressure_quantity
f.write("*DLOAD\n")
for ref_shape in femobj["PressureFaces"]:
@@ -57,12 +60,12 @@ def write_meshdata_constraint(f, femobj, prs_obj, ccxwriter):
f.write("** " + ref_shape[0] + "\n")
for face, fno in ref_shape[1]:
if fno > 0: # solid mesh face
f.write("{},P{},{:.13G}\n".format(face, fno, press_rev))
f.write("{},P{},{}\n".format(face, fno, press_rev))
# on shell mesh face: fno == 0
# normal of element face == face normal
elif fno == 0:
f.write("{},P,{:.13G}\n".format(face, press_rev))
f.write("{},P,{}\n".format(face, press_rev))
# on shell mesh face: fno == -1
# normal of element face opposite direction face normal
elif fno == -1:
f.write("{},P,{:.13G}\n".format(face, -1 * press_rev))
f.write("{},P,{}\n".format(face, -1 * press_rev))

View File

@@ -82,7 +82,7 @@ class DeformationWriter:
for obj in self.write.getMember("Fem::ConstraintPressure"):
if obj.References:
for name in obj.References[0][1]:
pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)")
pressure = float(obj.Pressure.getValueAs("Pa"))
if not obj.Reversed:
pressure *= -1
self.write.boundary(name, "Normal Force", pressure)

View File

@@ -298,7 +298,7 @@ class ElasticityWriter:
for obj in self.write.getMember("Fem::ConstraintPressure"):
if obj.References:
for name in obj.References[0][1]:
pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)")
pressure = float(obj.Pressure.getValueAs("Pa"))
if not obj.Reversed:
pressure *= -1
self.write.boundary(name, "Normal Force", pressure)

View File

@@ -261,7 +261,7 @@ class Flowwriter:
for obj in self.write.getMember("Fem::ConstraintPressure"):
if obj.References:
for name in obj.References[0][1]:
pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)")
pressure = float(obj.Pressure.getValueAs("Pa"))
if obj.Reversed:
pressure *= -1
self.write.boundary(name, "External Pressure", pressure)