[FEM] activate spring constraint
- the spring constraint is currently unused but it can be used for Elmer mechanical analyses This PR does so and also overhaul the dialog UI. - use the spring constraint also in an example file
This commit is contained in:
@@ -26,25 +26,31 @@
|
||||
#include "FemConstraintSpring.h"
|
||||
|
||||
|
||||
static const char* Stiffnesses[] = {"Normal Stiffness",
|
||||
"Tangential Stiffness", nullptr};
|
||||
|
||||
using namespace Fem;
|
||||
|
||||
PROPERTY_SOURCE(Fem::ConstraintSpring, Fem::Constraint)
|
||||
|
||||
ConstraintSpring::ConstraintSpring()
|
||||
{
|
||||
ADD_PROPERTY(normalStiffness,(0.0));
|
||||
ADD_PROPERTY(tangentialStiffness,(0.0));
|
||||
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintSpring",
|
||||
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
ADD_PROPERTY(NormalStiffness, (0.0));
|
||||
ADD_PROPERTY(TangentialStiffness, (0.0));
|
||||
ADD_PROPERTY(ElmerStiffness, (1));
|
||||
ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintSpring",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Points where arrows are drawn");
|
||||
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintSpring",
|
||||
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
|
||||
ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintSpring",
|
||||
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
|
||||
"Normals where symbols are drawn");
|
||||
|
||||
ElmerStiffness.setEnums(Stiffnesses);
|
||||
Points.setValues(std::vector<Base::Vector3d>());
|
||||
Normals.setValues(std::vector<Base::Vector3d>());
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ConstraintSpring::execute()
|
||||
App::DocumentObjectExecReturn* ConstraintSpring::execute()
|
||||
{
|
||||
return Constraint::execute();
|
||||
}
|
||||
|
||||
@@ -36,8 +36,9 @@ class FemExport ConstraintSpring : public Fem::Constraint
|
||||
public:
|
||||
ConstraintSpring();
|
||||
|
||||
App::PropertyFloat normalStiffness;
|
||||
App::PropertyFloat tangentialStiffness;
|
||||
App::PropertyStiffness NormalStiffness;
|
||||
App::PropertyStiffness TangentialStiffness;
|
||||
App::PropertyEnumeration ElmerStiffness;
|
||||
App::PropertyVectorList Points;
|
||||
App::PropertyVectorList Normals;
|
||||
|
||||
|
||||
@@ -854,10 +854,10 @@ void CmdFemConstraintSpring::activated(int)
|
||||
doCommand(
|
||||
Doc, "App.activeDocument().addObject(\"Fem::ConstraintSpring\",\"%s\")", FeatName.c_str());
|
||||
doCommand(Doc,
|
||||
"App.activeDocument().%s.normalStiffness = 1.0",
|
||||
"App.activeDocument().%s.NormalStiffness = 1.0",
|
||||
FeatName.c_str());//OvG: set default not equal to 0
|
||||
doCommand(Doc,
|
||||
"App.activeDocument().%s.tangentialStiffness = 0.0",
|
||||
"App.activeDocument().%s.TangentialStiffness = 0.0",
|
||||
FeatName.c_str());//OvG: set default to False
|
||||
doCommand(
|
||||
Doc, "App.activeDocument().%s.Scale = 1", FeatName.c_str());//OvG: set initial scale to 1
|
||||
|
||||
@@ -489,7 +489,6 @@ std::string TaskFemConstraintDisplacement::get_zFormula() const
|
||||
QString zFormula = ui->DisplacementZFormulaLE->text();
|
||||
zFormula.replace(QString::fromLatin1("\""), QString::fromLatin1("\\\""));
|
||||
return zFormula.toStdString();
|
||||
;
|
||||
}
|
||||
|
||||
bool TaskFemConstraintDisplacement::get_dispxfix() const
|
||||
|
||||
@@ -114,11 +114,8 @@ void initComboBox(QComboBox* combo, const std::vector<std::string>& textItems,
|
||||
combo->clear();
|
||||
for (unsigned int it = 0; it < textItems.size(); it++) {
|
||||
combo->insertItem(it, Base::Tools::fromStdString(textItems[it]));
|
||||
if (sItem == textItems[it]) {
|
||||
if (sItem == textItems[it])
|
||||
iItem = it;
|
||||
// Base::Console().Warning("Found the subtype and set the current index as %d for
|
||||
// subtype %s ComboBox\n", it, sItem);
|
||||
}
|
||||
}
|
||||
combo->setCurrentIndex(iItem);
|
||||
combo->blockSignals(false);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/SelectionObject.h>
|
||||
#include <Mod/Fem/App/FemConstraintSpring.h>
|
||||
@@ -71,22 +72,30 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring
|
||||
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
|
||||
|
||||
// Fill data into dialog elements
|
||||
ui->if_norm->setUnit(pcConstraint->NormalStiffness.getUnit());
|
||||
ui->if_norm->setMinimum(
|
||||
0);// TODO fix this -------------------------------------------------------------------
|
||||
ui->if_norm->setMaximum(FLOAT_MAX);
|
||||
Base::Quantity ns =
|
||||
Base::Quantity((pcConstraint->normalStiffness.getValue()), Base::Unit::Stiffness);
|
||||
Base::Quantity((pcConstraint->NormalStiffness.getValue()), Base::Unit::Stiffness);
|
||||
ui->if_norm->setValue(ns);
|
||||
|
||||
// Fill data into dialog elements
|
||||
ui->if_tan->setUnit(pcConstraint->TangentialStiffness.getUnit());
|
||||
ui->if_tan->setMinimum(
|
||||
0);// TODO fix this -------------------------------------------------------------------
|
||||
ui->if_tan->setMaximum(FLOAT_MAX);
|
||||
Base::Quantity ts =
|
||||
Base::Quantity((pcConstraint->tangentialStiffness.getValue()), Base::Unit::Stiffness);
|
||||
Base::Quantity((pcConstraint->TangentialStiffness.getValue()), Base::Unit::Stiffness);
|
||||
ui->if_tan->setValue(ts);
|
||||
|
||||
/* */
|
||||
ui->ElmerStiffnessCB->clear();
|
||||
auto stiffnesses = pcConstraint->ElmerStiffness.getEnumVector();
|
||||
QStringList stiffnessesList;
|
||||
for (auto item : stiffnesses) {
|
||||
stiffnessesList << QLatin1String(item.c_str());
|
||||
}
|
||||
ui->ElmerStiffnessCB->addItems(stiffnessesList);
|
||||
ui->ElmerStiffnessCB->setCurrentIndex(pcConstraint->ElmerStiffness.getValue());
|
||||
|
||||
ui->lw_references->clear();
|
||||
for (std::size_t i = 0; i < Objects.size(); i++) {
|
||||
@@ -96,7 +105,7 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring
|
||||
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
// Selection buttons
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
@@ -245,21 +254,20 @@ const std::string TaskFemConstraintSpring::getReferences() const
|
||||
return TaskFemConstraint::getReferences(items);
|
||||
}
|
||||
|
||||
/* Note: */
|
||||
double TaskFemConstraintSpring::get_normalStiffness() const
|
||||
std::string TaskFemConstraintSpring::get_normalStiffness() const
|
||||
{
|
||||
Base::Quantity stiffness = ui->if_norm->getQuantity();
|
||||
double stiffness_double = stiffness.getValueAs(Base::Quantity::NewtonPerMeter);
|
||||
return stiffness_double;
|
||||
return ui->if_norm->value().getSafeUserString().toStdString();
|
||||
}
|
||||
|
||||
double TaskFemConstraintSpring::get_tangentialStiffness() const
|
||||
std::string TaskFemConstraintSpring::get_tangentialStiffness() const
|
||||
{
|
||||
Base::Quantity stiffness = ui->if_tan->getQuantity();
|
||||
double stiffness_double = stiffness.getValueAs(Base::Quantity::NewtonPerMeter);
|
||||
return stiffness_double;
|
||||
return ui->if_tan->value().getSafeUserString().toStdString();
|
||||
}
|
||||
|
||||
std::string TaskFemConstraintSpring::getElmerStiffness() const
|
||||
{
|
||||
return Base::Tools::toStdString(ui->ElmerStiffnessCB->currentText());
|
||||
}
|
||||
|
||||
bool TaskFemConstraintSpring::event(QEvent* e)
|
||||
{
|
||||
@@ -320,13 +328,17 @@ bool TaskDlgFemConstraintSpring::accept()
|
||||
|
||||
try {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.normalStiffness = %f",
|
||||
"App.ActiveDocument.%s.NormalStiffness = \"%s\"",
|
||||
name.c_str(),
|
||||
parameterStiffness->get_normalStiffness());
|
||||
parameterStiffness->get_normalStiffness().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.tangentialStiffness = %f",
|
||||
"App.ActiveDocument.%s.TangentialStiffness = \"%s\"",
|
||||
name.c_str(),
|
||||
parameterStiffness->get_tangentialStiffness());
|
||||
parameterStiffness->get_tangentialStiffness().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.ElmerStiffness = '%s'",
|
||||
name.c_str(),
|
||||
parameterStiffness->getElmerStiffness().c_str());
|
||||
std::string scale = parameterStiffness->getScale();// OvG: determine modified scale
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.Scale = %s",
|
||||
|
||||
@@ -43,8 +43,9 @@ public:
|
||||
QWidget* parent = nullptr);
|
||||
~TaskFemConstraintSpring() override;
|
||||
const std::string getReferences() const override;
|
||||
double get_normalStiffness()const;
|
||||
double get_tangentialStiffness()const;
|
||||
std::string get_normalStiffness() const;
|
||||
std::string get_tangentialStiffness() const;
|
||||
std::string getElmerStiffness() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onReferenceDeleted();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>191</height>
|
||||
<height>217</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -59,40 +59,17 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lw_references">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
<width>16777215</width>
|
||||
<height>75</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_1">
|
||||
<property name="text">
|
||||
<string>Normal Stiffness</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::InputField" name="if_norm">
|
||||
<property name="text">
|
||||
<string notr="true">0 </string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@@ -105,28 +82,51 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::InputField" name="if_tan">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="if_tan">
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_1">
|
||||
<property name="text">
|
||||
<string>Normal Stiffness</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="if_norm">
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Stiffness for Elmer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="ElmerStiffnessCB">
|
||||
<property name="toolTip">
|
||||
<string>What stiffness should be
|
||||
used for the Elmer solver</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</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/>
|
||||
|
||||
@@ -41,7 +41,7 @@ def get_information():
|
||||
"name": "Deformation (nonlinear elasticity) - Elmer",
|
||||
"meshtype": "solid",
|
||||
"meshelement": "Tet10",
|
||||
"constraints": ["displacement"],
|
||||
"constraints": ["displacement", "spring"],
|
||||
"solvers": ["elmer"],
|
||||
"material": "solid",
|
||||
"equations": ["deformation"]
|
||||
@@ -166,6 +166,19 @@ def setup(doc=None, solvertype="elmer"):
|
||||
DisplaceRight.References = [(SpringObject, "Face5")]
|
||||
analysis.addObject(DisplaceRight)
|
||||
|
||||
# constraints spring
|
||||
StiffnessLeft = doc.addObject("Fem::ConstraintSpring", "StiffnessLeft")
|
||||
StiffnessLeft.TangentialStiffness = "50 N/m"
|
||||
StiffnessLeft.ElmerStiffness = "Tangential Stiffness"
|
||||
StiffnessLeft.References = [(SpringObject, "Face1")]
|
||||
analysis.addObject(StiffnessLeft)
|
||||
|
||||
StiffnessRight = doc.addObject("Fem::ConstraintSpring", "StiffnessRight")
|
||||
StiffnessRight.TangentialStiffness = "50 N/m"
|
||||
StiffnessRight.ElmerStiffness = "Tangential Stiffness"
|
||||
StiffnessRight.References = [(SpringObject, "Face5")]
|
||||
analysis.addObject(StiffnessRight)
|
||||
|
||||
# mesh
|
||||
femmesh_obj = analysis.addObject(ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
|
||||
femmesh_obj.Part = body
|
||||
|
||||
@@ -130,6 +130,15 @@ class DeformationWriter:
|
||||
displacement = obj.zDisplacementFormula
|
||||
self.write.boundary(name, "Displacement 3", displacement)
|
||||
self.write.handled(obj)
|
||||
for obj in self.write.getMember("Fem::ConstraintSpring"):
|
||||
if obj.References:
|
||||
for name in obj.References[0][1]:
|
||||
if obj.ElmerStiffness == "Normal Stiffness":
|
||||
spring = float(obj.NormalStiffness.getValueAs("N/m"))
|
||||
else:
|
||||
spring = float(obj.TangentialStiffness.getValueAs("N/m"))
|
||||
self.write.boundary(name, "Spring", spring)
|
||||
self.write.handled(obj)
|
||||
|
||||
def handleDeformationInitial(self, bodies):
|
||||
pass
|
||||
|
||||
@@ -346,6 +346,15 @@ class ElasticityWriter:
|
||||
displacement = obj.zDisplacementFormula
|
||||
self.write.boundary(name, "Displacement 3", displacement)
|
||||
self.write.handled(obj)
|
||||
for obj in self.write.getMember("Fem::ConstraintSpring"):
|
||||
if obj.References:
|
||||
for name in obj.References[0][1]:
|
||||
if obj.ElmerStiffness == "Normal Stiffness":
|
||||
spring = float(obj.NormalStiffness.getValueAs("N/m"))
|
||||
else:
|
||||
spring = float(obj.TangentialStiffness.getValueAs("N/m"))
|
||||
self.write.boundary(name, "Spring", spring)
|
||||
self.write.handled(obj)
|
||||
|
||||
def handleElasticityInitial(self, bodies):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user