Skip to content

Commit

Permalink
Merge branch 'Sam'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
brucedjones committed Jun 21, 2017
2 parents c4df3d0 + 5ed55ca commit afd403f
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 208 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def fieldCallback(x, y, z):
return [x/10, y*50, 0]
```

The callback is then applied with `model.SetIntField(someDoubleField,tag,fieldCallback);` or`model.SetDoubleField(someDoubleField,tag,fieldCallback);`. When using field callbacks, the callback must always take 3 arguments which indicate the x y and z positions, for a 2D pack z will be zero but is still required. The callback should return either single value or a vector of values, when the number of values returned is equal to the dimensionality of the field being set.

The callback is then applied with `model.SetIntField(someIntField,tag,fieldCallback);` or`model.SetDoubleField(someDoubleField,tag,fieldCallback);`. When using field callbacks, the callback must always take 3 arguments which indicate the x y and z positions, for a 2D pack z will be zero but is still required. The callback should return either single value or a vector of values, when the number of values returned is equal to the dimensionality of the field being set.
## Writing the output file

Once all parameters and field have been specified, the model is now ready to be written to a file. Currently only one format is supported, which is the format used within MIT Geonumerics, for other formats a new class deriving from the abstract writer class must be implemented. See sparkWriter.h/cpp for reference.
Expand Down
94 changes: 47 additions & 47 deletions examples/fieldCallback.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import pyck

L = [10.0, 10.0, 0.0]
r = 0.1

cubic = pyck.CubicPacker(L, r)
pack = pyck.StructuredPack(cubic)

cube = pyck.Cuboid(1, [2, 2, -1], [6, 6, 1])
sphere = pyck.Sphere(2, [2, 2, 2], 5)

pack.AddShape(cube)
pack.AddShape(sphere)
pack.Process()

model = pyck.Model(pack)


# Create an IntField
stateField = model.CreateIntField("State", 1)

# The IntField may be set in the traditional way:
model.SetIntField(stateField, 1, 10)

# Or we can use a callback to determine the value of the
# field as a function of position
# Note that the callback must always take arguments for X Y and Z
# regardless of the dimensionality of the pack


def fieldCallback(x, y, z):
return x

model.SetIntFieldCallback(stateField, 2, fieldCallback)

# The same can be done with DoubleFields
posField = model.CreateDoubleField("pos", 3)


def fieldCallback2(x, y, z):
return [x, y, z]
# Here our field is 3D, so we return a 3D value

model.SetDoubleFieldCallback(posField, 2, fieldCallback2)

writer = pyck.SparkWriter()
model.Serialize("hello.vtp", writer)
import pyck

L = [10.0, 10.0, 0.0]
r = 0.1

cubic = pyck.CubicPacker(L, r)
pack = pyck.StructuredPack(cubic)

cube = pyck.Cuboid(1, [2, 2, -1], [6, 6, 1])
sphere = pyck.Sphere(2, [2, 2, 2], 5)

pack.AddShape(cube)
pack.AddShape(sphere)
pack.Process()

model = pyck.Model(pack)


# Create an IntField
stateField = model.CreateIntField("State", 1)

# The IntField may be set in the traditional way:
model.SetIntField(stateField, 1, 10)

# Or we can use a callback to determine the value of the
# field as a function of position
# Note that the callback must always take arguments for X Y and Z
# regardless of the dimensionality of the pack


def fieldCallback(x, y, z):
return x

model.SetIntFieldCallback(stateField, 2, fieldCallback)

# The same can be done with DoubleFields
posField = model.CreateDoubleField("pos", 3)


def fieldCallback2(x, y, z):
return [x, y, z]
# Here our field is 3D, so we return a 3D value

model.SetDoubleFieldCallback(posField, 2, fieldCallback2)

writer = pyck.SparkWriter()
model.Serialize("hello.vtp", writer)
8 changes: 8 additions & 0 deletions model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ DoubleField *Model::GetDoubleField(int handle)
return doubleFields[handle];
}

int Model::GetNumberParticles(){
return (int)this->numParticles;
}

double* Model::GetPositions(){
return positions;
}

void Model::SetParameter(std::string key, std::string value)
{
parameters[key] = value;
Expand Down
10 changes: 10 additions & 0 deletions model.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ class Model {
*/
IntField *GetIntField(int handle);

/**
* Get the xyz position of a particle
*/
double *GetPositions();

/**
*/
int GetNumberParticles();

/**
* Set the values of an float field
* @param handle Handle of the field to be set
Expand Down
5 changes: 5 additions & 0 deletions pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ long Pack::GetNumParticles()
return numParticles;
}

double * Pack::GetPositions()
{
return positions;
}

long Pack::GetNumParticlesByState(int state)
{
long n = 0;
Expand Down
1 change: 1 addition & 0 deletions pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Pack {
*/
long GetNumParticlesByState(int state);

double * GetPositions();
double *positions; /**< Array containing all packed particle positions */
int *states; /**< Array containing all packed particle states */
long numParticles; /**< The number of particles packed in this pack */
Expand Down
1 change: 1 addition & 0 deletions swig/pack/structuredPack.i
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class StructuredPack : Pack {
void AddShape(Shape *shape);
void Process();
long GetNumParticles();
double * GetPositions();
long GetNumParticlesByState(int state);
std::vector<double> GetClosestParticlePosition(double *xyz);
};

0 comments on commit afd403f

Please sign in to comment.