Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bezier Field Solution Transfer #321

Draft
wants to merge 62 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d9eeb2b
Merging develop into master
Aug 29, 2019
b384d6c
Merging develop into master
Oct 7, 2019
d245e92
Merge branch 'develop'
cwsmith Oct 20, 2019
c33f4c4
Merging develop into master
Oct 30, 2019
ab96992
Merging develop into master
Oct 31, 2019
f7b1884
Merging develop into master
Nov 6, 2019
00bbb32
Merging develop into master
Nov 12, 2019
73e0dfb
Merging develop into master
Nov 13, 2019
c52aa74
Merging develop into master
Nov 15, 2019
f66ef98
Merging develop into master
Nov 21, 2019
7903280
Merging develop into master
Dec 11, 2019
d18ce6c
Merging develop into master
Dec 20, 2019
307f983
Merging develop into master
Dec 21, 2019
e8c5374
Merging develop into master
Jan 7, 2020
2cdb8ef
Merging develop into master
Jan 8, 2020
2b41420
Merging develop into master
Jan 22, 2020
89aee2b
Merging develop into master
Jan 23, 2020
bc34e3f
Merging develop into master
Jan 31, 2020
7037417
Merging develop into master
Feb 7, 2020
7f8f777
Merge branch 'develop'
cwsmith Feb 25, 2020
0627108
Adds required functionality for Bezier Fields
mortezah Mar 17, 2020
61ae04b
handle fields through Bezier shapes
Mar 18, 2020
1d6ab96
Takes care of blending when doing Bezier Fields
mortezah Mar 23, 2020
775b743
bezier representation of solution fields
Mar 24, 2020
2982d4e
testing bezier field solution transfer.
avinmoharana Apr 7, 2020
76badb6
Merge branch 'bezier_fields' of github.com:avinmoharana/core into bez…
mortezah Apr 7, 2020
47fb3b6
Renames files FieldTransfer to SolutionTransfer
mortezah Apr 7, 2020
2228cfc
Adds setBezierSolutionTransfers for clients
mortezah Apr 7, 2020
f71dfee
bezier field representation after Refine.
avinmoharana Apr 8, 2020
9a09525
Separates implementation of maSolutionTransfer
mortezah Apr 8, 2020
ac87f00
Adds crvBezierSolutionTransfer to CMake
mortezah Apr 8, 2020
9804ab7
Bezier representation of field values after Refine.
avinmoharana Apr 10, 2020
e10035f
Solution transfer: Bezier Field representation on Cavity.
avinmoharana Apr 13, 2020
7b571c0
solution field transfer upon refine.
avinmoharana Apr 19, 2020
81f419a
Adds bezier solution transfers after Adapt is made
mortezah Apr 19, 2020
0d4cf81
Debugging crvBezierSolutionFieldTransfer.
avinmoharana Apr 20, 2020
50dfbcc
Forward declares the crv::Adapt class in crv.h
mortezah Apr 20, 2020
06b74c7
Removes an unnecessary header file
mortezah Apr 20, 2020
5b76fa9
Merge branch 'develop' of github.com:SCOREC/core into bezier_fields
avinmoharana May 7, 2020
dfe6876
removes commented header file.
avinmoharana May 7, 2020
2c083b7
fixed solution transfer onCavity and onRefine.
avinmoharana May 8, 2020
1a8336c
Merge branch 'bezier_fields' of github.com:avinmoharana/core into STa…
avinmoharana May 11, 2020
515bf06
Merge branch 'develop' of github.com:SCOREC/core into STandBezierFields
avinmoharana May 14, 2020
dd2ec78
Merge branch 'develop' of github.com:SCOREC/core into bezier_fields
avinmoharana May 15, 2020
fb2b3ed
Appends the crv Solution transfers to the existing ones.
avinmoharana May 15, 2020
097d33d
Merge branch 'bezier_fields' of github.com:avinmoharana/core into STa…
avinmoharana May 16, 2020
613983d
removed print statements.
avinmoharana May 23, 2020
ffbffcc
getFieldTransferName added.
avinmoharana May 24, 2020
e273e25
constant field transfer in a cavity, weighted by old to new values.
avinmoharana May 28, 2020
aa75b6a
bezier fields + st.
avinmoharana Jun 6, 2020
44b059c
constant Field cavity transfer.
avinmoharana Jun 12, 2020
0b352bf
index fixed in ST OnRefine.
avinmoharana Jun 15, 2020
b77a821
changes specific to Laghos problem.
avinmoharana Jun 26, 2020
251213b
debugging field values after solutionTransfer + commented second orde…
avinmoharana Aug 3, 2020
1db8724
clean code.
avinmoharana Aug 18, 2020
58be87e
Code cleanup.
avinmoharana Aug 28, 2020
721999b
cleanup
avinmoharana Sep 2, 2020
3caaeb2
cleanup.
avinmoharana Sep 2, 2020
03cd0a2
removed print blending order.
avinmoharana Sep 8, 2020
83f850b
cleanup.
avinmoharana Sep 14, 2020
cfe92b4
regression test for bezier field.
avinmoharana Sep 15, 2020
e73749b
convert interpolating to bezier fix for blended entities.
avinmoharana Sep 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ set(SOURCES
crvBezier.cc
crvBezierPoints.cc
crvBezierShapes.cc
crvBezierFields.cc
crvBezierSolutionTransfer.cc
crvBlended.cc
crvCurveMesh.cc
crvElevation.cc
15 changes: 15 additions & 0 deletions crv/crv.h
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include "apfMesh2.h"
#include "apfShape.h"
#include <ma.h>
#include <maSolutionTransfer.h>
#include <mth.h>
#include <stdio.h>
#include <vector>
@@ -22,6 +23,9 @@
* \brief the curving functions are contained in this namespace */
namespace crv {

// forward declaration of the crv::Adapt
class Adapt;

/** \brief actually 1 greater than max order */
static unsigned const MAX_ORDER = 19;

@@ -37,6 +41,13 @@ int getBlendingOrder(const int type);
/** \brief count invalid elements of the mesh */
int countNumberInvalidElements(apf::Mesh2* m);

/** \ brief converts field f to Bezier entity wise */
void convertInterpolationFieldPoints(apf::MeshEntity* e,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana
Is this used by outside users or only internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
The converInterpolationFieldPoints is not currently used outside, but it would be nice to have an entity-specific convert routine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana

What do you mean by entity-specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
I meant while testing an operator we construct a toy example where this routine can get the control points/ interpolation points for a specific edge or a face.
The routine convertInterpolationFieldPoints is defined in crvBezierFields.cc and is used in crvBezierSolutionTransfer.cc and we don't have a header file defined for crvBezierFields.

apf::Field* f, int n, int ne, apf::NewArray<double> &c);

/** \brief converts field f, which is interpolating to Bezier */
void convertInterpolatingFieldToBezier(apf::Mesh2* m_mesh, apf::Field* f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana
Is this used by outside users or only internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
This can be used outside as well. If we have an interpolating field defined outside then we can convert to Bezier from outside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana if it is not used outside, it should not be here. If they are design issues that prevent this we should discuss and resolve those appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
We want this to be accessible from outside. Can we not keep the current design?


/** \brief Base Mesh curving object
\details P is the order, S is the space dimension,
different from the mesh dimension, used to distinguish between planar 2D
@@ -203,6 +214,10 @@ void writeInterpolationPointVtuFiles(apf::Mesh* m, const char* prefix);
int getTriNodeIndex(int P, int i, int j);
int getTetNodeIndex(int P, int i, int j, int k);

/** \brief adds bezier solution transfers */
ma::SolutionTransfer* setBezierSolutionTransfers(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana

Is this used by outside users or only internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
No this not used outside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinmoharana

then it should be made static. It also seems that this file is not a correct location for this. In that case, it has to be moved to the file it is defined. Where is the implementation (the actual code)? Can you just remove this declaration make the implementation static in the file it is defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortezah
The setBezierSolutionTransfers() is defined in crvBezierSolutionTransfer.cc and is called inside the adapt routine of crvAdapt.cc.
The current implementation uses the createBezierSolutionTransfer() (defined static in crvBezierSolutionTransfer.cc) to access the bezier fields and the setBezierSolutionTransfers adds those to solutionTransfer.

I can make the createBezierSolutionTransfer() accessible and define the setBezierSolutionTransfers routine in crvAdapt.cc, or define both only in crvAdapt.

const std::vector<apf::Field*>& fields, crv::Adapt* a);

/** \brief crv fail function */
void fail(const char* why) __attribute__((noreturn));

18 changes: 18 additions & 0 deletions crv/crvAdapt.cc
Original file line number Diff line number Diff line change
@@ -194,6 +194,16 @@ static void flagCleaner(crv::Adapt* a)
}
}

static void getAllBezierFields(ma::Mesh* m, std::vector<apf::Field*>& fields)
{
for (int i = 0; i < m->countFields(); i++) {
apf::FieldShape* fs = apf::getShape(m->getField(i));
std::string name = fs->getName();
if (name == std::string("Bezier"))
fields.push_back(m->getField(i));
}
}

void adapt(ma::Input* in)
{
std::string name = in->mesh->getShape()->getName();
@@ -205,6 +215,14 @@ void adapt(ma::Input* in)
double t0 = PCU_Time();
ma::validateInput(in);
Adapt* a = new Adapt(in);

// Setting up bezier field transfer for all fields with Bezier shapes
// This is not the cleanest way of doing this!
std::vector<apf::Field*> allFields;
getAllBezierFields(a->mesh, allFields);
in->solutionTransfer = crv::setBezierSolutionTransfers(allFields, a);
a->solutionTransfer = in->solutionTransfer;

ma::preBalance(a);

fixInvalidElements(a);
136 changes: 136 additions & 0 deletions crv/crvBezierFields.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2015 Scientific Computation Research Center
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/

#include "crv.h"
#include "crvBezier.h"
#include "crvBezierShapes.h"
#include "crvMath.h"
#include "crvShape.h"
#include "crvTables.h"
#include "crvQuality.h"
#include <apfField.h>
#include <lionPrint.h>
#include <cstdlib>
#include <mth_def.h>
#include <iostream>
#include <pcu_util.h>

namespace crv {

static void convertVectorFieldInterpolationPoints(int n, int ne,
apf::NewArray<apf::Vector3>& nodes,
apf::NewArray<double>& c,
apf::NewArray<apf::Vector3>& newNodes){

for(int i = 0; i < ne; ++i)
newNodes[i].zero();

for( int i = 0; i < ne; ++i)
for( int j = 0; j < n; ++j)
newNodes[i] += nodes[j]*c[i*n+j];
}

static void convertScalarFieldInterpolationPoints(int n, int ne,
apf::NewArray<double>& nodes,
apf::NewArray<double>& c,
apf::NewArray<double>& newNodes)
{

for(int i = 0; i < ne; ++i)
newNodes[i] = 0.;

for( int i = 0; i < ne; ++i)
for( int j = 0; j < n; ++j)
newNodes[i] += nodes[j]*c[i*n+j];
}

void convertInterpolationFieldPoints(apf::MeshEntity* e,
apf::Field* f,
int n, int ne, apf::NewArray<double>& c)
{

apf::NewArray<apf::Vector3> l, b(ne);
apf::NewArray<double> ls, bs(ne);
apf::MeshElement* me =
apf::createMeshElement(f->getMesh(),e);
apf::Element* elem =
apf::createElement(f,me);

if (apf::getValueType(f) == apf::VECTOR) {
apf::getVectorNodes(elem,l);
convertVectorFieldInterpolationPoints(n, ne, l, c, b);
for(int i = 0; i < ne; ++i)
apf::setVector(f, e, i, b[i]);
}
else if (apf::getValueType(f) == apf::SCALAR) {
apf::getScalarNodes(elem, ls);
convertScalarFieldInterpolationPoints(n, ne, ls, c, bs);
for(int i = 0; i < ne; ++i)
apf::setScalar(f, e, i, bs[i]);
}
else
printf("Field type not implemented\n");
apf::destroyElement(elem);
apf::destroyMeshElement(me);
}

void convertInterpolatingFieldToBezier(apf::Mesh2* m_mesh, apf::Field* f)
{
apf::FieldShape * fs = apf::getShape(f);
int order = fs->getOrder();

//apf::Field* fnew = createField(
// m_mesh, "copy_field", apf::getValueType(f), crv::getBezier(order));
//transferFields(m_mesh, f, fnew);

int md = m_mesh->getDimension();
//
int blendingOrder = getBlendingOrder(apf::Mesh::simplexTypes[md]);
//blendingOrder = 0;
// go downward, and convert interpolating to control points
int startDim = md - (blendingOrder > 0);

for(int d = startDim; d >= 1; --d){
if(!fs->hasNodesIn(d)) continue;
int n = fs->getEntityShape(apf::Mesh::simplexTypes[d])->countNodes();
int ne = fs->countNodesOn(apf::Mesh::simplexTypes[d]);
apf::NewArray<double> c;
getBezierTransformationCoefficients(order,
apf::Mesh::simplexTypes[d],c);
apf::MeshEntity* e;
apf::MeshIterator* it = m_mesh->begin(d);
while ((e = m_mesh->iterate(it))){
if(m_mesh->isOwned(e))
convertInterpolationFieldPoints(e,f,n,ne,c);
}
m_mesh->end(it);
}

for( int d = 2; d <= md; ++d){
std::cout<<" blendingorder of dimension "<<d <<" "<<
getBlendingOrder(apf::Mesh::simplexTypes[d])<<std::endl;
if(!fs->hasNodesIn(d) ||
!getBlendingOrder(apf::Mesh::simplexTypes[d])) continue;
int n = fs->getEntityShape(apf::Mesh::simplexTypes[d])->countNodes();
int ne = fs->countNodesOn(apf::Mesh::simplexTypes[d]);
apf::NewArray<double> c;
getInternalBezierTransformationCoefficients(m_mesh,order,1,
apf::Mesh::simplexTypes[d],c);
apf::MeshEntity* e;
apf::MeshIterator* it = m_mesh->begin(d);
while ((e = m_mesh->iterate(it))){
if(!isBoundaryEntity(m_mesh,e) && m_mesh->isOwned(e))
convertInterpolationFieldPoints(e,f,n-ne,ne,c);
}
m_mesh->end(it);
}

apf::synchronize(f);

}

}
Loading
Oops, something went wrong.