Skip to content

Commit

Permalink
FEM: Implement constraint displacement in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
ovginkel committed Feb 12, 2016
1 parent 6a10349 commit b1dc2cb
Show file tree
Hide file tree
Showing 30 changed files with 2,277 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Fem/App/AppFem.cpp
Expand Up @@ -50,6 +50,7 @@
#include "FemConstraintPressure.h"
#include "FemConstraintGear.h"
#include "FemConstraintPulley.h"
#include "FemConstraintDisplacement.h"

#include "FemResultObject.h"
#include "FemSolverObject.h"
Expand Down Expand Up @@ -138,6 +139,7 @@ PyMODINIT_FUNC initFem()
Fem::ConstraintPressure ::init();
Fem::ConstraintGear ::init();
Fem::ConstraintPulley ::init();
Fem::ConstraintDisplacement ::init();

Fem::FemResultObject ::init();
Fem::FemResultObjectPython ::init();
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Fem/App/CMakeLists.txt
Expand Up @@ -110,6 +110,7 @@ SET(FemScripts_SRCS
MechanicalMaterial.py
SelectionObserverFem.py
TestFem.py
ccxInpWriterFemConstraintDisplacement.py

TaskPanelFemBeamSection.ui
TaskPanelFemShellThickness.ui
Expand Down Expand Up @@ -184,6 +185,8 @@ SET(FemConstraints_SRCS
FemConstraintGear.h
FemConstraintPulley.cpp
FemConstraintPulley.h
FemConstraintDisplacement.h
FemConstraintDisplacement.cpp
)
SOURCE_GROUP("Constraints" FILES ${FemConstraints_SRCS})

Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Fem/App/FemConstraint.cpp
Expand Up @@ -173,9 +173,9 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
normals.push_back(NormalDirection.getValue());
//OvG: Scale by whole object mass in case of a vertex
GProp_GProps props;
BRepGProp::VolumeProperties(toposhape._Shape, props);
double lx = props.Mass();
*scale = this->calcDrawScaleFactor(sqrt(lx)); //OvG: setup draw scale for constraint
BRepGProp::VolumeProperties(toposhape._Shape, props);
double lx = props.Mass();
*scale = this->calcDrawScaleFactor(sqrt(lx)*0.5); //OvG: setup draw scale for constraint
} else if (sh.ShapeType() == TopAbs_EDGE) {
BRepAdaptor_Curve curve(TopoDS::Edge(sh));
double fp = curve.FirstParameter();
Expand All @@ -185,7 +185,7 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
double l = props.Mass();
// Create points with 10 units distance, but at least one at the beginning and end of the edge
int steps;
if (l >= 100) //OvG: Increase 10 units distance proportionately to l for larger objects.
if (l >= 30) //OvG: Increase 10 units distance proportionately to l for larger objects.
{
*scale = this->calcDrawScaleFactor(l); //OvG: setup draw scale for constraint
steps = (int)round(l / (10*( *scale)));
Expand Down Expand Up @@ -232,7 +232,7 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
isoc.Load(GeomAbs_IsoV, ulp);
double lu = (l + GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion()))/2.0;
int stepsv;
if (lv >= 100) //OvG: Increase 10 units distance proportionately to lv for larger objects.
if (lv >= 30) //OvG: Increase 10 units distance proportionately to lv for larger objects.
{
*scale = this->calcDrawScaleFactor(lv,lu); //OvG: setup draw scale for constraint
stepsv = (int)round(lv / (10*( *scale)));
Expand All @@ -250,7 +250,7 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
}
stepsv = stepsv>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:stepsv; //OvG: Place upper limit on number of steps
int stepsu;
if (lu >= 100) //OvG: Increase 10 units distance proportionately to lu for larger objects.
if (lu >= 30) //OvG: Increase 10 units distance proportionately to lu for larger objects.
{
*scale = this->calcDrawScaleFactor(lv,lu); //OvG: setup draw scale for constraint
stepsu = (int)round(lu / (10*( *scale)));
Expand Down
101 changes: 101 additions & 0 deletions src/Mod/Fem/App/FemConstraintDisplacement.cpp
@@ -0,0 +1,101 @@
/***************************************************************************
* Copyright (c) 2015 FreeCAD Developers *
* Authors: Michael Hindley <hindlemp@eskom.co.za> *
* Ruan Olwagen <olwager@eskom.co.za> *
* Oswald van Ginkel <vginkeo@eskom.co.za> *
* Based on Force constraint by Jan Rheinländer *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <Precision.hxx>
#include <TopoDS.hxx>
#include <gp_Lin.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#endif

#include "FemConstraintDisplacement.h"

using namespace Fem;

PROPERTY_SOURCE(Fem::ConstraintDisplacement, Fem::Constraint);

ConstraintDisplacement::ConstraintDisplacement()
{
ADD_PROPERTY(xDisplacement,(0.0));
ADD_PROPERTY(yDisplacement,(0.0));
ADD_PROPERTY(zDisplacement,(0.0));
ADD_PROPERTY(xRotation,(0.0));
ADD_PROPERTY(yRotation,(0.0));
ADD_PROPERTY(zRotation,(0.0));
ADD_PROPERTY(xFree,(1));
ADD_PROPERTY(yFree,(1));
ADD_PROPERTY(zFree,(1));
ADD_PROPERTY(xFix,(0));
ADD_PROPERTY(yFix,(0));
ADD_PROPERTY(zFix,(0));
ADD_PROPERTY(rotxFree,(1));
ADD_PROPERTY(rotyFree,(1));
ADD_PROPERTY(rotzFree,(1));
ADD_PROPERTY(rotxFix,(0));
ADD_PROPERTY(rotyFix,(0));
ADD_PROPERTY(rotzFix,(0));

ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintFixed",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Points where symbols are drawn");
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintFixed",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>());
}

App::DocumentObjectExecReturn *ConstraintDisplacement::execute(void)
{
return Constraint::execute();
}

const char* ConstraintDisplacement::getViewProviderName(void) const
{
return "FemGui::ViewProviderFemConstraintDisplacement";
}

void ConstraintDisplacement::onChanged(const App::Property* prop)
{
// Note: If we call this at the end, then the arrows are not oriented correctly initially
// because the NormalDirection has not been calculated yet
Constraint::onChanged(prop);

if (prop == &References) {
std::vector<Base::Vector3d> points;
std::vector<Base::Vector3d> normals;
int scale = 1; //OvG: Enforce use of scale
if (getPoints(points, normals, &scale)) {
Points.setValues(points);
Normals.setValues(normals);
Scale.setValue(scale); //OvG: Scale
Points.touch(); // This triggers ViewProvider::updateData()
}
}
}
82 changes: 82 additions & 0 deletions src/Mod/Fem/App/FemConstraintDisplacement.h
@@ -0,0 +1,82 @@
/***************************************************************************
* Copyright (c) 2015 FreeCAD Developers *
* Authors: Michael Hindley <hindlemp@eskom.co.za> *
* Ruan Olwagen <olwager@eskom.co.za> *
* Oswald van Ginkel <vginkeo@eskom.co.za> *
* Based on Force constraint by Jan Rheinländer *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#ifndef FEM_CONSTRAINTDISPLACEMENT_H
#define FEM_CONSTRAINTDISPLACEMENT_H

#include "FemConstraint.h"

namespace Fem
{

class AppFemExport ConstraintDisplacement : public Fem::Constraint
{
PROPERTY_HEADER(Fem::ConstraintDisplacement);

public:
/// Constructor
ConstraintDisplacement(void);

// Read-only (calculated values). These trigger changes in the ViewProvider
App::PropertyVectorList Points;
App::PropertyVectorList Normals;

//Displacement parameters
App::PropertyFloat xDisplacement;
App::PropertyFloat yDisplacement;
App::PropertyFloat zDisplacement;
App::PropertyFloat xRotation;
App::PropertyFloat yRotation;
App::PropertyFloat zRotation;
App::PropertyBool xFree;
App::PropertyBool yFree;
App::PropertyBool zFree;
App::PropertyBool xFix;
App::PropertyBool yFix;
App::PropertyBool zFix;
App::PropertyBool rotxFree;
App::PropertyBool rotyFree;
App::PropertyBool rotzFree;
App::PropertyBool rotxFix;
App::PropertyBool rotyFix;
App::PropertyBool rotzFix;
//App::PropertyBool element;

/// recalculate the object
virtual App::DocumentObjectExecReturn *execute(void);

/// returns the type name of the ViewProvider
const char* getViewProviderName(void) const;

protected:
virtual void onChanged(const App::Property* prop);

};

} //namespace Fem


#endif // FEM_CONSTRAINTDISPLACEMENT_H
3 changes: 3 additions & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -11,6 +11,8 @@ INSTALL(
Init.py
InitGui.py

ccxInpWriterFemConstraintDisplacement.py

convert2TetGen.py

SelectionObserverFem.py
Expand All @@ -28,6 +30,7 @@ INSTALL(

_CommandMechanicalShowResult.py
_TaskPanelResultControl.py

TaskPanelShowDisplacement.ui

_FemAnalysis.py
Expand Down
24 changes: 24 additions & 0 deletions src/Mod/Fem/FemCommands.py
Expand Up @@ -97,3 +97,27 @@ def analysis_has_solver(self):
return True
else:
return False

def hide_parts_constraints_show_meshes(self):
if FreeCAD.GuiUp:
for acnstrmesh in FreeCAD.activeDocument().Objects:
if "Constraint" in acnstrmesh.TypeId:
acnstrmesh.ViewObject.Visibility = False
if "Mesh" in acnstrmesh.TypeId:
aparttoshow = acnstrmesh.Name.replace("_Mesh","")
for apart in FreeCAD.activeDocument().Objects:
if aparttoshow == apart.Name:
apart.ViewObject.Visibility = False
acnstrmesh.ViewObject.Visibility = True #OvG: Hide constraints and parts and show meshes

def hide_meshes_show_parts_constraints(self):
if FreeCAD.GuiUp:
for acnstrmesh in FreeCAD.activeDocument().Objects:
if "Constraint" in acnstrmesh.TypeId:
acnstrmesh.ViewObject.Visibility = True
if "Mesh" in acnstrmesh.TypeId:
aparttoshow = acnstrmesh.Name.replace("_Mesh","")
for apart in FreeCAD.activeDocument().Objects:
if aparttoshow == apart.Name:
apart.ViewObject.Visibility = True
acnstrmesh.ViewObject.Visibility = False #OvG: Hide meshes and show constraints and meshed part e.g. on purging results
15 changes: 12 additions & 3 deletions src/Mod/Fem/FemTools.py
Expand Up @@ -175,13 +175,17 @@ def update_objects(self):
# Individual constraints are "Fem::ConstraintPressure" type
self.pressure_constraints = []
## @var beam_sections
# set of beam sections from the analyis. Updated with update_objects
# set of beam sections from the analysis. Updated with update_objects
# Individual beam sections are Proxy.Type "FemBeamSection"
self.beam_sections = []
## @var shell_thicknesses
# set of shell thicknesses from the analyis. Updated with update_objects
# set of shell thicknesses from the analysis. Updated with update_objects
# Individual shell thicknesses are Proxy.Type "FemShellThickness"
self.shell_thicknesses = []
## @var displacement_constraints
# set of displacements for the analysis. Updated with update_objects
# Individual displacement_constraints are Proxy.Type "FemConstraintDisplacement"
self.displacement_constraints = []

for m in self.analysis.Member:
if m.isDerivedFrom("Fem::FemSolverObjectPython"):
Expand Down Expand Up @@ -210,6 +214,10 @@ def update_objects(self):
PressureObjectDict = {}
PressureObjectDict['Object'] = m
self.pressure_constraints.append(PressureObjectDict)
elif m.isDerivedFrom("Fem::ConstraintDisplacement"): #OvG: Replacement reference to C++ implementation of Displacement Constraint
displacement_constraint_dict = {}
displacement_constraint_dict['Object'] = m
self.displacement_constraints.append(displacement_constraint_dict)
elif hasattr(m, "Proxy") and m.Proxy.Type == "FemBeamSection":
beam_section_dict = {}
beam_section_dict['Object'] = m
Expand Down Expand Up @@ -240,7 +248,7 @@ def check_prerequisites(self):
if has_no_references is True:
message += "More than one Material has empty References list (Only one empty References list is allowed!).\n"
has_no_references = True
if not self.fixed_constraints:
if not (self.fixed_constraints):
message += "No fixed-constraint nodes defined in the Analysis\n"
if self.analysis_type == "static":
if not (self.force_constraints or self.pressure_constraints):
Expand Down Expand Up @@ -269,6 +277,7 @@ def write_inp_file(self):
inp_writer = iw.inp_writer(self.analysis, self.mesh, self.materials,
self.fixed_constraints,
self.force_constraints, self.pressure_constraints,
self.displacement_constraints, #OvG: Stick to naming convention
self.beam_sections, self.shell_thicknesses,
self.analysis_type, self.eigenmode_parameters,
self.working_dir)
Expand Down

0 comments on commit b1dc2cb

Please sign in to comment.