Skip to content

Commit 3d2f5bf

Browse files
authored
Merge pull request #213 from asartori86/constraints
allow for different constraint matrices for different matrices
2 parents ce186f5 + c0f49c1 commit 3d2f5bf

File tree

8 files changed

+63
-43
lines changed

8 files changed

+63
-43
lines changed

include/pidomus.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ class piDoMUS : public ParameterAcceptor
321321
shared_ptr<FiniteElement<dim, spacedim> > fe;
322322
shared_ptr<DoFHandler<dim, spacedim> > dof_handler;
323323

324-
ConstraintMatrix constraints;
325-
ConstraintMatrix constraints_dot;
324+
std::vector<shared_ptr<ConstraintMatrix> > train_constraints;
325+
ConstraintMatrix constraints_dot;
326326

327327
LinearOperator<typename LAC::VectorType> jacobian_preconditioner_op;
328328
LinearOperator<typename LAC::VectorType> jacobian_preconditioner_op_finer;

include/pidomus_signals.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ struct Signals
4545
* have been included. Note that ConstraintMatrix::close() will be called
4646
* after this signal, so no need to call it inside.
4747
*
48-
* The functions that can attach to this signal must take two
48+
* By default, all the shared_ptrs points to the same
49+
* ConstraintMatrix, which is constructed according to the boundary
50+
* conditions set in the parameter file.
51+
*
52+
* The functions that can attach to this signal must take a
53+
* std::vector<shared_ptr<ConstraintMatrix> > and a
4954
* ConstraintMatrix.
5055
*/
51-
boost::signals2::signal<void (ConstraintMatrix &constraints,
56+
boost::signals2::signal<void (std::vector<shared_ptr<ConstraintMatrix> > &constraints,
5257
ConstraintMatrix &constraints_dot)> update_constraint_matrices;
5358

5459
/**

source/pidomus.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ piDoMUS<dim, spacedim, LAC>::piDoMUS (const std::string &name,
5858

5959
pgr("Refinement"),
6060

61+
train_constraints(interface.n_matrices),
6162

6263
current_time(std::numeric_limits<double>::quiet_NaN()),
6364
// IDA calls residual first with alpha = 0
@@ -107,6 +108,10 @@ piDoMUS<dim, spacedim, LAC>::piDoMUS (const std::string &name,
107108
interface.initialize_simulator (*this);
108109
lambdas.set_functions_to_default();
109110
111+
train_constraints[0] = SP(new ConstraintMatrix());
112+
113+
for (unsigned int i=1; i<n_matrices; ++i)
114+
train_constraints[i] = train_constraints[0];
110115
111116
for (unsigned int i=0; i<n_matrices; ++i)
112117
{
@@ -130,6 +135,7 @@ piDoMUS<dim, spacedim, LAC>::piDoMUS (const std::string &name,
130135
131136
pgr("Refinement"),
132137
138+
train_constraints(interface.n_matrices),
133139
134140
current_time(std::numeric_limits<double>::quiet_NaN()),
135141
// IDA calls residual first with alpha = 0
@@ -179,6 +185,7 @@ piDoMUS<dim, spacedim, LAC>::piDoMUS (const std::string &name,
179185
interface.initialize_simulator (*this);
180186
lambdas.set_functions_to_default();
181187
188+
train_constraints[0] = SP(new ConstraintMatrix);
182189
183190
for (unsigned int i=0; i<n_matrices; ++i)
184191
{
@@ -207,7 +214,7 @@ void piDoMUS<dim, spacedim, LAC>::run ()
207214
else
208215
refine_mesh();
209216
210-
constraints.distribute(solution);
217+
train_constraints[0]->distribute(solution);
211218
constraints_dot.distribute(solution_dot);
212219
213220
if (time_stepper == "ida")
@@ -338,7 +345,7 @@ void piDoMUS<dim, spacedim, LAC>::setup_dofs (const bool &first_run)
338345
matrices[i]->clear();
339346
initializer(*matrix_sparsities[i],
340347
*dof_handler,
341-
constraints,
348+
*train_constraints[i],
342349
interface.get_matrix_coupling(i));
343350
matrices[i]->reinit(*matrix_sparsities[i]);
344351
}
@@ -353,8 +360,8 @@ void piDoMUS<dim, spacedim, LAC>::setup_dofs (const bool &first_run)
353360
else if (!we_are_parallel)
354361
{
355362
const QGauss<dim> quadrature_formula(fe->degree + 1);
356-
VectorTools::project(interface.get_project_mapping(), *dof_handler, constraints, quadrature_formula, initial_solution, solution);
357-
VectorTools::project(interface.get_project_mapping(), *dof_handler, constraints, quadrature_formula, initial_solution_dot, solution_dot);
363+
VectorTools::project(interface.get_project_mapping(), *dof_handler, *train_constraints[0], quadrature_formula, initial_solution, solution);
364+
VectorTools::project(interface.get_project_mapping(), *dof_handler, *train_constraints[0], quadrature_formula, initial_solution_dot, solution_dot);
358365
}
359366
else
360367
{

source/pidomus_assemble.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ void piDoMUS<dim, spacedim, LAC>::assemble_matrices (const double t,
8282
{
8383

8484
for (unsigned int i=0; i<n_matrices; ++i)
85-
this->constraints.distribute_local_to_global (data.local_matrices[i],
86-
data.local_dof_indices,
87-
*(this->matrices[i]));
85+
this->train_constraints[i]->distribute_local_to_global (data.local_matrices[i],
86+
data.local_dof_indices,
87+
*(this->matrices[i]));
8888
};
8989

9090
auto local_assemble = [ this ]
@@ -217,9 +217,9 @@ piDoMUS<dim, spacedim, LAC>::residual(const double t,
217217
auto local_copy = [&dst, this] (const pidomus::CopyData & data)
218218
{
219219

220-
this->constraints.distribute_local_to_global (data.local_residual,
221-
data.local_dof_indices,
222-
dst);
220+
this->train_constraints[0]->distribute_local_to_global (data.local_residual,
221+
data.local_dof_indices,
222+
dst);
223223
};
224224

225225
auto local_assemble = [ this ]
@@ -257,7 +257,7 @@ piDoMUS<dim, spacedim, LAC>::residual(const double t,
257257
for (unsigned int i = 0; i < id.n_elements(); ++i)
258258
{
259259
auto j = id.nth_index_in_set(i);
260-
if (constraints.is_constrained(j))
260+
if (train_constraints[0]->is_constrained(j))
261261
dst[j] = solution(j) - locally_relevant_solution(j);
262262
}
263263

source/pidomus_eigen.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void piDoMUS<dim, spacedim, LAC>::solve_eigenproblem()
7878
else
7979
refine_mesh();
8080

81-
constraints.distribute(solution);
81+
train_constraints[0]->distribute(solution);
8282
constraints_dot.distribute(solution_dot);
8383

8484
// initialize mass matrix
@@ -91,7 +91,7 @@ void piDoMUS<dim, spacedim, LAC>::solve_eigenproblem()
9191
mass_matrix.clear();
9292
initializer(mass_pattern,
9393
*dof_handler,
94-
constraints,
94+
*train_constraints[0],
9595
mass_coupling);
9696

9797
mass_matrix.reinit(mass_pattern);
@@ -122,9 +122,9 @@ void piDoMUS<dim, spacedim, LAC>::solve_eigenproblem()
122122
(const pidomus::CopyMass & data)
123123
{
124124

125-
this->constraints.distribute_local_to_global (data.local_matrix,
126-
data.local_dof_indices,
127-
mass_matrix);
125+
this->train_constraints[0]->distribute_local_to_global (data.local_matrix,
126+
data.local_dof_indices,
127+
mass_matrix);
128128
};
129129

130130
auto local_assemble = [ this ]

source/pidomus_helper_functions.cc

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ syncronize(const double &t,
6161
update_functions_and_constraints(t);
6262
typename LAC::VectorType tmp(solution);
6363
typename LAC::VectorType tmp_dot(solution_dot);
64-
constraints.distribute(tmp);
64+
train_constraints[0]->distribute(tmp);
6565
constraints_dot.distribute(tmp_dot);
6666

6767
locally_relevant_solution = tmp;
@@ -84,7 +84,7 @@ syncronize(const double &t,
8484
update_functions_and_constraints(t);
8585
typename LAC::VectorType tmp(solution);
8686
typename LAC::VectorType tmp_dot(solution_dot);
87-
constraints.distribute(tmp);
87+
train_constraints[0]->distribute(tmp);
8888
constraints_dot.distribute(tmp_dot);
8989

9090
locally_relevant_solution = tmp;
@@ -98,8 +98,9 @@ syncronize(const double &t,
9898

9999
typename LAC::VectorType tmp(solution);
100100
typename LAC::VectorType tmp_dot(solution_dot);
101-
constraints.distribute(tmp);
101+
train_constraints[0]->distribute(tmp);
102102
constraints_dot.distribute(tmp_dot);
103+
103104
locally_relevant_solution = tmp;
104105
locally_relevant_solution_dot = tmp_dot;
105106
}
@@ -113,7 +114,7 @@ syncronize(const double &t,
113114

114115
typename LAC::VectorType tmp(solution);
115116
typename LAC::VectorType tmp_dot(solution_dot);
116-
constraints.distribute(tmp);
117+
train_constraints[0]->distribute(tmp);
117118
constraints_dot.distribute(tmp_dot);
118119

119120
locally_relevant_solution = tmp;
@@ -134,31 +135,38 @@ void piDoMUS<dim, spacedim, LAC>::update_functions_and_constraints (const double
134135
forcing_terms.set_time(t);
135136
neumann_bcs.set_time(t);
136137
}
138+
137139
// clear previously stored constraints
138-
constraints.clear();
140+
for (unsigned int i=0; i<n_matrices; ++i)
141+
train_constraints[i]->clear();
139142
constraints_dot.clear();
140143

141144
// compute hanging nodes
142145
DoFTools::make_hanging_node_constraints (*dof_handler,
143-
constraints);
146+
*train_constraints[0]);
144147

145148
DoFTools::make_hanging_node_constraints (*dof_handler,
146149
constraints_dot);
147150

148-
// compute boundary values
149-
apply_dirichlet_bcs(*dof_handler, dirichlet_bcs, constraints);
151+
zero_average.apply_zero_average_constraints(*dof_handler, *train_constraints[0]);
152+
153+
154+
155+
// compute boundary values for the system matrix
156+
apply_dirichlet_bcs(*dof_handler, dirichlet_bcs, *train_constraints[0]);
150157
apply_dirichlet_bcs(*dof_handler, dirichlet_bcs_dot, constraints_dot);
151158

152159

153-
// apply zero average constraints
154-
zero_average.apply_zero_average_constraints(*dof_handler, constraints);
160+
// apply zero average constraints to the system matrix
161+
zero_average.apply_zero_average_constraints(*dof_handler, *train_constraints[0]);
155162

156163
// add user-supplied bcs
157-
signals.update_constraint_matrices(constraints,constraints_dot);
164+
signals.update_constraint_matrices(train_constraints, constraints_dot);
158165

159166
// close the constraints
160-
constraints.close ();
161-
constraints_dot.close ();
167+
for (unsigned int i=0; i<n_matrices; ++i)
168+
train_constraints[i]->close();
169+
constraints_dot.close();
162170
}
163171

164172
template <int dim, int spacedim, typename LAC>
@@ -201,14 +209,14 @@ piDoMUS<dim, spacedim, LAC>::set_constrained_dofs_to_zero(typename LAC::VectorTy
201209
if (global_partitioning.n_elements() > 0)
202210
{
203211
auto k = global_partitioning.nth_index_in_set(0);
204-
if (constraints.is_constrained(k))
212+
if (train_constraints[0]->is_constrained(k))
205213
v[k] = 0;
206214
else
207215
v[k] = v[k];
208216
for (unsigned int i = 1; i < global_partitioning.n_elements(); ++i)
209217
{
210218
auto j = global_partitioning.nth_index_in_set(i);
211-
if (constraints.is_constrained(j))
219+
if (train_constraints[0]->is_constrained(j))
212220
v[j] = 0;
213221
}
214222
v.compress(VectorOperation::insert);

source/pidomus_mesh_refinement.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ piDoMUS<dim, spacedim, LAC>::solver_should_restart(const double t,
6262
auto _timer = computing_timer.scoped_timer ("Compute error estimator");
6363
update_functions_and_constraints(t);
6464

65-
constraints.distribute(solution);
65+
train_constraints[0]->distribute(solution);
6666
locally_relevant_solution = solution;
6767
constraints_dot.distribute(solution_dot);
6868
locally_relevant_solution_dot = solution_dot;
@@ -92,7 +92,7 @@ piDoMUS<dim, spacedim, LAC>::solver_should_restart(const double t,
9292
adaptive_refinement);
9393

9494
update_functions_and_constraints(t);
95-
constraints.distribute(solution);
95+
train_constraints[0]->distribute(solution);
9696
constraints_dot.distribute(solution_dot);
9797

9898
signals.fix_solutions_after_refinement(solution,solution_dot);
@@ -163,7 +163,7 @@ refine_and_transfer_solutions(LATrilinos::VectorType &y,
163163

164164

165165
update_functions_and_constraints(current_time);
166-
constraints.distribute(y);
166+
train_constraints[0]->distribute(y);
167167
constraints_dot.distribute(y_dot);
168168

169169
locally_relevant_y = y;
@@ -213,10 +213,10 @@ refine_and_transfer_solutions(LADealII::VectorType &y,
213213
y_expl = new_sols[2];
214214

215215
update_functions_and_constraints(previous_time);
216-
constraints.distribute(y_expl);
216+
train_constraints[0]->distribute(y_expl);
217217

218218
update_functions_and_constraints(current_time);
219-
constraints.distribute(y);
219+
train_constraints[0]->distribute(y);
220220
constraints_dot.distribute(y_dot);
221221

222222
locally_relevant_y = y;

tests/set_constrained_to_zero.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace dealii;
66
template<int fdim, int fspacedim, typename fn_LAC>
77
void test(piDoMUS<fdim,fspacedim,fn_LAC> &pi_foo)
88
{
9-
pi_foo.constraints.clear();
10-
pi_foo.constraints.add_line(0);
11-
pi_foo.constraints.close();
9+
pi_foo.train_constraints[0]->clear();
10+
pi_foo.train_constraints[0]->add_line(0);
11+
pi_foo.train_constraints[0]->close();
1212

1313
pi_foo.global_partitioning.clear();
1414
pi_foo.global_partitioning.set_size(2);

0 commit comments

Comments
 (0)