G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsHeatEquation.h
Go to the documentation of this file.
1 
14 #pragma once
15 #include <gsAssembler/gsVisitorMass.h>
16 
17 namespace gismo
18 {
19 
32 template <class T>
33 class gsHeatEquation : public gsAssembler<T>
34 {
35 public:
36  typedef gsAssembler<T> Base;
37 
38 public:
39 
41  explicit gsHeatEquation(gsAssembler<T> & stationary)
42  : Base(stationary), // note: unnecessary sliced copy here
43  m_stationary(&stationary), m_theta(0.5)
44  {
45  m_options.addReal("theta",
46  "Theta parameter determining the time integration scheme [0..1]", m_theta);
47  }
48 
49 public:
50 
51  void setTheta(const T th)
52  {
53  GISMO_ASSERT(th<=1 && th>=0, "Invalid value");
54  m_theta= th;
55  m_options.setReal("theta", m_theta);
56  }
57 
59  void assemble()
60  {
61  // Grab theta once and for all
62  m_theta = m_options.getReal("theta");
63 
64  // Assemble the stationary problem
65  m_stationary->assemble();
66 
67  //copy the Dirichlet values, to enable calling
68  // the construct solution functions
69  Base::m_ddof = m_stationary->allFixedDofs();
70 
71  // Assemble mass matrix
72  assembleMass();
73 
74  GISMO_ASSERT( m_stationary->matrix().rows() == m_mass.rows(),
75  "Something went terribly wrong.");
76  }
77 
86  void nextTimeStep(const gsMatrix<T> & curSolution, const T Dt);
87 
88  void nextTimeStep(const gsSparseMatrix<T> & sysMatrix,
89  const gsSparseMatrix<T> & massMatrix,
90  const gsMatrix<T> & rhs0,
91  const gsMatrix<T> & rhs1,
92  const gsMatrix<T> & curSolution,
93  const T Dt);
94 
95  void nextTimeStepFixedRhs(const gsSparseMatrix<T> & sysMatrix,
96  const gsSparseMatrix<T> & massMatrix,
97  const gsMatrix<T> & rhs,
98  const gsMatrix<T> & curSolution,
99  const T Dt);
100 
101  const gsSparseMatrix<T> & mass() const { return m_mass; }
102  const gsSparseMatrix<T> & stationaryMatrix() const { return m_stationary->matrix(); }
103  const gsSparseMatrix<T> & stationaryRhs() const { return m_stationary->rhs(); }
104 
106  void assembleMass();
107 
108 protected:
109 
110  using Base::m_options;
111 
113  using Base::m_system;
114 
115  gsAssembler<T> * m_stationary;
116 
119 
122 
123  using Base::m_pde_ptr;
124  using Base::m_bases;
125 
126 };// end class definition
127 
128 
129 } // namespace gismo
130 
131 
132 namespace gismo
133 {
134 
135 template<class T>
136 void gsHeatEquation<T>::nextTimeStep(const gsMatrix<T> & curSolution, const T Dt)
137 {
138  nextTimeStepFixedRhs(m_stationary->matrix(), m_mass,
139  m_stationary->rhs(), curSolution, Dt);
140 }
141 
142 /*
143 template<class T>
144 void gsHeatEquation<T>::nextTimeStep(const gsMatrix<T> & curSolution, const T Dt)
145 {
146  // Keep previous time
147  m_prevRhs.swap(m_stationary->rhs());
148  // Get current time
149  m_time += Dt;
150  m_stationary->rhs(m_time);
151 
152  // note: m_stationary->matrix() assumed constant in time
153 
154  nextTimeStep(m_stationary->matrix(), m_mass,
155  m_prevRhs, m_stationary->rhs(), curSolution, Dt);
156  m_prevRhs.swap(m_stationary->rhs());
157 }
158 */
159 
160 template<class T>
162  const gsSparseMatrix<T> & massMatrix,
163  const gsMatrix<T> & rhs0,
164  const gsMatrix<T> & rhs1,
165  const gsMatrix<T> & curSolution,
166  const T Dt)
167 {
168  GISMO_ASSERT( curSolution.rows() == massMatrix.cols(),
169  "Wrong size in current solution vector.");
170 
171  const T c1 = Dt * m_theta;
172  m_system.matrix() = massMatrix + c1 * sysMatrix;
173 
174  const T c2 = Dt * (1.0 - m_theta);
175  m_system.rhs().noalias() = c1 * rhs1 + c2 * rhs0 + (massMatrix - c2 * sysMatrix) * curSolution;
176 }
177 
178 template<class T>
179 void gsHeatEquation<T>::nextTimeStepFixedRhs(const gsSparseMatrix<T> & sysMatrix,
180  const gsSparseMatrix<T> & massMatrix,
181  const gsMatrix<T> & rhs,
182  const gsMatrix<T> & curSolution,
183  const T Dt)
184 {
185  GISMO_ASSERT( curSolution.rows() == massMatrix.cols(),
186  "Wrong size in current solution vector.");
187 
188  const T c1 = Dt * m_theta;
189  m_system.matrix() = massMatrix + c1 * sysMatrix;
190 
191  const T c2 = Dt * (1.0 - m_theta);
192  m_system.rhs().noalias() = Dt * rhs + (massMatrix - c2 * sysMatrix) * curSolution;
193 }
194 
195 
196 template<class T>
198 {
199  // the mass visitor used to need empty variable
200  // Base::m_ddof.resize(1, gsMatrix<T>() );
201 
202  const index_t m_dofs = this->numDofs();
203  if ( 0 == m_dofs ) // Are there any interior dofs ?
204  {
205  gsWarn<<"No interior DoFs for mass compuation.\n";
206  return;
207  }
208 
209  // Pre-allocate non-zero elements for each column of the
210  // sparse matrix
211  m_system.reserve(m_bases[0], m_options, 1);// zero rhs's
212 
213  // Assemble mass integrals
214  gsVisitorMass<T> mass;
215  for (size_t np=0; np < m_pde_ptr->domain().nPatches(); ++np )
216  {
217  //Assemble mass matrix for this patch
218  this->apply(mass, np);
219  }
220 
221  // Assembly is done, compress the matrix
222  this->finalize();
223 
224  // Store the mass matrix once and for all
225  m_system.matrix().swap(m_mass);
226 }
227 
228 } // namespace gismo
memory::shared_ptr< gsPde< T > > m_pde_ptr
Definition: gsAssembler.h:276
void assembleMass()
Mass assembly routine.
Definition: gsHeatEquation.h:197
gsOptionList m_options
Options.
Definition: gsAssembler.h:285
std::vector< gsMultiBasis< T > > m_bases
Definition: gsAssembler.h:282
gsHeatEquation(gsAssembler< T > &stationary)
Construction receiving all necessary data.
Definition: gsHeatEquation.h:41
const gsMatrix< T > & rhs() const
Returns the left-hand side vector(s) ( multiple right hand sides possible )
Definition: gsAssembler.h:618
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void setReal(const std::string &label, const Real &value)
Sets an existing option label to be equal to value.
Definition: gsOptionList.cpp:166
The visitor computes element mass integrals.
Definition: gsVisitorMass.h:29
T m_theta
Theta parameter determining the scheme.
Definition: gsHeatEquation.h:121
#define gsWarn
Definition: gsDebug.h:50
gsSparseSystem< T > m_system
Global sparse linear system.
Definition: gsAssembler.h:290
Constructs the assembler for the discretized isogeometric heat equation.
Definition: gsHeatEquation.h:33
void assemble()
Initial assembly routine.
Definition: gsHeatEquation.h:59
std::vector< gsMatrix< T > > m_ddof
Definition: gsAssembler.h:295
void addReal(const std::string &label, const std::string &desc, const Real &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:211
void nextTimeStep(const gsMatrix< T > &curSolution, const T Dt)
Computes the matrix and right-hand side for the next timestep.
Definition: gsHeatEquation.h:136
The assembler class provides generic routines for volume and boundary integrals that are used for for...
Definition: gsAssembler.h:265
gsSparseMatrix< T > m_mass
The mass matrix.
Definition: gsHeatEquation.h:118
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition: gsOptionList.cpp:44