~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to dolfin/fem/DirichletBC.cpp

  • Committer: Anders Logg
  • Date: 2008-05-22 06:46:27 UTC
  • mto: (2668.9.6 trunk)
  • mto: This revision was merged to the branch mainline in revision 2670.
  • Revision ID: logg@simula.no-20080522064627-rahrtqj3jqxnlc2j
More work on BCs

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    method(method), user_sub_domain(0)
59
59
{
60
60
  // Initialize sub domain markers
61
 
  initFromMesh();
 
61
  initFromMesh(sub_domain);
62
62
}
63
63
//-----------------------------------------------------------------------------
64
64
DirichletBC::DirichletBC(Function& g,
96
96
    sub_system(sub_system), method(method), user_sub_domain(0)
97
97
{
98
98
  // Initialize sub domain markers
99
 
  initFromMesh();
 
99
  initFromMesh(sub_domain);
100
100
}
101
101
//-----------------------------------------------------------------------------
102
102
DirichletBC::~DirichletBC()
133
133
                        const GenericVector* x, const DofMap& dof_map, const ufc::form& form)
134
134
{
135
135
  // FIXME: How do we reuse the dof map for u?
136
 
  
 
136
 
137
137
  // Simple check
138
138
  const uint N = dof_map.global_dimension();
139
139
  if (N != A.size(0) || N != A.size(1))
140
140
    error("Incorrect dimension of matrix for application of boundary conditions. Did you assemble it on a different mesh?");
141
141
  if (N != b.size())
142
142
    error("Incorrect dimension of matrix for application of boundary conditions. Did you assemble it on a different mesh?");
143
 
  
 
143
 
144
144
  // Set message string
145
145
  std::string s;
146
146
  if (method == topological)
161
161
  // A map to hold the mapping from boundary dofs to boundary values
162
162
  std::map<uint, real> boundary_values;
163
163
 
 
164
  // Choose strategy
164
165
  if (method == pointwise)
165
166
  {
166
167
    Progress p(s, _mesh.size(D));
254
255
  sub_domain.mark(*sub_domains, 0);
255
256
}
256
257
//-----------------------------------------------------------------------------
257
 
void DirichletBC::initFromMesh()
 
258
void DirichletBC::initFromMesh(uint sub_domain)
258
259
{
 
260
  dolfin_assert(facets.size() == 0);
 
261
 
259
262
  cout << "Creating sub domain markers for boundary condition." << endl;
260
 
  
 
263
 
261
264
  // Get data
262
265
  Array<uint>* facet_cells   = _mesh.data().array("boundary facet cells");
263
266
  Array<uint>* facet_numbers = _mesh.data().array("boundary facet numbers");
276
279
  dolfin_assert(size == facet_numbers->size());
277
280
  dolfin_assert(size == indicators->size());
278
281
 
279
 
  // Create mesh function for sub domain markers on facets
280
 
  const uint dim = _mesh.topology().dim();
281
 
  _mesh.init(dim - 1);
282
 
  sub_domains = new MeshFunction<uint>(_mesh, dim - 1);
283
 
  sub_domains_local = true;
284
 
 
285
 
  // Compute the maximum boundary indicator
286
 
  uint maxid = 0;
287
 
  for (uint i = 0; i < size; i++)
288
 
    maxid = std::max(maxid, (*indicators)[i]);
289
 
  cout << "maxid = " << maxid << endl;
290
 
 
291
 
  // Mark everything with the maximum value + 1
292
 
  (*sub_domains) = maxid + 1;
293
 
 
294
 
  // Mark facets according to data
 
282
  // Build set of boundary facets
295
283
  for (uint i = 0; i < size; i++)
296
284
  {
297
 
    // Get cell incident with facet
298
 
    Cell cell(_mesh, (*facet_cells)[i]);
299
 
 
300
 
    // Get facet
301
 
    uint facet = cell.entities(dim - 1)[(*facet_numbers)[i]];
302
 
 
303
 
    // Set marker
304
 
    sub_domains->set(facet, (*indicators)[i]);
 
285
    // Skip facets not on this boundary
 
286
    if ((*indicators)[i] != sub_domain)
 
287
      continue;
 
288
 
 
289
    // Copy data
 
290
    facets.push_back(std::pair<uint, uint>((*facet_cells)[i], (*facet_numbers)[i]));
305
291
  }
306
292
}
307
293
//-----------------------------------------------------------------------------
379
365
}
380
366
//-----------------------------------------------------------------------------
381
367
void DirichletBC::computeBCPointwise(std::map<uint, real>& boundary_values,
382
 
                                       Cell& cell,
383
 
                                       BoundaryCondition::LocalData& data)
 
368
                                     Cell& cell,
 
369
                                     BoundaryCondition::LocalData& data)
384
370
{
385
 
  UFCCell ufc_cell(cell);
 
371
  dolfin_assert(user_sub_domain);
386
372
 
387
373
  // Interpolate function on cell
 
374
  UFCCell ufc_cell(cell);
388
375
  g.interpolate(data.w, ufc_cell, *data.finite_element, cell);
389
376
      
390
377
  // Tabulate dofs on cell, and their coordinates