summaryrefslogtreecommitdiff
path: root/openEMS/FDTD/operator_cylindermultigrid.cpp
blob: 88f9f824ca64d4a47a82c8d9a8aa52c1ca198e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
/*
*	Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY{} without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "operator_cylindermultigrid.h"
#include "engine_cylindermultigrid.h"
#include "extensions/operator_ext_cylinder.h"
#include "tools/useful.h"
#include "CSUseful.h"

Operator_CylinderMultiGrid::Operator_CylinderMultiGrid(vector<double> Split_Radii, unsigned int level) : Operator_Cylinder()
{
	m_Split_Radii = Split_Radii;
	m_Split_Rad = m_Split_Radii.back();
	m_Split_Radii.pop_back();
	m_MultiGridLevel = level;
}

Operator_CylinderMultiGrid::~Operator_CylinderMultiGrid()
{
	Delete();
}

Operator_CylinderMultiGrid* Operator_CylinderMultiGrid::New(vector<double> Split_Radii, unsigned int numThreads, unsigned int level)
{
	if ((Split_Radii.size()==0) || (Split_Radii.size()>CYLIDINDERMULTIGRID_LIMIT))
	{
		cerr << "Operator_CylinderMultiGrid::New: Warning: Number of multigrids invalid! Split-Number: " << Split_Radii.size() << endl;
		return NULL;
	}
	cout << "Create cylindrical multi grid FDTD operator " << endl;
	Operator_CylinderMultiGrid* op = new Operator_CylinderMultiGrid(Split_Radii, level);
	op->setNumThreads(numThreads);
	op->Init();

	return op;
}

Engine* Operator_CylinderMultiGrid::CreateEngine()
{
	m_Engine = Engine_CylinderMultiGrid::New(this,m_numThreads);
	return m_Engine;
}

double Operator_CylinderMultiGrid::GetNumberCells() const
{
	if (numLines)
		return (numLines[0]-m_Split_Pos)*(numLines[1])*(numLines[2]) + m_InnerOp->GetNumberCells();
	return 0;
}

bool Operator_CylinderMultiGrid::SetupCSXGrid(CSRectGrid* grid)
{
	if (Operator_Cylinder::SetupCSXGrid(grid)==false)
		return false;

	// make this multigrid use the larger timestep by method 3, since no r==0 singularity can be part of this engine
	m_TimeStepVar = 3;

	if ((numLines[1]-CC_closedAlpha)%2 != 1)
	{
		cerr << "Operator_CylinderMultiGrid::SetupCSXGrid: Error, number of line in alpha direction must be odd... found: " << numLines[1] << endl;
		exit(0);
	}

	m_Split_Pos = 0;
	for (unsigned int n=0; n<numLines[0]; ++n)
	{
		if (m_Split_Rad < discLines[0][n])
		{
			m_Split_Pos = n;
			if (g_settings.GetVerboseLevel()>0)
				cout << "Operator_CylinderMultiGrid::SetupCSXGrid: Found mesh split position @" << m_Split_Pos << endl;
			m_Split_Rad = discLines[0][n];
			break;
		}
	}
	if ((m_Split_Pos<4) || (m_Split_Pos>numLines[0]-4))
	{
		cerr << "Operator_CylinderMultiGrid::SetupCSXGrid: Error, split invalid..." << endl;
		return false;
	}
	return true;
}

bool Operator_CylinderMultiGrid::SetGeometryCSX(ContinuousStructure* geo)
{
	if (Operator_Cylinder::SetGeometryCSX(geo)==false)
		return false;

	CSRectGrid* grid = geo->GetGrid();

	grid->ClearLines(0);
	grid->ClearLines(1);
	for (unsigned int n=0; n<m_Split_Pos ; ++n)
		grid->AddDiscLine(0,discLines[0][n]);
	for (unsigned int n=0; n<numLines[1]; n+=2)
		grid->AddDiscLine(1,discLines[1][n]);

	if (m_InnerOp->SetGeometryCSX(CSX)==false)
		return false;

	//restore grid to original mesh
	grid->ClearLines(0);
	grid->ClearLines(1);
	for (unsigned int n=0; n<numLines[0]; ++n)
		grid->AddDiscLine(0,discLines[0][n]);
	for (unsigned int n=0; n<numLines[1]; ++n)
		grid->AddDiscLine(1,discLines[1][n]);

	return true;
}

void Operator_CylinderMultiGrid::Init()
{
	Operator_Cylinder::Init();

	if (m_Split_Radii.empty())
		m_InnerOp = Operator_Cylinder::New(m_numThreads);
	else
		m_InnerOp = Operator_CylinderMultiGrid::New(m_Split_Radii,m_numThreads, m_MultiGridLevel+1);

	for (int n=0;n<2;++n)
	{
		m_interpol_pos_v_2p[n] = NULL;
		f4_interpol_v_2p[n]=NULL;
		m_interpol_pos_v_2pp[n] = NULL;
		f4_interpol_v_2pp[n]=NULL;

		m_interpol_pos_i_2p[n] = NULL;
		f4_interpol_i_2p[n]=NULL;
		m_interpol_pos_i_2pp[n] = NULL;
		f4_interpol_i_2pp[n]=NULL;
	}
}

bool Operator_CylinderMultiGrid::GetYeeCoords(int ny, unsigned int pos[3], double* coords, bool dualMesh) const
{
	bool ret = Operator_Cylinder::GetYeeCoords(ny,pos,coords,dualMesh);

	if (pos[0]<(m_Split_Pos-1))
		ret = false;

	return ret;
}

#ifdef MPI_SUPPORT
void Operator_CylinderMultiGrid::SetTag(int tag)
{
	m_MyTag = tag;
	m_InnerOp->SetTag(tag+1);
}

void Operator_CylinderMultiGrid::SetNeighborUp(int ny, int id)
{
	if (ny==0)
	{
		cerr << "Operator_CylinderMultiGrid::SetNeighborUp: Error: MPI segregation in radial direction not supported for a cylindircal multigrid. Exit!";
		MPI_Barrier(MPI_COMM_WORLD);
		exit(-1);
	}
	Operator_Cylinder::SetNeighborUp(ny,id);
	m_InnerOp->SetNeighborUp(ny,id);
}

void Operator_CylinderMultiGrid::SetNeighborDown(int ny, int id)
{
	if (ny==0)
	{
		cerr << "Operator_CylinderMultiGrid::SetNeighborDown: Error: MPI segregation in radial direction not supported for a cylindircal multigrid. Exit!";
		MPI_Barrier(MPI_COMM_WORLD);
		exit(-1);
	}
	Operator_Cylinder::SetNeighborDown(ny,id);
	m_InnerOp->SetNeighborDown(ny,id);
}
#endif

void Operator_CylinderMultiGrid::CalcStartStopLines(unsigned int &numThreads, vector<unsigned int> &start, vector<unsigned int> &stop) const
{
	vector<unsigned int> jpt = AssignJobs2Threads(numLines[0]- m_Split_Pos + 1, numThreads, true);

	numThreads = jpt.size();

	start.resize(numThreads);
	stop.resize(numThreads);

	start.at(0)= m_Split_Pos-1;
	stop.at(0)= jpt.at(0)-1  + m_Split_Pos-1;

	for (unsigned int n=1; n<numThreads; n++)
	{
		start.at(n) = stop.at(n-1)+1;
		stop.at(n) = start.at(n) + jpt.at(n) - 1;
	}
}


void Operator_CylinderMultiGrid::FillMissingDataStorage()
{
	unsigned int pos[3];
	double EffMat[4];
	for (int ny=0; ny<3; ++ny)
	{
		for (pos[0]=0; pos[0]<m_Split_Pos-1; ++pos[0])
		{
			for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
			{
				vector<CSPrimitives*> vPrims = this->GetPrimitivesBoundBox(pos[0], pos[1], -1, CSProperties::MATERIAL);
				for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
				{
					Calc_EffMatPos(ny,pos,EffMat,vPrims);

					if (m_epsR)
						m_epsR[ny][pos[0]][pos[1]][pos[2]] =  EffMat[0];
					if (m_kappa)
						m_kappa[ny][pos[0]][pos[1]][pos[2]] =  EffMat[1];
					if (m_mueR)
						m_mueR[ny][pos[0]][pos[1]][pos[2]] =  EffMat[2];
					if (m_sigma)
						m_sigma[ny][pos[0]][pos[1]][pos[2]] =  EffMat[3];
				}
			}
		}
	}
}

bool Operator_CylinderMultiGrid::GetCellCenterMaterialAvgCoord(const int pos[3], double coord[3]) const
{
	if (Operator_Cylinder::GetCellCenterMaterialAvgCoord(pos, coord)==false)
		return false;

	if (pos[0]>=((int)m_Split_Pos))
		return true;

	int pos_a = MapAlphaIndex2Range(pos[1])/2;
	if ((pos_a<0) || (pos_a>=(int)m_InnerOp->numLines[1]))
		return false;
	coord[1] = m_InnerOp->GetDiscLine(1,pos_a,true);
	return true;
}

int Operator_CylinderMultiGrid::CalcECOperator( DebugFlags debugFlags )
{
	int retCode=0;
	if (dT)
		m_InnerOp->SetTimestep(dT);

	//calc inner child first
	m_InnerOp->CalcECOperator();

	dT = m_InnerOp->GetTimestep();

	retCode = Operator_Cylinder::CalcECOperator( debugFlags );
	if (GetTimestepValid()==false)
	{
		cerr << "Operator_CylinderMultiGrid::CalcECOperator(): Warning, timestep invalid... resetting..." << endl;
		dT = opt_dT;
		m_InnerOp->SetTimestep(dT);
		m_InnerOp->CalcECOperator();
		retCode = Operator_Cylinder::CalcECOperator( debugFlags );
	}

	SetupInterpolation();

	//the data storage will only be filled up to m_Split_Pos-1, fill the remaining area here...
	FillMissingDataStorage();
	return retCode;
}

void Operator_CylinderMultiGrid::DumpPEC2File( string filename, unsigned int *range)
{
	if (range!=NULL)
		return Operator_Cylinder::DumpPEC2File(filename, range);

	range = new unsigned int[6];
	for (int n=0;n<3;++n)
	{
		range[2*n] = 0;
		range[2*n+1] = numLines[n]-1;
	}
	range[0] = m_Split_Pos-1;
	Operator_Cylinder::DumpPEC2File(filename + "_S" + ConvertInt(m_MultiGridLevel), range);
	delete[] range;
	range=NULL;

	if (dynamic_cast<Operator_CylinderMultiGrid*>(m_InnerOp))
		m_InnerOp->DumpPEC2File(filename);
	else // base cylindrical grid
		m_InnerOp->DumpPEC2File(filename + "_S" + ConvertInt(m_MultiGridLevel+1));
}

void Operator_CylinderMultiGrid::SetupInterpolation()
{
	// n==0 --> interpolation in r&z-direction
	// n==1 --> interpolation in a-direction
	for (int n=0;n<2;++n)
	{
		delete[] m_interpol_pos_v_2p[n];
		m_interpol_pos_v_2p[n] = new unsigned int[numLines[1]];
		Delete1DArray_v4sf(f4_interpol_v_2p[n]);
		f4_interpol_v_2p[n]=Create1DArray_v4sf(numLines[1]);

		delete[] m_interpol_pos_v_2pp[n];
		m_interpol_pos_v_2pp[n] = new unsigned int[numLines[1]];
		Delete1DArray_v4sf(f4_interpol_v_2pp[n]);
		f4_interpol_v_2pp[n]=Create1DArray_v4sf(numLines[1]);

		delete[] m_interpol_pos_i_2p[n];
		m_interpol_pos_i_2p[n] = new unsigned int[numLines[1]];
		Delete1DArray_v4sf(f4_interpol_i_2p[n]);
		f4_interpol_i_2p[n]=Create1DArray_v4sf(numLines[1]);

		delete[] m_interpol_pos_i_2pp[n];
		m_interpol_pos_i_2pp[n] = new unsigned int[numLines[1]];
		Delete1DArray_v4sf(f4_interpol_i_2pp[n]);
		f4_interpol_i_2pp[n]=Create1DArray_v4sf(numLines[1]);
	}

	bool isOdd, isEven;
	for (unsigned int a_n=0; a_n<numLines[1]; ++a_n)
	{
		isOdd = (a_n%2);
		isEven = !isOdd;

		/* current interpolation position for r,z direction
		  this       sub_grid 2p   sub_grid 2pp
		  0     <--		0			(-1) 0
		  1		<--		0			1
		  2		<--		1			0
		  3		<--		1			2
		  4		<--		2			1
		  5		<--		2			3
		  ...
		  */
		m_interpol_pos_i_2p[0][a_n] = a_n/2;
		m_interpol_pos_i_2pp[0][a_n] = a_n/2 + isOdd - isEven;
		if ((a_n==0) && CC_closedAlpha)
			m_interpol_pos_i_2pp[0][a_n] = m_InnerOp->numLines[1]-3;
		else if ((a_n==0) && !CC_closedAlpha)
			m_interpol_pos_i_2pp[0][a_n] = 0;

		//setup some special treatments for not closed alpha mesh
		if ((a_n==numLines[1]-2) && !CC_closedAlpha)
			m_interpol_pos_i_2pp[0][a_n] = a_n/2 - 1;
		if ((a_n==numLines[1]-1) && !CC_closedAlpha)
			m_interpol_pos_i_2p[0][a_n] = m_interpol_pos_i_2pp[0][a_n] = a_n/2;

		double dl_p=m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2p[0][a_n],true);
		double dl_pp=m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2pp[0][a_n],true);
		if ((a_n==0) && CC_closedAlpha)
			dl_pp -= 2*PI;

		for (int v=0;v<4;++v)
		{
			if (m_interpol_pos_i_2p[0][a_n]==m_interpol_pos_i_2pp[0][a_n])
				f4_interpol_i_2p[0][a_n].f[v] = 1.0;
			else
			{
				f4_interpol_i_2p[0][a_n].f[v] = (dl_pp-GetDiscLine(1,a_n,true)) / (dl_pp-dl_p);
				f4_interpol_i_2pp[0][a_n].f[v] = (GetDiscLine(1,a_n,true)-dl_p) / (dl_pp-dl_p);
			}
		}

		/* voltage interpolation position for r,z direction
		  this       sub_grid 2p   sub_grid 2pp
		  0     <--		0			0
		  1		<--		0			1
		  2		<--		1			1
		  3		<--		1			2
		  4		<--		2			2
		  5		<--		2			3
		  ...
		  */
		m_interpol_pos_v_2p[0][a_n] = a_n/2;
		m_interpol_pos_v_2pp[0][a_n] = a_n/2 + isOdd;

		dl_p=m_InnerOp->GetDiscLine(1,m_interpol_pos_v_2p[0][a_n],false);
		dl_pp=m_InnerOp->GetDiscLine(1,m_interpol_pos_v_2pp[0][a_n],false);

		for (int v=0;v<4;++v)
		{
			if (m_interpol_pos_v_2p[0][a_n]==m_interpol_pos_v_2pp[0][a_n])
				f4_interpol_v_2p[0][a_n].f[v] = 1.0;
			else
			{
				f4_interpol_v_2p[0][a_n].f[v] = (dl_pp-GetDiscLine(1,a_n,false)) / (dl_pp-dl_p);
				f4_interpol_v_2pp[0][a_n].f[v] = (GetDiscLine(1,a_n,false)-dl_p) / (dl_pp-dl_p);
			}
		}

		/* current interpolation position for the alpha direction
		  this       sub_grid 2p   sub_grid 2pp
		  0     <--		0			0
		  1		<--		0			1
		  2		<--		1			1
		  3		<--		1			2
		  4		<--		2			2
		  5		<--		2			3
		  ...
		  */
		m_interpol_pos_i_2p[1][a_n] = a_n/2;
		m_interpol_pos_i_2pp[1][a_n] = a_n/2 + isOdd;

		//setup some special treatments for not closed alpha mesh
		if ((a_n==1) && !CC_closedAlpha)
			m_interpol_pos_i_2p[1][a_n] = 2;
		if ((a_n==numLines[1]-2) && !CC_closedAlpha)
			m_interpol_pos_i_2pp[1][a_n] = a_n/2 - 1;

		for (int v=0;v<4;++v)
		{
			if (m_interpol_pos_i_2p[1][a_n]==m_interpol_pos_i_2pp[1][a_n])
				f4_interpol_i_2p[1][a_n].f[v] = GetDiscDelta(1,a_n,true)/m_InnerOp->GetDiscDelta(1,m_interpol_pos_i_2p[1][a_n],true);
			else
			{
				f4_interpol_i_2p[1][a_n].f[v] = (m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2pp[1][a_n],false)-GetDiscLine(1,a_n,false)) /
						(m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2pp[1][a_n],false)-m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2p[1][a_n],false));
				f4_interpol_i_2p[1][a_n].f[v] *= GetDiscDelta(1,a_n,true)/m_InnerOp->GetDiscDelta(1,m_interpol_pos_i_2p[1][a_n],true);

				f4_interpol_i_2pp[1][a_n].f[v] = (GetDiscLine(1,a_n,false)-m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2p[1][a_n],false)) /
						(m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2pp[1][a_n],false)-m_InnerOp->GetDiscLine(1,m_interpol_pos_i_2p[1][a_n],false));
				f4_interpol_i_2pp[1][a_n].f[v] *= GetDiscDelta(1,a_n,true)/m_InnerOp->GetDiscDelta(1,m_interpol_pos_i_2pp[1][a_n],true);
			}
		}

		/* voltage interpolation position for the alpha direction
		  this       sub_grid 2p   sub_grid 2pp
		  0     <--		0			(-1) 0
		  1		<--		0			1
		  2		<--		1			0
		  3		<--		1			2
		  4		<--		2			1
		  5		<--		2			3
		  ...
		  */
		m_interpol_pos_v_2p[1][a_n] = a_n/2;
		m_interpol_pos_v_2pp[1][a_n] = a_n/2 + isOdd - isEven;

		if ((a_n==0) && CC_closedAlpha)
			m_interpol_pos_v_2pp[1][a_n] = m_InnerOp->numLines[1]-3;
		else if ((a_n==0) && !CC_closedAlpha)
			m_interpol_pos_v_2pp[1][a_n] = 1;

		//setup some special treatments for not closed alpha mesh
		if ((a_n==numLines[1]-2) && !CC_closedAlpha)
			m_interpol_pos_v_2pp[1][a_n] = a_n/2 - 1;
		if ((a_n==numLines[1]-1) && !CC_closedAlpha)
		{
			m_interpol_pos_v_2p[1][a_n] = 0;
			m_interpol_pos_v_2pp[1][a_n] = 0;
		}

		dl_p=m_InnerOp->GetDiscLine(1,m_interpol_pos_v_2p[1][a_n],true);
		dl_pp=m_InnerOp->GetDiscLine(1,m_interpol_pos_v_2pp[1][a_n],true);

		for (int v=0;v<4;++v)
		{
			if (m_interpol_pos_v_2p[1][a_n]==m_interpol_pos_v_2pp[1][a_n])
				f4_interpol_v_2p[1][a_n].f[v] = f4_interpol_v_2pp[1][a_n].f[v] = 0;
			else
			{
				f4_interpol_v_2p[1][a_n].f[v] = (dl_pp-GetDiscLine(1,a_n,true)) / (dl_pp-dl_p);
				f4_interpol_v_2p[1][a_n].f[v] *= GetDiscDelta(1,a_n,false)/m_InnerOp->GetDiscDelta(1,m_interpol_pos_v_2p[1][a_n],false);

				f4_interpol_v_2pp[1][a_n].f[v] = (GetDiscLine(1,a_n,true)-dl_p) / (dl_pp-dl_p);
				f4_interpol_v_2pp[1][a_n].f[v] *= GetDiscDelta(1,a_n,false)/m_InnerOp->GetDiscDelta(1,m_interpol_pos_v_2pp[1][a_n],false);
			}
		}
	}
}

