11#include < aspect/simulator.h>
2- #include < deal.II/grid/tria.h>
2+ #include < aspect/simulator_access.h>
3+
34#include < aspect/material_model/interface.h>
45#include < aspect/material_model/visco_plastic.h>
56#include < aspect/simulator_access.h>
67#include < aspect/newton.h>
78
9+ #include < deal.II/grid/tria.h>
10+ #include < deal.II/base/exceptions.h>
11+ #include < deal.II/base/std_cxx11/shared_ptr.h>
12+
813#include < iostream>
914
10- int f (double parameter)
15+ template <int dim>
16+ void f (const aspect::SimulatorAccess<dim> &simulator_access,
17+ aspect::Assemblers::Manager<dim> &)
1118{
19+ // Prepare NewtonHandler for test
20+ const_cast <aspect::NewtonHandler<dim> &> (simulator_access.get_newton_handler ()).set_newton_derivative_scaling_factor (1.0 );
1221
13- std::cout << std::endl << " Test for p = " << parameter << std::endl;
22+ std::cout << std::endl << " Testing ViscoPlastic derivatives against analytical derivatives " << std::endl;
1423
15- const int dim=2 ;
1624 using namespace aspect ::MaterialModel;
1725 MaterialModelInputs<dim> in_base (5 ,3 );
1826 in_base.composition [0 ][0 ] = 0 ;
@@ -38,9 +46,9 @@ int f(double parameter)
3846 in_base.pressure [4 ] = 5e8 ;
3947
4048 /* *
41- * We can't take to small strain-rates, because then the difference in the
42- * visocisty will be too small for the double accuracy which stores
43- * the visocity solutions and the finite diference solution.
49+ * We can't take too small strain-rates, because then the difference in the
50+ * viscosity will be too small for the double accuracy which stores
51+ * the viscosity solutions and the finite difference solution.
4452 */
4553 in_base.strain_rate [0 ] = SymmetricTensor<2 ,dim>();
4654 in_base.strain_rate [0 ][0 ][0 ] = 1e-12 ;
@@ -125,48 +133,18 @@ int f(double parameter)
125133 MaterialModelOutputs<dim> out_dviscositydstrainrate_oneone (5 ,3 );
126134 MaterialModelOutputs<dim> out_dviscositydtemperature (5 ,3 );
127135
128- if (out_base.get_additional_output <MaterialModelDerivatives<dim> >() != NULL )
129- throw " error" ;
130-
131- out_base.additional_outputs .push_back (std::make_shared<MaterialModelDerivatives<dim> > (5 ));
132-
133- ViscoPlastic<dim> mat;
134- ParameterHandler prm;
135- mat.declare_parameters (prm);
136-
137- prm.enter_subsection (" Compositional fields" );
138- {
139- prm.set (" Number of fields" , " 3" );
140- }
141- prm.leave_subsection ();
142-
143- prm.enter_subsection (" Material model" );
144- {
145- prm.enter_subsection (" Visco Plastic" );
146- {
147- // prm.enter_subsection ("Viscosity");
148- // {
149- // prm.set ("Reference strain rate", "1e-20");
150- prm.set (" Angles of internal friction" , " 30" );
151- // }
152- // prm.leave_subsection();
153- }
154- prm.leave_subsection ();
155- }
156- prm.leave_subsection ();
157-
158- mat.parse_parameters (prm);
136+ out_base.additional_outputs .push_back (std_cxx11::make_shared<MaterialModelDerivatives<dim> > (5 ));
159137
160- mat .evaluate (in_base, out_base);
161- mat .evaluate (in_dviscositydpressure, out_dviscositydpressure);
162- mat .evaluate (in_dviscositydstrainrate_zerozero, out_dviscositydstrainrate_zerozero);
163- mat .evaluate (in_dviscositydstrainrate_onezero, out_dviscositydstrainrate_onezero);
164- mat .evaluate (in_dviscositydstrainrate_oneone, out_dviscositydstrainrate_oneone);
165- mat .evaluate (in_dviscositydtemperature, out_dviscositydtemperature);
138+ simulator_access. get_material_model () .evaluate (in_base, out_base);
139+ simulator_access. get_material_model () .evaluate (in_dviscositydpressure, out_dviscositydpressure);
140+ simulator_access. get_material_model () .evaluate (in_dviscositydstrainrate_zerozero, out_dviscositydstrainrate_zerozero);
141+ simulator_access. get_material_model () .evaluate (in_dviscositydstrainrate_onezero, out_dviscositydstrainrate_onezero);
142+ simulator_access. get_material_model () .evaluate (in_dviscositydstrainrate_oneone, out_dviscositydstrainrate_oneone);
143+ simulator_access. get_material_model () .evaluate (in_dviscositydtemperature, out_dviscositydtemperature);
166144
167145 // set up additional output for the derivatives
168146 MaterialModelDerivatives<dim> *derivatives;
169- derivatives = out_base.get_additional_output <MaterialModelDerivatives<dim> >();
147+ derivatives = out_base.template get_additional_output <MaterialModelDerivatives<dim> >();
170148
171149 double temp;
172150 for (unsigned int i = 0 ; i < 5 ; i++)
@@ -223,7 +201,7 @@ int f(double parameter)
223201 std::cout << " onezero at point " << i << " : Finite difference = " << temp << " . Analytical derivative = " << derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][0 ] << std::endl;
224202 if (std::fabs (temp - derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][0 ]) > 1e-3 * (std::fabs (temp) + std::fabs (derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][0 ])) )
225203 {
226- std::cout << " Error: The derivative of the viscosity to the strain rate is too different from the analitical value." << std::endl;
204+ std::cout << " Error: The derivative of the viscosity to the strain rate is too different from the analytical value." << std::endl;
227205 Error = true ;
228206 }
229207 }
@@ -241,34 +219,40 @@ int f(double parameter)
241219 std::cout << " oneone at point " << i << " : Finite difference = " << temp << " . Analytical derivative = " << derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][1 ] << std::endl;
242220 if (std::fabs (temp - derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][1 ]) > 1e-3 * (std::fabs (temp) + std::fabs (derivatives->viscosity_derivative_wrt_strain_rate [i][1 ][1 ])) )
243221 {
244- std::cout << " Error: The derivative of the viscosity to the strain rate is too different from the analitical value." << std::endl;
222+ std::cout << " Error: The derivative of the viscosity to the strain rate is too different from the analytical value." << std::endl;
245223 Error = true ;
246224 }
247225
248226 }
249227
250228 if (Error)
251229 {
252- std::cout << " Some parts of the test where not succesful ." << std::endl;
230+ std::cout << " Some parts of the test where not successful ." << std::endl;
253231 }
254232 else
255233 {
256234 std::cout << " OK" << std::endl;
257235 }
258236
259- return 42 ;
237+ // Restore NewtonHandler state after test
238+ const_cast <aspect::NewtonHandler<dim> &> (simulator_access.get_newton_handler ()).set_newton_derivative_scaling_factor (0.0 );
239+
240+ }
241+
242+ template <>
243+ void f (const aspect::SimulatorAccess<3 > &simulator_access,
244+ aspect::Assemblers::Manager<3 > &)
245+ {
246+ AssertThrow (false ,dealii::ExcInternalError ());
260247}
261248
262- int exit_function ()
249+ template <int dim>
250+ void signal_connector (aspect::SimulatorSignals<dim> &signals)
263251{
264- exit ( 0 ) ;
265- return 42 ;
252+ std::cout << " * Connecting signals " << std::endl ;
253+ signals. set_assemblers . connect (&f<dim>) ;
266254}
267- // run this function by initializing a global variable by it
268- int ik = f(-1 ); // Testing harmonic mean
269- int ji = f(0 ); // Testing geometric mean
270- int jj = f(1 ); // Testing arithmetic mean
271- int kj = f(1000 ); // Testing max function
272- int kl = exit_function();
273255
256+ ASPECT_REGISTER_SIGNALS_CONNECTOR (signal_connector<2 >,
257+ signal_connector<3 >)
274258
0 commit comments