# Uploading .txt files for particle placement

**URL:** <https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102>\
**Category:** Uncategorized\
**Created:** [February 12, 2020, 1:04am UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102 "2020-02-12T01:04:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brittlyd](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/brittlyd/32/25_2.png) [@brittlyd](https://gpusph.discourse.group/u/brittlyd)\
**Post date:** [February 12, 2020, 1:04am UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102/1 "2020-02-12T01:04:02Z")

</div>

I am wondering if there is a way to upload a .txt file that defines the particle placement? I know this is possible with a .h5sph file (like in CompleteSaExample), but I’m not sure about a .txt file. And if so, what format does the .txt have to be in? I have an object in the middle of my domain and when I try to fill the domain with fluid particles using the built-in geometries I get extremely large particle velocities at the first time step which results in a crash. So I created a grid of particles in Matlab to start the fluid around the object to avoid these high velocities, but I don’t know how to implement it in the input file.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![narcolessico](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/narcolessico/32/26_2.png) [@narcolessico](https://gpusph.discourse.group/u/narcolessico)\
**Post date:** [February 12, 2020, 7:53pm UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102/2 "2020-02-12T19:53:42Z")

</div>

The XProblem interface offers a addXYZFile() method with this purpose. The particles can be fluid or boundary. Please note that no resampling is performed, so the displacement resolution should roughly match the deltap of the problem.

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 18, 2020, 9:31am UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102/3 "2020-02-18T09:31:34Z")

</div>

Hello @brittlyd, and thanks for your interest in GPUPSH.

To expand on @narcolessico’s answer, the file format supported by `addXYZFile` is a simple list of coordinates (x, y, z), one point per line. The first parameter to `addXYZFile` defines the type of the geometry (and thus the type of the particles): use `GT_FLUID` if the point cloud is for the fluid, `GT_FIXED_BOUNDARY` for a wall, etc. The second parameter is the offset to use for the STL in case the XYZ file has an associated mesh (just use `Point(0, 0, 0)` otherwise). The third parameter is the file name to load.

For what it’s worth, the fact that filling the domain using the built-in geometries leads to extremely large particle velocities is most likely an indication of the fact that some particles are overlapping, which means that something is not being removed correctly. Could you share with us the source file for the test case that is giving you this issue? It could help us debug the issue.

---

<div class="post-metadata">

**Author:** ![brittlyd](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/brittlyd/32/25_2.png) [@brittlyd](https://gpusph.discourse.group/u/brittlyd)\
**Post date:** [February 25, 2020, 10:04pm UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102/4 "2020-02-25T22:04:19Z")

</div>

Hi @giuseppe.bilotta,

Yeah I had a feeling that overlapping was what was causing the large particle velocities, and I found the setEraseOperation function to fix that. I am still interested in uploading .txt files to define particle location for fixed and floating bodies. I created a .txt file with my particle locations in (x y z) format and used the addXYZFile method to try to create a simple cube in the domain (just as a text). Specifically, I wrote

```
GeometryID fixed_cube = addXYZFile(GT_FIXED_BOUNDARY, Point(0, 0, 0), 
                                                             "./data_files/WaveTankWASIRFBOX/text.txt",NULL);

```

and I recieved an error:

```
Initializing...
Reading particle data from the input: ./data_files/WaveTankWASIRFBOX/text.txt
FATAL: std::bad_alloc
Makefile:1227: recipe for target 'test' failed
make: *** [test] Error 1

```

I’m not exactly sure what this error is telling me or how to fix it. I’m pretty new to both GPUSPH and C++ so any advice would be greatly appreciated. I assume it is something wrong with my .txt file specifically, but I’m not quite sure. I uploaded a picture of part of my .txt file as reference.

 ![text_file](https://global.discourse-cdn.com/free1/uploads/gpusph/original/1X/d979229bf5d3fe14193687949aff3585fa55cffe.png)

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 26, 2020, 6:05pm UTC](https://gpusph.discourse.group/t/uploading-txt-files-for-particle-placement/102/5 "2020-02-26T18:05:21Z")

</div>

Hello @brittlyd,

`bad_alloc` errors generally indicate an out-of-memory condition or something similar. While this can happen when trying to load very large files on a system with low memory condition, it may also indicate some bug in the code (trying to allocate space for way more particles than necessary). If you can share the full example (sources and data file), I can have a look to see where the problem lies.
