Graph Framework
Loading...
Searching...
No Matches
solver.hpp
Go to the documentation of this file.
1//------------------------------------------------------------------------------
6//------------------------------------------------------------------------------
7//------------------------------------------------------------------------------
103//------------------------------------------------------------------------------
104#ifndef solver_h
105#define solver_h
106
107#include <thread>
108
109#include "dispersion.hpp"
110#include "output.hpp"
111
113namespace solver {
114//******************************************************************************
115// Solver interface.
116//******************************************************************************
117//------------------------------------------------------------------------------
121//------------------------------------------------------------------------------
122 template<dispersion::function DISPERSION_FUNCTION>
124 protected:
126 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
127 DISPERSION_FUNCTION::safe_math> w;
129 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
130 DISPERSION_FUNCTION::safe_math> kx;
132 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
133 DISPERSION_FUNCTION::safe_math> ky;
135 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
136 DISPERSION_FUNCTION::safe_math> kz;
138 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
139 DISPERSION_FUNCTION::safe_math> x;
141 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
142 DISPERSION_FUNCTION::safe_math> y;
144 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
145 DISPERSION_FUNCTION::safe_math> z;
147 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
148 DISPERSION_FUNCTION::safe_math> t;
149
152
154 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
155 DISPERSION_FUNCTION::safe_math> kx_next;
157 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
158 DISPERSION_FUNCTION::safe_math> ky_next;
160 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
161 DISPERSION_FUNCTION::safe_math> kz_next;
163 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
164 DISPERSION_FUNCTION::safe_math> x_next;
166 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
167 DISPERSION_FUNCTION::safe_math> y_next;
169 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
170 DISPERSION_FUNCTION::safe_math> z_next;
172 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
173 DISPERSION_FUNCTION::safe_math> t_next;
174
176 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
177 DISPERSION_FUNCTION::safe_math> residual;
178
180 workflow::manager<typename DISPERSION_FUNCTION::base,
181 DISPERSION_FUNCTION::safe_math> work;
183 const size_t index;
184
189
191 std::thread sync;
192
193 public:
194//------------------------------------------------------------------------------
209//------------------------------------------------------------------------------
210 solver_interface(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
211 DISPERSION_FUNCTION::safe_math> w,
212 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
213 DISPERSION_FUNCTION::safe_math> kx,
214 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
215 DISPERSION_FUNCTION::safe_math> ky,
216 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
217 DISPERSION_FUNCTION::safe_math> kz,
218 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
219 DISPERSION_FUNCTION::safe_math> x,
220 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
221 DISPERSION_FUNCTION::safe_math> y,
222 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
223 DISPERSION_FUNCTION::safe_math> z,
224 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
225 DISPERSION_FUNCTION::safe_math> t,
226 equilibrium::shared<typename DISPERSION_FUNCTION::base,
227 DISPERSION_FUNCTION::safe_math> &eq,
228 const std::string &filename="",
229 const size_t num_rays=0,
230 const size_t index=0) :
231 D(w, kx, ky, kz, x, y, z, t, eq), w(w),
232 kx(kx), ky(ky), kz(kz), x(x), y(y), z(z), t(t),
233 file(filename, num_rays), dataset(file),
234 index(index), work(index), sync([]{}) {}
235
236//------------------------------------------------------------------------------
238//------------------------------------------------------------------------------
240 sync.join();
241 }
242
243//------------------------------------------------------------------------------
251//------------------------------------------------------------------------------
252 virtual graph::shared_leaf<typename DISPERSION_FUNCTION::base,
253 DISPERSION_FUNCTION::safe_math>
254 init(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
255 DISPERSION_FUNCTION::safe_math> x,
256 const typename DISPERSION_FUNCTION::base tolerance = 1.0E-30,
257 const size_t max_iterations = 1000) final {
258 graph::input_nodes<typename DISPERSION_FUNCTION::base,
259 DISPERSION_FUNCTION::safe_math> inputs {
260 graph::variable_cast(this->t),
261 graph::variable_cast(this->w),
262 graph::variable_cast(this->x),
263 graph::variable_cast(this->y),
264 graph::variable_cast(this->z),
265 graph::variable_cast(this->kx),
266 graph::variable_cast(this->ky),
267 graph::variable_cast(this->kz)
268 };
269
270 residual = this->D.solve(x, inputs, index,
271 tolerance, max_iterations);
272
273 return residual;
274 }
275
276//------------------------------------------------------------------------------
280//------------------------------------------------------------------------------
281 virtual graph::shared_leaf<typename DISPERSION_FUNCTION::base,
282 DISPERSION_FUNCTION::safe_math> init() final {
283 graph::input_nodes<typename DISPERSION_FUNCTION::base,
284 DISPERSION_FUNCTION::safe_math> inputs {
285 graph::variable_cast(this->t),
286 graph::variable_cast(this->w),
287 graph::variable_cast(this->x),
288 graph::variable_cast(this->y),
289 graph::variable_cast(this->z),
290 graph::variable_cast(this->kx),
291 graph::variable_cast(this->ky),
292 graph::variable_cast(this->kz)
293 };
294
295 residual = this->D.get_residual();
296
297 return residual;
298 }
299
300//------------------------------------------------------------------------------
302//------------------------------------------------------------------------------
303 virtual void compile() {
304 graph::input_nodes<typename DISPERSION_FUNCTION::base,
305 DISPERSION_FUNCTION::safe_math> inputs = {
306 graph::variable_cast(this->t),
307 graph::variable_cast(this->w),
308 graph::variable_cast(this->x),
309 graph::variable_cast(this->y),
310 graph::variable_cast(this->z),
311 graph::variable_cast(this->kx),
312 graph::variable_cast(this->ky),
313 graph::variable_cast(this->kz)
314 };
315
316 graph::output_nodes<typename DISPERSION_FUNCTION::base,
317 DISPERSION_FUNCTION::safe_math> outputs = {
318 this->residual
319 };
320
321 graph::map_nodes<typename DISPERSION_FUNCTION::base,
322 DISPERSION_FUNCTION::safe_math> setters = {
323 {this->kx_next, graph::variable_cast(this->kx)},
324 {this->ky_next, graph::variable_cast(this->ky)},
325 {this->kz_next, graph::variable_cast(this->kz)},
326 {this->x_next, graph::variable_cast(this->x)},
327 {this->y_next, graph::variable_cast(this->y)},
328 {this->z_next, graph::variable_cast(this->z)},
329 {this->t_next, graph::variable_cast(this->t)}
330 };
331
332 work.add_item(inputs, outputs, setters, {}, NULL,
333 "solver_kernel", inputs.back()->size());
334 work.compile();
335
336 dataset.create_variable(file, "time", this->t, work.get_context());
338 dataset.create_variable(file, "w", this->w, work.get_context());
339 dataset.create_variable(file, "x", this->x, work.get_context());
340 dataset.create_variable(file, "y", this->y, work.get_context());
341 dataset.create_variable(file, "z", this->z, work.get_context());
342 dataset.create_variable(file, "kx", this->kx, work.get_context());
343 dataset.create_variable(file, "ky", this->ky, work.get_context());
344 dataset.create_variable(file, "kz", this->kz, work.get_context());
345
347 }
348
349//------------------------------------------------------------------------------
351//------------------------------------------------------------------------------
352 void sync_device() {
353 work.copy_to_device(this->t, graph::variable_cast(this->t)->data());
354 work.copy_to_device(this->w, graph::variable_cast(this->w)->data());
355 work.copy_to_device(this->x, graph::variable_cast(this->x)->data());
356 work.copy_to_device(this->y, graph::variable_cast(this->y)->data());
357 work.copy_to_device(this->z, graph::variable_cast(this->z)->data());
358 work.copy_to_device(this->kx, graph::variable_cast(this->kx)->data());
359 work.copy_to_device(this->ky, graph::variable_cast(this->ky)->data());
360 work.copy_to_device(this->kz, graph::variable_cast(this->kz)->data());
361 }
362
363//------------------------------------------------------------------------------
365//------------------------------------------------------------------------------
366 void sync_host() {
367 work.copy_to_host(this->t, graph::variable_cast(this->t)->data());
368 work.copy_to_host(this->w, graph::variable_cast(this->w)->data());
369 work.copy_to_host(this->x, graph::variable_cast(this->x)->data());
370 work.copy_to_host(this->y, graph::variable_cast(this->y)->data());
371 work.copy_to_host(this->z, graph::variable_cast(this->z)->data());
372 work.copy_to_host(this->kx, graph::variable_cast(this->kx)->data());
373 work.copy_to_host(this->ky, graph::variable_cast(this->ky)->data());
374 work.copy_to_host(this->kz, graph::variable_cast(this->kz)->data());
375 }
376
377//------------------------------------------------------------------------------
379//------------------------------------------------------------------------------
380 void step() {
381 work.run();
382 }
383
384//------------------------------------------------------------------------------
389//------------------------------------------------------------------------------
390 typename DISPERSION_FUNCTION::base check_residual(const size_t index) {
391 return work.check_value(index, this->residual);
392 }
393
394//------------------------------------------------------------------------------
398//------------------------------------------------------------------------------
399 void print(const size_t index) {
400 work.print(index, {
401 this->t,
402 this->residual,
403 this->w,
404 this->x,
405 this->y,
406 this->z,
407 this->kx,
408 this->ky,
409 this->kz
410 });
411 }
412
413//------------------------------------------------------------------------------
415//------------------------------------------------------------------------------
416 void write_step() {
417 sync.join();
418 work.wait();
419 sync = std::thread([this] {
421 });
422 }
423
424//------------------------------------------------------------------------------
426//------------------------------------------------------------------------------
428 D.print_dispersion();
429 }
430
431//------------------------------------------------------------------------------
433//------------------------------------------------------------------------------
434 void print_dkxdt() {
435 D.print_dkxdt();
436 }
437
438//------------------------------------------------------------------------------
440//------------------------------------------------------------------------------
441 void print_dkydt() {
442 D.print_dkydt();
443 }
444
445//------------------------------------------------------------------------------
447//------------------------------------------------------------------------------
448 void print_dkzdt() {
449 D.print_dkzdt();
450 }
451
452//------------------------------------------------------------------------------
454//------------------------------------------------------------------------------
455 void print_dxdt() {
456 D.print_dxdt();
457 }
458
459//------------------------------------------------------------------------------
461//------------------------------------------------------------------------------
462 void print_dydt() {
463 D.print_dydt();
464 }
465
466//------------------------------------------------------------------------------
468//------------------------------------------------------------------------------
469 void print_dzdt() {
470 D.print_dzdt();
471 }
472
473//------------------------------------------------------------------------------
475//------------------------------------------------------------------------------
477 residual->to_latex();
478 std::cout << std::endl;
479 }
480
481//------------------------------------------------------------------------------
483//------------------------------------------------------------------------------
485 x_next->to_latex();
486 std::cout << std::endl;
487 }
488
489//------------------------------------------------------------------------------
491//------------------------------------------------------------------------------
493 y_next->to_latex();
494 std::cout << std::endl;
495 }
496
497//------------------------------------------------------------------------------
499//------------------------------------------------------------------------------
501 z_next->to_latex();
502 std::cout << std::endl;
503 }
504
505//------------------------------------------------------------------------------
507//------------------------------------------------------------------------------
509 kx_next->to_latex();
510 std::cout << std::endl;
511 }
512
513//------------------------------------------------------------------------------
515//------------------------------------------------------------------------------
517 ky_next->to_latex();
518 std::cout << std::endl;
519 }
520
521//------------------------------------------------------------------------------
523//------------------------------------------------------------------------------
525 kz_next->to_latex();
526 std::cout << std::endl;
527 }
529 typedef DISPERSION_FUNCTION dispersion_function;
531 typedef typename DISPERSION_FUNCTION::base base;
533 static constexpr bool safe_math = DISPERSION_FUNCTION::safe_math;
534 };
535
537 template<class S>
538 concept method = std::is_base_of<solver_interface<typename S::dispersion_function>, S>::value;
539
540//******************************************************************************
541// Second Order Runge Kutta.
542//******************************************************************************
543//------------------------------------------------------------------------------
547//------------------------------------------------------------------------------
548 template<dispersion::function DISPERSION_FUNCTION>
549 class rk2 : public solver_interface<DISPERSION_FUNCTION> {
550 protected:
552 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
553 DISPERSION_FUNCTION::safe_math> kx1;
555 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
556 DISPERSION_FUNCTION::safe_math> ky1;
558 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
559 DISPERSION_FUNCTION::safe_math> kz1;
561 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
562 DISPERSION_FUNCTION::safe_math> x1;
564 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
565 DISPERSION_FUNCTION::safe_math> y1;
567 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
568 DISPERSION_FUNCTION::safe_math> z1;
569
571 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
572 DISPERSION_FUNCTION::safe_math> kx2;
574 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
575 DISPERSION_FUNCTION::safe_math> ky2;
577 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
578 DISPERSION_FUNCTION::safe_math> kz2;
580 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
581 DISPERSION_FUNCTION::safe_math> x2;
583 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
584 DISPERSION_FUNCTION::safe_math> y2;
586 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
587 DISPERSION_FUNCTION::safe_math> z2;
588
589 public:
590//------------------------------------------------------------------------------
606//------------------------------------------------------------------------------
607 rk2(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
608 DISPERSION_FUNCTION::safe_math> w,
609 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
610 DISPERSION_FUNCTION::safe_math> kx,
611 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
612 DISPERSION_FUNCTION::safe_math> ky,
613 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
614 DISPERSION_FUNCTION::safe_math> kz,
615 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
616 DISPERSION_FUNCTION::safe_math> x,
617 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
618 DISPERSION_FUNCTION::safe_math> y,
619 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
620 DISPERSION_FUNCTION::safe_math> z,
621 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
622 DISPERSION_FUNCTION::safe_math> t,
623 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
624 DISPERSION_FUNCTION::safe_math> dt,
625 equilibrium::shared<typename DISPERSION_FUNCTION::base,
626 DISPERSION_FUNCTION::safe_math> &eq,
627 const std::string &filename="",
628 const size_t num_rays=0,
629 const size_t index=0) :
630 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
631 filename, num_rays, index) {
632 this->kx1 = dt*this->D.get_dkxdt();
633 this->ky1 = dt*this->D.get_dkydt();
634 this->kz1 = dt*this->D.get_dkzdt();
635 this->x1 = dt*this->D.get_dxdt();
636 this->y1 = dt*this->D.get_dydt();
637 this->z1 = dt*this->D.get_dzdt();
638
640 graph::pseudo_variable(this->kx + kx1),
641 graph::pseudo_variable(this->ky + ky1),
642 graph::pseudo_variable(this->kz + kz1),
643 graph::pseudo_variable(this->x + x1),
644 graph::pseudo_variable(this->y + y1),
645 graph::pseudo_variable(this->z + z1),
646 graph::pseudo_variable(this->t + dt),
647 eq);
648
649 this->kx2 = dt*D2.get_dkxdt();
650 this->ky2 = dt*D2.get_dkydt();
651 this->kz2 = dt*D2.get_dkzdt();
652 this->x2 = dt*D2.get_dxdt();
653 this->y2 = dt*D2.get_dydt();
654 this->z2 = dt*D2.get_dzdt();
655
656 this->kx_next = this->kx + (this->kx1 + this->kx2)/2.0;
657 this->ky_next = this->ky + (this->ky1 + this->ky2)/2.0;
658 this->kz_next = this->kz + (this->kz1 + this->kz2)/2.0;
659 this->x_next = this->x + (this->x1 + this->x2 )/2.0;
660 this->y_next = this->y + (this->y1 + this->y2 )/2.0;
661 this->z_next = this->z + (this->z1 + this->z2 )/2.0;
662 this->t_next = this->t + dt;
663 }
664 };
665
666//******************************************************************************
667// Fourth Order Runge Kutta.
668//******************************************************************************
669//------------------------------------------------------------------------------
673//------------------------------------------------------------------------------
674 template<dispersion::function DISPERSION_FUNCTION>
675 class rk4 : public solver_interface<DISPERSION_FUNCTION> {
676 protected:
678 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
679 DISPERSION_FUNCTION::safe_math> kx1;
681 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
682 DISPERSION_FUNCTION::safe_math> ky1;
684 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
685 DISPERSION_FUNCTION::safe_math> kz1;
687 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
688 DISPERSION_FUNCTION::safe_math> x1;
690 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
691 DISPERSION_FUNCTION::safe_math> y1;
693 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
694 DISPERSION_FUNCTION::safe_math> z1;
695
697 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
698 DISPERSION_FUNCTION::safe_math> kx2;
700 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
701 DISPERSION_FUNCTION::safe_math> ky2;
703 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
704 DISPERSION_FUNCTION::safe_math> kz2;
706 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
707 DISPERSION_FUNCTION::safe_math> x2;
709 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
710 DISPERSION_FUNCTION::safe_math> y2;
712 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
713 DISPERSION_FUNCTION::safe_math> z2;
714
716 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
717 DISPERSION_FUNCTION::safe_math> kx3;
719 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
720 DISPERSION_FUNCTION::safe_math> ky3;
722 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
723 DISPERSION_FUNCTION::safe_math> kz3;
725 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
726 DISPERSION_FUNCTION::safe_math> x3;
728 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
729 DISPERSION_FUNCTION::safe_math> y3;
731 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
732 DISPERSION_FUNCTION::safe_math> z3;
733
735 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
736 DISPERSION_FUNCTION::safe_math> kx4;
738 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
739 DISPERSION_FUNCTION::safe_math> ky4;
741 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
742 DISPERSION_FUNCTION::safe_math> kz4;
744 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
745 DISPERSION_FUNCTION::safe_math> x4;
747 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
748 DISPERSION_FUNCTION::safe_math> y4;
750 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
751 DISPERSION_FUNCTION::safe_math> z4;
752
754 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
755 DISPERSION_FUNCTION::safe_math> t_sub;
756
757 public:
758//------------------------------------------------------------------------------
774//------------------------------------------------------------------------------
775 rk4(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
776 DISPERSION_FUNCTION::safe_math> w,
777 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
778 DISPERSION_FUNCTION::safe_math> kx,
779 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
780 DISPERSION_FUNCTION::safe_math> ky,
781 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
782 DISPERSION_FUNCTION::safe_math> kz,
783 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
784 DISPERSION_FUNCTION::safe_math> x,
785 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
786 DISPERSION_FUNCTION::safe_math> y,
787 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
788 DISPERSION_FUNCTION::safe_math> z,
789 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
790 DISPERSION_FUNCTION::safe_math> t,
791 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
792 DISPERSION_FUNCTION::safe_math> dt,
793 equilibrium::shared<typename DISPERSION_FUNCTION::base,
794 DISPERSION_FUNCTION::safe_math> &eq,
795 const std::string &filename="",
796 const size_t num_rays=0,
797 const size_t index=0) :
798 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
799 filename, num_rays, index) {
800 this->kx1 = dt*this->D.get_dkxdt();
801 this->ky1 = dt*this->D.get_dkydt();
802 this->kz1 = dt*this->D.get_dkzdt();
803 this->x1 = dt*this->D.get_dxdt();
804 this->y1 = dt*this->D.get_dydt();
805 this->z1 = dt*this->D.get_dzdt();
806
807 this->t_sub = this->t + dt/2.0;
808
810 graph::pseudo_variable(this->kx + kx1/2.0),
811 graph::pseudo_variable(this->ky + ky1/2.0),
812 graph::pseudo_variable(this->kz + kz1/2.0),
813 graph::pseudo_variable(this->x + x1/2.0),
814 graph::pseudo_variable(this->y + y1/2.0),
815 graph::pseudo_variable(this->z + z1/2.0),
816 graph::pseudo_variable(this->t_sub),
817 eq);
818
819 this->kx2 = dt*D2.get_dkxdt();
820 this->ky2 = dt*D2.get_dkydt();
821 this->kz2 = dt*D2.get_dkzdt();
822 this->x2 = dt*D2.get_dxdt();
823 this->y2 = dt*D2.get_dydt();
824 this->z2 = dt*D2.get_dzdt();
825
827 graph::pseudo_variable(this->kx + kx2/2.0),
828 graph::pseudo_variable(this->ky + ky2/2.0),
829 graph::pseudo_variable(this->kz + kz2/2.0),
830 graph::pseudo_variable(this->x + x2/2.0),
831 graph::pseudo_variable(this->y + y2/2.0),
832 graph::pseudo_variable(this->z + z2/2.0),
833 graph::pseudo_variable(this->t_sub),
834 eq);
835
836 this->kx3 = dt*D3.get_dkxdt();
837 this->ky3 = dt*D3.get_dkydt();
838 this->kz3 = dt*D3.get_dkzdt();
839 this->x3 = dt*D3.get_dxdt();
840 this->y3 = dt*D3.get_dydt();
841 this->z3 = dt*D3.get_dzdt();
842
843 this->t_next = this->t + dt;
844
846 graph::pseudo_variable(this->kx + kx3),
847 graph::pseudo_variable(this->ky + ky3),
848 graph::pseudo_variable(this->kz + kz3),
849 graph::pseudo_variable(this->x + x3),
850 graph::pseudo_variable(this->y + y3),
851 graph::pseudo_variable(this->z + z3),
853 eq);
854
855 this->kx4 = dt*D4.get_dkxdt();
856 this->ky4 = dt*D4.get_dkydt();
857 this->kz4 = dt*D4.get_dkzdt();
858 this->x4 = dt*D4.get_dxdt();
859 this->y4 = dt*D4.get_dydt();
860 this->z4 = dt*D4.get_dzdt();
861
862 this->kx_next = this->kx + (this->kx1 + 2.0*(this->kx2 + this->kx3) + this->kx4)/6.0;
863 this->ky_next = this->ky + (this->ky1 + 2.0*(this->ky2 + this->ky3) + this->ky4)/6.0;
864 this->kz_next = this->kz + (this->kz1 + 2.0*(this->kz2 + this->kz3) + this->kz4)/6.0;
865 this->x_next = this->x + (this->x1 + 2.0*(this->x2 + this->x3 ) + this->x4 )/6.0;
866 this->y_next = this->y + (this->y1 + 2.0*(this->y2 + this->y3 ) + this->y4 )/6.0;
867 this->z_next = this->z + (this->z1 + 2.0*(this->z2 + this->z3 ) + this->z4 )/6.0;
868 }
869 };
870
871//******************************************************************************
872// Adaptive time step Fourth Order Runge Kutta.
873//******************************************************************************
874//------------------------------------------------------------------------------
878//------------------------------------------------------------------------------
879 template<dispersion::function DISPERSION_FUNCTION>
880 class adaptive_rk4 : public rk4<DISPERSION_FUNCTION> {
881 protected:
885 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
886 DISPERSION_FUNCTION::safe_math> dt_var;
887
888 public:
889//------------------------------------------------------------------------------
905//------------------------------------------------------------------------------
906 adaptive_rk4(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
907 DISPERSION_FUNCTION::safe_math> w,
908 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
909 DISPERSION_FUNCTION::safe_math> kx,
910 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
911 DISPERSION_FUNCTION::safe_math> ky,
912 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
913 DISPERSION_FUNCTION::safe_math> kz,
914 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
915 DISPERSION_FUNCTION::safe_math> x,
916 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
917 DISPERSION_FUNCTION::safe_math> y,
918 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
919 DISPERSION_FUNCTION::safe_math> z,
920 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
921 DISPERSION_FUNCTION::safe_math> t,
922 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
923 DISPERSION_FUNCTION::safe_math> dt,
924 equilibrium::shared<typename DISPERSION_FUNCTION::base,
925 DISPERSION_FUNCTION::safe_math> &eq,
926 const std::string &filename="",
927 const size_t num_rays=0,
928 const size_t index=0) :
929 rk4<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, dt, eq,
930 filename, num_rays, index),
931 D(w,
932 graph::pseudo_variable(this->kx_next),
933 graph::pseudo_variable(this->ky_next),
934 graph::pseudo_variable(this->kz_next),
935 graph::pseudo_variable(this->x_next),
936 graph::pseudo_variable(this->y_next),
937 graph::pseudo_variable(this->z_next),
938 graph::pseudo_variable(this->t_next),
939 eq),
940 dt_var(dt) {}
941
942//------------------------------------------------------------------------------
944//------------------------------------------------------------------------------
945 virtual void compile() final {
946 auto var = graph::variable_cast(dt_var);
947 auto lambda = graph::variable(var->size(), static_cast<typename DISPERSION_FUNCTION::base> (1.0), "\\lambda");
948 auto loss = graph::one<typename DISPERSION_FUNCTION::base,
949 DISPERSION_FUNCTION::safe_math> ()/dt_var + lambda*D.get_d()*D.get_d();
950
951 graph::input_nodes<typename DISPERSION_FUNCTION::base,
952 DISPERSION_FUNCTION::safe_math> inputs = {
953 graph::variable_cast(this->t),
954 graph::variable_cast(this->w),
955 graph::variable_cast(this->x),
956 graph::variable_cast(this->y),
957 graph::variable_cast(this->z),
961 var,
963 };
964
965 solver::newton<typename DISPERSION_FUNCTION::base,
966 DISPERSION_FUNCTION::safe_math> (this->work, {
967 var, graph::variable_cast(lambda)
968 }, inputs, {}, loss, NULL);
969
970 inputs = {
971 graph::variable_cast(this->t),
972 graph::variable_cast(this->w),
973 graph::variable_cast(this->x),
974 graph::variable_cast(this->y),
975 graph::variable_cast(this->z),
979 var
980 };
981
982 graph::output_nodes<typename DISPERSION_FUNCTION::base,
983 DISPERSION_FUNCTION::safe_math> outputs = {
984 this->residual
985 };
986
987 graph::map_nodes<typename DISPERSION_FUNCTION::base,
988 DISPERSION_FUNCTION::safe_math> setters = {
989 {this->kx_next, graph::variable_cast(this->kx)},
990 {this->ky_next, graph::variable_cast(this->ky)},
991 {this->kz_next, graph::variable_cast(this->kz)},
992 {this->x_next, graph::variable_cast(this->x)},
993 {this->y_next, graph::variable_cast(this->y)},
994 {this->z_next, graph::variable_cast(this->z)},
995 {this->t_next, graph::variable_cast(this->t)}
996 };
997
998 this->work.add_item(inputs, outputs, setters, {}, NULL,
999 "solver_kernel", inputs.back()->size());
1000 this->work.compile();
1001 }
1002 };
1003
1004//******************************************************************************
1005// Split simplextic integrator
1006//******************************************************************************
1007//------------------------------------------------------------------------------
1011//------------------------------------------------------------------------------
1012 template<dispersion::function DISPERSION_FUNCTION>
1013 class split_simplextic : public solver_interface<DISPERSION_FUNCTION> {
1014 protected:
1016 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1017 DISPERSION_FUNCTION::safe_math> x1;
1019 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1020 DISPERSION_FUNCTION::safe_math> y1;
1022 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1023 DISPERSION_FUNCTION::safe_math> z1;
1024
1025 public:
1026//------------------------------------------------------------------------------
1042//------------------------------------------------------------------------------
1043 split_simplextic(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1044 DISPERSION_FUNCTION::safe_math> w,
1045 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1046 DISPERSION_FUNCTION::safe_math> kx,
1047 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1048 DISPERSION_FUNCTION::safe_math> ky,
1049 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1050 DISPERSION_FUNCTION::safe_math> kz,
1051 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1052 DISPERSION_FUNCTION::safe_math> x,
1053 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1054 DISPERSION_FUNCTION::safe_math> y,
1055 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1056 DISPERSION_FUNCTION::safe_math> z,
1057 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1058 DISPERSION_FUNCTION::safe_math> t,
1059 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1060 DISPERSION_FUNCTION::safe_math> dt,
1061 equilibrium::shared<typename DISPERSION_FUNCTION::base,
1062 DISPERSION_FUNCTION::safe_math> &eq,
1063 const std::string &filename="",
1064 const size_t num_rays=0,
1065 const size_t index=0) :
1066 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
1067 filename, num_rays, index) {
1068
1069// Test if the function is separable.
1071
1072 assert(zero->is_match(this->D.get_dkxdt()->df(kx)) &&
1073 zero->is_match(this->D.get_dkxdt()->df(ky)) &&
1074 zero->is_match(this->D.get_dkxdt()->df(kz)) &&
1075 zero->is_match(this->D.get_dkydt()->df(kx)) &&
1076 zero->is_match(this->D.get_dkydt()->df(ky)) &&
1077 zero->is_match(this->D.get_dkydt()->df(kz)) &&
1078 zero->is_match(this->D.get_dkzdt()->df(kx)) &&
1079 zero->is_match(this->D.get_dkzdt()->df(ky)) &&
1080 zero->is_match(this->D.get_dkzdt()->df(kz)) &&
1081 zero->is_match(this->D.get_dxdt()->df(x)) &&
1082 zero->is_match(this->D.get_dxdt()->df(y)) &&
1083 zero->is_match(this->D.get_dxdt()->df(z)) &&
1084 zero->is_match(this->D.get_dydt()->df(x)) &&
1085 zero->is_match(this->D.get_dydt()->df(y)) &&
1086 zero->is_match(this->D.get_dydt()->df(z)) &&
1087 zero->is_match(this->D.get_dzdt()->df(x)) &&
1088 zero->is_match(this->D.get_dzdt()->df(y)) &&
1089 zero->is_match(this->D.get_dzdt()->df(z)) &&
1090 "Hamiltonian is not separable.");
1091
1092 this->t_next = this->t + dt;
1093
1094 this->x1 = this->x + dt*this->D.get_dxdt()/2.0;
1095 this->y1 = this->y + dt*this->D.get_dydt()/2.0;
1096 this->z1 = this->z + dt*this->D.get_dzdt()/2.0;
1097
1102 graph::pseudo_variable(this->x1),
1103 graph::pseudo_variable(this->y1),
1104 graph::pseudo_variable(this->z1),
1106 eq);
1107
1108 this->kx_next = this->kx + dt*D2.get_dkxdt();
1109 this->ky_next = this->ky + dt*D2.get_dkydt();
1110 this->kz_next = this->kz + dt*D2.get_dkzdt();
1111
1116 graph::pseudo_variable(this->x1),
1117 graph::pseudo_variable(this->y1),
1118 graph::pseudo_variable(this->z1),
1120 eq);
1121
1122 this->x_next = this->x1 + dt*D3.get_dxdt()/2.0;
1123 this->y_next = this->y1 + dt*D3.get_dydt()/2.0;
1124 this->z_next = this->z1 + dt*D3.get_dzdt()/2.0;
1125 }
1126 };
1127}
1128
1129#endif /* solver_h */
Class interface to build dispersion relation functions.
Definition dispersion.hpp:1320
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dydt()
Provide right hand side for y update.
Definition dispersion.hpp:1529
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkydt()
Provide right hand side for z update.
Definition dispersion.hpp:1562
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkxdt()
Provide right hand side for z update.
Definition dispersion.hpp:1551
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkzdt()
Provide right hand side for z update.
Definition dispersion.hpp:1573
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > solve(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::input_nodes< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > inputs, const size_t index=0, const typename DISPERSION_FUNCTION::base tolerance=1.0E-30, const size_t max_iterations=1000)
Solve the dispersion relation for x.
Definition dispersion.hpp:1452
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dzdt()
Provide right hand side for z update.
Definition dispersion.hpp:1540
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_residual()
Get the dispersion residual.
Definition dispersion.hpp:1485
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dxdt()
Provide right hand side for x update.
Definition dispersion.hpp:1518
Class representing a netcdf dataset.
Definition output.hpp:166
void create_variable(const result_file &result, const std::string &name, graph::shared_leaf< T, SAFE_MATH > &node, jit::context< T, SAFE_MATH > &context)
Create a variable.
Definition output.hpp:260
void write(const result_file &result)
Write step.
Definition output.hpp:353
Class representing a netcdf based output file.
Definition output.hpp:32
void end_define_mode() const
End define mode.
Definition output.hpp:94
Adaptive Fourth Order Runge Kutta class.
Definition solver.hpp:880
dispersion::dispersion_interface< DISPERSION_FUNCTION > D
Dispersion residual.
Definition solver.hpp:883
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt_var
Time step variable.
Definition solver.hpp:886
adaptive_rk4(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt, equilibrium::shared< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > &eq, const std::string &filename="", const size_t num_rays=0, const size_t index=0)
Construct a new second order runge kutta solver.
Definition solver.hpp:906
virtual void compile() final
Compile the solver function.
Definition solver.hpp:945
Second Order Runge Kutta class.
Definition solver.hpp:549
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky2
ky2 subexpression.
Definition solver.hpp:575
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y2
y2 subexpression.
Definition solver.hpp:584
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx2
kx2 subexpression.
Definition solver.hpp:572
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx1
kx1 subexpression.
Definition solver.hpp:553
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
y1 subexpression.
Definition solver.hpp:565
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
x1 subexpression.
Definition solver.hpp:562
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz2
kz2 subexpression.
Definition solver.hpp:578
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
z1 subexpression.
Definition solver.hpp:568
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z2
z2 subexpression.
Definition solver.hpp:587
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky1
ky1 subexpression.
Definition solver.hpp:556
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz1
kz1 subexpression.
Definition solver.hpp:559
rk2(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt, equilibrium::shared< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > &eq, const std::string &filename="", const size_t num_rays=0, const size_t index=0)
Construct a new second order runge kutta solver.
Definition solver.hpp:607
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x2
x2 subexpression.
Definition solver.hpp:581
Fourth Order Runge Kutta class.
Definition solver.hpp:675
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky1
ky1 subexpression.
Definition solver.hpp:682
rk4(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt, equilibrium::shared< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > &eq, const std::string &filename="", const size_t num_rays=0, const size_t index=0)
Construct a new second order runge kutta solver.
Definition solver.hpp:775
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x2
x2 subexpression.
Definition solver.hpp:707
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx1
kx1 subexpression.
Definition solver.hpp:679
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z2
z2 subexpression.
Definition solver.hpp:713
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky4
ky4 subexpression.
Definition solver.hpp:739
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz1
kz1 subexpression.
Definition solver.hpp:685
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y4
y4 subexpression.
Definition solver.hpp:748
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky2
ky2 subexpression.
Definition solver.hpp:701
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz4
kz4 subexpression.
Definition solver.hpp:742
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx2
kx2 subexpression.
Definition solver.hpp:698
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y3
y3 subexpression.
Definition solver.hpp:729
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
z1 subexpression.
Definition solver.hpp:694
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y2
y2 subexpression.
Definition solver.hpp:710
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky3
ky3 subexpression.
Definition solver.hpp:720
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz3
kz3 subexpression.
Definition solver.hpp:723
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x4
x4 subexpression.
Definition solver.hpp:745
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz2
kz2 subexpression.
Definition solver.hpp:704
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z4
z4 subexpression.
Definition solver.hpp:751
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx4
kx4 subexpression.
Definition solver.hpp:736
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x3
x3 subexpression.
Definition solver.hpp:726
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
y1 subexpression.
Definition solver.hpp:691
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z3
z3 subexpression.
Definition solver.hpp:732
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
x1 subexpression.
Definition solver.hpp:688
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t_sub
t subexpression.
Definition solver.hpp:755
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx3
kx3 subexpression.
Definition solver.hpp:717
Class interface the solver.
Definition solver.hpp:123
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky
ky variable.
Definition solver.hpp:133
virtual graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > init() final
Method to initialize the rays.
Definition solver.hpp:282
void print_kz_next()
Print out the latex expression for the kz_next.
Definition solver.hpp:524
DISPERSION_FUNCTION::base base
Type def to retrieve the backend base type.
Definition solver.hpp:531
void print_z_next()
Print out the latex expression for the z_next.
Definition solver.hpp:500
output::data_set< typename DISPERSION_FUNCTION::base > dataset
Output dataset.
Definition solver.hpp:188
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz
kz variable.
Definition solver.hpp:136
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t_next
Next t value.
Definition solver.hpp:173
void print_ky_next()
Print out the latex expression for the ky_next.
Definition solver.hpp:516
void print_y_next()
Print out the latex expression for the y_next.
Definition solver.hpp:492
void sync_device()
Synchronize results from host to gpu.
Definition solver.hpp:352
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > residual
Residual.
Definition solver.hpp:177
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz_next
Next kz value.
Definition solver.hpp:161
void print_residual()
Print out the latex expression for the residual.
Definition solver.hpp:476
void print_dkzdt()
Print out the latex expression for the dkzdt.
Definition solver.hpp:448
DISPERSION_FUNCTION::base check_residual(const size_t index)
Check the residual.
Definition solver.hpp:390
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x_next
Next x value.
Definition solver.hpp:164
DISPERSION_FUNCTION dispersion_function
Type def to retrieve the dispersion function.
Definition solver.hpp:529
dispersion::dispersion_interface< DISPERSION_FUNCTION > D
Dispersion function interface.
Definition solver.hpp:151
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx
kx variable.
Definition solver.hpp:130
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z
z variable.
Definition solver.hpp:145
void print_dkxdt()
Print out the latex expression for the dkxdt.
Definition solver.hpp:434
virtual graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > init(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, const typename DISPERSION_FUNCTION::base tolerance=1.0E-30, const size_t max_iterations=1000) final
Method to initialize the rays.
Definition solver.hpp:254
virtual void compile()
Compile the solver function.
Definition solver.hpp:303
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w
w variable.
Definition solver.hpp:127
void print_x_next()
Print out the latex expression for the x_next.
Definition solver.hpp:484
void print_dxdt()
Print out the latex expression for the dxdt.
Definition solver.hpp:455
void print_kx_next()
Print out the latex expression for the kx_next.
Definition solver.hpp:508
std::thread sync
Async thread to write data files.
Definition solver.hpp:191
void step()
Method to step the rays.
Definition solver.hpp:380
const size_t index
Concurrent index.
Definition solver.hpp:183
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t
t variable.
Definition solver.hpp:148
void print_dydt()
Print out the latex expression for the dydt.
Definition solver.hpp:462
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx_next
Next kx value.
Definition solver.hpp:155
void print_dzdt()
Print out the latex expression for the dzdt.
Definition solver.hpp:469
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z_next
Next z value.
Definition solver.hpp:170
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y
y variable.
Definition solver.hpp:142
workflow::manager< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > work
Workflow manager.
Definition solver.hpp:181
void write_step()
Write result step.
Definition solver.hpp:416
void sync_host()
Synchronize results from gpu to host.
Definition solver.hpp:366
void print_dkydt()
Print out the latex expression for the dkydt.
Definition solver.hpp:441
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y_next
Next y value.
Definition solver.hpp:167
void print(const size_t index)
Print out the results.
Definition solver.hpp:399
void print_dispersion()
Print out the latex expression for the dispersion relation.
Definition solver.hpp:427
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x
x variable.
Definition solver.hpp:139
solver_interface(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t, equilibrium::shared< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > &eq, const std::string &filename="", const size_t num_rays=0, const size_t index=0)
Construct a new solver_interface with initial conditions.
Definition solver.hpp:210
output::result_file file
Output file.
Definition solver.hpp:186
static constexpr bool safe_math
Retrieve template parameter of safe math.
Definition solver.hpp:533
~solver_interface()
Destructor.
Definition solver.hpp:239
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky_next
Next ky value.
Definition solver.hpp:158
Predictor corrector that trys to minimize the dispersion residual.
Definition solver.hpp:1013
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
Half step y.
Definition solver.hpp:1020
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
Half step x.
Definition solver.hpp:1017
split_simplextic(graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > w, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t, graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt, equilibrium::shared< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > &eq, const std::string &filename="", const size_t num_rays=0, const size_t index=0)
Construct a split simplextic integrator.
Definition solver.hpp:1043
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
Half step z.
Definition solver.hpp:1023
Class representing a workflow manager.
Definition workflow.hpp:400
void add_item(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::input_nodes< T, SAFE_MATH > atomics, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size)
Add a workflow item.
Definition workflow.hpp:459
void wait()
Wait for GPU queue to finish.
Definition workflow.hpp:668
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition workflow.hpp:689
void run()
Run work items.
Definition workflow.hpp:649
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print results.
Definition workflow.hpp:700
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy buffer contents to the device.
Definition workflow.hpp:678
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:722
void compile()
Compile the workflow items.
Definition workflow.hpp:629
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition workflow.hpp:712
Solver method concept.
Definition solver.hpp:538
Base class for a dispersion relation.
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
std::shared_ptr< generic< T, SAFE_MATH > > shared
Convenience type alias for shared equilibria.
Definition equilibrium.hpp:470
Name space for graph nodes.
Definition arithmetic.hpp:13
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1154
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1167
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:2149
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:2169
shared_leaf< T, SAFE_MATH > variable(const size_t s, const std::string &symbol)
Construct a variable.
Definition node.hpp:2093
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
std::vector< std::pair< shared_leaf< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > map_nodes
Convenience type alias for mapping end codes back to inputs.
Definition node.hpp:2153
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:706
shared_leaf< T, SAFE_MATH > pseudo_variable(shared_leaf< T, SAFE_MATH > x)
Define pseudo variable convenience function.
Definition node.hpp:2314
Name space for solvers.
Definition newton.hpp:13
void newton(workflow::manager< T, SAFE_MATH > &work, graph::output_nodes< T, SAFE_MATH > vars, graph::input_nodes< T, SAFE_MATH > inputs, graph::input_nodes< T, SAFE_MATH > atomics, graph::shared_leaf< T, SAFE_MATH > func, graph::shared_random_state< T, SAFE_MATH > state, const T tolerance=1.0E-30, const size_t max_iterations=1000, const T step=1.0)
Determine the value of vars to minimize the loss function.
Definition newton.hpp:35
Implements output files in a netcdf format.