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