void Operator_CylinderMultiGrid::SetExcitationSignal(Excitation* exc)
{
	m_InnerOp->SetExcitationSignal(exc);
	Operator_Cylinder::SetExcitationSignal(exc);
}

void Operator_CylinderMultiGrid::Delete()
{
	delete m_InnerOp;
	m_InnerOp=0;

	for (int n=0;n<2;++n)
	{
		delete[] m_interpol_pos_v_2p[n];
		m_interpol_pos_v_2p[n]=NULL;
		Delete1DArray_v4sf(f4_interpol_v_2p[n]);
		f4_interpol_v_2p[n]=NULL;
		delete[] m_interpol_pos_v_2pp[n];
		m_interpol_pos_v_2pp[n]=NULL;
		Delete1DArray_v4sf(f4_interpol_v_2pp[n]);
		f4_interpol_v_2pp[n]=NULL;

		delete[] m_interpol_pos_i_2p[n];
		m_interpol_pos_i_2p[n]=NULL;
		Delete1DArray_v4sf(f4_interpol_i_2p[n]);
		f4_interpol_i_2p[n]=NULL;
		delete[] m_interpol_pos_i_2pp[n];
		m_interpol_pos_i_2pp[n]=NULL;
		Delete1DArray_v4sf(f4_interpol_i_2pp[n]);
		f4_interpol_i_2pp[n]=NULL;
	}
}

