G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsThinShellDWRHelper.h
Go to the documentation of this file.
1 
16 #pragma once
17 
19 
20 namespace gismo
21 {
22 
23 template <class T>
24 class gsThinShellDWRHelper
25 
26 {
27 public:
28  typedef typename gsThinShellAssemblerDWRBase<T>::bContainer bContainer;
29 
30 
31  // empty constructor
32  gsThinShellDWRHelper() {};
33 
34 
35  gsThinShellDWRHelper(gsThinShellAssemblerDWRBase<T> * assembler)
36  :
37  m_assembler(assembler)
38  {
39 
40  }
41 
42  void computeError(const gsVector<T> & U)
43  {
44  gsMultiPatch<T> primalL, deformed;
45 
46  m_assembler->constructSolutionL(U,deformed);
47  m_assembler->constructMultiPatchL(U,primalL);
48 
49  this->computeError(deformed,primalL);
50  }
51 
52  void computeError(const gsMultiPatch<T> & deformed, const gsMultiPatch<T> primalL, bool withLoads = false)
53  {
54  gsMatrix<T> points;
55  bContainer bnds;
56  this->computeError(deformed,primalL,bnds,points,true,withLoads);
57  }
58 
59  void computeError(const gsMultiPatch<T> & deformed, const gsMultiPatch<T> primalL, bool withLoads = false,
60  std::string filename = std::string(), unsigned np=1000, bool parametric=false, bool mesh=false)
61  {
62  gsMatrix<T> points;
63  bContainer bnds;
64  this->computeError(deformed,primalL,bnds,points,true,withLoads,filename,np,parametric,mesh);
65  }
66 
67  void computeError(const gsMultiPatch<T> & deformed, const gsMultiPatch<T> primalL,
68  const bContainer & bnds, const gsMatrix<T> & points, bool interior = true,bool withLoads=false,
69  std::string filename = std::string(), unsigned np=1000, bool parametric=false, bool mesh=false)
70  {
71  gsMultiPatch<T> dualL, dualH;
72  gsVector<T> solVector;
73  gsVector<T> rhsL(m_assembler->numDofsL());
74  rhsL.setZero();
75  gsVector<T> rhsH(m_assembler->numDofsH());
76  rhsH.setZero();
77 
78  gsSparseSolver<real_t>::uPtr solver;
79  #ifdef GISMO_WITH_PARDISO
80  solver = gsSparseSolver<real_t>::get( "PardisoLU");
81  #else
82  solver = gsSparseSolver<real_t>::get( "LU");
83  #endif
84 
85  gsInfo << "Assembling dual matrix (L)... "<< std::flush;
86  m_assembler->assembleMatrixL(deformed);
87  gsInfo << "done.\n";
88  gsInfo << "Assembling dual vector (L)... "<< std::flush;
89  if (interior)
90  {
91  m_assembler->assembleDualL(primalL,deformed);
92  rhsL+=m_assembler->dualL();
93  }
94  if (bnds.size()!=0)
95  {
96  m_assembler->assembleDualL(bnds,primalL,deformed);
97  rhsL+=m_assembler->dualL();
98  }
99  if (points.cols()!=0)
100  {
101  m_assembler->assembleDualL(points,primalL,deformed);
102  rhsL+=m_assembler->dualL();
103  }
104  gsInfo << "done.\n";
105  gsInfo << "Solving dual (L), size = "<<m_assembler->matrixL().rows()<<","<<m_assembler->matrixL().cols()<<"... "<< std::flush;
106  solver->compute(m_assembler->matrixL());
107  solVector = solver->solve(rhsL);
108  m_assembler->constructMultiPatchL(solVector,dualL);
109  gsInfo << "done.\n";
110 
111  gsInfo << "Assembling dual matrix (H)... "<< std::flush;
112  m_assembler->assembleMatrixH(deformed);
113  gsInfo << "done.\n";
114  gsInfo << "Assembling dual vector (H)... "<< std::flush;
115  if (interior)
116  {
117  m_assembler->assembleDualH(primalL,deformed);
118  rhsH+=m_assembler->dualH();
119  }
120  if (bnds.size()!=0)
121  {
122  m_assembler->assembleDualH(bnds,primalL,deformed);
123  rhsH+=m_assembler->dualH();
124  }
125  if (points.cols()!=0)
126  {
127  m_assembler->assembleDualH(points,primalL,deformed);
128  rhsH+=m_assembler->dualH();
129  }
130 
131  gsInfo << "done.\n";
132  gsInfo << "Solving dual (H), size = "<<m_assembler->matrixH().rows()<<","<<m_assembler->matrixH().cols()<<"... "<< std::flush;
133  solver->compute(m_assembler->matrixH());
134  solVector = solver->solve(rhsH);
135  m_assembler->constructMultiPatchH(solVector,dualH);
136  gsInfo << "done.\n";
137 
138  m_error = m_assembler->computeError(dualL,dualH,deformed,withLoads,filename,np,parametric,mesh);
139  m_errors = m_assembler->computeErrorElements(dualL,dualH,deformed,withLoads);
140  m_sqerrors = m_assembler->computeSquaredErrorElements(dualL,dualH,deformed,withLoads);
141  }
142 
143  T error() const { return m_error; }
144  std::vector<T> errors(bool normalize=false) const
145  {
146  if (normalize)
147  {
148  std::vector<T> result = m_errors;
149  for (typename std::vector<T>::iterator it = result.begin(); it!=result.end(); it++)
150  *it = std::abs(*it) / std::abs(m_error);
151  return result;
152  }
153  else
154  return m_errors;
155 
156  }
157  std::vector<T> absErrors(bool normalize=false) const
158  {
159  std::vector<T> result = m_errors;
160  if (normalize)
161  {
162  for (typename std::vector<T>::iterator it = result.begin(); it!=result.end(); it++)
163  *it = std::abs(*it) / std::abs(m_error);
164  }
165  else
166  {
167  for (typename std::vector<T>::iterator it = result.begin(); it!=result.end(); it++)
168  *it = std::abs(*it);
169  }
170  return result;
171  }
172  std::vector<T> sqErrors(bool normalize=false) const
173  {
174  if (normalize)
175  {
176  std::vector<T> result = m_sqerrors;
177  for (typename std::vector<T>::iterator it = result.begin(); it!=result.end(); it++)
178  *it = std::abs(*it) / (math::pow(m_error,2));
179  return result;
180  }
181  else
182  return m_sqerrors;
183  }
184 
185 protected:
186  // bool m_verbose;
187  gsThinShellAssemblerDWRBase<T> * m_assembler;
188  T m_error;
189  std::vector<T> m_errors, m_sqerrors;
190 };
191 
192 } // namespace gismo
Provides DWR assembly routines for the Kirchhoff-Love shell.
#define gsInfo
Definition: gsDebug.h:43
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4486