[FEM] Temperature constraints overhaul
- fix bug that changing constraint type in dialog lost flux value - accept and not immediately save any changed value - make the temperatures a PropertyTemperature to get rid of hacks - also fix some too long code lines
This commit is contained in:
@@ -34,12 +34,16 @@ PROPERTY_SOURCE(Fem::ConstraintInitialTemperature, Fem::Constraint)
|
||||
|
||||
ConstraintInitialTemperature::ConstraintInitialTemperature()
|
||||
{
|
||||
ADD_PROPERTY(initialTemperature,(300.0));
|
||||
ADD_PROPERTY(initialTemperature, (300.0));
|
||||
|
||||
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintInitialTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
ADD_PROPERTY_TYPE(Points, (Base::Vector3d()),
|
||||
"ConstraintInitialTemperature",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Points where symbols are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintInitialTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()),
|
||||
"ConstraintInitialTemperature",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
Points.setValues(std::vector<Base::Vector3d>());
|
||||
Normals.setValues(std::vector<Base::Vector3d>());
|
||||
|
||||
@@ -57,6 +61,19 @@ const char* ConstraintInitialTemperature::getViewProviderName() const
|
||||
return "FemGui::ViewProviderFemConstraintInitialTemperature";
|
||||
}
|
||||
|
||||
void ConstraintInitialTemperature::handleChangedPropertyType(Base::XMLReader& reader,
|
||||
const char* TypeName,
|
||||
App::Property* prop)
|
||||
{
|
||||
// property initialTemperature had App::PropertyFloat, was changed to App::PropertyTemperature
|
||||
if (prop == &initialTemperature && strcmp(TypeName, "App::PropertyFloat") == 0) {
|
||||
App::PropertyFloat initialTemperatureProperty;
|
||||
// restore the PropertyFloat to be able to set its value
|
||||
initialTemperatureProperty.Restore(reader);
|
||||
initialTemperature.setValue(initialTemperatureProperty.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ConstraintInitialTemperature::onChanged(const App::Property* prop)
|
||||
{
|
||||
// Note: If we call this at the end, then the arrows are not oriented correctly initially
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
App::PropertyVectorList Normals;
|
||||
|
||||
//Temperature parameters
|
||||
App::PropertyFloat initialTemperature;
|
||||
App::PropertyTemperature initialTemperature;
|
||||
|
||||
|
||||
/// recalculate the object
|
||||
@@ -55,6 +55,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;
|
||||
|
||||
};
|
||||
|
||||
@@ -36,16 +36,19 @@ static const char* ConstraintTypes[] = {"CFlux","Temperature", nullptr};
|
||||
|
||||
ConstraintTemperature::ConstraintTemperature()
|
||||
{
|
||||
ADD_PROPERTY(Temperature,(300.0));
|
||||
ADD_PROPERTY(CFlux,(0.0));
|
||||
ADD_PROPERTY_TYPE(ConstraintType,(1),"ConstraintTemperature",(App::PropertyType)(App::Prop_None),
|
||||
ADD_PROPERTY(Temperature, (300.0));
|
||||
ADD_PROPERTY(CFlux, (0.0));
|
||||
ADD_PROPERTY_TYPE(ConstraintType, (1), "ConstraintTemperature",
|
||||
(App::PropertyType)(App::Prop_None),
|
||||
"Type of constraint, temperature or concentrated heat flux");
|
||||
ConstraintType.setEnums(ConstraintTypes);
|
||||
|
||||
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintTemperature",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Points where symbols are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintTemperature",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
Points.setValues(std::vector<Base::Vector3d>());
|
||||
Normals.setValues(std::vector<Base::Vector3d>());
|
||||
}
|
||||
@@ -60,6 +63,24 @@ const char* ConstraintTemperature::getViewProviderName() const
|
||||
return "FemGui::ViewProviderFemConstraintTemperature";
|
||||
}
|
||||
|
||||
void ConstraintTemperature::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
|
||||
App::Property* prop)
|
||||
{
|
||||
// property Temperature had App::PropertyFloat and was changed to App::PropertyTemperature
|
||||
if (prop == &Temperature && strcmp(TypeName, "App::PropertyFloat") == 0) {
|
||||
App::PropertyFloat TemperatureProperty;
|
||||
// restore the PropertyFloat to be able to set its value
|
||||
TemperatureProperty.Restore(reader);
|
||||
Temperature.setValue(TemperatureProperty.getValue());
|
||||
}
|
||||
// property CFlux had App::PropertyFloat and was changed to App::PropertyPower
|
||||
else if (prop == &CFlux && strcmp(TypeName, "App::PropertyFloat") == 0) {
|
||||
App::PropertyFloat CFluxProperty;
|
||||
CFluxProperty.Restore(reader);
|
||||
CFlux.setValue(CFluxProperty.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ConstraintTemperature::onChanged(const App::Property* prop)
|
||||
{
|
||||
// Note: If we call this at the end, then the arrows are not oriented correctly initially
|
||||
|
||||
@@ -45,8 +45,8 @@ public:
|
||||
App::PropertyVectorList Normals;
|
||||
|
||||
//Temperature parameters
|
||||
App::PropertyFloat Temperature;
|
||||
App::PropertyFloat CFlux;
|
||||
App::PropertyTemperature Temperature;
|
||||
App::PropertyPower CFlux;
|
||||
App::PropertyEnumeration ConstraintType;
|
||||
|
||||
|
||||
@@ -57,6 +57,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;
|
||||
|
||||
};
|
||||
|
||||
@@ -60,21 +60,17 @@ TaskFemConstraintInitialTemperature::TaskFemConstraintInitialTemperature(
|
||||
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
|
||||
|
||||
// Fill data into dialog elements
|
||||
ui->if_temperature->setMinimum(0);
|
||||
ui->if_temperature->setMaximum(FLOAT_MAX);
|
||||
Base::Quantity t =
|
||||
Base::Quantity(pcConstraint->initialTemperature.getValue(), Base::Unit::Temperature);
|
||||
ui->if_temperature->setValue(t);
|
||||
ui->if_temperature->setValue(pcConstraint->initialTemperature.getQuantityValue());
|
||||
|
||||
ui->if_temperature->bind(pcConstraint->initialTemperature);
|
||||
}
|
||||
|
||||
TaskFemConstraintInitialTemperature::~TaskFemConstraintInitialTemperature()
|
||||
{}
|
||||
|
||||
double TaskFemConstraintInitialTemperature::get_temperature() const
|
||||
std::string TaskFemConstraintInitialTemperature::get_temperature() const
|
||||
{
|
||||
Base::Quantity temperature = ui->if_temperature->getQuantity();
|
||||
double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin);
|
||||
return temperature_in_kelvin;
|
||||
return ui->if_temperature->value().getSafeUserString().toStdString();
|
||||
}
|
||||
|
||||
void TaskFemConstraintInitialTemperature::changeEvent(QEvent*)
|
||||
@@ -119,9 +115,9 @@ bool TaskDlgFemConstraintInitialTemperature::accept()
|
||||
|
||||
try {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.initialTemperature = %f",
|
||||
"App.ActiveDocument.%s.initialTemperature = \"%s\"",
|
||||
name.c_str(),
|
||||
parameterTemperature->get_temperature());
|
||||
parameterTemperature->get_temperature().c_str());
|
||||
|
||||
std::string scale = parameterTemperature->getScale();// OvG: determine modified scale
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
explicit TaskFemConstraintInitialTemperature(
|
||||
ViewProviderFemConstraintInitialTemperature* ConstraintView, QWidget* parent = nullptr);
|
||||
~TaskFemConstraintInitialTemperature() override;
|
||||
double get_temperature()const;
|
||||
std::string get_temperature() const;
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e) override;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<width>268</width>
|
||||
<height>57</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -25,15 +25,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::InputField" name="if_temperature">
|
||||
<property name="text">
|
||||
<string>300 K</string>
|
||||
</property>
|
||||
<widget class="Gui::QuantitySpinBox" name="if_temperature">
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">K</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>300.000000000000000</double>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -41,9 +38,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/>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
#include <Gui/SelectionObject.h>
|
||||
#include <Mod/Fem/App/FemConstraintTemperature.h>
|
||||
|
||||
@@ -54,23 +55,6 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(
|
||||
ui->setupUi(proxy);
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
|
||||
// create a context menu for the listview of the references
|
||||
createDeleteAction(ui->lw_references);
|
||||
connect(deleteAction, &QAction::triggered,
|
||||
this, &TaskFemConstraintTemperature::onReferenceDeleted);
|
||||
|
||||
connect(ui->lw_references, &QListWidget::currentItemChanged,
|
||||
this, &TaskFemConstraintTemperature::setSelection);
|
||||
connect(ui->lw_references, &QListWidget::itemClicked,
|
||||
this, &TaskFemConstraintTemperature::setSelection);
|
||||
connect(ui->rb_temperature, &QRadioButton::clicked,
|
||||
this, &TaskFemConstraintTemperature::Temp);
|
||||
connect(ui->rb_cflux, &QRadioButton::clicked,
|
||||
this, &TaskFemConstraintTemperature::Flux);
|
||||
|
||||
connect(ui->if_temperature, qOverload<double>(&InputField::valueChanged),
|
||||
this, &TaskFemConstraintTemperature::onTempCfluxChanged);
|
||||
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
|
||||
// Get the feature data
|
||||
@@ -87,20 +71,17 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(
|
||||
std::string constraint_type = pcConstraint->ConstraintType.getValueAsString();
|
||||
if (constraint_type == "Temperature") {
|
||||
ui->rb_temperature->setChecked(1);
|
||||
std::string str = "Temperature";
|
||||
QString qstr = QString::fromStdString(str);
|
||||
ui->lbl_type->setText(qstr);
|
||||
Base::Quantity t =
|
||||
Base::Quantity(pcConstraint->Temperature.getValue(), Base::Unit::Temperature);
|
||||
ui->if_temperature->setValue(t);
|
||||
ui->if_temperature->setValue(pcConstraint->Temperature.getQuantityValue());
|
||||
|
||||
ui->if_temperature->bind(pcConstraint->Temperature);
|
||||
ui->if_temperature->setUnit(pcConstraint->Temperature.getUnit());
|
||||
}
|
||||
else if (constraint_type == "CFlux") {
|
||||
ui->rb_cflux->setChecked(1);
|
||||
std::string str = "Concentrated heat flux";
|
||||
QString qstr = QString::fromStdString(str);
|
||||
ui->lbl_type->setText(qstr);
|
||||
Base::Quantity c = Base::Quantity(pcConstraint->CFlux.getValue(), Base::Unit::Power);
|
||||
ui->if_temperature->setValue(c);
|
||||
ui->if_temperature->setValue(pcConstraint->CFlux.getQuantityValue());
|
||||
ui->if_temperature->bind(pcConstraint->CFlux);
|
||||
ui->if_temperature->setUnit(pcConstraint->CFlux.getUnit());
|
||||
}
|
||||
|
||||
ui->lw_references->clear();
|
||||
@@ -111,7 +92,28 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(
|
||||
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
// create a context menu for the listview of the references
|
||||
createDeleteAction(ui->lw_references);
|
||||
connect(
|
||||
deleteAction, &QAction::triggered, this, &TaskFemConstraintTemperature::onReferenceDeleted);
|
||||
|
||||
connect(ui->lw_references,
|
||||
&QListWidget::currentItemChanged,
|
||||
this,
|
||||
&TaskFemConstraintTemperature::setSelection);
|
||||
connect(ui->lw_references,
|
||||
&QListWidget::itemClicked,
|
||||
this,
|
||||
&TaskFemConstraintTemperature::setSelection);
|
||||
connect(ui->rb_temperature, &QRadioButton::clicked, this, &TaskFemConstraintTemperature::Temp);
|
||||
connect(ui->rb_cflux, &QRadioButton::clicked, this, &TaskFemConstraintTemperature::Flux);
|
||||
|
||||
connect(ui->if_temperature,
|
||||
qOverload<double>(&QuantitySpinBox::valueChanged),
|
||||
this,
|
||||
&TaskFemConstraintTemperature::onTempCfluxChanged);
|
||||
|
||||
// Selection buttons
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
@@ -132,48 +134,22 @@ void TaskFemConstraintTemperature::updateUI()
|
||||
|
||||
void TaskFemConstraintTemperature::onTempCfluxChanged(double val)
|
||||
{
|
||||
Fem::ConstraintTemperature* pcConstraint =
|
||||
static_cast<Fem::ConstraintTemperature*>(ConstraintView->getObject());
|
||||
if (ui->rb_temperature->isChecked()) {
|
||||
pcConstraint->Temperature.setValue(val);
|
||||
}
|
||||
else {
|
||||
pcConstraint->CFlux.setValue(val);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskFemConstraintTemperature::Temp()
|
||||
{
|
||||
Fem::ConstraintTemperature* pcConstraint =
|
||||
static_cast<Fem::ConstraintTemperature*>(ConstraintView->getObject());
|
||||
std::string name = ConstraintView->getObject()->getNameInDocument();
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.ConstraintType = %s",
|
||||
name.c_str(),
|
||||
get_constraint_type().c_str());
|
||||
std::string str = "Temperature";
|
||||
QString qstr = QString::fromStdString(str);
|
||||
ui->lbl_type->setText(qstr);
|
||||
Base::Quantity t = Base::Quantity(300, Base::Unit::Temperature);
|
||||
ui->if_temperature->setValue(t);
|
||||
pcConstraint->Temperature.setValue(300);
|
||||
ui->if_temperature->setUnit(pcConstraint->Temperature.getUnit());
|
||||
ui->if_temperature->setValue(pcConstraint->Temperature.getQuantityValue());
|
||||
}
|
||||
|
||||
void TaskFemConstraintTemperature::Flux()
|
||||
{
|
||||
Fem::ConstraintTemperature* pcConstraint =
|
||||
static_cast<Fem::ConstraintTemperature*>(ConstraintView->getObject());
|
||||
std::string name = ConstraintView->getObject()->getNameInDocument();
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.ConstraintType = %s",
|
||||
name.c_str(),
|
||||
get_constraint_type().c_str());
|
||||
std::string str = "Concentrated heat flux";
|
||||
QString qstr = QString::fromStdString(str);
|
||||
ui->lbl_type->setText(qstr);
|
||||
Base::Quantity c = Base::Quantity(0, Base::Unit::Power);
|
||||
ui->if_temperature->setValue(c);
|
||||
pcConstraint->CFlux.setValue(0);
|
||||
ui->if_temperature->setUnit(pcConstraint->CFlux.getUnit());
|
||||
ui->if_temperature->setValue(pcConstraint->CFlux.getQuantityValue());
|
||||
}
|
||||
|
||||
void TaskFemConstraintTemperature::addToSelection()
|
||||
@@ -302,20 +278,21 @@ const std::string TaskFemConstraintTemperature::getReferences() const
|
||||
return TaskFemConstraint::getReferences(items);
|
||||
}
|
||||
|
||||
double TaskFemConstraintTemperature::get_temperature() const {
|
||||
Base::Quantity temperature = ui->if_temperature->getQuantity();
|
||||
double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin);
|
||||
return temperature_in_kelvin;
|
||||
std::string TaskFemConstraintTemperature::get_temperature() const
|
||||
{
|
||||
return ui->if_temperature->value().getSafeUserString().toStdString();
|
||||
}
|
||||
|
||||
double TaskFemConstraintTemperature::get_cflux() const {
|
||||
Base::Quantity cflux = ui->if_temperature->getQuantity();
|
||||
double cflux_in_watt = cflux.getValueAs(Base::Quantity::Watt);
|
||||
return cflux_in_watt;
|
||||
std::string TaskFemConstraintTemperature::get_cflux() const
|
||||
{
|
||||
return ui->if_temperature->value().getSafeUserString().toStdString();
|
||||
}
|
||||
|
||||
std::string TaskFemConstraintTemperature::get_constraint_type() const {
|
||||
Fem::ConstraintTemperature* pcConstraint =
|
||||
static_cast<Fem::ConstraintTemperature*>(ConstraintView->getObject());
|
||||
std::string type;
|
||||
|
||||
if (ui->rb_temperature->isChecked()) {
|
||||
type = "\"Temperature\"";
|
||||
}
|
||||
@@ -385,7 +362,23 @@ bool TaskDlgFemConstraintTemperature::accept()
|
||||
const TaskFemConstraintTemperature* parameterTemperature =
|
||||
static_cast<const TaskFemConstraintTemperature*>(parameter);
|
||||
|
||||
auto type = parameterTemperature->get_constraint_type();
|
||||
|
||||
try {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.ConstraintType = %s",
|
||||
name.c_str(),
|
||||
parameterTemperature->get_constraint_type().c_str());
|
||||
if (type == "Temperature")
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.Temperature = \"%s\"",
|
||||
name.c_str(),
|
||||
parameterTemperature->get_temperature().c_str());
|
||||
else if (type == "CFlux")
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.CFlux = \"%s\"",
|
||||
name.c_str(),
|
||||
parameterTemperature->get_cflux().c_str());
|
||||
std::string scale = parameterTemperature->getScale();// OvG: determine modified scale
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.Scale = %s",
|
||||
|
||||
@@ -47,8 +47,8 @@ public:
|
||||
explicit TaskFemConstraintTemperature(ViewProviderFemConstraintTemperature *ConstraintView,QWidget *parent = nullptr);
|
||||
~TaskFemConstraintTemperature() override;
|
||||
const std::string getReferences() const override;
|
||||
double get_temperature()const;
|
||||
double get_cflux() const;
|
||||
std::string get_temperature() const;
|
||||
std::string get_cflux() const;
|
||||
std::string get_constraint_type() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
@@ -82,15 +82,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::InputField" name="if_temperature">
|
||||
<property name="text">
|
||||
<string>300 K</string>
|
||||
</property>
|
||||
<widget class="Gui::QuantitySpinBox" name="if_temperature">
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">K</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>300.000000000000000</double>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -100,9 +97,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/>
|
||||
|
||||
@@ -25,6 +25,8 @@ __title__ = "FreeCAD FEM calculix constraint initialtemperature"
|
||||
__author__ = "Bernd Hahnebach"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
|
||||
import FreeCAD
|
||||
|
||||
|
||||
def get_analysis_types():
|
||||
return ["thermomech"]
|
||||
@@ -46,7 +48,12 @@ def write_constraint(f, femobj, inittemp_obj, ccxwriter):
|
||||
|
||||
# floats read from ccx should use {:.13G}, see comment in writer module
|
||||
|
||||
f.write("{},{:.13G}\n".format(ccxwriter.ccx_nall, inittemp_obj.initialTemperature))
|
||||
f.write(
|
||||
"{},{}\n".format(
|
||||
ccxwriter.ccx_nall,
|
||||
FreeCAD.Units.Quantity(inittemp_obj.initialTemperature.getValueAs("K"))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Should only be one object in the analysis
|
||||
|
||||
@@ -25,6 +25,8 @@ __title__ = "FreeCAD FEM calculix constraint temperature"
|
||||
__author__ = "Bernd Hahnebach"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
|
||||
import FreeCAD
|
||||
|
||||
|
||||
def get_analysis_types():
|
||||
return ["thermomech"]
|
||||
@@ -68,12 +70,19 @@ def write_constraint(f, femobj, temp_obj, ccxwriter):
|
||||
NumberOfNodes = len(femobj["Nodes"])
|
||||
if temp_obj.ConstraintType == "Temperature":
|
||||
f.write("*BOUNDARY\n")
|
||||
f.write("{},11,11,{:.13G}\n".format(temp_obj.Name, temp_obj.Temperature))
|
||||
f.write(
|
||||
"{},11,11,{}\n".format(
|
||||
temp_obj.Name, FreeCAD.Units.Quantity(temp_obj.Temperature.getValueAs("K"))
|
||||
)
|
||||
)
|
||||
f.write("\n")
|
||||
elif temp_obj.ConstraintType == "CFlux":
|
||||
f.write("*CFLUX\n")
|
||||
f.write("{},11,{:.13G}\n".format(
|
||||
temp_obj.Name,
|
||||
temp_obj.CFlux * 0.001 / NumberOfNodes
|
||||
))
|
||||
# CFLUX has to be specified in mW
|
||||
f.write(
|
||||
"{},11,{}\n".format(
|
||||
temp_obj.Name,
|
||||
FreeCAD.Units.Quantity(temp_obj.CFlux.getValueAs("mW")) / NumberOfNodes
|
||||
)
|
||||
)
|
||||
f.write("\n")
|
||||
|
||||
@@ -186,7 +186,7 @@ class DeformationWriter:
|
||||
# temperature
|
||||
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if tempObj is not None:
|
||||
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
|
||||
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
|
||||
for name in bodies:
|
||||
self.write.material(name, "Reference Temperature", refTemp)
|
||||
# get the material data for all bodies
|
||||
|
||||
@@ -402,7 +402,7 @@ class ElasticityWriter:
|
||||
# temperature
|
||||
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if tempObj is not None:
|
||||
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
|
||||
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
|
||||
for name in bodies:
|
||||
self.write.material(name, "Reference Temperature", refTemp)
|
||||
# get the material data for all bodies
|
||||
|
||||
@@ -126,7 +126,7 @@ class Flowwriter:
|
||||
def handleFlowMaterial(self, bodies):
|
||||
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if tempObj is not None:
|
||||
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
|
||||
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
|
||||
for name in bodies:
|
||||
self.write.material(name, "Reference Temperature", refTemp)
|
||||
for obj in self.write.getMember("App::MaterialObject"):
|
||||
|
||||
@@ -103,12 +103,10 @@ class Heatwriter:
|
||||
if obj.References:
|
||||
for name in obj.References[0][1]:
|
||||
if obj.ConstraintType == "Temperature":
|
||||
temp = self.write.getFromUi(obj.Temperature, "K", "O")
|
||||
self.write.boundary(name, "Temperature", temp)
|
||||
temperature = float(obj.Temperature.getValueAs("K"))
|
||||
self.write.boundary(name, "Temperature", temperature)
|
||||
elif obj.ConstraintType == "CFlux":
|
||||
# the CFLUX property stores the value in µW
|
||||
# but the unit system is not aware of µW, only of mW
|
||||
flux = 0.001 * self.write.getFromUi(obj.CFlux, "mW", "M*L^2*T^-3")
|
||||
flux = float(obj.CFlux.getValueAs("W"))
|
||||
# CFLUX is the flux per mesh node
|
||||
flux = flux / NumberOfNodes
|
||||
self.write.boundary(name, "Temperature Load", flux)
|
||||
@@ -128,12 +126,12 @@ class Heatwriter:
|
||||
self.write.handled(obj)
|
||||
|
||||
def handleHeatInitial(self, bodies):
|
||||
obj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if obj is not None:
|
||||
for name in bodies:
|
||||
temp = self.write.getFromUi(obj.initialTemperature, "K", "O")
|
||||
self.write.initial(name, "Temperature", temp)
|
||||
self.write.handled(obj)
|
||||
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if tempObj is not None:
|
||||
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
|
||||
for name in bodies:
|
||||
self.write.initial(name, "Temperature", refTemp)
|
||||
self.write.handled(tempObj)
|
||||
|
||||
def _outputHeatBodyForce(self, obj, name):
|
||||
heatSource = self.write.getFromUi(obj.HeatSource, "W/kg", "L^2*T^-3")
|
||||
@@ -165,7 +163,7 @@ class Heatwriter:
|
||||
def handleHeatMaterial(self, bodies):
|
||||
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
|
||||
if tempObj is not None:
|
||||
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
|
||||
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
|
||||
for name in bodies:
|
||||
self.write.material(name, "Reference Temperature", refTemp)
|
||||
for obj in self.write.getMember("App::MaterialObject"):
|
||||
|
||||
@@ -7070,7 +7070,7 @@ Evolumes
|
||||
** Initial temperature constraint
|
||||
*INITIAL CONDITIONS,TYPE=TEMPERATURE
|
||||
** ConstraintInitialTemperature
|
||||
Nall,273
|
||||
Nall,273.0
|
||||
|
||||
***********************************************************
|
||||
** Sections
|
||||
@@ -7096,11 +7096,11 @@ ConstraintFixed,3
|
||||
** Fixed temperature constraint applied
|
||||
** ConstraintTemperatureHot
|
||||
*BOUNDARY
|
||||
ConstraintTemperatureHot,11,11,373
|
||||
ConstraintTemperatureHot,11,11,373.0
|
||||
|
||||
** ConstraintTemperatureNormal
|
||||
*BOUNDARY
|
||||
ConstraintTemperatureNormal,11,11,273
|
||||
ConstraintTemperatureNormal,11,11,273.0
|
||||
|
||||
|
||||
***********************************************************
|
||||
|
||||
@@ -123,7 +123,7 @@ Evolumes
|
||||
** Initial temperature constraint
|
||||
*INITIAL CONDITIONS,TYPE=TEMPERATURE
|
||||
** FemConstraintInitialTemperature
|
||||
Nall,300
|
||||
Nall,300.0
|
||||
|
||||
***********************************************************
|
||||
** Sections
|
||||
|
||||
Reference in New Issue
Block a user