⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boundg.cpp

📁 pic 模拟程序!面向对象
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//boundg.cpp#include "boundg.h"#include "boundary.h"#include "gpdist.h"#include "spatialg.h"#include "grid.h"#include "segmentg.h"///\dad{begin}#include "spbound.h"#include "diags.h"///\dad{end}#ifdef MPI_VERSION#include "mpi.h"extern MPI_Comm XOOPIC_COMM;extern int MPI_RANK;#define SRB_ANNOUNCE_TAG 100#define SRB_LINK_TAG 200typedef struct {  char *name;  int index;  int linkedP;} SRBdat;#endifint Between(Scalar i, Scalar lo, Scalar hi){return ((lo <= i) && (i <= hi));}//=================== BoundaryParams ClassBoundaryParams::BoundaryParams(GridParams* _GP, SpatialRegionGroup* srg)	  : ParameterGroup(){name = "Boundary"; parameterGroupList.add(&SP); GP = _GP; spatialRegionGroup = srg; j1.setNameAndDescription(ostring("j1"),  ostring("x1 Index for a boundary endpoint")); j1.setValue("-1"); k1.setNameAndDescription(ostring("k1"),  ostring("x1 Index for a boundary endpoint")); k1.setValue("-1"); j2.setNameAndDescription(ostring("j2"),  ostring("x2 Index for a boundary endpoint")); j2.setValue("-1"); k2.setNameAndDescription(ostring("k2"),  ostring("x2 Index for a boundary endpoint")); k2.setValue("-1"); A1.setNameAndDescription("A1","x1 Location (MKS) of boundary endpoint"); A1.setValue("-1"); parameterList.add(&A1); A2.setNameAndDescription("A2","x2 Location (MKS) of boundary endpoint"); A2.setValue("-1"); parameterList.add(&A2); B1.setNameAndDescription("B1","x1 Location (MKS) of boundary endpoint"); B1.setValue("-1"); parameterList.add(&B1); B2.setNameAndDescription("B2","x2 Location (MKS) of boundary endpoint"); B2.setValue("-1"); parameterList.add(&B2); fill.setNameAndDescription("fill",  "if fill = 1 the boundary is filled in"); fill.setValue("0"); parameterList.add(&fill); normal.setNameAndDescription(ostring("normal"),		ostring("Sign of normal to surface (1 or -1)")); normal.setValue("1"); EFFlag.setNameAndDescription("EFFlag",  "A flag to record EM energy"); EFFlag.setValue("0"); IdiagFlag.setNameAndDescription("IdiagFlag","Flag turning on and off current collection for this boundary"); IdiagFlag.setValue("0"); parameterList.add(&IdiagFlag); Ihist_len.setNameAndDescription("Ihist_len",""); Ihist_len.setValue("1024"); parameterList.add(&Ihist_len); Ihist_avg.setNameAndDescription("Ihist_avg",""); Ihist_avg.setValue("1"); parameterList.add(&Ihist_avg); spotSize_p0.setNameAndDescription("spotSize_p0"," "); spotSize_p1.setNameAndDescription("spotSize_p1"," "); waveLeng_p0.setNameAndDescription("waveLeng_p0"," "); waveLeng_p1.setNameAndDescription("waveLeng_p1"," "); focus_p0.setNameAndDescription("focus_p0"," "); focus_p1.setNameAndDescription("focus_p1"," "); amp_p0.setNameAndDescription("amp_p0"," "); amp_p1.setNameAndDescription("amp_p1"," "); tdelay_p0.setNameAndDescription("tdelay_p0"," "); tdelay_p1.setNameAndDescription("tdelay_p1"," "); pulLeng_p0.setNameAndDescription("pulLeng_p0"," "); pulLeng_p1.setNameAndDescription("pulLeng_p1"," "); pulShp_p0.setNameAndDescription("pulShp_p0"," "); pulShp_p1.setNameAndDescription("pulShp_p1"," "); chirp_p0.setNameAndDescription("chirp_p0"," "); chirp_p1.setNameAndDescription("chirp_p1"," "); parameterList.add(&j1); parameterList.add(&k1); parameterList.add(&j2); parameterList.add(&k2); parameterList.add(&normal); parameterList.add(&EFFlag); parameterList.add(&spotSize_p0); parameterList.add(&spotSize_p1); parameterList.add(&waveLeng_p0); parameterList.add(&waveLeng_p1); parameterList.add(&focus_p0); parameterList.add(&focus_p1); parameterList.add(&amp_p0); parameterList.add(&amp_p1); parameterList.add(&tdelay_p0); parameterList.add(&tdelay_p1); parameterList.add(&pulLeng_p0); parameterList.add(&pulLeng_p1); parameterList.add(&chirp_p0); parameterList.add(&chirp_p1); parameterList.add(&pulShp_p0); parameterList.add(&pulShp_p1); nxbins.setNameAndDescription("nxbins",""); nxbins.setValue("0"); parameterList.add(&nxbins); nenergybins.setNameAndDescription("nenergybins",""); nenergybins.setValue("0"); parameterList.add(&nenergybins); nthetabins.setNameAndDescription("nthetabins", ""); nthetabins.setValue("0"); parameterList.add(&nthetabins); theta_min.setNameAndDescription("theta_min", ""); theta_min.setValue("0"); parameterList.add(&theta_min); theta_max.setNameAndDescription("theta_max", ""); theta_max.setValue("90"); parameterList.add(&theta_max); energy_min.setNameAndDescription("energy_min", ""); energy_min.setValue("0"); parameterList.add(&energy_min); energy_max.setNameAndDescription("energy_max", ""); energy_max.setValue("100"); parameterList.add(&energy_max); Name.setNameAndDescription("name","A string label for this boundary"); Name.setValue("Noname"); parameterList.add(&Name);  //Time parameter stuff C.setNameAndDescription("C","DC value of time dependent function on the boundary"); A.setNameAndDescription("A","AC sinusoidal value of the boundary"); frequency.setNameAndDescription("frequency","frequency of the AC signal in Hz"); phase.setNameAndDescription("phase","phase of the AC signal"); trise.setNameAndDescription("trise","rise time of the envelope"); tpulse.setNameAndDescription("tpulse","pulse time of the envelope"); tfall.setNameAndDescription("tfall","fall time of the envelope"); tdelay.setNameAndDescription("tdelay","delay time before the envelope"); a0.setNameAndDescription("a0","lower amplitude of envelope"); a1.setNameAndDescription("a1","upper amplitude of envelope"); parameterList.add(&C);	C.setValue("1.0");	parameterList.add(&A);	A.setValue("0.0");	parameterList.add(&frequency);	frequency.setValue("0.0");	parameterList.add(&phase);	phase.setValue("0.0");	parameterList.add(&trise);	trise.setValue("0.0");	parameterList.add(&tpulse);	tpulse.setValue("10000.0");	parameterList.add(&tfall);	tfall.setValue("0.0"); 	parameterList.add(&tdelay);	tdelay.setValue("0.0");	parameterList.add(&a0);	a0.setValue("1.0");	parameterList.add(&a1);	a1.setValue("1.0"); xtFlag.setNameAndDescription("xtFlag",""); xtFlag.setValue("0"); parameterList.add(&xtFlag); F.setNameAndDescription("F",""); F.setValue("100"); parameterList.add(&F);	bPtr = NULL;								// gets set by CreateCounterPart()}; BoundaryParams::~BoundaryParams() {	int j = 1;	j+=1; }ostring BoundaryParams::AlignmentConstraint(){char buffer[200];  sprintf(buffer, "%s",""); return(ostring(buffer));}ostring BoundaryParams::OnGridConstraint() {  char buffer[200];  oopicList<LineSegment> *LS = SP.GetLineSegments();  oopicListIter<LineSegment> lsiter(*LS);    //Iterate over all the segments to make sure they're on the boundary  for(lsiter.restart(); !lsiter.Done(); lsiter++) {	 LineSegment *S = lsiter.current();	 int j1,j2,k1,k2,J,K,norm;	 j1 = (int)S->A.e1();	 k1 = (int)S->A.e2();	 j2 = (int)S->B.e1();	 k2 = (int)S->B.e2();	 J=GP->getJ();	 K=GP->getK();	 norm=S->normal;	 ostring name;	 name=S->SegName;	 	 if  ((Between(j1, 0,J) && Between(k1, 0,K) &&			 Between(j2, 0,J) && Between(k2, 0,K)))				sprintf(buffer, "%s","");	 else 		{		sprintf(buffer, "segment in boundary %s at (%d, %d)- (%d, %d) is not contained on grid\n", Name.getValue().c_str(),				  j1,k1,j2,k2);		break;	 }	 //  Check normal to warn about boundaries on the edge of the grid which have outward	 // normals	 if( ((j1==j2)&&j1==0 && norm ==-1) ||  ((j1==j2)&&j1==J && norm ==1)		 ||((k1==k2)&&k1==0 && norm ==-1) ||  ((k1==k2)&&k1==K && norm ==1) ){		sprintf(buffer,				  "warning: segment %s in boundary %s at (%d, %d)- (%d, %d) has normal directed outside the region\n",						S->SegName.c_str(),				  Name.getValue().c_str(),				  j1,k1,j2,k2);		TXSTRSTD::cout << buffer;	 }  }	 	    return(ostring(buffer));}BOOL BoundaryParams::HasLength(){if ((j1.getValue() == j2.getValue()) &&	  (k1.getValue() == k2.getValue()))  return 0; else  return 1;}void BoundaryParams::checkRules(){//ruleMessages.removeAll(); ostring result = AlignmentConstraint(); if (strlen(result.c_str()) > 0)	 ruleMessages.add(new ostring(result)); result = OnGridConstraint(); if (strlen(result.c_str()) > 0)	 ruleMessages.add(new ostring(result)); // Loop thru rules oopicListIter<RuleBase> nR(RuleList); oopicListIter<BaseParameter> nP(parameterList); for (nR.restart(); !nR.Done(); nR++) // Loop thru parameters and set parameter values required by rule  {for (nP.restart(); !nP.Done(); nP++)	 nR.current()->setRuleVariable(nP.current()->getName(),	 nP.current()->getValueAsDouble()); // Check the rule	ostring result = nR.current()->checkRule();	if (strlen(result.c_str()) > 0)	 ruleMessages.add(new ostring(result));}}//--------------------------------------------------------------------// setBoundaryParams sets up the following://	1.	Boundary ID//	2.	ParticleDiagnostic//	3.	TimeFunctionvoid BoundaryParams::setBoundaryParams(Boundary* _bPtr){	bPtr = _bPtr;	bPtr->setBoundaryName(Name.getValue());	bPtr->setFill(fill.getValue());	bPtr->set_particle_diag(createDistributionCollector());   bPtr->set_Ihist_len(Ihist_len.getValue());   bPtr->set_Ihist_avg(Ihist_avg.getValue());	SpaceTimeFunction* xtf = new SpaceTimeFunction(A.getValue(), C.getValue(),							  frequency.getValue(), phase.getValue(), 							  trise.getValue(), tfall.getValue(), tpulse.getValue(),								tdelay.getValue(), a0.getValue(),							  a1.getValue(), F.getValue(), xtFlag.getValue());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -