G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsNsAssembler.hpp
Go to the documentation of this file.
1
15#pragma once
16
18
20#include <gsUtils/gsPointGrid.h>
21
22// Element visitors
25
26namespace gismo
27{
28
29template<class T>
31 gsMultiBasis<T> const & basisVel,
32 gsMultiBasis<T> const & basisPres,
33 gsBoundaryConditions<T> const & bconditions,
34 const gsFunction<T> & body_force)
35{
36 // comment: same problems as in gsElasticityAssembler
37 gsPiecewiseFunction<T> rightHandSides;
38 rightHandSides.addPiece(body_force);
39 typename gsPde<T>::Ptr pde( new gsBasePde<T>(patches,bconditions,rightHandSides) );
40
41 m_dim = body_force.targetDim();
42 for (short_t d = 0; d < m_dim; ++d)
43 m_bases.push_back(basisVel);
44 m_bases.push_back(basisPres);
45
46 Base::initialize(pde, m_bases, defaultOptions());
47}
48
49template <class T>
51{
52 gsOptionList opt = Base::defaultOptions();
53 opt.addReal("Viscosity","Kinematic viscosity of the fluid",0.001);
54 opt.addReal("Density","Density of the fluid",1.);
55 opt.addReal("ForceScaling","Force scaling parameter",1.);
56 opt.addInt("Assembly","Type of the linear system to assemble",ns_assembly::newton_update);
57 return opt;
58}
59
60template <class T>
62{
63 // Pick up values from options
64 const T bdA = m_options.getReal("bdA");
65 const index_t bdB = m_options.getInt("bdB");
66 const T bdO = m_options.getReal("bdO");
67
68 index_t deg = 0;
69 for (index_t d = 0; d < m_bases[0][0].dim(); ++d )
70 if (m_bases[0][0].degree(d) > deg)
71 deg = m_bases[0][0].degree(d);
72
73 // m_dim velocity*velocity blocks + 1 pressure*velocity block (additioanal factor 2 for subgrid element)
74 index_t numElPerColumn = pow((bdA*deg+bdB),m_dim)*m_dim + pow((2*bdA*deg+bdB),m_dim);
75
76 m_system.reserve(numElPerColumn*(1+bdO),1);
77}
78
79template <class T>
81{
82 GISMO_ENSURE(m_dim == m_pde_ptr->domain().parDim(), "The RHS dimension and the domain dimension don't match!");
83 GISMO_ENSURE(m_dim == 2 || m_dim == 3, "Only two- and three-dimenstion domains are supported!");
84
85 std::vector<gsDofMapper> m_dofMappers(m_bases.size());
86 for (unsigned d = 0; d < m_bases.size(); d++)
87 m_bases[d].getMapper((dirichlet::strategy)m_options.getInt("DirichletStrategy"),
88 iFace::glue,m_pde_ptr->bc(),m_dofMappers[d],d,true);
89
90 m_system = gsSparseSystem<T>(m_dofMappers, gsVector<index_t>::Ones(m_bases.size()));
91 reserve();
92
93 for (unsigned d = 0; d < m_bases.size(); ++d)
94 Base::computeDirichletDofs(d);
95}
96
97//--------------------- SYSTEM ASSEMBLY ----------------------------------//
98
99template<class T>
100void gsNsAssembler<T>::assemble(bool saveEliminationMatrix)
101{
102 GISMO_UNUSED(saveEliminationMatrix);
103 m_system.matrix().setZero();
104 reserve();
105 m_system.rhs().setZero();
106
107 gsVisitorStokes<T> visitor(*m_pde_ptr);
108 Base::template push<gsVisitorStokes<T> >(visitor);
109
110 m_system.matrix().makeCompressed();
111}
112
113template <class T>
114bool gsNsAssembler<T>::assemble(const gsMatrix<T> & solutionVector,
115 const std::vector<gsMatrix<T> > & fixedDoFs)
116{
117 gsMultiPatch<T> velocity, pressure;
118 constructSolution(solutionVector,fixedDoFs,velocity,pressure);
119 assemble(velocity,pressure);
120
121 return true;
122}
123
124template <class T>
126 const gsMultiPatch<T> & pressure)
127{
128 m_system.matrix().setZero();
129 reserve();
130 m_system.rhs().setZero();
131
132 gsVisitorNavierStokes<T> visitor(*m_pde_ptr,velocity,pressure);
133 Base::template push<gsVisitorNavierStokes<T> >(visitor);
134
135 m_system.matrix().makeCompressed();
136}
137
138//--------------------- SOLUTION CONSTRUCTION ----------------------------------//
139
140template <class T>
142 const std::vector<gsMatrix<T> > & fixedDoFs,
143 gsMultiPatch<T>& velocity) const
144{
145 gsVector<index_t> unknowns(m_dim);
146 for (short_t d = 0; d < m_dim; ++d)
147 unknowns.at(d) = d;
148 Base::constructSolution(solVector,fixedDoFs,velocity,unknowns);
149}
150
151template <class T>
153 const std::vector<gsMatrix<T> > & fixedDoFs,
154 gsMultiPatch<T> & velocity, gsMultiPatch<T> & pressure) const
155{
156 // construct displacement
157 constructSolution(solVector,fixedDoFs,velocity);
158 // construct pressure
159 constructPressure(solVector,fixedDoFs,pressure);
160}
161
162template <class T>
164 const std::vector<gsMatrix<T> > & fixedDoFs,
165 gsMultiPatch<T>& pressure) const
166{
167 GISMO_UNUSED(fixedDoFs);
168 gsVector<index_t> unknowns(1);
169 unknowns.at(0) = m_dim;
170 Base::constructSolution(solVector,m_ddof,pressure,unknowns);
171}
172
173//--------------------- SPECIALS ----------------------------------//
174
175template <class T>
177 const std::vector<std::pair<index_t,boxSide> > & bdrySides, bool split) const
178{
179 // all temporary data structures
180 gsMatrix<T> quNodes, pressureValues, physGradJac, sigma;
181 gsVector<T> quWeights, normal;
182 // NEED_MEASURE for integration
183 // NEED_GRAD_TRANSFORM for velocity gradients transformation from parametric to physical domain
185 // NEED_DERIV for velocity gradients
187
188 gsMatrix<T> force;
189 force.setZero(m_dim, 2);
190 const T viscosity = m_options.getReal("Viscosity");
191 const T density = m_options.getReal("Density");
192
193 // loop over bdry sides
194 for (std::vector<std::pair<index_t,boxSide> >::const_iterator it = bdrySides.begin();
195 it != bdrySides.end(); ++it)
196 {
197 // basis of the patch
198 const gsBasis<T> & basis = m_bases[0][it->first];
199 // setting quadrature rule for the boundary side
200 gsGaussRule<T> bdQuRule(basis,1.0,1,it->second.direction());
201 // loop over elements of the side
202 typename gsBasis<T>::domainIter elem = basis.makeDomainIterator(it->second);
203 for (; elem->good(); elem->next())
204 {
205 // mapping quadrature rule to the element
206 bdQuRule.mapTo(elem->lowerCorner(),elem->upperCorner(),quNodes,quWeights);
207 // evaluate geoemtry mapping at the quad points
208 mdGeo.points = quNodes;
209 m_pde_ptr->patches().patch(it->first).computeMap(mdGeo);
210 // evaluate velocity at the quad points
211 mdVel.points = quNodes;
212 velocity.patch(it->first).computeMap(mdVel);
213 // evaluate pressure at the quad points
214 pressure.patch(it->first).eval_into(quNodes,pressureValues);
215
216 // loop over quad points
217 for (index_t q = 0; q < quWeights.rows(); ++q)
218 {
219 // transform gradients from parametric to physical
220 physGradJac = mdVel.jacobian(q)*(mdGeo.jacobian(q).cramerInverse());
221 // normal length is the local measure
222 outerNormal(mdGeo,q,it->second,normal);
223 // pressure contribution to the stress tensor
224 sigma = pressureValues.at(q)*gsMatrix<T>::Identity(m_dim,m_dim);
225 force.col(0) += quWeights[q] * sigma * normal;
226 sigma = -1*density*viscosity*(physGradJac + physGradJac.transpose());
227 force.col(1) += quWeights[q] * sigma * normal;
228 }
229 }
230 }
231 if (split)
232 return force;
233 else
234 return force.col(0) + force.col(1);
235}
236
237} // namespace ends
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
Class containing a set of boundary conditions.
Definition gsBoundaryConditions.h:342
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
virtual short_t targetDim() const
Dimension of the target space.
Definition gsFunctionSet.h:595
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition gsGaussRule.h:28
the gsMapData is a cache of pre-computed function (map) values.
Definition gsFuncData.h:349
gsMatrix< T > points
input (parametric) points
Definition gsFuncData.h:372
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition gsMatrix.h:211
Holds a set of patch-wise bases and their topology information.
Definition gsMultiBasis.h:37
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
gsGeometry< T > & patch(size_t i) const
Return the i-th patch.
Definition gsMultiPatch.h:292
virtual gsMatrix< T > computeForce(const gsMultiPatch< T > &velocity, const gsMultiPatch< T > &pressure, const std::vector< std::pair< index_t, boxSide > > &bdrySides, bool split=false) const
Definition gsNsAssembler.hpp:176
virtual void reserve()
a custom reserve function to allocate memory for the sparse matrix
Definition gsNsAssembler.hpp:61
virtual void assemble()
Main assemble routine, to be implemented in derived classes.
Definition gsNsAssembler.h:53
virtual void constructSolution(const gsMatrix< T > &solVector, const std::vector< gsMatrix< T > > &fixedDoFs, gsMultiPatch< T > &velocity) const
Construct velocity from computed solution vector and fixed degrees of freedom.
Definition gsNsAssembler.hpp:141
virtual void refresh()
Refresh routine to set dof-mappers.
Definition gsNsAssembler.hpp:80
gsNsAssembler(const gsMultiPatch< T > &patches, const gsMultiBasis< T > &basisVel, const gsMultiBasis< T > &basisPres, const gsBoundaryConditions< T > &bconditions, const gsFunction< T > &body_force)
Constructor.
Definition gsNsAssembler.hpp:30
virtual void constructPressure(const gsMatrix< T > &solVector, const std::vector< gsMatrix< T > > &fixedDoFs, gsMultiPatch< T > &pressure) const
@ brief Construct pressure from computed solution vector
Definition gsNsAssembler.hpp:163
static gsOptionList defaultOptions()
Returns the list of default options for assembly.
Definition gsNsAssembler.hpp:50
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
void addInt(const std::string &label, const std::string &desc, const index_t &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:201
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
A function depending on an index i, typically referring to a patch/sub-domain. On each patch a differ...
Definition gsPiecewiseFunction.h:29
void addPiece(const gsFunction< T > &func)
Add a piece.
Definition gsPiecewiseFunction.h:113
virtual void mapTo(const gsVector< T > &lower, const gsVector< T > &upper, gsMatrix< T > &nodes, gsVector< T > &weights) const
Maps quadrature rule (i.e., points and weights) from the reference domain to an element.
Definition gsQuadRule.h:177
A sparse linear system indexed by sets of degrees of freedom.
Definition gsSparseSystem.h:30
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
T at(index_t i) const
Returns the i-th element of the vector.
Definition gsVector.h:177
IMHO, a useless class, but it is necessary to use the gsAssembler class. Contains proper information ...
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
Provides matrix and rhs assebmly for stationary and transient incompressible Stokes and Navier-Stokes...
Provides functions to generate structured point data.
Visitor class for volumetric integration of thetangential Navier-Stokes system.
Visitor class for volumetric integration of the Stokes system.
The G+Smo namespace, containing all definitions for the library.
@ NEED_DERIV
Gradient of the object.
Definition gsForwardDeclarations.h:73
@ NEED_GRAD_TRANSFORM
Gradient transformation matrix.
Definition gsForwardDeclarations.h:77
@ NEED_MEASURE
The density of the measure pull back.
Definition gsForwardDeclarations.h:76
@ newton_update
stationary point iteration, 1st order, yields a new solution at each iteration
Definition gsBaseUtils.h:47