/
core.cc
2380 lines (2003 loc) · 102 KB
/
core.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2011 - 2017 by the authors of the ASPECT code.
This file is part of ASPECT.
ASPECT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
ASPECT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ASPECT; see the file doc/COPYING. If not see
<http://www.gnu.org/licenses/>.
*/
#include <aspect/simulator.h>
#include <aspect/global.h>
#include <aspect/assembly.h>
#include <aspect/utilities.h>
#include <aspect/melt.h>
#include <aspect/free_surface.h>
#include <aspect/geometry_model/initial_topography_model/zero_topography.h>
#include <deal.II/base/index_set.h>
#include <deal.II/base/conditional_ostream.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/signaling_nan.h>
#include <deal.II/lac/constraint_matrix.h>
#include <deal.II/lac/block_sparsity_pattern.h>
#include <deal.II/lac/sparsity_tools.h>
#include <deal.II/grid/grid_tools.h>
#include <deal.II/dofs/dof_renumbering.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_dgp.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/fe/mapping_q.h>
#include <deal.II/fe/mapping_cartesian.h>
#include <deal.II/numerics/error_estimator.h>
#include <deal.II/numerics/derivative_approximation.h>
#include <deal.II/numerics/vector_tools.h>
#include <deal.II/distributed/solution_transfer.h>
#include <deal.II/distributed/grid_refinement.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <locale>
#include <string>
using namespace dealii;
namespace aspect
{
namespace
{
/**
* Return whether t is an element of the given container object.
*/
template <typename Container>
bool is_element (const typename Container::value_type &t,
const Container &container)
{
for (typename Container::const_iterator p = container.begin();
p != container.end();
++p)
if (*p == t)
return true;
return false;
}
/**
* Helper function to construct the final std::vector of FEVariable before
* it is used to construct the Introspection object. Create the default
* setup based on parameters followed by a signal to allow modifications.
*/
template <int dim>
std::vector<VariableDeclaration<dim> > construct_variables(const Parameters<dim> ¶meters,
SimulatorSignals<dim> &signals,
std_cxx11::shared_ptr<MeltHandler<dim> > &melt_handler)
{
std::vector<VariableDeclaration<dim> > variables
= construct_default_variables (parameters);
if (melt_handler)
melt_handler->edit_finite_element_variables (parameters, variables);
signals.edit_finite_element_variables(variables);
return variables;
}
/**
* Helper function to construct mapping for the model.
* The mapping is given by a degree four MappingQ for the case
* of a curved mesh, and a cartesian mapping for a rectangular mesh that is
* not deformed. Use a MappingQ1 if the mesh is deformed.
* If a free surface is enabled, each mapping is later swapped out for a
* MappingQ1Eulerian, which allows for mesh deformation during the
* computation.
*/
template <int dim>
Mapping<dim> *construct_mapping(const GeometryModel::Interface<dim> &geometry_model,
const InitialTopographyModel::Interface<dim> &initial_topography_model)
{
if (geometry_model.has_curved_elements())
return new MappingQ<dim>(4, true);
if (dynamic_cast<const InitialTopographyModel::ZeroTopography<dim>*>(&initial_topography_model) != 0)
return new MappingCartesian<dim>();
return new MappingQ1<dim>();
}
}
/**
* Constructor of the IntermediaryConstructorAction class. Since the
* class has no members, there is nothing to initialize -- all we
* need to do is execute the 'action' argument.
*/
template <int dim>
Simulator<dim>::IntermediaryConstructorAction::
IntermediaryConstructorAction (std_cxx11::function<void ()> action)
{
action();
}
/**
* Constructor. Initialize all member variables.
**/
template <int dim>
Simulator<dim>::Simulator (const MPI_Comm mpi_communicator_,
ParameterHandler &prm)
:
assemblers (new internal::Assembly::AssemblerLists<dim>()),
parameters (prm, mpi_communicator_),
melt_handler (parameters.include_melt_transport ? new MeltHandler<dim> (prm) : NULL),
post_signal_creation(
std_cxx11::bind (&internals::SimulatorSignals::call_connector_functions<dim>,
std_cxx11::ref(signals))),
introspection (construct_variables<dim>(parameters, signals, melt_handler), parameters),
mpi_communicator (Utilities::MPI::duplicate_communicator (mpi_communicator_)),
iostream_tee_device(std::cout, log_file_stream),
iostream_tee_stream(iostream_tee_device),
pcout (iostream_tee_stream,
(Utilities::MPI::
this_mpi_process(mpi_communicator)
== 0)),
computing_timer (mpi_communicator,
pcout,
TimerOutput::never,
TimerOutput::wall_times),
initial_topography_model(InitialTopographyModel::create_initial_topography_model<dim>(prm)),
geometry_model (GeometryModel::create_geometry_model<dim>(prm)),
// make sure the parameters object gets a chance to
// parse those parameters that depend on symbolic names
// for boundary components
post_geometry_model_creation_action (std_cxx11::bind (&Parameters<dim>::parse_geometry_dependent_parameters,
std_cxx11::ref(parameters),
std_cxx11::ref(prm),
std_cxx11::cref(*geometry_model))),
material_model (MaterialModel::create_material_model<dim>(prm)),
gravity_model (GravityModel::create_gravity_model<dim>(prm)),
// create a boundary temperature model, but only if we actually need
// it. otherwise, allow the user to simply specify nothing at all
boundary_temperature (parameters.fixed_temperature_boundary_indicators.empty()
?
0
:
BoundaryTemperature::create_boundary_temperature<dim>(prm)),
// create a boundary composition model, but only if we actually need
// it. otherwise, allow the user to simply specify nothing at all
boundary_composition (parameters.fixed_composition_boundary_indicators.empty()
?
0
:
BoundaryComposition::create_boundary_composition<dim>(prm)),
prescribed_stokes_solution (PrescribedStokesSolution::create_prescribed_stokes_solution<dim>(prm)),
adiabatic_conditions (AdiabaticConditions::create_adiabatic_conditions<dim>(prm)),
time (std::numeric_limits<double>::quiet_NaN()),
time_step (0),
old_time_step (0),
timestep_number (0),
triangulation (mpi_communicator,
typename Triangulation<dim>::MeshSmoothing
(Triangulation<dim>::smoothing_on_refinement |
Triangulation<dim>::smoothing_on_coarsening),
parallel::distributed::Triangulation<dim>::mesh_reconstruction_after_repartitioning),
mapping(construct_mapping<dim>(*geometry_model,*initial_topography_model)),
// define the finite element
finite_element(introspection.get_fes(), introspection.get_multiplicities()),
dof_handler (triangulation),
last_pressure_normalization_adjustment (numbers::signaling_nan<double>()),
rebuild_stokes_matrix (true),
rebuild_stokes_preconditioner (true)
{
if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
{
// only open the log file on processor 0, the other processors won't be
// writing into the stream anyway
log_file_stream.open((parameters.output_directory + "log.txt").c_str(),
parameters.resume_computation ? std::ios_base::app : std::ios_base::out);
// we already printed the header to the screen, so here we just dump it
// into the log file.
print_aspect_header(log_file_stream);
}
computing_timer.enter_section("Initialization");
// first do some error checking for the parameters we got
{
// make sure velocity and traction boundary indicators don't appear in multiple lists
std::set<types::boundary_id> boundary_indicator_lists[6]
= { parameters.zero_velocity_boundary_indicators,
parameters.tangential_velocity_boundary_indicators,
parameters.free_surface_boundary_indicators,
std::set<types::boundary_id>() // to be prescribed velocity and traction boundary indicators
};
// sets of the boundary indicators only (no selectors and values)
std::set<types::boundary_id> velocity_bi;
std::set<types::boundary_id> traction_bi;
for (std::map<types::boundary_id,std::pair<std::string, std::string> >::const_iterator
p = parameters.prescribed_velocity_boundary_indicators.begin();
p != parameters.prescribed_velocity_boundary_indicators.end();
++p)
velocity_bi.insert(p->first);
for (std::map<types::boundary_id,std::pair<std::string, std::string> >::const_iterator
r = parameters.prescribed_traction_boundary_indicators.begin();
r != parameters.prescribed_traction_boundary_indicators.end();
++r)
traction_bi.insert(r->first);
// are there any indicators that occur in both the prescribed velocity and traction list?
std::set<types::boundary_id> intersection;
std::set_intersection (velocity_bi.begin(),
velocity_bi.end(),
traction_bi.begin(),
traction_bi.end(),
std::inserter(intersection, intersection.end()));
// if so, do they have different selectors?
if (!intersection.empty())
{
for (std::set<types::boundary_id>::const_iterator
it = intersection.begin();
it != intersection.end();
++it)
{
std::set<char> velocity_selector;
std::set<char> traction_selector;
for (std::string::const_iterator
it_selector = parameters.prescribed_velocity_boundary_indicators[*it].first.begin();
it_selector != parameters.prescribed_velocity_boundary_indicators[*it].first.end();
++it_selector)
velocity_selector.insert(*it_selector);
for (std::string::const_iterator
it_selector = parameters.prescribed_traction_boundary_indicators[*it].first.begin();
it_selector != parameters.prescribed_traction_boundary_indicators[*it].first.end();
++it_selector)
traction_selector.insert(*it_selector);
// if there are no selectors specified, throw exception
AssertThrow(!velocity_selector.empty() || !traction_selector.empty(),
ExcMessage ("Boundary indicator <"
+
Utilities::int_to_string(*it)
+
"> with symbolic name <"
+
geometry_model->translate_id_to_symbol_name (*it)
+
"> is listed as having both "
"velocity and traction boundary conditions in the input file."));
std::set<char> intersection_selector;
std::set_intersection (velocity_selector.begin(),
velocity_selector.end(),
traction_selector.begin(),
traction_selector.end(),
std::inserter(intersection_selector, intersection_selector.end()));
// if the same selectors are specified, throw exception
AssertThrow(intersection_selector.empty(),
ExcMessage ("Selectors of boundary indicator <"
+
Utilities::int_to_string(*it)
+
"> with symbolic name <"
+
geometry_model->translate_id_to_symbol_name (*it)
+
"> are listed as having both "
"velocity and traction boundary conditions in the input file."));
}
}
// remove correct boundary indicators that occur in both the velocity and the traction set
// but have different selectors
std::set<types::boundary_id> union_set;
std::set_union (velocity_bi.begin(),
velocity_bi.end(),
traction_bi.begin(),
traction_bi.end(),
std::inserter(union_set, union_set.end()));
// assign the prescribed boundary indicator list to the boundary_indicator_lists
boundary_indicator_lists[3] = union_set;
// for each combination of boundary indicator lists, make sure that the
// intersection is empty
for (unsigned int i=0; i<sizeof(boundary_indicator_lists)/sizeof(boundary_indicator_lists[0]); ++i)
for (unsigned int j=i+1; j<sizeof(boundary_indicator_lists)/sizeof(boundary_indicator_lists[0]); ++j)
{
std::set<types::boundary_id> intersection;
std::set_intersection (boundary_indicator_lists[i].begin(),
boundary_indicator_lists[i].end(),
boundary_indicator_lists[j].begin(),
boundary_indicator_lists[j].end(),
std::inserter(intersection, intersection.end()));
// if the same indicators are specified for different boundary conditions, throw exception
AssertThrow (intersection.empty(),
ExcMessage ("Boundary indicator <"
+
Utilities::int_to_string(*intersection.begin())
+
"> with symbolic name <"
+
geometry_model->translate_id_to_symbol_name (*intersection.begin())
+
"> is listed as having more "
"than one type of velocity or traction boundary condition in the input file."));
}
// Check that the periodic boundaries do not have other boundary conditions set
typedef std::set< std::pair< std::pair< types::boundary_id, types::boundary_id>, unsigned int> >
periodic_boundary_set;
periodic_boundary_set pbs = geometry_model->get_periodic_boundary_pairs();
for (periodic_boundary_set::iterator p = pbs.begin(); p != pbs.end(); ++p)
{
//Throw error if we are trying to use the same boundary for more than one boundary condition
AssertThrow( is_element( (*p).first.first, parameters.fixed_temperature_boundary_indicators ) == false &&
is_element( (*p).first.second, parameters.fixed_temperature_boundary_indicators ) == false &&
is_element( (*p).first.first, parameters.fixed_composition_boundary_indicators ) == false &&
is_element( (*p).first.second, parameters.fixed_composition_boundary_indicators ) == false &&
is_element( (*p).first.first, boundary_indicator_lists[0] ) == false && // zero velocity
is_element( (*p).first.second, boundary_indicator_lists[0] ) == false && // zero velocity
is_element( (*p).first.first, boundary_indicator_lists[1] ) == false && // tangential velocity
is_element( (*p).first.second, boundary_indicator_lists[1] ) == false && // tangential velocity
is_element( (*p).first.first, boundary_indicator_lists[2] ) == false && // free surface
is_element( (*p).first.second, boundary_indicator_lists[2] ) == false && // free surface
is_element( (*p).first.first, boundary_indicator_lists[3] ) == false && // prescribed traction or velocity
is_element( (*p).first.second, boundary_indicator_lists[3] ) == false, // prescribed traction or velocity
ExcMessage("Periodic boundaries must not have boundary conditions set."));
}
const std::set<types::boundary_id> all_boundary_indicators
= geometry_model->get_used_boundary_indicators();
if (parameters.nonlinear_solver!=NonlinearSolver::Advection_only)
{
// next make sure that all listed indicators are actually used by
// this geometry
for (unsigned int i=0; i<sizeof(boundary_indicator_lists)/sizeof(boundary_indicator_lists[0]); ++i)
for (typename std::set<types::boundary_id>::const_iterator
p = boundary_indicator_lists[i].begin();
p != boundary_indicator_lists[i].end(); ++p)
AssertThrow (all_boundary_indicators.find (*p)
!= all_boundary_indicators.end(),
ExcMessage ("One of the boundary indicators listed in the input file "
"is not used by the geometry model."));
}
else
{
// next make sure that there are no listed indicators
for (unsigned int i = 0; i<sizeof(boundary_indicator_lists)/sizeof(boundary_indicator_lists[0]); ++i)
AssertThrow (boundary_indicator_lists[i].empty(),
ExcMessage ("With solver type Advection only, one cannot set boundary conditions for velocity."));
}
// now do the same for the fixed temperature indicators and the
// compositional indicators
for (typename std::set<types::boundary_id>::const_iterator
p = parameters.fixed_temperature_boundary_indicators.begin();
p != parameters.fixed_temperature_boundary_indicators.end(); ++p)
AssertThrow (all_boundary_indicators.find (*p)
!= all_boundary_indicators.end(),
ExcMessage ("One of the fixed boundary temperature indicators listed in the input file "
"is not used by the geometry model."));
for (typename std::set<types::boundary_id>::const_iterator
p = parameters.fixed_composition_boundary_indicators.begin();
p != parameters.fixed_composition_boundary_indicators.end(); ++p)
AssertThrow (all_boundary_indicators.find (*p)
!= all_boundary_indicators.end(),
ExcMessage ("One of the fixed boundary composition indicators listed in the input file "
"is not used by the geometry model."));
}
// if any plugin wants access to the Simulator by deriving from SimulatorAccess, initialize it and
// call the initialize() functions immediately after.
//
// up front, we can not know whether a plugin derives from
// SimulatorAccess. all we have is a pointer to the base class of
// each plugin type (the 'Interface' class in the namespace
// corresponding to each plugin type), but this base class is not
// derived from SimulatorAccess. in order to find out whether a
// concrete plugin derives from this base (interface) class AND
// the SimulatorAccess class via multiple inheritance, we need to
// do a sideways dynamic_cast to this putative sibling of the
// interface class, and investigate if the dynamic_cast
// succeeds. if it succeeds, the dynamic_cast returns a non-NULL
// result, and we can test this in an if-statement. there is a nice
// idiom whereby we can write
// if (SiblingClass *ptr = dynamic_cast<SiblingClass*>(ptr_to_base))
// ptr->do_something()
// where we declare a variable *inside* the 'if' condition, and only
// enter the code block guarded by the 'if' in case the so-declared
// variable evaluates to something non-zero, which here means that
// the dynamic_cast succeeded and returned the address of the sibling
// object.
//
// we also need to let all models parse their parameters. this is done *after* setting
// up their SimulatorAccess base class so that they can query, for example, the
// geometry model's description of symbolic names for boundary parts. note that
// the geometry model is the only model whose run time parameters are already read
// at the time it is created
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(initial_topography_model.get()))
sim->initialize_simulator (*this);
initial_topography_model->initialize ();
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(geometry_model.get()))
sim->initialize_simulator (*this);
geometry_model->initialize ();
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(material_model.get()))
sim->initialize_simulator (*this);
material_model->parse_parameters (prm);
material_model->initialize ();
heating_model_manager.initialize_simulator (*this);
heating_model_manager.parse_parameters (prm);
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(gravity_model.get()))
sim->initialize_simulator (*this);
gravity_model->parse_parameters (prm);
gravity_model->initialize ();
// Create the initial condition plugins
initial_temperature_manager.initialize_simulator(*this);
initial_temperature_manager.parse_parameters (prm);
// Create the initial composition plugins
initial_composition_manager.initialize_simulator(*this);
initial_composition_manager.parse_parameters (prm);
if (boundary_temperature.get())
{
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(boundary_temperature.get()))
sim->initialize_simulator (*this);
boundary_temperature->parse_parameters (prm);
boundary_temperature->initialize ();
}
if (boundary_composition.get())
{
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(boundary_composition.get()))
sim->initialize_simulator (*this);
boundary_composition->parse_parameters (prm);
boundary_composition->initialize ();
}
// Make sure we only have a prescribed Stokes plugin if needed
if (parameters.nonlinear_solver==NonlinearSolver::Advection_only)
{
AssertThrow(prescribed_stokes_solution.get()!=NULL,
ExcMessage("For 'Advection only' solver you need to provide a Stokes plugin")
);
}
else
{
AssertThrow(prescribed_stokes_solution.get()==NULL,
ExcMessage("The prescribed stokes plugin you selected only works with solver type 'Advection only' ")
);
}
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(prescribed_stokes_solution.get()))
sim->initialize_simulator (*this);
if (prescribed_stokes_solution.get())
{
prescribed_stokes_solution->parse_parameters (prm);
prescribed_stokes_solution->initialize ();
}
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(adiabatic_conditions.get()))
sim->initialize_simulator (*this);
adiabatic_conditions->parse_parameters (prm);
adiabatic_conditions->initialize ();
// Initialize the free surface handler
if (parameters.free_surface_enabled)
{
//It should be possible to make the free surface work with any of a number of nonlinear
//schemes, but I do not see a way to do it in generality --IR
AssertThrow( parameters.nonlinear_solver == NonlinearSolver::IMPES ||
parameters.nonlinear_solver == NonlinearSolver::iterated_Stokes,
ExcMessage("The free surface scheme is only implemented for the IMPES or Iterated Stokes solver") );
//Pressure normalization doesn't really make sense with a free surface, and if we do
//use it, we can run into problems with geometry_model->depth().
AssertThrow ( parameters.pressure_normalization == "no",
ExcMessage("The free surface scheme can only be used with no pressure normalization") );
//Allocate the FreeSurfaceHandler object
free_surface.reset( new FreeSurfaceHandler<dim>( *this, prm ) );
}
// Initialize the melt handler
if (parameters.include_melt_transport)
{
AssertThrow( !parameters.use_discontinuous_temperature_discretization &&
!parameters.use_discontinuous_composition_discretization,
ExcMessage("Melt transport can not be used with discontinuous elements.") );
AssertThrow( !parameters.free_surface_enabled,
ExcMessage("Melt transport together with a free surface has not been tested.") );
melt_handler->initialize_simulator (*this);
}
postprocess_manager.initialize_simulator (*this);
postprocess_manager.parse_parameters (prm);
mesh_refinement_manager.initialize_simulator (*this);
mesh_refinement_manager.parse_parameters (prm);
termination_manager.initialize_simulator (*this);
termination_manager.parse_parameters (prm);
lateral_averaging.initialize_simulator (*this);
geometry_model->create_coarse_mesh (triangulation);
global_Omega_diameter = GridTools::diameter (triangulation);
for (std::map<types::boundary_id,std::pair<std::string,std::string> >::const_iterator
p = parameters.prescribed_velocity_boundary_indicators.begin();
p != parameters.prescribed_velocity_boundary_indicators.end();
++p)
{
BoundaryVelocity::Interface<dim> *bv
= BoundaryVelocity::create_boundary_velocity<dim>
(p->second.second);
boundary_velocity[p->first].reset (bv);
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(bv))
sim->initialize_simulator(*this);
bv->parse_parameters (prm);
bv->initialize ();
}
for (std::map<types::boundary_id,std::pair<std::string,std::string> >::const_iterator
p = parameters.prescribed_traction_boundary_indicators.begin();
p != parameters.prescribed_traction_boundary_indicators.end();
++p)
{
BoundaryTraction::Interface<dim> *bv
= BoundaryTraction::create_boundary_traction<dim>
(p->second.second);
boundary_traction[p->first].reset (bv);
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(bv))
sim->initialize_simulator(*this);
bv->parse_parameters (prm);
bv->initialize ();
}
// determine how to treat the pressure. we have to scale it for the solver
// to make velocities and pressures of roughly the same (numerical) size,
// and we may have to fix up the right hand side vector before solving for
// compressible models if there are no in-/outflow boundaries
pressure_scaling = material_model->reference_viscosity() / geometry_model->length_scale();
std::set<types::boundary_id> open_velocity_boundary_indicators
= geometry_model->get_used_boundary_indicators();
for (std::map<types::boundary_id,std::pair<std::string,std::string> >::const_iterator
p = parameters.prescribed_velocity_boundary_indicators.begin();
p != parameters.prescribed_velocity_boundary_indicators.end();
++p)
open_velocity_boundary_indicators.erase (p->first);
for (std::set<types::boundary_id>::const_iterator
p = parameters.zero_velocity_boundary_indicators.begin();
p != parameters.zero_velocity_boundary_indicators.end();
++p)
open_velocity_boundary_indicators.erase (*p);
for (std::set<types::boundary_id>::const_iterator
p = parameters.tangential_velocity_boundary_indicators.begin();
p != parameters.tangential_velocity_boundary_indicators.end();
++p)
open_velocity_boundary_indicators.erase (*p);
// We need to do the RHS compatibility modification, if the model is
// compressible or compatible (in the case of melt transport), and
// there is no open boundary to balance the pressure.
do_pressure_rhs_compatibility_modification = ((material_model->is_compressible() && !parameters.include_melt_transport)
||
(parameters.include_melt_transport && !material_model->is_compressible()))
&&
(open_velocity_boundary_indicators.size() == 0);
// make sure that we don't have to fill every column of the statistics
// object in each time step.
statistics.set_auto_fill_mode(true);
// finally produce a record of the run-time parameters by writing
// the currently used values into a file
// Only write the parameter files on the root node to avoid file system conflicts
if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
{
std::ofstream prm_out ((parameters.output_directory + "parameters.prm").c_str());
AssertThrow (prm_out,
ExcMessage (std::string("Could not open file <") +
parameters.output_directory + "parameters.prm>."));
prm.print_parameters(prm_out, ParameterHandler::Text);
}
if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
{
std::ofstream prm_out ((parameters.output_directory + "parameters.tex").c_str());
AssertThrow (prm_out,
ExcMessage (std::string("Could not open file <") +
parameters.output_directory + "parameters.tex>."));
prm.print_parameters(prm_out, ParameterHandler::LaTeX);
}
// check that the setup of equations, material models, and heating terms is consistent
check_consistency_of_formulation();
// now that all member variables have been set up, also
// connect the functions that will actually do the assembly
set_assemblers();
computing_timer.exit_section();
}
/**
* Destructor.
*/
template <int dim>
Simulator<dim>::~Simulator ()
{
// wait if there is a thread that's still writing the statistics
// object (set from the output_statistics() function)
output_statistics_thread.join();
}
namespace
{
/**
* Conversion object where one can provide a function that returns
* a tensor for the velocity at a given point and it returns something
* that matches the dealii::Function interface with a number of output
* components equal to the number of components of the finite element
* in use.
*/
template <int dim>
class VectorFunctionFromVelocityFunctionObject : public Function<dim>
{
public:
/**
* Given a function object that takes a Point and returns a Tensor<1,dim>,
* convert this into an object that matches the Function@<dim@>
* interface.
*
* @param n_components total number of components of the finite element system.
* @param function_object The function that will form one component
* of the resulting Function object.
*/
VectorFunctionFromVelocityFunctionObject (const unsigned int n_components,
const std_cxx11::function<Tensor<1,dim> (const Point<dim> &)> &function_object);
/**
* Return the value of the
* function at the given
* point. Returns the value the
* function given to the constructor
* produces for this point.
*/
virtual double value (const Point<dim> &p,
const unsigned int component = 0) const;
/**
* Return all components of a
* vector-valued function at a
* given point.
*
* <tt>values</tt> shall have the right
* size beforehand,
* i.e. #n_components.
*/
virtual void vector_value (const Point<dim> &p,
Vector<double> &values) const;
private:
/**
* The function object which we call when this class's value() or
* value_list() functions are called.
**/
const std_cxx11::function<Tensor<1,dim> (const Point<dim> &)> function_object;
};
template <int dim>
VectorFunctionFromVelocityFunctionObject<dim>::
VectorFunctionFromVelocityFunctionObject
(const unsigned int n_components,
const std_cxx11::function<Tensor<1,dim> (const Point<dim> &)> &function_object)
:
Function<dim>(n_components),
function_object (function_object)
{
}
template <int dim>
double
VectorFunctionFromVelocityFunctionObject<dim>::value (const Point<dim> &p,
const unsigned int component) const
{
Assert (component < this->n_components,
ExcIndexRange (component, 0, this->n_components));
if (component < dim)
{
const Tensor<1,dim> v = function_object(p);
return v[component];
}
else
return 0;
}
template <int dim>
void
VectorFunctionFromVelocityFunctionObject<dim>::
vector_value (const Point<dim> &p,
Vector<double> &values) const
{
AssertDimension(values.size(), this->n_components);
// set everything to zero, and then the right components to their correct values
values = 0;
const Tensor<1,dim> v = function_object(p);
for (unsigned int d=0; d<dim; ++d)
values(d) = v[d];
}
}
template <int dim>
void
Simulator<dim>::
start_timestep ()
{
// first produce some output for the screen to show where we are
if (parameters.convert_to_years == true)
pcout << "*** Timestep " << timestep_number
<< ": t=" << time/year_in_seconds
<< " years"
<< std::endl;
else
pcout << "*** Timestep " << timestep_number
<< ": t=" << time
<< " seconds"
<< std::endl;
nonlinear_iteration = 0;
// then interpolate the current boundary velocities. copy constraints
// into current_constraints and then add to current_constraints
compute_current_constraints ();
//TODO: do this in a more efficient way (TH)? we really only need
// to make sure that the time dependent velocity boundary conditions
// end up in the right hand side in the right way; we currently do
// that by re-assembling the entire system
if (!boundary_velocity.empty())
rebuild_stokes_matrix = rebuild_stokes_preconditioner = true;
// notify different system components that we started the next time step
// TODO: implement this for all plugins that might need it at one place.
// Temperature BC are currently updated in compute_current_constraints
material_model->update();
gravity_model->update();
heating_model_manager.update();
adiabatic_conditions->update();
mesh_refinement_manager.update();
if (prescribed_stokes_solution.get())
prescribed_stokes_solution->update();
// do the same for the traction boundary conditions and other things
// that end up in the bilinear form. we update those that end up in
// the constraints object when calling compute_current_constraints()
// above
for (typename std::map<types::boundary_id,std_cxx11::shared_ptr<BoundaryTraction::Interface<dim> > >::iterator
p = boundary_traction.begin();
p != boundary_traction.end(); ++p)
p->second->update ();
}
template <int dim>
void
Simulator<dim>::
compute_current_constraints ()
{
current_constraints.clear ();
current_constraints.reinit (introspection.index_sets.system_relevant_set);
current_constraints.merge (constraints);
{
// set the current time and do the interpolation
// for the prescribed velocity fields
for (typename std::map<types::boundary_id,std_cxx11::shared_ptr<BoundaryVelocity::Interface<dim> > >::iterator
p = boundary_velocity.begin();
p != boundary_velocity.end(); ++p)
{
p->second->update ();
VectorFunctionFromVelocityFunctionObject<dim> vel
(introspection.n_components,
std_cxx11::bind (static_cast<Tensor<1,dim> (BoundaryVelocity::Interface<dim>::*)(
const types::boundary_id,
const Point<dim> &) const> (&BoundaryVelocity::Interface<dim>::boundary_velocity),
p->second,
p->first,
std_cxx11::_1));
// here we create a mask for interpolate_boundary_values out of the 'selector'
std::vector<bool> mask(introspection.component_masks.velocities.size(), false);
const std::string &comp = parameters.prescribed_velocity_boundary_indicators[p->first].first;
if (comp.length()>0)
{
for (std::string::const_iterator direction=comp.begin(); direction!=comp.end(); ++direction)
{
switch (*direction)
{
case 'x':
mask[introspection.component_indices.velocities[0]] = true;
break;
case 'y':
mask[introspection.component_indices.velocities[1]] = true;
break;
case 'z':
// we must be in 3d, or 'z' should never have gotten through
Assert (dim==3, ExcInternalError());
if (dim==3)
mask[introspection.component_indices.velocities[2]] = true;
break;
default:
Assert (false, ExcInternalError());
}
}
}
else
{
// no mask given -- take all velocities
for (unsigned int i=0; i<introspection.component_masks.velocities.size(); ++i)
mask[i]=introspection.component_masks.velocities[i];
}
VectorTools::interpolate_boundary_values (*mapping,
dof_handler,
p->first,
vel,
current_constraints,
mask);
}
}
// If there is a fixed boundary temperature,
// update the temperature boundary condition.
if (boundary_temperature.get())
boundary_temperature->update();
// if using continuous temperature FE, do the same for the temperature variable:
// evaluate the current boundary temperature and add these constraints as well
if (!parameters.use_discontinuous_temperature_discretization)
{
// obtain the boundary indicators that belong to Dirichlet-type
// temperature boundary conditions and interpolate the temperature
// there
for (std::set<types::boundary_id>::const_iterator
p = parameters.fixed_temperature_boundary_indicators.begin();
p != parameters.fixed_temperature_boundary_indicators.end(); ++p)
{
Assert (is_element (*p, geometry_model->get_used_boundary_indicators()),
ExcInternalError());
VectorTools::interpolate_boundary_values (*mapping,
dof_handler,
*p,
VectorFunctionFromScalarFunctionObject<dim>(std_cxx11::bind (&BoundaryTemperature::Interface<dim>::boundary_temperature,
std_cxx11::cref(*boundary_temperature),
*p,
std_cxx11::_1),
introspection.component_masks.temperature.first_selected_component(),
introspection.n_components),
current_constraints,
introspection.component_masks.temperature);
}
}
// If there are fixed boundary compositions,
// update the composition boundary condition.
if (boundary_composition.get())
boundary_composition->update();
// now do the same for the composition variable:
if (!parameters.use_discontinuous_composition_discretization)
{
// obtain the boundary indicators that belong to Dirichlet-type
// composition boundary conditions and interpolate the composition
// there
for (unsigned int c=0; c<introspection.n_compositional_fields; ++c)
for (std::set<types::boundary_id>::const_iterator
p = parameters.fixed_composition_boundary_indicators.begin();
p != parameters.fixed_composition_boundary_indicators.end(); ++p)
{
Assert (is_element (*p, geometry_model->get_used_boundary_indicators()),
ExcInternalError());
VectorTools::interpolate_boundary_values (*mapping,
dof_handler,
*p,
VectorFunctionFromScalarFunctionObject<dim>(std_cxx11::bind (&BoundaryComposition::Interface<dim>::boundary_composition,
std_cxx11::cref(*boundary_composition),
*p,
std_cxx11::_1,
c),
introspection.component_masks.compositional_fields[c].first_selected_component(),
introspection.n_components),
current_constraints,
introspection.component_masks.compositional_fields[c]);
}
}
// let plugins add more constraints if they so choose, then close the
// constraints object
signals.post_constraints_creation(*this, current_constraints);
current_constraints.close();
}
template <int dim>
void
Simulator<dim>::
setup_system_matrix (const std::vector<IndexSet> &system_partitioning)
{
system_matrix.clear ();
Table<2,DoFTools::Coupling> coupling (introspection.n_components,
introspection.n_components);