core icon indicating copy to clipboard operation
core copied to clipboard

adapt only unstructured portion of mesh w/ tet boundary layers

Open cwsmith opened this issue 7 years ago • 18 comments

That PHASTA folks want to adapt the unstructured portion of a mesh based on a size field coming from the solver and without changing the tet boundary layer. Currently, unless we can exactly compute the current metric tensor on a BL vertex, then we can't set a size field on a given vertex that indicates 'do nothing'.

For the problem being considered the location of the boundary layers is defined by the expression:

The are where x^2 + y^2 > R  where R is a number we can give you. That is the top of the BL extends from  R_inner < r < R_pipe.

The following ma functionality freezes a non-simplex (hex/wedge) BL based on topology:

https://github.com/SCOREC/core/blob/133ca4d6a17d2f73220fed1a66247ecee5fd6594/ma/maLayer.cc#L11-L55

Could an user call back be defined to support freezing portions of the mesh using this flag or a similar one? For the PHASTA use case using the LAYER flag would make sense. If that approach is taken then the proposed function should be named accordingly to indicate some association with boundary layers.

cwsmith avatar Sep 19 '18 16:09 cwsmith

Dear SCOREC team, following up the discussion Cameron posted two weeks ago, here are some questions I have right now:

  1. is this LAYER flag the one that prevents adaptation in a wedge BL mesh?
  2. If yes, is there an easy way to label BL entities given an all-tet mesh? If not, we can still double check the vertex's coordinates and decide whether to set the flag for it or not. Any clarification/suggestion will be appreciated.

Best regards, Jun

hapfang avatar Oct 02 '18 19:10 hapfang

One way we can do this is as follows:

The user can create an int tag using apf::Mesh2::createIntTag(name, 1) to put a tag on the mesh which specifies the boundary layer elements (i.e., the tag will have a non-zero value for elements in the boundary layer and a zero value for the elements outside of the boundary layer). The user then will pass the "name" of the tag to "ma" as follows when setting up the adapt parameters:

ma::input->userDefinedBLTagName (note that this new parameter is not part of the mesh adapt at the moment and will be added once we decide this approach is the way to go about this)

We will update the function static long markLayerElements(Adapt* a) so that it marks the additional user-defined elements in addition to the non-simplicial elements with the LAYER flag.

Let me know if this sounds good and then Ajinkya and I will work on the implementation.

mortezah avatar Oct 03 '18 16:10 mortezah

Thanks a lot Morteza. It is indeed a good idea. I have one more question about the BL element tagging. Is there any information available to distinguish the BL tets (created from BL wedges) from the regular tets in the bulk? If not, we can still rely on the vertex coordinates to tag the BL nodes/elements.

hapfang avatar Oct 03 '18 16:10 hapfang

@hapfang, that information is not available. In other words, we cannot distinguish between tets created from BL wedges and "regular" tets.

mortezah avatar Oct 03 '18 16:10 mortezah

Got it.

hapfang avatar Oct 03 '18 17:10 hapfang

@mortezah Just a passerby in this but if your the goal of the tag you are talking about is to turn off adaption for any elements marked with a tag, this is not specific for boundary layers, so naming should be something more general e.g. shouldAdapt

jacobmerson avatar Oct 03 '18 19:10 jacobmerson

Hi Morteza, have you got any chance to update static long markLayerElements(Adapt* a) so it could take in the ma::input->userDefinedBLTagName? I have also tried writing a piece of simple code to tag the BL vertices where we wanna skip the adapt. https://github.com/PHASTA/core/blob/BLAdaptFrozen/phasta/phAdapt.cc#L155-L168

  const unsigned iPipeBLFrozen = 0;
  if(iPipeBLFrozen == 1) {
    double dist;
    apf::MeshIterator* it = m->begin(0);
    apf::MeshEntity* v;
    while ((v = m->iterate(it))) {
      apf::Vector3 vCoord;
      m->getPoint(v, 0, vCoord);
      dist = sqrt(vCoord[0]*vCoord[0]+vCoord[1]*vCoord[1]);
      if(dist > 9.5e-3)
	m->createIntTag("adaptSkipTag",1);
    }
    m->end(it);
  }

It will be great if you could take a look on it and check if I used createIntTag correctly or not. Thanks a lot.

hapfang avatar Oct 09 '18 17:10 hapfang

Hi Cameron Morteza, I understand you guys probably have a long to-do list. Unfortunately we are also under press to push this BL frozen adaptation for the annular flow simulation with phastaChef. If neither of you is available to code this new feature any time soon, I would like to take a try. Any help is very much appreciated for a layman like me.

In the following code block, the marking is all done at the mesh element level. However, my tagging of adaptSkipTag is performed at the vertex level, which is straightforward as I have to loop over the vertex, check its coordinates, and decide to tag or not. I guess I have to bring this tagging information up to the element as well. If so, what is the recommended way to proceed? https://github.com/SCOREC/core/blob/133ca4d6a17d2f73220fed1a66247ecee5fd6594/ma/maLayer.cc#L11-L55

The constant LAYER seems to have a value of 1024 (1<<10). As for the BL adaptSkip tag, do I have to be careful with the tag value, or any positive integer would work? In the example below

      if(dist > 9.5e-3)
	m->createIntTag("adaptSkipTag",1);

Could it work if I intend to create a tag adaptSkipTag with the value of 1 in mesh object m?

