48class VTKOutputObserver
49:
public ITimeIntegratorObserver<TDomain, TAlgebra>,
50 public ITimeIntegratorStageObserver_start<TDomain, TAlgebra>,
51 public ITimeIntegratorStageObserver_finalize<TDomain, TAlgebra>,
52 public ITimeIntegratorStageObserver_end<TDomain, TAlgebra>
55 typedef ITimeIntegratorObserver<TDomain, TAlgebra> base_type;
56 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
57 typedef VTKOutput<TDomain::dim> vtk_type;
60 : m_sp_vtk(SPNULL), m_filename(
"0000"), m_startTime(0.0), m_plotStep(0.0) {}
62 VTKOutputObserver(
const char *filename, SmartPtr<vtk_type> vtk)
63 : m_sp_vtk(vtk), m_filename(filename), m_startTime(0.0), m_plotStep(0.0) {}
65 VTKOutputObserver(
const char *filename, SmartPtr<vtk_type> vtk, number plotStep)
66 : m_sp_vtk(vtk), m_filename(filename), m_startTime(0.0), m_plotStep(plotStep) {}
68 virtual ~VTKOutputObserver()
69 { m_sp_vtk = SPNULL; }
72 void set_output_scales(
const std::vector<number>& vScales)
74 m_vOutputScales = vScales;
78 bool step_process(SmartPtr<grid_function_type> uNew,
int step, number time, number dt) OVERRIDE
84 bool start_action(SmartPtr<grid_function_type> u,
int step, number time, number dt) OVERRIDE
86 if (!m_sp_vtk.valid())
89 writeToFile(u, step, time);
98 bool finalize_action(SmartPtr<grid_function_type> uNew,
int step, number time, number dt) OVERRIDE
100 if (!m_sp_vtk.valid())
103 if (m_plotStep == 0.0)
105 writeToFile(uNew, step, time);
110 number rem = fmod(time - dt - m_startTime, m_plotStep);
111 number nextPlotTimePt = time - dt - rem + m_plotStep;
112 int nextStep = (int) ((nextPlotTimePt - m_startTime + 0.5 * m_plotStep) / m_plotStep);
114 if (nextPlotTimePt > time)
116 m_uOld = uNew->clone();
120 SmartPtr<grid_function_type> uCur = uNew->clone_without_values();
121 while (nextPlotTimePt <= time)
123 number alpha = (time - nextPlotTimePt) / dt;
124 VecScaleAdd(
static_cast<typename TAlgebra::vector_type&
>(*uCur),
125 alpha,
static_cast<typename TAlgebra::vector_type&
>(*m_uOld),
126 1.0 - alpha,
static_cast<typename TAlgebra::vector_type&
>(*uNew));
128 writeToFile(uCur, nextStep, nextPlotTimePt);
130 nextPlotTimePt = (++nextStep) * m_plotStep;
133 m_uOld = uNew->clone();
138 bool end_action(SmartPtr<grid_function_type> u,
int step, number time, number dt) OVERRIDE
140 if (!m_sp_vtk.valid())
143 m_sp_vtk->write_time_pvd(m_filename.c_str(), *u);
149 void writeToFile(SmartPtr<grid_function_type> u,
int step, number time)
151 if (m_vOutputScales.size())
153 SmartPtr<grid_function_type> uTmp = u->clone_without_values();
154 ScaleGF<grid_function_type>(uTmp, u, m_vOutputScales);
155 m_sp_vtk->print(m_filename.c_str(), *uTmp, step, time);
158 m_sp_vtk->print(m_filename.c_str(), *u, step, time);
162 SmartPtr<vtk_type> m_sp_vtk;
163 SmartPtr<grid_function_type> m_uOld;
164 std::string m_filename;
167 std::vector<number> m_vOutputScales;
172class ConnectionViewerOutputObserver
173:
public ITimeIntegratorObserver<TDomain, TAlgebra>
176 typedef ITimeIntegratorObserver<TDomain, TAlgebra> base_type;
177 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
179 ConnectionViewerOutputObserver(
const char *filename)
180 : m_filename(filename), m_outputTime(-1.0) {}
182 ConnectionViewerOutputObserver(
const char *filename, number t_out)
183 : m_filename(filename), m_outputTime(t_out) {}
185 virtual ~ConnectionViewerOutputObserver()
188 bool step_process(SmartPtr<grid_function_type> uNew,
int step, number time, number dt) OVERRIDE
191 if (m_outputTime >=0.0 && time != m_outputTime)
return true;
193 SaveVectorForConnectionViewer<grid_function_type>(*uNew, m_filename.c_str());
198 std::string m_filename;