MFEM  v3.3
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
linearform.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 // Implementation of class LinearForm
13 
14 #include "fem.hpp"
15 
16 namespace mfem
17 {
18 
20 {
21  dlfi.Append (lfi);
22 }
23 
25 {
26  blfi.Append (lfi);
27 }
28 
30 {
31  flfi.Append(lfi);
32  flfi_marker.Append(NULL); // NULL -> all attributes are active
33 }
34 
36  Array<int> &bdr_attr_marker)
37 {
38  flfi.Append(lfi);
39  flfi_marker.Append(&bdr_attr_marker);
40 }
41 
43 {
44  Array<int> vdofs;
45  ElementTransformation *eltrans;
46  Vector elemvect;
47 
48  int i;
49 
50  Vector::operator=(0.0);
51 
52  if (dlfi.Size())
53  for (i = 0; i < fes -> GetNE(); i++)
54  {
55  fes -> GetElementVDofs (i, vdofs);
56  eltrans = fes -> GetElementTransformation (i);
57  for (int k=0; k < dlfi.Size(); k++)
58  {
59  dlfi[k]->AssembleRHSElementVect(*fes->GetFE(i), *eltrans, elemvect);
60  AddElementVector (vdofs, elemvect);
61  }
62  }
63 
64  if (blfi.Size())
65  for (i = 0; i < fes -> GetNBE(); i++)
66  {
67  fes -> GetBdrElementVDofs (i, vdofs);
68  eltrans = fes -> GetBdrElementTransformation (i);
69  for (int k=0; k < blfi.Size(); k++)
70  {
71  blfi[k]->AssembleRHSElementVect(*fes->GetBE(i), *eltrans, elemvect);
72  AddElementVector (vdofs, elemvect);
73  }
74  }
75 
76  if (flfi.Size())
77  {
79  Mesh *mesh = fes->GetMesh();
80 
81  // Which boundary attributes need to be processed?
82  Array<int> bdr_attr_marker(mesh->bdr_attributes.Size() ?
83  mesh->bdr_attributes.Max() : 0);
84  bdr_attr_marker = 0;
85  for (int k = 0; k < flfi.Size(); k++)
86  {
87  if (flfi_marker[k] == NULL)
88  {
89  bdr_attr_marker = 1;
90  break;
91  }
92  Array<int> &bdr_marker = *flfi_marker[k];
93  MFEM_ASSERT(bdr_marker.Size() == bdr_attr_marker.Size(),
94  "invalid boundary marker for boundary face integrator #"
95  << k << ", counting from zero");
96  for (int i = 0; i < bdr_attr_marker.Size(); i++)
97  {
98  bdr_attr_marker[i] |= bdr_marker[i];
99  }
100  }
101 
102  for (i = 0; i < mesh->GetNBE(); i++)
103  {
104  const int bdr_attr = mesh->GetBdrAttribute(i);
105  if (bdr_attr_marker[bdr_attr-1] == 0) { continue; }
106 
107  tr = mesh->GetBdrFaceTransformations(i);
108  if (tr != NULL)
109  {
110  fes -> GetElementVDofs (tr -> Elem1No, vdofs);
111  for (int k = 0; k < flfi.Size(); k++)
112  {
113  if (flfi_marker[k] &&
114  (*flfi_marker[k])[bdr_attr-1] == 0) { continue; }
115 
116  flfi[k] -> AssembleRHSElementVect (*fes->GetFE(tr -> Elem1No),
117  *tr, elemvect);
118  AddElementVector (vdofs, elemvect);
119  }
120  }
121  }
122  }
123 }
124 
125 void LinearForm::Update(FiniteElementSpace *f, Vector &v, int v_offset)
126 {
127  fes = f;
128  NewDataAndSize((double *)v + v_offset, fes->GetVSize());
129 }
130 
132 {
133  int k;
134  for (k=0; k < dlfi.Size(); k++) { delete dlfi[k]; }
135  for (k=0; k < blfi.Size(); k++) { delete blfi[k]; }
136  for (k=0; k < flfi.Size(); k++) { delete flfi[k]; }
137 }
138 
139 }
int Size() const
Logical size of the array.
Definition: array.hpp:109
int GetVSize() const
Definition: fespace.hpp:163
int GetBdrAttribute(int i) const
Return the attribute of boundary element i.
Definition: mesh.hpp:824
void NewDataAndSize(double *d, int s)
Set the Vector data and size, deleting the old data, if owned.
Definition: vector.hpp:94
int GetNBE() const
Returns number of boundary elements.
Definition: mesh.hpp:587
void Assemble()
Assembles the linear form i.e. sums over all domain/bdr integrators.
Definition: linearform.cpp:42
Abstract base class LinearFormIntegrator.
Definition: lininteg.hpp:22
Vector & operator=(const double *v)
Definition: vector.cpp:117
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:136
T Max() const
Find the maximal element in the array, using the comparison operator &lt; for class T.
Definition: array.cpp:108
void AddBdrFaceIntegrator(LinearFormIntegrator *lfi)
Adds new Boundary Face Integrator.
Definition: linearform.cpp:29
FaceElementTransformations * GetBdrFaceTransformations(int BdrElemNo)
Definition: mesh.cpp:687
void AddBoundaryIntegrator(LinearFormIntegrator *lfi)
Adds new Boundary Integrator.
Definition: linearform.cpp:24
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add (element) subvector to the vector.
Definition: vector.cpp:550
void AddDomainIntegrator(LinearFormIntegrator *lfi)
Adds new Domain Integrator.
Definition: linearform.cpp:19
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition: mesh.hpp:142
~LinearForm()
Destroys linear form.
Definition: linearform.cpp:131
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement associated with i&#39;th element.
Definition: fespace.cpp:1134
Vector data type.
Definition: vector.hpp:36
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement for the i&#39;th boundary element.
Definition: fespace.cpp:1369