Skip to content

Commit 82cdeca

Browse files
committed
Ensure Dirichlet boundary conditions at construction time
1 parent 7f50fab commit 82cdeca

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

source/pbat/sim/vbd/Data.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,13 @@ Data& Data::WithPartitions(std::vector<std::vector<Index>> const& partitionsIn)
7777
return *this;
7878
}
7979

80-
Data& Data::WithDirichletConstrainedVertices(
81-
IndexVectorX const& dbcIn,
82-
bool bDbcSorted,
83-
bool bPartitionsSorted)
80+
Data& Data::WithDirichletConstrainedVertices(IndexVectorX const& dbcIn, bool bDbcSorted)
8481
{
8582
this->dbc = dbcIn;
8683
if (not bDbcSorted)
8784
{
8885
std::sort(this->dbc.begin(), this->dbc.end());
8986
}
90-
for (auto& partition : partitions)
91-
{
92-
std::vector<Index> freePartition = partition;
93-
if (not bPartitionsSorted)
94-
{
95-
std::sort(partition.begin(), partition.end());
96-
}
97-
std::set_difference(
98-
partition.begin(),
99-
partition.end(),
100-
this->dbc.begin(),
101-
this->dbc.end(),
102-
freePartition.begin());
103-
std::swap(partition, freePartition);
104-
}
10587
return *this;
10688
}
10789

@@ -131,7 +113,6 @@ Data& Data::WithHessianDeterminantZeroUnder(Scalar zero)
131113

132114
Data& Data::Construct(bool bValidate)
133115
{
134-
// clang-format off
135116
if (xt.size() == 0)
136117
{
137118
xt = x;
@@ -160,8 +141,25 @@ Data& Data::Construct(bool bValidate)
160141
lame.row(0).setConstant(mu);
161142
lame.row(1).setConstant(lambda);
162143
}
144+
// Constrained vertices must not move
145+
v(Eigen::all, dbc).setZero();
146+
aext(Eigen::all, dbc).setZero();
147+
for (auto& partition : partitions)
148+
{
149+
std::vector<Index> freePartition = partition;
150+
std::sort(partition.begin(), partition.end());
151+
std::set_difference(
152+
partition.begin(),
153+
partition.end(),
154+
this->dbc.begin(),
155+
this->dbc.end(),
156+
freePartition.begin());
157+
std::swap(partition, freePartition);
158+
}
159+
163160
if (bValidate)
164161
{
162+
// clang-format off
165163
bool const bPerVertexQuantityDimensionsValid =
166164
x.cols() == xt.cols() and
167165
x.cols() == v.cols() and

source/pbat/sim/vbd/Data.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ PBAT_API struct Data
3030
Eigen::Ref<IndexVectorX const> const& GVGe,
3131
Eigen::Ref<IndexVectorX const> const& GVGilocal);
3232
Data& WithPartitions(std::vector<std::vector<Index>> const& partitions);
33-
Data& WithDirichletConstrainedVertices(
34-
IndexVectorX const& dbc,
35-
bool bDbcSorted = true,
36-
bool bPartitionsSorted = false);
33+
Data& WithDirichletConstrainedVertices(IndexVectorX const& dbc, bool bDbcSorted = true);
3734
Data& WithInitializationStrategy(EInitializationStrategy strategy);
3835
Data& WithRayleighDamping(Scalar kD);
3936
Data& WithCollisionPenalty(Scalar kC);

0 commit comments

Comments
 (0)