# Re: Need help to set up the model

```Mohammad -

Welcome to FiPy.```
```
It's not a problem to mix triangles and quadrilaterals. FiPy is designed for
this. The complication is that FiPy constructs cells from faces and faces are
defined by vertices (nodes), so we need to reconstruct the face definitions

Cribbing from gmshMesh.py:
============
import fipy as fp
from fipy.meshes.mesh2D import Mesh2D
from fipy.tools import numerix as nx

node_coordinates = fp.numerix.array(
((0., 0.),
(1., 0.),
(0., 1.),
(1., 1.),
(2., 0.),
(3., 0.),
(2., 1.),
(3., 1.),
(2., 2.),
(3., 2.)
)
)

(0, 1, 2, -1),
(1, 3, 2, -1),
(1, 4, 6, 3),
(4, 5, 7, -1),
(4, 7, 6, -1),
(6, 7, 9, 8)
), value=0.)

currNumFaces = 0
cellsToFaces = nx.ones(cell_node_id.shape, long) * -1
facesDict    = {}
uniqueFaces  = []

for cellIdx, cell in enumerate(cell_node_id):
cell = cell.compressed()
faces = fp.numerix.concatenate((cell[..., nx.newaxis],
fp.numerix.roll(cell, -1)[...,
nx.newaxis]),
axis=1)
for faceIdx, face in enumerate(faces):
keyStr = ' '.join([str(x) for x in sorted(face)])

if keyStr in facesDict:
cellsToFaces[cellIdx][faceIdx] = facesDict[keyStr]
else: # new face
facesDict[keyStr] = currNumFaces
cellsToFaces[cellIdx][faceIdx] = currNumFaces
uniqueFaces.append(list(face))
currNumFaces += 1

# pad short faces with -1
maxFaceLen = max([len(f) for f in uniqueFaces])
uniqueFaces = [[-1] * (maxFaceLen - len(f)) + f for f in uniqueFaces]

facesToVertices = nx.array(uniqueFaces, dtype=int)

mesh = Mesh2D(vertexCoords=node_coordinates.swapaxes(0, 1).copy('C'),
faceVertexIDs=facesToVertices.swapaxes(0, 1)[::-1],
cellFaceIDs=cellsToFaces.swapaxes(0, 1).copy('C'))
============

In order to help with the boundary conditions, I need to know more about how
define them, both their location and their values.

- Jon

>
> Hello Everyone,
> I sent below email to Dr. Guyer and he advised me to join the mailing list
> and bring my questions here. Thank you!
>
> Attached is a python file that I tried to modify one of the examples based on
> my need.
> First of all, I have a big problem in creating my mesh. I could not find how
> that. The one showed in the attached file is just a template and it is not my
> mesh. For my mesh, I have node_coordinates and cell_node_id: The mesh was
> created using SMS software.
> node_coordinates:
> array([[ 360980. , 4709150. ],
>        [ 361720. , 4709170. ],
>        [ 360610. , 4709140. ],
>        ...,
>        [ 354182. , 4692112. ],
>        [ 353605. , 4692098.2],
>        [ 353914. , 4691819. ]])
>
> cell_node_id:
> array([[   0,    3,    4,   --],
>        [   2,    7,    3,    0],
>        [   5,    1,    4,    9],
>        ...,
>        [1005, 1009, 1011, 1008],
>        [1006, 1010, 1012, 1009],
>        [1013, 1011, 1009, 1012]])
>
> my mesh has both triangles and quadrilateral cells.  if that makes problem I
> can create my mesh just with triangles
>
> After creating my mesh, I know how to set up the model as I did in the
> attached file, but still I don't know how to set up Boundary Condition. from
> node_string 1 and 2 (below figure), variable concentration over time
> introduced to the lake.
>
> Any comments and help would be appreciated.
>
> Thanks
>
> ------ Forwarded Message ------
> To: jonathan.gu...@nist.gov
> Sent: 2019-11-14 11:50:31 AM
> Subject: Need help to set up the model
>
> Hello Dr. Guyer
> I am PhD student from University of Windsor, Canada. I am working on
> microbial modelling in the lake and would like to use Fipy to solve the E.
> coli transport equation. the governing equation is
>
> <wnxflldd.png>
>
> where C is the E. coli concentration and k is the decay rate. k is function
> of temperature and solar radiation which I have the time series of solar
> radiation. I also have water temperature for each cell from the hydrodynamic
> model.
> lets say the k value can be calculate as:
>
> k = k0 * 10 ^( 20 - T) * Solar_Radiation
>
> where k0 is constant and T is temperature.
>
> I also have time series of velocities (u, v and w) from hydrodynamic model
> for each cell. Here is my mesh:
> <rjrrcjsy.png>
> which node-string  1 and 2 are input and 3 is the output of the lake. E coli
> concentration from the inputs can be provided as time series too.
> Can I solve this problem with Fipy? would you please help me to set up the
> python code to do it.
>
> looking forward to hear from you soon.
> Thank you,
>
>   <image.jpg>
> PhD Candidate
> Department of Civil & Environmental Eng.
> CEI, Room 3084, Desk-I5
> 401 Sunset Ave. Windsor ON N9B 3P4
> Mobile: 519-992-8267
> uwindsor.ca/engineering
>
> <Fipy_Lake_Model.py>_______________________________________________
> fipy mailing list
> fipy@nist.gov
> http://www.ctcms.nist.gov/fipy
>  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
```