Skip to content

Commit

Permalink
[FEM] fix pipeline recompute bug
Browse files Browse the repository at this point in the history
- on recomputing scalar or warp filters the information about the field was lost.
  This is because the validity of an array was tested before it is actually filled

- also fix MSVC warning of using a C++ keyword as variable
- also avoid an unnecessary recompute after Elmer solver was run
  • Loading branch information
donovaly committed Aug 7, 2022
1 parent c4547c0 commit 90afc19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
53 changes: 28 additions & 25 deletions src/Mod/Fem/App/FemPostFilter.cpp
Expand Up @@ -26,9 +26,10 @@
# include <vtkPointData.h>
#endif

#include <App/Document.h>

#include "FemPostFilter.h"
#include "FemPostPipeline.h"
#include <App/Document.h>


using namespace Fem;
Expand Down Expand Up @@ -455,10 +456,10 @@ FemPostScalarClipFilter::~FemPostScalarClipFilter() {
DocumentObjectExecReturn* FemPostScalarClipFilter::execute(void) {

std::string val;
if (m_scalarFields.hasEnums() && Scalars.getValue() >= 0)
if (Scalars.getValue() >= 0)
val = Scalars.getValueAsString();

std::vector<std::string> array;
std::vector<std::string> ScalarsArray;

vtkSmartPointer<vtkDataObject> data = getInputData();
if (!data || !data->IsA("vtkDataSet"))
Expand All @@ -467,18 +468,21 @@ DocumentObjectExecReturn* FemPostScalarClipFilter::execute(void) {
vtkDataSet* dset = vtkDataSet::SafeDownCast(data);
vtkPointData* pd = dset->GetPointData();

// get all scalar fields
for (int i = 0; i < pd->GetNumberOfArrays(); ++i) {
if (pd->GetArray(i)->GetNumberOfComponents() == 1)
array.emplace_back(pd->GetArrayName(i));
ScalarsArray.emplace_back(pd->GetArrayName(i));
}

App::Enumeration empty;
Scalars.setValue(empty);
m_scalarFields.setEnums(array);
m_scalarFields.setEnums(ScalarsArray);
Scalars.setValue(m_scalarFields);

std::vector<std::string>::iterator it = std::find(array.begin(), array.end(), val);
if (!val.empty() && it != array.end())
// search if the current field is in the available ones and set it
std::vector<std::string>::iterator it =
std::find(ScalarsArray.begin(), ScalarsArray.end(), val);
if (!val.empty() && it != ScalarsArray.end())
Scalars.setValue(val.c_str());

//recalculate the filter
Expand Down Expand Up @@ -506,11 +510,10 @@ short int FemPostScalarClipFilter::mustExecute(void) const {

if (Value.isTouched() ||
InsideOut.isTouched() ||
Scalars.isTouched()) {

Scalars.isTouched())
return 1;
}
else return App::DocumentObject::mustExecute();
else
return App::DocumentObject::mustExecute();
}

void FemPostScalarClipFilter::setConstraintForField() {
Expand Down Expand Up @@ -558,10 +561,10 @@ FemPostWarpVectorFilter::~FemPostWarpVectorFilter() {
DocumentObjectExecReturn* FemPostWarpVectorFilter::execute(void) {

std::string val;
if (m_vectorFields.hasEnums() && Vector.getValue() >= 0)
if (Vector.getValue() >= 0)
val = Vector.getValueAsString();

std::vector<std::string> array;
std::vector<std::string> VectorArray;

vtkSmartPointer<vtkDataObject> data = getInputData();
if (!data || !data->IsA("vtkDataSet"))
Expand All @@ -570,18 +573,21 @@ DocumentObjectExecReturn* FemPostWarpVectorFilter::execute(void) {
vtkDataSet* dset = vtkDataSet::SafeDownCast(data);
vtkPointData* pd = dset->GetPointData();

// get all vector fields
for (int i = 0; i < pd->GetNumberOfArrays(); ++i) {
if (pd->GetArray(i)->GetNumberOfComponents() == 3)
array.emplace_back(pd->GetArrayName(i));
VectorArray.emplace_back(pd->GetArrayName(i));
}

App::Enumeration empty;
Vector.setValue(empty);
m_vectorFields.setEnums(array);
m_vectorFields.setEnums(VectorArray);
Vector.setValue(m_vectorFields);

std::vector<std::string>::iterator it = std::find(array.begin(), array.end(), val);
if (!val.empty() && it != array.end())
// search if the current field is in the available ones and set it
std::vector<std::string>::iterator it =
std::find(VectorArray.begin(), VectorArray.end(), val);
if (!val.empty() && it != VectorArray.end())
Vector.setValue(val.c_str());

//recalculate the filter
Expand All @@ -590,25 +596,22 @@ DocumentObjectExecReturn* FemPostWarpVectorFilter::execute(void) {

void FemPostWarpVectorFilter::onChanged(const Property* prop) {

if (prop == &Factor) {
if (prop == &Factor)
m_warp->SetScaleFactor(Factor.getValue());
}
else if (prop == &Vector && (Vector.getValue() >= 0)) {
else if (prop == &Vector && (Vector.getValue() >= 0))
m_warp->SetInputArrayToProcess(0, 0, 0,
vtkDataObject::FIELD_ASSOCIATION_POINTS, Vector.getValueAsString());
}

Fem::FemPostFilter::onChanged(prop);
}

short int FemPostWarpVectorFilter::mustExecute(void) const {

if (Factor.isTouched() ||
Vector.isTouched()) {

Vector.isTouched())
return 1;
}
else return App::DocumentObject::mustExecute();
else
return App::DocumentObject::mustExecute();
}


Expand Down
1 change: 0 additions & 1 deletion src/Mod/Fem/femsolver/elmer/tasks.py
Expand Up @@ -255,7 +255,6 @@ def run(self):
# at the moment we scale the mesh back using Elmer
# this might be changed in future, therefore leave this
# self.solver.ElmerResult.scale(1000)
self.solver.ElmerResult.getLastPostObject().touch()
self.solver.ElmerResult.recomputeChildren()
self.solver.Document.recompute()

Expand Down

0 comments on commit 90afc19

Please sign in to comment.