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> residule;
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 tolarance = 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 residule = this->D.solve(x, inputs, index,
271 tolarance, max_iterations);
272
273 return residule;
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 residule = this->D.get_residule();
296
297 return residule;
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->residule
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,
333 graph::shared_random_state<typename DISPERSION_FUNCTION::base,
334 DISPERSION_FUNCTION::safe_math> (),
335 "solver_kernel", inputs.back()->size());
336 work.compile();
337
338 dataset.create_variable(file, "time", this->t, work.get_context());
340 dataset.create_variable(file, "w", this->w, work.get_context());
341 dataset.create_variable(file, "x", this->x, work.get_context());
342 dataset.create_variable(file, "y", this->y, work.get_context());
343 dataset.create_variable(file, "z", this->z, work.get_context());
344 dataset.create_variable(file, "kx", this->kx, work.get_context());
345 dataset.create_variable(file, "ky", this->ky, work.get_context());
346 dataset.create_variable(file, "kz", this->kz, work.get_context());
347
349 }
350
351//------------------------------------------------------------------------------
353//------------------------------------------------------------------------------
354 void sync_device() {
355 work.copy_to_device(this->t, graph::variable_cast(this->t)->data());
356 work.copy_to_device(this->w, graph::variable_cast(this->w)->data());
357 work.copy_to_device(this->x, graph::variable_cast(this->x)->data());
358 work.copy_to_device(this->y, graph::variable_cast(this->y)->data());
359 work.copy_to_device(this->z, graph::variable_cast(this->z)->data());
360 work.copy_to_device(this->kx, graph::variable_cast(this->kx)->data());
361 work.copy_to_device(this->ky, graph::variable_cast(this->ky)->data());
362 work.copy_to_device(this->kz, graph::variable_cast(this->kz)->data());
363 }
364
365//------------------------------------------------------------------------------
367//------------------------------------------------------------------------------
368 void sync_host() {
369 work.copy_to_host(this->t, graph::variable_cast(this->t)->data());
370 work.copy_to_host(this->w, graph::variable_cast(this->w)->data());
371 work.copy_to_host(this->x, graph::variable_cast(this->x)->data());
372 work.copy_to_host(this->y, graph::variable_cast(this->y)->data());
373 work.copy_to_host(this->z, graph::variable_cast(this->z)->data());
374 work.copy_to_host(this->kx, graph::variable_cast(this->kx)->data());
375 work.copy_to_host(this->ky, graph::variable_cast(this->ky)->data());
376 work.copy_to_host(this->kz, graph::variable_cast(this->kz)->data());
377 }
378
379//------------------------------------------------------------------------------
381//------------------------------------------------------------------------------
382 void step() {
383 work.run();
384 }
385
386//------------------------------------------------------------------------------
391//------------------------------------------------------------------------------
392 typename DISPERSION_FUNCTION::base check_residule(const size_t index) {
393 return work.check_value(index, this->residule);
394 }
395
396//------------------------------------------------------------------------------
400//------------------------------------------------------------------------------
401 void print(const size_t index) {
402 work.print(index, {
403 this->t,
404 this->residule,
405 this->w,
406 this->x,
407 this->y,
408 this->z,
409 this->kx,
410 this->ky,
411 this->kz
412 });
413 }
414
415//------------------------------------------------------------------------------
417//------------------------------------------------------------------------------
418 void write_step() {
419 sync.join();
420 work.wait();
421 sync = std::thread([this] {
423 });
424 }
425
426//------------------------------------------------------------------------------
428//------------------------------------------------------------------------------
430 D.print_dispersion();
431 }
432
433//------------------------------------------------------------------------------
435//------------------------------------------------------------------------------
436 void print_dkxdt() {
437 D.print_dkxdt();
438 }
439
440//------------------------------------------------------------------------------
442//------------------------------------------------------------------------------
443 void print_dkydt() {
444 D.print_dkydt();
445 }
446
447//------------------------------------------------------------------------------
449//------------------------------------------------------------------------------
450 void print_dkzdt() {
451 D.print_dkzdt();
452 }
453
454//------------------------------------------------------------------------------
456//------------------------------------------------------------------------------
457 void print_dxdt() {
458 D.print_dxdt();
459 }
460
461//------------------------------------------------------------------------------
463//------------------------------------------------------------------------------
464 void print_dydt() {
465 D.print_dydt();
466 }
467
468//------------------------------------------------------------------------------
470//------------------------------------------------------------------------------
471 void print_dzdt() {
472 D.print_dzdt();
473 }
474
475//------------------------------------------------------------------------------
477//------------------------------------------------------------------------------
479 residule->to_latex();
480 std::cout << std::endl;
481 }
482
483//------------------------------------------------------------------------------
485//------------------------------------------------------------------------------
487 x_next->to_latex();
488 std::cout << std::endl;
489 }
490
491//------------------------------------------------------------------------------
493//------------------------------------------------------------------------------
495 y_next->to_latex();
496 std::cout << std::endl;
497 }
498
499//------------------------------------------------------------------------------
501//------------------------------------------------------------------------------
503 z_next->to_latex();
504 std::cout << std::endl;
505 }
506
507//------------------------------------------------------------------------------
509//------------------------------------------------------------------------------
511 kx_next->to_latex();
512 std::cout << std::endl;
513 }
514
515//------------------------------------------------------------------------------
517//------------------------------------------------------------------------------
519 ky_next->to_latex();
520 std::cout << std::endl;
521 }
522
523//------------------------------------------------------------------------------
525//------------------------------------------------------------------------------
527 kz_next->to_latex();
528 std::cout << std::endl;
529 }
531 typedef DISPERSION_FUNCTION dispersion_function;
533 typedef typename DISPERSION_FUNCTION::base base;
535 static constexpr bool safe_math = DISPERSION_FUNCTION::safe_math;
536 };
537
539 template<class S>
540 concept method = std::is_base_of<solver_interface<typename S::dispersion_function>, S>::value;
541
542//******************************************************************************
543// Second Order Runge Kutta.
544//******************************************************************************
545//------------------------------------------------------------------------------
549//------------------------------------------------------------------------------
550 template<dispersion::function DISPERSION_FUNCTION>
551 class rk2 : public solver_interface<DISPERSION_FUNCTION> {
552 protected:
554 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
555 DISPERSION_FUNCTION::safe_math> kx1;
557 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
558 DISPERSION_FUNCTION::safe_math> ky1;
560 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
561 DISPERSION_FUNCTION::safe_math> kz1;
563 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
564 DISPERSION_FUNCTION::safe_math> x1;
566 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
567 DISPERSION_FUNCTION::safe_math> y1;
569 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
570 DISPERSION_FUNCTION::safe_math> z1;
571
573 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
574 DISPERSION_FUNCTION::safe_math> kx2;
576 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
577 DISPERSION_FUNCTION::safe_math> ky2;
579 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
580 DISPERSION_FUNCTION::safe_math> kz2;
582 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
583 DISPERSION_FUNCTION::safe_math> x2;
585 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
586 DISPERSION_FUNCTION::safe_math> y2;
588 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
589 DISPERSION_FUNCTION::safe_math> z2;
590
591 public:
592//------------------------------------------------------------------------------
608//------------------------------------------------------------------------------
609 rk2(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
610 DISPERSION_FUNCTION::safe_math> w,
611 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
612 DISPERSION_FUNCTION::safe_math> kx,
613 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
614 DISPERSION_FUNCTION::safe_math> ky,
615 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
616 DISPERSION_FUNCTION::safe_math> kz,
617 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
618 DISPERSION_FUNCTION::safe_math> x,
619 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
620 DISPERSION_FUNCTION::safe_math> y,
621 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
622 DISPERSION_FUNCTION::safe_math> z,
623 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
624 DISPERSION_FUNCTION::safe_math> t,
625 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
626 DISPERSION_FUNCTION::safe_math> dt,
627 equilibrium::shared<typename DISPERSION_FUNCTION::base,
628 DISPERSION_FUNCTION::safe_math> &eq,
629 const std::string &filename="",
630 const size_t num_rays=0,
631 const size_t index=0) :
632 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
633 filename, num_rays, index) {
634 this->kx1 = dt*this->D.get_dkxdt();
635 this->ky1 = dt*this->D.get_dkydt();
636 this->kz1 = dt*this->D.get_dkzdt();
637 this->x1 = dt*this->D.get_dxdt();
638 this->y1 = dt*this->D.get_dydt();
639 this->z1 = dt*this->D.get_dzdt();
640
642 graph::pseudo_variable(this->kx + kx1),
643 graph::pseudo_variable(this->ky + ky1),
644 graph::pseudo_variable(this->kz + kz1),
645 graph::pseudo_variable(this->x + x1),
646 graph::pseudo_variable(this->y + y1),
647 graph::pseudo_variable(this->z + z1),
648 graph::pseudo_variable(this->t + dt),
649 eq);
650
651 this->kx2 = dt*D2.get_dkxdt();
652 this->ky2 = dt*D2.get_dkydt();
653 this->kz2 = dt*D2.get_dkzdt();
654 this->x2 = dt*D2.get_dxdt();
655 this->y2 = dt*D2.get_dydt();
656 this->z2 = dt*D2.get_dzdt();
657
658 this->kx_next = this->kx + (this->kx1 + this->kx2)/2.0;
659 this->ky_next = this->ky + (this->ky1 + this->ky2)/2.0;
660 this->kz_next = this->kz + (this->kz1 + this->kz2)/2.0;
661 this->x_next = this->x + (this->x1 + this->x2 )/2.0;
662 this->y_next = this->y + (this->y1 + this->y2 )/2.0;
663 this->z_next = this->z + (this->z1 + this->z2 )/2.0;
664 this->t_next = this->t + dt;
665 }
666 };
667
668//******************************************************************************
669// Fourth Order Runge Kutta.
670//******************************************************************************
671//------------------------------------------------------------------------------
675//------------------------------------------------------------------------------
676 template<dispersion::function DISPERSION_FUNCTION>
677 class rk4 : public solver_interface<DISPERSION_FUNCTION> {
678 protected:
680 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
681 DISPERSION_FUNCTION::safe_math> kx1;
683 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
684 DISPERSION_FUNCTION::safe_math> ky1;
686 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
687 DISPERSION_FUNCTION::safe_math> kz1;
689 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
690 DISPERSION_FUNCTION::safe_math> x1;
692 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
693 DISPERSION_FUNCTION::safe_math> y1;
695 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
696 DISPERSION_FUNCTION::safe_math> z1;
697
699 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
700 DISPERSION_FUNCTION::safe_math> kx2;
702 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
703 DISPERSION_FUNCTION::safe_math> ky2;
705 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
706 DISPERSION_FUNCTION::safe_math> kz2;
708 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
709 DISPERSION_FUNCTION::safe_math> x2;
711 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
712 DISPERSION_FUNCTION::safe_math> y2;
714 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
715 DISPERSION_FUNCTION::safe_math> z2;
716
718 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
719 DISPERSION_FUNCTION::safe_math> kx3;
721 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
722 DISPERSION_FUNCTION::safe_math> ky3;
724 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
725 DISPERSION_FUNCTION::safe_math> kz3;
727 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
728 DISPERSION_FUNCTION::safe_math> x3;
730 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
731 DISPERSION_FUNCTION::safe_math> y3;
733 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
734 DISPERSION_FUNCTION::safe_math> z3;
735
737 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
738 DISPERSION_FUNCTION::safe_math> kx4;
740 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
741 DISPERSION_FUNCTION::safe_math> ky4;
743 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
744 DISPERSION_FUNCTION::safe_math> kz4;
746 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
747 DISPERSION_FUNCTION::safe_math> x4;
749 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
750 DISPERSION_FUNCTION::safe_math> y4;
752 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
753 DISPERSION_FUNCTION::safe_math> z4;
754
756 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
757 DISPERSION_FUNCTION::safe_math> t_sub;
758
759 public:
760//------------------------------------------------------------------------------
776//------------------------------------------------------------------------------
777 rk4(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
778 DISPERSION_FUNCTION::safe_math> w,
779 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
780 DISPERSION_FUNCTION::safe_math> kx,
781 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
782 DISPERSION_FUNCTION::safe_math> ky,
783 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
784 DISPERSION_FUNCTION::safe_math> kz,
785 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
786 DISPERSION_FUNCTION::safe_math> x,
787 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
788 DISPERSION_FUNCTION::safe_math> y,
789 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
790 DISPERSION_FUNCTION::safe_math> z,
791 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
792 DISPERSION_FUNCTION::safe_math> t,
793 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
794 DISPERSION_FUNCTION::safe_math> dt,
795 equilibrium::shared<typename DISPERSION_FUNCTION::base,
796 DISPERSION_FUNCTION::safe_math> &eq,
797 const std::string &filename="",
798 const size_t num_rays=0,
799 const size_t index=0) :
800 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
801 filename, num_rays, index) {
802 this->kx1 = dt*this->D.get_dkxdt();
803 this->ky1 = dt*this->D.get_dkydt();
804 this->kz1 = dt*this->D.get_dkzdt();
805 this->x1 = dt*this->D.get_dxdt();
806 this->y1 = dt*this->D.get_dydt();
807 this->z1 = dt*this->D.get_dzdt();
808
809 this->t_sub = this->t + dt/2.0;
810
812 graph::pseudo_variable(this->kx + kx1/2.0),
813 graph::pseudo_variable(this->ky + ky1/2.0),
814 graph::pseudo_variable(this->kz + kz1/2.0),
815 graph::pseudo_variable(this->x + x1/2.0),
816 graph::pseudo_variable(this->y + y1/2.0),
817 graph::pseudo_variable(this->z + z1/2.0),
818 graph::pseudo_variable(this->t_sub),
819 eq);
820
821 this->kx2 = dt*D2.get_dkxdt();
822 this->ky2 = dt*D2.get_dkydt();
823 this->kz2 = dt*D2.get_dkzdt();
824 this->x2 = dt*D2.get_dxdt();
825 this->y2 = dt*D2.get_dydt();
826 this->z2 = dt*D2.get_dzdt();
827
829 graph::pseudo_variable(this->kx + kx2/2.0),
830 graph::pseudo_variable(this->ky + ky2/2.0),
831 graph::pseudo_variable(this->kz + kz2/2.0),
832 graph::pseudo_variable(this->x + x2/2.0),
833 graph::pseudo_variable(this->y + y2/2.0),
834 graph::pseudo_variable(this->z + z2/2.0),
835 graph::pseudo_variable(this->t_sub),
836 eq);
837
838 this->kx3 = dt*D3.get_dkxdt();
839 this->ky3 = dt*D3.get_dkydt();
840 this->kz3 = dt*D3.get_dkzdt();
841 this->x3 = dt*D3.get_dxdt();
842 this->y3 = dt*D3.get_dydt();
843 this->z3 = dt*D3.get_dzdt();
844
845 this->t_next = this->t + dt;
846
848 graph::pseudo_variable(this->kx + kx3),
849 graph::pseudo_variable(this->ky + ky3),
850 graph::pseudo_variable(this->kz + kz3),
851 graph::pseudo_variable(this->x + x3),
852 graph::pseudo_variable(this->y + y3),
853 graph::pseudo_variable(this->z + z3),
855 eq);
856
857 this->kx4 = dt*D4.get_dkxdt();
858 this->ky4 = dt*D4.get_dkydt();
859 this->kz4 = dt*D4.get_dkzdt();
860 this->x4 = dt*D4.get_dxdt();
861 this->y4 = dt*D4.get_dydt();
862 this->z4 = dt*D4.get_dzdt();
863
864 this->kx_next = this->kx + (this->kx1 + 2.0*(this->kx2 + this->kx3) + this->kx4)/6.0;
865 this->ky_next = this->ky + (this->ky1 + 2.0*(this->ky2 + this->ky3) + this->ky4)/6.0;
866 this->kz_next = this->kz + (this->kz1 + 2.0*(this->kz2 + this->kz3) + this->kz4)/6.0;
867 this->x_next = this->x + (this->x1 + 2.0*(this->x2 + this->x3 ) + this->x4 )/6.0;
868 this->y_next = this->y + (this->y1 + 2.0*(this->y2 + this->y3 ) + this->y4 )/6.0;
869 this->z_next = this->z + (this->z1 + 2.0*(this->z2 + this->z3 ) + this->z4 )/6.0;
870 }
871 };
872
873//******************************************************************************
874// Adaptive timestep Fourth Order Runge Kutta.
875//******************************************************************************
876//------------------------------------------------------------------------------
880//------------------------------------------------------------------------------
881 template<dispersion::function DISPERSION_FUNCTION>
882 class adaptive_rk4 : public rk4<DISPERSION_FUNCTION> {
883 protected:
887 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
888 DISPERSION_FUNCTION::safe_math> dt_var;
889
890 public:
891//------------------------------------------------------------------------------
907//------------------------------------------------------------------------------
908 adaptive_rk4(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
909 DISPERSION_FUNCTION::safe_math> w,
910 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
911 DISPERSION_FUNCTION::safe_math> kx,
912 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
913 DISPERSION_FUNCTION::safe_math> ky,
914 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
915 DISPERSION_FUNCTION::safe_math> kz,
916 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
917 DISPERSION_FUNCTION::safe_math> x,
918 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
919 DISPERSION_FUNCTION::safe_math> y,
920 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
921 DISPERSION_FUNCTION::safe_math> z,
922 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
923 DISPERSION_FUNCTION::safe_math> t,
924 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
925 DISPERSION_FUNCTION::safe_math> dt,
926 equilibrium::shared<typename DISPERSION_FUNCTION::base,
927 DISPERSION_FUNCTION::safe_math> &eq,
928 const std::string &filename="",
929 const size_t num_rays=0,
930 const size_t index=0) :
931 rk4<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, dt, eq,
932 filename, num_rays, index),
933 D(w,
934 graph::pseudo_variable(this->kx_next),
935 graph::pseudo_variable(this->ky_next),
936 graph::pseudo_variable(this->kz_next),
937 graph::pseudo_variable(this->x_next),
938 graph::pseudo_variable(this->y_next),
939 graph::pseudo_variable(this->z_next),
940 graph::pseudo_variable(this->t_next),
941 eq),
942 dt_var(dt) {}
943
944//------------------------------------------------------------------------------
946//------------------------------------------------------------------------------
947 virtual void compile() final {
948 auto var = graph::variable_cast(dt_var);
949 auto lambda = graph::variable(var->size(), static_cast<typename DISPERSION_FUNCTION::base> (1.0), "\\lambda");
950 auto loss = graph::one<typename DISPERSION_FUNCTION::base,
951 DISPERSION_FUNCTION::safe_math> ()/dt_var + lambda*D.get_d()*D.get_d();
952
953 graph::input_nodes<typename DISPERSION_FUNCTION::base,
954 DISPERSION_FUNCTION::safe_math> inputs = {
955 graph::variable_cast(this->t),
956 graph::variable_cast(this->w),
957 graph::variable_cast(this->x),
958 graph::variable_cast(this->y),
959 graph::variable_cast(this->z),
963 var,
965 };
966
967 solver::newton(this->work, {
968 var, graph::variable_cast(lambda)
969 }, inputs, loss, graph::shared_random_state<typename DISPERSION_FUNCTION::base,
970 DISPERSION_FUNCTION::safe_math> ());
971
972 inputs = {
973 graph::variable_cast(this->t),
974 graph::variable_cast(this->w),
975 graph::variable_cast(this->x),
976 graph::variable_cast(this->y),
977 graph::variable_cast(this->z),
981 var
982 };
983
984 graph::output_nodes<typename DISPERSION_FUNCTION::base,
985 DISPERSION_FUNCTION::safe_math> outputs = {
986 this->residule
987 };
988
989 graph::map_nodes<typename DISPERSION_FUNCTION::base,
990 DISPERSION_FUNCTION::safe_math> setters = {
991 {this->kx_next, graph::variable_cast(this->kx)},
992 {this->ky_next, graph::variable_cast(this->ky)},
993 {this->kz_next, graph::variable_cast(this->kz)},
994 {this->x_next, graph::variable_cast(this->x)},
995 {this->y_next, graph::variable_cast(this->y)},
996 {this->z_next, graph::variable_cast(this->z)},
997 {this->t_next, graph::variable_cast(this->t)}
998 };
999
1000 this->work.add_item(inputs, outputs, setters,
1001 graph::shared_random_state<typename DISPERSION_FUNCTION::base,
1002 DISPERSION_FUNCTION::safe_math> (),
1003 "solver_kernel", inputs.back()->size());
1004 this->work.compile();
1005 }
1006 };
1007
1008//******************************************************************************
1009// Split simplextic integrator
1010//******************************************************************************
1011//------------------------------------------------------------------------------
1015//------------------------------------------------------------------------------
1016 template<dispersion::function DISPERSION_FUNCTION>
1017 class split_simplextic : public solver_interface<DISPERSION_FUNCTION> {
1018 protected:
1020 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1021 DISPERSION_FUNCTION::safe_math> x1;
1023 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1024 DISPERSION_FUNCTION::safe_math> y1;
1026 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1027 DISPERSION_FUNCTION::safe_math> z1;
1028
1029 public:
1030//------------------------------------------------------------------------------
1046//------------------------------------------------------------------------------
1047 split_simplextic(graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1048 DISPERSION_FUNCTION::safe_math> w,
1049 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1050 DISPERSION_FUNCTION::safe_math> kx,
1051 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1052 DISPERSION_FUNCTION::safe_math> ky,
1053 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1054 DISPERSION_FUNCTION::safe_math> kz,
1055 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1056 DISPERSION_FUNCTION::safe_math> x,
1057 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1058 DISPERSION_FUNCTION::safe_math> y,
1059 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1060 DISPERSION_FUNCTION::safe_math> z,
1061 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1062 DISPERSION_FUNCTION::safe_math> t,
1063 graph::shared_leaf<typename DISPERSION_FUNCTION::base,
1064 DISPERSION_FUNCTION::safe_math> dt,
1065 equilibrium::shared<typename DISPERSION_FUNCTION::base,
1066 DISPERSION_FUNCTION::safe_math> &eq,
1067 const std::string &filename="",
1068 const size_t num_rays=0,
1069 const size_t index=0) :
1070 solver_interface<DISPERSION_FUNCTION> (w, kx, ky, kz, x, y, z, t, eq,
1071 filename, num_rays, index) {
1072
1073// Test if the function is separatable.
1075
1076 assert(zero->is_match(this->D.get_dkxdt()->df(kx)) &&
1077 zero->is_match(this->D.get_dkxdt()->df(ky)) &&
1078 zero->is_match(this->D.get_dkxdt()->df(kz)) &&
1079 zero->is_match(this->D.get_dkydt()->df(kx)) &&
1080 zero->is_match(this->D.get_dkydt()->df(ky)) &&
1081 zero->is_match(this->D.get_dkydt()->df(kz)) &&
1082 zero->is_match(this->D.get_dkzdt()->df(kx)) &&
1083 zero->is_match(this->D.get_dkzdt()->df(ky)) &&
1084 zero->is_match(this->D.get_dkzdt()->df(kz)) &&
1085 zero->is_match(this->D.get_dxdt()->df(x)) &&
1086 zero->is_match(this->D.get_dxdt()->df(y)) &&
1087 zero->is_match(this->D.get_dxdt()->df(z)) &&
1088 zero->is_match(this->D.get_dydt()->df(x)) &&
1089 zero->is_match(this->D.get_dydt()->df(y)) &&
1090 zero->is_match(this->D.get_dydt()->df(z)) &&
1091 zero->is_match(this->D.get_dzdt()->df(x)) &&
1092 zero->is_match(this->D.get_dzdt()->df(y)) &&
1093 zero->is_match(this->D.get_dzdt()->df(z)) &&
1094 "Hamiltonian is not separable.");
1095
1096 this->t_next = this->t + dt;
1097
1098 this->x1 = this->x + dt*this->D.get_dxdt()/2.0;
1099 this->y1 = this->y + dt*this->D.get_dydt()/2.0;
1100 this->z1 = this->z + dt*this->D.get_dzdt()/2.0;
1101
1106 graph::pseudo_variable(this->x1),
1107 graph::pseudo_variable(this->y1),
1108 graph::pseudo_variable(this->z1),
1110 eq);
1111
1112 this->kx_next = this->kx + dt*D2.get_dkxdt();
1113 this->ky_next = this->ky + dt*D2.get_dkydt();
1114 this->kz_next = this->kz + dt*D2.get_dkzdt();
1115
1120 graph::pseudo_variable(this->x1),
1121 graph::pseudo_variable(this->y1),
1122 graph::pseudo_variable(this->z1),
1124 eq);
1125
1126 this->x_next = this->x1 + dt*D3.get_dxdt()/2.0;
1127 this->y_next = this->y1 + dt*D3.get_dydt()/2.0;
1128 this->z_next = this->z1 + dt*D3.get_dzdt()/2.0;
1129 }
1130 };
1131}
1132
1133#endif /* solver_h */
Class interface to build dispersion relation functions.
Definition dispersion.hpp:1327
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dydt()
Provide right hand side for y update.
Definition dispersion.hpp:1508
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkydt()
Provide right hand side for z update.
Definition dispersion.hpp:1541
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_residule()
Get the disperison residule.
Definition dispersion.hpp:1464
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkxdt()
Provide right hand side for z update.
Definition dispersion.hpp:1530
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dkzdt()
Provide right hand side for z update.
Definition dispersion.hpp:1552
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 tolarance=1.0E-30, const size_t max_iterations=1000)
Solve the dispersion relation for x.
Definition dispersion.hpp:1432
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dzdt()
Provide right hand side for z update.
Definition dispersion.hpp:1519
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > get_dxdt()
Provide right hand side for x update.
Definition dispersion.hpp:1497
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:882
dispersion::dispersion_interface< DISPERSION_FUNCTION > D
Dispersion residule.
Definition solver.hpp:885
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > dt_var
Time step variable.
Definition solver.hpp:888
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:908
virtual void compile() final
Compile the solver function.
Definition solver.hpp:947
Second Order Runge Kutta class.
Definition solver.hpp:551
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky2
ky2 subexpression.
Definition solver.hpp:577
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y2
y2 subexpression.
Definition solver.hpp:586
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx2
kx2 subexpression.
Definition solver.hpp:574
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx1
kx1 subexpression.
Definition solver.hpp:555
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
y1 subexpression.
Definition solver.hpp:567
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
x1 subexpression.
Definition solver.hpp:564
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz2
kz2 subexpression.
Definition solver.hpp:580
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
z1 subexpression.
Definition solver.hpp:570
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z2
z2 subexpression.
Definition solver.hpp:589
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky1
ky1 subexpression.
Definition solver.hpp:558
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz1
kz1 subexpression.
Definition solver.hpp:561
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:609
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x2
x2 subexpression.
Definition solver.hpp:583
Fourth Order Runge Kutta class.
Definition solver.hpp:677
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky1
ky1 subexpression.
Definition solver.hpp:684
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:777
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x2
x2 subexpression.
Definition solver.hpp:709
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx1
kx1 subexpression.
Definition solver.hpp:681
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z2
z2 subexpression.
Definition solver.hpp:715
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky4
ky4 subexpression.
Definition solver.hpp:741
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz1
kz1 subexpression.
Definition solver.hpp:687
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y4
y4 subexpression.
Definition solver.hpp:750
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky2
ky2 subexpression.
Definition solver.hpp:703
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz4
kz4 subexpression.
Definition solver.hpp:744
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx2
kx2 subexpression.
Definition solver.hpp:700
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y3
y3 subexpression.
Definition solver.hpp:731
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
z1 subexpression.
Definition solver.hpp:696
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y2
y2 subexpression.
Definition solver.hpp:712
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > ky3
ky3 subexpression.
Definition solver.hpp:722
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz3
kz3 subexpression.
Definition solver.hpp:725
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x4
x4 subexpression.
Definition solver.hpp:747
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz2
kz2 subexpression.
Definition solver.hpp:706
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z4
z4 subexpression.
Definition solver.hpp:753
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx4
kx4 subexpression.
Definition solver.hpp:738
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x3
x3 subexpression.
Definition solver.hpp:728
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
y1 subexpression.
Definition solver.hpp:693
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z3
z3 subexpression.
Definition solver.hpp:734
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
x1 subexpression.
Definition solver.hpp:690
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > t_sub
t subexpression.
Definition solver.hpp:757
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kx3
kx3 subexpression.
Definition solver.hpp:719
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 initalize the rays.
Definition solver.hpp:282
void print_kz_next()
Print out the latex expression for the kz_next.
Definition solver.hpp:526
DISPERSION_FUNCTION::base base
Type def to retrieve the backend base type.
Definition solver.hpp:533
void print_z_next()
Print out the latex expression for the z_next.
Definition solver.hpp:502
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:518
void print_y_next()
Print out the latex expression for the y_next.
Definition solver.hpp:494
void sync_device()
Syncronize results from host to gpu.
Definition solver.hpp:354
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > kz_next
Next kz value.
Definition solver.hpp:161
void print_dkzdt()
Print out the latex expression for the dkzdt.
Definition solver.hpp:450
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x_next
Next x value.
Definition solver.hpp:164
DISPERSION_FUNCTION::base check_residule(const size_t index)
Check the residule.
Definition solver.hpp:392
DISPERSION_FUNCTION dispersion_function
Type def to retrieve the dispersion function.
Definition solver.hpp:531
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:436
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:486
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 tolarance=1.0E-30, const size_t max_iterations=1000) final
Method to initalize the rays.
Definition solver.hpp:254
void print_dxdt()
Print out the latex expression for the dxdt.
Definition solver.hpp:457
void print_kx_next()
Print out the latex expression for the kx_next.
Definition solver.hpp:510
std::thread sync
Async thread to write data files.
Definition solver.hpp:191
void step()
Method to step the rays.
Definition solver.hpp:382
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:464
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:471
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
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > residule
Residule.
Definition solver.hpp:177
void write_step()
Write result step.
Definition solver.hpp:418
void sync_host()
Syncronize results from gpu to host.
Definition solver.hpp:368
void print_residule()
Print out the latex expression for the residule.
Definition solver.hpp:478
void print_dkydt()
Print out the latex expression for the dkydt.
Definition solver.hpp:443
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:401
void print_dispersion()
Print out the latex expression for the dispersion relation.
Definition solver.hpp:429
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 inital 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:535
~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 disperison residule.
Definition solver.hpp:1017
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > y1
Half step y.
Definition solver.hpp:1024
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > x1
Half step x.
Definition solver.hpp:1021
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:1047
graph::shared_leaf< typename DISPERSION_FUNCTION::base, DISPERSION_FUNCTION::safe_math > z1
Half step z.
Definition solver.hpp:1027
Class representing a workflow manager.
Definition workflow.hpp:171
void run()
Run work items.
Definition workflow.hpp:285
void wait()
Wait for GPU queue to finish.
Definition workflow.hpp:294
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition workflow.hpp:315
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::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size)
Add a workflow item.
Definition workflow.hpp:221
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print results.
Definition workflow.hpp:326
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy buffer contents to the device.
Definition workflow.hpp:304
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:348
void compile()
Compile the workflow items.
Definition workflow.hpp:262
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition workflow.hpp:338
Solver method concept.
Definition solver.hpp:540
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:472
Name space for graph nodes.
Definition arithmetic.hpp:13
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:994
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1007
std::shared_ptr< random_state_node< T, SAFE_MATH > > shared_random_state
Convenience type alias for shared sqrt nodes.
Definition random.hpp:272
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:1730
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:1746
shared_leaf< T, SAFE_MATH > variable(const size_t s, const std::string &symbol)
Construct a variable.
Definition node.hpp:1674
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:673
std::vector< std::pair< shared_leaf< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > map_nodes
Convenience type alias for maping end codes back to inputs.
Definition node.hpp:1734
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:688
shared_leaf< T, SAFE_MATH > pseudo_variable(shared_leaf< T, SAFE_MATH > x)
Define pseudo variable convience function.
Definition node.hpp:1902
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::shared_leaf< T, SAFE_MATH > func, graph::shared_random_state< T, SAFE_MATH > state, const T tolarance=1.0E-30, const size_t max_iterations=1000, const T step=1.0)
Determine the value of vars to minimze the loss function.
Definition newton.hpp:34
Impliments output files in a netcdf format.