43 typedef typename TAlgebra::vector_type vector_type;
54 auto limex_integrator =
make_sp(
new limex_type(2));
55 auto newton_solver =
make_sp(
new newton_solver_type());
56 auto linear_solver =
make_sp(
new linear_solver_type());
57 auto ilu =
make_sp(
new ilu_type());
60 auto linear_conv_check =
make_sp(
new conv_check_type(100, 1e-6, 1e-4));
61 linear_solver->set_preconditioner(ilu);
62 linear_solver->set_convergence_check(linear_conv_check);
64 auto newton_conv_check =
make_sp(
new conv_check_type(1, 5e-12, 1e-12));
65 newton_conv_check->set_supress_unsuccessful(
true);
67 newton_solver->set_linear_solver(linear_solver);
68 newton_solver->set_convergence_check(newton_conv_check);
71 auto estimator =
make_sp(
new gf_estimator_type());
74 if (cmp && cmp[0] !=
'\0') {
75 auto l2_cmp =
make_sp(
new l2_type(cmp, 2));
76 estimator->add(l2_cmp.template cast_dynamic<composite_type>());
78 auto l2_A =
make_sp(
new l2_type(
"A", 2));
79 auto l2_v =
make_sp(
new l2_type(
"v", 2));
80 estimator->add(l2_A.template cast_dynamic<composite_type>());
81 estimator->add(l2_v.template cast_dynamic<composite_type>());
85 limex_integrator->add_stage(1, newton_solver, domain_disc);
86 limex_integrator->add_stage(2, newton_solver, domain_disc);
88 limex_integrator->set_tolerance(tolerance);
89 limex_integrator->set_dt_min(1e-12);
90 limex_integrator->set_dt_max(1e10);
91 limex_integrator->add_error_estimator(estimator);
92 limex_integrator->set_increase_factor(2.0);
93 limex_integrator->select_cost_strategy(make_sp<LimexNonlinearCost>(
new LimexNonlinearCost()));
95 return limex_integrator;
105 typedef typename TGridFunction::algebra_type
algebra_type;
116 factory->set_b(params.b);
117 factory->set_gravity(params.gravity);
118 factory->set_diffusion(params.diffusion);
119 factory->set_domain(m_domain);
120 factory->set_ks(params.ks);
123 auto elem_discs = factory->create_1d_swe(
"River");
124 m_elem_disc_A = elem_discs[0];
125 m_elem_disc_v = elem_discs[1];
127 auto A = m_elem_disc_A->value();
128 auto v = m_elem_disc_v->value();
132 auto h =
make_sp(
new inverse_linker_type());
133 h->divide(A, params.b);
136 auto source_linker =
make_sp(
new scale_add_linker_type());
137 source_linker->add(1.0, m_qex);
138 source_linker->add(1.0, params.qr);
139 m_elem_disc_A->set_source(source_linker);
142 auto domain_disc =
make_sp(
new domain_disc_type(m_approx_space));
144 auto neumann_A =
make_sp(
new neumann_type(
"A"));
145 auto neumann_v =
make_sp(
new neumann_type(
"v"));
146 auto dirichlet_A =
make_sp(
new dirichlet_type());
147 auto dirichlet_v =
make_sp(
new dirichlet_type());
150 auto flowrate =
make_sp(
new scale_add_linker_type());
154 auto vv =
make_sp(
new scale_add_linker_type());
156 auto outflow =
make_sp(
new scale_add_linker_type());
157 outflow->add(params.gravity, h);
158 outflow->add(params.gravity, factory->export_sohle());
159 outflow->add(1.0, vv);
162 auto outflow_dir = factory->get_boundary_dir();
163 auto wall_dir =
make_sp(
new scale_add_linker_type());
164 wall_dir->add(-1.0, outflow_dir);
166 auto out_outflow =
make_sp(
new scale_add_linker_type());
167 auto out_flowrate =
make_sp(
new scale_add_linker_type());
168 out_outflow->add(outflow_dir, outflow);
169 out_flowrate->add(outflow_dir, flowrate);
172 dirichlet_A->add(params.dirichlet_A,
"A",
"Level");
173 dirichlet_v->add(0.0,
"v",
"Wall");
175 neumann_A->add(out_flowrate.template cast_dynamic<TNumberData>(),
"Sink",
"River");
176 neumann_v->add(out_outflow.template cast_dynamic<TNumberData>(),
"Sink",
"River");
177 neumann_v->add(out_outflow.template cast_dynamic<TNumberData>(),
"Level",
"River");
192 vtk->select(
"v",
"v");
193 vtk->select(
"A",
"A");
194 vtk->select(factory->export_sohle().template cast_dynamic<UserData<number, dim>>(),
"sohle");
199 voutflow->add(v, downStreamVec);
200 auto outflow_observer =
make_sp(
new outflow_observer_type(voutflow, A,
"Sink",
"River"));
201 limex_integrator->attach_observer(outflow_observer);
212 if (!m_domain->empty() ||
true) {
213 limex_integrator->apply(this->m_u, tEnd, this->m_u, tStart);
221 typedef typename TGridFunction::template dim_traits<1>::const_iterator const_iterator;
223 const_iterator iter = this->m_u->template begin<grid_base_object>();
224 const_iterator iterEnd = this->m_u->template end<grid_base_object>();
228 integrand_type A_integrand = integrand_type(m_elem_disc_A->value(), this->m_u.get(), tEnd);
229 number value = 1000 * Integrate<dim, 1, const_iterator>(iter, iterEnd,
230 this->m_u->domain()->position_accessor(),
233 vtk->print(
"results/rivers", *this->m_u, m_step, tEnd);
235 std::ofstream myfile;
236 myfile.open(
"results/river_outflow.txt", std::ios::out | std::ios::app);
237 myfile << tEnd <<
"\t" << outflow_observer->value() <<
"\t"<< value <<
"\n";
238 UG_LOGN(
"Total River outflow for dt = " <<tEnd - tStart <<
" is " << outflow_observer->value() <<
" kg\n" );
254 const char* m_filename =
"results/river_outflow.txt";
259 std::ofstream myfile;
260 myfile.open(m_filename, std::ios::out | std::ios::trunc);
261 myfile <<
"time\taccumulated outflow since last measurement\tstorage\n";
267 dom->update_domain_info();
269 std::vector<std::string> additionalSHNames = dom->additional_subset_handler_names();
270 std::vector<SmartPtr<ISubsetHandler>> ash(additionalSHNames.size());
271 for(
size_t i = 0; i < additionalSHNames.size(); ++i) {
272 ash[i] = dom->additional_subset_handler(additionalSHNames[i]);
281 LoadGridFromUGX(*(dom->grid()), ph, num_ph, *(dom->subset_handler()), additionalSHNames, ash, filename, dom->position_attachment());
283 dom->update_subset_infos(-2);
285 dom->update_domain_info();
293 m_approx_space->add(
"A",
"Lagrange", 1);
294 m_approx_space->add(
"v",
"Lagrange", 1);
295 m_approx_space->init_levels();
296 m_approx_space->init_top_surface();
299 this->m_u =
make_sp(
new TGridFunction(m_approx_space));
305 factory->set_domain(m_domain);
306 factory->set_b(params.b);
307 factory->set_gravity(params.gravity);
308 factory->set_diffusion(params.diffusion);
309 factory->set_ks(params.ks);
311 auto elem_discs = factory->create_1d_swe(
"River");
312 m_elem_disc_A = elem_discs[0];
313 m_elem_disc_v = elem_discs[1];
SmartPtr< LimexTimeIntegrator< TDomain, TAlgebra > > create_limex_solver(number tolerance, SmartPtr< DomainDiscretization< TDomain, TAlgebra > > domain_disc, SmartPtr< TDomain > domain, const char *cmp="")
Creates and configures the Limex Time Integrator for the St. Venant equations.
Definition st_venant_submodule_impl.h:36