CG  Version 25
Cgsm.h
Go to the documentation of this file.
1 #ifndef SOLID_MECHANICS_H
2 #define SOLID_MECHANICS_H
3 
4 // ***************************************************
5 // ************ Solver for Solid Mechanics ***********
6 // ***************************************************
7 
8 #include "Overture.h"
9 #include "ArraySimple.h"
10 #include "UnstructuredMapping.h"
11 #include "InterfaceInfo.h"
12 
13 #include "DomainSolver.h"
14 
15 class GL_GraphicsInterface;
16 class GUIState;
17 class MappedGridOperators;
18 class OGFunction;
19 class Ogshow;
20 class DialogData;
21 class ShowFileReader;
23 class Oges;
24 
25 
26 class Cgsm : public DomainSolver
27 {
28  public:
29 
31  {
37  };
38 
40  {
50  gaussianIntegralInitialCondition, // from Tom Hagstrom
57  };
58 
60  {
67  };
68 
69 // enum TwlightZoneForcingEnum
70 // {
71 // polynomialTwilightZone,
72 // trigonometricTwilightZone,
73 // pulseTwilightZone
74 // } twilightZoneOption;
75 
76  // Here are known solutions
78  {
84 
85 
87  {
90  };
91 
92 
93  Cgsm(CompositeGrid & cg,
94  GenericGraphicsInterface *ps=NULL,
95  Ogshow *show=NULL,
96  const int & plotOption=1 );
97 
98  ~Cgsm();
99 
100 
101 
102 int
103 addDissipation( int current, real t, real dt, realMappedGridFunction *fields, const Range & C );
104 
105 static int
106 addPrefix(const aString label[], const aString & prefix, aString cmd[], const int maxCommands);
107 
108 void
109 advance( int current, real t, real dt );
110 
111 // advance the solution as a first-order system
112 void
113 advanceFOS( int current, real t, real dt,
114  RealCompositeGridFunction *ut = NULL,
115  real tForce= 0. );
116 
117 // advance a time step using the method of lines
118 void
119 advanceMethodOfLines( int current, real t, real dt );
120 
121 // advance the solution as a second-order system
122 void
123 advanceSOS( int current, real t, real dt,
124  RealCompositeGridFunction *ut = NULL,
125  real tForce= 0. );
126 
127 
128 
129 void
130 applyBoundaryConditions( int option, real dt, int current, int prev );
131 
132 // Here is apply BC function from the DomainSolver:
133 virtual int
135  const int & option =-1,
136  int grid_= -1,
137  GridFunction *puOld=NULL,
138  const real & dt =-1. );
139 int
140 assignAnnulusEigenfunction(const int gfIndex, const EvaluationOptionsEnum evalOption );
141 
142 void
143 assignBoundaryConditions( int option, int grid, real t, real dt, realMappedGridFunction & u,
144  realMappedGridFunction & uOld, int current );
145 
146 void
147 assignBoundaryConditionsFOS( int option, int grid, real t, real dt, realMappedGridFunction & u,
148  realMappedGridFunction & uOld, int current );
149 
150 void
151 assignBoundaryConditionsSOS( int option, int grid, real t, real dt, realMappedGridFunction & u,
152  realMappedGridFunction & uOld, int current );
153 
154 int
156 
157 int
158 assignHempInitialConditions(int gfIndex);
159 
160 virtual int
161 assignInitialConditions(int gfIndex);
162 
163 void
164 assignInterfaceBoundaryConditions( int current, real t, real dt );
165 
166 int
168 
169 int
170 assignSpecialInitialConditions(int gfIndex, const EvaluationOptionsEnum evalOption);
171 
172 int
174 
175 int
177 
178 int
180 
181 void
182 checkArrays(const aString & label);
183 
184 void
185 checkDisplacementAndStress( const int current, real t );
186 
187 void
188 computeDissipation( int current, real t, real dt );
189 
190 void
192  const real & tFinal,
193  const real & nextTimeToPlot,
194  int & numberOfSubSteps,
195  real & dtNew,
196  const bool & adjustTimeStep =true );
197 
198 // base cale version:
199 virtual realCompositeGridFunction &
200 getAugmentedSolution( GridFunction & gf0, realCompositeGridFunction & v );
201 
202 realCompositeGridFunction&
203 getAugmentedSolution(int current, realCompositeGridFunction & v, const real t);
204 
205 bool
206 getBoundsForPML( MappedGrid & mg, Index Iv[3], int extra=0 );
207 
208 // Return the list of interface data needed by a given interface:
209 virtual int
210 getInterfaceDataOptions( GridFaceDescriptor & info, int & interfaceDataOptions ) const;
211 
212 void
213 getLocalBoundsAndBoundaryConditions( const realMappedGridFunction & a,
214  IntegerArray & gidLocal,
215  IntegerArray & dimensionLocal,
216  IntegerArray & bcLocal );
217 
218 virtual void
219 getUt( GridFunction & cgf,
220  const real & t,
221  RealCompositeGridFunction & ut,
222  real tForce );
223 
224 void
225 getUtFOS(GridFunction & cgf,
226  const real & t,
227  RealCompositeGridFunction & ut,
228  real tForce );
229 
230 void
231 getUtSOS(GridFunction & cgf,
232  const real & t,
233  RealCompositeGridFunction & ut,
234  real tForce );
235 
236 void
237 getVelocityAndStress( const int current, real t,
238  realCompositeGridFunction *pv =NULL, int vComponent =0,
239  realCompositeGridFunction *ps =NULL, int sComponent =0,
240  bool computeMaxNorms = true );
241 
242 int
243 endTimeStep( real & t0, real & dt0, AdvanceOptions & advanceOptions );
244 
245 void
246 getEnergy( int current, real t, real dt );
247 
248 void
249 getErrors( int current, real t, real dt, const aString & label =nullString );
250 
251 // void getField( real x, real y, real t, real *eField );
252 
253 int
254 getForcing( int current, int grid, realArray & u , real t, real dt, int option=0 );
255 
256 virtual int
257 getInitialConditions(const aString & command = nullString,
258  DialogData *interface =NULL,
259  GUIState *guiState = NULL,
260  DialogState *dialogState = NULL );
261 
262 void
263 getMaxDivAndCurl( const int current, real t,
264  realCompositeGridFunction *pu=NULL, int component=0,
265  realCompositeGridFunction *pvor=NULL, int vorComponent=0,
266  realCompositeGridFunction *pDensity=NULL, int rhoComponent=0,
267  bool computeMaxNorms= true );
268 
269 int
270 getMethodName( aString & methodName );
271 
272  // ===Choose time step====
273 virtual real
275 
276 void
278 
279 void
281 
282 int
284 
285 virtual int
286 initializeTimeStepping( real & t0, real & dt0 );
287 
288 virtual int
290  int interfaceDataOptions,
291  GridFaceDescriptor & info,
292  GridFaceDescriptor & gfd,
293  int gfIndex, real t );
294 
295 int
296 outputResults( int current, real t, real dt );
297 
298 int
299 outputResultsAfterEachTimeStep( int current, real t, real dt, int stepNumber );
300 
301 int
302 plot(int current, real t, real dt );
303 
304 int
305 printMemoryUsage(FILE *file = stdout );
306 
307 // int
308 // printStatistics(FILE *file = stdout);
309 
310 virtual void
311 printTimeStepInfo( const int & step, const real & t, const real & cpuTime );
312 
313 int
314 project( int numberOfStepsTaken, int current, real t, real dt );
315 
316 //int
317 // saveParametersToShowFile();
318 
319 // void
320 // saveShow( int current, real t, real dt );
321 
322 virtual void
323 saveShow( GridFunction & gf0 );
324 
325 virtual void
326 saveShowFileComments( Ogshow &show );
327 
328 int
329 setBoundaryCondition( aString & answer, IntegerArray & originalBoundaryCondition );
330 
331 int
333 
334 virtual int
335 setPlotTitle(const real &t, const real &dt);
336 
337 int
338 setupGrids();
339 int
341 
342 virtual int
343 setupPde(aString & reactionName, bool restartChosen, IntegerArray & originalBoundaryCondition);
344 
345 virtual int
347 
348 virtual int
350 
351 void
352 smoothDivergence(realCompositeGridFunction & u, const int numberOfSmooths );
353 
354 int
355 solve();
356 
357 virtual int
358 startTimeStep( real & t0, real & dt0, int & currentGF, int & nextGF, AdvanceOptions & advanceOptions );
359 
360 // *old* this next function is used by the cgmp
361 // virtual void
362 // takeOneStep( real & t, real & dt, int stepNumber, int & numberOfSubSteps );
363 
364 int
365 takeTimeStep( real & t0, real & dt0, int correction, AdvanceOptions & advanceOptions );
366 
367 virtual int
368 updateForAdaptiveGrids(CompositeGrid & cg);
369 
370 virtual int
372 
373 virtual int
374 userDefinedBoundaryValues(const real & t,
375  GridFunction & gf0,
376  const int & grid,
377  int side0 = -1,
378  int axis0 = -1,
380 
381 virtual int
382 userDefinedForcing( realArray & f, const realMappedGridFunction & u, int iparam[], real rparam[] );
383 
384 virtual void
386 
387 virtual int
388 userDefinedInitialConditions(CompositeGrid & cg, realCompositeGridFunction & u );
389 
390 virtual void
392 
393 
394 int
396 
397 // int updateShowFile(const aString & command= nullString, DialogData *interface =NULL );
398 
399 bool
401 
402 
403 protected:
404 
405 int
406 buildTimeSteppingDialog(DialogData & dialog );
407 
408 int
409 getTimeSteppingOption(const aString & answer, DialogData & dialog );
410 
411 int
412 buildForcingOptionsDialog(DialogData & dialog );
413 int
414 getForcingOption(const aString & command, DialogData & dialog );
415 
416 int
417 buildGeneralOptionsDialog(DialogData & dialog );
418 int
419 getGeneralOption(const aString & answer, DialogData & dialog );
420 
421 int
422 buildInputOutputOptionsDialog(DialogData & dialog );
423 int
424 getInputOutputOption(const aString & command, DialogData & dialog );
425 
426 int
427 buildPlotOptionsDialog(DialogData & dialog );
428 int
429 getPlotOption(const aString & command, DialogData & dialog );
430 
431 int
432 buildParametersDialog(DialogData & dialog ); // parameters that can be changed at run time.
433 
434 int
435 saveSequenceInfo( real t0, RealArray & sequenceData );
436 int
438 
439 void
440 setup(const real & time = 0. );
441 
442 int
443 updateForNewTimeStep(GridFunction & cgf, real & dt );
444 
445 void
446 writeParameterSummary( FILE *file );
447 
448 public: // should be protected:
449 
452 
453  real c1,c2;
456 
457  std::vector<InterfaceInfo> interfaceInfo; // holds info and work-space for interfaces
458 
459  int kx,ky,kz;
460 
461  real deltaT;
462 
464  real gaussianSourceParameters[5]; // gamma,omega,x0,y0,z0
465 
468  real gaussianPulseParameters[maxNumberOfGaussianPulses][6]; // beta scale, exponent, x0,y0,z0
469 
472  real gaussianChargeSourceParameters[maxNumberOfGaussianChargeSources][9]; // a,beta,p, x0,y0,z0, v0,v1,v2
473 
475  RealArray dxMinMax; // holds min and max grid spacings
478 
483 
488 
493  real dScale; // displacement scale factor (for plotting the displacement)
494 
495  real radiusForCheckingErrors; // if >0 only check errors in a disk (sphere) of this radius
496 
498 
499  real cylinderRadius, cylinderAxisStart,cylinderAxisEnd; // for eigenfunctions of the cylinder
500 
501  int numberLinesForPML; // width of the PML in grid lines
502  int pmlPower;
504  int pmlErrorOffset; // only check errors within this many lines of the pml
505 
506  realArray *vpml; // for PML
507 
508 // int orderOfAccuracyInSpace;
509 // int orderOfAccuracyInTime;
512 
513  real initialConditionParameters[10]; // holds parameters for various initial conditions
515 
516  aString probeFileName; // save the probes in this file
517  ArraySimple<real> probes; // output solution at these points
518  ArraySimple<int> probeGridLocation; // holds closest grid and grid point
519  int frequencyToSaveProbes; // save probe data every this many steps
520 
521  FILE *probeFile; // save probe data to this file
522 
523 
524  // for plane material interface
526 
527  // For radiation boundaryConditions:
528  int radbcGrid[2], radbcSide[2], radbcAxis[2];
529  // RadiationBoundaryCondition *radiationBoundaryCondition;
530 
531 
532  CompositeGridOperators *cgop;
533  realCompositeGridFunction *cgdissipation;
534  realCompositeGridFunction *cgerrp;
535  realCompositeGridFunction *variableDissipation;
536  realCompositeGridFunction *knownSolution; // for holding a known solution that may be expensive to recompute
537 
538  // These next variables are for higher order time stepping
539  int numberOfTimeLevels; // keep this many time levels of u
540 
541  int myid; // processor number
542  int numberOfFunctions; // number of f=du/dt
544  realCompositeGridFunction *cgfn;
545 
546  GUIState *runTimeDialog;
548 
549  aString movieFileName;
552  // int numberOfGridPoints;
553  int totalNumberOfArrays; // for counting A++ array
554 
555  aString nameOfGridFile;
556  ShowFileReader *referenceShowFileReader; // for comparing to a reference solution
557 
558  // for sequences saved in the show file
561 
566 
567 // enum TimingEnum
568 // {
569 // totalTime=0,
570 // timeForInitialize,
571 // timeForInitialConditions,
572 // timeForAdvance,
573 // timeForAdvanceRectangularGrids,
574 // timeForAdvanceCurvilinearGrids,
575 // timeForAdvanceUnstructuredGrids,
576 // timeForAdvOpt,
577 // timeForDissipation,
578 // timeForBoundaryConditions,
579 // timeForInterfaceBC,
580 // timeForRadiationBC,
581 // timeForRaditionKernel,
582 // timeForInterpolate,
583 // timeForUpdateGhostBoundaries,
584 // timeForGetError,
585 // timeForForcing,
586 // timeForProject,
587 // timeForComputingDeltaT,
588 // timeForPlotting,
589 // timeForShowFile,
590 // timeForWaiting,
591 // maximumNumberOfTimings // number of entries in this list
592 // };
593 // RealArray timing; // for timings, cpu time for some function
594 // aString timingName[maximumNumberOfTimings]; // name of the function being timed
595 
597 };
598 
599 #endif