Setup

SetDirectory["~/Work/SpecTest7/test"];

Parameters

NR=40;

NA=NR;

Coordinates

NN=2*NR-1;

tmp=Table[Cos[((π ii)/NN)],{ii,NN,0,-1}];

N[tmp]

ChebR=N[tmp[[NR+1;;NN+1]]]

rarr=ChebR;

aarr=ChebR;

Setup patches

patch=Table[{rarr[[ii]],aarr[[jj]]},{ii,1,NR},{jj,1,NA}];

mask=Table[If[r<1./.{r->rarr[[ii]],a->aarr[[jj]]},1,0],{ii,1,NR},{jj,1,NA}];

Setup vector masks and index

disp[mat_]:=MatrixForm[Chop[Reverse[mat],2]]

vecmask=Table[mask,{var,1,5}];

disp[vecmask[[2]]]

disp[vecmask[[4]]]

Print["Setup indexing"]

vecpos=0;

index={};

Do[
If[vecmask[[var,ii,jj]]==1,
{
vecmask[[var,ii,jj]]=vecpos;vecpos+=1;
AppendTo[index,{var,ii,jj}];
}
,
vecmask[[var,ii,jj]]=-1;
];
,{var,1,5},{ii,1,NR},{jj,1,NA}];

vecsize=vecpos;

vecsize

Write Out

file1=OpenWrite["patch.dat",BinaryFormat->True];

Print[file1];

BinaryWrite[file1,{NR,NA},"Integer32"];

Do[

BinaryWrite[file1,patch[[ii,jj]],"Real64"];

Do[

BinaryWrite[file1,vecmask[[var,ii,jj]],"Integer32"];

,{var,1,5}];

,{ii,1,NR},{jj,1,NA}];

Close[file1];

Initial data and diffeo

Hmm

T[r_,a_]:=0;

A[r_,a_]:=0;

B[r_,a_]:=0;

F[r_,a_]:=0;

S[r_,a_]:=0;

cond[ii_,jj_]:=mask[[ii,jj]];

TarrP=Table[T[rarr[[ii]],aarr[[jj]]],{ii,1,NR},{jj,1,NA}];

AarrP=Table[A[rarr[[ii]],aarr[[jj]]],{ii,1,NR},{jj,1,NA}];

BarrP=Table[B[rarr[[ii]],aarr[[jj]]],{ii,1,NR},{jj,1,NA}];

FarrP=Table[F[rarr[[ii]],aarr[[jj]]],{ii,1,NR},{jj,1,NA}];

SarrP=Table[S[rarr[[ii]],aarr[[jj]]],{ii,1,NR},{jj,1,NA}];

Clear[T,A,B,F,S];

file2=OpenWrite["init.dat",BinaryFormat->True];

BinaryWrite[file2,Flatten[Transpose[{Flatten[TarrP],Flatten[AarrP],Flatten[BarrP],Flatten[FarrP],Flatten[SarrP]}]],"Real64"];

Close[file2];