void Operator_CylinderMultiGrid::Reset()
{
	Delete();
	Operator_Cylinder::Reset();
}

void Operator_CylinderMultiGrid::SetBoundaryCondition(int* BCs)
{
	Operator_Cylinder::SetBoundaryCondition(BCs);
	int oldBC = BCs[1];
	BCs[1] = 0; //always PEC in +r-direction
	m_InnerOp->SetBoundaryCondition(BCs);
	BCs[1] = oldBC;
}

void Operator_CylinderMultiGrid::AddExtension(Operator_Extension* op_ext)
{
	//check whether extension is save to use in multi-grid
	if (op_ext->IsCylindricalMultiGridSave(false)==false)
	{
		cerr << "Operator_CylinderMultiGrid::AddExtension: Warning: Operator extension \"" << op_ext->GetExtensionName() << "\" is not compatible with cylindrical multi-grids!! skipping...!" << endl;
		delete op_ext;
		return;
	}

	Operator_Cylinder::AddExtension(op_ext);

	// cylinder extension does not need to be cloned, it will be created by each operator of its own...
	if (dynamic_cast<Operator_Ext_Cylinder*>(op_ext))
		return;

	//check whether extension is save to use in child multi-grid
	if (op_ext->IsCylindricalMultiGridSave(true))
	{
		Operator_Extension* child_Ext = op_ext->Clone(m_InnerOp);
		if (child_Ext==NULL)
		{
			cerr << "Operator_CylinderMultiGrid::AddExtension: Warning, extension: " << op_ext->GetExtensionName() << " can not be cloned for the child operator. Skipping Extension... " << endl;
			return;
		}
		//give the copy to child
		m_InnerOp->AddExtension(child_Ext);
	}
}

void Operator_CylinderMultiGrid::ShowStat() const
{
	m_InnerOp->ShowStat();
	m_InnerOp->ShowExtStat();
	Operator_Cylinder::ShowStat();
}