Changes between Version 1 and Version 2 of SubSampling


Ignore:
Timestamp:
06/27/13 22:46:28 (12 years ago)
Author:
Jonathan
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • SubSampling

    v1 v2  
    11= Sub Sampling =
    2 AstroBEAR stores most fluid quantities as volume averages in the {{{q}}} array.  That is
     2
     3== Cell centered quantities ==
     4* AstroBEAR stores most fluid quantities as volume averages in the array {{{Info%q(i,j,k,:)}}}
     5* Each cell is a cube with a side {{{dx=levels(Info%level)%dx}}}
     6* The 'lower' corner of the cube is located at {{{Info%xbounds(:,1) + ((/i,j,k/)-1)*dx}}}
     7* The 'upper' corner of the cube is located at {{{Info%xbounds(:,1) + ((/i,j,k/))*dx}}}
     8* The 'center' of the cube is located at {{{Info%xbounds(:,1) + (REAL(/i,j,k/)-.5)*dx}}}
     9=== Sub-sampling ===
     10* If we break each cube into NxNxN sub-pieces, and set {{{ddx=dx/N}}} then the center of the [ii,jj,kk] sub piece will be at {{{Info%xBounds(:,1)+(/i-1,j-1,k-1/)*dx + (REAL(/ii,jj,kk/)-.5)*ddx}}}
     11* So we could use the following routine to initialize cell centered quantities in q.  Here is a routine for density.
     12{{{
     13dx=levels(Info%level)%dx
     14ddx=dx/N
     15DO i=1,Info%mX(1)
     16  DO j=1,Info%mx(2)
     17    DO k=1,Info%mx(3)
     18      new_rho=0d0
     19      DO ii=1,N
     20        DO jj=1,N
     21          DO kk=1,N
     22            pos=Info%xBounds(:,1)+(/i-1,j-1,k-1/)*dx + (REAL(/ii,jj,kk/)-.5)*ddx
     23            new_rho=new_rho+rho_func(pos)
     24          END DO
     25        END DO
     26      END DO
     27      Info%q(i,j,k,1)=new_rho/N**nDim
     28    END DO
     29  END DO
     30END DO
     31}}}
     32
     33 or we could try to speed it up by reducing some repeated computations.
     34{{{
     35dx=levels(Info%level)%dx
     36ddx=dx/N
     37DO i=1,Info%mX(1)
     38  pos(1)=Info%xBbounds(1,1)+(i-1)*dx
     39  DO j=1,Info%mx(2)
     40    pos(2)=Info%xBbounds(1,1)+(i-1)*dx
     41    DO k=1,Info%mx(3)
     42      pos(3)=Info%xBbounds(1,1)+(i-1)*dx
     43      new_rho=0d0
     44      DO ii=1,N
     45        ppos(1)=pos(1)+(REAL(ii)-.5)*ddx
     46        DO jj=1,N
     47          ppos(2)=pos(2)+(REAL(jj)-.5)*ddx
     48          DO kk=1,N
     49            ppos(3)=pos(3)+(REAL(kk)-.5)*ddx
     50            new_rho=new_rho+rho_func(pos)
     51          END DO
     52        END DO
     53      END DO
     54      Info%q(i,j,k,1)=new_rho/N**nDim
     55    END DO
     56  END DO
     57END DO
     58}}}
     59
     60 and sometimes we may be implementing a function that is only defined for a certain region (like a clump object etc...) where the value for q outside of a given radius is unknown.  In that case, we just want to add up changes to q for subcells within the region.  So for example to calculate the x component of the potential along a given edge we would
     61{{{
     62dx=levels(Info%level)%dx
     63ddx=dx/N
     64DO i=1,Info%mX(1)+1
     65  pos(1)=Info%xBbounds(1,1)+(i-1)*dx
     66  DO j=1,Info%mx(2)+1
     67    pos(2)=Info%xBbounds(1,1)+(i-1)*dx
     68    DO k=1,Info%mx(3)+1
     69      pos(3)=Info%xBbounds(1,1)+(i-1)*dx
     70      drho=0d0
     71      DO ii=1,N
     72        ppos(1)=pos(1)+(REAL(ii)-.5)*ddx
     73        DO jj=1,N
     74          ppos(2)=pos(2)+(REAL(jj)-.5)*ddx
     75          DO kk=1,N
     76            ppos(3)=pos(3)+(REAL(kk)-.5)*ddx
     77            drho=(rho_func(ppos)-Info%q(i,j,k,1))
     78          END DO
     79        END DO
     80      END DO
     81      Info%q(i,j,k,1)=Info%q(i,j,k,1)+drho/N**nDim
     82    END DO
     83  END DO
     84END DO
     85}}}
     86
     87For face centered fields we could also subsample, but their is the divergence criterion to consider for B-fields.  We could calculate the potential on a subgrid, and then take a bunch of curls on each face and add them up, but Stoke's theorem lets us just do the integral around the outside.  So we really just need to subsample along the appropriate edge for each component of the vector potential.
     88{{{
     89dx=levels(Info%level)%dx
     90ddx=dx/N
     91DO i=1,Info%mX(1)
     92  pos(1)=Info%xBbounds(1,1)+(i-1)*dx
     93  DO j=1,Info%mx(2)
     94    pos(2)=Info%xBbounds(1,1)+(i-1)*dx
     95    DO k=1,Info%mx(3)
     96      pos(3)=Info%xBbounds(1,1)+(i-1)*dx
     97      drho=0d0
     98      DO ii=1,N
     99        ppos(1)=pos(1)+(REAL(ii)-.5)*ddx
     100        DO jj=1,N
     101          ppos(2)=pos(2)+(REAL(jj)-.5)*ddx
     102          DO kk=1,N
     103            ppos(3)=pos(3)+(REAL(kk)-.5)*ddx
     104            drho=(rho_func(ppos)-Info%q(i,j,k,1))
     105          END DO
     106        END DO
     107      END DO
     108      Info%q(i,j,k,1)=Info%q(i,j,k,1)+drho/N**nDim
     109    END DO
     110  END DO
     111END DO
     112}}}
     113