Thanks a lot for your time and assistance. Jun

hapfang avatar Oct 11 '18 16:10 hapfang

I will spend some time on this over the weekend. Meanwhile, note that you are using the tags incorrectly in your code sample above. The statement m->createIntTag("adaptSkipTag",1) creates an int tag with one integer value (not value of 1). The values have to be set up later. Below is an example:

apf::MeshTag* tag = m->createIntTag("adaptSkipTag",1);
int value = 2;
while ((v = m->iterate(it))) {
      apf::Vector3 vCoord;
      m->getPoint(v, 0, vCoord);
      dist = sqrt(vCoord[0]*vCoord[0]+vCoord[1]*vCoord[1]);
      if(dist > 9.5e-3)
        m->setIntTag (v, tag, &value);
}
m->end(it);

mortezah avatar Oct 11 '18 16:10 mortezah

Thank you so much for the prompt reply Morteza. The correction makes sense to me. Please let me know if there is anything I could help.

hapfang avatar Oct 11 '18 16:10 hapfang

@hapfang, I just added a commit. After creating an int tag on the mesh you can pass the tag name to mesh adapt by setting in->userDefinedLayerTagName = "the tag name you just created"

When creating the tag assign non-zero values to each element (tet) in the boundary layer in your mesh. MarkLayerElements will interpret all the entities in the closure of the tets as entities in the boundary layer.

mortezah avatar Oct 14 '18 21:10 mortezah

@mortezah Thank you so much for the help. I am testing the new functions and will report back soon.

hapfang avatar Oct 14 '18 21:10 hapfang

@cwsmith @mortezah I have a quick question regarding how to access the points in PUMI associated with a certain element/region? Below is the code snippet that I used to tag the BL mesh in a pipe domain (the pipe centerline is along (0, 0, z)) .

156   if(iPipeBLAadaptSkip == 1) {
157     double dist, dist1;
158     apf::MeshTag* tag = m->createIntTag("pipeBLAdaptSkip",1);
159     int value = 2;
160     apf::MeshIterator* it = m->begin(3); //Loop over mesh tet elements
161     apf::MeshEntity* e;
162     while ((e = m->iterate(it))) {
163       apf::Vector3 vCoord;
164       dist = 0;
165       dist1 = 0;
166       for (int i = 0; i < m->countNodesOn(e); ++i) //Loop over vertices associated with the tet element
167       {
168         m->getPoint(e, i, vCoord);
169         dist1 = sqrt(vCoord[0]*vCoord[0]+vCoord[1]*vCoord[1]); //Estiamte the distance from pipe center
170         if(dist < dist1) dist = dist1;
171       }
172       if(dist > 9.5e-3) //Tag the tet if this if condition is true
173         m->setIntTag (e, tag, &value);
174     }
175     m->end(it);

I have found f->countNodesOn(e) in the source, but f seems to be a Field. Is there a counterpart for Mesh object?

hapfang avatar Oct 15 '18 15:10 hapfang

@hapfang countNodesOn will return zero for a linear tet element.

what you want to do to achieve your goal is to get the downward verts of the tet first (using m->getDownward) then iterate over the verts and use m->getPoint(vert, 0, vCoord) to get the coords of the vert.

mortezah avatar Oct 15 '18 15:10 mortezah

@mortezah Thanks a lot for the suggestion. I have updated the algorithm but it is not working yet.

155   const unsigned iPipeBLAadaptSkip = 1;
156   if(iPipeBLAadaptSkip == 1) {
157     double dist, dist1;
158     apf::MeshTag* tag = m->createIntTag("pipeBLAdaptSkip",1);
159     int value = 2;
160     apf::MeshIterator* it = m->begin(3); //Loop over mesh tet elements
161     apf::MeshEntity* e;
162     while ((e = m->iterate(it))) {
163       apf::Vector3 vCoord;
164       dist = 0;
165       dist1 = 0;
166       apf::MeshEntity* verts[4];
167       m->getDownward(e, 0, verts);
168       for (int i = 0; i < 4; i++) //Loop over vertices associated with the tet element
169       {
170         m->getPoint(verts[i], 0, vCoord);
171         dist1 = sqrt(vCoord[0]*vCoord[0]+vCoord[1]*vCoord[1]); //Estiamte the distance from pipe center
172         if(dist < dist1) dist = dist1;
173       }
174       if(dist > 9.5e-3) //Tag the tet if this if condition is true
175         m->setIntTag (e, tag, &value);
176     }
177     m->end(it);
178   }

Could you please help double check the way I access the verts? In addition to the tagging, I also give the tag name in maInput.cc. Is it the right way to specify the tag name, or I should move this to adapt.inp file?

70   in->userDefinedLayerTagName = "pipeBLAdaptSkip";

hapfang avatar Oct 15 '18 16:10 hapfang

I don't know how the adapt is set up in phasta. But for sure you don't want to change maInput.cc.

mortezah avatar Oct 15 '18 16:10 mortezah

PHASTA calculates a size field for each vert which is transferred to Chef for adaptation. How shall I tell ma the tag name? I notice most of maInput parameters are not specified in adapt.inp.

hapfang avatar Oct 15 '18 16:10 hapfang

@hapfang can you send me an example adapt.inp file?

mortezah avatar Oct 15 '18 21:10 mortezah